當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。