本文整理汇总了Python中nansat.Nansat.shape方法的典型用法代码示例。如果您正苦于以下问题:Python Nansat.shape方法的具体用法?Python Nansat.shape怎么用?Python Nansat.shape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nansat.Nansat
的用法示例。
在下文中一共展示了Nansat.shape方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_undo
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
def test_undo(self):
n1 = Nansat(self.test_file_stere, logLevel=40)
shape1 = n1.shape()
n1.resize(10)
n1.undo()
shape2 = n1.shape()
self.assertEqual(shape1, shape2)
示例2: test_reproject_gcps
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
def test_reproject_gcps(self):
n1 = Nansat(self.test_file_stere, logLevel=40)
n2 = Nansat(self.test_file_gcps, logLevel=40)
n1.reproject(n2)
tmpfilename = os.path.join(ntd.tmp_data_path,
'nansat_reproject_gcps.png')
n1.write_figure(tmpfilename, 2, clim='hist')
self.assertEqual(n1.shape(), n2.shape())
self.assertEqual(type(n1[1]), np.ndarray)
示例3: test_export_selected_bands
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [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)
示例4: test_crop_lonlat
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
def test_crop_lonlat(self):
n1 = Nansat(self.test_file_gcps, logLevel=40)
ext = n1.crop_lonlat([28, 29], [70.5, 71])
self.assertEqual(n1.shape(), (111, 110))
self.assertEqual(ext, (31, 89, 110, 111))
self.assertEqual(type(n1[1]), np.ndarray)
示例5: test_export_netcdf
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [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)
示例6: test_crop_no_gcps_arctic
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
def test_crop_no_gcps_arctic(self):
n1 = Nansat(self.test_file_arctic, logLevel=40)
ext = n1.crop(10, 20, 50, 60)
self.assertEqual(n1.shape(), (60, 50))
self.assertEqual(ext, (10, 20, 50, 60))
self.assertEqual(type(n1[1]), np.ndarray)
示例7: test_dont_export2thredds_gcps
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [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'])
示例8: test_reproject_domain
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
def test_reproject_domain(self):
n = Nansat(self.test_file_gcps, logLevel=40)
d = Domain(4326, "-te 27 70 30 72 -ts 500 500")
n.reproject(d)
tmpfilename = os.path.join(ntd.tmp_data_path,
'nansat_reproject_domain.png')
n.write_figure(tmpfilename, 2, clim='hist')
self.assertEqual(n.shape(), (500, 500))
self.assertEqual(type(n[1]), np.ndarray)
示例9: test_watermask
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
def test_watermask(self):
''' if watermask data exists: should fetch array with watermask
else: should raise an error'''
n1 = Nansat(self.test_file_gcps, logLevel=40)
mod44path = os.getenv('MOD44WPATH')
if mod44path is not None and os.path.exists(mod44path + '/MOD44W.vrt'):
wm = n1.watermask()[1]
self.assertEqual(type(wm), np.ndarray)
self.assertEqual(wm.shape[0], n1.shape()[0])
self.assertEqual(wm.shape[1], n1.shape()[1])
示例10: test_export_netcdf
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [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)
示例11: test_add_band_and_reproject
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [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.)
示例12: test_init_domain
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
def test_init_domain(self):
d = Domain(4326, "-te 25 70 35 72 -ts 500 500")
n = Nansat(domain=d, logLevel=40)
self.assertEqual(type(n), Nansat)
self.assertEqual(n.shape(), (500, 500))
示例13: main
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
def main( argv=None ):
year = '2012'
useMask = False
if argv is None:
argv = sys.argv
if argv is None:
print ( "Please specify the path/year to the asar folder! \n")
return
# Parse arguments
try:
opts, args = getopt.getopt(argv,"hi:o:",["year=","oPath=","iPath=","useMask="])
except getopt.GetoptError:
print 'readASAR.py -year <year> ...'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'readASAR.py -year <year> ...'
sys.exit()
elif opt in ("-year", "--year"):
year = arg
elif opt in ("-oPath", "--oPath"):
oPath = arg
elif opt in ("-iPath", "--iPath"):
iPath = arg
elif opt in ("-useMask", "--useMask"):
useMask = arg
oPath = '/media/SOLabNFS2/tmp/roughness/' + year + '/'
iPath = '/media/SOLabNFS2/store/satellite/asar/' + year + '/'
if not os.path.exists(oPath):
os.makedirs(oPath)
dirNames=os.listdir(iPath)
for dirName in dirNames:
fileNames=os.listdir(iPath+dirName)
for fileName in fileNames:
figureName = oPath + fileName[0:27] + '/' + fileName + '_proj.png'
kmlName = oPath + fileName[0:27] + '/' + fileName + '.kml'
if not os.path.exists(oPath + fileName[0:27] + '/'):
os.makedirs(oPath + fileName[0:27] + '/')
if os.path.isfile(kmlName):
print "%s already processed" % (fileName)
continue
else:
print "%s" % (fileName)
# try to create Nansat object
try:
n = Nansat(iPath + dirName + '/' + fileName, mapperName='asar', logLevel=27)
except Exception as e:
print "Failed to create Nansat object:"
print str(e)
os.rmdir(oPath + fileName[0:27] + '/' )
continue
#~ Get the bands
raw_counts = n[1]
inc_angle = n[2]
#~ NICE image (roughness)
pol = n.bands()[3]['polarization']
if pol == 'HH':
ph = (2.20495, -14.3561e-2, 11.28e-4)
sigma0_hh_ref = exp( ( ph[0]+inc_angle*ph[1]+inc_angle**2*ph[2])*log(10) )
roughness = n[3]/sigma0_hh_ref
elif pol == 'VV':
pv = (2.29373, -15.393e-2, 15.1762e-4)
sigma0_vv_ref = exp( ( pv[0]+inc_angle*pv[1]+inc_angle**2*pv[2])*log(10) )
roughness = n[3]/sigma0_vv_ref
#~ Create new band
n.add_band(bandID=4, array=roughness, \
parameters={'name':'roughness', \
'wkv': 'surface_backwards_scattering_coefficient_of_radar_wave', \
'dataType': 6})
# Reproject 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 1000m
# 4. Reproject
# 5. Write image
n.reproject() # 1.
lons, lats = n.get_corners() # 2.
# Pixel resolution
#~ pxlRes = distancelib.getPixelResolution(array(lats), array(lons), n.shape())
#~ pxlRes = array(pxlRes)*360/40000 # great circle distance
pxlRes = array(distancelib.getPixelResolution(array(lats), array(lons), n.shape(), 'deg'))
ipdb.set_trace()
#.........这里部分代码省略.........
示例14: Nansat
# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import shape [as 别名]
# create Nansat object
#~ n = Nansat(iPath + fileName, mapperName="modis_l1", logLevel=10)
n = Nansat(iPath + fileName, mapperName="modis_l1")
# list bands and georeference of the object
print n
# 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))
extentString = '-lle %f %f %f %f -tr %f %f' % (min(lons), min(lats), \
max(lons), max(lats), pxlRes[1], pxlRes[0])
d = Domain(srs=srsString, ext=extentString) # 3.
print d
n.reproject(d) # 4.
# 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]