Skip to content
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

allow melt from not-last-day-of-month #175

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions seaice_ecdr/intermediate_monthly.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,20 @@ def calc_cdr_melt_onset_day_monthly(
) -> xr.DataArray:
"""Create the `cdr_melt_onset_day_monthly` variable."""
# Create `cdr_melt_onset_day_monthly`. This is the value from
# the last day of the month.
cdr_melt_onset_day_monthly = daily_melt_onset_for_month.sel(
time=daily_melt_onset_for_month.time.max()
)
# the last day of the month unless the month is incomplete.
# xarray uses np.datetime64[ns] for time
max_date = daily_melt_onset_for_month.time.max()
if daily_melt_onset_for_month.time.dtype == np.datetime64(1, "ns").dtype:
trey-stafford marked this conversation as resolved.
Show resolved Hide resolved
unix_epoch = np.datetime64(0, "s")
one_second = np.timedelta64(1, "s")
for dt64 in daily_melt_onset_for_month.time.data:
seconds_since_epoch = (dt64 - unix_epoch) / one_second
date = dt.datetime.utcfromtimestamp(seconds_since_epoch).date()
if date.strftime("%j") == "244":
max_date = dt64
logger.info(f"Found non-max date with melt: {max_date}")
trey-stafford marked this conversation as resolved.
Show resolved Hide resolved

cdr_melt_onset_day_monthly = daily_melt_onset_for_month.sel(time=max_date)
cdr_melt_onset_day_monthly.name = "cdr_melt_onset_day_monthly"
cdr_melt_onset_day_monthly = cdr_melt_onset_day_monthly.drop_vars("time")

Expand Down