本文整理汇总了Python中nansat.Nansat.add_band方法的典型用法代码示例。如果您正苦于以下问题:Python Nansat.add_band方法的具体用法?Python Nansat.add_band怎么用?Python Nansat.add_band使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nansat.Nansat
的用法示例。
在下文中一共展示了Nansat.add_band方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_export_gcps_complex_to_netcdf
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
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)
示例2: test_get_item_inf_expressions
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_get_item_inf_expressions(self):
''' inf should be replaced with nan '''
d = Domain(4326, "-te 25 70 35 72 -ts 500 500")
n = Nansat(domain=d, logLevel=40)
arr = np.empty((500, 500))
n.add_band(arr, {'expression': 'np.array([0,1,2,3,np.inf,5,6,7])'})
self.assertIsInstance(n[1], np.ndarray)
self.assertTrue(np.isnan(n[1][4]))
示例3: test_dont_export2thredds_gcps
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_dont_export2thredds_gcps(self):
n = Nansat(self.test_file_gcps, log_level=40, mapper=self.default_mapper)
n2 = Nansat.from_domain(n)
n.add_band(np.ones(n2.shape(), np.float32))
tmpfilename = os.path.join(self.tmp_data_path,
'nansat_export2thredds.nc')
self.assertRaises(ValueError, n2.export2thredds, tmpfilename,
['L_645'])
示例4: test_dont_export2thredds_gcps
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_dont_export2thredds_gcps(self):
n = Nansat(self.test_file_gcps, logLevel=40)
n2 = Nansat(domain=n)
n.add_band(np.ones(n2.shape(), np.float32))
tmpfilename = os.path.join(ntd.tmp_data_path,
'nansat_export2thredds.nc')
self.assertRaises(OptionError, n2.export2thredds, tmpfilename,
['L_645'])
示例5: test_add_band
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_add_band(self):
d = Domain(4326, "-te 25 70 35 72 -ts 500 500")
arr = np.random.randn(500, 500)
n = Nansat(domain=d, logLevel=40)
n.add_band(arr, {'name': 'band1'})
self.assertEqual(type(n), Nansat)
self.assertEqual(type(n[1]), np.ndarray)
self.assertEqual(n.get_metadata('name', 1), 'band1')
self.assertEqual(n[1].shape, (500, 500))
示例6: test_add_subvrts_only_to_one_nansat
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_add_subvrts_only_to_one_nansat(self):
d = Domain(4326, "-te 25 70 35 72 -ts 500 500")
arr = np.random.randn(500, 500)
n1 = Nansat(domain=d, logLevel=40)
n2 = Nansat(domain=d, logLevel=40)
n1.add_band(arr, {'name': 'band1'})
self.assertEqual(type(n1.vrt.bandVRTs), dict)
self.assertTrue(len(n1.vrt.bandVRTs) > 0)
self.assertEqual(n2.vrt.bandVRTs, {})
示例7: test_get_item_basic_expressions
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_get_item_basic_expressions(self):
''' Testing get_item with some basic expressions '''
d = Domain(4326, "-te 25 70 35 72 -ts 500 500")
n = Nansat(domain=d, logLevel=40)
arr = np.empty((500, 500))
n.add_band(arr, {'expression': '1+1'})
n.add_band(arr, {'expression': 'np.random.randn(500, 500)'})
self.assertIsInstance(n[1], int)
self.assertIsInstance(n[2], np.ndarray)
self.assertEqual(n[1], 2)
self.assertEqual(len(n[2]), 500)
self.assertEqual(len(n[2][0]), 500)
示例8: test_export_selected_bands
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_export_selected_bands(self):
n = Nansat(self.test_file_gcps)
resfile = 'tmp.nc'
new_band = np.random.randn(n.shape()[0], n.shape()[1])
n.add_band(new_band, {'name': 'newBand'})
# Test with band numbers
n.export(resfile, bands=[4, 2])
self.assertTrue(os.path.exists(resfile))
nn = Nansat(resfile)
self.assertTrue(nn.has_band('newBand'))
self.assertTrue(nn.has_band('L_555'))
os.unlink(resfile)
示例9: test_export2thredds_longlat_list
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_export2thredds_longlat_list(self):
d = Domain("+proj=latlong +datum=WGS84 +ellps=WGS84 +no_defs",
"-te 27 70 31 72 -ts 200 200")
n = Nansat(domain=d)
n.add_band(np.ones(d.shape(), np.float32),
parameters={'name': 'L_469'})
n.set_metadata('time_coverage_start', '2016-01-19')
tmpfilename = os.path.join(ntd.tmp_data_path,
'nansat_export2thredds_longlat.nc')
n.export2thredds(tmpfilename, ['L_469'])
ncI = netcdf_file(tmpfilename, 'r')
ncIVar = ncI.variables['L_469']
self.assertTrue(ncIVar.grid_mapping in ncI.variables.keys())
示例10: test_add_band_and_reproject
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_add_band_and_reproject(self):
''' Should add band and swath mask
and return 0 in areas out of swath '''
n = Nansat(self.test_file_gcps, logLevel=40)
d = Domain(4326, "-te 27 70 30 72 -ts 500 500")
n.add_band(np.ones(n.shape()))
n.reproject(d)
b1 = n[1]
b4 = n[4]
self.assertTrue(n.has_band('swathmask'))
self.assertTrue(b1[0, 0] == 0)
self.assertTrue(b1[300, 300] > 0)
self.assertTrue(np.isnan(b4[0, 0]))
self.assertTrue(b4[300, 300] == 1.)
示例11: test_export_netcdf
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_export_netcdf(self):
""" Test export and following import of data with bands containing np.nan values """
n = Nansat(self.test_file_gcps, mapper=self.default_mapper)
arrNoNaN = np.random.randn(n.shape()[0], n.shape()[1])
n.add_band(arrNoNaN, {'name': 'testBandNoNaN'})
arrWithNaN = arrNoNaN.copy()
arrWithNaN[int(n.shape()[0] / 2.) - 10:int(n.shape()[0] / 2 + 10),
int(n.shape()[1] / 2.) - 10:int(n.shape()[1] / 2 + 10)] = np.nan
n.add_band(arrWithNaN, {'name': 'testBandWithNaN'})
n.export(self.tmp_filename)
exported = Nansat(self.tmp_filename, mapper=self.default_mapper)
earrNoNaN = exported['testBandNoNaN']
# Use allclose to allow some roundoff errors
self.assertTrue(np.allclose(arrNoNaN, earrNoNaN))
earrWithNaN = exported['testBandWithNaN']
np.testing.assert_allclose(arrWithNaN, earrWithNaN)
示例12: test_repr_basic
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_repr_basic(self):
''' repr should include some basic elements '''
d = Domain(4326, "-te 25 70 35 72 -ts 500 500")
n = Nansat(domain=d, logLevel=40)
arr = np.empty((500, 500))
exp = 'np.array([0,1,2,3,np.inf,5,6,7])'
n.add_band(arr, {'expression': exp})
n_repr = repr(n)
self.assertIn(exp, n_repr, 'The expressions should be in repr')
self.assertIn('SourceFilename', n_repr)
self.assertIn('/vsimem/', n_repr)
self.assertIn('500 x 500', n_repr)
self.assertIn('Projection:', n_repr)
self.assertIn('25', n_repr)
self.assertIn('72', n_repr)
self.assertIn('35', n_repr)
self.assertIn('70', n_repr)
示例13: test_export_netcdf
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def test_export_netcdf(self):
''' Test export and following import of data with bands containing
np.nan values
'''
n = Nansat(self.test_file_gcps)
arrNoNaN = np.random.randn(n.shape()[0], n.shape()[1])
n.add_band(arrNoNaN, {'name': 'testBandNoNaN'})
arrWithNaN = arrNoNaN.copy()
arrWithNaN[n.shape()[0] / 2 - 10:n.shape()[0] / 2 + 10,
n.shape()[1] / 2 - 10:n.shape()[1] / 2 + 10] = np.nan
n.add_band(arrWithNaN, {'name': 'testBandWithNaN'})
n.export(self.tmpfilename)
exported = Nansat(self.tmpfilename)
earrNoNaN = exported['testBandNoNaN']
# Use allclose to allow some roundoff errors
self.assertTrue(np.allclose(arrNoNaN, earrNoNaN))
earrWithNaN = exported['testBandWithNaN']
np.testing.assert_allclose(arrWithNaN, earrWithNaN)
os.unlink(self.tmpfilename)
示例14: boreali_processing
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
def boreali_processing(obj, final_path):
wavelen = [412, 443, 469, 488, 531, 547, 555, 645, 667, 678]
cpa_limits = [0.01, 2,
0.01, 1,
0.01, 1, 10]
b = Boreali('michigan', wavelen)
n = Nansat(obj)
dom = Domain('+proj=latlong +datum=WGS84 +ellps=WGS84 +no_defs', '-lle -86.3 44.6 -85.2 45.3 -ts 300 200')
n.reproject(dom)
theta = numpy.zeros_like(n[2])
custom_n = Nansat(domain=n)
band_rrs_numbers = list(map(lambda x: n._get_band_number('Rrs_' + str(x)),
wavelen))
for index in range(0, len(wavelen)):
# Преобразуем в Rrsw
rrsw = n[band_rrs_numbers[index]] / (0.52 + 1.7 * n[band_rrs_numbers[index]])
custom_n.add_band(rrsw, parameters={'name': 'Rrsw_' + str(wavelen[index]),
'units': 'sr-1',
'wavelength': wavelen[index]})
custom_n = create_mask(custom_n)
cpa = b.process(custom_n, cpa_limits, mask=custom_n['mask'], theta=theta, threads=4)
custom_n.add_band(array=cpa[0], parameters={'name': 'chl',
'long_name': 'Chlorophyl-a',
'units': 'mg m-3'})
custom_n.add_band(array=cpa[1], parameters={'name': 'tsm',
'long_name': 'Total suspended matter',
'units': 'g m-3'})
custom_n.add_band(array=cpa[2], parameters={'name': 'doc',
'long_name': 'Dissolved organic carbon',
'units': 'gC m-3'})
custom_n.add_band(array=cpa[3], parameters={'name': 'mse',
'long_name': 'Root Mean Square Error',
'units': 'sr-1'})
custom_n.add_band(array=cpa[4], parameters={'name': 'mask',
'long_name': 'L2 Boreali mask',
'units': '1'})
custom_n.export(final_path + obj.split('/')[-1] + 'cpa_deep.nc')
fig_params = {'legend': True,
'LEGEND_HEIGHT': 0.5,
'NAME_LOCATION_Y': 0,
'mask_array': cpa[4],
'mask_lut': {1: [255, 255, 255], 2: [128, 128, 128], 4: [200, 200, 255]}}
custom_n.write_figure(final_path + obj.split('/')[-1] + 'chl_deep.png', 'chl', clim=[0, 1.], **fig_params)
custom_n.write_figure(final_path + obj.split('/')[-1] + 'tsm_deep.png', 'tsm', clim=[0, 1.], **fig_params)
custom_n.write_figure(final_path + obj.split('/')[-1] + 'doc_deep.png', 'doc', clim=[0, .2], **fig_params)
custom_n.write_figure(final_path + obj.split('/')[-1] + 'mse_deep.png', 'mse', clim=[1e-5, 1e-2], logarithm=True, **fig_params)
n.write_figure(final_path + obj.split('/')[-1] + 'rgb_deep.png',
[16, 14, 6],
clim=[[0, 0, 0], [0.006, 0.04, 0.024]],
mask_array=cpa[4],
mask_lut={2: [128, 128, 128]})
示例15: sin
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import add_band [as 别名]
print n.shape()
# get list with coordinates of the object corners
print n.get_corners()
# get lists with coordinates of the object borders
print n.get_border()
raw_counts = n[1]
inc_angle = n[2]
#~ sigma0 = n[3]
sigma0 = raw_counts**2.0 * sin(deg2rad(inc_angle))
sigma0 = 10*log10(sigma0)
n.add_band(bandID=4, array=sigma0)
# 1. Remove speckle noise (using Lee-Wiener filter)
speckle_filter('wiener', 7)
# Reprojected image into Lat/Lon WGS84 (Simple Cylindrical) projection
# 1. Cancel previous reprojection
# 2. Get corners of the image and the pixel resolution
# 3. Create Domain with stereographic projection, corner coordinates and resolution 1000m
# 4. Reproject
# 5. Write image
n.reproject() # 1.
lons, lats = n.get_corners() # 2.
pxlRes = distancelib.getPixelResolution(array(lats), array(lons), n.shape(), units="deg")
srsString = "+proj=latlong +datum=WGS84 +ellps=WGS84 +no_defs"
#~ extentString = '-lle %f %f %f %f -ts 3000 3000' % (min(lons), min(lats), max(lons), max(lats))