本文整理汇总了Python中nansat.vrt.VRT._create_bands方法的典型用法代码示例。如果您正苦于以下问题:Python VRT._create_bands方法的具体用法?Python VRT._create_bands怎么用?Python VRT._create_bands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nansat.vrt.VRT
的用法示例。
在下文中一共展示了VRT._create_bands方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Mapper
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import _create_bands [as 别名]
class Mapper(VRT):
""" Create VRT with mapping of WKV """
def __init__(self, fileName, gdalDataset, gdalMetadata, latlonGrid=None, mask="", **kwargs):
""" Create VRT
Parameters
-----------
fileName : string
gdalDataset : gdal dataset
gdalMetadata : gdal metadata
latlonGrid : numpy 2 layered 2D array with lat/lons of desired grid
"""
# test if input files is ASCAT
iDir, iFile = os.path.split(fileName)
iFileName, iFileExt = os.path.splitext(iFile)
try:
assert iFileName[0:6] == "ascat_" and iFileExt == ".nc"
except:
raise WrongMapperError
# Create geolocation
subDataset = gdal.Open('NETCDF:"' + fileName + '":lat')
self.GeolocVRT = VRT(srcRasterXSize=subDataset.RasterXSize, srcRasterYSize=subDataset.RasterYSize)
GeolocMetaDict = [
{
"src": {
"SourceFilename": ('NETCDF:"' + fileName + '":lon'),
"SourceBand": 1,
"ScaleRatio": 0.00001,
"ScaleOffset": -360,
},
"dst": {},
},
{
"src": {
"SourceFilename": ('NETCDF:"' + fileName + '":lat'),
"SourceBand": 1,
"ScaleRatio": 0.00001,
"ScaleOffset": 0,
},
"dst": {},
},
]
self.GeolocVRT._create_bands(GeolocMetaDict)
GeolocObject = GeolocationArray(
xVRT=self.GeolocVRT,
yVRT=self.GeolocVRT,
# x = lon, y = lat
xBand=1,
yBand=2,
lineOffset=0,
pixelOffset=0,
lineStep=1,
pixelStep=1,
)
# create empty VRT dataset with geolocation only
VRT.__init__(
self,
srcRasterXSize=subDataset.RasterXSize,
srcRasterYSize=subDataset.RasterYSize,
gdalDataset=subDataset,
geolocationArray=GeolocObject,
srcProjection=GeolocObject.d["SRS"],
)
# Scale and NODATA should ideally be taken directly from raw file
metaDict = [
{
"src": {
"SourceFilename": ('NETCDF:"' + fileName + '":wind_speed'),
"ScaleRatio": 0.01,
"NODATA": -32767,
},
"dst": {"name": "wind_speed", "wkv": "wind_speed"},
},
{
"src": {"SourceFilename": ('NETCDF:"' + fileName + '":wind_dir'), "ScaleRatio": 0.1, "NODATA": -32767},
"dst": {"name": "wind_direction", "wkv": "wind_direction"},
},
]
self._create_bands(metaDict)
# This should not be necessary
# - should be provided by GeolocationArray!
self.dataset.SetProjection(GeolocObject.d["SRS"])
# Add time
startTime = datetime.datetime(
int(iFileName[6:10]),
int(iFileName[10:12]),
int(iFileName[12:14]),
int(iFileName[15:17]),
int(iFileName[17:19]),
#.........这里部分代码省略.........
示例2: Mapper
# 需要导入模块: from nansat.vrt import VRT [as 别名]
# 或者: from nansat.vrt.VRT import _create_bands [as 别名]
class Mapper(VRT):
''' Create VRT with mapping of WKV '''
def __init__(self, fileName, gdalDataset, gdalMetadata,
latlonGrid=None, mask='', **kwargs):
''' Create VRT
Parameters
-----------
fileName : string
gdalDataset : gdal dataset
gdalMetadata : gdal metadata
latlonGrid : numpy 2 layered 2D array with lat/lons of desired grid
'''
# test if input files is ASCAT
iDir, iFile = os.path.split(fileName)
iFileName, iFileExt = os.path.splitext(iFile)
try:
assert iFileName[0:6] == 'ascat_' and iFileExt == '.nc'
except:
raise WrongMapperError
# Create geolocation
subDataset = gdal.Open('NETCDF:"' + fileName + '":lat')
self.GeolocVRT = VRT(srcRasterXSize=subDataset.RasterXSize,
srcRasterYSize=subDataset.RasterYSize)
GeolocMetaDict = [{'src': {'SourceFilename': ('NETCDF:"' + fileName +
'":lon'),
'SourceBand': 1,
'ScaleRatio': 0.00001,
'ScaleOffset': -360},
'dst': {}},
{'src': {'SourceFilename': ('NETCDF:"' + fileName +
'":lat'),
'SourceBand': 1,
'ScaleRatio': 0.00001,
'ScaleOffset': 0},
'dst': {}}]
self.GeolocVRT._create_bands(GeolocMetaDict)
GeolocObject = GeolocationArray(xVRT=self.GeolocVRT,
yVRT=self.GeolocVRT,
# x = lon, y = lat
xBand=1, yBand=2,
lineOffset=0, pixelOffset=0,
lineStep=1, pixelStep=1)
# create empty VRT dataset with geolocation only
VRT.__init__(self,
srcRasterXSize=subDataset.RasterXSize,
srcRasterYSize=subDataset.RasterYSize,
gdalDataset=subDataset,
geolocationArray=GeolocObject,
srcProjection=GeolocObject.d['SRS'])
# Scale and NODATA should ideally be taken directly from raw file
metaDict = [{'src': {'SourceFilename': ('NETCDF:"' + fileName +
'":wind_speed'),
'ScaleRatio': 0.01,
'NODATA': -32767},
'dst': {'name': 'wind_speed',
'wkv': 'wind_speed'}
},
{'src': {'SourceFilename': ('NETCDF:"' + fileName +
'":wind_dir'),
'ScaleRatio': 0.1,
'NODATA': -32767},
'dst': {'name': 'wind_direction',
'wkv': 'wind_direction'}}]
self._create_bands(metaDict)
# This should not be necessary
# - should be provided by GeolocationArray!
self.dataset.SetProjection(GeolocObject.d['SRS'])
# Add time
startTime = datetime.datetime(int(iFileName[6:10]),
int(iFileName[10:12]),
int(iFileName[12:14]),
int(iFileName[15:17]),
int(iFileName[17:19]),
int(iFileName[19:21]))
self._set_time(startTime)