Skip to content

set period if dimension cyclicity automatically set #237

@ThibHlln

Description

@ThibHlln

Hi Sadie, Hi David,

I've noticed that when I define a field with a cyclic spatial dimension (e.g. -180 degrees east to +180 degrees east), I get an error message in cf-python==3.10.0 that I was not getting in cf-python==3.8.0 because my cyclic dimension does not have a period. See example below:

import cf

f = cf.Field()

lon = f.set_construct(
    cf.DimensionCoordinate(
        properties={'standard_name': 'longitude',
                    'units': 'degrees_east',
                    'axis': 'X'},
        data=cf.Data([-150, -90, -30, 30, 90, 150]),
        bounds=cf.Bounds(data=cf.Data([[-180, -120], [-120, -60], [-60, 0], [0, 60], [60, 120], [120, 180]]))
    ),
    axes=f.set_construct(cf.DomainAxis(size=6))
)

With this example, when setting the longitude construct, I get thrown the following:

Traceback (most recent call last):
File "", line 1, in
File "/Users/thibhlln/opt/miniconda3/envs/hj38/lib/python3.8/site-packages/cf/mixin/fielddomain.py", line 2651, in set_construct
self.autocyclic(key=out, coord=construct, config=autocyclic)
File "/Users/thibhlln/opt/miniconda3/envs/hj38/lib/python3.8/site-packages/cfdm/decorators.py", line 181, in verbose_override_wrapper
return method_with_verbose_kwarg(*args, **kwargs)
File "/Users/thibhlln/opt/miniconda3/envs/hj38/lib/python3.8/site-packages/cf/mixin/fielddomain.py", line 1244, in autocyclic
self.cyclic(key, iscyclic=True, period=period, config=config)
File "/Users/thibhlln/opt/miniconda3/envs/hj38/lib/python3.8/site-packages/cf/field.py", line 5116, in cyclic
raise ValueError(
ValueError: A cyclic dimension coordinate must have a period

I don't know if cyclicity was automatically checked for and set before, and I believe that this is a good thing that it is if the bounds show that it is a cyclic dimension, however, I am wondering whether the period could not also be set automatically at the same time? This would be very convenient.

Thank you.
Thibault

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions