gridmarthe.write_marthe_grid

gridmarthe.write_marthe_grid(ds, fileout='grid.out', varname='charge', file_permh=None, nan_value=9999.0, title=None, dims=None, debug=False)[source]

Write Dataset as MartheGrid v9 file

ds should contain x, y, dx, dy, attrs[[‘title’, ‘original_dimensions’]] in case of error, please use gridmarthe.reset_geometry() first. When providing a path to file_permh argument, this is called automatically.

A good pratice is to provide the permh file when writing dataset to marthegrid format.

>>> gm.write_marthe_grid(ds, 'toto.out', file_permh='./mymodel/model.permh')

WARNING: This function was developped to write parameters grids to marthe format. Not to recreate simulation results (hydraulic head at several timesteps for example) as gridmarthe format. This means that this function should not be used for dataset with several timesteps. Example, to create a new initial hydraulic head file based on simulation, select the timestep in dataset before writing.

>>> ds = ds_head.isel(time=16) # or do an aggregation (eg mean over a period)
>>> gm.write_marthe_grid(ds, 'mymodel.charg')
Parameters:
  • ds (xr.Dataset) – dataset containing data, coordinates (x,y[,z]), dx,dy and dimensions (in attrs).

  • fileout (str) – filename to write

  • varname (str, optional) – variable name (key) containing values.

  • file_permh (str, optional) – path to the permh file corresponding to current Marthe model. Needed to recreate full dimension if NaN dropped before.

  • nan_value (float, optional) – custom value to fillna, when using a permh field to reset geometry

  • title (str, optional) – title written in marthe grid file

  • dims (list of array, optional) –

    list containing array of dimension for every grid (ie len(dims) > 1 if nested grid)

    • format is [[x_main_grid, y_main_grid, z_main_grid], [x_nested_1, …], …]

    eg. [[354,252,2], [182,156,2]] - if only main grid : [[nx,ny,nz]] - if None (default, dims will be parsed from ds.attrs[‘original_dimensions’] which is added when read with gridmarthe.load_marthe_grid(). If not present (lost in some computation for example), please use py:func:gridmarthe.reset_geometry or provide list of dims manually.

  • debug (bool, optional) – print debug informations. Default is False

Returns:

status (int.) – 0 if everything’s ok. 1 otherwise.