Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround AWIPS bug not handling integers properly in "awips_tiled" writer #2671

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading