Skip to content

Commit

Permalink
Merge pull request #36 from nsidc/handle_lineslopecheck
Browse files Browse the repository at this point in the history
Handle lineslopecheck
  • Loading branch information
trey-stafford authored Jan 3, 2024
2 parents a8b66e3 + de17e3b commit 1979da3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
that define e.g., valid ice masks. This code was very specific to NSIDC's
internal infrastructure and unpublished data. It is now the responsibility of
other programs utlizing this library to provide masks, input TBs, etc.
* Replace `BootstrapAlgError` in `get_linfit` with a logged warning. Use default
slope and offset values instead of failing when there are less than 125 valid
pixels.

# v0.2.0

Expand Down
28 changes: 18 additions & 10 deletions pm_icecon/bt/compute_bt_ic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
WeatherFilterParamsForSeason,
)
from pm_icecon.constants import DEFAULT_FLAG_VALUES
from pm_icecon.errors import BootstrapAlgError, UnexpectedSatelliteError
from pm_icecon.errors import UnexpectedSatelliteError


# TODO: this function very similar to `get_invalid_tbs_mask` in `compute_nt_ic`.
Expand Down Expand Up @@ -228,24 +228,32 @@ def get_linfit(

num_valid_pixels = is_valid.sum()
if num_valid_pixels <= 125:
raise BootstrapAlgError(f"Insufficient valid linfit points: {num_valid_pixels}")
bt_error_message = f"""
Insufficient valid linfit points: {num_valid_pixels}
"""
logger.warning(f"Possible BootstrapAlgError: {bt_error_message}")

slopeb, intrca = np.polyfit(
x=tbx[is_valid],
y=tby[is_valid],
deg=1,
)
slopeb = lnline["slope"]
intrca = lnline["offset"]
else:
slopeb, intrca = np.polyfit(
x=tbx[is_valid],
y=tby[is_valid],
deg=1,
)

if slopeb > max_slope:
raise BootstrapAlgError(
f"Line slope check failed. {slopeb=} > {max_slope=}. "
bt_error_message = f"""
Line slope check failed. {slopeb=} > {max_slope=}. "
"This may need some additional investigation! The code from Goddard would"
" fall back on defaults defined by the `iceline` parameter if this"
" condition was met. However, it is probably better to investigate"
" this situation and determine what to do on a case-by-case basis"
' rather than "silently" fall back on some default values. We are not'
" sure how the default values of (`iceline`) were originally chosen."
)
"""
logger.warning(f"Possible BootstrapAlgError:{bt_error_message}")
slopeb = max_slope

fit_off = intrca + add
fit_slp = slopeb
Expand Down

0 comments on commit 1979da3

Please sign in to comment.