def get_select_packages(select_packages, exdir, dirs):
    found_dirs = []
    for d in dirs:
        pth = os.path.join(exdir, d)
        namefiles = pymake.get_namefiles(pth)
        ftypes = []
        for namefile in namefiles:
            ftype = pymake.get_mf6_ftypes(namefile, select_packages)
            if ftype not in ftypes:
                ftypes += ftype
        if len(ftypes) > 0:
            ftypes = [item.upper() for item in ftypes]
            for pak in select_packages:
                if pak in ftypes:
                    found_dirs.append(d)
                    break
    return found_dirs
Beispiel #2
0
def edit_namefiles():
    namefiles = pymake.get_namefiles(expth)
    for namefile in namefiles:
        # read existing namefile
        f = open(namefile, 'r')
        lines = f.read().splitlines()
        f.close()
        # convert file extensions to lower case
        f = open(namefile, 'w')
        for line in lines:
            t = line.split()
            fn, ext = os.path.splitext(t[2])
            f.write('{:15s} {:3s} {} '.format(t[0], t[1],
                                              '{}{}'.format(fn, ext.lower())))
            if len(t) > 3:
                f.write('{}'.format(t[3]))
            f.write('\n')
        f.close()
Beispiel #3
0
def edit_namefiles():
    namefiles = pymake.get_namefiles(expth)
    for namefile in namefiles:
        # read existing namefile
        f = open(namefile, 'r')
        lines = f.read().splitlines()
        f.close()
        # convert file extensions to lower case
        f = open(namefile, 'w')
        for line in lines:
            t = line.split()
            fn, ext = os.path.splitext(t[2])
            f.write('{:15s} {:3s} {} '.format(t[0], t[1],
                                              '{}{}'.format(fn, ext.lower())))
            if len(t) > 3:
                f.write('{}'.format(t[3]))
            f.write('\n')
        f.close()
Beispiel #4
0
def run_mf5to6(sim):
    """
    Run the MODFLOW 6 simulation and compare to existing head file or
    appropriate MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, or MODFLOW-LGR run.

    """
    src = os.path.join(exdir, sim.name)
    dst = os.path.join('temp', 'working')

    # set default version
    version = 'mf2005'
    lgrpth = None
    compare = False
    cpth = None

    # determine if compare directory exists in directory or if mflgr control
    # file is in directory
    listdir = os.listdir(src)
    for value in listdir:
        fpth = os.path.join(src, value)
        if os.path.isfile(fpth):
            ext = os.path.splitext(fpth)[1]
            if '.lgr' in ext.lower():
                version = 'mflgr'
                lgrpth = fpth
        elif os.path.isdir(fpth):
            if 'compare' in value.lower() or 'cmp' in value.lower():
                compare = True
                cpth = value

    msg = 'Copying {} files to working directory'.format(version)
    # copy lgr files to working directory
    if lgrpth is not None:
        print(msg)
        npth = lgrpth
        pymake.setup(lgrpth, dst)
    # copy modflow 2005, NWT, or USG files to working directory
    else:
        print(msg)
        npths = pymake.get_namefiles(src)
        if len(npths) < 1:
            msg = 'No name files in {}'.format(src)
            print(msg)
            assert False
        npth = npths[0]
        pymake.setup(npth, dst)

    # read ftype from name file to set modflow version
    if version != 'mflgr':
        lines = [line.rstrip('\n') for line in open(npth)]
        for line in lines:
            if len(line) < 1:
                continue
            t = line.split()
            ftype = t[0].upper()
            if ftype == 'NWT' or ftype == 'UPW':
                version = 'mfnwt'
                break
            elif ftype == 'SMS' or ftype == 'DISU':
                version = 'mfusg'
                break

    # run converter
    exe = os.path.abspath(target_dict['mf5to6'])
    msg = sfmt.format('using executable', exe)
    print(msg)
    nmsg = 'Program terminated normally'
    try:
        nam = os.path.basename(npth)
        success, buff = flopy.run_model(exe, nam, model_ws=dst,
                                        silent=False, report=True,
                                        normal_msg=nmsg,
                                        cargs='mf6')
        msg = sfmt.format('MODFLOW 5 to 6 run', nam)
        if success:
            print(msg)
        else:
            print('ERROR: ' + msg)
    except:
        msg = sfmt.format('MODFLOW 5 to 6 run', nam)
        print('ERROR: ' + msg)
        success = False

    assert success, msg

    # path to copy

    # copy files in the compare directory
    if compare:
        dst2 = os.path.join(dst, cpth)
        tpth = os.path.join(exdir, sim.name, cpth)
        shutil.copytree(tpth, dst2)
    # copy original modflow files to the appopriate directory
    # (mf2005, mfnwt, or mfusg) in temp/working
    else:
        dst2 = os.path.join(dst, version)
        pymake.setup(npth, dst2)

    # standard setup
    src = dst
    dst = os.path.join('temp', sim.name)
    sim.setup(src, dst)

    # clean up temp/working directory (src)
    if os.path.exists(src):
        msg = 'Removing {} directory'.format(src)
        print(msg)
        shutil.rmtree(src)
        time.sleep(0.5)

    # standard comparison run
    sim.run()
    sim.compare()
    sim.teardown()
def run_mf5to6(sim):
    """
    Run the MODFLOW 6 simulation and compare to existing head file or
    appropriate MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, or MODFLOW-LGR run.

    """
    src = os.path.join(exdir, sim.name)
    dst = os.path.join("temp", "working")

    # set default version
    version = "mf2005"
    lgrpth = None

    # determine if compare directory exists in directory or if mflgr control
    # file is in directory
    listdir = os.listdir(src)
    for value in listdir:
        fpth = os.path.join(src, value)
        if os.path.isfile(fpth):
            ext = os.path.splitext(fpth)[1]
            if ".lgr" in ext.lower():
                version = "mflgr"
                lgrpth = fpth
        elif os.path.isdir(fpth):
            if "compare" in value.lower() or "cmp" in value.lower():
                compare = True
                cpth = value

    msg = "Copying {} files to working directory".format(version)
    # copy lgr files to working directory
    if lgrpth is not None:
        print(msg)
        npth = lgrpth
        pymake.setup(lgrpth, dst)
    # copy modflow 2005, NWT, or USG files to working directory
    else:
        print(msg)
        npths = pymake.get_namefiles(src)
        if len(npths) < 1:
            msg = "No name files in {}".format(src)
            print(msg)
            assert False
        npth = npths[0]
        pymake.setup(npth, dst)

    # read ftype from name file to set modflow version
    if version != "mflgr":
        lines = [line.rstrip("\n") for line in open(npth)]
        for line in lines:
            if len(line) < 1:
                continue
            t = line.split()
            ftype = t[0].upper()
            if ftype == "NWT" or ftype == "UPW":
                version = "mfnwt"
                break
            elif ftype == "SMS" or ftype == "DISU":
                version = "mfusg"
                break

    # run converter
    exe = os.path.abspath(target_dict["mf5to6"])
    msg = sfmt.format("using executable", exe)
    print(msg)
    nmsg = "Program terminated normally"
    try:
        nam = os.path.basename(npth)
        success, buff = flopy.run_model(
            exe,
            nam,
            model_ws=dst,
            silent=False,
            report=True,
            normal_msg=nmsg,
            cargs="mf6",
        )
        msg = sfmt.format("MODFLOW 5 to 6 run", nam)
        if success:
            print(msg)
        else:
            print("ERROR: " + msg)
    except:
        msg = sfmt.format("MODFLOW 5 to 6 run", nam)
        print("ERROR: " + msg)
        success = False

    assert success, msg

    # standard setup
    src = dst
    dst = os.path.join("temp", sim.name)
    sim.setup(src, dst)

    # clean up temp/working directory (src)
    if os.path.exists(src):
        msg = "Removing {} directory".format(src)
        print(msg)
        shutil.rmtree(src)
        time.sleep(0.5)

    # standard comparison run
    sim.run()
    sim.compare()
    sim.teardown()
Beispiel #6
0
def get_namefiles():
    exclude_tests = ('7_swtv4_ex', )
    namefiles = pymake.get_namefiles(expth, exclude=exclude_tests)
    simname = pymake.get_sim_name(namefiles, rootpth=expth)
    return zip(namefiles, simname)
Beispiel #7
0
    def run(self):
        """
        Run the model and assert if the model terminated successfully
        """
        msg = sfmt.format('Run test', self.name)
        print(msg)

        # Set nam as namefile name without path
        nam = None

        # run mf6 models
        exe = os.path.abspath(targets.target_dict[targets.program])
        msg = sfmt.format('using executable', exe)
        print(msg)
        try:
            success, buff = flopy.run_model(exe,
                                            nam,
                                            model_ws=self.simpath,
                                            silent=False,
                                            report=True)
            msg = sfmt.format('MODFLOW 6 run', self.name)
            if success:
                print(msg)
            else:
                print(msg)
        except:
            msg = sfmt.format('MODFLOW 6 run', self.name)
            print(msg)
            success = False

        assert success

        self.nam_cmp = None
        if success:
            if self.action is not None:
                if self.action.lower() == 'compare':
                    msg = sfmt.format('Comparison files', self.name)
                    print(msg)
                else:
                    cpth = os.path.join(self.simpath, self.action)
                    key = self.action.lower().replace('.cmp', '')
                    exe = os.path.abspath(targets.target_dict[key])
                    npth = pymake.get_namefiles(cpth)[0]
                    nam = os.path.basename(npth)
                    self.nam_cmp = nam
                    try:
                        success_cmp, buff = flopy.run_model(exe,
                                                            nam,
                                                            model_ws=cpth,
                                                            silent=False,
                                                            report=True)
                        msg = sfmt.format('Comparison run',
                                          self.name + '/' + key)
                        if success:
                            print(msg)
                        else:
                            print(msg)
                    except:
                        success_cmp = False
                        msg = sfmt.format('Comparison run',
                                          self.name + '/' + key)
                        print(msg)

                    assert success_cmp

        return
def run_mf5to6(sim):
    """
    Run the MODFLOW 6 simulation and compare to existing head file or
    appropriate MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, or MODFLOW-LGR run.

    """
    src = os.path.join(example_basedir, sim.name)
    dst = os.path.join("temp", "working")

    # set lgrpth to None
    lgrpth = None

    # determine if compare directory exists in directory or if mflgr control
    # file is in directory
    listdir = os.listdir(src)
    for value in listdir:
        fpth = os.path.join(src, value)
        if os.path.isfile(fpth):
            ext = os.path.splitext(fpth)[1]
            if ".lgr" in ext.lower():
                lgrpth = fpth

    print("Copying files to working directory")
    # copy lgr files to working directory
    if lgrpth is not None:
        npth = lgrpth
        pymake.setup(lgrpth, dst)
    # copy MODFLOW-2005, MODFLOW-NWT, or MODFLOW-USG files to working directory
    else:
        npths = pymake.get_namefiles(src)
        if len(npths) < 1:
            msg = "No name files in {}".format(src)
            print(msg)
            assert False
        npth = npths[0]
        pymake.setup(npth, dst)

    # run the mf5to6 converter
    exe = os.path.abspath(target_dict["mf5to6"])
    print(sfmt.format("using executable", exe))
    nmsg = "Program terminated normally"
    try:
        nam = os.path.basename(npth)
        success, buff = flopy.run_model(
            exe,
            nam,
            model_ws=dst,
            silent=False,
            report=True,
            normal_msg=nmsg,
            cargs="mf6",
        )
        msg = sfmt.format("MODFLOW 5 to 6 run", nam)
        if success:
            print(msg)
        else:
            print("ERROR: " + msg)
    except:
        msg = sfmt.format("MODFLOW 5 to 6 run", nam)
        print("ERROR: " + msg)
        success = False

    assert success, msg

    # standard setup
    src = dst
    dst = os.path.join("temp", sim.name)
    sim.setup(src, dst)

    # clean up temp/working directory (src)
    if os.path.exists(src):
        msg = "Removing {} directory".format(src)
        print(msg)
        shutil.rmtree(src)
        time.sleep(0.5)

    # standard comparison run
    sim.run()
    sim.compare()
    sim.teardown()
Beispiel #9
0
    def run(self):
        """
        Run the model and assert if the model terminated successfully
        """
        msg = sfmt.format("Run test", self.name)
        print(msg)

        # Set nam as namefile name without path
        nam = None

        # run mf6 models
        target, ext = os.path.splitext(targets.program)
        exe = os.path.abspath(targets.target_dict[target])
        msg = sfmt.format("using executable", exe)
        print(msg)
        try:
            success, buff = flopy.run_model(exe,
                                            nam,
                                            model_ws=self.simpath,
                                            silent=False,
                                            report=True)
            msg = sfmt.format("MODFLOW 6 run", self.name)
            if success:
                print(msg)
            else:
                print(msg)
        except:
            msg = sfmt.format("MODFLOW 6 run", self.name)
            print(msg)
            success = False

        if self.require_failure is None:
            assert success, "MODFLOW 6 model did not terminate normally"
        else:
            if self.require_failure:
                assert success is False, "MODFLOW 6 model should have failed"
            else:
                assert (success is
                        True), "MODFLOW 6 model should not have failed"

        self.nam_cmp = None
        if success:
            if self.action is not None:
                if self.action.lower() == "compare":
                    msg = sfmt.format("Comparison files", self.name)
                    print(msg)
                else:
                    cpth = os.path.join(self.simpath, self.action)
                    key = self.action.lower().replace(".cmp", "")
                    exe = os.path.abspath(targets.target_dict[key])
                    if ("mf6" in key or "libmf6" in key
                            or "mf6-regression" in key):
                        nam = None
                    else:
                        npth = pymake.get_namefiles(cpth)[0]
                        nam = os.path.basename(npth)
                    self.nam_cmp = nam
                    try:
                        if self.bmifunc is None:
                            success_cmp, buff = flopy.run_model(
                                exe,
                                nam,
                                model_ws=cpth,
                                silent=False,
                                report=True,
                            )
                        else:
                            success_cmp, buff = self.bmifunc(exe,
                                                             self.idxsim,
                                                             model_ws=cpth)
                        msg = sfmt.format("Comparison run",
                                          self.name + "/" + key)
                        if success:
                            print(msg)
                        else:
                            print(msg)
                    except:
                        success_cmp = False
                        msg = sfmt.format("Comparison run",
                                          self.name + "/" + key)
                        print(msg)

                    assert success_cmp, "Unsuccessful comparison"

        return
Beispiel #10
0
def get_namefiles():
    exclude_tests = ('7_swtv4_ex',)
    namefiles = pymake.get_namefiles(expth, exclude=exclude_tests)
    simname = pymake.get_sim_name(namefiles, rootpth=expth)
    return zip(namefiles, simname)
def get_mf6_models():
    """
        Get a list of test models
    """
    # determine if running on travis
    is_travis = 'TRAVIS' in os.environ

    # get current branch
    if is_travis:
        branch = os.environ['BRANCH']
    else:
        branch = get_branch()
    print('On branch {}'.format(branch))

    # tuple of example files to exclude
    exclude = (None, )

    # update exclude
    if is_travis:
        exclude_travis = ('test022_MNW2_Fig28', 'test007_751x751_confined')
        exclude = exclude + exclude_travis
    exclude = list(exclude)

    # write a summary of the files to exclude
    print('list of tests to exclude:')
    for idx, ex in enumerate(exclude):
        print('    {}: {}'.format(idx + 1, ex))

    # build list of directories with valid example files
    dirs = [d for d in os.listdir(exdir) if 'test' in d and d not in exclude]

    # exclude dev examples on master or release branches
    if 'master' in branch.lower() or 'release' in branch.lower():
        drmv = []
        for d in dirs:
            if '_dev' in d.lower():
                drmv.append(d)
        for d in drmv:
            dirs.remove(d)

    # sort in numerical order for case sensitive os
    dirs = sorted(dirs, key=lambda v: (v.upper(), v[0].islower()))

    # determine if only a selection of models should be run
    select_dirs = None
    select_packages = None
    for idx, arg in enumerate(sys.argv):
        if arg.lower() == '--sim':
            if len(sys.argv) > idx + 1:
                select_dirs = sys.argv[idx + 1:]
                break
        elif arg.lower() == '--pak':
            if len(sys.argv) > idx + 1:
                select_packages = sys.argv[idx + 1:]
                select_packages = [item.upper() for item in select_packages]
                break
        elif arg.lower() == '--match':
            if len(sys.argv) > idx + 1:
                like = sys.argv[idx + 1]
                dirs = [item for item in dirs if like in item]
                break

    # determine if the selection of model is in the test models to evaluate
    if select_dirs is not None:
        found_dirs = []
        for d in select_dirs:
            if d in dirs:
                found_dirs.append(d)
        dirs = found_dirs
        if len(dirs) < 1:
            msg = 'Selected models not available in test'
            print(msg)

    # determine if the specified package(s) is in the test models to evaluate
    if select_packages is not None:
        found_dirs = []
        for d in dirs:
            pth = os.path.join(exdir, d)
            namefiles = pymake.get_namefiles(pth)
            ftypes = []
            for namefile in namefiles:
                ftype = pymake.autotest.get_mf6_ftypes(namefile,
                                                       select_packages)
                if ftype not in ftypes:
                    ftypes += ftype
            if len(ftypes) > 0:
                ftypes = [item.upper() for item in ftypes]
                for pak in select_packages:
                    if pak in ftypes:
                        found_dirs.append(d)
                        break
        dirs = found_dirs
        if len(dirs) < 1:
            msg = 'Selected packages not available ['
            for pak in select_packages:
                msg += ' {}'.format(pak)
            msg += ']'
            print(msg)

    return dirs
def get_mf6_models():
    """
    Get a list of test models
    """
    # determine if running on travis
    is_travis = "TRAVIS" in os.environ
    is_github_action = "CI" in os.environ

    # get current branch
    is_CI = False
    if is_travis:
        is_CI = True
        branch = os.environ["BRANCH"]
    elif is_github_action:
        is_CI = True
        branch = os.path.basename(os.environ["GITHUB_REF"])
    else:
        branch = get_branch()
    print("On branch {}".format(branch))

    # tuple of example files to exclude
    exclude = (None,)

    # update exclude
    if is_CI:
        exclude_CI = (
            "test022_MNW2_Fig28",
            "test007_751x751",
            "test007_751x751_confined",
            "test206_gwtbuy-goswami",
            "test207_gwtbuy-elderRa60",
            "test208_gwtbuy-elderRa400",
        )
        exclude = exclude + exclude_CI
    exclude = list(exclude)

    # write a summary of the files to exclude
    print("list of tests to exclude:")
    for idx, ex in enumerate(exclude):
        print("    {}: {}".format(idx + 1, ex))

    # build list of directories with valid example files
    if exdir is not None:
        dirs = [
            d for d in os.listdir(exdir) if "test" in d and d not in exclude
        ]
    else:
        dirs = []

    # exclude dev examples on master or release branches
    if "master" in branch.lower() or "release" in branch.lower():
        drmv = []
        for d in dirs:
            if "_dev" in d.lower():
                drmv.append(d)
        for d in drmv:
            dirs.remove(d)

    # sort in numerical order for case sensitive os
    if len(dirs) > 0:
        dirs = sorted(dirs, key=lambda v: (v.upper(), v[0].islower()))

    # determine if only a selection of models should be run
    select_dirs = None
    select_packages = None
    for idx, arg in enumerate(sys.argv):
        if arg.lower() == "--sim":
            if len(sys.argv) > idx + 1:
                select_dirs = sys.argv[idx + 1 :]
                break
        elif arg.lower() == "--pak":
            if len(sys.argv) > idx + 1:
                select_packages = sys.argv[idx + 1 :]
                select_packages = [item.upper() for item in select_packages]
                break
        elif arg.lower() == "--match":
            if len(sys.argv) > idx + 1:
                like = sys.argv[idx + 1]
                dirs = [item for item in dirs if like in item]
                break

    # determine if the selection of model is in the test models to evaluate
    if select_dirs is not None:
        found_dirs = []
        for d in select_dirs:
            if d.endswith("*"):
                for test_dir in dirs:
                    if test_dir.startswith(d.replace("*", "")):
                        found_dirs.append(test_dir)
            else:
                if d in dirs:
                    found_dirs.append(d)

        dirs = found_dirs
        if len(dirs) < 1:
            msg = "Selected models not available in test"
            print(msg)

    # determine if the specified package(s) is in the test models to evaluate
    if select_packages is not None:
        found_dirs = []
        for d in dirs:
            pth = os.path.join(exdir, d)
            namefiles = pymake.get_namefiles(pth)
            ftypes = []
            for namefile in namefiles:
                ftype = pymake.get_mf6_ftypes(namefile, select_packages)
                if ftype not in ftypes:
                    ftypes += ftype
            if len(ftypes) > 0:
                ftypes = [item.upper() for item in ftypes]
                for pak in select_packages:
                    if pak in ftypes:
                        found_dirs.append(d)
                        break
        dirs = found_dirs
        if len(dirs) < 1:
            msg = "Selected packages not available ["
            for pak in select_packages:
                msg += " {}".format(pak)
            msg += "]"
            print(msg)

    return dirs
Beispiel #13
0
def get_mf6_models():
    """
    Get a list of test models
    """

    # determine if test directory exists
    dirtest = dir_avail()
    if not dirtest:
        return []

    # tuple of example files to exclude
    exclude = ("test006_03models", "test018_NAC", "test051_uzf1d_a")

    exclude_continuous_integration = (
        "test006_gwf3_transport",
        "test006_Gwf1-Lnf1",
    )

    # build list of directories with valid example files
    exclude = list(exclude + exclude_continuous_integration)
    dirs = [d for d in os.listdir(exdir) if "test" in d and d not in exclude]
    # sort in numerical order for case sensitive os
    dirs = sorted(dirs, key=lambda v: (v.upper(), v[0].islower()))

    # determine if only a selection of models should be run
    select_dirs = None
    select_packages = None
    for idx, arg in enumerate(sys.argv):
        if arg.lower() == "--sim":
            if len(sys.argv) > idx + 1:
                select_dirs = sys.argv[idx + 1:]
                break
        elif arg.lower() == "--pak":
            if len(sys.argv) > idx + 1:
                select_packages = sys.argv[idx + 1:]
                select_packages = [item.upper() for item in select_packages]
                break

    # determine if the selection of model is in the test models to evaluate
    if select_dirs is not None:
        found_dirs = []
        for d in select_dirs:
            if d in dirs:
                found_dirs.append(d)
        dirs = found_dirs
        if len(dirs) < 1:
            msg = "Selected models not available in test"
            print(msg)

    # determine if the specified package(s) is in the test models to evaluate
    if select_packages is not None:
        found_dirs = []
        for d in dirs:
            pth = os.path.join(exdir, d)
            namefiles = pymake.get_namefiles(pth)
            ftypes = []
            for namefile in namefiles:
                ftype = pymake.autotest.get_mf6_ftypes(namefile,
                                                       select_packages)
                if ftype not in ftypes:
                    ftypes += ftype
            if len(ftypes) > 0:
                ftypes = [item.upper() for item in ftypes]
                for pak in select_packages:
                    if pak in ftypes:
                        found_dirs.append(d)
                        break
        dirs = found_dirs
        if len(dirs) < 1:
            msg = "Selected packages not available ["
            for pak in select_packages:
                msg += " {}".format(pak)
            msg += "]"
            print(msg)

    return dirs
Beispiel #14
0
    def run(self):
        """
        Run the model and assert if the model terminated successfully
        """
        msg = sfmt.format("Run test", self.name)
        print(msg)

        # Set nam as namefile name without path
        nam = None

        # run mf6 models
        target, ext = os.path.splitext(targets.program)
        exe = os.path.abspath(targets.target_dict[target])
        msg = sfmt.format("using executable", exe)
        print(msg)
        try:
            success, buff = flopy.run_model(
                exe, nam, model_ws=self.simpath, silent=False, report=True
            )
            msg = sfmt.format("MODFLOW 6 run", self.name)
            if success:
                print(msg)
            else:
                print(msg)
        except:
            msg = sfmt.format("MODFLOW 6 run", self.name)
            print(msg)
            success = False

        # set failure based on success and require_failure setting
        if self.require_failure is None:
            msg = "MODFLOW 6 model did not terminate normally"
            if success:
                failure = False
            else:
                failure = True
        else:
            if self.require_failure:
                msg = "MODFLOW 6 model should have failed"
                if not success:
                    failure = False
                else:
                    failure = True
            else:
                msg = "MODFLOW 6 model should not have failed"
                if success:
                    failure = False
                else:
                    failure = True

        # print end of mfsim.lst to the screen
        if failure and self.is_CI:
            fpth = os.path.join(self.simpath, "mfsim.lst")
            msg = self._get_mfsim_listing(fpth) + msg

        # test for failure
        assert not failure, msg

        self.nam_cmp = None
        if success:
            if self.action is not None:
                if self.action.lower() == "compare":
                    msg = sfmt.format("Comparison files", self.name)
                    print(msg)
                else:
                    cpth = os.path.join(self.simpath, self.action)
                    key = self.action.lower().replace(".cmp", "")
                    exe = os.path.abspath(targets.target_dict[key])
                    msg = sfmt.format("comparison executable", exe)
                    print(msg)
                    if (
                        "mf6" in key
                        or "libmf6" in key
                        or "mf6-regression" in key
                    ):
                        nam = None
                    else:
                        npth = pymake.get_namefiles(cpth)[0]
                        nam = os.path.basename(npth)
                    self.nam_cmp = nam
                    try:
                        if self.api_func is None:
                            success_cmp, buff = flopy.run_model(
                                exe,
                                nam,
                                model_ws=cpth,
                                silent=False,
                                report=True,
                            )
                        else:
                            success_cmp, buff = self.api_func(
                                exe, self.idxsim, model_ws=cpth
                            )
                        msg = sfmt.format(
                            "Comparison run", self.name + "/" + key
                        )
                        print(msg)

                        # print end of mfsim.lst to the screen
                        if "mf6" in key:
                            if not success and self.is_CI:
                                fpth = os.path.join(cpth, "mfsim.lst")
                                print(self._get_mfsim_listing(fpth))

                    except:
                        success_cmp = False
                        msg = sfmt.format(
                            "Comparison run", self.name + "/" + key
                        )
                        print(msg)

                    assert success_cmp, "Unsuccessful comparison run"

        return
Beispiel #15
0
def get_mf5to6_models():
    """
        Get a list of test models
    """
    # list of example files to exclude
    exclude = ['test1ss_ic1',
               'test9.5-3layer',
               'testmm2',
               'testmm3',
               'testmmSimple',
               'testps3a',
               'testTwri',
               'testTwrip',
               'test028_sfr_simple']
    if sys.platform.lower() == 'win32':
        exclude.append('testlgrsfr')

    # write a summary of the files to exclude
    print('list of tests to exclude:')
    for idx, ex in enumerate(exclude):
        print('    {}: {}'.format(idx + 1, ex))

    # build list of directories with valid example files
    if exdir is not None:
        dirs = [d for d in os.listdir(exdir)
                if 'test' in d and d not in exclude]
        # sort in numerical order for case sensitive os
        dirs = sorted(dirs, key=lambda v: (v.upper(), v[0].islower()))
    else:
        dirs = []

    # determine if only a selection of models should be run
    select_dirs = None
    select_packages = None
    for idx, arg in enumerate(sys.argv):
        if arg.lower() == '--sim':
            if len(sys.argv) > idx + 1:
                select_dirs = sys.argv[idx + 1:]
                break
        elif arg.lower() == '--pak':
            if len(sys.argv) > idx + 1:
                select_packages = sys.argv[idx + 1:]
                select_packages = [item.upper() for item in
                                   select_packages]
                break

    # determine if the selection of model is in the test models to evaluate
    if select_dirs is not None:
        found_dirs = []
        for d in select_dirs:
            if d in dirs:
                found_dirs.append(d)
        dirs = found_dirs
        if len(dirs) < 1:
            msg = 'Selected models not available in test'
            print(msg)

    # determine if the specified package(s) is in the test models to evaluate
    if select_packages is not None:
        found_dirs = []
        for d in dirs:
            pth = os.path.join(exdir, d)
            namefiles = pymake.get_namefiles(pth)
            ftypes = []
            for namefile in namefiles:
                for pak in select_packages:
                    ftype = pymake.get_entries_from_namefile(namefile,
                                                             ftype=pak)
                    for t in ftype:
                        if t[1] is not None:
                            if t[1] not in ftypes:
                                ftypes.append(t[1].upper())
            if len(ftypes) > 0:
                ftypes = [item.upper() for item in ftypes]
                for pak in select_packages:
                    if pak in ftypes:
                        found_dirs.append(d)
                        break
        dirs = found_dirs
        if len(dirs) < 1:
            msg = 'Selected packages not available ['
            for idx, pak in enumerate(select_packages):
                msg += '{}'.format(pak)
                if idx + 1 < len(select_packages):
                    msg += ', '
            msg += ']'
            print(msg)

    return dirs
def get_mf6_models():
    """
        Get a list of test models
    """
    # determine if running on travis
    is_travis = 'TRAVIS' in os.environ
    is_github_action = 'CI' in os.environ

    # tuple of example files to exclude
    exclude = (None, )

    # update exclude
    if is_travis or is_github_action:
        exclude_CI = (None, )
        exclude = exclude + exclude_CI
    exclude = list(exclude)

    # write a summary of the files to exclude
    print('list of tests to exclude:')
    for idx, ex in enumerate(exclude):
        print('    {}: {}'.format(idx + 1, ex))

    # build list of directories with valid example files
    if exdir is not None:
        dirs = [
            d for d in os.listdir(exdir) if 'test' in d and d not in exclude
        ]
        # sort in numerical order for case sensitive os
        dirs = sorted(dirs, key=lambda v: (v.upper(), v[0].islower()))
    else:
        dirs = []

    # determine if only a selection of models should be run
    select_dirs = None
    select_packages = None
    for idx, arg in enumerate(sys.argv):
        if arg.lower() == '--sim':
            if len(sys.argv) > idx + 1:
                select_dirs = sys.argv[idx + 1:]
                break
        elif arg.lower() == '--pak':
            if len(sys.argv) > idx + 1:
                select_packages = sys.argv[idx + 1:]
                select_packages = [item.upper() for item in select_packages]
                break

    # determine if the selection of model is in the test models to evaluate
    if select_dirs is not None:
        found_dirs = []
        for d in select_dirs:
            if d in dirs:
                found_dirs.append(d)
        dirs = found_dirs
        if len(dirs) < 1:
            msg = 'Selected models not available in test'
            print(msg)

    # determine if the specified package(s) is in the test models to evaluate
    if select_packages is not None:
        found_dirs = []
        for d in dirs:
            pth = os.path.join(exdir, d)
            namefiles = pymake.get_namefiles(pth)
            ftypes = []
            for namefile in namefiles:
                ftype = pymake.get_mf6_ftypes(namefile, select_packages)
                if ftype not in ftypes:
                    ftypes += ftype
            if len(ftypes) > 0:
                ftypes = [item.upper() for item in ftypes]
                for pak in select_packages:
                    if pak in ftypes:
                        found_dirs.append(d)
                        break
        dirs = found_dirs
        if len(dirs) < 1:
            msg = 'Selected packages not available ['
            for pak in select_packages:
                msg += ' {}'.format(pak)
            msg += ']'
            print(msg)

    return dirs
def get_mf6_models():
    """
        Get a list of test models
    """
    # tuple of example files to exclude
    exclude = ('test006_03models',
               'test018_NAC',
               'test051_uzf1d_a')

    # build list of directories with valid example files
    exclude = list(exclude)
    if exdir is not None:
        dirs = [d for d in os.listdir(exdir)
                if 'test' in d and d not in exclude]
        # sort in numerical order for case sensitive os
        dirs = sorted(dirs, key=lambda v: (v.upper(), v[0].islower()))
    else:
        dirs = []

    # determine if only a selection of models should be run
    select_dirs = None
    select_packages = None
    for idx, arg in enumerate(sys.argv):
        if arg.lower() == '--sim':
            if len(sys.argv) > idx + 1:
                select_dirs = sys.argv[idx + 1:]
                break
        elif arg.lower() == '--pak':
            if len(sys.argv) > idx + 1:
                select_packages = sys.argv[idx + 1:]
                select_packages = [item.upper() for item in select_packages]
                break

    # determine if the selection of model is in the test models to evaluate
    if select_dirs is not None:
        found_dirs = []
        for d in select_dirs:
            if d in dirs:
                found_dirs.append(d)
        dirs = found_dirs
        if len(dirs) < 1:
            msg = 'Selected models not available in test'
            print(msg)

    # determine if the specified package(s) is in the test models to evaluate
    if select_packages is not None:
        found_dirs = []
        for d in dirs:
            pth = os.path.join(exdir, d)
            namefiles = pymake.get_namefiles(pth)
            ftypes = []
            for namefile in namefiles:
                ftype = pymake.autotest.get_mf6_ftypes(namefile,
                                                       select_packages)
                if ftype not in ftypes:
                    ftypes += ftype
            if len(ftypes) > 0:
                ftypes = [item.upper() for item in ftypes]
                for pak in select_packages:
                    if pak in ftypes:
                        found_dirs.append(d)
                        break
        dirs = found_dirs
        if len(dirs) < 1:
            msg = 'Selected packages not available ['
            for pak in select_packages:
                msg += ' {}'.format(pak)
            msg += ']'
            print(msg)

    return dirs