def test_to_image_2D(self, mock_geoimage): """ Conversion to image """ # 2D data = np.arange(25).reshape((5, 5)) p = dataset.Dataset(data, mode="L", fill_value=0, palette=[0, 1, 2, 3, 4, 5]) to_image(p) np.testing.assert_array_equal(data, mock_geoimage.call_args[0][0][0]) mock_geoimage.reset_mock()
def test_to_image_3D(self, mock_geoimage): """Conversion to image.""" # 3D data = np.arange(75).reshape((3, 5, 5)) p = xr.DataArray(data, dims=['bands', 'y', 'x']) p['bands'] = ['R', 'G', 'B'] to_image(p) np.testing.assert_array_equal(data[0], mock_geoimage.call_args[0][0][0]) np.testing.assert_array_equal(data[1], mock_geoimage.call_args[0][0][1]) np.testing.assert_array_equal(data[2], mock_geoimage.call_args[0][0][2])
def test_to_image_2D(self, mock_geoimage): """ Conversion to image """ # 2D data = np.arange(25).reshape((5, 5)) p = projectable.Projectable(data, mode="L", fill_value=0, palette=[0, 1, 2, 3, 4, 5]) to_image(p) np.testing.assert_array_equal(data, mock_geoimage.call_args[0][0][0]) mock_geoimage.reset_mock()
def test_to_image_3D(self, mock_geoimage): """ Conversion to image """ # 3D data = np.arange(75).reshape((3, 5, 5)) p = dataset.Dataset(data) to_image(p) np.testing.assert_array_equal(data[0], mock_geoimage.call_args[0][0][0]) np.testing.assert_array_equal(data[1], mock_geoimage.call_args[0][0][1]) np.testing.assert_array_equal(data[2], mock_geoimage.call_args[0][0][2])
def test_to_image_3D(self, mock_geoimage): """ Conversion to image """ # 3D data = np.arange(75).reshape((3, 5, 5)) p = projectable.Projectable(data) to_image(p) np.testing.assert_array_equal(data[0], mock_geoimage.call_args[0][0][0]) np.testing.assert_array_equal(data[1], mock_geoimage.call_args[0][0][1]) np.testing.assert_array_equal(data[2], mock_geoimage.call_args[0][0][2])
def test_to_image_2D(self, mock_geoimage): """Conversion to image.""" # 2D data = np.arange(25).reshape((5, 5)) p = xr.DataArray(data, attrs=dict(mode="L", fill_value=0, palette=[0, 1, 2, 3, 4, 5]), dims=['y', 'x']) to_image(p) np.testing.assert_array_equal( data, mock_geoimage.call_args[0][0].values) mock_geoimage.reset_mock()
def get_image(self, sector_def): local = self.scene.resample(sector_def) img = to_image(local[self.product].squeeze()) self.enhance_image(img) img = add_overlay(img, area=sector_def, coast_dir=COAST_DIR, color=GOLDENROD, fill_value=0) pilimg = img.pil_image() self.decorate_pilimg(pilimg) return pilimg
global_scene.load([10.8]) area = "EuropeCanaryS95" local_scene = global_scene.resample(area) import numpy as np from satpy.composites import BWCompositor from satpy.enhancements import colorize from satpy.writers import to_image arr = np.array([[0, 0, 0], [255, 0, 0]]) np.save("/tmp/binary_colormap.npy", arr) compositor = BWCompositor("test", standard_name="colorized_ir_clouds") composite = compositor((local_scene[10.8], )) img = to_image(composite) kwargs = { "palettes": [{ "filename": "/tmp/binary_colormap.npy", "min_value": 223.15, "max_value": 303.15 }] } kwargs = { "palettes": [{ "colors": "spectral", "min_value": 223.15, "max_value": 303.15 }]
maia_scene = Scene(reader='maia', filenames=[fnmaia]) print(maia_scene.available_dataset_ids()) maia_scene.load(["CloudType", "ct", "cma", "cma_conf", 'opaq_cloud', "CloudTopPres", "CloudTopTemp", "Alt_surface"]) # CloudType is a bit field containing the actual "ct" with values # from 0 to 20 which can be interpreted according to the cpool colormap # "ct" can be display in black and white: maia_scene.show("ct") # but it is better to palettize the image: # step 1: creation of the palette mycolors = [] for i in range(21): mycolors.append(hex_to_rgb(cpool[i])) arr = np.array(mycolors) np.save("/tmp/binary_maia_ct_colormap.npy", arr) # step2: creation of the composite compositor = BWCompositor("test", standard_name="maia_ct") composite = compositor((maia_scene["ct"],)) kwargs = {"palettes": [ {"filename": "/tmp/binary_maia_ct_colormap.npy", "min_value": 0, "max_value": 20}]} img = to_image(composite) palettize(img, ** kwargs) img.show() img.pil_save("ct.png")