stems.io package¶
Subpackages¶
Submodules¶
Module contents¶
Input/output helpers
-
stems.io.
open_dataset
(paths, chunks='auto', concat_dim=None, crs=None, **kwds)[source]¶ Open an xarray dataset (somewhat) intelligently
- Parameters
paths (str or List[str]) – Either a string glob in the form “path/to/my/files/*.nc” or an explicit list of files to open.
chunks ('auto', int or dict) – Number of chunks or the chunk size for each dimension. If ‘auto’, reads chunks from first file in
paths
and usesplants.io.chunking_.best_chunksizes()
to guess an appropriate chunksize based on the most frequently used chunksize per dimension. Otherwise, pass chunks ontoxr.open_mfdataset()
.concat_dim (None, str, DataArray or Index, optional) – Dimension to concatenate files along. This argument is passed on to
xarray.auto_combine()
along with the dataset objects. You only need to provide this argument if the dimension along which you want to concatenate is not a dimension in the original datasets, e.g., if you want to stack a collection of 2D arrays along a third dimension. By default, xarray attempts to infer this argument by examining component files. Setconcat_dim=None
explicitly to disable concatenation.crs (rasterio.crs.CRS, int, or str, optional) – Coordinate reference system to assign, if not already georeferenced. If type is not
CRS
, will be converted usingplants.gis.convert.to_crs()
.kwds (optional) – Options passed to
xarray.open_mfdataset()
- Returns
Multi-file dataset
- Return type
- Raises
IOError – Raise if
paths
does not parse into any filenames (e.g., a bad glob)
-
stems.io.
xarray_map
(y, x, count, dtype, crs=None, nodata=-9999, dim_band='band')[source]¶ A raster map with
count
bands :param y: Y coordinates :type y: array-like :param x: X coordinates :type x: array-like :param count: Number of bands :type count: int :param dtype: Data type :type dtype: np.dtype :param crs: Optionally, give the raster a CRS :type crs: CRS, optional :param nodata: No Data Value to initialize data with :type nodata: float or int- Returns
3D (band, y, x,) “map” to write data into
- Return type
xr.DataArray
-
class
stems.io.
VRTDataset
(separate=True)[source]¶ Bases:
object
Create a VRT from a band in one or more datasets
- Parameters
separate (bool, optional) – Put input bands in separate, stacked bands in the output
-
add_band
(self, path, src_bidx=1, vrt_bidx=None, validate=True, **band_kwds)[source]¶ Add a band to VRT dataset
- Parameters
path (str) – List of paths to open as datasets
src_bidx (int, optional) – Band indices of datasets to include. Defaults to
1
vrt_bidx (int or None) – Destination band in VRT for new band. Only used if
self.separate
is Truevalidate (bool, optional) – Validate band forms to expected attributes before adding
band_kwds (dict) – Additional keyword arguments passed onto
VRTSourceBand
- Returns
vrt_bidx – VRT band index
- Return type
- Raises
ValueError – Raised if vrt_bidx is invalid
-
property
bands
¶ Bands organized by output VRT band
- Type
dict[int, list[VRTSourceBand]]
-
property
bounds
¶ Bounding box of VRTDataset
- Type
BoundingBox
-
property
crs
¶ VRTDataset coordinate reference system
- Type
CRS
-
classmethod
from_bands
(paths, separate=True, bidx=1, **kwds)[source]¶ - Parameters
paths (str or list[str]) – List of paths to open as datasets
separate (bool, optional) – Put input bands in separate, stacked bands in the output
bidx (int, list[int], optional) – Band indices of datasets to include. If
int
, allpaths
will use this bandbidx
. Otherwise, pass a list of band indices for each path inpaths
. Defaults to1
.kwds (dict) – Keywords to pass to
VRTSourceBand()
for each band. Pass a list or tuple as a value to specify different values for each band.
- Returns
VRTDataset initialized from input paths
- Return type
-
property
transform
¶ Affine transform for VRTDataset
- Type
Affine
-
class
stems.io.
VRTSourceBand
(path, src_bidx, description=None, nodata=None, keep_open=False)[source]¶ Bases:
object
A VRT band originating from some other file
Note that all properties on this object return information used for VRT XML generation, but not XML elements (e.g., returns the SubElement name and this new element’s text value).
- Parameters
-
property
blockxsize
¶
-
property
blockysize
¶
-
property
bounds
¶
-
property
colorinterp
¶
-
property
crs
¶
-
property
description
¶
-
property
dtype
¶
-
property
height
¶
-
property
nodata
¶
-
property
shape
¶
-
property
transform
¶
-
property
width
¶