Skip to content

Commit

Permalink
Merge pull request #2671 from djhoese/bugfix-awips-integers
Browse files Browse the repository at this point in the history
Workaround AWIPS bug not handling integers properly in "awips_tiled" writer
  • Loading branch information
djhoese authored Dec 11, 2023
2 parents d90acf5 + 91b59ca commit ad6af05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion satpy/tests/writer_tests/test_awips_tiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_basic_numbered_1_tile(self, extra_attrs, expected_filename, use_save_da
check_required_properties(unmasked_ds, output_ds)
scale_factor = output_ds["data"].encoding["scale_factor"]
np.testing.assert_allclose(input_data_arr.values, output_ds["data"].data,
atol=scale_factor / 2)
atol=scale_factor * 0.75)

def test_units_length_warning(self, tmp_path):
"""Test long 'units' warnings are raised."""
Expand Down
8 changes: 7 additions & 1 deletion satpy/writers/awips_tiled.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,13 @@ def _get_factor_offset_fill(input_data_arr, vmin, vmax, encoding):
# max value
fills = [2 ** (file_bit_depth - 1) - 1]

mx = (vmax - vmin) / (2 ** bit_depth - 1 - num_fills)
# NOTE: AWIPS is buggy and does not properly handle both
# halves an integers data space. The below code limits
# unsigned integers to the positive half and this seems
# to work better with current AWIPS.
mx = (vmax - vmin) / (2 ** (bit_depth - 1) - 1 - num_fills)
# NOTE: This is what the line should look like if AWIPS wasn't buggy:
# mx = (vmax - vmin) / (2 ** bit_depth - 1 - num_fills)
bx = vmin
if not is_unsigned and not unsigned_in_signed:
bx += 2 ** (bit_depth - 1) * mx
Expand Down

0 comments on commit ad6af05

Please sign in to comment.