Skip to content

Commit

Permalink
Merge pull request #178 from emileten/fix-standardize-gcm-360-day-cal…
Browse files Browse the repository at this point in the history
…endar

fix bad references
  • Loading branch information
emileten authored Feb 14, 2022
2 parents 322c775 + 5071545 commit 6959c17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix incorrect references when standardizing gcm (PR #178, @emileten)

## [0.16.1] - 2022-01-27
### Fixed
Expand Down
16 changes: 11 additions & 5 deletions dodola/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,30 +372,36 @@ def standardize_gcm(ds, leapday_removal=True):
# we want this to fail, as pr units are something we don't expect
raise ValueError("check units: pr units attribute is not kg m-2 s-1")

cal = get_calendar(ds)
cal = get_calendar(ds_cleaned)

if (
cal == "360_day" or leapday_removal
): # calendar conversion is necessary in either case
# if calendar is just integers, xclim cannot understand it
if ds.time.dtype == "int64":
if ds_cleaned.time.dtype == "int64":
ds_cleaned["time"] = xr.decode_cf(ds_cleaned).time
if cal == "360_day":
if leapday_removal: # 360 day -> noleap
ds_converted = xclim_convert_360day_calendar_interpolate(
ds=ds, target="noleap", align_on="random", interpolation="linear"
ds=ds_cleaned,
target="noleap",
align_on="random",
interpolation="linear",
)
else: # 360 day -> standard
ds_converted = xclim_convert_360day_calendar_interpolate(
ds=ds, target="standard", align_on="random", interpolation="linear"
ds=ds_cleaned,
target="standard",
align_on="random",
interpolation="linear",
)
else: # any -> noleap
# remove leap days and update calendar
ds_converted = xclim_remove_leapdays(ds_cleaned)

# rechunk, otherwise chunks are different sizes
ds_out = ds_converted.chunk(
{"time": 730, "lat": len(ds.lat), "lon": len(ds.lon)}
{"time": 730, "lat": len(ds_cleaned.lat), "lon": len(ds_cleaned.lon)}
)

else:
Expand Down

0 comments on commit 6959c17

Please sign in to comment.