Skip to content

Commit

Permalink
Merge pull request #2858 from djhoese/bugfix-awipstiled-xarray-compat
Browse files Browse the repository at this point in the history
Fix default AWIPS tiled _FillValue of -1 for newer versions of xarray
  • Loading branch information
mraspaud authored Jul 19, 2024
2 parents f60a579 + b62f10b commit 2e2418f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions satpy/writers/awips_tiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def _get_factor_offset_fill(input_data_arr, vmin, vmax, encoding):
fills = [2 ** file_bit_depth - 1]
elif unsigned_in_signed:
# max unsigned value is -1 as a signed int
fills = [-1]
fills = [dtype.type(-1)]
else:
# max value
fills = [2 ** (file_bit_depth - 1) - 1]
Expand Down Expand Up @@ -1063,12 +1063,10 @@ def apply_tile_coord_encoding(self, new_ds, xy_factors):
new_ds.coords["x"].encoding["dtype"] = "int16"
new_ds.coords["x"].encoding["scale_factor"] = np.float64(xy_factors.mx)
new_ds.coords["x"].encoding["add_offset"] = np.float64(xy_factors.bx)
new_ds.coords["x"].encoding["_FillValue"] = -1
if "y" in new_ds.coords:
new_ds.coords["y"].encoding["dtype"] = "int16"
new_ds.coords["y"].encoding["scale_factor"] = np.float64(xy_factors.my)
new_ds.coords["y"].encoding["add_offset"] = np.float64(xy_factors.by)
new_ds.coords["y"].encoding["_FillValue"] = -1
return new_ds

def apply_tile_info(self, new_ds, tile_info):
Expand Down Expand Up @@ -1102,7 +1100,7 @@ def apply_misc_metadata(self, new_ds, sector_id=None, creator=None, creation_tim
if creator is None:
creator = "Satpy Version {} - AWIPS Tiled Writer".format(__version__)
if creation_time is None:
creation_time = dt.datetime.utcnow()
creation_time = dt.datetime.now(dt.timezone.utc)

self._add_sector_id_global(new_ds, sector_id)
new_ds.attrs["Conventions"] = "CF-1.7"
Expand Down Expand Up @@ -1598,7 +1596,7 @@ def save_datasets(self, datasets, sector_id=None, # noqa: D417
area_data_arrs = self._group_by_area(datasets)
datasets_to_save = []
output_filenames = []
creation_time = dt.datetime.utcnow()
creation_time = dt.datetime.now(dt.timezone.utc)
area_tile_data_gen = self._iter_area_tile_info_and_datasets(
area_data_arrs, template, lettered_grid, sector_id, num_subtiles,
tile_size, tile_count, use_sector_reference)
Expand Down

0 comments on commit 2e2418f

Please sign in to comment.