Пример #1
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:
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]
#--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')
Пример #4
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)
    #print dt
    dt = flow.sp_end[kper - 1]
    print kper, dt
    cbc_dts.append(dt)
    #for r,c,rch,rgp in rc_tups:
    #    rch_cbc[rch].append(flux[0,r-1,c-1])
    for rc in rch_cbc.keys():
        rch_cbc[rc].append(flux[0, rc[0] - 1, rc[1] - 1])
    kper += 1

df_cbc = pandas.DataFrame(rch_cbc, index=cbc_dts)
df_cbc.to_csv('cbc_df.csv', index_label='datetime')
sys.exit()

aq_file = flow.root + '.aqx'
aq_obj = mfb.SWR_Record(flow.nlay, aq_file)
aqx_dts = []
while True:
    this_rec = copy.deepcopy(rch_init)
    totim, length, kper, kstp, swrstp, success, records = aq_obj.next()
    dt = flow.sp_end[kper - 1]

    if not success: break
    print kper, dt
    aqx_dts.append(dt)
    for i, rec in enumerate(records):
        #rch_aqx[rec[0]].append(rec[-1])
        rc = rc_tups[rec[0]]
        this_rec[rc] += rec[-1]

    for rc in this_rec.keys():
Пример #6
0
                     
          
#--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]))
    print 'SWR binary from totim ',sys.argv[1],' read'
except:
    totim,dt,kper,kstp,swrstp,success,r = swr_obj.get_record()   
    
#print reach_key[:,0],r
#np.savetxt('stage_out.dat',np.array([reach_key[:,0],r]))
save_stage(reach_key[:,0],reach_key[:,1],r)



#pylab.show()  
                         '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
Пример #8
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.)
Пример #9
0
        if basearg == '-resultsdir':
            try:
                iarg += 1
                ResultsDir = sys.argv[iarg]
                #--replace path in SWRStageFile with the value passed from the command line
                SWRStageFile = 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( SWRStageFile, start_date, end_date )
print '  for {0} stage stations'.format( num_sites )

#--open swr stage file
SWRObj = mfb.SWR_Record(0,SWRStageFile)
itime  = SWRObj.get_item_number('totim')
istage = SWRObj.get_item_number('stage')

#--make sure output directories exist
OutputDir = os.path.join( ResultsDir, 'Figures', 'StageObs' )
umdutils.TestDirExist([os.path.join( ResultsDir,'Figures','dir.tst' ),os.path.join( OutputDir, 'dir.tst' )])
#--simulation dates
on_date = start_date
plot_dates = []
plot_dates.append( on_date )
while on_date < end_date:
    on_date += timedelta(days=1.)
    plot_dates.append( on_date )
plot_dates = np.array( plot_dates )
Пример #10
0
    return
    
   

nrow,ncol,nlay = 411,501,6
delr,delc = 500,500
offset = [728600.0,577350.0,0.0]
results = 'results\\'
nreach = 2400


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


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


for i in fig_idx:
    
    array = np.zeros_like(reach_array) - 9999
    m_array = np.zeros_like(reach_array) - 999.    
    for a in range(0,len(compele)):
        thisCompele = reach_key[np.where(reach_key[:,1]==a+1)].astype(int)