def test_get_no_transect_interactive(self): import matplotlib.pyplot as plt plt.ion() n1 = Nansat(self.test_file_gcps, logLevel=40) noneResult = n1.get_transect() self.assertEqual(noneResult, None) plt.ioff()
def test_get_transect_false(self): n1 = Nansat(self.test_file_gcps, logLevel=40) v, xy, pl = n1.get_transect([(28.31299128, 70.93709219), (28.93691525, 70.69646524)]) self.assertEqual(len(v['1:L_645']), 2) self.assertEqual(len(v['1:L_645']), len(xy)) self.assertEqual(len(v['1:L_645']), len(pl)) self.assertEqual(type(xy['shape0']['latitude']), np.ndarray) self.assertEqual(type(pl['shape0'][0]), np.ndarray)
def test_get_transect_wrong_band(self): n1 = Nansat(self.test_file_gcps, logLevel=40) t = n1.get_transect([[0, 28.31299128], [0, 70.93709219]], [10]) self.assertTrue('line' in t.dtype.fields) self.assertTrue('pixel' in t.dtype.fields) self.assertTrue('lat' in t.dtype.fields) self.assertTrue('lon' in t.dtype.fields) self.assertEqual(type(t['lat']), np.ndarray) self.assertEqual(type(t['lon']), np.ndarray)
def test_get_transect_wrong_band(self): n1 = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper) t = n1.get_transect([[0, 28.31299128], [0, 70.93709219]], [10]) self.assertTrue('line' in t.dtype.fields) self.assertTrue('pixel' in t.dtype.fields) self.assertTrue('lat' in t.dtype.fields) self.assertTrue('lon' in t.dtype.fields) self.assertEqual(type(t['lat']), np.ndarray) self.assertEqual(type(t['lon']), np.ndarray)
def test_get_transect_outside(self): n1 = Nansat(self.test_file_gcps, logLevel=40) v, xy, pl = n1.get_transect([[(28.31299128, 70.93709219), (0.0, 0.0)]]) self.assertTrue(len(v['1:L_645']['shape0']) > 50) self.assertEqual(len(v['1:L_645']['shape0']), len(xy['shape0']['latitude'])) self.assertEqual(len(v['1:L_645']['shape0']), len(pl['shape0'][0])) self.assertEqual(type(xy['shape0']['latitude']), np.ndarray) self.assertEqual(type(pl['shape0'][0]), np.ndarray)
def test_get_transect_outside(self): n1 = Nansat(self.test_file_gcps, logLevel=40) t = n1.get_transect([[0, 28.31299128], [0, 70.93709219]], [1]) self.assertTrue('L_645' in t.dtype.fields) self.assertTrue('line' in t.dtype.fields) self.assertTrue('pixel' in t.dtype.fields) self.assertTrue('lat' in t.dtype.fields) self.assertTrue('lon' in t.dtype.fields) self.assertEqual(type(t['lat']), np.ndarray) self.assertEqual(type(t['lon']), np.ndarray)
def test_get_transect_pixlin(self): n1 = Nansat(self.test_file_gcps, logLevel=40) t = n1.get_transect([[10, 20], [10, 10]], ['L_645'], lonlat=False) self.assertTrue('L_645' in t.dtype.fields) self.assertTrue('line' in t.dtype.fields) self.assertTrue('pixel' in t.dtype.fields) self.assertTrue('lat' in t.dtype.fields) self.assertTrue('lon' in t.dtype.fields) self.assertEqual(type(t['lat']), np.ndarray) self.assertEqual(type(t['lon']), np.ndarray) self.assertEqual(len(t['lon']), 11)
def test_get_transect_data(self): n1 = Nansat(self.test_file_gcps, logLevel=40) b1 = n1[1] t = n1.get_transect([[28.3], [70.9]], [], data=b1) self.assertTrue('input' in t.dtype.fields) self.assertTrue('L_645' not in t.dtype.fields) self.assertTrue('line' in t.dtype.fields) self.assertTrue('pixel' in t.dtype.fields) self.assertTrue('lat' in t.dtype.fields) self.assertTrue('lon' in t.dtype.fields) self.assertEqual(type(t['lat']), np.ndarray) self.assertEqual(type(t['lon']), np.ndarray)
def test_get_transect_data(self): n1 = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper) b1 = n1[1] t = n1.get_transect([[28.3], [70.9]], [], data=b1) self.assertTrue('input' in t.dtype.fields) self.assertTrue('L_645' not in t.dtype.fields) self.assertTrue('line' in t.dtype.fields) self.assertTrue('pixel' in t.dtype.fields) self.assertTrue('lat' in t.dtype.fields) self.assertTrue('lon' in t.dtype.fields) self.assertEqual(type(t['lat']), np.ndarray) self.assertEqual(type(t['lon']), np.ndarray)
def test_get_transect(self): n1 = Nansat(self.test_file_gcps, logLevel=40) v, xy, pl = n1.get_transect([[(28.31299128, 70.93709219), (28.93691525, 70.69646524)]]) tmpfilename = os.path.join(ntd.tmp_data_path, 'nansat_get_transect.png') plt.plot(v['1:L_645']['shape0'], xy['shape0']['latitude']) plt.savefig(tmpfilename) plt.close('all') self.assertTrue(len(v['1:L_645']['shape0']) > 50) self.assertEqual(len(v['1:L_645']['shape0']), len(xy['shape0']['latitude'])) self.assertEqual(len(v['1:L_645']['shape0']), len(pl['shape0'][0])) self.assertEqual(type(xy['shape0']['latitude']), np.ndarray) self.assertEqual(type(pl['shape0'][0]), np.ndarray)
def test_get_transect(self): plt.switch_backend('agg') n1 = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper) t = n1.get_transect([[28.31299128, 28.93691525], [70.93709219, 70.69646524]], [str('L_645')]) tmpfilename = os.path.join(self.tmp_data_path, 'nansat_get_transect.png') plt.plot(t['lat'], t['L_645'], '.-') plt.savefig(tmpfilename) plt.close('all') self.assertTrue('L_645' in t.dtype.fields) self.assertTrue('line' in t.dtype.fields) self.assertTrue('pixel' in t.dtype.fields) self.assertTrue('lat' in t.dtype.fields) self.assertTrue('lon' in t.dtype.fields) self.assertEqual(type(t['lat']), np.ndarray) self.assertEqual(type(t['lon']), np.ndarray)
def test_get_transect(self): n1 = Nansat(self.test_file_gcps, logLevel=40) t = n1.get_transect([[28.31299128, 28.93691525], [70.93709219, 70.69646524]], ['L_645']) tmpfilename = os.path.join(ntd.tmp_data_path, 'nansat_get_transect.png') plt.plot(t['lat'], t['L_645'], '.-') plt.savefig(tmpfilename) plt.close('all') self.assertTrue('L_645' in t.dtype.fields) self.assertTrue('line' in t.dtype.fields) self.assertTrue('pixel' in t.dtype.fields) self.assertTrue('lat' in t.dtype.fields) self.assertTrue('lon' in t.dtype.fields) self.assertEqual(type(t['lat']), np.ndarray) self.assertEqual(type(t['lon']), np.ndarray)
n.export_band(oFileName + '07.tif', bandID=1, driver='GTiff') # get array with watermask (landmask) # -- Get Nansat object with watermask wm = n.watermask()[1] # -- Reproject with cubic interpolation d = Domain(4326, "-te 27 70.3 31 71.5 -ts 300 300") n.reproject(d, 2) # -- Write image n.write_figure(oFileName + '08_pro.png', clim='hist') # Get transect of the 1st and 2nd bands corresponding to the given points values, lonlat, pixlinCoord = n.get_transect( points=((29.287, 71.153), (29.275, 71.145), (29.210, 71.154)), transect=False, bandList=[1, 2]) # print the results print '1stBandVal 2ndBandVal pix/lin lon/lat ' for i in range (len(values[0])): print '%6d %10d %13.2f /%6.2f %7.2f /%6.2f' % (values[0][i], values[1][i], pixlinCoord[0][i], pixlinCoord[1][i], lonlat[0][i], lonlat[1][i]) print '' print '\n***nansat_test completed successfully. Output files are found here:' + oFileName
# Write indexed picture with data from the first band n.write_figure(oFileName + '.png', clim='hist') # Reproject input image onto map of Norwegian Coast # 1. Create domain describing the desired map # 2. Transform the original satellite image # 3. Write the transfromed image into RGB picture dLatlong = Domain("+proj=latlong +datum=WGS84 +ellps=WGS84 +no_defs", "-te 27 70.2 31 71.5 -ts 500 500") n.reproject(dLatlong) n.write_figure(oFileName + 'pro.png', bands=[1, 2, 3], clim=[0, 100]) # Export projected satelite image into NetCDF format n.export(oFileName + '.nc') # Collect values from interactively drawn transect # 1. draw transect interactively # 2. plot the values values, lonlat, pixlinCoord = n.get_transect() plt.plot(lonlat[0], values[0], '.-'); plt.show() # run tests of other nansat components import test_domain import test_nansat import test_figure import test_nansatmap import test_nansatshape import test_mosaic import test_pointbrowser