コード例 #1
0
def plot():

    hds_file = grid.modelname + '.hds'
    hds_obj = mfb.MODFLOW_Head(grid.nlay, grid.nrow, grid.ncol, hds_file)
    htimes = hds_obj.get_time_list()
    q_args = []
    plot_dir = 'png\\'

    for htime in htimes[20:]:
        htime = htime[-1]
        totim, kper, kstp, arr, success = hds_obj.get_array(htime)
        for k in range(grid.nlay):

            ibnd = np.loadtxt(grid.ibound_names[k])
            arr_lay = arr[k, :, :]
            arr_lay = np.ma.masked_where(ibnd == 0, arr_lay)
            print k, arr_lay.min(), arr_lay.max()
            pname = plot_dir + 'head_' + str(k + 1) + '.png'
            plot_array(pname, arr_lay)

        break
コード例 #2
0
def extract(iter, kper):

    if iter != None:
        bak_prefix = seawat.ref_dir + 'bak\\' + str(iter) + '_'

    conc_file = 'MT3D001.UCN'
    concObj = mfb.MT3D_Concentration(seawat.nlay, seawat.nrow, seawat.ncol,
                                     conc_file)
    ctimes = concObj.get_time_list()
    init_time = ctimes[np.where(ctimes[:, 2] == kper)][0]
    init_seekpoint = long(init_time[-1])
    totim, kstp, kper, c, success = concObj.get_array(init_seekpoint)
    for k, lay in enumerate(seawat.layer_botm_names):
        aname = seawat.ref_dir + 'mod\\sconc_1_' + str(k + 1) + '.ref'
        if iter != None:
            bakname = bak_prefix + 'sconc_1_' + str(k + 1) + '.ref'
            aname2 = seawat.ref_dir + 'sconc_1_' + str(k + 1) + '.ref'
            shutil.copy(aname, bakname)
            shutil.copy(aname, aname2)
        print 'writing ', aname
        f = open(aname, 'w', 0)
        f.write(toString(c[k, :, :]))
        f.close()
コード例 #3
0
#--read ibound
ib_ref = os.path.join('..', 'REF', 'UMD_IBOUND.ref')
ib = au.loadArrayFromFile(nrow, ncol, ib_ref)
#--read the bottom of the model
bot_ref = os.path.join('..', 'REF', 'UMD_BOTM_L1.ref')
model_bot1 = au.loadArrayFromFile(nrow, ncol, bot_ref)
bot_ref = os.path.join('..', 'REF', 'UMD_BOTM_L2.ref')
model_bot2 = au.loadArrayFromFile(nrow, ncol, bot_ref)
bot_ref = os.path.join('..', 'REF', 'UMD_BOTM_L3.ref')
model_bot3 = au.loadArrayFromFile(nrow, ncol, bot_ref)
#--default data if command line argument not defined for variable
head_file = os.path.join(ResultsDir, 'UMD.hds')
zeta_file = os.path.join(ResultsDir, 'UMD.zta')
#--get available times in the head file
#--get available times in the head file
headObj = mfb.MODFLOW_Head(nlay, nrow, ncol, head_file)
head_time_list = headObj.get_time_list()
#--zeta surface to extract
zetaObj = mfb.MODFLOW_CBB(nlay, nrow, ncol, zeta_file)
zta_text = '    ZETAPLANE  1'
z1_time_list = zetaObj.get_time_list(zta_text)
zta_text = '    ZETAPLANE  2'
z2_time_list = zetaObj.get_time_list(zta_text)
#--get last head and last zeta
#--read head data - final zeta surface
iposition = long(head_time_list[-1, 3])
totim, kstp, kper, h, success = headObj.get_array(iposition)
#--read zeta data - final zeta surface
iposition = long(z1_time_list[-1, 3])
z1, totim, success = zetaObj.get_array(iposition)
iposition = long(z2_time_list[-1, 3])
コード例 #4
0
def main(num_plots):

    #--load well locations and pandas dataframe
    well_shapename = '..\\..\\_gis\\shapes\\pws_combine'
    well_points = sf.load_shape_list(well_shapename)
    #shp = sf.reader(well_shapename)
    #print sf.get_fieldnames(well_shapename)
    records = sf.load_as_dict(well_shapename, loadShapes=False)
    well_names = records['DPEP_NAME']
    well_zbots = records['zbot']
    float_zbots = []
    for i, wb in enumerate(well_zbots):
        float_zbots.append(float(wb))
    well_zbots = np.array(float_zbots)
    well_rows, well_cols = records['row'], records['column']
    pump = pandas.read_csv(
        '..\\..\\_pumpage\\dataframes\\pws_filled_zeros.csv',
        index_col=0,
        parse_dates=True)

    #--load lines and active dates
    line_shapename = '..\\..\\_gis\shapes\sw_reaches'
    lines = sf.load_shape_list(line_shapename)
    shp = sf.Reader(line_shapename)
    fnames = sf.get_fieldnames(line_shapename, ignorecase=True)
    #for i,fn in enumerate(fnames):
    #    print i,fn
    a_idx = fnames.index('ACTIVE_ST')
    line_active = []
    for i in range(shp.numRecords):
        rec = shp.record(i)
        year = int(rec[a_idx])
        if year < flow.start.year:
            year = flow.start.year
        dt = datetime(year=year, month=1, day=1)
        line_active.append(dt)

    #--head stuff
    #--use bot of Q5 to check for dry cells
    #hds_elev = np.loadtxt(flow.ref_dir+'Q5_bot.ref')
    #hds_layer_idx = 0
    #head_file = flow.root+'.hds'
    #headObj = mfb.MODFLOW_Head(flow.nlay,flow.nrow,flow.ncol,head_file)
    #htimes = headObj.get_time_list()

    #--conc stuff
    conc_lay_idxs = [0, 5, 9, 11]
    conc_file = 'MT3D001.UCN'
    concObj = mfb.MT3D_Concentration(seawat.nlay, seawat.nrow, seawat.ncol,
                                     conc_file)
    ctimes = concObj.get_time_list()

    #--zeta stuff
    #zta_layer_idx = 0
    #zta_elev = np.loadtxt(flow.ref_dir+'Q1_bot.ref')
    #zeta_file = flow.root+'.zta'
    #zetaObj = mfb.MODFLOW_CBB(flow.nlay,flow.nrow,flow.ncol,zeta_file)
    #zta_text = '    ZETAPLANE  1'
    #z1times = zetaObj.get_time_list(zta_text)
    #zeta_file = None

    #-- stress period step
    sp_step = 1
    plt_dir = 'png\\results\\seawat\\'

    #--for ffmpeg - sequentially numbered
    plt_num = 1
    istart = 0
    q_args = []
    for i, [start, end] in enumerate(zip(seawat.sp_start, seawat.sp_end)):
        if i >= istart and i % sp_step == 0:
            print 'building args list for stress period ending on ', end
            #--find the conc output nearest the end of the stress period

            try:
                kper_seekpoints = ctimes[np.where(ctimes[:, 2] == i + 1), -1]
                c_seekpoint = long(kper_seekpoints[0][-1])

            except:
                break

            act_lines = []
            for ldt, line in zip(line_active, lines):
                if ldt <= start:
                    act_lines.append(line)

            act_wells = []
            if i == 0:
                plt_start = start
            else:
                plt_start = seawat.sp_start[i - sp_step]
            plt_end = seawat.sp_end[i]
            pump_plt = pump[plt_start:plt_end]
            pump_plt_sum = pump_plt.sum()
            for wname, wpoint, wrow, wcol, wzbot in zip(
                    well_names, well_points, well_rows, well_cols, well_zbots):
                if wname in pump_plt.keys() and pump_plt_sum[wname] != 0:
                    act_wells.append(wpoint)

            fig_name = plt_dir + 'sp{0:03.0f}_conc.png'.format(plt_num)
            fig_title = 'stress period ' + str(
                i + 1) + ' start date ' + start.strftime('%d/%m/%Y')
            args = [
                fig_name, c_seekpoint, conc_lay_idxs, act_lines, act_wells,
                fig_title
            ]
            q_args.append(args)
            plt_num += 1
            if num_plots != None and i > num_plots:
                break

    jobq = mp.JoinableQueue()

    #--for testing
    if num_plots != None:
        jobq.put_nowait(q_args[0])
        jobq.put_nowait(None)
        plot_worker(jobq, 1, conc_file)
        return

    procs = []
    num_procs = 3

    for i in range(num_procs):
        #--pass the woker function jobq and a PID
        p = mp.Process(target=plot_worker, args=(jobq, i, conc_file))
        p.daemon = True
        print 'starting process', p.name
        p.start()
        procs.append(p)

    for q in q_args:
        jobq.put(q)

    for p in procs:
        jobq.put(None)

    #--block until all finish
    for p in procs:
        p.join()
        print p.name, 'Finished'

    anim_name = 'png\\demo_conc.avi'
    if os.path.exists(anim_name):
        os.remove(anim_name)
    cmd_line = 'ffmpeg.exe -i png\\results\\seawat\\sp%03d_conc.png -r 24 ' + anim_name + ' -y'
    os.system(cmd_line)
    return
コード例 #5
0
ファイル: SWRSample05.py プロジェクト: jdhughes/MF2005-SWR1
	swr_qaq04[n] = ce1[n,iextbf] #/ 86400.

#SWRObj = mfb.SWR_Record(2,SWR_file)
#ce1 = SWRObj.get_gage(iobs04)
##print 'qaq04 layer 2\n', ce1
#nt =  np.shape(ce1)[0]
#for n  in range(0,nt):
#	swr_qaq04[n] = swr_qaq04[n] + ce1[n,iextbf] #/ 86400.

#--MODFLOW results
#--heads
ncol = 6
nrow = 6
nlay = 2

iobs1node = mfb.icrl_from_kij(1,3,4,nlay,nrow,ncol)
iobs2node = mfb.icrl_from_kij(1,4,5,nlay,nrow,ncol)
iobs3node = mfb.icrl_from_kij(1,5,6,nlay,nrow,ncol)
iobs4node = mfb.icrl_from_kij(1,6,5,nlay,nrow,ncol)
#print 'MODFLOW observation location', iobs1node, iobs2node, iobs3node, iobs4node

HEAD_file = '..\\SWRSample05\\Results\\SWRSample05.hds'

HEADObj = mfb.MODFLOW_Head(nlay,ncol,nrow,HEAD_file)
mf1 = HEADObj.get_gage(iobs1node)
nmft =  np.shape(mf1)[0]
mf_t = np.zeros(nmft) 
mf_h01 = np.zeros(nmft) 
t = np.zeros(nmft) 
for n  in range(0,nmft):
	mf_t[n] = mf1[n,0]
コード例 #6
0
#--get a list of unique structure reaches
us = np.unique(sdata[:, idx_reach])
#print us

#--load structure info
ds_13a = swr.ds_13a('swr_full\\swr_ds13a_working_strval.dat')
ds_13a.load_structures()
#sys.exit()

#--load the entire active reach stage record
#--better to do it once than over and over
reach_key = np.loadtxt('swr_full\\swr_ds4a.dat',
                       skiprows=2,
                       usecols=[0, 2, 4, 5])
swr_obj = mfb.SWR_Record(0, 'results\\bro_6lay.stg')
totim, dt, kper, kstp, swrstp, success, r = swr_obj.next()
stage = r.copy()
stage_totim = [totim]
while True:
    totim, dt, kper, kstp, swrstp, success, r = swr_obj.next()
    if success is False:
        break
    stage = np.hstack((stage, r))
    stage_totim.append(totim)

#print stage.shape,stage_totim[0],stage_totim[-1]
#sys.exit()

#--iswrbnd
iswrbnd = np.loadtxt('swr_full\\swr_ds6.dat')
コード例 #7
0
def plot_worker(jobq, pid, hds_name, zta_name, dry_elev, zta_elev):

    if hds_name is not None:
        headObj = mfb.MODFLOW_Head(flow.nlay, flow.nrow, flow.ncol, hds_name)
        htimes = headObj.get_time_list()
        ntimes = htimes.shape[0]

    if zta_name is not None:
        zeta_file = flow.root + '.zta'
        zetaObj = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, zeta_file)
        zta_text = '    ZETAPLANE  1'
        z1times = zetaObj.get_time_list(zta_text)

    while True:
        args = jobq.get()
        if args == None:
            break
        '''args[0] = plot name           
           args[1] = hds seekpoint         
           args[2] = zeta seekpoint 
           args[3] = active reaches
           args[4] = active wells           
           args[5] = head layer index
           args[6] = zta layer index 
           args[7] = fig_title                 

        '''
        fig_name = args[0]
        hds_seekpoint = args[1]
        zta_seekpoint = args[2]
        lines = args[3]
        wells = args[4]
        h_layer_idx = args[5]
        z_layer_idx = args[6]
        fig_title = args[7]

        #--load and mask head
        if hds_name is not None:
            totim, kstp, kper, h, success = headObj.get_array(hds_seekpoint)

            hd = np.copy(h[h_layer_idx, :, :])
            dtw = np.copy(h[h_layer_idx, :, :])
            dtw = flow.top - dtw

            mask_flood = np.ones_like(dtw)
            mask_flood = np.ma.masked_where(dtw >= 0, mask_flood)
            mask_flood = np.ma.masked_where(
                np.logical_and(flow.ibound != 1, flow.ibound != 2), mask_flood)

            mask_dry = np.ones_like(dtw)
            mask_dry = np.ma.masked_where(hd > dry_elev, mask_dry)
            mask_dry = np.ma.masked_where(
                np.logical_and(flow.ibound != 1, flow.ibound != 2), mask_dry)

            hd = np.ma.masked_where(
                np.logical_and(flow.ibound != 1, flow.ibound != 2), hd)
            dtw = np.ma.masked_where(
                np.logical_and(flow.ibound != 1, flow.ibound != 2), dtw)

        #--load and mask zeta surface 1
        if zta_name is not None:
            z, totim, success = zetaObj.get_array(zta_seekpoint)

            z1 = z[z_layer_idx, :, :]
            z1m = np.ma.masked_where(z1 < zta_elev, z1)
            z1m = np.ma.masked_where(
                np.logical_and(flow.ibound != 1, flow.ibound != 2), z1m)
            dz1 = flow.top - z1m

        fig = pylab.figure(figsize=(8, 8))

        ax1 = pylab.axes((0.05, 0.525, 0.45, 0.45))
        ax2 = pylab.axes((0.05, 0.055, 0.45, 0.45))

        cax1 = pylab.axes((0.05, 0.53, 0.45, 0.015))
        cax2 = pylab.axes((0.05, 0.05, 0.45, 0.015))

        p1 = ax1.imshow(hd,
                        extent=imshow_extent,
                        cmap=cmap,
                        interpolation='none',
                        vmax=hd_levels[-1],
                        vmin=hd_levels[0])
        #p2 = ax2.imshow(dtw,extent=imshow_extent,cmap=cmap,interpolation='none',vmax=dtw_levels[-1],vmin=dtw_levels[0])
        p2 = ax2.imshow(z1m,
                        extent=imshow_extent,
                        interpolation='none',
                        vmax=0.0,
                        vmin=-135.0)

        #ax1.imshow(mask_flood,alpha=0.5,extent=imshow_extent,cmap=cmap_flood,interpolation='nearest',vmin=0,vmax=1)
        #ax2.imshow(mask_flood,alpha=0.5,extent=imshow_extent,cmap=cmap_flood,interpolation='nearest',vmin=0,vmax=1)

        ax1.imshow(mask_dry,
                   extent=imshow_extent,
                   cmap=cmap_dry,
                   interpolation='nearest',
                   vmin=0,
                   vmax=1)
        ax2.imshow(mask_dry,
                   extent=imshow_extent,
                   cmap=cmap_dry,
                   interpolation='nearest',
                   vmin=0,
                   vmax=1)

        cb1 = pylab.colorbar(p1, cax=cax1, orientation='horizontal')
        cb2 = pylab.colorbar(p2, cax=cax2, orientation='horizontal')

        cb1.set_label('water table elevation $ft NGVD$')
        cb2.set_label('elevation of interface $ft NGVD$')

        ax1.set_ylim(flow.plt_y)
        ax1.set_xlim(flow.plt_x)
        ax2.set_ylim(flow.plt_y)
        ax2.set_xlim(flow.plt_x)

        ax1.set_xticklabels([])

        #-- plot active reaches
        for line in lines:

            ax1.plot(line[0, :], line[1, :], 'k-', lw=0.25)
            ax2.plot(line[0, :], line[1, :], 'k-', lw=0.25)

        #-- plot active wells
        #for wpoint in wells:
        #    color=salt_well_color
        #    if hds_name:
        #        ax1.plot(wpoint[0],wpoint[1],'.',mfc=color,mec='none',ms=4)
        #        ax2.plot(wpoint[0],wpoint[1],'.',mfc=color,mec='none',ms=4)
        #    if zta_name:
        #        ax3.plot(wpoint[0],wpoint[1],'.',mfc=color,mec='none',ms=4)
        #        ax4.plot(wpoint[0],wpoint[1],'.',mfc=color,mec='none',ms=4)
        for wpoint in wells:
            color = 'k'

            ax1.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)
            ax2.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)

        fig.text(0.25, 0.965, fig_title, ha='center')
        pylab.savefig(fig_name, dpi=300, format='png', bbox_inches='tight')
        pylab.close('all')
        print pid, '-- done--', fig_title
        jobq.task_done()
    jobq.task_done()
    return
    l_idx = 0
    for t, b in zip(botm[:-1], botm[1:]):
        if z_elev >= t:
            in_lay[l_idx] = 1.0
        elif z_elev <= b:
            in_lay[l_idx] = 0.0
        else:
            in_lay[l_idx] = 0.5
        l_idx += 1
    return in_lay


#--read the zeta file
extract_sp = 48
zeta_file = flow.root + '.zta'
zetaObj = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, zeta_file)
zta_text = '    ZETAPLANE  1'
z1times = zetaObj.get_time_list(zta_text)
zta_seekpoint = long(z1times[extract_sp, 3])
z, totim, success = zetaObj.get_array(zta_seekpoint)
z1 = z[0, :, :]

#--build 3-d vertical geometry array
botm = np.zeros((seawat.nlay + 1, seawat.nrow, seawat.ncol))
botm[0, :, :] = seawat.top
for i, l in enumerate(seawat.layer_botm_names):
    b = np.loadtxt(seawat.ref_dir + l + '_bot.ref')
    botm[i + 1, :, :] = b

#--load the ibound to limit calcs
ibound = np.loadtxt(flow.ref_dir + 'ibound_CS.ref')
コード例 #9
0
a_idx = fnames.index('ACTIVE_ST')
line_active = []
for i in range(shp.numRecords):
    rec = shp.record(i)
    year = int(rec[a_idx])
    if year < bro.start.year:
        year = bro.start.year
    dt = datetime(year=year, month=1, day=1)
    line_active.append(dt)

#--head stuff
#--use bot of layer 1 to check for dry cells
l1_bot = np.loadtxt('ref\\Q5_bot.ref')
hds_layer_idx = 0
head_file = bro.modelname + '.hds'
headObj = mfb.MODFLOW_Head(bro.nlay, bro.nrow, bro.ncol, head_file)
htimes = headObj.get_time_list()
ntimes = htimes.shape[0]

#--swi stuff
#zta_layer_idx_1 = 3
#zta_layer_idx_2 = 4
#zta_layer_bot_1 = np.loadtxt('ref\\Q2_bot.ref')
#zta_layer_bot_2 = np.loadtxt('ref\\Q1_bot.ref')
#zeta_file = bro.modelname+'.zta'
#zetaObj = mfb.MODFLOW_CBB(bro.nlay,bro.nrow,bro.ncol,zeta_file)
#zta_text = '    ZETAPLANE  1'
#z1times = zetaObj.get_time_list(zta_text)
#zta_text = '    ZETAPLANE  2'
#z2times = zetaObj.get_time_list(zta_text)
コード例 #10
0
nreach = 2400

day_2_sec = 1.0/86400.0


shape_dir = 'shapes\\'


  
#sys.exit()
  
#--heads
ibound = np.loadtxt('ref\ibound.ref')


hds_handle = mfb.MODFLOW_Head(nlay,nrow,ncol,results+'bro_6lay.hds')
totim,kstp,kper,h,success = hds_handle.get_record()

conc_handle = mfb.MT3D_Concentration(nlay,nrow,ncol,'MT3D001.UCN')
totim_c,kstp_c,kper_c,c,success = conc_handle.get_record()

#--write concentrations at the end of the model run
for l in range(nlay):
    au.ref2grd('shapes\\conc_layer'+str(l+1)+'.txt',c[l,:,:],nrow,ncol,offset,500.0)        


#--loop over each month, using the last day in the month
#tot_days = 0
#for m in range(1,13):
#     
#    days = calendar.mdays[m]
コード例 #11
0
child = root.find('SimulatedSMPResults')
if child != None:
    SaveSimData = True
    ftxt = '{0}_{1}.smp'.format(child.text, TimeSample)
    fsimout = open(ftxt, 'w')
    print 'Processed simulated data will be saved to...{0}'.format(ftxt)
#--determine the SWR data to extract
swrdata = []
ctag = 'SWRModelItems'
swrmodelitems = root.find(ctag)
if swrmodelitems != None:
    for modelitem in swrmodelitems.findall('modelitem'):
        swrdata.append(modelitem.text)
if len(swrdata) == 0: SWRBudgetError(ctag, 10)
#--build index of data to extract from the flow file
SWRObj = mfb.SWR_Record(-1, SWRFlowFile)
swrdata_index = []
for sd in swrdata:
    idx = SWRObj.get_item_number(sd)
    swrdata_index.append(idx)
#--determine the number of pool budget observations
num_pools_obs = 0
ctag = 'swbudget'
for swbudget in root.findall(ctag):
    num_pools_obs += 1
if num_pools_obs == 0: SWRBudgetError(ctag, 11)
#--write summary information
print 'SWR pool definition file...{0}'.format(SWRPoolFile)
print 'processing stage data from...{0}\nFor the period from {1} to {2}'.format(
    SWRFlowFile, start_date, end_date)
print '  for {0} pool(s)'.format(num_pools_obs)
コード例 #12
0
                         'dis\\dataset.txt',
                         skiprows=2,
                         usecols=[0, 2, 4, 5])

f_out_riv = open('test.riv', 'w')
f_out_riv.write('#swr river equivalent\n')
f_out_riv.write('{0:10.0f} {1:10.0f}\n'.format(0, 0))
f_out_riv.write('{0:10.0f} {1:10.0f}\n'.format(nreach, 0))

f_out_wel = open('test.wel', 'w')
f_out_wel.write('#swr wel package equivalent\n')
f_out_wel.write('{0:10.0f} {1:10.0f}\n'.format(0, 0))
f_out_wel.write('{0:10.0f} {1:10.0f}\n'.format(nreach + mxact, 0))

#--get aq_ex info
swr_obj = mfb.SWR_Record(1, results + 'bro_7lay.aqx')
swr_items = swr_obj.get_item_list()
header_items = swr_obj.get_header_items()
st_idx = swr_items.index('stage')
cond_idx = swr_items.index('cond')
lay_idx = swr_items.index('ilay')
rch_idx = swr_items.index('irch')
aqflow_idx = swr_items.index('aq-rchflow')
bot_idx = swr_items.index('bottom')

#--setup unique,row and col arrays
totim, dt, kper, kstp, swrstp, success, r = swr_obj.next()
rch_unique = np.unique(r[:, rch_idx])
row = np.zeros_like(rch_unique) - 999
col = np.zeros_like(rch_unique) - 999
コード例 #13
0

#--use the iswrbnd to mask the inactive reaches
iswrbnd = np.loadtxt('swr_full\\swr_ds6.dat')



#--first make a backup copy
for l in range(bi.nlay):
    shutil.copy('ref\\init_heads_'+str(l+1)+'.ref','ref\\init_heads_'+str(l+1)+'_bak.ref')
shutil.copy('swr_full\\swr_ds14a.dat','swr_full\\swr_ds_14a_bak.dat')    
                     
          
#--heads
top = np.loadtxt('ref\\top_filter_20_edge.ref')
hds_handle = mfb.MODFLOW_Head(bi.nlay,bi.nrow,bi.ncol,results+'bro_6lay.hds')
try:
    totim,kstp,kper,h,success = hds_handle.get_record(float(sys.argv[1]))
    print 'heads from totim ',sys.argv[1],' read'
except:
    totim,kstp,kper,h,success = hds_handle.get_record()        
for l in range(bi.nlay):
    np.savetxt('ref\\init_heads_'+str(l+1)+'.ref',h[l,:,:],fmt='%15.6e')
h = ma.masked_where(h < -900.0,h)
h = ma.masked_where(h > top,h)
au.plotArray(h[0,:,:],bi.delr,bi.delc,offset=bi.offset,output=None,title='head')

#--get stages for init stage
swr_obj = mfb.SWR_Record(0,results+'bro_6lay.stg')
try:
    totim,dt,kper,kstp,swrstp,success,r = swr_obj.get_record(float(sys.argv[1]))
コード例 #14
0
def plot_worker(jobq, pid, dry_elev, zta_elev, hds1, hds2, zta1, zta2):

    headObj1 = mfb.MODFLOW_Head(flow.nlay, flow.nrow, flow.ncol, hds1)

    headObj2 = mfb.MODFLOW_Head(flow.nlay, flow.nrow, flow.ncol, hds2)

    zetaObj1 = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, zta1)

    zetaObj2 = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, zta2)

    while True:
        args = jobq.get()
        if args == None:
            break
        '''args[0] = plot name           
           args[1] = hds1 seekpoint         
           args[2] = zeta1 seekpoint
           args[3] = hds2 seekpoint
           args[4] = zeta2 seekpoint 
           args[5] = active reaches
           args[6] = active wells           
           args[7] = head layer index
           args[8] = zta layer index 
           args[9] = fig_title                 

        '''
        fig_name = args[0]
        hds1_seekpoint = args[1]
        zta1_seekpoint = args[2]
        hds2_seekpoint = args[3]
        zta2_seekpoint = args[4]
        lines = args[5]
        wells = args[6]
        h_layer_idx = args[7]
        z_layer_idx = args[8]
        fig_title = args[9]

        #--load and mask head

        totim, kstp, kper, h1, success = headObj1.get_array(hds1_seekpoint)
        hd1 = h1[h_layer_idx, :, :]
        hd1 = np.ma.masked_where(
            np.logical_and(flow.ibound != 1, flow.ibound != 2), hd1)

        totim, kstp, kper, h2, success = headObj2.get_array(hds2_seekpoint)
        hd2 = h2[h_layer_idx, :, :]
        hd2 = np.ma.masked_where(
            np.logical_and(flow.ibound != 1, flow.ibound != 2), hd2)

        hd_diff = hd1 - hd2
        hd_diff = np.ma.masked_where(np.abs(hd_diff) < 0.01, hd_diff)

        #hd1 = np.ma.masked_where(np.abs(hd_diff)<0.01,hd1)
        hd2 = np.ma.masked_where(np.abs(hd_diff) < 0.01, hd2)

        z1, totim, success = zetaObj1.get_array(zta1_seekpoint)
        z1 = z1[z_layer_idx, :, :]
        z1m = np.ma.masked_where(z1 < zta_elev, z1)
        z1m = np.ma.masked_where(
            np.logical_and(flow.ibound != 1, flow.ibound != 2), z1m)

        z2, totim, success = zetaObj2.get_array(zta2_seekpoint)
        z2 = z2[z_layer_idx, :, :]
        z2m = np.ma.masked_where(z2 < zta_elev, z2)
        z2m = np.ma.masked_where(
            np.logical_and(flow.ibound != 1, flow.ibound != 2), z2m)

        zt_diff = z1 - z2
        zt_diff = np.ma.masked_where(np.abs(zt_diff) < 0.1, zt_diff)

        fig = pylab.figure(figsize=(8, 8))

        ax1 = pylab.axes((0.05, 0.525, 0.45, 0.45))
        ax2 = pylab.axes((0.05, 0.055, 0.45, 0.45))
        cax1 = pylab.axes((0.05, 0.53, 0.45, 0.015))
        cax2 = pylab.axes((0.05, 0.05, 0.45, 0.015))

        #vmax = max(np.max(hd1),np.max(hd2))
        #vmin = min(np.min(hd1),np.min(hd2))
        vmax, vmin = 10, -5.0

        p1 = ax1.imshow(hd1,
                        extent=imshow_extent,
                        cmap=cmap,
                        interpolation='none',
                        vmax=vmax,
                        vmin=vmin)
        p2 = ax2.imshow(hd_diff,
                        extent=imshow_extent,
                        cmap=cmap,
                        interpolation='none')  #,vmax=vmax,vmin=vmin)

        cb1 = pylab.colorbar(p1, cax=cax1, orientation='horizontal')
        cb2 = pylab.colorbar(p2, cax=cax2, orientation='horizontal')

        cb1.set_label('elevation $ft NGVD$')
        cb2.set_label('elevation $ft NGVD$')

        ax1.set_ylim(flow.plt_y)
        ax1.set_xlim(flow.plt_x)
        ax2.set_ylim(flow.plt_y)
        ax2.set_xlim(flow.plt_x)

        ax1.set_xticklabels([])

        ax3 = pylab.axes((0.525, 0.525, 0.45, 0.45))
        ax4 = pylab.axes((0.525, 0.055, 0.45, 0.45))
        cax3 = pylab.axes((0.525, 0.53, 0.45, 0.015))
        cax4 = pylab.axes((0.525, 0.05, 0.45, 0.015))
        p3 = ax3.imshow(z1m, extent=imshow_extent, interpolation='none')
        p4 = ax4.imshow(zt_diff, extent=imshow_extent, interpolation='none')

        cb3 = pylab.colorbar(p3, cax=cax3, orientation='horizontal')
        cb4 = pylab.colorbar(p4, cax=cax4, orientation='horizontal')

        cb3.set_label('interface elevation $ft NGVD$')
        cb4.set_label('interface elevation $ft NGVD$')

        ax3.set_ylim(flow.plt_y)
        ax3.set_xlim(flow.plt_x)
        ax4.set_ylim(flow.plt_y)
        ax4.set_xlim(flow.plt_x)

        ax3.set_xticklabels([])
        ax3.set_yticklabels([])
        ax4.set_yticklabels([])

        #-- plot active reaches
        for line in lines:
            ax1.plot(line[0, :], line[1, :], 'k-', lw=0.25)
            ax2.plot(line[0, :], line[1, :], 'k-', lw=0.25)
            ax3.plot(line[0, :], line[1, :], 'k-', lw=0.25)
            ax4.plot(line[0, :], line[1, :], 'k-', lw=0.25)

        for wpoint in wells:
            color = 'k'
            ax1.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)
            ax2.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)
            ax3.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)
            ax4.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)

        fig.text(0.5, 0.965, fig_title, ha='center')
        pylab.savefig(fig_name, dpi=300, format='png', bbox_inches='tight')
        pylab.close('all')
        print pid, '-- done--', fig_title
        jobq.task_done()
    jobq.task_done()
    return
コード例 #15
0
        if basearg == '-resultsdir':
            try:
                iarg += 1
                ResultsDir = sys.argv[iarg]
                #--replace path in SWRFlowFile with the value passed from the command line
                SWRFlowFile = os.path.join(ResultsDir, SWRBaseName)
                print 'command line arg: -resultsdir = ', ResultsDir
            except:
                print 'cannot parse command line arg: -resultsdir'

print 'processing stage data from...{0}\nFor the period from {1} to {2}'.format(
    SWRFlowFile, start_date, end_date)
print '  for {0} discharge stations'.format(num_sites)

#--open swr connection flow file
SWRObj = mfb.SWR_Record(-2, SWRFlowFile)
itime = SWRObj.get_item_number('totim')
iflow = SWRObj.get_item_number('flow')

#--make sure output directories exist
OutputDir = os.path.join(ResultsDir, 'Figures', 'FlowObs')
umdutils.TestDirExist([
    os.path.join(ResultsDir, 'Figures', 'dir.tst'),
    os.path.join(OutputDir, 'dir.tst')
])
#--simulation dates
on_date = start_date
sim_dates = []
sim_dates.append(on_date)
while on_date < end_date:
    on_date += timedelta(days=1.)
コード例 #16
0
def plot_worker(jobq, pid, conc_file):

    concObj = mfb.MT3D_Concentration(seawat.nlay, seawat.nrow, seawat.ncol,
                                     conc_file)
    ctimes = concObj.get_time_list()

    while True:
        args = jobq.get()
        if args == None:
            break
        '''args[0] = plot name           
           args[1] = conc seekpoint         
           args[2] = conc layer to plot 
           args[3] = active reaches
           args[4] = active wells                    
           args[5] = fig_title                 

        '''
        fig_name = args[0]
        conc_seekpoint = args[1]
        lay_idxs = args[2]
        lines = args[3]
        wells = args[4]
        fig_title = args[5]

        totim, kstp, kper, c, success = concObj.get_array(conc_seekpoint)
        c = np.ma.masked_where(c <= 0.014, c)

        fig = pylab.figure(figsize=(8, 8))

        ax1 = pylab.axes((0.05, 0.525, 0.45, 0.45))
        ax2 = pylab.axes((0.05, 0.055, 0.45, 0.45))
        ax3 = pylab.axes((0.525, 0.525, 0.45, 0.45))
        ax4 = pylab.axes((0.525, 0.055, 0.45, 0.45))

        cax1 = pylab.axes((0.05, 0.53, 0.45, 0.015))
        cax2 = pylab.axes((0.05, 0.05, 0.45, 0.015))
        cax3 = pylab.axes((0.525, 0.53, 0.45, 0.015))
        cax4 = pylab.axes((0.525, 0.05, 0.45, 0.015))

        print np.max(c[lay_idxs[1], :, :])
        print np.min(c[lay_idxs[1], :, :])

        p1 = ax1.imshow(c[lay_idxs[0], :, :],
                        extent=imshow_extent,
                        cmap=cmap,
                        interpolation='none',
                        vmax=1.0,
                        vmin=0.0)
        p2 = ax2.imshow(c[lay_idxs[1], :, :],
                        extent=imshow_extent,
                        cmap=cmap,
                        interpolation='none',
                        vmax=1.0,
                        vmin=0.0)
        p3 = ax3.imshow(c[lay_idxs[2], :, :],
                        extent=imshow_extent,
                        cmap=cmap,
                        interpolation='none',
                        vmax=1.0,
                        vmin=0.0)
        p4 = ax4.imshow(c[lay_idxs[3], :, :],
                        extent=imshow_extent,
                        cmap=cmap,
                        interpolation='none',
                        vmax=1.0,
                        vmin=0.0)

        cb1 = pylab.colorbar(p1, cax=cax1, orientation='horizontal')
        cb2 = pylab.colorbar(p2, cax=cax2, orientation='horizontal')
        cb3 = pylab.colorbar(p3, cax=cax3, orientation='horizontal')
        cb4 = pylab.colorbar(p4, cax=cax4, orientation='horizontal')

        cb1.set_label('Concentration ' + seawat.layer_botm_names[lay_idxs[0]])
        cb2.set_label('Concentration ' + seawat.layer_botm_names[lay_idxs[1]])
        cb3.set_label('Concentration ' + seawat.layer_botm_names[lay_idxs[2]])
        cb4.set_label('Concentration ' + seawat.layer_botm_names[lay_idxs[3]])

        ax1.set_ylim(flow.plt_y)
        ax1.set_xlim(flow.plt_x)
        ax2.set_ylim(flow.plt_y)
        ax2.set_xlim(flow.plt_x)
        ax3.set_ylim(flow.plt_y)
        ax3.set_xlim(flow.plt_x)
        ax4.set_ylim(flow.plt_y)
        ax4.set_xlim(flow.plt_x)

        ax1.set_xticklabels([])
        ax3.set_xticklabels([])
        ax3.set_yticklabels([])
        ax4.set_yticklabels([])

        #-- plot active reaches
        for line in lines:
            ax1.plot(line[0, :], line[1, :], 'k-', lw=0.25)
            ax2.plot(line[0, :], line[1, :], 'k-', lw=0.25)
            ax3.plot(line[0, :], line[1, :], 'k-', lw=0.25)
            ax4.plot(line[0, :], line[1, :], 'k-', lw=0.25)

        #-- plot active wells
        #for wpoint in wells:
        #    color=salt_well_color
        #    if hds_name:
        #        ax1.plot(wpoint[0],wpoint[1],'.',mfc=color,mec='none',ms=4)
        #        ax2.plot(wpoint[0],wpoint[1],'.',mfc=color,mec='none',ms=4)
        #    if zta_name:
        #        ax3.plot(wpoint[0],wpoint[1],'.',mfc=color,mec='none',ms=4)
        #        ax4.plot(wpoint[0],wpoint[1],'.',mfc=color,mec='none',ms=4)
        for wpoint in wells:
            color = 'k'
            ax1.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)
            ax2.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)
            ax3.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)
            ax4.plot(wpoint[0], wpoint[1], '.', mfc=color, mec='none', ms=4)

        fig.text(0.5, 0.965, fig_title, ha='center')
        pylab.savefig(fig_name, dpi=300, format='png', bbox_inches='tight')
        pylab.close('all')
        print pid, '-- done--', fig_title
        jobq.task_done()
    jobq.task_done()
    return
コード例 #17
0
shape_dir = 'shapes\\'


  
#sys.exit()
  
#--heads
ibound = np.loadtxt('ref\ibound.ref')


#--loop over each month, using the last day in the month
tot_days = 0
for m in range(1,13):
     
    days = calendar.mdays[m]
    tot_days += days
    
    hds_handle = mfb.MODFLOW_Head(nlay,nrow,ncol,results+'bro_6lay.hds')
    totim,kstp,kper,h,success = hds_handle.get_record(tot_days)
           
    
    print 'day',tot_days,' processing for month ',m
    for l in range(nlay):
        
        this_head = h[l,:,:]        
        this_head[np.where(ibound==0)] = -9999.0
                     
        au.ref2grd('shapes\\head_layer'+str(l+1)+'_month'+str(m)+'.txt',\
                   h[l,:,:],nrow,ncol,offset,500.0)        
コード例 #18
0
#for i,fn in enumerate(fnames):
#    print i,fn
a_idx = fnames.index('ACTIVE_ST')
line_active = []
for i in range(shp.numRecords):
    rec = shp.record(i)
    year = int(rec[a_idx])
    if year < bro.start.year:
        year = bro.start.year
    dt = datetime(year=year,month=1,day=1)
    line_active.append(dt)


#--head instance
head_file = bro.modelname+'.hds'
headObj = mfb.MODFLOW_Head(bro.nlay,bro.nrow,bro.ncol,head_file)
htimes = headObj.get_time_list()
ntimes = htimes.shape[0]

#--izeta instance
zeta_file = bro.modelname+'.zta'

zetaObj = mfb.MODFLOW_CBB(bro.nlay,bro.nrow,bro.ncol,zeta_file)
zta_text = '    ZETAPLANE  1'
z1times = zetaObj.get_time_list(zta_text)
zta_text = '    ZETAPLANE  2'
z2times = zetaObj.get_time_list(zta_text)
#ntimes = times.shape[0]

#--plot infos
hd_levels = [-15.0,-5.0,-2.5,0.0,2.5,5.0,15.0]
コード例 #19
0
layer_refs = ['bot_q4.ref','bot_q3.ref','bot_q2.ref',\
              'bot_q1.ref','bot_t2.ref','bot_t1.ref']
l = 1
for r in layer_refs:
    this_lay = np.loadtxt(dir+r)
    master[l] = this_lay
    l += 1
    
   
xsec_row = 268
xsec_row = 185  #pompano
#xsec_row = 277   #dixie
#xsec_row = 380   #C-9
start_col,end_col = 250,450

conc_handle = mfb.MT3D_Concentration(nlay,nrow,ncol,'MT3D001.UCN')
totim_c,kstp_c,kper_c,c,success = conc_handle.get_record()

plot_array = master[:,xsec_row,start_col:end_col]
color_array = c[:,xsec_row,start_col:end_col]
fig = pylab.figure()

#xs,zs = get_cell_corners(delc,plot_array,offset)
#ax = pylab.subplot(211)
#p = ax.fill(xs,zs,edgecolor='none')



ax2 = pylab.subplot(111)

for l in range(1,nlay+1):
コード例 #20
0
shapename = '..\\..\\_gis\\scratch\\sw_reaches_conn_SWRpolylines_2'
records = shapefile.load_as_dict(shapename, loadShapes=False)
rc_tups = {}
rch_cbc, rch_aqx = {}, {}
rch_init = {}
for r, c, rch, rchgrp in zip(records['ROW'], records['COLUMN'],
                             records['REACH'], records['RCH_GRP']):
    rc_tup = (r, c)
    rc_tups[rch] = rc_tup
    rch_cbc[rc_tup] = []
    rch_aqx[rc_tup] = []
    rch_init[rc_tup] = 0.0

cbc_file = flow.root + '.cbc'
cbc_obj = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, cbc_file)
flux_type = '     SWR LEAKAGE'
#flux_times = cbb_obj.get_time_list(flux_type)
cbc_dts = []
#for flxtime in flux_times:
kper = 1
while True:
    flux, totim, success = cbc_obj.read_next_fluxtype(flux_type)
    if not success:
        break
    #seekpoint = flxtime[3]
    #flux,totim,success = cbb_obj.get_array(seekpoint)
    #kper = flxtime[2]
    #td = timedelta(days=totim)
    #dt = flow.start + td
    #print dt
コード例 #21
0
import pylab
import numpy as np

import MFBinaryClass as mfb

nrow, ncol, nlay = 383, 262, 3

hds_obj = mfb.MODFLOW_Head(nlay, nrow, ncol, 'tsala.hds')
totim, kstp, kper, hd, success = hds_obj.get_record()

for l in range(nlay):
    np.savetxt('ref\\init_heads_' + str(l + 1) + '.ref',
               hd[l, :, :],
               fmt='%15.6e')
コード例 #22
0
                ResultsDir = sys.argv[iarg]
                #--replace path in HeadFile with the value passed from the command line
                HeadFile = os.path.join(ResultsDir, HeadBaseName)
                print 'command line arg: -resultsdir = ', ResultsDir
            except:
                print 'cannot parse command line arg: -resultsdir'

print 'processing head data from...{0}\nFor the period from {1} to {2}'.format(
    HeadFile, start_date, end_date)
print '  for {0} head stations'.format(num_sites)

#--read discretization data
offset, nlay, nrow, ncol, delr, delc = mfd.load_dis_file(DIS_file)
xedge, yedge = mfd.edge_coordinates(nrow, ncol, delr, delc)
#--open head file
headObj = mfb.MODFLOW_Head(nlay, nrow, ncol, HeadFile)
times = headObj.get_time_list()
#--read ibound
ib = au.loadArrayFromFile(nrow, ncol, IBOUND_file)
#--read the top of layer 1
top_file = os.path.join('..', 'REF', 'UMD_URBAN_EDEN_TOPO.ref')
temp = au.loadArrayFromFile(nrow, ncol, top_file)
#--read layer bottoms
bot = np.zeros((nlay + 1, nrow, ncol), np.float)
bot[0, :, :] = np.copy(temp)
for k in xrange(0, nlay):
    bot_file = os.path.join('..', 'REF', 'UMD_BOTM_L{0}.ref'.format(k + 1))
    temp = au.loadArrayFromFile(nrow, ncol, bot_file)
    bot[k + 1, :, :] = np.copy(temp)

#--make sure output directories exist
コード例 #23
0
import numpy as np
import MFBinaryClass as mfb
from bro_pred import seawat
'''get initial conditions for seawat model predictive run - heads and zetas
'''

hds_file = '..\\..\\_model\\bro.02\\seawat.hds'
conc_file = '..\\..\\_model\\bro.02\\MT3D001.UCN'

hds_obj = mfb.MODFLOW_Head(seawat.nlay, seawat.nrow, seawat.ncol, hds_file)
conc_obj = mfb.MT3D_Concentration(seawat.nlay, seawat.nrow, seawat.ncol,
                                  conc_file)

htimes = hds_obj.get_time_list()
ctimes = conc_obj.get_time_list()

hseekpoint = long(htimes[-1, 3])
cseekpoint = long(ctimes[-1, 3])

hds_save = seawat.ref_dir + 'strt_'
conc_save = seawat.ref_dir + 'sconc_1_'

htotim, kstp, kper, h, hsuccess = hds_obj.get_array(hseekpoint)
ctotim, ckstp, ckper, c, csuccess = conc_obj.get_array(cseekpoint)

if not hsuccess:
    raise Exception('could not extract heads')

if not csuccess:
    raise Exception('could not extract zetas')
コード例 #24
0
              os.path.join( 'Results_DSL0304', 'UMD.fls' ), \
              os.path.join( 'Results_PCT125', 'UMD.fls' ), \
              os.path.join( 'Results_stat', 'UMD.fls' ) ]
yNames = [ '+0.304 m sea-level\n+25% PWS', \
           '+0.304 m sea-level', \
           '+25% PWS', \
           'Base case' ]
PBaseflow = np.zeros((len(flow_data)), np.float)
NBaseflow = np.zeros((len(flow_data)), np.float)
PBaseflowDry = np.zeros((len(flow_data)), np.float)
NBaseflowDry = np.zeros((len(flow_data)), np.float)
pool_number = 36
for idx, f in enumerate(flow_data):
    print 'reading data from...{0}'.format(f)
    fn = os.path.join(model_dir, f)
    SWRObj = mfb.SWR_Record(-1, fn)
    index_time = SWRObj.get_item_number('totim')
    index_bf = SWRObj.get_item_number('qbflow')
    ce1 = SWRObj.get_gage(pool_number)
    IsDry = True
    DryDays = 0
    for jdx in xrange(0, ce1.shape[0]):
        on_time = ce1[jdx, index_time]
        ondate = start_date + dt.timedelta(days=int(on_time))
        if on_time > float(num_days.days):
            break
        if IsDry == True:
            if ondate.month == dry_month_end:
                IsDry = False
        elif IsDry == False:
            if ondate.month == dry_month_start:
コード例 #25
0
def main():

    #--load well locations and pandas dataframe
    well_shapename = '..\\..\\_gis\\shapes\\pws_combine'
    well_points = sf.load_shape_list(well_shapename)
    #shp = sf.reader(well_shapename)
    #print sf.get_fieldnames(well_shapename)
    records = sf.load_as_dict(well_shapename, loadShapes=False)
    well_names = records['DPEP_NAME']
    well_zbots = records['zbot']
    float_zbots = []
    for i, wb in enumerate(well_zbots):
        float_zbots.append(float(wb))
    well_zbots = np.array(float_zbots)
    well_rows, well_cols = records['row'], records['column']
    pump = pandas.read_csv(
        '..\\..\\_pumpage\\dataframes\\pws_filled_zeros.csv',
        index_col=0,
        parse_dates=True)

    #--load lines and active dates
    line_shapename = '..\\..\\_gis\shapes\sw_reaches'
    lines = sf.load_shape_list(line_shapename)
    shp = sf.Reader(line_shapename)
    fnames = sf.get_fieldnames(line_shapename, ignorecase=True)
    #for i,fn in enumerate(fnames):
    #    print i,fn
    a_idx = fnames.index('ACTIVE_ST')
    line_active = []
    for i in range(shp.numRecords):
        rec = shp.record(i)
        year = int(rec[a_idx])
        if year < flow.start.year:
            year = flow.start.year
        dt = datetime(year=year, month=1, day=1)
        line_active.append(dt)

    #--head stuff
    #--use bot of Q5 to check for dry cells
    hds_elev = np.loadtxt(flow.ref_dir + 'Q5_bot.ref')
    hds_layer_idx = 0
    head_file = flow.root + '.hds'
    headObj = mfb.MODFLOW_Head(flow.nlay, flow.nrow, flow.ncol, head_file)
    htimes = headObj.get_time_list()

    #--zeta stuff
    zta_layer_idx = 0
    zta_elev = np.loadtxt(flow.ref_dir + 'Q1_bot.ref')
    zeta_file = flow.root + '.zta'
    zetaObj = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, zeta_file)
    zta_text = '    ZETAPLANE  1'
    z1times = zetaObj.get_time_list(zta_text)
    #zeta_file = None

    #-- stress period step
    sp_step = 1
    plt_dir = 'png\\results\\'

    #--for ffmpeg - sequentially numbered
    plt_num = 1
    istart = 0
    q_args = []
    for i, dt in enumerate(flow.sp_start):
        if i >= istart and i % sp_step == 0:
            print 'building args list for ', dt
            try:
                h_seekpoint = long(htimes[i, 3])
            except:
                break
            if zeta_file:
                z_seekpoint = long(z1times[i, 3])
            else:
                z_seekpoint = None

            act_lines = []
            for ldt, line in zip(line_active, lines):
                if ldt <= dt:
                    act_lines.append(line)

            act_wells = []
            if i == 0:
                plt_start = dt
            else:
                plt_start = flow.sp_start[i - sp_step]
            plt_end = flow.sp_end[i]
            pump_plt = pump[plt_start:plt_end]
            pump_plt_sum = pump_plt.sum()
            for wname, wpoint, wrow, wcol, wzbot in zip(
                    well_names, well_points, well_rows, well_cols, well_zbots):
                if wname in pump_plt.keys() and pump_plt_sum[wname] != 0:
                    act_wells.append(wpoint)

            fig_name = plt_dir + 'sp{0:03.0f}.png'.format(plt_num)
            #fig_title = 'stress period '+str(i+1)+' start date '+dt.strftime('%d/%m/%Y')
            fig_title = str(dt.year)
            args = [
                fig_name, h_seekpoint, z_seekpoint, act_lines, act_wells,
                hds_layer_idx, zta_layer_idx, fig_title
            ]
            q_args.append(args)
            plt_num += 1

    jobq = mp.JoinableQueue()

    #--for testing
    #jobq.put_nowait(q_args[0])
    #jobq.put_nowait(None)
    #plot_worker(jobq,0,head_file,None,hds_elev,zta_elev)
    #return

    procs = []
    num_procs = 6

    for i in range(num_procs):
        #--pass the woker function jobq and a PID
        p = mp.Process(target=plot_worker,
                       args=(jobq, i, head_file, zeta_file, hds_elev,
                             zta_elev))
        p.daemon = True
        print 'starting process', p.name
        p.start()
        procs.append(p)

    for q in q_args:
        jobq.put(q)

    for p in procs:
        jobq.put(None)

    #--block until all finish
    for p in procs:
        p.join()
        print p.name, 'Finished'

    cmd_line = 'ffmpeg.exe -i results\sp%03d.png -r 24 demo.avi -y'
    os.system(cmd_line)
    return
コード例 #26
0
delc = 1.0
delz = z_len / nlay

try:
    plt = [sys.argv[1]]
except:
    plt = ['h', 'c']

xsec_row = 0

cmap_heads = pylab.get_cmap('Spectral_r')
cmap_conc = cmap_heads
figsize = (4.67, 2.57)
axes = []
if 'h' in plt:
    hds_obj = mfb.MODFLOW_Head(nlay, nrow, ncol, 'henry_coarse.hds')
    while True:
        totim, kstp, kper, hd, success = hds_obj.next()
        print 'head', totim
        if success == False:
            break
        fig = pylab.figure()
        ax = pylab.subplot(111, aspect='equal')
        p = ax.pcolor(np.flipud(hd[:, xsec_row, :]),
                      cmap=cmap_heads,
                      vmin=hd.min(),
                      vmax=hd.max())
        ax.set_yticklabels([])
        ax.set_xticklabels([])
        cax = pylab.colorbar(p, orientation='horizontal')
        cax.ax.set_title('heads ' + str(totim))
コード例 #27
0
def apply():

    #--calibration
    keyfile = 'misc\\bro.03_calibration_seawatlist.key'
    key_well, key_wfield = {}, {}
    wconc, wfconc, wfflux, wfmass = {}, {}, {}, {}
    f = open(keyfile, 'r')
    for line in f:
        if 'wel' in line:
            raw = line.strip().split()
            kij = (int(raw[1]) - 1, int(raw[2]) - 1, int(raw[3]) - 1)
            if raw[0] in key_wfield.keys():
                if kij not in key_wfield[raw[0]]:
                    key_wfield[raw[0]].append(kij)
            else:
                key_wfield[raw[0]] = [kij]
                wfconc[raw[0]] = []
                wfflux[raw[0]] = []
                wfmass[raw[0]] = []

            if raw[4] in key_well.keys():
                key_well[raw[4]].append(kij)
            else:
                key_well[raw[4]] = [kij]
                wconc[raw[4]] = []

    path = 'bro.03\\calibration\\'
    cbc_file = path + cal.root + '_wel.cbc'
    cbc_obj = mfb.MODFLOW_CBB(cal.nlay, cal.nrow, cal.ncol, cbc_file)
    flux_type = '           WELLS'
    conc_file = path + 'MT3D001.UCN'
    conc_obj = mfb.MT3D_Concentration(cal.nlay, cal.nrow, cal.ncol, conc_file)
    dts = []
    for itime, end in enumerate(cal.sp_end):
        print end, '\r',
        ctotim, conc, kstp, kper, csuccess = conc_obj.next()
        flux, ftotim, fsuccess = cbc_obj.read_next_fluxtype(flux_type)

        if not csuccess:
            #raise Exception('Error reading binary file: '+str(conc_file))
            break
        if not fsuccess:
            #raise Exception('Error reading binary file: '+str(cbc_file))
            break
        if kper != itime + 1:
            #raise Exception('cbc kper not the same as loop kper')
            break
        if ctotim != ftotim:
            #raise Exception('cbc totim not the same as conc totim')
            break
        dts.append(end)
        #--individual wells - max concetration at any node for active wells
        for wname, kijs in key_well.iteritems():
            max_conc, max_flux = 0.0, 0.0
            for (k, i, j) in kijs:
                cn = conc[k, i, j]
                fx = np.abs(flux[k, i, j])
                if fx > 0.0 and cn > max_conc:
                    max_conc = cn
                    max_flux = fx
            if max_flux != 0.0:
                wconc[wname].append(max_conc)
            else:
                wconc[wname].append(np.NaN)

        #-- well fields
        for wname, kijs in key_wfield.iteritems():
            tot_mass, tot_fx = 0.0, 0.0
            for (k, i, j) in kijs:
                cn = conc[k, i, j]
                fx = np.abs(flux[k, i, j])
                tot_mass += (cn * fx)
                tot_fx += fx
            if tot_fx > 0.0:
                avg_conc = tot_mass / tot_fx

            else:
                avg_conc = np.NaN
                tot_mass = np.NaN

            wfconc[wname].append(avg_conc)
            wfflux[wname].append(tot_fx)
            wfmass[wname].append(tot_mass)

    df_wconc = pandas.DataFrame(wconc, index=dts)
    df_wconc.to_csv('calibration_wconc.csv')

    df_wfconc = pandas.DataFrame(wfconc, index=dts)
    df_wfconc.to_csv('calibration_wfconc.csv')
    df_wfmass = pandas.DataFrame(wfmass, index=dts)
    df_wfmass.to_csv('calibration_wfmass.csv')
コード例 #28
0
ファイル: MODFLOWFinal.py プロジェクト: jdhughes/PyClassMat
# --problem size
nlay, nrow, ncol = 1, 41, 40
# --default data if command line argument not defined for variable
head_file = "..\\data\\CoastalAquifer.hds"
# --get available times in the head file
get_cell = 1
headObj = mfb.MODFLOW_Head(nlay, nrow, ncol, head_file)
t = headObj.get_gage(get_cell)
ntimes = t.shape[0]
mf_times = np.zeros((ntimes), np.float)
for i in range(0, ntimes):
    mf_times[i] = t[i, 0]

# --create a time-series plot of head
headObj = mfb.MODFLOW_Head(nlay, nrow, ncol, head_file)
get_cell = mfb.icrl_from_kij(1, 18, 31, nlay, nrow, ncol)
t = headObj.get_gage(get_cell)
ztf = figure(figsize=(4, 2), facecolor="w")
ztf.subplots_adjust(wspace=0.2, hspace=0.2, left=0.15, right=0.95, bottom=0.15, top=0.95)
ax = ztf.add_subplot(1, 1, 1)
hp = ax.plot(mf_times / 365.25 - 100.0, t[:, 1])
ax.set_xlim(0, 50)
xlabel("Time since the beginning of groundwater withdrawls (years)")
ylabel("Head (m)")
output_name = "..\\figures.MF\\Cell_{0}.png".format(get_cell)
ztf.savefig(output_name, dpi=300)
# --create a time-series plot of drawdown
h0 = t[:, 1].max()
ztf = figure(figsize=(4, 2), facecolor="w")
ztf.subplots_adjust(wspace=0.2, hspace=0.2, left=0.15, right=0.95, bottom=0.15, top=0.95)
ax = ztf.add_subplot(1, 1, 1)
コード例 #29
0
#--problem size
nlay, nrow, ncol = 3, 189, 101
#--read ibound
ib_ref = os.path.join('..', 'REF', 'UMD_IBOUND.ref')
ib = au.loadArrayFromFile(nrow, ncol, ib_ref)
#--make sure output directories exist
OutputDir = os.path.join(ResultsDir, 'Figures', 'AnnualMET')
umdutils.TestDirExist([
    os.path.join(ResultsDir, 'Figures', 'dir.tst'),
    os.path.join(OutputDir, 'dir.tst')
])
#--default data if command line argument not defined for variable
met_file = os.path.join(ResultsDir, 'UMD.MET.bin')
#--get available times in the head file
#--zeta surface to extract
metObj = mfb.MODFLOW_CBB(nlay, nrow, ncol, met_file)
text = '     ET SEGMENTS'
sys.stdout.write('Building time list for...{0}\n'.format(text))
ets_time_list = metObj.get_time_list(text)
text = ' NEXRAD RAINFALL'
sys.stdout.write('Building time list for...{0}\n'.format(text))
rch_time_list = metObj.get_time_list(text)
text = '   SEPTIC RETURN'
sys.stdout.write('Building time list for...{0}\n'.format(text))
sep_time_list = metObj.get_time_list(text)
ntimes = sep_time_list.shape[0]
#--make a map
#--read shapefile to use as base map on figures
shape_name = os.path.join('D:/', 'Data', 'Users', 'jdhughes', 'GIS',
                          'Project Data', '2080DBF00', 'Spatial', 'FigureData',
                          'BaseMap')
コード例 #30
0
rch_idx = 4
rchgrp_idx = 5
wr = shapefile.Writer()
for item in polyline_header:
    wr.field(item[0],fieldType=item[1],size=item[2],decimal=item[3])


reach_key = load_reaches(nreach,'dis\\dataset.txt',skiprows=2,usecols=[0,2,4,5])
reach_array = np.zeros((nrow,ncol)) - 999.

ibnd = load_swr_ibnd('swr\\swr_ibnd.dat')
print ibnd[0]
#sys.exit()


swr_obj = mfb.SWR_Record(-1,results+'bro_7lay.rgp')
#totim,dt,kper,kstp,swrstp,success,compele = swr_obj.get_record()
ce_items = swr_obj.get_item_list()
#f_list = []
#print compele.shape
#sys.exit()

#for item in ce_items:
#    wr.field(item,fieldType='N',size=30,decimal=5)
#
##--loop over each polyline
#print 'processing reaches...'
#for p in range(num_records):
#    this_rec = reach_shp.record(p)
#    this_rchgrp = this_rec[rchgrp_idx]
#    this_reach = this_rec[rch_idx]
コード例 #31
0
            lines.append(line)
        f.close()
        wel_bnds_seawat[dt] = lines

#aq_file = flow.root+'.aqx'
#aq_obj = mfb.SWR_Record(flow.nlay,aq_file)

#--get baseflow from each reach
#fls_file = flow.root+'.fls'
#fls_obj = mfb.SWR_Record(-1,fls_file)
#fls_items = fls_obj.get_item_list()
#bf_idx = 6
sp_num = 1

cbc_file = flow.root + '_swr.cbc'
cbc_obj = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, cbc_file)
flux_type = '     SWR LEAKAGE'

#--for writing the external wel lists
bnd_prefix_seawat = seawat.list_dir + '\\welswr_'
bnd_prefix_flow = flow.list_dir + '\\welswr_'

f_wel_seawat = open(seawat.root + '_swr.wel', 'w', 0)
f_wel_seawat.write('# ' + sys.argv[0] + ' ' + str(datetime.now()) + '\n')
f_wel_seawat.write('# combined pumpage and swr qbflow\n')
#--write a guess of mxact
f_wel_seawat.write(' {0:9.0f} {1:9.0f} {2}\n'.format(20000, seawat.well_unit,
                                                     'NOPRINT'))

f_wel_flow = open(flow.root + '_swr.wel', 'w', 0)
f_wel_flow.write('# ' + sys.argv[0] + ' ' + str(datetime.now()) + '\n')
コード例 #32
0
def main():

    #--load well locations and pandas dataframe
    well_shapename = '..\\..\\_gis\\shapes\\pws_combine'
    well_points = sf.load_shape_list(well_shapename)

    #--load lines and active dates
    line_shapename = '..\\..\\_gis\shapes\sw_reaches'
    lines = sf.load_shape_list(line_shapename)

    #--head stuff
    #--use bot of Q5 to check for dry cells
    hds_elev = np.loadtxt(flow.ref_dir + 'Q5_bot.ref')
    hds_layer_idx = 0
    head_file = flow.root + '.hds'
    headObj = mfb.MODFLOW_Head(flow.nlay, flow.nrow, flow.ncol, head_file)
    htimes = headObj.get_time_list()

    #--zeta stuff
    zta_layer_idx = 0
    zta_elev = np.loadtxt(flow.ref_dir + 'Q1_bot.ref')
    zeta_file = flow.root + '.zta'
    zetaObj = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, zeta_file)
    zta_text = '    ZETAPLANE  1'
    z1times = zetaObj.get_time_list(zta_text)
    #zeta_file = None

    #-- stress period step
    sp_step = 1
    plt_dir = 'png\\results\\'

    #--for ffmpeg - sequentially numbered
    plt_num = 1
    istart = 0
    q_args = []
    for i, dt in enumerate(flow.sp_start):
        if i >= istart and i % sp_step == 0:
            print 'building args list for ', dt
            try:
                h_seekpoint = long(htimes[i, 3])
            except:
                break
            if zeta_file:
                z_seekpoint = long(z1times[i, 3])
            else:
                z_seekpoint = None

            fig_name = plt_dir + 'sp{0:03.0f}.png'.format(plt_num)
            #fig_title = 'stress period '+str(i+1)+' start date '+dt.strftime('%d/%m/%Y')
            fig_title = str(dt.year)
            args = [
                fig_name, h_seekpoint, z_seekpoint, lines, well_points,
                hds_layer_idx, zta_layer_idx, fig_title
            ]
            q_args.append(args)
            plt_num += 1

    jobq = mp.JoinableQueue()

    #--for testing
    #jobq.put_nowait(q_args[0])
    #jobq.put_nowait(None)
    #plot_worker(jobq,0,head_file,None,hds_elev,zta_elev)
    #return

    procs = []
    num_procs = 3

    for i in range(num_procs):
        #--pass the woker function jobq and a PID
        p = mp.Process(target=plot_worker,
                       args=(jobq, i, head_file, zeta_file, hds_elev,
                             zta_elev))
        p.daemon = True
        print 'starting process', p.name
        p.start()
        procs.append(p)

    for q in q_args:
        jobq.put(q)

    for p in procs:
        jobq.put(None)

    #--block until all finish
    for p in procs:
        p.join()
        print p.name, 'Finished'

    cmd_line = 'ffmpeg.exe -i results\sp%03d.png -r 24 demo.avi -y'
    os.system(cmd_line)
    return