本文整理汇总了Python中nansat.vrt.VRT类的典型用法代码示例。如果您正苦于以下问题:Python VRT类的具体用法?Python VRT怎么用?Python VRT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VRT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, fileName, gdalDataset, gdalMetadata, **kwargs):
title_correct = False
if not gdalMetadata:
raise WrongMapperError
for key, val in gdalMetadata.iteritems():
if "title" in key:
if not val == "Daily AMSR-E Arctic lead area fraction [in percent]":
raise WrongMapperError
else:
title_correct = True
if not title_correct:
raise WrongMapperError
# initiate VRT for the NSIDC 10 km grid
VRT.__init__(
self,
srcGeoTransform=(-3850000, 6250, 0.0, 5850000, 0.0, -6250),
srcProjection=NSR(3411).wkt,
srcRasterXSize=1216,
srcRasterYSize=1792,
)
src = {"SourceFilename": 'NETCDF:"%s":lf' % fileName, "SourceBand": 1}
dst = {"name": "leadFraction", "long_name": "AMSRE sea ice lead fraction"}
self._create_band(src, dst)
self.dataset.FlushCache()
示例2: __init__
def __init__(self, fileName, gdalDataset, gdalMetadata, **kwargs):
''' Create NCEP VRT '''
if not gdalDataset:
raise WrongMapperError
geotransform = gdalDataset.GetGeoTransform()
if (geotransform != (-0.25, 0.5, 0.0, 90.25, 0.0, -0.5) or
gdalDataset.RasterCount != 2): # Not water proof
raise WrongMapperError
metaDict = [{'src': {'SourceFilename': fileName,
'SourceBand': 1},
'dst': {'wkv': 'eastward_wind',
'height': '10 m'}},
{'src': {'SourceFilename': fileName,
'SourceBand': 2},
'dst': {'wkv': 'northward_wind',
'height': '10 m'}},
{'src': [{'SourceFilename': fileName,
'SourceBand': 1,
'DataType': gdalDataset.GetRasterBand(1).DataType
},
{'SourceFilename': fileName,
'SourceBand': 2,
'DataType': gdalDataset.GetRasterBand(2).DataType
}],
'dst': {'wkv': 'wind_speed',
'PixelFunctionType': 'UVToMagnitude',
'name': 'windspeed',
'height': '2 m'
}},
{'src': [{'SourceFilename': fileName,
'SourceBand': 1,
'DataType': gdalDataset.GetRasterBand(1).DataType
},
{'SourceFilename': fileName,
'SourceBand': 2,
'DataType': gdalDataset.GetRasterBand(2).DataType
}],
'dst': {'wkv': 'wind_from_direction',
'PixelFunctionType': 'UVToDirectionFrom',
'name': 'winddirection',
'height': '2 m'
}
}]
# create empty VRT dataset with geolocation only
VRT.__init__(self, gdalDataset)
# add bands with metadata and corresponding values to the empty VRT
self._create_bands(metaDict)
# Adding valid time from the GRIB file to dataset
validTime = gdalDataset.GetRasterBand(1).\
GetMetadata()['GRIB_VALID_TIME']
self._set_time(datetime.datetime.
utcfromtimestamp(int(validTime.strip().split(' ')[0])))
return
示例3: test_copy_vrt_pixel_func
def test_copy_vrt_pixel_func(self):
vrt1 = VRT()
vrt1_xml = '''
<VRTDataset rasterXSize="200" rasterYSize="200">
<VRTRasterBand dataType="Byte" band="1">
<ComplexSource>
<SourceFilename relativeToVRT="0">%s</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="200" RasterYSize="200" DataType="Byte" BlockXSize="200" BlockYSize="13" />
<SrcRect xOff="0" yOff="0" xSize="200" ySize="200" />
<DstRect xOff="0" yOff="0" xSize="200" ySize="200" />
</ComplexSource>
</VRTRasterBand>
<VRTRasterBand dataType="Float32" band="2" subClass="VRTDerivedRasterBand">
<ComplexSource>
<SourceFilename relativeToVRT="0">%s</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="200" RasterYSize="200" DataType="Byte" BlockXSize="128" BlockYSize="128" />
<SrcRect xOff="0" yOff="0" xSize="200" ySize="200" />
<DstRect xOff="0" yOff="0" xSize="200" ySize="200" />
</ComplexSource>
<PixelFunctionType>sqrt</PixelFunctionType>
</VRTRasterBand>
</VRTDataset>
''' % (self.test_file_gcps, vrt1.filename)
vrt1.write_xml(vrt1_xml)
vrt2 = vrt1.copy()
self.assertFalse(os.path.basename(vrt1.filename) in vrt2.xml)
示例4: test_create_band
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: __init__
def __init__(self, fileName, gdalDataset, gdalMetadata, **kwargs):
'''
Mapping for the global 30 arc-second elevation (see
https://lta.cr.usgs.gov/GTOPO30).
Parameters:
-----------
fileName : string
Either the name of a gtopo30 DEM file, or <path>/gtopo30.vrt. The
latter is an aggregation of the DEM-files available with gtopo30
except the Antarctic one, which is in polarstereographic
projection. You can create your own gtopo30.vrt file with gdal:
> gdalbuildvrt gtopo30.vrt [E,W]*.DEM
'''
bn = os.path.basename(fileName)
if not bn=='gtopo30.vrt' and not os.path.splitext(bn)[1]=='.DEM':
raise WrongMapperError
metaDict = [{'src': {'SourceFilename': fileName, 'SourceBand': 1},
'dst': {'wkv': 'height_above_reference_ellipsoid'}}]
# create empty VRT dataset with geolocation only
VRT.__init__(self, gdalDataset)
# add bands with metadata and corresponding values to the empty VRT
self._create_bands(metaDict)
示例6: __init__
def __init__(self, fileName, gdalDataset, gdalMetadata, **kwargs):
''' Create VRT '''
##############
# Get time
##############
if fileName[0:len(keywordBase)] != keywordBase:
raise AttributeError("Wrong mapper")
timestr = fileName[len(keywordBase)+1::]
time = datetime.strptime(timestr, '%Y%m%d%H%M')
######################################################
# Find windFileName corresponding to a Nansat-readable
# file in your local (or remote) file archive
######################################################
windFileName = localFolder + <.......>
######################################################
# Open file with any other Nansat mapper
######################################################
w = Nansat(windFileName)
VRT.__init__(self, vrtDataset=w.vrt.dataset)
return
示例7: test_create_band_name_wkv
def test_create_band_name_wkv(self):
short_name='sigma0'
wkv = dict(short_name=short_name)
self.mock_pti['get_wkv_variable'].return_value=wkv
vrt = VRT()
self.assertEqual(vrt._create_band_name({'wkv': short_name}), (short_name, wkv))
self.assertEqual(vrt._create_band_name({'wkv': short_name, 'suffix': 'HH'}),
(short_name + '_HH', wkv))
示例8: test_make_filename
def test_make_filename(self):
filename1 = VRT._make_filename()
filename2 = VRT._make_filename(extention='smth')
filename3 = VRT._make_filename(nomem=True)
self.assertTrue(filename1.startswith('/vsimem/'))
self.assertTrue(filename2.startswith('/vsimem/'))
self.assertTrue(filename2.endswith('.smth'))
self.assertTrue(os.path.exists(filename3))
示例9: test_get_projection_raises_NansatProjectionError
def test_get_projection_raises_NansatProjectionError(self, dataset):
dataset.GetProjection.return_value = ''
dataset.GetGCPProjection.return_value = ''
dataset.GetMetadata.return_value = {}
vrt = VRT()
with self.assertRaises(NansatProjectionError):
proj = vrt.get_projection()
示例10: set_gcps
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))
)
示例11: test_get_projection_dataset
def test_get_projection_dataset(self, dataset):
proj = 'SOME_PROJECTION'
dataset.GetProjection.return_value = proj
dataset.GetGCPProjection.return_value = ''
dataset.GetMetadata.return_value = {}
vrt = VRT()
proj_src = vrt.get_projection()
self.assertEqual(proj_src, (proj, 'dataset'))
示例12: __init__
def __init__(self, fileName, gdalDataset, gdalMetadata, **kwargs):
''' Create LANDSAT VRT '''
# try to open .tar or .tar.gz or .tgz file with tar
try:
tarFile = tarfile.open(fileName)
except:
raise WrongMapperError
tarNames = tarFile.getnames()
#print tarNames
metaDict = []
for tarName in tarNames:
if ((tarName[0] == 'L' or tarName[0] == 'M') and
(tarName[-4:] == '.TIF' or tarName[-4:] == '.tif')):
#print tarName
bandNo = tarName[-6:-4]
metaDict.append({
'src': {'SourceFilename': '/vsitar/%s/%s' % (fileName,
tarName),
'SourceBand': 1},
'dst': {'wkv': 'toa_outgoing_spectral_radiance',
'suffix': bandNo}})
if not metaDict:
raise WrongMapperError
#print metaDict
sizeDiffBands = []
for iFile in range(len(metaDict)):
tmpName = metaDict[iFile]['src']['SourceFilename']
gdalDatasetTmp = gdal.Open(tmpName)
if iFile == 0:
gdalDatasetTmp0 = gdalDatasetTmp
xSize = gdalDatasetTmp.RasterXSize
ySize = gdalDatasetTmp.RasterYSize
elif (xSize != gdalDatasetTmp.RasterXSize or
ySize != gdalDatasetTmp.RasterYSize):
sizeDiffBands.append(iFile)
# create empty VRT dataset with geolocation only
VRT.__init__(self, gdalDatasetTmp0)
# add bands with metadata and corresponding values to the empty VRT
self._create_bands(metaDict)
# 8th band of LANDSAT8 is a double size band.
# Reduce the size to same as the 1st band.
if len(sizeDiffBands) != 0:
vrtXML = self.read_xml()
node0 = Node.create(vrtXML)
for iBand in sizeDiffBands:
iBandNode = node0.nodeList('VRTRasterBand')[iBand]
iNodeDstRect = iBandNode.node('DstRect')
iNodeDstRect.replaceAttribute('xSize', str(xSize))
iNodeDstRect.replaceAttribute('ySize', str(ySize))
self.write_xml(node0.rawxml())
示例13: test_get_projection_geolocation
def test_get_projection_geolocation(self, dataset):
proj = 'SOME_PROJECTION'
dataset.GetProjection.return_value = ''
dataset.GetGCPProjection.return_value = ''
dataset.GetMetadata.return_value = {'SRS': proj}
vrt = VRT()
proj_src = vrt.get_projection()
self.assertEqual(proj_src, (proj, 'geolocation'))
示例14: __init__
def __init__(self, inputFileName, gdalDataset, gdalMetadata, logLevel=30,
**kwargs):
# check if mapper fits
if not gdalMetadata:
raise WrongMapperError
if not os.path.splitext(inputFileName)[1] == '.mnt':
raise WrongMapperError
try:
mbNorthLatitude = float(gdalMetadata['NC_GLOBAL#mbNorthLatitude'])
mbSouthLatitude = float(gdalMetadata['NC_GLOBAL#mbSouthLatitude'])
mbEastLongitude = float(gdalMetadata['NC_GLOBAL#mbEastLongitude'])
mbWestLongitude = float(gdalMetadata['NC_GLOBAL#mbWestLongitude'])
mbProj4String = gdalMetadata['NC_GLOBAL#mbProj4String']
Number_lines = int(gdalMetadata['NC_GLOBAL#Number_lines'])
Number_columns = int(gdalMetadata['NC_GLOBAL#Number_columns'])
Element_x_size = float(gdalMetadata['NC_GLOBAL#Element_x_size'])
Element_y_size = float(gdalMetadata['NC_GLOBAL#Element_y_size'])
except:
raise WrongMapperError
# find subdataset with DEPTH
subDatasets = gdalDataset.GetSubDatasets()
dSourceFile = None
for subDataset in subDatasets:
if subDataset[0].endswith('.mnt":DEPTH'):
dSourceFile = subDataset[0]
if dSourceFile is None:
raise WrongMapperError
dSubDataset = gdal.Open(dSourceFile)
dMetadata = dSubDataset.GetMetadata()
try:
scale_factor = dMetadata['DEPTH#scale_factor']
add_offset = dMetadata['DEPTH#add_offset']
except:
raise WrongMapperError
geoTransform = [mbWestLongitude, Element_x_size, 0,
mbNorthLatitude, 0, -Element_y_size]
# create empty VRT dataset with geolocation only
VRT.__init__(self, srcGeoTransform=geoTransform,
srcMetadata=gdalMetadata,
srcProjection=NSR(mbProj4String).wkt,
srcRasterXSize=Number_columns,
srcRasterYSize=Number_lines)
metaDict = [{'src': {'SourceFilename': dSourceFile,
'SourceBand': 1,
'ScaleRatio' : scale_factor,
'ScaleOffset' : add_offset},
'dst': {'wkv': 'depth'}}]
# add bands with metadata and corresponding values to the empty VRT
self._create_bands(metaDict)
示例15: test_add_swath_mask_band
def test_add_swath_mask_band(self, create_band):
vrt = VRT()
vrt.filename = '/temp/filename.vrt'
vrt._add_swath_mask_band()
src = [{'SourceFilename': '/temp/filename.vrt',
'SourceBand': 1,
'DataType': 1}]
dst ={'dataType': 1,
'wkv': 'swath_binary_mask',
'PixelFunctionType': 'OnesPixelFunc'}
create_band.assert_called_once_with(src=src, dst=dst)