def test_export_gcps_complex_to_netcdf(self): ''' Should export file with GCPs and write correct complex bands''' n0 = Nansat(self.test_file_gcps, logLevel=40) b0 = n0['L_469'] n1 = Nansat(domain=n0) n1.add_band(b0.astype('complex64'), parameters={'name': 'L_469'}) tmpfilename = os.path.join(ntd.tmp_data_path, 'nansat_export_gcps_complex.nc') n1.export(tmpfilename) ncf = netcdf_file(tmpfilename) self.assertTrue(os.path.exists(tmpfilename)) self.assertTrue('GCPX' in ncf.variables) self.assertTrue('GCPY' in ncf.variables) self.assertTrue('GCPPixel' in ncf.variables) self.assertTrue('GCPLine' in ncf.variables) n2 = Nansat(tmpfilename) b2 = n2['L_469'] np.testing.assert_allclose(b0, b2) lon0, lat0 = n0.get_geolocation_grids() lon2, lat2 = n1.get_geolocation_grids() np.testing.assert_allclose(lon0, lon2) np.testing.assert_allclose(lat0, lat2)
def test_geolocation_of_exportedNC_vs_original(self): """ Lon/lat in original and exported file should coincide """ orig = Nansat(self.test_file_gcps, mapper=self.default_mapper) orig.export(self.tmp_filename) copy = Nansat(self.tmp_filename, mapper=self.default_mapper) lon0, lat0 = orig.get_geolocation_grids() lon1, lat1 = copy.get_geolocation_grids() np.testing.assert_allclose(lon0, lon1) np.testing.assert_allclose(lat0, lat1)
def geolocation_of_exportedNC_vs_original(self, file): orig = Nansat(file) testFile = 'test.nc' orig.export(testFile) copy = Nansat(testFile) lon0, lat0 = orig.get_geolocation_grids() lon1, lat1 = copy.get_geolocation_grids() np.testing.assert_allclose(lon0, lon1) np.testing.assert_allclose(lat0, lat1) os.unlink(ncfile)
def geolocation_of_exportedNC_vs_original(self, file): orig = Nansat(file) testFile = "test.nc" orig.export(testFile) copy = Nansat(testFile) lon0, lat0 = orig.get_geolocation_grids() lon1, lat1 = copy.get_geolocation_grids() np.testing.assert_allclose(lon0, lon1) np.testing.assert_allclose(lat0, lat1) os.unlink(ncfile)
def test_geolocation_of_exportedNC_vs_original(self): ''' Lon/lat in original and exported file should coincide ''' orig = Nansat(self.test_file_gcps) tmpfilename = os.path.join(ntd.tmp_data_path, 'nansat_export_gcps.nc') orig.export(tmpfilename) copy = Nansat(tmpfilename) lon0, lat0 = orig.get_geolocation_grids() lon1, lat1 = copy.get_geolocation_grids() np.testing.assert_allclose(lon0, lon1) np.testing.assert_allclose(lat0, lat1)
def test_geolocation_of_exportedNC_vs_original(self): ''' Lon/lat in original and exported file should coincide ''' orig = Nansat(self.test_file_gcps) orig.export(self.tmpfilename) copy = Nansat(self.tmpfilename) lon0, lat0 = orig.get_geolocation_grids() lon1, lat1 = copy.get_geolocation_grids() np.testing.assert_allclose(lon0, lon1) np.testing.assert_allclose(lat0, lat1) os.unlink(self.tmpfilename)
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_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 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_export_gcps_to_netcdf(self): ''' Should export file with GCPs and write correct bands''' n0 = Nansat(self.test_file_gcps, logLevel=40) tmpfilename = os.path.join(ntd.tmp_data_path, 'nansat_export_gcps.nc') n0.export(tmpfilename) ncf = netcdf_file(tmpfilename) self.assertTrue(os.path.exists(tmpfilename)) self.assertTrue('GCPX' in ncf.variables) self.assertTrue('GCPY' in ncf.variables) self.assertTrue('GCPPixel' in ncf.variables) self.assertTrue('GCPLine' in ncf.variables) n1 = Nansat(tmpfilename) b0 = n0['L_469'] b1 = n1['L_469'] np.testing.assert_allclose(b0, b1) lon0, lat0 = n0.get_geolocation_grids() lon1, lat1 = n1.get_geolocation_grids() np.testing.assert_allclose(lon0, lon1) np.testing.assert_allclose(lat0, lat1)
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_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_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_reproject_pure_geolocation(self): n0 = Nansat(self.test_file_gcps) b0 = n0[1] lon0, lat0 = n0.get_geolocation_grids() d1 = Domain.from_lonlat(lon=lon0, lat=lat0) d2 = Domain.from_lonlat(lon=lon0, lat=lat0, add_gcps=False) d3 = Domain(NSR().wkt, '-te 27 70 31 72 -ts 500 500') n1 = Nansat.from_domain(d1, b0) n2 = Nansat.from_domain(d2, b0) n1.reproject(d3) n2.reproject(d3) b1 = n1[1] b2 = n2[1] self.assertTrue(np.allclose(b1, b2))
# get array with watermask (landmask) b # it must be done after reprojection! # 1. Get Nansat object with watermask # 2. Get array from Nansat object. 0 - land, 1 - water #wm = n.watermask(mod44path='/media/magDesk/media/SOLabNFS/store/auxdata/coastline/mod44w/') wm = n.watermask(mod44path='/media/data/data/auxdata/coastline/mod44w/') wmArray = wm[1] n.write_figure(oFileName + '_proj.png', clim='hist', bands=[3], \ mask_array=wmArray, mask_lut={0: [204, 153, 25]}) # 5. # write figure with lat/lon grid # 1. Get lat/lon arrays from Nansat object (may take some time) # 2. Make figure with lat/lon grids lonGrid, latGrid = n.get_geolocation_grids() n.write_figure(oFileName + '_latlon.png', bands=[1], \ latGrid=latGrid, lonGrid=lonGrid, \ latlonGridSpacing=10, latlonLabels=10, \ mask_array=wmArray, mask_lut={0: [0, 0, 0]}) # make KML file with image borders (to be opened in Googe Earth) n.write_kml(kmlFileName=oFileName + '_preview.kml') # make image with map of the file location n.write_map(oFileName + '_map.png') # Reprojected image into stereographic projection # 1. Cancel previous reprojection # 2. Get corners of the image # 3. Create Domain with stereographic projection, corner coordinates and resolution 1000m
fig.save(oFileName + '03_title.png') # Create a Figure object (fig) fig = Figure(array) # add logo to image to the lower left corner # (make sure file is in the current folder) fig.process(cmin=10, cmax=60, logoFileName='nansat_logo_s.png', logoLocation=[10, -35], logoSize=[20, 20], legend=True, LEGEND_HEIGHT=0.3) # Save the figure fig.save(oFileName + '04_logo.png') # Create a Figure object (fig) fig = Figure(array) # Get lat/lon arrays from Nansat object (may take some time) lonGrid, latGrid = n.get_geolocation_grids() # Make figure with lat/lon grids fig.process(cmin=10, cmax=60, latGrid=latGrid, lonGrid=lonGrid, latlonGridSpacing=10, latlonLabels=10) # save the fig fig.save(oFileName + '05_latlon.png', ) # Create a Figure object (fig) fig = Figure(array) # Get Nansat object with watermask wm = n.watermask() # Get array from Nansat object. 0 - land, 1 - water wmArray = wm[1] # Compute min and max valuse from ratio clim = fig.clim_from_histogram(ratio=1.0) # Make figure with land overlay (gray) and apply brightness gamma correction