flopy.export.utils module

array2d_export(f, u2d, fmt=None, **kwargs)[source]

export helper for Util2d instances

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

  • u2d (Util2d 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 supercede the flopy.model.modelgrid

    if fmt is set to ‘vtk’, parameters of vtk.export_array

array3d_export(f, u3d, fmt=None, **kwargs)[source]

export helper for Transient2d instances

Parameters
  • f (str) – 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 supercede the flopy.model.modelgrid

    if fmt is set to ‘vtk’, parameters of vtk.export_array

contour_array(modelgrid, ax, a, **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

Returns

contour_set

Return type

ContourSet

ensemble_helper(inputs_filename, outputs_filename, 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, a, nodata=- 9999, fieldname='value', **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) – Path of output file. Export format is determined by file extention. ‘.asc’ Arc Ascii grid ‘.tif’ GeoTIFF (requries 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’)

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

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, a, fieldname='level', interval=None, levels=None, maxlevels=1000, epsg=None, prj=None, **kwargs)[source]

Contour an array using matplotlib; write shapefile of contours.

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

  • filename (str) – Path of output file with ‘.shp’ extention.

  • 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

  • epsg (int) – EPSG code. See https://www.epsg-registry.org/ or spatialreference.org

  • prj (str) – Existing projection file to be used with new shapefile.

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

export_contourf(filename, contours, fieldname='level', epsg=None, prj=None, **kwargs)[source]

Write matplotlib filled contours to shapefile.

Parameters
  • filename (str) – 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’.

  • epsg (int) – EPSG code. See https://www.epsg-registry.org/ or spatialreference.org

  • prj (str) – Existing projection file to be used with new shapefile.

  • **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(modelgrid, filename, contours, fieldname='level', epsg=None, prj=None, **kwargs)[source]

Convert matplotlib contour plot object to shapefile.

Parameters
  • modelgrid (flopy.discretization.Grid) – flopy modelgrid instance

  • filename (str) – 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

  • epsg (int) – EPSG code. See https://www.epsg-registry.org/ or spatialreference.org

  • prj (str) – Existing projection file to be used with new shapefile.

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

Returns

df

Return type

dataframe of shapefile contents

generic_array_export(f, 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) – 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, mfl, **kwargs)[source]

export helper for MfList instances

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

  • mfl (MfList instance) –

  • **kwargs (keyword arguments) –

    modelgridflopy.discretization.Grid

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

model_export(f, ml, fmt=None, **kwargs)[source]

Method to export a model to a shapefile or netcdf file

Parameters
  • f (str) – file name (“.nc” for netcdf or “.shp” for shapefile) or dictionary of ….

  • 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 supercede the built in modelgrid object

    epsgint

    epsg projection code

    prjstr

    prj file name

    if fmt is set to ‘vtk’, parameters of vtk.export_model

output_helper(f, ml, oudic, **kwargs)[source]

Export model outputs using the model spatial reference info.

Parameters
  • f (str) – filename for output - must have .shp or .nc extension

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

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

  • **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

casts down double precision to single precision for netCDF files

package_export(f, pak, fmt=None, **kwargs)[source]

Method to export a package to shapefile or netcdf

Parameters
  • f (str) – output file name (ends in .shp for shapefile or .nc for netcdf)

  • 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 supercede the built in modelgrid object

    epsgint

    epsg projection code

    prjstr

    prj file name

    if fmt is set to ‘vtk’, parameters of vtk.export_package

Returns

f

Return type

NetCdf object or None

transient2d_export(f, t2d, fmt=None, **kwargs)[source]

export helper for Transient2d instances

Parameters
  • f (str) – 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 supercede the flopy.model.modelgrid

    if fmt is set to ‘vtk’, parameters of vtk.export_transient