flopy.utils.datafile module

Module to read MODFLOW output files. The module contains shared abstract classes that should not be directly accessed.

class Header(filetype=None, precision='single')[source]

Bases: object

The header class is an abstract base class to create headers for MODFLOW files

get_dtype()[source]

Return the dtype

get_names()[source]

Return the dtype names

get_values()[source]

Return the header values

class LayerFile(filename, precision, verbose, kwargs)[source]

Bases: object

The LayerFile class is the abstract base class from which specific derived classes are formed. LayerFile This class should not be instantiated directly.

close()[source]

Close the file handle.

get_alldata(mflay=None, nodata=- 9999)[source]

Get all of the data from the file.

Parameters
  • mflay (integer) – MODFLOW zero-based layer number to return. If None, then all all layers will be included. (Default is None.)

  • nodata (float) – The nodata value in the data array. All array values that have the nodata value will be assigned np.nan.

Returns

data – Array has size (ntimes, nlay, nrow, ncol) if mflay is None or it has size (ntimes, nrow, ncol) if mlay is specified.

Return type

numpy array

Notes

Examples

get_data(kstpkper=None, idx=None, totim=None, mflay=None)[source]

Get data from the file for the specified conditions.

Parameters
  • idx (int) – The zero-based record number. The first record is record 0.

  • kstpkper (tuple of ints) – A tuple containing the time step and stress period (kstp, kper). These are zero-based kstp and kper values.

  • totim (float) – The simulation time.

  • mflay (integer) – MODFLOW zero-based layer number to return. If None, then all all layers will be included. (Default is None.)

Returns

data – Array has size (nlay, nrow, ncol) if mflay is None or it has size (nrow, ncol) if mlay is specified.

Return type

numpy array

Notes

if both kstpkper and totim are None, will return the last entry

Examples

get_kstpkper()[source]

Get a list of unique stress periods and time steps in the file

Returns

out – List of unique kstp, kper combinations in binary file. kstp and kper values are presently zero-based.

Return type

list of (kstp, kper) tuples

get_times()[source]

Get a list of unique times in the file

Returns

out – List contains unique simulation times (totim) in binary file.

Return type

list of floats

list_records()[source]

Print a list of all of the records in the file obj.list_records()

plot(axes=None, kstpkper=None, totim=None, mflay=None, filename_base=None, **kwargs)[source]

Plot 3-D model output data in a specific location in LayerFile instance

Parameters
  • axes (list of matplotlib.pyplot.axis) – List of matplotlib.pyplot.axis that will be used to plot data for each layer. If axes=None axes will be generated. (default is None)

  • kstpkper (tuple of ints) – A tuple containing the time step and stress period (kstp, kper). These are zero-based kstp and kper values.

  • totim (float) – The simulation time.

  • mflay (int) – MODFLOW zero-based layer number to return. If None, then all all layers will be included. (default is None)

  • filename_base (str) – Base file name that will be used to automatically generate file names for output image files. Plots will be exported as image files if file_name_base is not None. (default is None)

  • **kwargs (dict) –

    pcolorbool

    Boolean used to determine if matplotlib.pyplot.pcolormesh plot will be plotted. (default is True)

    colorbarbool

    Boolean used to determine if a color bar will be added to the matplotlib.pyplot.pcolormesh. Only used if pcolor=True. (default is False)

    contourbool

    Boolean used to determine if matplotlib.pyplot.contour plot will be plotted. (default is False)

    clabelbool

    Boolean used to determine if matplotlib.pyplot.clabel will be plotted. Only used if contour=True. (default is False)

    gridbool

    Boolean used to determine if the model grid will be plotted on the figure. (default is False)

    masked_valueslist

    List of unique values to be excluded from the plot.

    file_extensionstr

    Valid matplotlib.pyplot file extension for savefig(). Only used if filename_base is not None. (default is ‘png’)

Return type

None

Notes

Examples

>>> import flopy
>>> hdobj = flopy.utils.HeadFile('test.hds')
>>> times = hdobj.get_times()
>>> hdobj.plot(totim=times[-1])
to_shapefile(filename, kstpkper=None, totim=None, mflay=None, attrib_name='lf_data')[source]
Export model output data to a shapefile at a specific location

in LayerFile instance.

Parameters
  • filename (str) – Shapefile name to write

  • kstpkper (tuple of ints) – A tuple containing the time step and stress period (kstp, kper). These are zero-based kstp and kper values.

  • totim (float) – The simulation time.

  • mflay (integer) – MODFLOW zero-based layer number to return. If None, then layer 1 will be written

  • attrib_name (str) – Base name of attribute columns. (default is ‘lf_data’)

Return type

None

Notes

Examples

>>> import flopy
>>> hdobj = flopy.utils.HeadFile('test.hds')
>>> times = hdobj.get_times()
>>> hdobj.to_shapefile('test_heads_sp6.shp', totim=times[-1])