geost.read_model_netcdf#
- geost.read_model_netcdf(nc_file: str | Path, data_vars: str | list[str] | None = None, bbox: tuple[float, float, float, float] | None = None, load: bool = False, **xr_kwargs) Dataset | DataArray[source]#
Read data from a NetCDF file of a voxelmodel or layermodel data into an xarray Dataset or DataArray.
- Parameters:
nc_file (str | Path) – Path to the netcdf file of the voxelmodel or layermodel.
data_vars (str | list[str] | None, optional) – List of data variable names or a single data variable name specifying which data variables to return.
bbox (tuple[float, float, float, float] | None, optional) – Specify a bounding box (xmin, ymin, xmax, ymax) to return a selected area. The default is None. If bbox is None and the dataset is large, it is recommended to use lazy loading (load=False) and specify chunks (see examples below) to avoid memory issues.
load (bool, optional) – If True, the netcdf file is loaded into memory immediately. This will improve the speed of several analyses but will cause higher memory usage or memory error if the dataset is too large. Use False for lazy loading, which allows to process data that does not fit into memory. The default is False.
**xr_kwargs – Additional keyword arguments xarray.open_dataset. See relevant documentation for details.
- Returns:
xarray Dataset instance of the netcdf file or DataArray if a single variable is selected.
- Return type:
xr.Dataset | xr.DataArray
Examples
Read all model data from a local NetCDF file:
>>> import geost >>> model = geost.read_model_netcdf("my_netcdf_file.nc")
Read one or more data variables within a specific area from the NetCDF file and directly load the data into memory:
>>> model = geost.read_model_netcdf( ... "my_netcdf_file.nc", data_vars="my_var", bbox=(1, 1, 3, 3), load=True ... ) >>> model = geost.read_model_netcdf( ... "my_netcdf_file.nc", ... data_vars=["my_var", "my_other_var"], ... bbox=(1, 1, 3, 3), ... load=True ... )
Read the entire model data but specify chunks to avoid memory issues when the dataset is large:
>>> model = geost.read_model_netcdf( ... "my_netcdf_file.nc", ... chunks={"x": 100, "y": 100, "z": -1} # -1 takes the entire "z" dimension in a chunk ... )