geost.models.VoxelModel.from_netcdf#

classmethod VoxelModel.from_netcdf(nc_path: str | Path, data_vars: List[str] = None, bbox: tuple[float, float, float, float] = None, lazy: bool = True, **xr_kwargs)[source]#

Read data from a NetCDF file of a voxelmodel data into a VoxelModel instance.

This assumes the voxelmodel is according to the following conventions: - The coordinate dimensions of the voxelmodel are: “x”, “y” (horizontal) and “z” (depth). - The coordinates in the y-dimension are in descending order.

Parameters:
  • nc_path (str | Path) – Path to the netcdf file of the voxelmodel.

  • data_vars (ArrayLike) – List or array-like object specifying which data variables to return.

  • bbox (tuple (xmin, ymin, xmax, ymax), optional) – Specify a bounding box (xmin, ymin, xmax, ymax) to return a selected area of the voxelmodel. The default is None.

  • lazy (bool, optional) – If True, netcdf loads lazily. Use False for speed improvements for larger areas but that still fit into memory. The default is False.

  • **xr_kwargs – Additional keyword arguments xarray.open_dataset. See relevant documentation for details.

Returns:

VoxelModel instance of the netcdf file.

Return type:

VoxelModel

Examples

Read all model data from a local NetCDF file:

>>> VoxelModel.from_netcdf("my_netcdf_file.nc")

Read specific data variables and the data within a specific area from the NetCDF file:

>>> VoxelModel.from_netcdf(
...     "my_netcdf_file.nc",
...     data_vars=["my_var"],
...     bbox=(1, 1, 3, 3) # (xmin, ymin, xmax, ymax)
... )

Note that this method assumes the y-coordinates are in descending order. For y- ascending coordinates change ymin and ymax coordinates:

>>> VoxelModel.from_netcdf(
...     "my_netcdf_file.nc", bbox=(1, 3, 1, 3) # (xmin, ymax, xmax, ymin)
... )