Пример #1
0
    def load(f, model, ext_unit_dict=None):
        """
        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
        -------
        dis : ModflowLpf object
            ModflowLpf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> lpf = flopy.modflow.ModflowLpf.load('test.lpf', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, NPLPF - line already read above
        if model.verbose:
            print '   loading IBCFCB, HDRY, NPLPF...'
        t = line.strip().split()
        ilpfcb, hdry, nplpf = int(t[0]), float(t[1]), int(t[2])
        if ilpfcb != 0:
            model.add_pop_key_list(ilpfcb)
            ilpfcb = 53
        # options
        storagecoefficient = False
        constantcv = False
        thickstrt = False
        nocvcorrection = False
        novfc = False
        if len(t) > 3:
            for k in xrange(3, len(t)):
                if 'STORAGECOEFFICIENT' in t[k].upper():
                    storagecoefficient = True
                elif 'CONSTANTCV' in t[k].upper():
                    constantcv = True
                elif 'THICKSTRT' in t[k].upper():
                    thickstrt = True
                elif 'NOCVCORRECTION' in t[k].upper():
                    nocvcorrection = True
                elif 'NOVFC' in t[k].upper():
                    novfc = True
        # LAYTYP array
        if model.verbose:
            print '   loading LAYTYP...'
        laytyp = np.empty((nlay), dtype=np.int)
        laytyp = read1d(f, laytyp)
        # LAYAVG array
        if model.verbose:
            print '   loading LAYAVG...'
        layavg = np.empty((nlay), dtype=np.int)
        layavg = read1d(f, layavg)
        # CHANI array
        if model.verbose:
            print '   loading CHANI...'
        chani = np.empty((nlay), dtype=np.float32)
        chani = read1d(f, chani)
        # LAYVKA array
        if model.verbose:
            print '   loading LAYVKA...'
        layvka = np.empty((nlay), dtype=np.float32)
        layvka = read1d(f, layvka)
        # LAYWET array
        if model.verbose:
            print '   loading LAYWET...'
        laywet = np.empty((nlay), dtype=np.int)
        laywet = read1d(f, laywet)
        # Item 7: WETFCT, IWETIT, IHDWET
        wetfct, iwetit, ihdwet = None, None, None
        iwetdry = laywet.sum()
        if iwetdry > 0:
            if model.verbose:
                print '   loading WETFCT, IWETIT, IHDWET...'
            line = f.readline()
            t = line.strip().split()
            wetfct, iwetit, ihdwet = float(t[0]), int(t[1]), int(t[2])

        #--parameters data
        par_types = []
        if nplpf > 0:
            par_types, parm_dict = mfpar.load(f, nplpf, model.verbose)
            #print parm_dict

        #--non-parameter data
        transient = not model.get_package('DIS').steady.all()
        hk = [0] * nlay
        hani = [0] * nlay
        vka = [0] * nlay
        ss = [0] * nlay
        sy = [0] * nlay
        vkcb = [0] * nlay
        wetdry = [0] * nlay
        for k in range(nlay):
            if model.verbose:
                print '   loading hk layer {0:3d}...'.format(k + 1)
            if 'hk' not in par_types:
                t = util_2d.load(f, model, (nrow, ncol), np.float32, 'hk',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol),
                                         'hk',
                                         parm_dict,
                                         findlayer=k)
            hk[k] = t
            if chani[k] < 0:
                if model.verbose:
                    print '   loading hani layer {0:3d}...'.format(k + 1)
                if 'hani' not in par_types:
                    t = util_2d.load(f, model, (nrow, ncol), np.float32,
                                     'hani', ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol),
                                             'hani',
                                             parm_dict,
                                             findlayer=k)
                hani[k] = t
            if model.verbose:
                print '   loading vka layer {0:3d}...'.format(k + 1)
            if 'vka' not in par_types and 'vani' not in par_types:
                t = util_2d.load(f, model, (nrow, ncol), np.float32, 'vka',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol),
                                         'vka',
                                         parm_dict,
                                         findlayer=k)
            vka[k] = t
            if transient:
                if model.verbose:
                    print '   loading ss layer {0:3d}...'.format(k + 1)
                if 'ss' not in par_types:
                    t = util_2d.load(f, model, (nrow, ncol), np.float32, 'ss',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol),
                                             'ss',
                                             parm_dict,
                                             findlayer=k)
                ss[k] = t
                if laytyp[k] != 0:
                    if model.verbose:
                        print '   loading sy layer {0:3d}...'.format(k + 1)
                    if 'sy' not in par_types:
                        t = util_2d.load(f, model, (nrow, ncol), np.float32,
                                         'sy', ext_unit_dict)
                    else:
                        line = f.readline()
                        t = mfpar.parameter_fill(model, (nrow, ncol),
                                                 'sy',
                                                 parm_dict,
                                                 findlayer=k)
                    sy[k] = t
            #if self.parent.get_package('DIS').laycbd[k] > 0:
            if model.get_package('DIS').laycbd[k] > 0:
                if model.verbose:
                    print '   loading vkcb layer {0:3d}...'.format(k + 1)
                if 'vkcb' not in par_types:
                    t = util_2d.load(f, model, (nrow, ncol), np.float32,
                                     'vkcb', ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol),
                                             'vkcb',
                                             parm_dict,
                                             findlayer=k)
                vkcb[k] = t
            if (laywet[k] != 0 and laytyp[k] != 0):
                if model.verbose:
                    print '   loading wetdry layer {0:3d}...'.format(k + 1)
                t = util_2d.load(f, model, (nrow, ncol), np.float32, 'wetdry',
                                 ext_unit_dict)
                wetdry[k] = t

        #--create instance of lpf class
        lpf = ModflowLpf(model,
                         ilpfcb=ilpfcb,
                         laytyp=laytyp,
                         layavg=layavg,
                         chani=chani,
                         laywet=laywet,
                         hdry=hdry,
                         iwdflg=iwetdry,
                         wetfct=wetfct,
                         iwetit=iwetit,
                         ihdwet=ihdwet,
                         hk=hk,
                         hani=hani,
                         vka=vka,
                         ss=ss,
                         sy=sy,
                         vkcb=vkcb,
                         wetdry=wetdry,
                         storagecoefficient=storagecoefficient,
                         constantcv=constantcv,
                         thickstrt=thickstrt,
                         novfc=novfc)
        return lpf
Пример #2
0
    def load(f, model, nper=None, ext_unit_dict=None):
        """
        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.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        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
        -------
        evt : ModflowEvt object
            ModflowEvt object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> evt = flopy.modflow.mfevt.load('test.evt', m)

        """
        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        if "parameter" in line.lower():
            raw = line.strip().split()
            assert int(raw[1]) == 0,"Parameters not supported"
            line = f.readline()
        #dataset 2
        t = line.strip().split()
        nevtop = int(t[0])
        ievtcb = 0
        try:
            if int(t[1]) != 0:
                ievtcb = 53
        except:
            pass
        if nper is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        #read data for every stress period
        surf = []
        evtr = []
        exdp = []
        ievt = []
        current_surf = []
        current_evtr = []
        current_exdp = []
        current_ievt = []
        for iper in xrange(nper):
            line = f.readline()
            t = line.strip().split()
            insurf = int(t[0])
            inevtr = int(t[1])
            inexdp = int(t[2])
            if (nevtop == 2):
              inievt = int(t[3])
            if insurf >= 0:
                print \
                    '   loading surf stress period {0:3d}...'.format(iper+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'surf',
                                 ext_unit_dict)
                current_surf = t
            surf.append(current_surf)
            if inevtr >= 0:
                print \
                    '   loading evtr stress period {0:3d}...'.format(iper+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'evtr',
                                 ext_unit_dict)
                current_evtr = t
            evtr.append(current_evtr)
            if inexdp >= 0:
                print \
                    '   loading exdp stress period {0:3d}...'.format(iper+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'exdp',
                                 ext_unit_dict)
                current_exdp = t
            exdp.append(current_exdp)
            if nevtop == 2:
                if inievt >= 0:
                    print '   loading ievt stress period {0:3d}...'.format(
                        iper+1)
                    t = util_2d.load(f, model, (nrow,ncol), np.int32, 'ievt',
                                     ext_unit_dict)
                    current_ievt = t
                ievt.append(current_ievt)
        #--create evt object
        evt = ModflowEvt(model, nevtop=nevtop, ievtcb=ievtcb, 
                         surf=surf, evtr=evtr, exdp=exdp, ievt=ievt)
        return evt
Пример #3
0
    def load(f, model, nper=None, ext_unit_dict=None):
        """
        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.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        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
        -------
        rch : ModflowRch object
            ModflowRch object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> rch = flopy.modflow.mfrch.load('test.rch', m)

        """
        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        if "parameter" in line.lower():
            raw = line.strip().split()
            assert int(raw[1]) == 0,"Parameters not supported"
            line = f.readline()
        #dataset 2
        t = line.strip().split()
        nrchop = int(t[0])
        irchcb = 0
        try:
            if int(t[1]) != 0:
                irchcb = 53
        except:
            pass
        if nper is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        #read data for every stress period
        rech = []
        irch = []
        current_rech = []
        current_irch = []
        for iper in xrange(nper):
            line = f.readline()
            t = line.strip().split()
            inrech = int(t[0])
            if nrchop == 2:
                inirch = int(t[1])
            if inrech >= 0:
                print \
                    '   loading rech stress period {0:3d}...'.format(iper+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'rech',
                                 ext_unit_dict)
                current_rech = t
            rech.append(current_rech)
            if nrchop == 2:
                if inirch >= 0:
                    print '   loading irch stress period {0:3d}...'.format(
                        iper+1)
                    t = util_2d.load(f, model, (nrow,ncol), np.int, 'irch',
                                     ext_unit_dict)
                    current_irch = t
                irch.append(current_irch)
        rch = ModflowRch(model, nrchop=nrchop, irchcb=irchcb, rech=rech,
                         irch=irch)
        return rch
Пример #4
0
    def load(f, model, ext_unit_dict=None):
        """
        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
        -------
        dis : ModflowLpf object
            ModflowLpf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> lpf = flopy.modflow.ModflowLpf.load('test.lpf', m)

        """

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

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, NPLPF - line already read above
        if model.verbose:
            print('   loading IBCFCB, HDRY, NPLPF...')
        t = line.strip().split()
        ilpfcb, hdry, nplpf = int(t[0]), float(t[1]), int(t[2])
        if ilpfcb != 0:
            model.add_pop_key_list(ilpfcb)
            ilpfcb = 53
        # options
        storagecoefficient = False
        constantcv = False
        thickstrt = False
        nocvcorrection = False
        novfc = False
        if len(t) > 3:
            for k in range(3,len(t)):
                if 'STORAGECOEFFICIENT' in t[k].upper():
                    storagecoefficient = True
                elif 'CONSTANTCV' in t[k].upper():
                    constantcv = True
                elif 'THICKSTRT' in t[k].upper():
                    thickstrt = True
                elif 'NOCVCORRECTION' in t[k].upper():
                    nocvcorrection = True
                elif 'NOVFC' in t[k].upper():
                    novfc = True
        # LAYTYP array
        if model.verbose:
            print('   loading LAYTYP...')
        laytyp = np.empty((nlay), dtype=np.int)
        laytyp = read1d(f, laytyp)
        # LAYAVG array
        if model.verbose:
            print('   loading LAYAVG...')
        layavg = np.empty((nlay), dtype=np.int)
        layavg = read1d(f, layavg)
        # CHANI array
        if model.verbose:
            print('   loading CHANI...')
        chani = np.empty((nlay), dtype=np.float32)
        chani = read1d(f, chani)
        # LAYVKA array
        if model.verbose:
            print('   loading LAYVKA...')
        layvka = np.empty((nlay), dtype=np.float32)
        layvka = read1d(f, layvka)
        # LAYWET array
        if model.verbose:
            print('   loading LAYWET...')
        laywet = np.empty((nlay), dtype=np.int)
        laywet = read1d(f, laywet)
        # Item 7: WETFCT, IWETIT, IHDWET
        wetfct,iwetit,ihdwet = None, None, None
        iwetdry = laywet.sum()
        if iwetdry > 0:
            if model.verbose:
                print('   loading WETFCT, IWETIT, IHDWET...')
            line = f.readline()
            t = line.strip().split()
            wetfct, iwetit, ihdwet = float(t[0]), int(t[1]), int(t[2])

        # parameters data
        par_types = []
        if nplpf > 0:
            par_types, parm_dict = mfpar.load(f, nplpf, model.verbose)
            #print parm_dict

        # non-parameter data
        transient = not model.get_package('DIS').steady.all()
        hk = [0] * nlay
        hani = [0] * nlay
        vka = [0] * nlay
        ss = [0] * nlay
        sy = [0] * nlay
        vkcb = [0] * nlay
        wetdry = [0] * nlay
        for k in range(nlay):
            if model.verbose:
                print('   loading hk layer {0:3d}...'.format(k+1))
            if 'hk' not in par_types:
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'hk',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol), 'hk', parm_dict, findlayer=k)
            hk[k] = t
            if chani[k] < 0:
                if model.verbose:
                    print('   loading hani layer {0:3d}...'.format(k+1))
                if 'hani' not in par_types:
                    t = util_2d.load(f, model, (nrow, ncol), np.float32, 'hani',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'hani', parm_dict, findlayer=k)
                hani[k] = t
            if model.verbose:
                print('   loading vka layer {0:3d}...'.format(k+1))
            if 'vka' not in par_types and 'vani' not in par_types:
                t = util_2d.load(f, model, (nrow, ncol), np.float32, 'vka',
                                 ext_unit_dict)
            else:
                line = f.readline()
                key = 'vka'
                if 'vani' in par_types:
                    key = 'vani'
                t = mfpar.parameter_fill(model, (nrow, ncol), key, parm_dict, findlayer=k)
            vka[k] = t
            if transient:
                if model.verbose:
                    print('   loading ss layer {0:3d}...'.format(k+1))
                if 'ss' not in par_types:
                    t = util_2d.load(f, model, (nrow, ncol), np.float32, 'ss',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'ss', parm_dict, findlayer=k)
                ss[k] = t
                if laytyp[k] != 0:
                    if model.verbose:
                        print('   loading sy layer {0:3d}...'.format(k+1))
                    if 'sy' not in par_types:
                        t = util_2d.load(f, model, (nrow, ncol), np.float32, 'sy',
                                         ext_unit_dict)
                    else:
                        line = f.readline()
                        t = mfpar.parameter_fill(model, (nrow, ncol), 'sy', parm_dict, findlayer=k)
                    sy[k] = t
            #if self.parent.get_package('DIS').laycbd[k] > 0:
            if model.get_package('DIS').laycbd[k] > 0:
                if model.verbose:
                    print('   loading vkcb layer {0:3d}...'.format(k+1))
                if 'vkcb' not in par_types:
                    t = util_2d.load(f, model, (nrow, ncol), np.float32, 'vkcb',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'vkcb', parm_dict, findlayer=k)
                vkcb[k] = t
            if (laywet[k] != 0 and laytyp[k] != 0):
                if model.verbose:
                    print('   loading wetdry layer {0:3d}...'.format(k+1))
                t = util_2d.load(f, model, (nrow, ncol), np.float32, 'wetdry',
                                 ext_unit_dict)
                wetdry[k] = t

        # create instance of lpf class
        lpf = ModflowLpf(model, ilpfcb=ilpfcb, laytyp=laytyp, layavg=layavg, chani=chani,
                         layvka=layvka, laywet=laywet, hdry=hdry, iwdflg=iwetdry,
                         wetfct=wetfct, iwetit=iwetit, ihdwet=ihdwet,
                         hk=hk, hani=hani, vka=vka, ss=ss, sy=sy, vkcb=vkcb,
                         wetdry=wetdry, storagecoefficient=storagecoefficient,
                         constantcv=constantcv,thickstrt=thickstrt,novfc=novfc)
        return lpf
Пример #5
0
    def load(f, model, ext_unit_dict=None):
        """
        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
        -------
        dis : ModflowUPW object
            ModflowLpf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> lpf = flopy.modflow.ModflowUpw.load('test.upw', m)

        """

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

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, NPLPF - line already read above
        if model.verbose:
            print('   loading IUPWCB, HDRY, NPUPW, IPHDRY...')
        t = line.strip().split()
        iupwcb, hdry, npupw, iphdry = int(t[0]), float(t[1]), int(t[2]), int(t[3])
        if iupwcb != 0:
            model.add_pop_key_list(iupwcb)
            iupwcb = 53
        # options
        noparcheck = False
        if len(t) > 3:
            for k in range(3,len(t)):
                if 'NOPARCHECK' in t[k].upper():
                    noparcheck = True
        # LAYTYP array
        if model.verbose:
            print('   loading LAYTYP...')
        line = f.readline()
        t = line.strip().split()
        laytyp = np.array((t[0:nlay]),dtype=np.int)
        # LAYAVG array
        if model.verbose:
            print('   loading LAYAVG...')
        line = f.readline()
        t = line.strip().split()
        layavg = np.array((t[0:nlay]),dtype=np.int)
        # CHANI array
        if model.verbose:
            print('   loading CHANI...')
        line = f.readline()
        t = line.strip().split()
        chani = np.array((t[0:nlay]),dtype=np.float32)
        # LAYVKA array
        if model.verbose:
            print('   loading LAYVKA...')
        line = f.readline()
        t = line.strip().split()
        layvka = np.array((t[0:nlay]),dtype=np.int)
        # LAYWET array
        if model.verbose:
            print('   loading LAYWET...')
        line = f.readline()
        t = line.strip().split()
        laywet = np.array((t[0:nlay]),dtype=np.int)
        # Item 7: WETFCT, IWETIT, IHDWET
        wetfct,iwetit,ihdwet = None,None,None
        iwetdry = laywet.sum()
        if iwetdry > 0:
            raise Exception('LAYWET should be 0 for UPW')

        #--get parameters
        par_types = []
        if npupw > 0:
            par_types, parm_dict = mfpar.load(f, nplpf, model.verbose)

        #--get arrays
        transient = not model.get_package('DIS').steady.all()
        hk = [0] * nlay
        hani = [0] * nlay
        vka = [0] * nlay
        ss = [0] * nlay
        sy = [0] * nlay
        vkcb = [0] * nlay
        for k in range(nlay):
            if model.verbose:
                print('   loading hk layer {0:3d}...'.format(k+1))
            if 'hk' not in par_types:
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'hk',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol), 'hk', parm_dict, findlayer=k)
            hk[k] = t
            if chani[k] < 1:
                if model.verbose:
                    print('   loading hani layer {0:3d}...'.format(k+1))
                if 'hani' not in par_types:
                    t = util_2d.load(f, model, (nrow,ncol), np.float32, 'hani',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'hani', parm_dict, findlayer=k)
                hani[k] = t
            if model.verbose:
                print('   loading vka layer {0:3d}...'.format(k+1))
            if 'vka' not in par_types and 'vani' not in par_types:
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'vka',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol), 'vka', parm_dict, findlayer=k)
            vka[k] = t
            if transient:
                if model.verbose:
                    print('   loading ss layer {0:3d}...'.format(k+1))
                if 'ss' not in par_types:
                    t = util_2d.load(f, model, (nrow,ncol), np.float32, 'ss',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'ss', parm_dict, findlayer=k)
                ss[k] = t
                if laytyp[k] != 0:
                    if model.verbose:
                        print('   loading sy layer {0:3d}...'.format(k+1))
                    if 'sy' not in par_types:
                        t = util_2d.load(f, model, (nrow,ncol), np.float32, 'sy',
                                         ext_unit_dict)
                    else:
                        line = f.readline()
                        t = mfpar.parameter_fill(model, (nrow, ncol), 'sy', parm_dict, findlayer=k)
                    sy[k] = t
            if model.get_package('DIS').laycbd[k] > 0:
                if model.verbose:
                    print('   loading vkcb layer {0:3d}...'.format(k+1))
                if 'vkcb' not in par_types:
                    t = util_2d.load(f, model, (nrow,ncol), np.float32, 'vkcb',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'vkcb', parm_dict, findlayer=k)
                vkcb[k] = t

        #--create upw object
        upw = ModflowUpw(model, iupwcb=iupwcb, iphdry=iphdry, hdry=hdry,
                         noparcheck=noparcheck,
                         laytyp=laytyp, layavg=layavg, chani=chani,
                         layvka=layvka, laywet=laywet,
                         hk=hk, hani=hani, vka=vka, ss=ss, sy=sy, vkcb=vkcb)

        #--return upw object
        return upw
Пример #6
0
    def load(f, model, ext_unit_dict=None):
        """
        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
        -------
        dis : ModflowDis object
            ModflowDis object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> dis = flopy.modflow.ModflowDis.load('test.dis', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # dataset 1
        nlay, nrow, ncol, nper, itmuni, lenuni = line.strip().split()[0:6]
        nlay = int(nlay)
        nrow = int(nrow)
        ncol = int(ncol)
        nper = int(nper)
        itmuni = int(itmuni)
        lenuni = int(lenuni)
        # dataset 2 -- laycbd
        if model.verbose:
            print '   Loading dis package with:\n      ' + \
                  '{0} layers, {1} rows, {2} columns, and {3} stress periods'.format(nlay, nrow, ncol,nper)
            print '   loading laycbd...'
        laycbd = np.empty((nlay), dtype=np.int)
        d = 0
        while True:
            line = f.readline()
            raw = line.strip('\n').split()
            for val in raw:
                laycbd[d] = np.int(val)
                d += 1
                if d == nlay:
                    break
            if d == nlay:
                break
        #dataset 3 -- delr
        if model.verbose:
            print '   loading delr...'
        delr = util_2d.load(f, model, (1, ncol), np.float32, 'delr',
                            ext_unit_dict)
        delr = delr.array.reshape((ncol))
        #dataset 4 -- delc
        if model.verbose:
            print '   loading delc...'
        delc = util_2d.load(f, model, (1, nrow), np.float32, 'delc',
                            ext_unit_dict)
        delc = delc.array.reshape((nrow))
        #dataset 5 -- top
        if model.verbose:
            print '   loading top...'
        top = util_2d.load(f, model, (nrow, ncol), np.float32, 'top',
                           ext_unit_dict)
        #dataset 6 -- botm
        if model.verbose:
            print '   loading botm...'
        ncbd = laycbd.sum()
        botm = util_3d.load(f, model, (nlay + ncbd, nrow, ncol), np.float32,
                            'botm', ext_unit_dict)
        #dataset 7 -- stress period info
        if model.verbose:
            print '   loading stress period data...'
        perlen = []
        nstp = []
        tsmult = []
        steady = []
        for k in xrange(nper):
            line = f.readline()
            a1, a2, a3, a4 = line.strip().split()[0:4]
            a1 = float(a1)
            a2 = int(a2)
            a3 = float(a3)
            if a4.upper() == 'TR':
                a4 = False
            else:
                a4 = True
            perlen.append(a1)
            nstp.append(a2)
            tsmult.append(a3)
            steady.append(a4)

        #--create dis object instance
        dis = ModflowDis(model, nlay, nrow, ncol, nper, delr, delc, laycbd,
                         top, botm, perlen, nstp, tsmult, steady, itmuni,
                         lenuni)
        #--return dis object instance
        return dis
Пример #7
0
    def load(f, model, nrow=None, ncol=None, ext_unit_dict=None):
        """
        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.
        nrow : int
            number of rows. If not specified it will be retrieved from
            the model object. (default is None).
        ncol : int
            number of columns. If not specified it will be retrieved from
            the model object. (default is None).
        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
        -------
        zone : ModflowZone dict

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> zon = flopy.modflow.ModflowZon.load('test.zon', m)

        """

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

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        #dataset 1
        t = line.strip().split()
        nzn = int(t[0])

        #get nlay,nrow,ncol if not passed
        if nrow is None and ncol is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        #read zone data
        zone_dict = collections.OrderedDict()
        for n in range(nzn):
            line = f.readline()
            t = line.strip().split()
            if len(t[0]) > 10:
                zonnam = t[0][0:10].lower()
            else:
                zonnam = t[0].lower()
            if model.verbose:
                sys.stdout.write('   reading data for "{:<10s}" zone\n'.format(zonnam))
            #--load data
            t = util_2d.load(f, model, (nrow, ncol), np.int, zonnam,
                             ext_unit_dict)
            #--add unit number to list of external files in ext_unit_dict to remove.
            if t.locat is not None:
                model.add_pop_key_list(t.locat)
            zone_dict[zonnam] = t
        zon = ModflowZon(model, zone_dict=zone_dict)
        return zon
Пример #8
0
    def load(f, model, ext_unit_dict=None):
        """
        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
        -------
        dis : ModflowUPW object
            ModflowLpf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> lpf = flopy.modflow.ModflowUpw.load('test.upw', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, NPLPF - line already read above
        if model.verbose:
            print '   loading IUPWCB, HDRY, NPUPW, IPHDRY...'
        t = line.strip().split()
        iupwcb, hdry, npupw, iphdry = int(t[0]), float(t[1]), int(t[2]), int(t[3])
        if iupwcb != 0:
            model.add_pop_key_list(iupwcb)
            iupwcb = 53
        # options
        noparcheck = False
        if len(t) > 3:
            for k in xrange(3,len(t)):
                if 'NOPARCHECK' in t[k].upper():
                    noparcheck = True
        # LAYTYP array
        if model.verbose:
            print '   loading LAYTYP...'
        line = f.readline()
        t = line.strip().split()
        laytyp = np.array((t[0:nlay]),dtype=np.int)
        # LAYAVG array
        if model.verbose:
            print '   loading LAYAVG...'
        line = f.readline()
        t = line.strip().split()
        layavg = np.array((t[0:nlay]),dtype=np.int)
        # CHANI array
        if model.verbose:
            print '   loading CHANI...'
        line = f.readline()
        t = line.strip().split()
        chani = np.array((t[0:nlay]),dtype=np.float32)
        # LAYVKA array
        if model.verbose:
            print '   loading LAYVKA...'
        line = f.readline()
        t = line.strip().split()
        layvka = np.array((t[0:nlay]),dtype=np.int)
        # LAYWET array
        if model.verbose:
            print '   loading LAYWET...'
        line = f.readline()
        t = line.strip().split()
        laywet = np.array((t[0:nlay]),dtype=np.int)
        # Item 7: WETFCT, IWETIT, IHDWET
        wetfct,iwetit,ihdwet = None,None,None
        iwetdry = laywet.sum()
        if iwetdry > 0:
            raise Exception, 'LAYWET should be 0 for UPW'

        #--get parameters
        par_types = []
        if npupw > 0:
            par_types, parm_dict = mfpar.load(f, nplpf, model.verbose)

        #--get arrays
        transient = not model.get_package('DIS').steady.all()
        hk = [0] * nlay
        hani = [0] * nlay
        vka = [0] * nlay
        ss = [0] * nlay
        sy = [0] * nlay
        vkcb = [0] * nlay
        for k in range(nlay):
            if model.verbose:
                print '   loading hk layer {0:3d}...'.format(k+1)
            if 'hk' not in par_types:
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'hk',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol), 'hk', parm_dict, findlayer=k)
            hk[k] = t
            if chani[k] < 1:
                if model.verbose:
                    print '   loading hani layer {0:3d}...'.format(k+1)
                if 'hani' not in par_types:
                    t = util_2d.load(f, model, (nrow,ncol), np.float32, 'hani',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'hani', parm_dict, findlayer=k)
                hani[k] = t
            if model.verbose:
                print '   loading vka layer {0:3d}...'.format(k+1)
            if 'vka' not in par_types and 'vani' not in par_types:
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'vka',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol), 'vka', parm_dict, findlayer=k)
            vka[k] = t
            if transient:
                if model.verbose:
                    print '   loading ss layer {0:3d}...'.format(k+1)
                if 'ss' not in par_types:
                    t = util_2d.load(f, model, (nrow,ncol), np.float32, 'ss',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'ss', parm_dict, findlayer=k)
                ss[k] = t
                if laytyp[k] != 0:
                    if model.verbose:
                        print '   loading sy layer {0:3d}...'.format(k+1)
                    if 'sy' not in par_types:
                        t = util_2d.load(f, model, (nrow,ncol), np.float32, 'sy',
                                         ext_unit_dict)
                    else:
                        line = f.readline()
                        t = mfpar.parameter_fill(model, (nrow, ncol), 'sy', parm_dict, findlayer=k)
                    sy[k] = t
            if model.get_package('DIS').laycbd[k] > 0:
                if model.verbose:
                    print '   loading vkcb layer {0:3d}...'.format(k+1)
                if 'vkcb' not in par_types:
                    t = util_2d.load(f, model, (nrow,ncol), np.float32, 'vkcb',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'vkcb', parm_dict, findlayer=k)
                vkcb[k] = t

        #--create upw object
        upw = ModflowUpw(model, iupwcb=iupwcb, iphdry=iphdry, hdry=hdry,
                         noparcheck=noparcheck,
                         laytyp=laytyp, layavg=layavg, chani=chani,
                         layvka=layvka, laywet=laywet,
                         hk=hk, hani=hani, vka=vka, ss=ss, sy=sy, vkcb=vkcb)

        #--return upw object
        return upw
Пример #9
0
    def load(f, model, nlay=None, nrow=None, ncol=None, ext_unit_dict=None):
        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #A1 and A2 
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        
        a3 = line.strip().split()
        nlay, nrow, ncol, nper, ncomp, mcomp = int(a3[0]), int(a3[1]), \
                                               int(a3[2]), int(a3[3]), \
                                               int(a3[4]), int(a3[5])
        if ncomp > 1:
            raise NotImplementedError("BTN.load() doesn't support ncomp > 1")

        a4 = f.readline().strip().split()
        tunit, lunit, munit = a4

        a5 = f.readline().strip().split()

        a6 = f.readline().strip().split()


        delr = util_2d.load(f, model, (ncol, 1), np.float32, 'delr',
                              ext_unit_dict)
        delc = util_2d.load(f, model, (nrow, 1), np.float32, 'delc',
                              ext_unit_dict)
        htop = util_2d.load(f, model, (nrow, ncol), np.float32, 'htop',
                              ext_unit_dict)
        dz = util_3d.load(f, model, (nlay, nrow, ncol), np.float32, 'dz',
                          ext_unit_dict)
        prsity = util_3d.load(f, model, (nlay, nrow, ncol), np.float32, 'prsity',
                          ext_unit_dict)
        icbund = util_3d.load(f, model, (nlay, nrow, ncol) ,np.int, 'icbund',
                          ext_unit_dict)
        sconc = util_3d.load(f, model, (nlay, nrow, ncol), np.float32, 'sconc',
                          ext_unit_dict)

        a14 = f.readline().strip().split()
        cinact,thkmin = float(a14[0]), float(a14[1])

        a15 = f.readline().strip().split()
        ifmtcn,ifmtnp,ifmtrf,ifmtdp = int(a15[0]), int(a15[1]), int(a15[2]),\
                                      int(a15[3])
        savucn = False
        if (a15[4].lower() == 't'): savucn = True

        a16 = f.readline().strip().split()
        nprs = int(a16[0])
        timprs = []
        while len(timprs) < nprs:
            line = f.readline().strip().split()
            [timprs.append(float(l)) for l in line]

        a18 = f.readline().strip().split()
        nobs, nprobs = int(a18[0]), int(a18[1])
        obs = []
        while len(obs) < nobs:
            line = np.array(f.readline().strip().split(), dtype=np.int)
            obs.append(line)
        obs = np.array(obs)

        a20 = f.readline().strip().split()
        chkmas = False
        if (a20[0].lower() == 't'): chkmas = True
        nprmas = int(a20[1])
        dt0, mxstrn, ttsmult, ttsmax = [], [], [], []
        for kper in xrange(nper):
            line = f.readline().strip().split()
            tsm = float(line[2])
            if tsm <= 0:
                raise Exception("tsmult <= 0 not supported")
            line = f.readline().strip().split()

            dt0.append(float(line[0]))
            mxstrn.append(int(line[1]))
            ttsmult.append(float(line[2]))
            ttsmax.append(float(line[3]))

        f.close()
        btn = Mt3dBtn(model, ncomp=ncomp, mcomp=mcomp, tunit=tunit,
                      lunit=lunit, munit=munit, prsity=prsity, icbund=icbund,
                      sconc=sconc, cinact=cinact, thkmin=thkmin,
                      ifmtcn=ifmtcn, ifmtnp=ifmtnp, ifmtrf=ifmtrf,
                      ifmtdp=ifmtdp, savucn=savucn, nprs=nprs,\
                      timprs=timprs, obs=obs, nprobs=nprobs, chkmas=chkmas,\
                      nprmas=nprmas, dt0=dt0, mxstrn=mxstrn, ttsmult=ttsmult,\
                      ttsmax=ttsmax)
        return btn
Пример #10
0
    def load(f, model, nrow=None, ncol=None, ext_unit_dict=None):
        """
        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.
        nrow : int
            number of rows. If not specified it will be retrieved from
            the model object. (default is None).
        ncol : int
            number of columns. If not specified it will be retrieved from
            the model object. (default is None).
        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
        -------
        zone : ModflowMult dict

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> mlt = flopy.modflow.ModflowMlt.load('test.mlt', m)

        """

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

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        #dataset 1
        t = line.strip().split()
        nml = int(t[0])

        #get nlay,nrow,ncol if not passed
        if nrow is None and ncol is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        #read zone data
        mult_dict = collections.OrderedDict()
        for n in range(nml):
            line = f.readline()
            t = line.strip().split()
            if len(t[0]) > 10:
                mltnam = t[0][0:10].lower()
            else:
                mltnam = t[0].lower()
            if model.verbose:
                sys.stdout.write('   reading data for "{:<10s}" mult\n'.format(mltnam))
            readArray = True
            kwrd = None
            if len(t) > 1:
                if 'function' in t[1].lower() or 'expression' in t[1].lower():
                    readArray = False
                    kwrd = t[1].lower()
            # load data
            if readArray:
                t = util_2d.load(f, model, (nrow, ncol), np.float32, mltnam,
                                 ext_unit_dict)
                # add unit number to list of external files in ext_unit_dict to remove.
                if t.locat is not None:
                    model.add_pop_key_list(t.locat)
            else:
                line = f.readline()
                t = [kwrd, line]
                t = ModflowMlt.mult_function(mult_dict, line)
            mult_dict[mltnam] = t

        # create mlt dictionary
        mlt = ModflowMlt(model, mult_dict=mult_dict)

        return mlt
Пример #11
0
    def load(f, model, nper=None, ext_unit_dict=None):
        """
        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.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        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
        -------
        rch : ModflowRch object
            ModflowRch object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> rch = flopy.modflow.ModflowRch.load('test.rch', m)

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        npar = 0
        if "parameter" in line.lower():
            raw = line.strip().split()
            npar = np.int(raw[1])
            if npar > 0:
                if model.verbose:
                    print '   Parameters detected. Number of parameters = ', npar
            line = f.readline()
        #dataset 2
        t = line.strip().split()
        nrchop = int(t[0])
        ipakcb = 0
        try:
            if int(t[1]) != 0:
                model.add_pop_key_list(int(t[1]))
                ipakcb = 53
        except:
            pass

        #--dataset 3 and 4 - parameters data
        pak_parms = None
        if npar > 0:
            pak_parms = mfparbc.loadarray(f, npar, model.verbose)

        if nper is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        #read data for every stress period
        rech = {}
        irch = None
        if nrchop == 2:
            irch = {}
        current_rech = []
        current_irch = []
        for iper in xrange(nper):
            line = f.readline()
            t = line.strip().split()
            inrech = int(t[0])
            if nrchop == 2:
                inirch = int(t[1])
            if inrech >= 0:
                if npar == 0:
                    if model.verbose:
                        print \
                            '   loading rech stress period {0:3d}...'.format(iper+1)
                    t = util_2d.load(f, model, (nrow, ncol), np.float32, 'rech', ext_unit_dict)
                else:
                    parm_dict = {}
                    for ipar in xrange(inrech):
                        line = f.readline()
                        t = line.strip().split()
                        pname = t[0].lower()
                        try:
                            c = t[1].lower()
                            instance_dict = pak_parms.bc_parms[pname][1]
                            if c in instance_dict:
                                iname = c
                            else:
                                iname = 'static'
                        except:
                            iname = 'static'
                        parm_dict[pname] = iname
                    t = mfparbc.parameter_bcfill(model, (nrow, ncol), parm_dict, pak_parms)

                current_rech = t
            rech[iper] = current_rech
            if nrchop == 2:
                if inirch >= 0:
                    if model.verbose:
                        print '   loading irch stress period {0:3d}...'.format(
                            iper+1)
                    t = util_2d.load(f, model, (nrow,ncol), np.int, 'irch',
                                     ext_unit_dict)
                    current_irch = t
                irch[iper] = current_irch
        rch = ModflowRch(model, nrchop=nrchop, ipakcb=ipakcb, rech=rech,
                         irch=irch)
        return rch
Пример #12
0
    def load(f, model, ext_unit_dict=None):
        '''
        f is either a filename or a file handle.  if the arrays in the file
        are specified using interal, external, or older style array control
        records, then f should be a file handle, and the ext_unit_dict
        dictionary of unitnumber:open(filename, 'r') must be included.
        '''
        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, IWDFLG, WETFCT, IWETIT, IHDWET - line already read above
        print '   loading IBCFCB, HDRY, IWDFLG, WETFCT, IWETIT, IHDWET...'
        t = line.strip().split()
        ibcfcb,hdry,iwdflg,wetfct,iwetit,ihdwet = int(t[0]),float(t[1]),int(t[2]),float(t[3]),int(t[4]),int(t[5])
        if ibcfcb != 0:
            ibcfcb = 53
        # LAYCON array
        print '   loading LAYCON...'
        line = f.readline()
        t = line.strip().split()
        intercellt = np.zeros(nlay, dtype=np.int)
        laycon = np.zeros(nlay, dtype=np.int)
        for k in xrange(nlay):
            ival = int(t[k])
            if ival > 9:
                intercellt[k] = int(t[k][0])
                laycon[k] = int(t[k][1])
            else:
                laycon[k] = ival
        # TRPY array
        print '   loading TRPY...'
        trpy = util_2d.load(f, model, (1, nlay), np.float32, 'trpy', ext_unit_dict)
        trpy = trpy.array.reshape( (nlay) )
        # property data for each layer based on options
        transient = not model.get_package('DIS').steady.all()
        sf1 = np.empty((nlay,nrow,ncol), dtype=np.float)
        tran = np.empty((nlay,nrow,ncol), dtype=np.float)
        hy = np.empty((nlay,nrow,ncol), dtype=np.float)
        if nlay > 1:
            vcont = np.empty((nlay-1,nrow,ncol), dtype=np.float)
        else:
            vcont = 1.0
        sf2 = np.empty((nlay,nrow,ncol), dtype=np.float)
        wetdry = np.empty((nlay,nrow,ncol), dtype=np.float)
        for k in xrange(nlay):
            if transient == True:
                print '   loading sf1 layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'sf1', ext_unit_dict)
                sf1[k,:,:] = t.array
            if ((laycon[k] == 0) or (laycon[k] == 2)):
                print '   loading tran layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'tran', ext_unit_dict)
                tran[k,:,:] = t.array
            else:
                print '   loading hy layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'hy', ext_unit_dict)
                hy[k,:,:] = t.array
            if k < (nlay - 1):
                print '   loading vcont layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'vcont', ext_unit_dict)
                vcont[k,:,:] = t.array
            if ((transient == True) and ((laycon[k] == 2) or (laycon[k] == 3))):
                print '   loading sf2 layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'sf2', ext_unit_dict)
                sf2[k,:,:] = t.array
            if ((iwdflg <> 0) and ((laycon[k] == 1) or (laycon[k] == 3))):
                print '   loading sf2 layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'wetdry', ext_unit_dict)
                wetdry[k,:,:] = t.array

        bcf = ModflowBcf(model,ibcfcb=ibcfcb,intercellt=intercellt,laycon=laycon,trpy=trpy,hdry=hdry,iwdflg=iwdflg,wetfct=wetfct,iwetit=iwetit,ihdwet=ihdwet,
                         tran=tran,hy=hy,vcont=vcont,sf1=sf1,sf2=sf2,wetdry=wetdry)
        return bcf
Пример #13
0
    def load(f, model, nrow=None, ncol=None, ext_unit_dict=None):
        """
        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.
        nrow : int
            number of rows. If not specified it will be retrieved from
            the model object. (default is None).
        ncol : int
            number of columns. If not specified it will be retrieved from
            the model object. (default is None).
        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
        -------
        zone : ModflowMult dict

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> mlt = flopy.modflow.ModflowMlt.load('test.mlt', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        #dataset 1
        t = line.strip().split()
        nml = int(t[0])

        #get nlay,nrow,ncol if not passed
        if nrow is None and ncol is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        #read zone data
        mult_dict = collections.OrderedDict()
        for n in xrange(nml):
            line = f.readline()
            t = line.strip().split()
            if len(t[0]) > 10:
                mltnam = t[0][0:10].lower()
            else:
                mltnam = t[0].lower()
            if model.verbose:
                sys.stdout.write('   reading data for "{:<10s}" mult\n'.format(mltnam))
            readArray = True
            kwrd = None
            if len(t) > 1:
                if 'function' in t[1].lower() or 'expression' in t[1].lower():
                    readArray = False
                    kwrd = t[1].lower()
            #--load data
            if readArray:
                t = util_2d.load(f, model, (nrow, ncol), np.float32, mltnam,
                                 ext_unit_dict)
                #--add unit number to list of external files in ext_unit_dict to remove.
                if t.locat is not None:
                    model.add_pop_key_list(t.locat)
            else:
                line = f.readline()
                t = [kwrd, line]
                t = ModflowMlt.mult_function(mult_dict, line)
            mult_dict[mltnam] = t

        #--create mlt dictionary
        mlt = ModflowMlt(model, mult_dict=mult_dict)

        return mlt
Пример #14
0
    def load(f, model, nper=None, ext_unit_dict=None):
        """
        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.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        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
        -------
        rch : ModflowRch object
            ModflowRch object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> rch = flopy.modflow.ModflowRch.load('test.rch', m)

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

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        npar = 0
        if "parameter" in line.lower():
            raw = line.strip().split()
            npar = np.int(raw[1])
            if npar > 0:
                if model.verbose:
                    print('   Parameters detected. Number of parameters = ', npar)
            line = f.readline()
        #dataset 2
        t = line.strip().split()
        nrchop = int(t[0])
        ipakcb = 0
        try:
            if int(t[1]) != 0:
                model.add_pop_key_list(int(t[1]))
                ipakcb = 53
        except:
            pass

        #--dataset 3 and 4 - parameters data
        pak_parms = None
        if npar > 0:
            pak_parms = mfparbc.loadarray(f, npar, model.verbose)

        if nper is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        #read data for every stress period
        rech = {}
        irch = None
        if nrchop == 2:
            irch = {}
        current_rech = []
        current_irch = []
        for iper in range(nper):
            line = f.readline()
            t = line.strip().split()
            inrech = int(t[0])
            if nrchop == 2:
                inirch = int(t[1])
            if inrech >= 0:
                if npar == 0:
                    if model.verbose:
                        print('   loading rech stress period {0:3d}...'.format(iper+1))
                    t = util_2d.load(f, model, (nrow, ncol), np.float32, 'rech', ext_unit_dict)
                else:
                    parm_dict = {}
                    for ipar in range(inrech):
                        line = f.readline()
                        t = line.strip().split()
                        pname = t[0].lower()
                        try:
                            c = t[1].lower()
                            instance_dict = pak_parms.bc_parms[pname][1]
                            if c in instance_dict:
                                iname = c
                            else:
                                iname = 'static'
                        except:
                            iname = 'static'
                        parm_dict[pname] = iname
                    t = mfparbc.parameter_bcfill(model, (nrow, ncol), parm_dict, pak_parms)

                current_rech = t
            rech[iper] = current_rech
            if nrchop == 2:
                if inirch >= 0:
                    if model.verbose:
                        print('   loading irch stress period {0:3d}...'.format(
                            iper+1))
                    t = util_2d.load(f, model, (nrow,ncol), np.int, 'irch',
                                     ext_unit_dict)
                    current_irch = t
                irch[iper] = current_irch
        rch = ModflowRch(model, nrchop=nrchop, ipakcb=ipakcb, rech=rech,
                         irch=irch)
        return rch
Пример #15
0
    def load(f, model, nrow=None, ncol=None, ext_unit_dict=None):
        """
        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.
        nrow : int
            number of rows. If not specified it will be retrieved from
            the model object. (default is None).
        ncol : int
            number of columns. If not specified it will be retrieved from
            the model object. (default is None).
        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
        -------
        zone : ModflowZone dict

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> zon = flopy.modflow.ModflowZon.load('test.zon', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        #dataset 1
        t = line.strip().split()
        nzn = int(t[0])

        #get nlay,nrow,ncol if not passed
        if nrow is None and ncol is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        #read zone data
        zone_dict = collections.OrderedDict()
        for n in xrange(nzn):
            line = f.readline()
            t = line.strip().split()
            if len(t[0]) > 10:
                zonnam = t[0][0:10].lower()
            else:
                zonnam = t[0].lower()
            if model.verbose:
                sys.stdout.write(
                    '   reading data for "{:<10s}" zone\n'.format(zonnam))
            #--load data
            t = util_2d.load(f, model, (nrow, ncol), np.int, zonnam,
                             ext_unit_dict)
            #--add unit number to list of external files in ext_unit_dict to remove.
            if t.locat is not None:
                model.add_pop_key_list(t.locat)
            zone_dict[zonnam] = t
        zon = ModflowZon(model, zone_dict=zone_dict)
        return zon
Пример #16
0
    def load(f, model, ext_unit_dict=None):
        """
        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
        -------
        swi2 : ModflowSwi2 object

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> lpf = flopy.modflow.ModflowSwi2.load('test.swi2', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        # --read dataset 1
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 1\n')
        t = line.strip().split()
        nsrf = int(t[0])
        istrat = int(t[1])
        nobs = int(t[2])
        if int(t[3]) > 0:
            model.add_pop_key_list(int(t[3]))
            iswizt = 55
        if int(t[4]) > 0:
            model.add_pop_key_list(int(t[4]))
            iswibd = 56
        else:
            iswibd = 0
        iswiobs = 0
        if int(t[5]) > 0:
            model.add_pop_key_list(int(t[5]))
            iswiobs = 1051
        options = []
        adaptive = False
        for idx in xrange(6, len(t)):
            if '#' in t[idx]:
                break
            options.append(t[idx])
            if 'adaptive' in t[idx].lower():
                adaptive = True

        #--read dataset 2a
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 2a\n')
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        t = line.strip().split()
        nsolver = int(t[0])
        iprsol = int(t[1])
        mutsol = int(t[2])

        #--read dataset 2b
        solver2params = {}
        if nsolver == 2:
            if model.verbose:
                sys.stdout.write('  loading swi2 dataset 2b\n')
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            t = line.strip().split()
            solver2params['mxiter'] = int(t[0])
            solver2params['iter1'] = int(t[1])
            solver2params['npcond'] = int(t[2])
            solver2params['zclose'] = float(t[3])
            solver2params['rclose'] = float(t[4])
            solver2params['relax'] = float(t[5])
            solver2params['nbpol'] = int(t[6])
            solver2params['damp'] = float(t[7])
            solver2params['dampt'] = float(t[8])

        #--read dataset 3a
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 3a\n')
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        t = line.strip().split()
        toeslope = float(t[0])
        tipslope = float(t[1])
        alpha = None
        beta = 0.1
        if len(t) > 2:
            try:
                alpha = float(t[2])
                beta = float(t[3])
            except:
                pass

        #--read dataset 3b
        nadptmx, nadptmn, adptfct = None, None, None
        if adaptive:
            if model.verbose:
                sys.stdout.write('  loading swi2 dataset 3b\n')
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            t = line.strip().split()
            nadptmx = int(t[0])
            nadptmn = int(t[1])
            adptfct = float(t[2])

        #--read dataset 4
        if model.verbose:
            print '   loading nu...'
        if istrat == 1:
            nnu = nsrf + 1
        else:
            nnu = nsrf + 2
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        nu = util_2d.load(f, model, (1, nnu), np.float32, 'nu', ext_unit_dict)
        nu = nu.array.reshape((nnu))

        #--read dataset 5
        if model.verbose:
            print '   loading initial zeta surfaces...'
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        zeta = []
        for n in xrange(nsrf):
            ctxt = 'zeta_surf{:02d}'.format(n + 1)
            zeta.append(
                util_3d.load(f, model, (nlay, nrow, ncol), np.float32, ctxt,
                             ext_unit_dict))

        #--read dataset 6
        if model.verbose:
            print '   loading initial ssz...'
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        ssz = util_3d.load(f, model, (nlay, nrow, ncol), np.float32, 'ssz',
                           ext_unit_dict)

        #--read dataset 7
        if model.verbose:
            print '   loading initial isource...'
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        isource = util_3d.load(f, model, (nlay, nrow, ncol), np.int, 'isource',
                               ext_unit_dict)

        #--read dataset 8
        obsname = []
        obslrc = []
        if nobs > 0:
            if model.verbose:
                print '   loading observation locations...'
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            for i in xrange(nobs):
                if i > 0:
                    try:
                        line = f.readline()
                    except:
                        break
                t = line.strip().split()
                obsname.append(t[0])
                kk = int(t[1])
                ii = int(t[2])
                jj = int(t[3])
                obslrc.append([kk, ii, jj])
                nobs = len(obsname)

        #--create swi2 instance
        swi2 = ModflowSwi2(model,
                           nsrf=nsrf,
                           istrat=istrat,
                           nobs=nobs,
                           iswizt=iswizt,
                           iswibd=iswibd,
                           iswiobs=iswiobs,
                           options=options,
                           nsolver=nsolver,
                           iprsol=iprsol,
                           mutsol=mutsol,
                           solver2params=solver2params,
                           toeslope=toeslope,
                           tipslope=tipslope,
                           alpha=alpha,
                           beta=beta,
                           nadptmx=nadptmx,
                           nadptmn=nadptmn,
                           adptfct=adptfct,
                           nu=nu,
                           zeta=zeta,
                           ssz=ssz,
                           isource=isource,
                           obsnam=obsname,
                           obslrc=obslrc)

        #--return swi2 instance
        return swi2
Пример #17
0
    def load(f, model, ext_unit_dict=None):
        """
        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.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        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
        -------
        wel : ModflowBcf object
            ModflowBcf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> wel = flopy.modflow.ModflowBcf.load('test.bcf', m)

        """

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

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, IWDFLG, WETFCT, IWETIT, IHDWET - line already read above
        if model.verbose:
            print('   loading IBCFCB, HDRY, IWDFLG, WETFCT, IWETIT, IHDWET...')
        t = line.strip().split()
        ibcfcb,hdry,iwdflg,wetfct,iwetit,ihdwet = int(t[0]),float(t[1]),int(t[2]),float(t[3]),int(t[4]),int(t[5])
        if ibcfcb != 0:
            model.add_pop_key_list(ibcfcb)
            ibcfcb = 53
        # LAYCON array
        if model.verbose:
            print('   loading LAYCON...')
        line = f.readline()
        t = line.strip().split()
        intercellt = np.zeros(nlay, dtype=np.int)
        laycon = np.zeros(nlay, dtype=np.int)
        for k in range(nlay):
            ival = int(t[k])
            if ival > 9:
                intercellt[k] = int(t[k][0])
                laycon[k] = int(t[k][1])
            else:
                laycon[k] = ival
        # TRPY array
        if model.verbose:
            print('   loading TRPY...')
        trpy = util_2d.load(f, model, (1, nlay), np.float32, 'trpy', ext_unit_dict)
        trpy = trpy.array.reshape( (nlay) )
        # property data for each layer based on options
        transient = not model.get_package('DIS').steady.all()
        sf1 = np.empty((nlay,nrow,ncol), dtype=np.float)
        tran = np.empty((nlay,nrow,ncol), dtype=np.float)
        hy = np.empty((nlay,nrow,ncol), dtype=np.float)
        if nlay > 1:
            vcont = np.empty((nlay-1,nrow,ncol), dtype=np.float)
        else:
            vcont = 1.0
        sf2 = np.empty((nlay,nrow,ncol), dtype=np.float)
        wetdry = np.empty((nlay,nrow,ncol), dtype=np.float)
        for k in range(nlay):
            if transient == True:
                if model.verbose:
                    print('   loading sf1 layer {0:3d}...'.format(k+1))
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'sf1', ext_unit_dict)
                sf1[k,:,:] = t.array
            if ((laycon[k] == 0) or (laycon[k] == 2)):
                if model.verbose:
                    print('   loading tran layer {0:3d}...'.format(k+1))
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'tran', ext_unit_dict)
                tran[k,:,:] = t.array
            else:
                if model.verbose:
                    print('   loading hy layer {0:3d}...'.format(k+1))
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'hy', ext_unit_dict)
                hy[k,:,:] = t.array
            if k < (nlay - 1):
                if model.verbose:
                    print('   loading vcont layer {0:3d}...'.format(k+1))
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'vcont', ext_unit_dict)
                vcont[k,:,:] = t.array
            if ((transient == True) and ((laycon[k] == 2) or (laycon[k] == 3))):
                if model.verbose:
                    print('   loading sf2 layer {0:3d}...'.format(k+1))
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'sf2', ext_unit_dict)
                sf2[k,:,:] = t.array
            if ((iwdflg != 0) and ((laycon[k] == 1) or (laycon[k] == 3))):
                if model.verbose:
                    print('   loading sf2 layer {0:3d}...'.format(k+1))
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'wetdry', ext_unit_dict)
                wetdry[k,:,:] = t.array

        # create instance of bcf object
        bcf = ModflowBcf(model, ibcfcb=ibcfcb, intercellt=intercellt, laycon=laycon, trpy=trpy, hdry=hdry,
                         iwdflg=iwdflg, wetfct=wetfct, iwetit=iwetit, ihdwet=ihdwet,
                         tran=tran, hy=hy, vcont=vcont, sf1=sf1, sf2=sf2, wetdry=wetdry)

        # return bcf object
        return bcf
Пример #18
0
    def load(f, model, ext_unit_dict=None):
        """
        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
        -------
        swi2 : ModflowSwi2 object

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> lpf = flopy.modflow.ModflowSwi2.load('test.swi2', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        # --read dataset 1
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 1\n')
        t = line.strip().split()
        nsrf = int(t[0])
        istrat = int(t[1])
        nobs = int(t[2])
        if int(t[3]) > 0:
            model.add_pop_key_list(int(t[3]))
            iswizt = 55
        if int(t[4]) > 0:
            model.add_pop_key_list(int(t[4]))
            iswibd = 56
        else:
            iswibd = 0
        iswiobs = 0
        if int(t[5]) > 0:
            model.add_pop_key_list(int(t[5]))
            iswiobs = 1051
        options = []
        adaptive = False
        for idx in xrange(6, len(t)):
            if '#' in t[idx]:
                break
            options.append(t[idx])
            if 'adaptive' in t[idx].lower():
                adaptive = True

        #--read dataset 2a
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 2a\n')
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        t = line.strip().split()
        nsolver = int(t[0])
        iprsol = int(t[1])
        mutsol = int(t[2])

        #--read dataset 2b
        solver2params = {}
        if nsolver == 2:
            if model.verbose:
                sys.stdout.write('  loading swi2 dataset 2b\n')
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            t = line.strip().split()
            solver2params['mxiter'] = int(t[0])
            solver2params['iter1'] = int(t[1])
            solver2params['npcond'] = int(t[2])
            solver2params['zclose'] = float(t[3])
            solver2params['rclose'] = float(t[4])
            solver2params['relax'] = float(t[5])
            solver2params['nbpol'] = int(t[6])
            solver2params['damp'] = float(t[7])
            solver2params['dampt'] = float(t[8])

        #--read dataset 3a
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 3a\n')
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        t = line.strip().split()
        toeslope = float(t[0])
        tipslope = float(t[1])
        alpha = None
        beta = 0.1
        if len(t) > 2:
            try:
                alpha = float(t[2])
                beta = float(t[3])
            except:
                pass

        #--read dataset 3b
        nadptmx, nadptmn, adptfct = None, None, None
        if adaptive:
            if model.verbose:
                sys.stdout.write('  loading swi2 dataset 3b\n')
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            t = line.strip().split()
            nadptmx = int(t[0])
            nadptmn = int(t[1])
            adptfct = float(t[2])

        #--read dataset 4
        if model.verbose:
            print '   loading nu...'
        if istrat == 1:
            nnu = nsrf + 1
        else:
            nnu = nsrf + 2
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        nu = util_2d.load(f, model, (1, nnu), np.float32, 'nu',
                          ext_unit_dict)
        nu = nu.array.reshape((nnu))

        #--read dataset 5
        if model.verbose:
            print '   loading initial zeta surfaces...'
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        zeta = []
        for n in xrange(nsrf):
            ctxt = 'zeta_surf{:02d}'.format(n+1)
            zeta.append(util_3d.load(f, model, (nlay, nrow, ncol),
                                     np.float32, ctxt, ext_unit_dict))

        #--read dataset 6
        if model.verbose:
            print '   loading initial ssz...'
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        ssz = util_3d.load(f, model, (nlay, nrow, ncol), np.float32,
                           'ssz', ext_unit_dict)

        #--read dataset 7
        if model.verbose:
            print '   loading initial isource...'
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        isource = util_3d.load(f, model, (nlay, nrow, ncol), np.int,
                               'isource', ext_unit_dict)

        #--read dataset 8
        obsname = []
        obslrc = []
        if nobs > 0:
            if model.verbose:
                print '   loading observation locations...'
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            for i in xrange(nobs):
                if i > 0:
                    try:
                        line = f.readline()
                    except:
                        break
                t = line.strip().split()
                obsname.append(t[0])
                kk = int(t[1])
                ii = int(t[2])
                jj = int(t[3])
                obslrc.append([kk, ii, jj])
                nobs = len(obsname)

        #--create swi2 instance
        swi2 = ModflowSwi2(model, nsrf=nsrf, istrat=istrat, nobs=nobs, iswizt=iswizt, iswibd=iswibd,
                           iswiobs=iswiobs,options=options,
                           nsolver=nsolver, iprsol=iprsol, mutsol=mutsol, solver2params=solver2params,
                           toeslope=toeslope, tipslope=tipslope, alpha=alpha, beta=beta,
                           nadptmx=nadptmx, nadptmn=nadptmn, adptfct=adptfct,
                           nu=nu, zeta=zeta, ssz=ssz, isource=isource,
                           obsnam=obsname, obslrc=obslrc)

        #--return swi2 instance
        return swi2
Пример #19
0
    def load(f, model, ext_unit_dict=None):
        """
        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.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        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
        -------
        wel : ModflowBcf object
            ModflowBcf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> wel = flopy.modflow.ModflowBcf.load('test.bcf', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, IWDFLG, WETFCT, IWETIT, IHDWET - line already read above
        if model.verbose:
            print '   loading IBCFCB, HDRY, IWDFLG, WETFCT, IWETIT, IHDWET...'
        t = line.strip().split()
        ibcfcb,hdry,iwdflg,wetfct,iwetit,ihdwet = int(t[0]),float(t[1]),int(t[2]),float(t[3]),int(t[4]),int(t[5])
        if ibcfcb != 0:
            model.add_pop_key_list(ibcfcb)
            ibcfcb = 53
        # LAYCON array
        if model.verbose:
            print '   loading LAYCON...'
        line = f.readline()
        t = line.strip().split()
        intercellt = np.zeros(nlay, dtype=np.int)
        laycon = np.zeros(nlay, dtype=np.int)
        for k in xrange(nlay):
            ival = int(t[k])
            if ival > 9:
                intercellt[k] = int(t[k][0])
                laycon[k] = int(t[k][1])
            else:
                laycon[k] = ival
        # TRPY array
        if model.verbose:
            print '   loading TRPY...'
        trpy = util_2d.load(f, model, (1, nlay), np.float32, 'trpy', ext_unit_dict)
        trpy = trpy.array.reshape( (nlay) )
        # property data for each layer based on options
        transient = not model.get_package('DIS').steady.all()
        sf1 = np.empty((nlay,nrow,ncol), dtype=np.float)
        tran = np.empty((nlay,nrow,ncol), dtype=np.float)
        hy = np.empty((nlay,nrow,ncol), dtype=np.float)
        if nlay > 1:
            vcont = np.empty((nlay-1,nrow,ncol), dtype=np.float)
        else:
            vcont = 1.0
        sf2 = np.empty((nlay,nrow,ncol), dtype=np.float)
        wetdry = np.empty((nlay,nrow,ncol), dtype=np.float)
        for k in xrange(nlay):
            if transient == True:
                if model.verbose:
                    print '   loading sf1 layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'sf1', ext_unit_dict)
                sf1[k,:,:] = t.array
            if ((laycon[k] == 0) or (laycon[k] == 2)):
                if model.verbose:
                    print '   loading tran layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'tran', ext_unit_dict)
                tran[k,:,:] = t.array
            else:
                if model.verbose:
                    print '   loading hy layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'hy', ext_unit_dict)
                hy[k,:,:] = t.array
            if k < (nlay - 1):
                if model.verbose:
                    print '   loading vcont layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'vcont', ext_unit_dict)
                vcont[k,:,:] = t.array
            if ((transient == True) and ((laycon[k] == 2) or (laycon[k] == 3))):
                if model.verbose:
                    print '   loading sf2 layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'sf2', ext_unit_dict)
                sf2[k,:,:] = t.array
            if ((iwdflg <> 0) and ((laycon[k] == 1) or (laycon[k] == 3))):
                if model.verbose:
                    print '   loading sf2 layer {0:3d}...'.format(k+1)
                t = util_2d.load(f, model, (nrow,ncol), np.float32, 'wetdry', ext_unit_dict)
                wetdry[k,:,:] = t.array

        #--create instance of bcf object
        bcf = ModflowBcf(model, ibcfcb=ibcfcb, intercellt=intercellt, laycon=laycon, trpy=trpy, hdry=hdry,
                         iwdflg=iwdflg, wetfct=wetfct, iwetit=iwetit, ihdwet=ihdwet,
                         tran=tran, hy=hy, vcont=vcont, sf1=sf1, sf2=sf2, wetdry=wetdry)

        #--return bcf object
        return bcf
Пример #20
0
    def load(f, model, ext_unit_dict=None):
        """
        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
        -------
        dis : ModflowDis object
            ModflowDis object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> dis = flopy.modflow.ModflowDis.load('test.dis', m)

        """

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

        if type(f) is not file:
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # dataset 1
        nlay, nrow, ncol, nper, itmuni, lenuni = line.strip().split()[0:6]
        nlay = int(nlay)
        nrow = int(nrow)
        ncol = int(ncol)
        nper = int(nper)
        itmuni = int(itmuni)
        lenuni = int(lenuni)
        # dataset 2 -- laycbd
        if model.verbose:
            print '   Loading dis package with:\n      ' + \
                  '{0} layers, {1} rows, {2} columns, and {3} stress periods'.format(nlay, nrow, ncol,nper)
            print '   loading laycbd...'
        laycbd = np.empty( (nlay), dtype=np.int)
        d = 0
        while True:
            line = f.readline()
            raw = line.strip('\n').split()
            for val in raw:
                laycbd[d] = np.int(val)
                d += 1
                if d == nlay:
                    break
            if d == nlay:
                break
        #dataset 3 -- delr
        if model.verbose:
            print '   loading delr...'
        delr = util_2d.load(f, model, (1, ncol), np.float32, 'delr',
                            ext_unit_dict)
        delr = delr.array.reshape( (ncol) )
        #dataset 4 -- delc
        if model.verbose:
            print '   loading delc...'
        delc = util_2d.load(f, model, (1, nrow), np.float32, 'delc',
                            ext_unit_dict)
        delc = delc.array.reshape( (nrow) )
        #dataset 5 -- top
        if model.verbose:
            print '   loading top...'
        top = util_2d.load(f, model, (nrow,ncol), np.float32, 'top',
                           ext_unit_dict)
        #dataset 6 -- botm
        if model.verbose:
            print '   loading botm...'
        ncbd=laycbd.sum()
        botm = util_3d.load(f, model, (nlay+ncbd,nrow,ncol), np.float32,
                            'botm', ext_unit_dict)
        #dataset 7 -- stress period info
        if model.verbose:
            print '   loading stress period data...'
        perlen = []
        nstp = []
        tsmult = []
        steady = []
        for k in xrange(nper):
            line = f.readline()
            a1, a2, a3, a4 = line.strip().split()[0:4]
            a1 = float(a1)
            a2 = int(a2)
            a3 = float(a3)
            if a4.upper() == 'TR':
                a4 = False
            else:
                a4 = True
            perlen.append(a1)
            nstp.append(a2)
            tsmult.append(a3)
            steady.append(a4)

        #--create dis object instance
        dis = ModflowDis(model, nlay, nrow, ncol, nper, delr, delc, laycbd, 
                         top, botm, perlen, nstp, tsmult, steady, itmuni,
                         lenuni)
        #--return dis object instance
        return dis
Пример #21
0
    def load(f, model, nlay=None, nrow=None, ncol=None, ext_unit_dict=None):
        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        #A1 and A2
        while True:
            line = f.readline()
            if line[0] != '#':
                break

        a3 = line.strip().split()
        nlay, nrow, ncol, nper, ncomp, mcomp = int(a3[0]), int(a3[1]), \
                                               int(a3[2]), int(a3[3]), \
                                               int(a3[4]), int(a3[5])
        if ncomp > 1:
            raise NotImplementedError("BTN.load() doesn't support ncomp > 1")

        a4 = f.readline().strip().split()
        tunit, lunit, munit = a4

        a5 = f.readline().strip().split()

        a6 = f.readline().strip().split()

        delr = util_2d.load(f, model, (ncol, 1), np.float32, 'delr',
                            ext_unit_dict)
        delc = util_2d.load(f, model, (nrow, 1), np.float32, 'delc',
                            ext_unit_dict)
        htop = util_2d.load(f, model, (nrow, ncol), np.float32, 'htop',
                            ext_unit_dict)
        dz = util_3d.load(f, model, (nlay, nrow, ncol), np.float32, 'dz',
                          ext_unit_dict)
        prsity = util_3d.load(f, model, (nlay, nrow, ncol), np.float32,
                              'prsity', ext_unit_dict)
        icbund = util_3d.load(f, model, (nlay, nrow, ncol), np.int, 'icbund',
                              ext_unit_dict)
        sconc = util_3d.load(f, model, (nlay, nrow, ncol), np.float32, 'sconc',
                             ext_unit_dict)

        a14 = f.readline().strip().split()
        cinact, thkmin = float(a14[0]), float(a14[1])

        a15 = f.readline().strip().split()
        ifmtcn,ifmtnp,ifmtrf,ifmtdp = int(a15[0]), int(a15[1]), int(a15[2]),\
                                      int(a15[3])
        savucn = False
        if (a15[4].lower() == 't'): savucn = True

        a16 = f.readline().strip().split()
        nprs = int(a16[0])
        timprs = []
        while len(timprs) < nprs:
            line = f.readline().strip().split()
            [timprs.append(float(l)) for l in line]

        a18 = f.readline().strip().split()
        nobs, nprobs = int(a18[0]), int(a18[1])
        obs = []
        while len(obs) < nobs:
            line = np.array(f.readline().strip().split(), dtype=np.int)
            obs.append(line)
        obs = np.array(obs)

        a20 = f.readline().strip().split()
        chkmas = False
        if (a20[0].lower() == 't'): chkmas = True
        nprmas = int(a20[1])
        dt0, mxstrn, ttsmult, ttsmax = [], [], [], []
        for kper in range(nper):
            line = f.readline().strip().split()
            tsm = float(line[2])
            if tsm <= 0:
                raise Exception("tsmult <= 0 not supported")
            line = f.readline().strip().split()

            dt0.append(float(line[0]))
            mxstrn.append(int(line[1]))
            ttsmult.append(float(line[2]))
            ttsmax.append(float(line[3]))

        f.close()
        btn = Mt3dBtn(model, ncomp=ncomp, mcomp=mcomp, tunit=tunit,
                      lunit=lunit, munit=munit, prsity=prsity, icbund=icbund,
                      sconc=sconc, cinact=cinact, thkmin=thkmin,
                      ifmtcn=ifmtcn, ifmtnp=ifmtnp, ifmtrf=ifmtrf,
                      ifmtdp=ifmtdp, savucn=savucn, nprs=nprs,\
                      timprs=timprs, obs=obs, nprobs=nprobs, chkmas=chkmas,\
                      nprmas=nprmas, dt0=dt0, mxstrn=mxstrn, ttsmult=ttsmult,\
                      ttsmax=ttsmax)
        return btn