当前位置: 首页>>代码示例>>Python>>正文


Python xarray.open_rasterio方法代码示例

本文整理汇总了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) 
开发者ID:intake,项目名称:intake-xarray,代码行数:20,代码来源:raster.py

示例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 
开发者ID:pytroll,项目名称:satpy,代码行数:27,代码来源:generic_image.py

示例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) 
开发者ID:recipy,项目名称:recipy,代码行数:8,代码来源:run_xarray.py

示例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]) 
开发者ID:holoviz,项目名称:hvplot,代码行数:16,代码来源:testgeo.py

示例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) 
开发者ID:intake,项目名称:intake-xarray,代码行数:10,代码来源:raster.py

示例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) 
开发者ID:holoviz,项目名称:geoviews,代码行数:37,代码来源:util.py


注:本文中的xarray.open_rasterio方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。