flopy.utils.modpathfile module

Support for MODPATH output files.

class EndpointFile(filename: str | PathLike, verbose: bool = False)[source]

Bases: ModpathFile

Particle endpoint file.

Parameters:
  • filename (str or PathLike) – Path of the endpoint file

  • verbose (bool) – Show verbose output. Default is False.

Examples

>>> import flopy
>>> ep_file = flopy.utils.EndpointFile('model.mpend')
>>> ep1 = endobj.get_data(partid=1)
dtypes = {3: dtype([('zone', '<i4'), ('j', '<i4'), ('i', '<i4'), ('k', '<i4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('zloc', '<f4'), ('time', '<f4'), ('x0', '<f4'), ('y0', '<f4'), ('zloc0', '<f4'), ('j0', '<i4'), ('i0', '<i4'), ('k0', '<i4'), ('zone0', '<i4'), ('cumulativetimestep', '<i4'), ('ipcode', '<i4'), ('time0', '<f4')]), 5: dtype([('zone', '<i4'), ('j', '<i4'), ('i', '<i4'), ('k', '<i4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('zloc', '<f4'), ('time', '<f4'), ('x0', '<f4'), ('y0', '<f4'), ('zloc0', '<f4'), ('j0', '<i4'), ('i0', '<i4'), ('k0', '<i4'), ('zone0', '<i4'), ('cumulativetimestep', '<i4'), ('ipcode', '<i4'), ('time0', '<f4')]), 6: dtype([('particleid', '<i4'), ('particlegroup', '<i4'), ('status', '<i4'), ('time0', '<f4'), ('time', '<f4'), ('initialgrid', '<i4'), ('k0', '<i4'), ('i0', '<i4'), ('j0', '<i4'), ('cellface0', '<i4'), ('zone0', '<i4'), ('xloc0', '<f4'), ('yloc0', '<f4'), ('zloc0', '<f4'), ('x0', '<f4'), ('y0', '<f4'), ('z0', '<f4'), ('finalgrid', '<i4'), ('k', '<i4'), ('i', '<i4'), ('j', '<i4'), ('cellface', '<i4'), ('zone', '<i4'), ('xloc', '<f4'), ('yloc', '<f4'), ('zloc', '<f4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('label', 'S40')]), 7: dtype([('particleid', '<i4'), ('particlegroup', '<i4'), ('particleidloc', '<i4'), ('status', '<i4'), ('time0', '<f4'), ('time', '<f4'), ('node0', '<i4'), ('k0', '<i4'), ('xloc0', '<f4'), ('yloc0', '<f4'), ('zloc0', '<f4'), ('x0', '<f4'), ('y0', '<f4'), ('z0', '<f4'), ('zone0', '<i4'), ('initialcellface', '<i4'), ('node', '<i4'), ('k', '<i4'), ('xloc', '<f4'), ('yloc', '<f4'), ('zloc', '<f4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('zone', '<i4'), ('cellface', '<i4')])}
get_alldata()[source]

Get endpoint data from the endpoint file for all endpoints.

Returns:

data – A numpy recarray with the endpoint particle data

Return type:

numpy record array

Notes

Examples

>>> import flopy
>>> endobj = flopy.utils.EndpointFile('model.mpend')
>>> e = endobj.get_alldata()
get_destination_endpoint_data(dest_cells, source=False)[source]

Get endpoint data that terminate in a set of destination cells.

Parameters:
  • dest_cells (list or array of tuples) – (k, i, j) of each destination cell for MODPATH versions less than MODPATH 7 or node number of each destination cell. (zero based)

  • source (bool) – Boolean to specify is dest_cells applies to source or destination cells (default is False).

Returns:

Slice of endpoint data array (e.g. EndpointFile.get_alldata) containing only endpoint data with final locations in (k,i,j) or (node) dest_cells.

Return type:

np.recarray

Examples

>>> import flopy
>>> e = flopy.utils.EndpointFile('modpath.endpoint')
>>> e0 = e.get_destination_endpoint_data([(0, 0, 0),
...                                       (1, 0, 0)])
get_maxtraveltime()[source]

Get the maximum travel time.

Returns:

out – Maximum travel time.

Return type:

float

kijnames = ['k0', 'i0', 'j0', 'node0', 'k', 'i', 'j', 'node', 'particleid', 'particlegroup', 'particleidloc', 'zone0', 'zone']
write_shapefile(data=None, endpoint_data=None, shpname='endpoints.shp', direction='ending', mg=None, crs=None, **kwargs)[source]

Write particle starting / ending locations to shapefile.

datanp.recarray

Record array of same form as that returned by EndpointFile.get_alldata. (if none, EndpointFile.get_alldata() is exported).

endpoint_datanp.recarray

Record array of same form as that returned by EndpointFile.get_alldata. (if none, EndpointFile.get_alldata() is exported).

Deprecated since version 3.7: The endpoint_data option will be removed for FloPy 4. Use data instead.

shpnamestr

File path for shapefile

directionstr

String defining if starting or ending particle locations should be considered. (default is ‘ending’)

mgflopy.discretization.grid instance

Used to scale and rotate Global x,y,z values in MODPATH Endpoint file.

crspyproj.CRS, int, str, optional

Coordinate reference system (CRS) for the model grid (must be projected; geographic CRS are not supported). The value can be anything accepted by pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:26916”) or a WKT string.

kwargs : keyword arguments to flopy.export.shapefile_utils.recarray2shp

Deprecated since version 3.5: The following keyword options will be removed for FloPy 3.6: - epsg (int): use crs instead.

class ModpathFile(filename: str | PathLike, verbose: bool = False)[source]

Bases: ParticleTrackFile

Provides MODPATH output file support.

intersect(cells, to_recarray) List[recarray] | recarray[source]

Find intersection of pathlines with cells.

static parse(file_path: str | PathLike, file_type: str) Tuple[bool, int, int, int | None][source]
Extract preliminary information from a MODPATH output file:
  • whether in compact format

  • how many rows to skip

  • the MODPATH version

Parameters:
  • file_path (str or PathLike) – The output file path

  • file_type (str) – The output file type: pathline, endpoint, or timeseries

Returns:

out – A tuple (compact, skiprows, version)

Return type:

bool, int, int

class PathlineFile(filename: str | PathLike, verbose: bool = False)[source]

Bases: ModpathFile

Particle pathline file.

Parameters:
  • filename (str or PathLike) – Path of the pathline file

  • verbose (bool) – Show verbose output. Default is False.

Examples

>>> import flopy
>>> pl_file = flopy.utils.PathlineFile('model.mppth')
>>> pl1 = pthobj.get_data(partid=1)
dtypes = {3: dtype([('particleid', '<i4'), ('x', '<f4'), ('y', '<f4'), ('zloc', '<f4'), ('z', '<f4'), ('time', '<f4'), ('j', '<i4'), ('i', '<i4'), ('k', '<i4'), ('cumulativetimestep', '<i4')]), 5: dtype([('particleid', '<i4'), ('x', '<f4'), ('y', '<f4'), ('zloc', '<f4'), ('z', '<f4'), ('time', '<f4'), ('j', '<i4'), ('i', '<i4'), ('k', '<i4'), ('cumulativetimestep', '<i4')]), 6: dtype([('particleid', '<i4'), ('particlegroup', '<i4'), ('timepointindex', '<i4'), ('cumulativetimestep', '<i4'), ('time', '<f4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('k', '<i4'), ('i', '<i4'), ('j', '<i4'), ('grid', '<i4'), ('xloc', '<f4'), ('yloc', '<f4'), ('zloc', '<f4'), ('linesegmentindex', '<i4')]), 7: dtype([('particleid', '<i4'), ('particlegroup', '<i4'), ('sequencenumber', '<i4'), ('particleidloc', '<i4'), ('time', '<f4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('k', '<i4'), ('node', '<i4'), ('xloc', '<f4'), ('yloc', '<f4'), ('zloc', '<f4'), ('stressperiod', '<i4'), ('timestep', '<i4')])}
get_destination_pathline_data(dest_cells, to_recarray=False)[source]

Get pathline data that pass through a set of destination cells.

Parameters:
  • dest_cells (list or array of tuples) – (k, i, j) of each destination cell for MODPATH versions less than MODPATH 7 or node number of each destination cell. (zero based)

  • to_recarray (bool) – Boolean that controls returned pthldest. If to_recarray is True, a single recarray with all of the pathlines that intersect dest_cells are returned. If to_recarray is False, a list of recarrays (the same form as returned by get_alldata method) that intersect dest_cells are returned (default is False).

Returns:

Slice of pathline data array (e.g. PathlineFile._data) containing only pathlines that pass through (k,i,j) or (node) dest_cells.

Return type:

np.recarray

Examples

>>> import flopy
>>> p = flopy.utils.PathlineFile('modpath.pathline')
>>> p0 = p.get_destination_pathline_data([(0, 0, 0),
...                                       (1, 0, 0)])
kijnames = ['k', 'i', 'j', 'node', 'particleid', 'particlegroup', 'linesegmentindex', 'particleidloc', 'sequencenumber']
write_shapefile(data=None, pathline_data=None, one_per_particle=True, direction='ending', shpname='pathlines.shp', mg=None, crs=None, **kwargs)[source]

Write pathlines to a shapefile.

Parameters:
  • data (np.recarray) – Record array of same form as that returned by .get_alldata() (if None, .get_alldata() is exported).

  • timeseries_data (np.recarray) –

    Record array of same form as that returned by .get_alldata() (if None, .get_alldata() is exported).

    Deprecated since version 3.7: The timeseries_data option will be removed for FloPy 4. Use data instead.

  • one_per_particle (boolean (default True)) – True writes a single LineString with a single set of attribute data for each particle. False writes a record/geometry for each pathline segment (each row in the Timeseries file). This option can be used to visualize attribute information (time, model layer, etc.) across a pathline in a GIS.

  • direction (str) – String defining if starting or ending particle locations should be included in shapefile attribute information. Only used if one_per_particle=False. (default is ‘ending’)

  • shpname (str) – File path for shapefile

  • mg (flopy.discretization.grid instance) – Used to scale and rotate Global x,y,z values in MODPATH Timeseries file.

  • crs (pyproj.CRS, int, str, optional) – Coordinate reference system (CRS) for the model grid (must be projected; geographic CRS are not supported). The value can be anything accepted by pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:26916”) or a WKT string.

  • kwargs (keyword arguments to flopy.export.shapefile_utils.recarray2shp) –

    Deprecated since version 3.5: The following keyword options will be removed for FloPy 3.6: - epsg (int): use crs instead.

class TimeseriesFile(filename, verbose=False)[source]

Bases: ModpathFile

Particle timeseries file.

Parameters:
  • filename (str or PathLike) – Path of the timeseries file

  • verbose (bool) – Show verbose output. Default is False.

Examples

>>> import flopy
>>> ts_file = flopy.utils.TimeseriesFile('model.timeseries')
>>> ts1 = tsobj.get_data(partid=1)
dtypes = {3: dtype([('timestepindex', '<i4'), ('particleid', '<i4'), ('node', '<i4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('zloc', '<f4'), ('time', '<f4'), ('timestep', '<i4')]), 5: dtype([('timestepindex', '<i4'), ('particleid', '<i4'), ('node', '<i4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('zloc', '<f4'), ('time', '<f4'), ('timestep', '<i4')]), 6: dtype([('timepointindex', '<i4'), ('timestep', '<i4'), ('time', '<f4'), ('particleid', '<i4'), ('particlegroup', '<i4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('grid', '<i4'), ('k', '<i4'), ('i', '<i4'), ('j', '<i4'), ('xloc', '<f4'), ('yloc', '<f4'), ('zloc', '<f4')]), 7: dtype([('timepointindex', '<i4'), ('timestep', '<i4'), ('time', '<f4'), ('particleid', '<i4'), ('particlegroup', '<i4'), ('particleidloc', '<i4'), ('node', '<i4'), ('xloc', '<f4'), ('yloc', '<f4'), ('zloc', '<f4'), ('x', '<f4'), ('y', '<f4'), ('z', '<f4'), ('k', '<i4')])}
get_destination_timeseries_data(dest_cells)[source]

Get timeseries data that pass through a set of destination cells.

Parameters:

dest_cells (list or array of tuples) – (k, i, j) of each destination cell for MODPATH versions less than MODPATH 7 or node number of each destination cell. (zero based)

Returns:

Slice of timeseries data array (e.g. TmeseriesFile._data) containing only timeseries that pass through (k,i,j) or (node) dest_cells.

Return type:

np.recarray

Examples

>>> import flopy
>>> ts = flopy.utils.TimeseriesFile('modpath.timeseries')
>>> tss = ts.get_destination_timeseries_data([(0, 0, 0),
...                                           (1, 0, 0)])
kijnames = ['k', 'i', 'j', 'node', 'particleid', 'particlegroup', 'particleidloc', 'timestep', 'timestepindex', 'timepointindex']
write_shapefile(data=None, timeseries_data=None, one_per_particle=True, direction='ending', shpname='pathlines.shp', mg=None, crs=None, **kwargs)[source]

Write timeseries to a shapefile

datanp.recarray

Record array of same form as that returned by Timeseries.get_alldata(). (if none, Timeseries.get_alldata() is exported).

timeseries_datanp.recarray

Record array of same form as that returned by Timeseries.get_alldata(). (if none, Timeseries.get_alldata() is exported).

Deprecated since version 3.7: The timeseries_data option will be removed for FloPy 4. Use data instead.

one_per_particleboolean (default True)

True writes a single LineString with a single set of attribute data for each particle. False writes a record/geometry for each pathline segment (each row in the Timeseries file). This option can be used to visualize attribute information (time, model layer, etc.) across a pathline in a GIS.

directionstr

String defining if starting or ending particle locations should be included in shapefile attribute information. Only used if one_per_particle=False. (default is ‘ending’)

shpnamestr

File path for shapefile

mgflopy.discretization.grid instance

Used to scale and rotate Global x,y,z values in MODPATH Timeseries file.

crspyproj.CRS, int, str, optional

Coordinate reference system (CRS) for the model grid (must be projected; geographic CRS are not supported). The value can be anything accepted by pyproj.CRS.from_user_input(), such as an authority string (eg “EPSG:26916”) or a WKT string.

kwargs : keyword arguments to flopy.export.shapefile_utils.recarray2shp

Deprecated since version 3.5: The following keyword options will be removed for FloPy 3.6: - epsg (int): use crs instead.