本文整理汇总了Python中nansat.vrt.VRT.from_array方法的典型用法代码示例。如果您正苦于以下问题:Python VRT.from_array方法的具体用法?Python VRT.from_array怎么用?Python VRT.from_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nansat.vrt.VRT
的用法示例。
在下文中一共展示了VRT.from_array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_complex_band
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_find_complex_band(self):
a = np.random.randn(100,100)
vrt1 = VRT.from_array(a)
vrt2 = VRT.from_array(a.astype(np.complex64))
vrt3 = VRT.from_gdal_dataset(vrt1.dataset)
vrt3.create_bands([{'src': {'SourceFilename': vrt1.filename}},
{'src': {'SourceFilename': vrt2.filename}}])
self.assertEqual(vrt1._find_complex_band(), None)
self.assertEqual(vrt2._find_complex_band(), 1)
self.assertEqual(vrt3._find_complex_band(), 2)
示例2: test_from_filenames
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_from_filenames(self):
lon, lat = np.meshgrid(np.linspace(0,5,10), np.linspace(10,20,30))
x_vrt = VRT.from_array(lon)
y_vrt = VRT.from_array(lat)
g = Geolocation.from_filenames(x_vrt.filename, y_vrt.filename)
self.assertIsInstance(g, Geolocation)
self.assertEqual(g.data['X_DATASET'], x_vrt.filename)
self.assertEqual(g.data['Y_DATASET'], y_vrt.filename)
self.assertEqual(g.data['LINE_OFFSET'], '0')
self.assertEqual(g.data['LINE_STEP'], '1')
self.assertEqual(g.data['PIXEL_OFFSET'], '0')
self.assertEqual(g.data['PIXEL_STEP'], '1')
示例3: vrts_from_arrays
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def vrts_from_arrays(self, data, variable_names, pol='', resize=True, resample_alg=2):
""" Convert input dict with arrays into dict with VRTs
Parameters
----------
data : dict
2D arrays with data from LUT
variable_names : list of str
variable names that should be converted to VRTs
pol : str
HH, HV, etc
resize : bool
Shall VRT be zoomed to full size?
resample_alg : int
Index of resampling algorithm. See VRT.get_resized_vrt()
Returns
-------
vrts : dict with (resized) VRTs
"""
vrts = {}
for var_name in variable_names:
vrts[var_name+pol] = VRT.from_array(data[var_name+pol])
if resize:
vrts[var_name+pol] = vrts[var_name+pol].get_resized_vrt(self.dataset.RasterXSize,
self.dataset.RasterYSize,
resample_alg)
return vrts
示例4: test_create_band
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_create_band(self):
array = gdal.Open(self.test_file_gcps).ReadAsArray()[1, 10:, :]
vrt1 = VRT.from_array(array)
vrt2 = VRT(x_size=array.shape[1], y_size=array.shape[0])
self.assertEqual(vrt2.dataset.RasterCount, 0)
vrt2.create_band({'SourceFilename': vrt1.filename})
self.assertEqual(vrt2.dataset.RasterCount, 1)
示例5: test_get_super_vrt_and_copy
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_get_super_vrt_and_copy(self):
array = np.zeros((10,10))
vrt = VRT.from_array(array)
vrt = vrt.get_super_vrt()
vrt = vrt.copy()
data = vrt.dataset.ReadAsArray()
self.assertFalse(data is None)
self.assertTrue(np.all(data == array))
示例6: test_from_array
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_from_array(self):
array = gdal.Open(self.test_file_gcps).ReadAsArray()[1, 10:, :]
vrt = VRT.from_array(array)
self.assertEqual(vrt.dataset.RasterXSize, array.shape[1])
self.assertEqual(vrt.dataset.RasterYSize, array.shape[0])
self.assertEqual(vrt.dataset.RasterCount, 1)
self.assertIn('filename', list(vrt.dataset.GetMetadata().keys()))
self.assertEqual(gdal.Unlink(vrt.filename.replace('.vrt', '.raw')), 0)
示例7: set_gcps
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def set_gcps(self, lon, lat, gdal_dataset):
""" Set gcps """
self.band_vrts['new_lon_VRT'] = VRT.from_array(lon)
self.dataset.SetGCPs(VRT._lonlat2gcps(lon, lat, n_gcps=400), NSR().wkt)
# Add geolocation from correct longitudes and latitudes
self._add_geolocation(
Geolocation(self.band_vrts['new_lon_VRT'], self, x_band=1, y_band=self._latitude_band_number(gdal_dataset))
)
示例8: test_split_complex_bands
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_split_complex_bands(self):
a = np.random.randn(100,100)
vrt1 = VRT.from_array(a.astype(np.complex64))
vrt2 = VRT.from_array(a)
vrt3 = VRT.from_array(a.astype(np.complex64))
vrt4 = VRT.from_gdal_dataset(vrt1.dataset)
vrt4.create_bands([{'src': {'SourceFilename': vrt1.filename}, 'dst': {'name': 'vrt1'}},
{'src': {'SourceFilename': vrt2.filename}, 'dst': {'name': 'vrt2'}},
{'src': {'SourceFilename': vrt3.filename}, 'dst': {'name': 'vrt3'}}])
vrt4.split_complex_bands()
self.assertEqual(vrt4.dataset.RasterCount,5)
self.assertEqual(vrt4.dataset.GetRasterBand(1).GetMetadataItem(str('name')), 'vrt2')
self.assertEqual(vrt4.dataset.GetRasterBand(2).GetMetadataItem(str('name')), 'vrt1_real')
self.assertEqual(vrt4.dataset.GetRasterBand(3).GetMetadataItem(str('name')), 'vrt1_imag')
self.assertEqual(vrt4.dataset.GetRasterBand(4).GetMetadataItem(str('name')), 'vrt3_real')
self.assertEqual(vrt4.dataset.GetRasterBand(5).GetMetadataItem(str('name')), 'vrt3_imag')
示例9: test_export
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_export(self):
array = gdal.Open(self.test_file_gcps).ReadAsArray()[1, 10:, :]
vrt = VRT.from_array(array)
vrt.export(self.tmp_filename)
self.assertTrue(self.tmp_filename)
tree = ET.parse(self.tmp_filename)
root = tree.getroot()
self.assertEqual(root.tag, 'VRTDataset')
self.assertIn('rasterXSize', list(root.keys()))
self.assertIn('rasterYSize', list(root.keys()))
self.assertEqual([e.tag for e in root], ['Metadata', 'VRTRasterBand'])
示例10: test_init
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_init(self):
lon, lat = np.meshgrid(np.linspace(0,5,10), np.linspace(10,20,30))
x_vrt = VRT.from_array(lon)
y_vrt = VRT.from_array(lat)
ga = Geolocation(x_vrt, y_vrt)
self.assertIsInstance(ga, Geolocation)
self.assertEqual(ga.data['X_DATASET'], x_vrt.filename)
self.assertEqual(ga.data['Y_DATASET'], y_vrt.filename)
self.assertEqual(ga.data['LINE_OFFSET'], '0')
self.assertEqual(ga.data['LINE_STEP'], '1')
self.assertEqual(ga.data['PIXEL_OFFSET'], '0')
self.assertEqual(ga.data['PIXEL_STEP'], '1')
self.assertEqual(ga.data['SRS'], 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",'
'6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUT'
'HORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORI'
'TY["EPSG","8901"]],UNIT["degree",0.0174532925199433'
',AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]')
self.assertEqual(ga.data['X_BAND'], '1')
self.assertEqual(ga.data['Y_BAND'], '1')
self.assertEqual(ga.x_vrt, x_vrt)
self.assertEqual(ga.y_vrt, y_vrt)
示例11: test_make_source_bands_xml
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_make_source_bands_xml(self):
array = gdal.Open(self.test_file_gcps).ReadAsArray()[1, 10:, :]
vrt1 = VRT.from_array(array)
src1 = {'SourceFilename': vrt1.filename}
src2 = VRT._make_source_bands_xml(src1)
self.assertIn('XML', src2)
self.assertEqual(src2['SourceFilename'], vrt1.filename)
self.assertEqual(src2['SourceBand'], 1)
self.assertEqual(src2['LUT'], '')
self.assertEqual(src2['NODATA'], '')
self.assertEqual(src2['SourceType'], 'ComplexSource')
self.assertEqual(src2['ScaleRatio'], 1.0)
self.assertEqual(src2['ScaleOffset'], 0.0)
self.assertEqual(src2['DataType'], 1)
self.assertEqual(src2['xSize'], 200)
self.assertEqual(src2['ySize'], 190)
with self.assertRaises(KeyError):
src2 = VRT._make_source_bands_xml({})
示例12: __init__
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def __init__(self, filename, gdal_dataset, metadata, quartile=0, *args, **kwargs):
super(Mapper, self).__init__(filename, gdal_dataset, metadata, *args, **kwargs)
intervals = [0,1,2,3]
if not quartile in intervals:
raise ValueError('quartile must be one of [0,1,2,3]')
y_size = self.dataset.RasterYSize/4
y_offset = [y_size*qq for qq in intervals][quartile]
# Crop
self.set_offset_size('y', y_offset, y_size)
# Add quartile to metadata
self.dataset.SetMetadataItem('quartile', str(quartile))
# Create band of times
# TODO: resolve nansat issue #263 (https://github.com/nansencenter/nansat/issues/263)
#import ipdb; ipdb.set_trace()
tt = self.times()[int(y_offset) : int(y_offset + y_size)]
self.dataset.SetMetadataItem('time_coverage_start', tt[0].astype(datetime).isoformat())
self.dataset.SetMetadataItem('time_coverage_end', tt[-1].astype(datetime).isoformat())
time_stamps = (tt - tt[0]) / np.timedelta64(1, 's')
self.band_vrts['time'] = VRT.from_array(
np.tile(time_stamps, (self.dataset.RasterXSize, 1)).transpose()
)
self.create_band(
src = {
'SourceFilename': self.band_vrts['time'].filename,
'SourceBand': 1,
},
dst = {
'name': 'timestamp',
'time_coverage_start': tt[0].astype(datetime).isoformat(),
'units': 'seconds since time_coverage_start',
}
)
示例13: test_create_band_name_existing_name
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_create_band_name_existing_name(self):
self.mock_pti['get_wkv_variable'].side_effect = IndexError
vrt = VRT.from_array(np.zeros((10,10)))
vrt.dataset.GetRasterBand(1).SetMetadata({'name':'band1'})
self.assertEqual(vrt._create_band_name({'name': 'band1'}), ('band1_0000', {}))
示例14: __init__
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
#.........这里部分代码省略.........
###############################
d = Domain(ds=gdalDataset)
lon, lat = d.get_geolocation_grids(100)
'''
(GDAL?) Radarsat-2 data is stored with maximum latitude at first
element of each column and minimum longitude at first element of each
row (e.g. np.shape(lat)=(59,55) -> latitude maxima are at lat[0,:],
and longitude minima are at lon[:,0])
In addition, there is an interpolation error for direct estimate along
azimuth. We therefore estimate the heading along range and add 90
degrees to get the "satellite" heading.
'''
if str(passDirection).upper() == 'DESCENDING':
sat_heading = initial_bearing(lon[:, :-1], lat[:, :-1],
lon[:, 1:], lat[:, 1:]) + 90
elif str(passDirection).upper() == 'ASCENDING':
sat_heading = initial_bearing(lon[:, 1:], lat[:, 1:],
lon[:, :-1], lat[:, :-1]) + 90
else:
print('Can not decode pass direction: ' + str(passDirection))
# Calculate SAR look direction
look_direction = sat_heading + antennaPointing
# Interpolate to regain lost row
look_direction = np.mod(look_direction, 360)
look_direction = scipy.ndimage.interpolation.zoom(
look_direction, (1, 11./10.))
# Decompose, to avoid interpolation errors around 0 <-> 360
look_direction_u = np.sin(np.deg2rad(look_direction))
look_direction_v = np.cos(np.deg2rad(look_direction))
look_u_VRT = VRT.from_array(look_direction_u)
look_v_VRT = VRT.from_array(look_direction_v)
# Note: If incidence angle and look direction are stored in
# same VRT, access time is about twice as large
lookVRT = VRT.from_lonlat(lon, lat)
lookVRT.create_band(
[{'SourceFilename': look_u_VRT.filename, 'SourceBand': 1},
{'SourceFilename': look_v_VRT.filename, 'SourceBand': 1}],
{'PixelFunctionType': 'UVToDirectionTo'})
# Blow up to full size
lookVRT = lookVRT.get_resized_vrt(gdalDataset.RasterXSize, gdalDataset.RasterYSize)
# Store VRTs so that they are accessible later
self.band_vrts['look_u_VRT'] = look_u_VRT
self.band_vrts['look_v_VRT'] = look_v_VRT
self.band_vrts['lookVRT'] = lookVRT
# Add band to full sized VRT
lookFileName = self.band_vrts['lookVRT'].filename
metaDict.append({'src': {'SourceFilename': lookFileName,
'SourceBand': 1},
'dst': {'wkv': 'sensor_azimuth_angle',
'name': 'look_direction'}})
###############################
# Create bands
###############################
self.create_bands(metaDict)
###################################################
# Add derived band (incidence angle) calculated
# using pixel function "BetaSigmaToIncidence":
示例15: test_copy_vrt_with_band
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import from_array [as 别名]
def test_copy_vrt_with_band(self):
array = gdal.Open(self.test_file_gcps).ReadAsArray()[1, 10:, :]
vrt1 = VRT.from_array(array)
vrt2 = vrt1.copy()
self.assertEqual(vrt2.dataset.RasterCount, 1)