本文整理匯總了Python中xarray.open_rasterio方法的典型用法代碼示例。如果您正苦於以下問題:Python xarray.open_rasterio方法的具體用法?Python xarray.open_rasterio怎麽用?Python xarray.open_rasterio使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xarray
的用法示例。
在下文中一共展示了xarray.open_rasterio方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _open_files
# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import open_rasterio [as 別名]
def _open_files(self, files):
import xarray as xr
das = [xr.open_rasterio(f, chunks=self.chunks, **self._kwargs)
for f in files]
out = xr.concat(das, dim=self.dim)
coords = {}
if self.pattern:
coords = {
k: xr.concat(
[xr.DataArray(
np.full(das[i].sizes.get(self.dim, 1), v),
dims=self.dim
) for i, v in enumerate(values)], dim=self.dim)
for k, values in reverse_formats(self.pattern, files).items()
}
return out.assign_coords(**coords).chunk(self.chunks)
示例2: read
# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import open_rasterio [as 別名]
def read(self):
"""Read the image."""
dataset = rasterio.open(self.finfo['filename'])
# Create area definition
if hasattr(dataset, 'crs') and dataset.crs is not None:
self.area = utils.get_area_def_from_raster(dataset)
data = xr.open_rasterio(dataset, chunks=(1, CHUNK_SIZE, CHUNK_SIZE))
attrs = data.attrs.copy()
# Rename to Satpy convention
data = data.rename({'band': 'bands'})
# Rename bands to [R, G, B, A], or a subset of those
data['bands'] = BANDS[data.bands.size]
# Mask data if alpha channel is present
try:
data = mask_image_data(data)
except ValueError as err:
logger.warning(err)
data.attrs = attrs
self.file_content['image'] = data
示例3: open_rasterio
# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import open_rasterio [as 別名]
def open_rasterio(self):
"""
Use xarray.open_rasterio to read image.tiff.
"""
file_name = os.path.join(self.data_dir, "image.tiff")
xarray.open_rasterio(file_name)
示例4: setUp
# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import open_rasterio [as 別名]
def setUp(self):
try:
import xarray as xr
import rasterio # noqa
import geoviews # noqa
import cartopy.crs as ccrs
except:
raise SkipTest('xarray, rasterio, geoviews, or cartopy not available')
import hvplot.xarray # noqa
import hvplot.pandas # noqa
self.da = (xr.open_rasterio(
'https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif')
.sel(band=1))
self.crs = ccrs.epsg(self.da.crs.split('epsg:')[1])
示例5: _open_dataset
# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import open_rasterio [as 別名]
def _open_dataset(self):
import xarray as xr
files = fsspec.open_local(self.urlpath, **self.storage_options)
if isinstance(files, list):
self._ds = self._open_files(files)
else:
self._ds = xr.open_rasterio(files, chunks=self.chunks,
**self._kwargs)
示例6: load_tiff
# 需要導入模塊: import xarray [as 別名]
# 或者: from xarray import open_rasterio [as 別名]
def load_tiff(filename, crs=None, apply_transform=False, nan_nodata=False, **kwargs):
"""
Returns an RGB or Image element loaded from a geotiff file.
The data is loaded using xarray and rasterio. If a crs attribute
is present on the loaded data it will attempt to decode it into
a cartopy projection otherwise it will default to a non-geographic
HoloViews element.
Parameters
----------
filename: string
Filename pointing to geotiff file to load
crs: Cartopy CRS or EPSG string (optional)
Overrides CRS inferred from the data
apply_transform: boolean
Whether to apply affine transform if defined on the data
nan_nodata: boolean
If data contains nodata values convert them to NaNs
**kwargs:
Keyword arguments passed to the HoloViews/GeoViews element
Returns
-------
element: Image/RGB/QuadMesh element
"""
try:
import xarray as xr
except:
raise ImportError('Loading tiffs requires xarray to be installed')
with warnings.catch_warnings():
warnings.filterwarnings('ignore')
da = xr.open_rasterio(filename)
return from_xarray(da, crs, apply_transform, nan_nodata, **kwargs)