<jupyter_start><jupyter_text>FloPy  MODFLOW-2005 based model checker demonstration<jupyter_code>import os
import sys

# run installed version of flopy or add local path
try:
    import flopy
except:
    fpth = os.path.abspath(os.path.join('..', '..'))
    sys.path.append(fpth)
    import flopy

print(sys.version)
print('flopy version: {}'.format(flopy.__version__))<jupyter_output>flopy is installed in /Users/jdhughes/Documents/Development/flopy_git/flopy_fork/flopy
3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 14:38:56) 
[Clang 4.0.1 (tags/RELEASE_401/final)]
flopy version: 3.3.1<jupyter_text>Set the working directory<jupyter_code>path = os.path.join('..', 'data', 'mf2005_test')<jupyter_output><empty_output><jupyter_text>Load example dataset and change the model work space<jupyter_code>m = flopy.modflow.Modflow.load('test1ss.nam', model_ws=path)
m.change_model_ws('data')<jupyter_output>changing model workspace...
   data<jupyter_text>By default, the checker performs a model-level check when a set of model files are loaded, unless load is called with `check=False`. The load check only produces screen output if load is called with `verbose=True`. Checks are also performed at the package level when an individual package is loaded The `check()` methodEach model and each package has a `check()` method. The check method has three arguments:<jupyter_code>help(m.check)<jupyter_output>Help on method check in module flopy.mbase:

check(f=None, verbose=True, level=1) method of flopy.modflow.mf.Modflow instance
    Check model data for common errors.
    
    Parameters
    ----------
    f : str or file handle
        String defining file name or file handle for summary file
        of check method output. If a string is passed a file handle
        is created. If f is None, check method does not write
        results to a summary file. (default is None)
    verbose : bool
        Boolean flag used to determine if check method results are
        written to the screen
    level : int
        Check method analysis level. If level=0, summary checks are
        performed. If level=1, full checks are performed.
    
    Returns
    -------
    None
    
    Examples
    --------
    
    >>> import flopy
    >>> m = flopy.modflow.Modflow.load('model.nam')
    >>> m.check()<jupyter_text>The check classBy default, check is called at the model level without a summary output file, but with `verbose=True` and `level=1`. The check methods return an instance of the **check** class, which is housed with the flopy utilities.<jupyter_code>chk = m.check()<jupyter_output>test1ss MODEL DATA VALIDATION SUMMARY:
  3 Warnings:
    1 instance of 
    OC package: action(s) defined in OC stress_period_data ignored as they are not part the stress periods defined by DIS
    1 instance of 
    RCH package: Mean R/T ratio < checker warning threshold of 2e-08 for 1 stress periods
    1 instance of 
    RCH package: Variable NRCHOP set to value other than 3

  Checks that passed:
    Unit number conflicts
    Compatible solver package
    DIS package: zero or negative thickness
    DIS package: thin cells (less than checker threshold of 1.0)
    DIS package: nan values in top array
    DIS package: nan values in bottom array
    BAS6 package: isolated cells in ibound array
    BAS6 package: Not a number
    LPF package: zero or negative horizontal hydraulic conductivity values
    LPF package: negative horizontal anisotropy values
    LPF package: vertical hydraulic conductivity values below checker threshold of 1e-11
    LPF package: vertical hydraulic conductivi[...]<jupyter_text>Summary arrayMost of the attributes and methods in **check** are intended to be used by the ``check()`` methods. The central attribute of **check** is the summary array:<jupyter_code>chk.summary_array<jupyter_output><empty_output><jupyter_text>This is a numpy record array that summarizes errors and warnings found by the checker. The package, layer-row-column location of the error, the offending value, and a description of the error are provided. In the checker, errors and warnings are loosely defined as follows:   Errors:either input that would cause MODFLOW to crash, or inputs that almost certainly mis-represent the intended conceptual model. Warnings:inputs that are potentially problematic, but may be intentional.each package-level check produces a **check** instance with a summary array. The model level checks combine the summary arrays from the packages into a master summary array. At the model and the package levels, the summary array is used to generate the screen output shown above. At either level, the summary array can be written to a csv file by supply a filename to the `f` argument. Specifying `level=2` prints the summary array to the screen.<jupyter_code>m.check(level=2)<jupyter_output>Errors and/or Warnings encountered.
Errors and/or Warnings encountered.

test1ss MODEL DATA VALIDATION SUMMARY:
  3 Warnings:
    1 instance of 
    OC package: action(s) defined in OC stress_period_data ignored as they are not part the stress periods defined by DIS
    1 instance of 
    RCH package: Mean R/T ratio < checker warning threshold of 2e-08 for 1 stress periods
    1 instance of 
    RCH package: Variable NRCHOP set to value other than 3

  Checks that passed:
    Unit number conflicts
    Compatible solver package
    DIS package: zero or negative thickness
    DIS package: thin cells (less than checker threshold of 1.0)
    DIS package: nan values in top array
    DIS package: nan values in bottom array
    BAS6 package: isolated cells in ibound array
    BAS6 package: Not a number
    LPF package: zero or negative horizontal hydraulic conductivity values
    LPF package: negative horizontal anisotropy values
    LPF package: vertical hydraulic conductivity values below c[...]<jupyter_text>example of package level check and summary file<jupyter_code>m.rch.check()<jupyter_output>RCH PACKAGE DATA VALIDATION:
  2 Warnings:
    1 instance of 
    Mean R/T ratio < checker warning threshold of 2e-08 for 1 stress periods
    1 instance of 
    Variable NRCHOP set to value other than 3<jupyter_text>example of summary output file<jupyter_code>m.check(f='checksummary.csv')
try:
    import pandas as pd
    df = pd.read_csv('data/checksummary.csv')
except:
    df = open('data/checksummary.csv').readlines()
df<jupyter_output><empty_output><jupyter_text>checking on `write_input()`checking is also performed by default when `write_input()` is called at the package or model level. Checking on write is performed with the same `verbose` setting as specified for the model. However, if errors or warnings are encountered and `level=1` (default) or higher, a screen message notifies the user of the errors.By default, the checks performed on `load()` and `write_input()` save results to a summary file, which is named after the packge or the model.<jupyter_code>m.write_input()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0684656236543706, 'fraction_numerical': 0.011195636572412803, 'mean_word_length': 4.045619116582187, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '16128', 'license': 'CC0-1.0', 'n_tokens_mistral': 2017, 'n_tokens_neox': 1898, 'n_words': 861, 'path': 'examples/Notebooks/flopy3_ModelCheckerExample.ipynb', 'repo_name': 'aleaf/flopy', 'size': '6967'}