flopy.export.utils module

array2d_export(f: str | PathLike, u2d, fmt=None, verbose=False, **kwargs)[source]

export helper for Util2d instances

Parameters:
  • f (str or PathLike) – filename or existing export instance type (NetCdf only for now)

  • u2d (Util2d instance) –

  • fmt (str) – output format flag. ‘vtk’ will export to vtk

  • verbose (bool) – whether to print verbose output

  • **kwargs (keyword arguments) –

    min_valid : minimum valid value max_valid : maximum valid value modelgrid : flopy.discretization.Grid

    model grid instance which will supersede the flopy.model.modelgrid

    if fmt is set to ‘vtk’, parameters of Vtk initializer

array3d_export(f: str | PathLike, u3d, fmt=None, **kwargs)[source]

export helper for Transient2d instances

Parameters:
  • f (str or PathLike) – filename or existing export instance type (NetCdf only for now)

  • u3d (Util3d instance) –

  • fmt (str) – output format flag. ‘vtk’ will export to vtk

  • **kwargs (keyword arguments) –

    min_valid : minimum valid value max_valid : maximum valid value modelgrid : flopy.discretization.Grid

    model grid instance which will supersede the flopy.model.modelgrid

    if fmt is set to ‘vtk’, parameters of Vtk initializer

contour_array(modelgrid, ax, a, layer=0, **kwargs)[source]

Create a QuadMesh plot of the specified array using pcolormesh

Parameters:
  • modelgrid (flopy.discretization.Grid object) – modelgrid object

  • ax (matplotlib.axes.Axes) – ax to add the contours

  • a (np.ndarray) – array to contour

  • layer (int, optional) – layer to contour

Returns:

contour_set

Return type:

ContourSet

ensemble_helper(inputs_filename: str | PathLike, outputs_filename: str | PathLike, models, add_reals=True, **kwargs)[source]

Helper to export an ensemble of model instances. Assumes all models have same dis and reference information, only difference is properties and boundary conditions. Assumes model.nam.split(‘_’)[-1] is the realization suffix to use in the netcdf variable names

export_array(modelgrid, filename: str | PathLike, a, nodata=-9999, fieldname='value', verbose=False, **kwargs)[source]

Write a numpy array to Arc Ascii grid or shapefile with the model reference.

Parameters:
  • modelgrid (flopy.discretization.StructuredGrid object) – model grid

  • filename (str or PathLike) – Path of output file. Export format is determined by file extension. ‘.asc’ Arc Ascii grid ‘.tif’ GeoTIFF (requires rasterio package) ‘.shp’ Shapefile

  • a (2D numpy.ndarray) – Array to export

  • nodata (scalar) – Value to assign to np.nan entries (default -9999)

  • fieldname (str) – Attribute field name for array values (shapefile export only). (default ‘values’)

  • verbose (bool, optional, default False) – whether to show verbose output

  • kwargs – keyword arguments to np.savetxt (ascii) rasterio.open (GeoTIFF) or flopy.export.shapefile_utils.write_grid_shapefile

Notes

Rotated grids will be either be unrotated prior to export, using scipy.ndimage.rotate (Arc Ascii format) or rotation will be included in their transform property (GeoTiff format). In either case the pixels will be displayed in the (unrotated) projected geographic coordinate system, so the pixels will no longer align exactly with the model grid (as displayed from a shapefile, for example). A key difference between Arc Ascii and GeoTiff (besides disk usage) is that the unrotated Arc Ascii will have a different grid size, whereas the GeoTiff will have the same number of rows and pixels as the original.

export_array_contours(modelgrid, filename: str | PathLike, a, fieldname='level', interval=None, levels=None, maxlevels=1000, **kwargs)[source]

Contour an array using matplotlib; write shapefile of contours.

Parameters:
  • modelgrid (flopy.discretization.Grid object) – model grid object

  • filename (str or PathLike) – Path of output file with ‘.shp’ extension.

  • a (2D numpy array) – Array to contour

  • fieldname (str) – gis field name

  • interval (float) – interval to calculate levels from

  • levels (list) – list of contour levels

  • maxlevels (int) – maximum number of contour levels

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

export_contourf(filename, contours, fieldname='level', verbose=False, **kwargs)[source]

Write matplotlib filled contours to shapefile.

Parameters:
  • filename (str or PathLike) – name of output shapefile (e.g. myshp.shp)

  • contours (matplotlib.contour.QuadContourSet or list of them) – (object returned by matplotlib.pyplot.contourf)

  • fieldname (str) – Name of shapefile attribute field to contain the contour level. The fieldname column in the attribute table will contain the lower end of the range represented by the polygon. Default is ‘level’.

  • verbose (bool, optional, default False) – whether to show verbose output

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

Return type:

None

Examples

>>> import flopy
>>> import matplotlib.pyplot as plt
>>> from flopy.export.utils import export_contourf
>>> a = np.random.random((10, 10))
>>> cs = plt.contourf(a)
>>> export_contourf('myfilledcontours.shp', cs)
export_contours(filename: str | PathLike, contours, fieldname='level', verbose=False, **kwargs)[source]

Convert matplotlib contour plot object to shapefile.

Parameters:
  • filename (str or PathLike) – path of output shapefile

  • contours (matplotlib.contour.QuadContourSet or list of them) – (object returned by matplotlib.pyplot.contour)

  • fieldname (str) – gis attribute table field name

  • verbose (bool, optional, default False) – whether to show verbose output

  • **kwargs (key-word arguments to flopy.export.shapefile_utils.recarray2shp) –

Returns:

df

Return type:

dataframe of shapefile contents

generic_array_export(f: str | PathLike, array, var_name='generic_array', dimensions=('time', 'layer', 'y', 'x'), precision_str='f4', units='unitless', **kwargs)[source]

Method to export a generic array to NetCdf

Parameters:
  • f (str or PathLike) – filename or existing export instance type (NetCdf only for now)

  • array (np.ndarray) –

  • var_name (str) – variable name

  • dimensions (tuple) – netcdf dimensions

  • precision_str (str) – binary precision string, default “f4”

  • units (string) – units of array data

  • **kwargs (keyword arguments) –

    modelflopy.modflow.mbase

    flopy model object

mflist_export(f: str | PathLike | NetCdf, mfl, **kwargs)[source]

export helper for MfList instances

Parameters:
  • f (str or PathLike or NetCdf) – file path or existing export instance type (NetCdf only for now)

  • mfl (MfList instance) –

  • **kwargs (keyword arguments) –

    modelgridflopy.discretization.Grid

    model grid instance which will supersede the flopy.model.modelgrid

    crspyproj.CRS, int, str, optional if prjfile is specified

    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.

    prjfilestr or pathlike, optional if crs is specified

    ESRI-style projection file with well-known text defining the CRS for the model grid (must be projected; geographic CRS are not supported).

model_export(f: str | PathLike | NetCdf | dict, ml, fmt=None, **kwargs)[source]

Method to export a model to a shapefile or netcdf file

Parameters:
  • f (str or PathLike or NetCdf or dict) – file path (“.nc” for netcdf or “.shp” for shapefile) or NetCDF object or dictionary

  • ml (flopy.modflow.mbase.ModelInterface object) – flopy model object

  • fmt (str) – output format flag. ‘vtk’ will export to vtk

  • **kwargs (keyword arguments) –

    modelgrid: flopy.discretization.Grid

    user supplied modelgrid object which will supersede the built in modelgrid object

    crspyproj.CRS, int, str, optional if prjfile is specified

    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.

    prjfilestr or pathlike, optional if crs is specified

    ESRI-style projection file with well-known text defining the CRS for the model grid (must be projected; geographic CRS are not supported).

    if fmt is set to ‘vtk’, parameters of Vtk initializer

output_helper(f: str | PathLike | NetCdf | dict, ml, oudic, verbose=False, **kwargs)[source]

Export model outputs using the model spatial reference info.

Parameters:
  • f (str or PathLike or NetCdf or dict) – filepath to write output to (must have .shp or .nc extension), NetCDF object, or dictionary

  • ml (flopy.mbase.ModelInterface derived type) –

  • oudic (dict) – output_filename,flopy datafile/cellbudgetfile instance

  • verbose (bool) – whether to show verbose output

  • **kwargs (keyword arguments) –

    modelgridflopy.discretizaiton.Grid

    user supplied model grid instance that will be used for export in lieu of the models model grid instance

    mflayint

    zero based model layer which can be used in shapefile exporting

    kperint

    zero based stress period which can be used for shapefile exporting

Return type:

None

Note:

casts down double precision to single precision for netCDF files

package_export(f: str | PathLike | NetCdf | dict, pak, fmt=None, verbose=False, **kwargs)[source]

Method to export a package to shapefile or netcdf

Parameters:
  • f (str or PathLike or NetCdf or dict) – output file path (extension .shp for shapefile or .nc for netcdf) or NetCDF object or dictionary

  • pak (flopy.pakbase.Package object) – package to export

  • fmt (str) – output format flag. ‘vtk’ will export to vtk

  • kwargs (**) –

    modelgrid: flopy.discretization.Grid

    user supplied modelgrid object which will supersede the built in modelgrid object

    crspyproj.CRS, int, str, optional if prjfile is specified

    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.

    prjfilestr or pathlike, optional if crs is specified

    ESRI-style projection file with well-known text defining the CRS for the model grid (must be projected; geographic CRS are not supported).

    if fmt is set to ‘vtk’, parameters of Vtk initializer

Returns:

f

Return type:

NetCdf object or None

transient2d_export(f: str | PathLike, t2d, fmt=None, **kwargs)[source]

export helper for Transient2d instances

Parameters:
  • f (str or PathLike) – filename or existing export instance type (NetCdf only for now)

  • t2d (Transient2d instance) –

  • fmt (str) – output format flag. ‘vtk’ will export to vtk

  • **kwargs (keyword arguments) –

    min_valid : minimum valid value max_valid : maximum valid value modelgrid : flopy.discretization.Grid

    model grid instance which will supersede the flopy.model.modelgrid

    if fmt is set to ‘vtk’, parameters of Vtk initializer