def test_write_and_read_file_P(test_image_small_arctic_P, tmp_path): """Test writing and reading P image.""" import rasterio from trollimage.colormap import Colormap from satpy.writers.ninjogeotiff import NinJoGeoTIFFWriter fn = os.fspath(tmp_path / "test.tif") ngtw = NinJoGeoTIFFWriter() ngtw.save_image( test_image_small_arctic_P, filename=fn, fill_value=255, PhysicUnit="N/A", PhysicValue="N/A", SatelliteNameID=6400014, ChannelID=900015, DataType="PPRN", DataSource="dowsing rod", keep_palette=True, cmap=Colormap(*enumerate(zip(*([np.linspace(0, 1, 256)] * 3))))) src = rasterio.open(fn) assert len(src.indexes) == 1 # mode P assert src.colorinterp[0] == rasterio.enums.ColorInterp.palette tgs = src.tags() assert tgs["ninjo_FileName"] == fn assert tgs["ninjo_DataSource"] == "dowsing rod"
def test_write_and_read_file_LA(test_image_latlon, tmp_path): """Test writing and reading LA image.""" import rasterio from satpy.writers.ninjogeotiff import NinJoGeoTIFFWriter fn = os.fspath(tmp_path / "test.tif") ngtw = NinJoGeoTIFFWriter() ngtw.save_dataset( test_image_latlon.data, filename=fn, fill_value=None, # to make it LA PhysicUnit="%", PhysicValue="Reflectance", SatelliteNameID=6400014, ChannelID=900015, DataType="GORN", DataSource="dowsing rod") src = rasterio.open(fn) assert len(src.indexes) == 2 # mode LA tgs = src.tags() assert tgs["ninjo_FileName"] == fn assert tgs["ninjo_DataSource"] == "dowsing rod" np.testing.assert_allclose(float(tgs["ninjo_Gradient"]), 0.30816176470588236) np.testing.assert_allclose(float(tgs["ninjo_AxisIntercept"]), -49.603125) assert tgs["ninjo_PhysicValue"] == "Reflectance" assert tgs["ninjo_TransparentPixel"] == "-1" # meaning not set
def test_write_and_read_file(test_image_small_mid_atlantic_L, tmp_path): """Test that it writes a GeoTIFF with the appropriate NinJo-tags.""" import rasterio from satpy.writers.ninjogeotiff import NinJoGeoTIFFWriter fn = os.fspath(tmp_path / "test.tif") ngtw = NinJoGeoTIFFWriter() ngtw.save_dataset(test_image_small_mid_atlantic_L.data, filename=fn, fill_value=0, blockxsize=128, blockysize=128, compress="lzw", predictor=2, PhysicUnit="C", PhysicValue="Temperature", SatelliteNameID=6400014, ChannelID=900015, DataType="GORN", DataSource="dowsing rod") src = rasterio.open(fn) tgs = src.tags() assert tgs["ninjo_FileName"] == fn assert tgs["ninjo_DataSource"] == "dowsing rod" np.testing.assert_allclose(float(tgs["ninjo_Gradient"]), 0.4653780307919959) np.testing.assert_allclose(float(tgs["ninjo_AxisIntercept"]), -79.86837954904149)
def test_write_and_read_file_RGB(test_image_large_asia_RGB, tmp_path): """Test writing and reading RGB.""" import rasterio from satpy.writers.ninjogeotiff import NinJoGeoTIFFWriter fn = os.fspath(tmp_path / "test.tif") ngtw = NinJoGeoTIFFWriter() ngtw.save_dataset(test_image_large_asia_RGB.data, filename=fn, fill_value=0, PhysicUnit="N/A", PhysicValue="N/A", SatelliteNameID=6400014, ChannelID=900015, DataType="GORN", DataSource="dowsing rod") src = rasterio.open(fn) tgs = src.tags() assert tgs["ninjo_FileName"] == fn assert tgs["ninjo_DataSource"] == "dowsing rod" assert "ninjo_Gradient" not in tgs.keys() assert "ninjo_AxisIntercept" not in tgs.keys() assert tgs["ninjo_PhysicValue"] == "N/A"
def test_write_and_read_file_units(test_image_small_mid_atlantic_K_L, tmp_path, caplog): """Test that it writes a GeoTIFF with the appropriate NinJo-tags and units.""" import rasterio from satpy.writers.ninjogeotiff import NinJoGeoTIFFWriter fn = os.fspath(tmp_path / "test.tif") ngtw = NinJoGeoTIFFWriter() with caplog.at_level(logging.DEBUG): ngtw.save_dataset(test_image_small_mid_atlantic_K_L.data, filename=fn, fill_value=0, blockxsize=128, blockysize=128, compress="lzw", predictor=2, PhysicUnit="C", PhysicValue="Temperature", SatelliteNameID=6400014, ChannelID=900015, DataType="GORN", DataSource="dowsing rod") assert "Adding offset for K → °C conversion" in caplog.text # a better test would be to check that the attributes haven't changed at # all, but that currently fails due to # https://github.com/pytroll/satpy/issues/2022 assert test_image_small_mid_atlantic_K_L.data.attrs["enhancement_history"][ 0] != { "scale": 1, "offset": 273.15 } src = rasterio.open(fn) tgs = src.tags() assert tgs["ninjo_FileName"] == fn assert tgs["ninjo_DataSource"] == "dowsing rod" np.testing.assert_allclose(float(tgs["ninjo_Gradient"]), 0.465379, rtol=1e-5) np.testing.assert_allclose(float(tgs["ninjo_AxisIntercept"]), -79.86838) fn2 = os.fspath(tmp_path / "test2.tif") with caplog.at_level(logging.WARNING): ngtw.save_dataset(test_image_small_mid_atlantic_K_L.data, filename=fn2, fill_value=0, blockxsize=128, blockysize=128, compress="lzw", predictor=2, PhysicUnit="F", PhysicValue="Temperature", SatelliteNameID=6400014, ChannelID=900015, DataType="GORN", DataSource="dowsing rod") assert ("Writing F to ninjogeotiff headers, but " "data attributes have unit K. " "No conversion applied.") in caplog.text