Skip to content

Commit

Permalink
Merge pull request #2711 from djhoese/feat-mirs-noaa21-coeff-handling
Browse files Browse the repository at this point in the history
Add support for NOAA-21 in MiRS limb correction
  • Loading branch information
djhoese authored Jan 5, 2024
2 parents d7f0af6 + fb21a71 commit afb4049
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 156 deletions.
15 changes: 9 additions & 6 deletions satpy/readers/mirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ def force_time(self, key):
def _get_coeff_filenames(self):
"""Retrieve necessary files for coefficients if needed."""
coeff_fn = {"sea": None, "land": None}
if self.platform_name == "noaa-20":
coeff_fn["land"] = retrieve("readers/limbcoef_atmsland_noaa20.txt")
coeff_fn["sea"] = retrieve("readers/limbcoef_atmssea_noaa20.txt")
if self.platform_name.startswith("noaa"):
suffix = self.platform_name[-2:]
coeff_fn["land"] = retrieve(f"readers/limbcoef_atmsland_noaa{suffix}.txt")
coeff_fn["sea"] = retrieve(f"readers/limbcoef_atmssea_noaa{suffix}.txt")
if self.platform_name == "npp":
coeff_fn["land"] = retrieve("readers/limbcoef_atmsland_snpp.txt")
coeff_fn["sea"] = retrieve("readers/limbcoef_atmssea_snpp.txt")
Expand Down Expand Up @@ -335,19 +336,21 @@ def _nan_for_dtype(data_arr_dtype):
return np.timedelta64("NaT")
if np.issubdtype(data_arr_dtype, np.datetime64):
return np.datetime64("NaT")
return np.nan
return np.float32(np.nan)

@staticmethod
def _scale_data(data_arr, scale_factor, add_offset):
"""Scale data, if needed."""
scaling_needed = not (scale_factor == 1 and add_offset == 0)
if scaling_needed:
data_arr = data_arr * scale_factor + add_offset
data_arr = data_arr * np.float32(scale_factor) + np.float32(add_offset)
return data_arr

def _fill_data(self, data_arr, fill_value, scale_factor, add_offset):
"""Fill missing data with NaN."""
if fill_value is not None:
# NOTE: Sfc_type and other category products are not detected or handled properly
# and will be converted from integers to 32-bit floats in this step
fill_value = self._scale_data(fill_value, scale_factor, add_offset)
fill_out = self._nan_for_dtype(data_arr.dtype)
data_arr = data_arr.where(data_arr != fill_value, fill_out)
Expand All @@ -372,7 +375,7 @@ def apply_attributes(self, data, ds_info):
"""
try:
global_attr_fill = self.nc.missing_value
global_attr_fill = self.nc.attrs["missing_value"]
except AttributeError:
global_attr_fill = 1.0

Expand Down
Loading

0 comments on commit afb4049

Please sign in to comment.