imod.mf6.open_cbc#
- imod.mf6.open_cbc(cbc_path: str | Path, grb_path: str | Path, flowja: bool = False, simulation_start_time: datetime64 | None = None, time_unit: str | None = 'd', merge_to_dataset: bool = False) Dataset | UgridDataset | Dict[str, DataArray | UgridDataArray] [source]#
Open modflow6 cell-by-cell (.cbc) file.
The data is lazily read per timestep and automatically converted into (dense) xr.DataArrays or xu.UgridDataArrays, for DIS and DISV respectively. The conversion is done via the information stored in the Binary Grid file (GRB).
The
flowja
argument controls whether the flow-ja-face array (if present) is returned in grid form as “as is”. By defaultflowja=False
and the array is returned in “grid form”, meaning:DIS: in right, front, and lower face flow. All flows are placed in the cell.
DISV: in horizontal and lower face flow.the horizontal flows are placed on the edges and the lower face flow is placed on the faces.
When
flowja=True
, the flow-ja-face array is returned as it is found in the CBC file, with a flow for every cell to cell connection. Additionally, aconnectivity
DataArray is returned describing for every cell (n) its connected cells (m).- Parameters:
cbc_path (str, pathlib.Path) – Path to the cell-by-cell flows file
grb_path (str, pathlib.Path) – Path to the binary grid file
flowja (bool, default value: False) – Whether to return the flow-ja-face values “as is” (
True
) or in a grid form (False
).simulation_start_time (Optional datetime) – The time and date correpsonding to the beginning of the simulation. Use this to convert the time coordinates of the output array to calendar time/dates. time_unit must also be present if this argument is present.
time_unit (Optional str) – The time unit MF6 is working in, in string representation. Only used if simulation_start_time was provided. Admissible values are: ns -> nanosecond ms -> microsecond s -> second m -> minute h -> hour d -> day w -> week Units “month” or “year” are not supported, as they do not represent unambiguous timedelta values durations.
merge_to_dataset (bool, default value: False) – Merge output to dataset.
- Returns:
cbc_content – DataArray contains float64 data of the budgets, with dimensions (“time”, “layer”, “y”, “x”).
- Return type:
xr.Dataset | Dict[str, xr.DataArray]
Examples
Open a cbc file:
>>> import imod >>> cbc_content = imod.mf6.open_cbc("budgets.cbc", "my-model.grb")
Check the contents:
>>> print(cbc_content.keys())
Get the drainage budget, compute a time mean for the first layer:
>>> drn_budget = cbc_content["drn] >>> mean = drn_budget.sel(layer=1).mean("time")