Exemplo n.º 1
0
    def read_DIS(self):
        DX, DY, NLAY, self.NROW, self.NCOL, i = disutil.read_meta_data(self.SFRdata.MFdis)

        # get layer tops/bottoms
        self.layer_elevs = np.zeros((NLAY+1, self.NROW, self.NCOL))
        for c in range(NLAY + 1):
            tmp, i = disutil.read_nrow_ncol_vals(self.SFRdata.MFdis, self.NROW, self.NCOL, 'float', i)
            self.layer_elevs[c, :, :] = tmp

        # make dictionary of model top elevations by cellnum
        for c in range(self.NCOL):
            for r in range(self.NROW):
                cellnum = r*self.NCOL + c + 1
                self.elevs_by_cellnum[cellnum] = self.layer_elevs[0, r, c]
Exemplo n.º 2
0
    def read_DIS(self):
        self.DX, self.DY, self.NLAY, self.NROW, self.NCOL, i = disutil.read_meta_data(self.SFRdata.MFdis)

        self.DX *= self.mult
        self.DY = (self.DY * self.mult)[::-1]
        self.delx = np.append(np.diff(self.DX), np.diff(self.DX)[-1]) # add another spacing on because the vector doesn't include distal edge of grid
        self.dely = np.append(np.diff(self.DY), np.diff(self.DY)[-1])

        # get layer tops/bottoms
        self.layer_elevs = np.zeros((self.NLAY+1, self.NROW, self.NCOL))
        for c in range(self.NLAY + 1):
            tmp, i = disutil.read_nrow_ncol_vals(self.SFRdata.MFdis, self.NROW, self.NCOL, 'float', i)
            self.layer_elevs[c, :, :] = tmp

        # make dictionary of model top elevations by cellnum
        for c in range(self.NCOL):
            for r in range(self.NROW):
                cellnum = r*self.NCOL + c + 1
                self.elevs_by_cellnum[cellnum] = self.layer_elevs[0, r, c]
Exemplo n.º 3
0
    def read_DIS(self):
        self.DX, self.DY, self.NLAY, self.NROW, self.NCOL, i = disutil.read_meta_data(
            self.SFRdata.MFdis)

        self.DX *= self.mult
        self.DY = (self.DY * self.mult)[::-1]
        self.delx = np.append(
            np.diff(self.DX),
            np.diff(self.DX)[-1]
        )  # add another spacing on because the vector doesn't include distal edge of grid
        self.dely = np.append(np.diff(self.DY), np.diff(self.DY)[-1])

        # get layer tops/bottoms
        self.layer_elevs = np.zeros((self.NLAY + 1, self.NROW, self.NCOL))
        for c in range(self.NLAY + 1):
            tmp, i = disutil.read_nrow_ncol_vals(self.SFRdata.MFdis, self.NROW,
                                                 self.NCOL, 'float', i)
            self.layer_elevs[c, :, :] = tmp

        # make dictionary of model top elevations by cellnum
        for c in range(self.NCOL):
            for r in range(self.NROW):
                cellnum = r * self.NCOL + c + 1
                self.elevs_by_cellnum[cellnum] = self.layer_elevs[0, r, c]
Exemplo n.º 4
0
if DISutils_path not in sys.path:
    sys.path.append(DISutils_path)
import discomb_utilities
import os
import numpy as np

GHBfile = 'D:\\ATLData\\BadRiver\\Calibration_base\\BadRiver_GHB.tpl'
DISfile = 'D:\\ATLData\\Documents\\GitHub\\SFR\\BadRiver.dis'


# read in DIS information
DX, DY, nlay, nrows, ncols, i = discomb_utilities.read_meta_data(DISfile)

layer_elevs = np.zeros((nlay+1, nrows, ncols))
for c in range(nlay + 1):
    tmp, i = discomb_utilities.read_nrow_ncol_vals(DISfile, nrows, ncols, 'float', i)
    layer_elevs[c, :, :] = tmp

# read in GHBfile
header = 4
indat = open(GHBfile).readlines()
if "ptf" in indat[0]:
    header += 1

# write new GHB file
ofp = open(GHBfile+'_new', 'w')
logfile = open(os.path.split(GHBfile)[0]+'\\fix_GHB_log.txt', 'w')
logfile.write('Adjustments to GHB layering:\nl,r,c,elevation,new_layer\n')
for i in range(header):
    ofp.write(indat[i])
for i in range(len(indat))[header:]:
Exemplo n.º 5
0
raw_elevations = defaultdict(list)
min_max_elevations = defaultdict(list)
for seg in new_segs:

    lengths[seg] = list(new_streamcells_df[new_streamcells_df['Segment'] == seg].sort('Reach').LengthFt)
    raw_elevations[seg] = list(new_streamcells_df[new_streamcells_df['Segment'] == seg].sort('Reach').DEM_elev)
    min_max_elevations[seg] = [np.min(new_streamcells_df[new_streamcells_df['Segment'] == seg].sort('Reach').Elevmin),
                               np.max(new_streamcells_df[new_streamcells_df['Segment'] == seg].sort('Reach').Elevmax)]

# smooth interior elevations
elevations_sm, slopes = sm.connect_downhill(new_segs, lengths, raw_elevations, min_max_elevations, ofp)
elevations_sm = raw_elevations
'''
# read in elevations from dis file
DX, DY, NLAY, NROW, NCOL, i = disutil.read_meta_data(DISfile)
topdata, i = disutil.read_nrow_ncol_vals(DISfile, NROW, NCOL, np.float, i)

print "writing {}...".format(Mat1_updated)
# lookup row column from node number
X, Y = np.meshgrid(np.arange(1, NCOL+1), np.arange(1, NROW+1))
cr = np.vstack([X.ravel(), Y.ravel()])

Mat1_new_dict = {}
# build dict of new_segs (parallel structure to exisiting SFR dataframe)
for cell in new_streamcells_df.index:
    if new_streamcells_df.ix[cell, 'Segment'] > 0:
        node = new_streamcells_df.ix[cell, MFgrid_node_attribute]
        c, r = cr[:, node-1] # headache! -1 needed to translate from base=1 to base=0

        #sbtop = topdata[r, c] # get streambed top from model top
        seg, reach = int(new_streamcells_df.ix[cell, 'Segment']), int(new_streamcells_df.ix[cell, 'Reach'])
Exemplo n.º 6
0
raw_elevations = defaultdict(list)
min_max_elevations = defaultdict(list)
for seg in new_segs:

    lengths[seg] = list(new_streamcells_df[new_streamcells_df['Segment'] == seg].sort('Reach').LengthFt)
    raw_elevations[seg] = list(new_streamcells_df[new_streamcells_df['Segment'] == seg].sort('Reach').DEM_elev)
    min_max_elevations[seg] = [np.min(new_streamcells_df[new_streamcells_df['Segment'] == seg].sort('Reach').Elevmin),
                               np.max(new_streamcells_df[new_streamcells_df['Segment'] == seg].sort('Reach').Elevmax)]

# smooth interior elevations
elevations_sm, slopes = sm.connect_downhill(new_segs, lengths, raw_elevations, min_max_elevations, ofp)
elevations_sm = raw_elevations
'''
# read in elevations from dis file
DX, DY, NLAY, NROW, NCOL, i = disutil.read_meta_data(DISfile)
topdata, i = disutil.read_nrow_ncol_vals(DISfile, NROW, NCOL, np.float, i)

print "writing {}...".format(Mat1_updated)
# lookup row column from node number
X, Y = np.meshgrid(np.arange(1, NCOL + 1), np.arange(1, NROW + 1))
cr = np.vstack([X.ravel(), Y.ravel()])

Mat1_new_dict = {}
# build dict of new_segs (parallel structure to exisiting SFR dataframe)
for cell in new_streamcells_df.index:
    if new_streamcells_df.ix[cell, 'Segment'] > 0:
        node = new_streamcells_df.ix[cell, MFgrid_node_attribute]
        c, r = cr[:, node -
                  1]  # headache! -1 needed to translate from base=1 to base=0

        #sbtop = topdata[r, c] # get streambed top from model top
Exemplo n.º 7
0
DISutils_path = 'D:\\ATLData\\Documents\\GitHub\\SFR'
if DISutils_path not in sys.path:
    sys.path.append(DISutils_path)
import discomb_utilities
import os
import numpy as np

GHBfile = 'D:\\ATLData\\BadRiver\\Calibration_base\\BadRiver_GHB.tpl'
DISfile = 'D:\\ATLData\\Documents\\GitHub\\SFR\\BadRiver.dis'

# read in DIS information
DX, DY, nlay, nrows, ncols, i = discomb_utilities.read_meta_data(DISfile)

layer_elevs = np.zeros((nlay + 1, nrows, ncols))
for c in range(nlay + 1):
    tmp, i = discomb_utilities.read_nrow_ncol_vals(DISfile, nrows, ncols,
                                                   'float', i)
    layer_elevs[c, :, :] = tmp

# read in GHBfile
header = 4
indat = open(GHBfile).readlines()
if "ptf" in indat[0]:
    header += 1

# write new GHB file
ofp = open(GHBfile + '_new', 'w')
logfile = open(os.path.split(GHBfile)[0] + '\\fix_GHB_log.txt', 'w')
logfile.write('Adjustments to GHB layering:\nl,r,c,elevation,new_layer\n')
for i in range(header):
    ofp.write(indat[i])
for i in range(len(indat))[header:]:
Exemplo n.º 8
0
    VE = float(inpars.findall('.//options/VE')[0].text)
except:
    VE = -999

# get dimmensions
DX, DY, NLAY, NROW, NCOL, i = discomb_utilities.read_meta_data(DISfile)
if Xunits=='miles':
    DX,DY = DX/5280.0, DY/5280.0

row_interval = interval
col_interval = interval

# get layer tops/bottoms from DIS file
layer_elevs=np.zeros((NLAY+1, NROW, NCOL))
for c in range(NLAY+1):
    tmp, i = discomb_utilities.read_nrow_ncol_vals(DISfile, NROW, NCOL, 'float', i)
    layer_elevs[c, :, :] = tmp


if watertable.lower()=='on':
    hds = bf.HeadFile(HDSfile)
    heads = hds.get_data(kstp=1, kper=1)
    watertable = heads[0,:,:]
else:
    WTcolor = None
    WTthick = None

make_xsections([layer_elevs],watertable,DX,DY,[startrow,endrow,startcol,endcol],
               row_interval,col_interval,[xsname],colors,VE,
               Xunits=Xunits,linewidth=linewidth,WTcolor=WTcolor,WTthick=WTthick)
print "\nDone!"
Exemplo n.º 9
0
#
# Read in and handle the discritization file
#
indat = open(infile_dis,'r').readlines()

print 'Reading in the meta data'
DX,DY,NLAY,NROW,NCOL,i = disu.read_meta_data(indat)
[X,Y]=np.meshgrid(DX,DY)

print 'reading the model top and layer bottoms'
# Now read the Layer TOP and BOTTOMS
vertical_dis = np.zeros((NLAY+1,NROW,NCOL))
# now read the Model TOP
print 'reading model top'
TMP,i = disu.read_nrow_ncol_vals(indat,NROW,NCOL,np.float,i)
vertical_dis[0] = np.flipud(TMP)


# now read each of the other layers
for k in np.arange(NLAY):
    clay = k+1
    print 'reading bottom of layer --> %d ' %(clay)
    TMP,i = disu.read_nrow_ncol_vals(indat,NROW,NCOL,np.float,i)
    vertical_dis[k] = np.flipud(TMP)    

#
# Burn in the lake stages, if requested
#
if burn_in_lakes:
    indat = open(infile_lak,'r').readlines()
Exemplo n.º 10
0
# set bounds for vector field
r1, c1 = r1 + int(0.5*interval), c1 + int(0.5*interval)

# make GIS folder if there isn't one
if not os.path.isdir(path):
    os.makedirs(path)

# read in model information from DIS and SPC files
DX,DY,nlay,nrows,ncols,i=discomb_utilities.read_meta_data(os.path.join(path,disfile))
cellsize = DX[1] # grid must be uniform for ascii!!!

# get layer tops/bottoms
layer_elevs=np.zeros((nlay+1,nrows,ncols))
for c in range(nlay+1):
    tmp,i=discomb_utilities.read_nrow_ncol_vals(os.path.join(path,disfile),nrows,ncols,'float',i)
    layer_elevs[c,:,:]=tmp
    
# make a meshgrid for each vector location
X = cellsize*Coords_multiplier*(np.arange(ncols)+0.5)[c1:c2:interval] + originX
Y = cellsize*Coords_multiplier*(np.arange(nrows)+0.5) + originY
Y = np.flipud(Y)[r1:r2:interval] # need -0.5 above because of the flipud!!!
xy = np.meshgrid(X,Y)
cellnums = np.reshape(np.arange(nrows*ncols)+1, (ncols, nrows))[c1:c2:interval, r1:r2:interval]

# expand DX so that it can be broadcast with DY (if nrows != ncols)
DX, DY = np.expand_dims(DX, axis=0), np.expand_dims(DY, axis=1)

for l in range(nlay):
    
    # absolute discharge quantities
Exemplo n.º 11
0
        heads = hds.get_data(kstp=1, kper=1)
    except:
        print "\nError: Cannot read binary head-save file! {0}".format(os.path.join(path,headsfile))
        quit()
    return heads
    
########### Main Program ######################################################

# read in model information from DIS and SPC files
DX,DY,nlay,nrows,ncols,i=discomb_utilities.read_meta_data(os.path.join(path,disfile))


# get layer tops/bottoms
layer_elevs=np.zeros((nlay+1,nrows,ncols))
for c in range(nlay+1):
    tmp,i=discomb_utilities.read_nrow_ncol_vals(os.path.join(path,disfile),nrows,ncols,'float',i)
    layer_elevs[c,:,:]=tmp

# get list of K files
Kfiles=[f for f in os.listdir(path) if '._k' in f]

# initialize output pdf for R and K arrays
pdf=PdfPages(outpdf_kp)
print '\nsaving plots to %s:' %(outpdf_kp)
print Rchfile,
for cf in sorted(Kfiles):
    print cf,
print "\n"

# first plot recharge
Recharge_array, rchmult = read_rch(os.path.join(path, Rchfile))