예제 #1
0
파일: mfdis.py 프로젝트: arkottke/flopy
    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
예제 #2
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
예제 #3
0
파일: mfswi2.py 프로젝트: arkottke/flopy
    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
예제 #4
0
파일: mfbas.py 프로젝트: arkottke/flopy
    def load(f, model, nlay=None, 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.
        nlay, nrow, ncol : int, optional
            If not provided, then the model must contain a discretization
            package with correct values for these parameters.
        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
        -------
        bas : ModflowBas object
            ModflowBas object (of type :class:`flopy.modflow.ModflowBas`)

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> bas = flopy.modflow.ModflowBas.load('test.bas', m, nlay=1, nrow=10,
        >>>                                      ncol=10)

        """

        if model.verbose:
            sys.stdout.write('loading bas6 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 -- options
        line = line.upper()
        opts = line.strip().split()
        ixsec = False
        ichflg = False
        ifrefm = False
        iprinttime = False
        ishowp = False
        istoperror = False
        stoper = None
        if 'XSECTION' in opts:
            ixsec = True
        if 'CHTOCH' in opts:
            ichflg = True
        if 'FREE' in opts:
            ifrefm = True
        if 'PRINTTIME' in opts:
            iprinttime = True
        if 'SHOWPROGRESS' in opts:
            ishowp = True
        if 'STOPERROR' in opts:
            istoperror = True
            i = opts.index('STOPERROR')
            stoper = np.float32(opts[i+1])
        #get nlay,nrow,ncol if not passed
        if nlay is None and nrow is None and ncol is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        #dataset 2 -- ibound
        ibound = util_3d.load(f, model, (nlay, nrow, ncol), np.int, 'ibound',
                              ext_unit_dict)
        #print ibound.array
        #dataset 3 -- hnoflo
        line = f.readline()
        hnoflo = np.float32(line.strip().split()[0])
        #dataset 4 -- strt
        strt = util_3d.load(f, model, (nlay, nrow, ncol), np.float32, 'strt',
                            ext_unit_dict)
        f.close()
        #create bas object and return
        bas = ModflowBas(model, ibound=ibound, strt=strt,
                         ixsec=ixsec, ifrefm=ifrefm, ichflg=ichflg,
                         stoper=stoper, hnoflo=hnoflo)
        return bas
예제 #5
0
    def load(f, model, nlay=None, 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.
        nlay, nrow, ncol : int, optional
            If not provided, then the model must contain a discretization
            package with correct values for these parameters.
        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
        -------
        bas : ModflowBas object
            ModflowBas object (of type :class:`flopy.modflow.ModflowBas`)

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> bas = flopy.modflow.ModflowBas.load('test.bas', m, nlay=1, nrow=10,
        >>>                                      ncol=10)

        """

        if model.verbose:
            sys.stdout.write('loading bas6 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 -- options
        line = line.upper()
        opts = line.strip().split()
        ixsec = False
        ichflg = False
        ifrefm = False
        iprinttime = False
        ishowp = False
        istoperror = False
        stoper = None
        if 'XSECTION' in opts:
            ixsec = True
        if 'CHTOCH' in opts:
            ichflg = True
        if 'FREE' in opts:
            ifrefm = True
        if 'PRINTTIME' in opts:
            iprinttime = True
        if 'SHOWPROGRESS' in opts:
            ishowp = True
        if 'STOPERROR' in opts:
            istoperror = True
            i = opts.index('STOPERROR')
            stoper = np.float32(opts[i + 1])
        #get nlay,nrow,ncol if not passed
        if nlay is None and nrow is None and ncol is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        #dataset 2 -- ibound
        ibound = util_3d.load(f, model, (nlay, nrow, ncol), np.int, 'ibound',
                              ext_unit_dict)
        #print ibound.array
        #dataset 3 -- hnoflo
        line = f.readline()
        hnoflo = np.float32(line.strip().split()[0])
        #dataset 4 -- strt
        strt = util_3d.load(f, model, (nlay, nrow, ncol), np.float32, 'strt',
                            ext_unit_dict)
        f.close()
        #create bas object and return
        bas = ModflowBas(model,
                         ibound=ibound,
                         strt=strt,
                         ixsec=ixsec,
                         ifrefm=ifrefm,
                         ichflg=ichflg,
                         stoper=stoper,
                         hnoflo=hnoflo)
        return bas
예제 #6
0
파일: mtbtn.py 프로젝트: arkottke/flopy
    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
예제 #7
0
파일: mfdis.py 프로젝트: Kirubaharan/flopy
    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
예제 #8
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