flopy.utils.datafile Module

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

class flopy.utils.datafile.Header(filetype=None, precision='single')

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

get_dtype()

Return the dtype

get_names()

Return the dtype names

get_values()

Return the header values

class flopy.utils.datafile.LayerFile(filename, precision, verbose, kwargs)

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

close()

Close the file handle.

get_alldata(mflay=None, nodata=-9999)

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 : numpy array

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

get_data(kstpkper=None, idx=None, totim=None, mflay=None)

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 : numpy array

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

Notes

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

get_kstpkper()

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

Returns:

out : list of (kstp, kper) tuples

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

get_times()

Get a list of unique times in the file

Returns:

out : list of floats

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

list_records()

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)

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

pcolor
: bool

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

colorbar
: bool

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

contour
: bool

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

clabel
: bool

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

grid
: bool

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

masked_values
: list

List of unique values to be excluded from the plot.

file_extension
: str

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

Returns:

None

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')
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’)

Returns:

None

Examples

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