Пример #1
0
def _parse1a(line):
    line = line_parse(line)
    line = [s.lower() if isinstance(s, str) else s for s in line]
    specifythtr = True if 'specifythtr' in line else False
    specifythti = True if 'specifythti' in line else False
    nosurfleak = True if 'nosurfleak' in line else False
    return specifythtr, specifythti, nosurfleak
Пример #2
0
def _parse8(line):
    iuzrow = None
    iuzcol = None
    iuzopt = 0
    line = line_parse(line)
    if len(line) > 1:
        iuzrow = _pop_item(line, int)
        iuzcol = _pop_item(line, int)
        iftunit = _pop_item(line, int)
        iuzopt = _pop_item(line, int)
    else:
        iftunit = _pop_item(line, int)
    return iuzrow, iuzcol, iftunit, iuzopt
Пример #3
0
    def load(f, model, nper=None, gwt=False, nsol=1, ext_unit_dict=None):

        if model.verbose:
            sys.stdout.write('loading mnw2 package file...\n')

        structured = model.structured
        if nper is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
            nper = 1 if nper == 0 else nper  # otherwise iterations from 0, nper won't run

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        # dataset 1
        line = line_parse(next(f))
        wel1flag, qsumflag, byndflag = map(int, line)

        # dataset 2
        mnwobs = pop_item(line_parse(next(f)), int)
        wellid_unit_qndflag_qhbflag_concflag = []
        if mnwobs > 0:
            for i in range(mnwobs):
                # dataset 3
                line = line_parse(next(f))
                wellid = pop_item(line, str)
                unit = pop_item(line, int)
                qndflag = pop_item(line, int)
                qbhflag = pop_item(line, int)
                tmp = [wellid, unit, qndflag, qbhflag]
                if gwt and len(line) > 0:
                    tmp.append(pop_item(line, int))
                wellid_unit_qndflag_qhbflag_concflag.append(tmp)
        return ModflowMnwi(model, wel1flag=wel1flag, qsumflag=qsumflag, byndflag=byndflag, mnwobs=mnwobs,
                           wellid_unit_qndflag_qhbflag_concflag=wellid_unit_qndflag_qhbflag_concflag,
                           extension='mnwi', unitnumber=58)
Пример #4
0
def _parse1(line):
    ntrail2 = None
    nsets2 = None
    line = line_parse(line)
    nuztop = _pop_item(line, int)
    iuzfopt = _pop_item(line, int)
    irunflg = _pop_item(line, int)
    ietflag = _pop_item(line, int)
    iuzfcb1 = _pop_item(line, int)
    iuzfcb2 = _pop_item(line, int)
    if iuzfopt > 0:
        ntrail2 = _pop_item(line, int)
        nsets2 = _pop_item(line, int)
    nuzgag = _pop_item(line, int)
    surfdep = _pop_item(line, float)
    return nuztop, iuzfopt, irunflg, ietflag, iuzfcb1, iuzfcb2, ntrail2, nsets2, nuzgag, surfdep
Пример #5
0
def test_line_parse():
    """t027 test line_parse method in MNW2 Package class"""
    # ensure that line_parse is working correctly
    # comment handling
    line = line_parse('Well-A  -1                   ; 2a. WELLID,NNODES')
    assert line == ['Well-A', '-1']
Пример #6
0
def test_line_parse():
    """t027 test line_parse method in MNW2 Package class"""
    # ensure that line_parse is working correctly
    # comment handling
    line = line_parse('Well-A  -1                   ; 2a. WELLID,NNODES')
    assert line == ['Well-A', '-1']
Пример #7
0
def test_line_parse():
    # ensure that line_parse is working correctly
    # comment handling
    line = line_parse('Well-A  -1                   ; 2a. WELLID,NNODES')
    assert line == ['Well-A', '-1']
Пример #8
0
    def load(f, model, ext_unit_dict=None, check=False):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        uzf : ModflowUZF1 object
            ModflowUZF1 object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> uzf = flopy.modflow.ModflowUZF1.load('test.uzf', m)

        """
        if model.verbose:
            sys.stdout.write('loading uzf package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline() # can't use next() because util2d uses readline()
            # (can't mix iteration types in python 2)
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # dataset 1a
        specifythtr, specifythti, nosurfleak = _parse1a(line)
        # dataset 1b
        nuztop, iuzfopt, irunflg, ietflg, iuzfcb1, iuzfcb2, \
        ntrail2, nsets2, nuzgag, surfdep = _parse1(line)

        arrays = {'finf': [], # datasets 10, 12, 14, 16 are lists of util2d arrays
                  'pet': [],
                  'extdp': [],
                  'extwc': []}
        def load_util2d(name, dtype, per=None):
            print('   loading {} array...'.format(name))
            if per is not None:
                arrays[name].append(Util2d.load(f, model, (nrow, ncol), dtype, name,
                                                ext_unit_dict))
            else:
                arrays[name] = Util2d.load(f, model, (nrow, ncol), dtype, name,
                                           ext_unit_dict)

        # dataset 2
        load_util2d('iuzfbnd', np.int)

        # dataset 3
        if irunflg > 0:
            load_util2d('irunbnd', np.int)

        # dataset 4
        if iuzfopt in [0, 1]:
            load_util2d('vks', np.float32)

        if iuzfopt > 0:
            # dataset 5
            load_util2d('eps', np.float32)

            # dataset 6
            load_util2d('thts', np.float32)

            if not model.dis.steady[0]:
                # dataset 7 (initial water content; only read if not steady-state)
                load_util2d('thti', np.float32)

        # dataset 8
        uzgag = {}
        if nuzgag > 0:
            for i in range(nuzgag):
                iuzrow, iuzcol, iftunit, iuzopt = _parse8(f.readline())
                tmp = [iuzrow, iuzcol] if iftunit > 0 else []
                tmp.append(iftunit)
                if iuzopt > 0:
                    tmp.append(iuzopt)
                uzgag[iftunit] = tmp

        # dataset 9
        for per in range(nper):
            print('stress period {}:'.format(per+1))
            line = line_parse(f.readline())
            nuzf1 = _pop_item(line, int)

            # dataset 10
            if nuzf1 > 0:
                load_util2d('finf', np.float32, per=per)

            if ietflg > 0:
                # dataset 11
                line = line_parse(f.readline())
                nuzf2 = _pop_item(line, int)
                if nuzf2 > 0:
                    # dataset 12
                    load_util2d('pet', np.float32, per=per)
                # dataset 13
                line = line_parse(f.readline())
                nuzf3 = _pop_item(line, int)
                if nuzf3 > 0:
                    # dataset 14
                    load_util2d('extdp', np.float32, per=per)
                # dataset 15
                line = line_parse(f.readline())
                nuzf4 = _pop_item(line, int)
                if nuzf4 > 0:
                    # dataset 16
                    load_util2d('extwc', np.float32, per=per)

        # close the file
        f.close()

        # create uzf object
        return ModflowUzf1(model,
                           nuztop=nuztop, iuzfopt=iuzfopt, irunflg=irunflg, ietflg=ietflg,
                           iuzfcb1=iuzfcb1, iuzfcb2=iuzfcb2,
                           ntrail2=ntrail2, nsets=nsets2, nuzgag=nuzgag,
                           surfdep=surfdep, uzgag=uzgag,
                           specifythtr=specifythtr, specifythti=specifythti, nosurfleak=nosurfleak,
                           **arrays
                           )