Skip to content

Commit

Permalink
Add test for unit conversion
Browse files Browse the repository at this point in the history
Add a test for NinJoTIFF unit conversion.  Currently only tests that %
maps to % correctly, corresponding to the failure in
pytroll#1614
  • Loading branch information
gerritholl committed Mar 24, 2021
1 parent 3623c03 commit d4cc05e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions satpy/tests/writer_tests/test_ninjotiff.py
Expand Up @@ -21,6 +21,7 @@
import unittest
from unittest import mock

import numpy as np
import xarray as xr


Expand Down Expand Up @@ -82,3 +83,16 @@ def test_image(self, iwsi, save_dataset):
assert(nt.save.mock_calls[0][2]['ch_min_measurement_unit']
< nt.save.mock_calls[0][2]['ch_max_measurement_unit'])
assert(ret == nt.save.return_value)

def test_convert_units(self):
"""Test that unit conversions work as expected."""
from ..utils import make_fake_scene
from satpy.writers.ninjotiff import convert_units
# ensure that converting from % to itself does not change the data
sc = make_fake_scene(
{"VIS006": np.arange(25).reshape(5, 5)},
common_attrs={"units": "%"})
ds_in = sc["VIS006"]
ds_out = convert_units(ds_in, "%", "%")
np.testing.assert_array_equal(ds_in, ds_out)
assert ds_in.attrs == ds_out.attrs

0 comments on commit d4cc05e

Please sign in to comment.