コード例 #1
0
    def test_convert_units_other(self):
        """Test that other unit conversions are not implemented."""
        # test arbitrary different conversion
        from ..utils import make_fake_scene
        from satpy.writers.ninjotiff import convert_units
        sc = make_fake_scene(
            {"rain_rate": np.arange(25, dtype="f8").reshape(5, 5)},
            common_attrs={"units": "millimeter/hour"})

        ds_in = sc["rain_rate"]
        with pytest.raises(NotImplementedError):
            convert_units(ds_in, "millimeter/hour", "m/s")
コード例 #2
0
 def test_convert_units_self(self):
     """Test that unit conversion to themselves do nothing."""
     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, dtype="f4").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
コード例 #3
0
 def test_convert_units_temp(self):
     """Test that temperature unit conversions works as expected."""
     # test converting between °C and K
     from ..utils import make_fake_scene
     from satpy.writers.ninjotiff import convert_units
     sc = make_fake_scene(
         {"IR108": np.arange(25, dtype="f4").reshape(5, 5)},
         common_attrs={"units": "K"})
     ds_in = sc["IR108"]
     for out_unit in ("C", "CELSIUS"):
         ds_out = convert_units(ds_in, "K", out_unit)
         np.testing.assert_array_almost_equal(ds_in + 273.15, ds_out)
         assert ds_in.attrs != ds_out.attrs
         assert ds_out.attrs["units"] == out_unit
     # test that keys aren't lost
     assert ds_out.attrs.keys() - ds_in.attrs.keys() <= {"units"}
     assert ds_in.attrs.keys() <= ds_out.attrs.keys()