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

Platform specific nt gradient thresholds #46

Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pm_icecon/bt/xfer_tbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# RSS-specific Tb transformation values
# Each key is a platform name. This mapps to another dictionary of Tb channel
# names w/ maps to a tuple representing a slope and offset.
rss_tb_xfers = dict(
rss_tb_xfers: dict[str, dict[str, tuple[float, float]]] = dict(
n07=dict(
v37=(0.97901150, 6.6694386),
h37=(1.0065762, 4.6935520),
Expand Down
13 changes: 4 additions & 9 deletions pm_icecon/nt/params/amsr2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
from pm_tb_data._types import Hemisphere

from pm_icecon.nt._types import NasateamGradientRatioThresholds
from pm_icecon.nt.params.goddard_rss import (
RSS_F17_NORTH_GRADIENT_THRESHOLDS,
RSS_F17_SOUTH_GRADIENT_THRESHOLDS,
)
from pm_icecon.nt.params.gradient_thresholds import get_cdr_rss_thresholds
from pm_icecon.nt.tiepoints import NasateamTiePoints, get_tiepoints


Expand All @@ -26,12 +23,10 @@ def get_amsr2_params(
nt_tiepoints = get_tiepoints(satellite="u2", hemisphere=hemisphere)

# Gradient thresholds
nt_gradient_thresholds = (
RSS_F17_NORTH_GRADIENT_THRESHOLDS
if hemisphere == "north"
else RSS_F17_SOUTH_GRADIENT_THRESHOLDS
nt_gradient_thresholds = get_cdr_rss_thresholds(
hemisphere=hemisphere, platform="f17"
)
logger.info("NT gradient threshold values for AMSR2 are copied from f17_final")
logger.info("NT gradient threshold values for AMSR2 are copied from f17")

return NasateamParams(
tiepoints=nt_tiepoints,
Expand Down
24 changes: 0 additions & 24 deletions pm_icecon/nt/params/goddard_rss.py

This file was deleted.

101 changes: 101 additions & 0 deletions pm_icecon/nt/params/gradient_thresholds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""Gradient thresholds for the nasateam weather filter.
"""
from pm_tb_data._types import NORTH, SOUTH

from pm_icecon.nt._types import NasateamGradientRatioThresholds
from pm_icecon.errors import UnexpectedSatelliteError

# These thresholds defined specifically for the CDR. These differ from thoes
# defined by Goddard.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These gradient thresholds are specific to the CDR, so I added a note here and made the variable and function names explicit.

# RSS is Remote Sensing Systems. Data from RSS is used for the Final CDR
# (g02202)
CDR_RSS_THRESHOLDS_NORTH = dict(
f17=NasateamGradientRatioThresholds(
{
"3719": 0.050,
"2219": 0.045,
}
),
f13=NasateamGradientRatioThresholds(
{
"3719": 0.050,
"2219": 0.045,
}
),
f11=NasateamGradientRatioThresholds(
{
"3719": 0.050,
"2219": 0.045,
}
),
f08=NasateamGradientRatioThresholds(
{
"3719": 0.050,
"2219": 0.045,
}
),
n07=NasateamGradientRatioThresholds(
{
"3719": 0.07,
# This value ensures the threshold is never met for SMMR.
# TODO: Better way to express this? `None`?
"2219": 9999.9,
}
),
)

CDR_RSS_THRESHOLDS_SOUTH = dict(
f17=NasateamGradientRatioThresholds(
{
"3719": 0.057,
"2219": 0.045,
}
),
f13=NasateamGradientRatioThresholds(
{
"3719": 0.050,
"2219": 0.045,
}
),
f11=NasateamGradientRatioThresholds(
{
"3719": 0.050,
"2219": 0.045,
}
),
f08=NasateamGradientRatioThresholds(
{
"3719": 0.050,
"2219": 0.045,
}
),
n07=NasateamGradientRatioThresholds(
{
"3719": 0.076,
# This value ensures the threshold is never met for SMMR.
# TODO: Better way to express this? `None`?
"2219": 9999.9,
}
),
)


def get_cdr_rss_thresholds(
*, hemisphere, platform: str
) -> NasateamGradientRatioThresholds:
"""Get Gradient thresholds for the CDR.

Note that goddard specific thresholds are defined and used in the `test_nt`
regression test file.
"""
rss_thresholds = {
NORTH: CDR_RSS_THRESHOLDS_NORTH,
SOUTH: CDR_RSS_THRESHOLDS_SOUTH,
}[hemisphere]
if platform not in rss_thresholds.keys():
raise UnexpectedSatelliteError(
f"No {hemisphere[0].upper()}H thresholds defined for {platform=}."
)
platform = platform.lower()

return rss_thresholds[platform]
13 changes: 3 additions & 10 deletions pm_icecon/nt/params/nsidc0001.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
"""Parameters for use with NSIDC-0001 data."""

from loguru import logger
from pm_tb_data._types import Hemisphere
from pm_icecon._types import ValidSatellites

from pm_icecon.nt.params.goddard_rss import (
RSS_F17_NORTH_GRADIENT_THRESHOLDS,
RSS_F17_SOUTH_GRADIENT_THRESHOLDS,
)
from pm_icecon.nt.params.gradient_thresholds import get_cdr_rss_thresholds
from pm_icecon.nt.tiepoints import get_tiepoints
from pm_icecon.nt.params.amsr2 import NasateamParams

Expand All @@ -20,12 +16,9 @@ def get_0001_nt_params(
nt_tiepoints = get_tiepoints(satellite=platform, hemisphere=hemisphere)

# Gradient thresholds
nt_gradient_thresholds = (
RSS_F17_NORTH_GRADIENT_THRESHOLDS
if hemisphere == "north"
else RSS_F17_SOUTH_GRADIENT_THRESHOLDS
nt_gradient_thresholds = get_cdr_rss_thresholds(
hemisphere=hemisphere, platform=platform
)
logger.info("NT gradient threshold values for {platform} are copied from f17_final")

return NasateamParams(
tiepoints=nt_tiepoints,
Expand Down
25 changes: 19 additions & 6 deletions pm_icecon/tests/regression/test_nt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@
from pm_icecon.tests.regression import CDR_TESTDATA_DIR
from pm_icecon.interpolation import spatial_interp_tbs
from pm_icecon.nt.compute_nt_ic import goddard_nasateam
from pm_icecon.nt.params.goddard_rss import (
RSS_F17_NORTH_GRADIENT_THRESHOLDS,
RSS_F17_SOUTH_GRADIENT_THRESHOLDS,
)
from pm_icecon.nt.tiepoints import get_tiepoints
from pm_icecon.util import get_ps25_grid_shape
from pm_icecon.nt._types import NasateamGradientRatioThresholds


RSS_GODDARD_F17_NORTH_GRADIENT_THRESHOLDS = NasateamGradientRatioThresholds(
{
"3719": 0.050,
"2219": 0.045,
}
)


RSS_GODDARD_F17_SOUTH_GRADIENT_THRESHOLDS = NasateamGradientRatioThresholds(
Copy link
Contributor Author

@trey-stafford trey-stafford Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values from Goddard differ from the values we use for the CDR. Regression tests fail if we use the CDR values.

{
"3719": 0.053,
"2219": 0.045,
}
)


def _get_ps25_sst_mask(
Expand Down Expand Up @@ -110,9 +123,9 @@ def _get_minic(*, hemisphere: Hemisphere):
minic=_get_minic(hemisphere=hemisphere),
invalid_ice_mask=invalid_ice_mask,
gradient_thresholds=(
RSS_F17_NORTH_GRADIENT_THRESHOLDS
RSS_GODDARD_F17_NORTH_GRADIENT_THRESHOLDS
if hemisphere == "north"
else RSS_F17_SOUTH_GRADIENT_THRESHOLDS
else RSS_GODDARD_F17_SOUTH_GRADIENT_THRESHOLDS
),
tiepoints=get_tiepoints(satellite="17_final", hemisphere=hemisphere),
)
Expand Down
Loading