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
#--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]) z2, totim, success = zetaObj.get_array(iposition) #--save data #--heads
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
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
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] dtw_levels = [0.0,1.5,2.5,5.0,15.0] zelev_min,zelev_max = -150.0,0.0 imshow_extent = [bro.x[0],bro.x[-1],bro.y[0],bro.y[-1]] #mask_color = '#E0E0E0' mask_color = '#FFFFFF' cmap = mpl.cm.jet cmap.set_bad(mask_color,1)
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
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('flowref\\Q5_bot.ref') hds_layer_idx = 0 head_file1 = 'flow.hds' headObj1 = mfb.MODFLOW_Head(flow.nlay, flow.nrow, flow.ncol, head_file1) htimes1 = headObj1.get_time_list() head_file2 = 'flow_noriv.hds' headObj2 = mfb.MODFLOW_Head(flow.nlay, flow.nrow, flow.ncol, head_file2) htimes2 = headObj2.get_time_list() #--zeta stuff zta_layer_idx = 0 zta_elev = np.loadtxt('flowref\\Q1_bot.ref') zeta_file1 = 'flow.zta' zetaObj1 = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, zeta_file1) zta_text1 = ' ZETAPLANE 1' z1times1 = zetaObj1.get_time_list(zta_text1) zeta_file2 = 'flow_noriv.zta' zetaObj2 = mfb.MODFLOW_CBB(flow.nlay, flow.nrow, flow.ncol, zeta_file2) zta_text2 = ' ZETAPLANE 1' z1times2 = zetaObj2.get_time_list(zta_text2) #-- stress period step sp_step = 1 plt_dir = 'png\\results_compare\\' #--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_seekpoint1 = long(htimes1[i, 3]) h_seekpoint2 = long(htimes2[i, 3]) except: break z_seekpoint1 = long(z1times1[i, 3]) z_seekpoint2 = long(z1times2[i, 3]) 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') args = [ fig_name, h_seekpoint1, z_seekpoint1, h_seekpoint2, z_seekpoint2, 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,1,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, hds_elev, zta_elev, head_file1, head_file2, zeta_file1, zeta_file2)) 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' return
import numpy as np import MFBinaryClass as mfb from bro_pred import flow '''get initial conditions for flow model predictive run - heads and zetas ''' hds_file = '..\\..\\_model\\bro.03\\flow.hds' zta_file = '..\\..\\_model\\bro.03\\flow.zta' zta_text = ' ZETAPLANE 1' hds_obj = mfb.MODFLOW_Head(flow.nlay,flow.nrow,flow.ncol,hds_file) zta_obj = mfb.MODFLOW_CBB(flow.nlay,flow.nrow,flow.ncol,zta_file) htimes = hds_obj.get_time_list() ztimes = zta_obj.get_time_list(zta_text) hseekpoint = long(htimes[-1,3]) zseekpoint = long(ztimes[-1,3]) hds_save = flow.ref_dir+'strt_1.ref' zta_save = flow.ref_dir+'IZETA_1_L1.ref' htotim,kstp,kper,h,hsuccess = hds_obj.get_array(hseekpoint) z,ztotim,zsuccess = zta_obj.get_array(zseekpoint) if not hsuccess: raise Exception('could not extract heads') if not zsuccess: raise Exception('could not extract zetas')
wellfield_conc[wfield] = [] wellfield_flux[wfield] = [] if wname in well_kij.keys(): well_kij[wname].append(kij) else: well_kij[wname] = [kij] well_conc[wname] = [] well_flux[wname] = [] f.close() break #--for individual wells cbc_file = seawat.root + '_wel.cbc' cbc_obj = mfb.MODFLOW_CBB(seawat.nlay, seawat.nrow, seawat.ncol, cbc_file, aslist=True) flux_type = ' WELLS' conc_file = 'MT3D001.UCN' conc_obj = mfb.MT3D_Concentration(seawat.nlay, seawat.nrow, seawat.ncol, conc_file) for itime, end in enumerate(seawat.sp_end): ctotim, conc, kstp, kper, csuccess = conc_obj.next() flux, ftotim, fsuccess = cbc_obj.read_next_fluxtype(flux_type) #nnz_kijs = [] #for i in range(seawat.nrow): # for j in range(seawat.ncol): # for k in range(seawat.nlay): # if flux[k,i,j] != 0.0: