imod.formats.ipf.save#

imod.formats.ipf.save(path, df, itype=None, assoc_ext='txt', nodata=1e+20, assoc_columns=None)[source]#

Saves the contents of a pandas DataFrame to one or more IPF files, and associated (TXT) files.

Can write multiple IPF files if one of the columns is named “layer”. In turn, multiple associated (TXT) files may written for each of these IPF files. Note that the ID must be unique for each layer. See the examples.

Parameters
  • path (pathlib.Path or str) – path of the written IPF file. Any associated files are written relative to this path, based on the ID column.

  • df (pandas.DataFrame) – DataFrame containing the data to write.

  • itype (int or str or None) –

    IPF type. Defaults to None, in which case no associated files are created. Possible other values, either integer or string:

    • 1 or "timeseries"

    • 2 or "borehole1d"

    • 3 or "cpt"

    • 4 or "borehole3d"

  • assoc_ext (str) – Extension of the associated files. Defaults to “txt”.

  • nodata (float) – The value given to nodata values. These are generally NaN (Not-a-Number) in pandas, but this leads to errors in iMOD(FLOW) for IDFs. Defaults to value of 1.0e20 instead.

  • assoc_columns (optional, list or dict) – Columns to store in the associated file. In case of a dictionary, the columns will be renamed according to the mapping in the dictionary. Defaults to None.

Returns

Writes files.

Return type

None

Examples

To write a single IPF without associated timeseries or boreholes:

>>> imod.ipf.save("static-data.ipf", df)

To write timeseries data:

>>> imod.ipf.save("transient-data.ipf", df, itype="timeseries")

If a "layer" column is present, make sure the ID is unique per layer:

>>> df["id"] = df["id"].str.cat(df["layer"], sep="_")
>>> imod.ipf.save("layered.ipf", df, itype="timeseries")

An error will be raised otherwise.