Skip to content

Commit

Permalink
Rename melt_onset_day_cdr_seaice_conc -> cdr_melt_onset_day
Browse files Browse the repository at this point in the history
  • Loading branch information
trey-stafford committed Sep 13, 2024
1 parent 433c7d3 commit e2abd8e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 43 deletions.
14 changes: 4 additions & 10 deletions seaice_ecdr/complete_daily_ecdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def read_melt_onset_field_from_complete_daily(
)

# TODO: Perhaps these field names should be in a dictionary somewhere?
melt_onset_from_ds = cde_ds["melt_onset_day_cdr_seaice_conc"].to_numpy()
melt_onset_from_ds = cde_ds["cdr_melt_onset_day"].to_numpy()

return melt_onset_from_ds

Expand Down Expand Up @@ -384,7 +384,7 @@ def _add_melt_onset_for_nh(
)

# Update cde_ds with melt onset info
cde_ds_with_melt_onset["melt_onset_day_cdr_seaice_conc"] = (
cde_ds_with_melt_onset["cdr_melt_onset_day"] = (
("time", "y", "x"),
melt_onset_field,
{
Expand All @@ -404,14 +404,8 @@ def _add_melt_onset_for_nh(
# the np.squeeze() function here is to remove the time dim so that
# this becomes a 2d array for updating the qa_... field
is_melt_has_occurred = np.squeeze(
(
MELT_SEASON_FIRST_DOY
<= cde_ds_with_melt_onset["melt_onset_day_cdr_seaice_conc"].data
)
& (
cde_ds_with_melt_onset["melt_onset_day_cdr_seaice_conc"].data
<= MELT_SEASON_LAST_DOY
)
(MELT_SEASON_FIRST_DOY <= cde_ds_with_melt_onset["cdr_melt_onset_day"].data)
& (cde_ds_with_melt_onset["cdr_melt_onset_day"].data <= MELT_SEASON_LAST_DOY)
)
# TODO: the flag value being "or"ed to the bitmask should be looked
# up as the temporally-interpolation-has-occured value
Expand Down
2 changes: 1 addition & 1 deletion seaice_ecdr/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Note: quotes below (>) are taken from the CDR v4 ATBD:
https://nsidc.org/sites/default/files/documents/technical-reference/cdrp-atbd-final.pdf
Includes code repsonsible for creating the `melt_onset_day_cdr_seaice_conc`
Includes code repsonsible for creating the `cdr_melt_onset_day`
variable in final CDR files:
> contains the day of year on which melting sea ice was first detected in each
Expand Down
42 changes: 17 additions & 25 deletions seaice_ecdr/monthly.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
concentration
* `cdr_qa_seaice_conc_monthly`: QA Fields (Weather filters, land
spillover, valid ice mask, spatial and temporal interpolation, melt onset)
* `melt_onset_day_cdr_seaice_conc_monthly`: Melt onset day (Value from the last
* `cdr_melt_onset_day_monthly`: Melt onset day (Value from the last
day of the month)
Notes about CDR v4:
Expand Down Expand Up @@ -404,38 +404,32 @@ def calc_stdv_of_cdr_seaice_conc_monthly(
return stdv_of_cdr_seaice_conc_monthly


def calc_melt_onset_day_cdr_seaice_conc_monthly(
def calc_cdr_melt_onset_day_monthly(
*,
daily_melt_onset_for_month: xr.DataArray,
) -> xr.DataArray:
"""Create the `melt_onset_day_cdr_seaice_conc_monthly` variable."""
# Create `melt_onset_day_cdr_seaice_conc_monthly`. This is the value from
"""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.
melt_onset_day_cdr_seaice_conc_monthly = daily_melt_onset_for_month.sel(
cdr_melt_onset_day_monthly = daily_melt_onset_for_month.sel(
time=daily_melt_onset_for_month.time.max()
)
melt_onset_day_cdr_seaice_conc_monthly.name = (
"melt_onset_day_cdr_seaice_conc_monthly"
)
melt_onset_day_cdr_seaice_conc_monthly = (
melt_onset_day_cdr_seaice_conc_monthly.drop_vars("time")
)
cdr_melt_onset_day_monthly.name = "cdr_melt_onset_day_monthly"
cdr_melt_onset_day_monthly = cdr_melt_onset_day_monthly.drop_vars("time")

melt_onset_day_cdr_seaice_conc_monthly = (
melt_onset_day_cdr_seaice_conc_monthly.assign_attrs(
long_name="Monthly Day of Snow Melt Onset Over Sea Ice",
units="1",
valid_range=(np.ubyte(60), np.ubyte(255)),
grid_mapping="crs",
)
cdr_melt_onset_day_monthly = cdr_melt_onset_day_monthly.assign_attrs(
long_name="Monthly Day of Snow Melt Onset Over Sea Ice",
units="1",
valid_range=(np.ubyte(60), np.ubyte(255)),
grid_mapping="crs",
)
melt_onset_day_cdr_seaice_conc_monthly.encoding = dict(
cdr_melt_onset_day_monthly.encoding = dict(
_FillValue=None,
dtype=np.uint8,
zlib=True,
)

return melt_onset_day_cdr_seaice_conc_monthly
return cdr_melt_onset_day_monthly


def _assign_time_to_monthly_ds(
Expand Down Expand Up @@ -555,12 +549,10 @@ def make_monthly_ds(
# Add monthly melt onset if the hemisphere is north. We don't detect melt in
# the southern hemisphere.
if hemisphere == NORTH:
melt_onset_day_cdr_seaice_conc_monthly = calc_melt_onset_day_cdr_seaice_conc_monthly(
daily_melt_onset_for_month=daily_ds_for_month.melt_onset_day_cdr_seaice_conc,
)
monthly_ds_data_vars["melt_onset_day_cdr_seaice_conc_monthly"] = (
melt_onset_day_cdr_seaice_conc_monthly
cdr_melt_onset_day_monthly = calc_cdr_melt_onset_day_monthly(
daily_melt_onset_for_month=daily_ds_for_month.cdr_melt_onset_day,
)
monthly_ds_data_vars["cdr_melt_onset_day_monthly"] = cdr_melt_onset_day_monthly

monthly_ds = xr.Dataset(
data_vars=monthly_ds_data_vars,
Expand Down
4 changes: 2 additions & 2 deletions seaice_ecdr/set_daily_ncattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ def finalize_cdecdr_ds(

# Note: this is NH only, hence the try/except block
try:
ds["melt_onset_day_cdr_seaice_conc"] = (
ds["cdr_melt_onset_day"] = (
("time", "y", "x"),
ds["melt_onset_day_cdr_seaice_conc"].data,
ds["cdr_melt_onset_day"].data,
{
"standard_name": "status_flag",
"long_name": "Day Of Year of NH Snow Melt Onset On Sea Ice",
Expand Down
10 changes: 5 additions & 5 deletions seaice_ecdr/tests/unit/test_monthly.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
_get_daily_complete_filepaths_for_month,
_platform_id_for_month,
_qa_field_has_flag,
calc_cdr_melt_onset_day_monthly,
calc_cdr_qa_seaice_conc_monthly,
calc_cdr_seaice_conc_monthly,
calc_melt_onset_day_cdr_seaice_conc_monthly,
calc_stdv_of_cdr_seaice_conc_monthly,
calc_surface_type_mask_monthly,
check_min_days_for_valid_month,
Expand Down Expand Up @@ -257,7 +257,7 @@ def _mock_daily_ds_for_month():
raw_nt_seaice_conc=(("x", "time"), _mock_data),
raw_bt_seaice_conc=(("x", "time"), _mock_data),
cdr_qa_seaice_conc=(("x", "time"), _mock_daily_qa_fields),
melt_onset_day_cdr_seaice_conc=(("x", "time"), _mock_daily_melt_onset),
cdr_melt_onset_day=(("x", "time"), _mock_daily_melt_onset),
surface_type_mask=(("x", "time"), _mock_surface_type_mask),
filepaths=(
("time",),
Expand Down Expand Up @@ -440,7 +440,7 @@ def test_calc_stdv_of_cdr_seaice_conc_monthly():
)


def test_calc_melt_onset_day_cdr_seaice_conc_monthly():
def test_calc_cdr_melt_onset_day_monthly():
# time ->
pixel_one = np.array([60, 60, 60])
pixel_two = np.array([np.nan, 200, 200])
Expand All @@ -464,7 +464,7 @@ def test_calc_melt_onset_day_cdr_seaice_conc_monthly():
),
)

actual = calc_melt_onset_day_cdr_seaice_conc_monthly(
actual = calc_cdr_melt_onset_day_monthly(
daily_melt_onset_for_month=mock_daily_melt,
)

Expand Down Expand Up @@ -519,7 +519,7 @@ def test_monthly_ds(monkeypatch, tmpdir):
[
"cdr_seaice_conc_monthly",
"stdv_of_cdr_seaice_conc_monthly",
"melt_onset_day_cdr_seaice_conc_monthly",
"cdr_melt_onset_day_monthly",
"cdr_qa_seaice_conc_monthly",
"crs",
"surface_type_mask",
Expand Down

0 comments on commit e2abd8e

Please sign in to comment.