Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update xcdat.open_mfdataset time decoding logic (#161)
- Fixes issue with incorrect time values being decoded in `decode_time_units()` for non-CF compliant time units by using the time values as offsets to the reference date in the "units" attribute - Fixes calling `open_mfdataset(decode_times=False)` when datasets have the same numerically encoded time values, but differing non-CF compliant time units (e.g., "months since 2000-01-01", "months since 2001-01-01"), resulting in time values being dropped Summary of Changes - Add optional boolean kwarg `decode_times` to `open_dataset()` and `open_mfdataset()` - Add conditionals to handle this kwarg when True or False - Add optional callable kwarg `preprocess` to `open_mfdataset()` - Add `_preprocess_non_cf_dataset()` function to decode datasets' time values with non-CF compliant units before concatenating (handles cases where the datasets have the same time values and different time units, which would otherwise result in dropping of time values) - Update `decode_non_cf_time()` - Rename from `decode_time_units()` to `decode_non_cf_time()` - Remove logic for checking cf compliance, which is now handled by `_has_cf_compliant_time()` - Fix incorrect start date for decoded time coordinates by forming them using offsets and reference dates, instead of reference date as the start point and a fixed `pd.date_range()` - Using `pd.date_range()` incorrectly assumes no gaps/missing data and that coordinate points started at the beginning of the month. It also did not handle calendar types correctly (e.g,. leap years), and would reset offsets at the beginning of the month or year if they weren't already. - Add decoding of time bounds - Add utility function `_split_time_units_attr()` for splitting "units" attribute into units and reference date strings - Update docstrings of methods - Update test fixtures for correctness and readable syntax Co-authored-by: Tom Vo <[email protected]>
- Loading branch information