Skip to content

Commit

Permalink
fix : Makes sure that the apply_fill_value method is not applyed if t…
Browse files Browse the repository at this point in the history
…he _FillValue is not into the attributes
  • Loading branch information
ClementLaplace committed Nov 22, 2024
1 parent b00303e commit e9732c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
5 changes: 3 additions & 2 deletions satpy/readers/li_base_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ def get_measured_variable(self, var_paths, fill_value=np.nan):
# Also handle fill value here (but only if it is not None, so that we can still bypass this
# step if needed)
arr = self.apply_fill_value(arr, fill_value)

return arr

def apply_fill_value(self, arr, fill_value):
"""Apply fill values, unless it is None."""
"""Apply fill values, unless it is None and when _FillValue is provided."""
if arr.attrs.get("_FillValue") is None:
return arr
if fill_value is not None:
if np.isnan(fill_value):
fill_value = np.float32(np.nan)
Expand Down
5 changes: 0 additions & 5 deletions satpy/tests/reader_tests/test_li_l2_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,6 @@ def test_coords_generation(self, filetype_infos):
products = ["li_l2_af_nc",
"li_l2_afr_nc",
"li_l2_afa_nc"]

for prod in products:
handler = LIL2NCFileHandler("filename", {}, extract_filetype_info(filetype_infos, prod))

Expand All @@ -611,7 +610,6 @@ def test_coords_generation(self, filetype_infos):

elevation = handler.get_measured_variable(handler.swath_coordinates["elevation"])
elevation = handler.apply_use_rescaling(elevation)

# Initialize proj_dict
proj_var = handler.swath_coordinates["projection"]
geos_proj = handler.get_measured_variable(proj_var, fill_value=None)
Expand All @@ -634,9 +632,6 @@ def test_coords_generation(self, filetype_infos):
elevation_vals = elevation.values * point_height
azimuth_vals *= -1
lon_ref, lat_ref = projection(azimuth_vals, elevation_vals, inverse=True)
# Convert to float32:
lon_ref = lon_ref.astype(np.float32)
lat_ref = lat_ref.astype(np.float32)

handler.generate_coords_from_scan_angles()
lon = handler.internal_variables["longitude"].values
Expand Down

0 comments on commit e9732c8

Please sign in to comment.