-
Notifications
You must be signed in to change notification settings - Fork 7
Operator constraint update: Adding support for idealised calendars (eg. 360 day) #1705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a sensible approach. I've suggested some additional date strings to add as tests, which I think will require some changes to your date parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to support the full range of ISO 8601 dates. Additional test cases to add:
- Basic format:
20250924 - Basic format with time:
20250924T0921Z - Month precision:
2025-09 - Microseconds:
2025-09-24T09:21:42.123456 - Alternate UTC representation:
2025-09-24T09:21+00:00 - Indian Standard Time:
2025-09-24T09:21+05:30
We probably don't need to support week dates (2025-W01) or ordinal dates (2025-365).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be any issue adding a 24 KiB test file. Stick it somewhere under tests/test_data/.
… test.read.py. Modifications: Constraints.py: Commits modifying this file have added the function 'my_pdt_fromstring()' which parses out am ISO date string into temporal coordinates (year, month, day, hour, minute and second) to return a PartialDateTime object to replicate the 'fromisoformat()' method. The function for 'generate_time_constraint()' is also modified such to use 'my_pdt_fromstring()' rather than 'fromisoformat()'. This has therefore allowed for the ability to process files with more idealised calendars included in CF Metadata convention (eg. 360 day). test_constraint.py: A series of test functions have been written to test the 'my_pdt_fromstring()' function added to constraints.py. These verify the function is able to correctly parse a given date string and return a PartialDateTtime. test_read.py: A test function named 'test_read_cubes_generate_time_constraint()' verifies that a cube can be read and correctly constrained along the time coordinate. NOTE: the test function added to test_read.py uses a NetCDF file that has not been included in the pull request. The file in question has a size of 24 KB, similar to other data files included within the test_data folder and uses a 360 day calendar. We would like to further ask for further approval to add this. Fixes #1701
052b90a to
41e26e1
Compare
Constraints.py: This commit modifies the file to add wider support for offset formats (e.g. hh, hhmm, hh:mm) with the my_pdt_fromstring() function.
constraints.py: Format of pdt output changed for special case YYYY-MM for the my_pdt_fromstring() function. test_constraints.py: asserts modified for the special case YYYY-MM test to reflect changes to my_pdt_fromstring() function. test_read.py: More specific asserts added to the test_read_cubes_generate_time_constraint() test to reflect file properties.
Updates #1701:
This update modifies 3 files; constraints.py, test_constraints.py and test.read.py.
Modifications:
Constraints.py: Commits modifying this file have added the function 'my_pdt_fromstring()' which parses out am ISO date string into temporal coordinates (year, month, day, hour, minute and second) to return a PartialDateTime object to replicate the 'fromisoformat()' method. The function for 'generate_time_constraint()' is also modified such to use 'my_pdt_fromstring()' rather than 'fromisoformat()'. This has therefore allowed for the ability to process files with more idealised calendars included in CF Metadata convention (eg. 360 day).
test_constraint.py: A series of test functions have been written to test the 'my_pdt_fromstring()' function added to constraints.py. These verify the function is able to correctly parse a given date string and return a PartialDateTtime.
test_read.py: A test function named 'test_read_cubes_generate_time_constraint()' verifies that a cube can be read and correctly constrained along the time coordinate.
NOTE: the test function added to test_read.py uses a NetCDF file that has not been included in the pull request. The file in question has a size of 24 KB, similar to other data files included within the test_data folder and uses a 360 day calendar. We would like to further ask for further approval to add this.