pymake.autotest.autotest module

A typical example of using the autotest functionality for MODFLOW-2005 and comparing the MODFLOW-2005 results to MODFLOW-2000 results is:

import pymake

# Setup
testpth = "../test/mytest"
nam1 = "model1.nam"
pymake.setup(nam1, testpth)

# run test models
success, buff = flopy.run_model(
        "mf2005", nam1, model_ws=testpth, silent=True
    )
if success:
    testpth_reg = os.path.join(testpth, "mf2000")
    nam2 = "model2.name"
    pymake.setup(nam2, testpth_reg)
    success_reg, buff = flopy.run_model(
            "mf2000", nam2, model_ws=testpth_reg, silent=True
        )

# compare results
if success and success_reg:
    fpth = os.path.split(os.path.join(testpth, nam1))[0]
    outfile1 = os.path.join(fpth, "bud.cmp")
    fpth = os.path.split(os.path.join(testpth, nam2))[0]
    outfile2 = os.path.join(fpth, "hds.cmp")
    success_reg = pymake.compare(
        os.path.join(testpth, nam1),
        os.path.join(testpth_reg, nam2),
        max_cumpd=0.01,
        max_incpd=0.01,
        htol=0.001,
        outfile1=outfile1,
        outfile2=outfile2,
    )

# Clean things up
if success_reg:
    pymake.teardown(testpth)

Note: autotest functionality will likely be removed from pymake in the future to a dedicated GitHub repository.

compare(namefile1, namefile2, precision='auto', max_cumpd=0.01, max_incpd=0.01, htol=0.001, outfile1=None, outfile2=None, files1=None, files2=None)[source]

Compare the budget and head results for two MODFLOW-based model simulations.

Parameters
  • namefile1 (str) – namefile path for base model

  • namefile2 (str) – namefile path for comparison model

  • precision (str) – precision for binary head file (“auto”, “single”, or “double”) default is “auto”

  • max_cumpd (float) – maximum percent discrepancy allowed for cumulative budget terms (default is 0.01)

  • max_incpd (float) – maximum percent discrepancy allowed for incremental budget terms (default is 0.01)

  • htol (float) – maximum allowed head difference (default is 0.001)

  • outfile1 (str) – budget comparison output file name. If outfile1 is None, no budget comparison output is saved. (default is None)

  • outfile2 (str) – head comparison output file name. If outfile2 is None, no head comparison output is saved. (default is None)

  • files1 (str) – base model output file. If files1 is not None, results will be extracted from files1 and namefile1 will not be used. (default is None)

  • files2 (str) – comparison model output file. If files2 is not None, results will be extracted from files2 and namefile2 will not be used. (default is None)

Returns

success – boolean indicating if the budget and head differences are less than max_cumpd, max_incpd, and htol.

Return type

bool

compare_budget(namefile1, namefile2, max_cumpd=0.01, max_incpd=0.01, outfile=None, files1=None, files2=None)[source]

Compare the budget results from two simulations.

Parameters
  • namefile1 (str) – namefile path for base model

  • namefile2 (str) – namefile path for comparison model

  • max_cumpd (float) – maximum percent discrepancy allowed for cumulative budget terms (default is 0.01)

  • max_incpd (float) – maximum percent discrepancy allowed for incremental budget terms (default is 0.01)

  • outfile (str) – budget comparison output file name. If outfile is None, no comparison output is saved. (default is None)

  • files1 (str) – base model output file. If files1 is not None, results will be extracted from files1 and namefile1 will not be used. (default is None)

  • files2 (str) – comparison model output file. If files2 is not None, results will be extracted from files2 and namefile2 will not be used. (default is None)

Returns

success – boolean indicating if the difference between budgets are less than max_cumpd and max_incpd

Return type

bool

compare_concs(namefile1, namefile2, precision='auto', ctol=0.001, outfile=None, files1=None, files2=None, difftol=False, verbose=False)[source]

Compare the mt3dms and mt3dusgs concentration results from two simulations.

Parameters
  • namefile1 (str) – namefile path for base model

  • namefile2 (str) – namefile path for comparison model

  • precision (str) – precision for binary head file (“auto”, “single”, or “double”) default is “auto”

  • ctol (float) – maximum allowed concentration difference (default is 0.001)

  • outfile (str) – concentration comparison output file name. If outfile is None, no comparison output is saved. (default is None)

  • files1 (str) – base model output file. If files1 is not None, results will be extracted from files1 and namefile1 will not be used. (default is None)

  • files2 (str) – comparison model output file. If files2 is not None, results will be extracted from files2 and namefile2 will not be used. (default is None)

  • difftol (bool) – boolean determining if the absolute value of the concentration difference greater than ctol should be evaluated (default is False)

  • verbose (bool) – boolean indicating if verbose output should be written to the terminal (default is False)

Returns

success – boolean indicating if the concentration differences are less than ctol.

Return type

bool

compare_heads(namefile1, namefile2, precision='auto', text='head', text2=None, htol=0.001, outfile=None, files1=None, files2=None, difftol=False, verbose=False, exfile=None, exarr=None, maxerr=None)[source]

Compare the head results from two simulations.

Parameters
  • namefile1 (str) – namefile path for base model

  • namefile2 (str) – namefile path for comparison model

  • precision (str) – precision for binary head file (“auto”, “single”, or “double”) default is “auto”

  • htol (float) – maximum allowed head difference (default is 0.001)

  • outfile (str) – head comparison output file name. If outfile is None, no comparison output is saved. (default is None)

  • files1 (str) – base model output file. If files1 is not None, results will be extracted from files1 and namefile1 will not be used. (default is None)

  • files2 (str) – comparison model output file. If files2 is not None, results will be extracted from files2 and namefile2 will not be used. (default is None)

  • difftol (bool) – boolean determining if the absolute value of the head difference greater than htol should be evaluated (default is False)

  • verbose (bool) – boolean indicating if verbose output should be written to the terminal (default is False)

  • exfile (str) – path to a file with exclusion array data. Head differences will not be evaluated where exclusion array values are greater than zero. (default is None)

  • exarr (numpy.ndarry) – exclusion array. Head differences will not be evaluated where exclusion array values are greater than zero. (default is None).

  • maxerr (int) – maximum number of head difference greater than htol that should be reported. If maxerr is None, all head difference greater than htol will be reported. (default is None)

Returns

success – boolean indicating if the head differences are less than htol.

Return type

bool

compare_stages(namefile1=None, namefile2=None, files1=None, files2=None, htol=0.001, outfile=None, difftol=False, verbose=False)[source]

Compare SWR process stage results from two simulations.

Parameters
  • namefile1 (str) – namefile path for base model

  • namefile2 (str) – namefile path for comparison model

  • precision (str) – precision for binary head file (“auto”, “single”, or “double”) default is “auto”

  • htol (float) – maximum allowed stage difference (default is 0.001)

  • outfile (str) – head comparison output file name. If outfile is None, no comparison output is saved. (default is None)

  • files1 (str) – base model output file. If files1 is not None, results will be extracted from files1 and namefile1 will not be used. (default is None)

  • files2 (str) – comparison model output file. If files2 is not None, results will be extracted from files2 and namefile2 will not be used. (default is None)

  • difftol (bool) – boolean determining if the absolute value of the stage difference greater than htol should be evaluated (default is False)

  • verbose (bool) – boolean indicating if verbose output should be written to the terminal (default is False)

Returns

success – boolean indicating if the stage differences are less than htol.

Return type

bool

compare_swrbudget(namefile1, namefile2, max_cumpd=0.01, max_incpd=0.01, outfile=None, files1=None, files2=None)[source]

Compare the SWR budget results from two simulations.

Parameters
  • namefile1 (str) – namefile path for base model

  • namefile2 (str) – namefile path for comparison model

  • max_cumpd (float) – maximum percent discrepancy allowed for cumulative budget terms (default is 0.01)

  • max_incpd (float) – maximum percent discrepancy allowed for incremental budget terms (default is 0.01)

  • outfile (str) – budget comparison output file name. If outfile is None, no comparison output is saved. (default is None)

  • files1 (str) – base model output file. If files1 is not None, results will be extracted from files1 and namefile1 will not be used. (default is None)

  • files2 (str) – comparison model output file. If files2 is not None, results will be extracted from files2 and namefile2 will not be used. (default is None)

Returns

success – boolean indicating if the difference between budgets are less than max_cumpd and max_incpd

Return type

bool

get_entries_from_namefile(namefile, ftype=None, unit=None, extension=None)[source]

Get entries from a namefile. Can select using FTYPE, UNIT, or file extension.

Parameters
  • namefile (str) – path to a MODFLOW-based model name file

  • ftype (str) – package type

  • unit (int) – file unit number

  • extension (str) – file extension

Returns

entries – list of tuples containing FTYPE, UNIT, FNAME, STATUS for each namefile entry that meets a user-specified value.

Return type

list of tuples

get_input_files(namefile)[source]

Return a list of all the input files in this model.

Parameters

namefile (str) – path to a MODFLOW-based model name file

Returns

filelist – list of MODFLOW-based model input files

Return type

list

get_mf6_blockdata(f, blockstr)[source]

Return list with all non comments between start and end of block specified by blockstr.

Parameters
  • f (file object) – open file object

  • blockstr (str) – name of block to search

Returns

data – list of data in specified block

Return type

list

get_mf6_comparison(src)[source]

Determine comparison type for MODFLOW 6 simulation.

Parameters

src (str) – directory path to search for comparison types

Returns

action – comparison type

Return type

str

get_mf6_files(mfnamefile)[source]

Return a list of all the MODFLOW 6 input and output files in this model.

Parameters

mfnamefile (str) – path to the MODFLOW 6 simulation name file

Returns

  • filelist (list) – list of MODFLOW 6 input files in a simulation

  • outplist (list) – list of MODFLOW 6 output files in a simulation

get_mf6_ftypes(namefile, ftypekeys)[source]

Return a list of FTYPES that are in the name file and in ftypekeys.

Parameters
  • namefile (str) – path to a MODFLOW 6 name file

  • ftypekeys (list) – list of desired FTYPEs

Returns

ftypes – list of FTYPES that match ftypekeys in namefile

Return type

list

get_mf6_mshape(disfile)[source]

Return the shape of the MODFLOW 6 model.

Parameters

disfile (str) – path to a MODFLOW 6 discretization file

Returns

mshape – tuple with the shape of the MODFLOW 6 model.

Return type

tuple

get_mf6_nper(tdisfile)[source]

Return the number of stress periods in the MODFLOW 6 model.

Parameters

tdisfile (str) – path to the TDIS file

Returns

nper – number of stress periods in the simulation

Return type

int

get_namefiles(pth, exclude=None)[source]

Search through a path (pth) for all .nam files.

Parameters
  • pth (str) – path to model files

  • exclude (str or lst) – File or list of files to exclude from the search (default is None)

Returns

namefiles – List of namefiles with paths

Return type

lst

get_sim_name(namefiles, rootpth=None)[source]

Get simulation name.

Parameters
  • namefiles (str or list of strings) – path(s) to MODFLOW-based model name files

  • rootpth (str) – optional root directory path (default is None)

Returns

simname – list of namefiles without the file extension

Return type

list

setup(namefile, dst, remove_existing=True, extrafiles=None)[source]

Setup MODFLOW-based model files for autotests.

Parameters
  • namefile (str) – MODFLOW-based model name file.

  • dst (str) – destination path for comparison model or file(s)

  • remove_existing (bool) – boolean indicating if an existing comparision model or file(s) should be replaced (default is True)

  • extrafiles (str or list of str) – list of extra files to include in the comparision

setup_comparison(namefile, dst, remove_existing=True)[source]

Setup a comparison model or comparision file(s) for a MODFLOW-based model.

Parameters
  • namefile (str) – MODFLOW-based model name file.

  • dst (str) – destination path for comparison model or file(s)

  • remove_existing (bool) – boolean indicating if an existing comparision model or file(s) should be replaced (default is True)

setup_mf6(src, dst, mfnamefile='mfsim.nam', extrafiles=None, remove_existing=True)[source]

Copy all of the MODFLOW 6 input files from the src directory to the dst directory.

Parameters
  • src (src) – directory path with original MODFLOW 6 input files

  • dst (str) – directory path that original MODFLOW 6 input files will be copied to

  • mfnamefile (str) – optional MODFLOW 6 simulation name file (default is mfsim.nam)

  • extrafiles (bool) – boolean indicating if extra files should be included (default is None)

  • remove_existing (bool) – boolean indicating if existing file in dst should be removed (default is True)

Returns

  • mf6inp (list) – list of MODFLOW 6 input files

  • mf6outp (list) – list of MODFLOW 6 output files

setup_mf6_comparison(src, dst, remove_existing=True)[source]

Setup comparision for MODFLOW 6 simulation.

Parameters
  • src (src) – directory path with original MODFLOW 6 input files

  • dst (str) – directory path that original MODFLOW 6 input files will be copied to

  • remove_existing (bool) – boolean indicating if existing file in dst should be removed (default is True)

Returns

action – comparison type

Return type

str

teardown(src)[source]

Teardown a autotest directory.

Parameters

src (str) – autotest directory to teardown