Skip to content

Commit f42d10b

Browse files
committed
dev
1 parent d7c7293 commit f42d10b

File tree

3 files changed

+123
-53
lines changed

3 files changed

+123
-53
lines changed

cf/field.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,47 +3006,47 @@ def close(self):
30063006
removed_at="5.0.0",
30073007
) # pragma: no cover
30083008

3009-
def iscyclic(self, *identity, **filter_kwargs):
3010-
"""Returns True if the specified axis is cyclic.
3011-
3012-
.. versionadded:: 1.0
3013-
3014-
.. seealso:: `axis`, `cyclic`, `period`, `domain_axis`
3015-
3016-
:Parameters:
3017-
3018-
identity, filter_kwargs: optional
3019-
Select the unique domain axis construct returned by
3020-
``f.domain_axis(*identity, **filter_kwargs)``. See
3021-
`domain_axis` for details.
3022-
3023-
:Returns:
3024-
3025-
`bool`
3026-
True if the selected axis is cyclic, otherwise False.
3027-
3028-
**Examples**
3029-
3030-
>>> f.iscyclic('X')
3031-
True
3032-
>>> f.iscyclic('latitude')
3033-
False
3034-
3035-
>>> x = f.iscyclic('long_name=Latitude')
3036-
>>> x = f.iscyclic('dimensioncoordinate1')
3037-
>>> x = f.iscyclic('domainaxis2')
3038-
>>> x = f.iscyclic('key%domainaxis2')
3039-
>>> x = f.iscyclic('ncdim%y')
3040-
>>> x = f.iscyclic(2)
3041-
3042-
"""
3043-
axis = self.domain_axis(
3044-
*identity, key=True, default=None, **filter_kwargs
3045-
)
3046-
if axis is None:
3047-
raise ValueError("Can't identify unique domain axis")
3048-
3049-
return axis in self.cyclic()
3009+
# def iscyclic(self, *identity, **filter_kwargs):
3010+
# """Returns True if the specified axis is cyclic.
3011+
#
3012+
# .. versionadded:: 1.0
3013+
#
3014+
# .. seealso:: `axis`, `cyclic`, `period`, `domain_axis`
3015+
#
3016+
# :Parameters:
3017+
#
3018+
# identity, filter_kwargs: optional
3019+
# Select the unique domain axis construct returned by
3020+
# ``f.domain_axis(*identity, **filter_kwargs)``. See
3021+
# `domain_axis` for details.
3022+
#
3023+
# :Returns:
3024+
#
3025+
# `bool`
3026+
# True if the selected axis is cyclic, otherwise False.
3027+
#
3028+
# **Examples**
3029+
#
3030+
# >>> f.iscyclic('X')
3031+
# True
3032+
# >>> f.iscyclic('latitude')
3033+
# False
3034+
#
3035+
# >>> x = f.iscyclic('long_name=Latitude')
3036+
# >>> x = f.iscyclic('dimensioncoordinate1')
3037+
# >>> x = f.iscyclic('domainaxis2')
3038+
# >>> x = f.iscyclic('key%domainaxis2')
3039+
# >>> x = f.iscyclic('ncdim%y')
3040+
# >>> x = f.iscyclic(2)
3041+
#
3042+
# """
3043+
# axis = self.domain_axis(
3044+
# *identity, key=True, default=None, **filter_kwargs
3045+
# )
3046+
# if axis is None:
3047+
# raise ValueError("Can't identify unique domain axis")
3048+
#
3049+
# return axis in self.cyclic()
30503050

30513051
def weights(
30523052
self,

cf/mixin/fielddomain.py

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,10 +1345,13 @@ def autocyclic(self, key=None, coord=None, verbose=None, config={}):
13451345
# Don't do anything
13461346
return
13471347

1348+
dry_run = config.get("dry_run")
1349+
13481350
if "cyclic" in config:
13491351
if not config["cyclic"]:
1350-
if not noop:
1352+
if not dry_run:
13511353
self.cyclic(key, iscyclic=False, config=config)
1354+
13521355
return False
13531356
else:
13541357
period = coord.period()
@@ -1357,23 +1360,45 @@ def autocyclic(self, key=None, coord=None, verbose=None, config={}):
13571360
else:
13581361
period = config.get("period")
13591362

1360-
self.cyclic(key, iscyclic=True, period=period, config=config)
1363+
if not dry_run:
1364+
self.cyclic(
1365+
key, iscyclic=True, period=period, config=config
1366+
)
1367+
13611368
return True
13621369

1370+
# if axis is not None:
1371+
# if coord is not None:
1372+
# raise ValueError("TODO")
1373+
#
1374+
# key, coord = self.dimension_coordinate(
1375+
# filter_by_axis=(axis,), item=True, default=(None, None)
1376+
# )
1377+
# if coord is None:
1378+
# if not dry_run:
1379+
# self.cyclic(key, iscyclic=False, config=config)
1380+
#
1381+
# return False
1382+
13631383
if coord is None:
13641384
key, coord = self.dimension_coordinate(
13651385
"X", item=True, default=(None, None)
13661386
)
13671387
if coord is None:
1388+
if not dry_run:
1389+
self.cyclic(key, iscyclic=False, config=config)
1390+
13681391
return False
13691392
elif "X" in config:
13701393
if not config["X"]:
1371-
if not noop:
1394+
if not dry_run:
13721395
self.cyclic(key, iscyclic=False, config=config)
1396+
13731397
return False
13741398
elif not coord.X:
1375-
if not noop:
1399+
if not dry_run:
13761400
self.cyclic(key, iscyclic=False, config=config)
1401+
13771402
return False
13781403

13791404
bounds_range = config.get("bounds_range")
@@ -1382,14 +1407,16 @@ def autocyclic(self, key=None, coord=None, verbose=None, config={}):
13821407
else:
13831408
bounds = coord.get_bounds(None)
13841409
if bounds is None:
1385-
if not noop:
1410+
if not dry_run:
13861411
self.cyclic(key, iscyclic=False, config=config)
1412+
13871413
return False
13881414

13891415
data = bounds.get_data(None, _fill_value=False)
13901416
if data is None:
1391-
if not noop:
1417+
if not dry_run:
13921418
self.cyclic(key, iscyclic=False, config=config)
1419+
13931420
return False
13941421

13951422
bounds_units = bounds.Units
@@ -1411,7 +1438,9 @@ def autocyclic(self, key=None, coord=None, verbose=None, config={}):
14111438
elif bounds_units.equivalent(_units_degrees):
14121439
period = Data(360.0, units="degrees")
14131440
else:
1414-
self.cyclic(key, iscyclic=False, config=config)
1441+
if not dry_run:
1442+
self.cyclic(key, iscyclic=False, config=config)
1443+
14151444
return False
14161445

14171446
period.Units = bounds_units
@@ -1422,14 +1451,16 @@ def autocyclic(self, key=None, coord=None, verbose=None, config={}):
14221451
bounds_range = None
14231452

14241453
if bounds_range is None or bounds_range != period:
1425-
if not noop:
1454+
if not dry_run:
14261455
self.cyclic(key, iscyclic=False, config=config)
1456+
14271457
return False
14281458

14291459
config = config.copy()
14301460
config["axis"] = self.get_data_axes(key, default=(None,))[0]
14311461

1432-
self.cyclic(key, iscyclic=True, period=period, config=config)
1462+
if not dry_run:
1463+
self.cyclic(key, iscyclic=True, period=period, config=config)
14331464

14341465
return True
14351466

@@ -1885,6 +1916,7 @@ def cyclic(
18851916
coordinates, otherwise it is assumed to have the same
18861917
units as the dimension coordinates.
18871918
1919+
18881920
config: `dict`, optional
18891921
Additional parameters for optimising the
18901922
operation. See the code for details.
@@ -1923,7 +1955,15 @@ def cyclic(
19231955
cyclic = self._cyclic
19241956

19251957
if not identity and not filter_kwargs:
1926-
return cyclic.copy()
1958+
cyclic = cyclic.copy()
1959+
if (
1960+
len(cyclic) < len(self.domain_axes(todict=True))
1961+
and self.autocyclic()
1962+
):
1963+
cyclic = cyclic.update(self._cyclic)
1964+
self._cyclic = cyclic
1965+
1966+
return cyclic
19271967

19281968
axis = config.get("axis")
19291969
if axis is None:
@@ -2251,6 +2291,8 @@ def get_coordinate_reference(
22512291
def iscyclic(self, *identity, **filter_kwargs):
22522292
"""Returns True if the given axis is cyclic.
22532293
2294+
If
2295+
22542296
{{unique construct}}
22552297
22562298
.. versionadded:: 1.0

cf/test/test_Field.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,9 +2970,37 @@ def test_Field_cyclic_iscyclic(self):
29702970

29712971
# Setting
29722972
self.assertEqual(f2.cyclic("X", iscyclic=False), set(("domainaxis2",)))
2973-
self.assertEqual(f2.cyclic(), set())
2974-
self.assertEqual(f2.cyclic("X", period=360), set())
29752973
self.assertEqual(f2.cyclic(), set(("domainaxis2",)))
2974+
2975+
f2.cyclic("Y", period=360), set()
2976+
self.assertEqual(
2977+
f2.cyclic(),
2978+
set(
2979+
(
2980+
"domainaxis1",
2981+
"domainaxis2",
2982+
)
2983+
),
2984+
)
2985+
self.assertTrue(f2.iscyclic("Y"))
2986+
self.assertEqual(
2987+
f2.cyclic("Y", iscyclic=False),
2988+
set(
2989+
(
2990+
"domainaxis1",
2991+
"domainaxis2",
2992+
)
2993+
),
2994+
)
2995+
self.assertEqual(f2.cyclic(), set(("domainaxis2",)))
2996+
2997+
# Auto setting of cyclicity
2998+
self.assertTrue(f2.iscyclic("X"))
2999+
f2.cyclic("X", iscyclic=False)
3000+
self.assertFalse(f2._cyclic)
3001+
self.assertEqual(f2.cyclic(), set(("domainaxis2",)))
3002+
3003+
f2.cyclic("X", iscyclic=False)
29763004
self.assertTrue(f2.iscyclic("X"))
29773005

29783006
def test_Field_is_discrete_axis(self):

0 commit comments

Comments
 (0)