def test_get_auto_ticks_vector(self): n = Nansat(self.test_file_gcps) lon, lat = n.get_geolocation_grids() f = Figure(lon) lonTicks = f._get_auto_ticks([28, 29, 30, 100], lon) self.assertEqual(len(lonTicks), 3)
def test_get_auto_ticks_number(self): n = Nansat(self.test_file_gcps) lon, lat = n.get_geolocation_grids() f = Figure(lon) lonTicks = f._get_auto_ticks(5, lon) latTicks = f._get_auto_ticks(5, lat) self.assertEqual(len(lonTicks), 5) n.logger.error(str(lonTicks)) n.logger.error(str(latTicks))
def test_get_tick_index_from_grid(self): ''' Should return indeces of pixel closest to ticks ''' n = Nansat(self.test_file_gcps) lon, lat = n.get_geolocation_grids() f = Figure(lon) lonTicksIdx = f._get_tick_index_from_grid([28.5, 29], lon, 1, lon.shape[1]) latTicksIdx = f._get_tick_index_from_grid([71, 71.5], lat, lat.shape[0], 1) n.logger.error(str(lonTicksIdx)) n.logger.error(str(latTicksIdx))
def nansatFigure(nparr, mask, min, max, dir, fn, cmapName='gray'): f = Figure(nparr) f.process( cmin = min, cmax = max, cmapName = cmapName, mask_array=mask, mask_lut={0:[255,0,0]} ) f.save(os.path.join(dir,fn), transparency=[255,0,0])
def test_add_latlon_grids_list(self): ''' Should create figure with lon/lat gridlines given manually ''' tmpfilename = os.path.join(self.tmp_data_path, 'figure_latlon_grids_list.png') n = Nansat(self.test_file_gcps, mapper=self.default_mapper) b = n[1] lon, lat = n.get_geolocation_grids() f = Figure(b) f.process(clim='hist', lonGrid=lon, latGrid=lat, lonTicks=[28, 29, 30], latTicks=[70.5, 71, 71.5, 73]) f.save(tmpfilename) self.assertEqual(type(f), Figure) self.assertTrue(os.path.exists(tmpfilename))
def test_add_latlon_grids_number(self): ''' Should create figure with lon/lat gridlines given manually ''' tmpfilename = os.path.join(self.tmp_data_path, 'figure_latlon_grids_number.png') n = Nansat(self.test_file_gcps, mapper=self.default_mapper) n.resize(3) b = n[1] lon, lat = n.get_geolocation_grids() f = Figure(b) f.process(cmax=100, lonGrid=lon, latGrid=lat, lonTicks=7, latTicks=7) f.save(tmpfilename) self.assertEqual(type(f), Figure) self.assertTrue(os.path.exists(tmpfilename))
def test_make_transparent_color(self, mock1): f = Figure() img_array = np.array([[1.,2.],[3.,4.]]) f.pilImg = Image.fromarray(img_array) f.reprojMask = np.zeros((2,2)) == 1 f.transparency = [1,1,1] f._make_transparent_color() self.assertTrue((np.array(f.pilImg)[:,:,3] == np.array([[0,255],[255,255]])).all())
def nansatFigure(nparr, mask, min, max, dir, fn, cmapName='gray'): f = Figure(nparr) f.process(cmin=min, cmax=max, cmapName=cmapName, mask_array=mask, mask_lut={0: [255, 0, 0]}) f.save(os.path.join(dir, fn), transparency=[255, 0, 0])
def test_add_latlon_grids_auto(self): ''' Should create figure with lon/lat gridlines spaced automatically ''' tmpfilename = os.path.join(ntd.tmp_data_path, 'figure_latlon_grids_auto.png') n = Nansat(self.test_file_gcps) b = n[1] lon, lat = n.get_geolocation_grids() f = Figure(b) f.process(clim='hist', lonGrid=lon, latGrid=lat) f.save(tmpfilename) self.assertEqual(type(f), Figure) self.assertTrue(os.path.exists(tmpfilename))
def test_init_array(self): f = Figure(np.zeros((10,10))) self.assertEqual(type(f), Figure)
def test_apply_logarithm(self, mock1): f = Figure() f.array = np.ones((1,2,2))*0.1 f.apply_logarithm() self.assertTrue(np.allclose(np.ones((1,2,2))*0.31622777, f.array))
This class consequently create a figrue from 2D numpy array (1band) or an RGB figure from 3D numpy array (3bands) This class has fllolowing methods: estimate min/max, apply logarithmic scaling, convert to uint8, append legend, save to a file ''' # Create a Nansat object (n) n = Nansat(iFileName) # get numpy array from the Nansat object array = n[1] # Create a Figure object (fig) fig = Figure(array) # Set minimum and maximum values fig.process(cmin=10, cmax=60) # Save the figure fig.save(oFileName + '01_clim.png') # Create a Figure object (fig) fig = Figure(array) # Compute min and max valuse from ratio clim = fig.clim_from_histogram(ratio=1.0) # Set cmin and cmax values fig.process(cmin=clim[0], cmax=clim[1]) # Save the figure fig.save(oFileName + '02_clim.png') # Create a Figure object (fig)
def test_apply_logarithm(self, mock1): f = Figure() f.array = np.ones((1, 2, 2)) * 0.1 f.apply_logarithm() self.assertTrue(np.allclose(np.ones((1, 2, 2)) * 0.31622777, f.array))