def write_text(): with open("./experimetal_settings.log", "w") as f: f.write("# Experimental Settings\n") f.write("# " + pm.version() + "\n") f.write("# " + pm.CaMa_ver() + "\n") f.write("#======================================================\n") # Experimental Settings f.write("# Experiment Name: " + pm.experiment() + "\n") f.write("# Experiment Mode: " + "%d" % (pm.mode()) + "\n") # Runoff data f.write("# Runoff Data: " + pm.input(pm.mode()) + "\n") # Time domain for analysis f.write("# Start Date: %04d-%02d-%02d\n" % (pm.starttime())) f.write("# End Date: %04d-%02d-%02d\n" % (pm.endtime())) # Calibration f.write("# Model Calibration: " + calibration(pm.calibrate()) + "\n") # Assimilation Settings f.write("# Assimilation Mode: " + assimlation_mode(pm.conflag()) + "\n") f.write("# Assimilation Domain: \n") f.write("# \tWest : %5.2f\n" % (pm.assimW())) f.write("# \tSouth: %5.2f\n" % (pm.assimS())) f.write("# \tEest : %5.2f\n" % (pm.assimE())) f.write("# \tNorth: %5.2f\n" % (pm.assimN())) f.write("# Assimilation Settings: \n") f.write("# \tPatch Size : " + patch_character(pm.patch_size()) + "\n") f.write("# \tPatch Id : " + pm.patch_name() + " " + pm.patch_id() + "\n") f.write("# \tInflation Method : " + inflation_para(pm.rho()) + "\n") f.write("# Assimilation Statistics: \n") f.write("# \tMean : " + stat_name(pm.conflag(), pm.calibrate())[0] + "\n") f.write("# \tStandrad Deviation : " + stat_name(pm.conflag(), pm.calibrate())[1] + "\n") return 0
def SWOT_day(yyyy,mm,dd): st_year,st_month,st_date=pm.starttime() start_time=datetime.date(st_year,st_month,st_date) this_time=datetime.date(int(yyyy),int(mm),int(dd)) days=this_time-start_time days=days.days return days%21+1
def prepare_obs_old(): """ Prepare observations as textfile """ # global lname, xlist, ylist, leledif, lEGM08, lEGM96, satellite # if pm.obs_name() == "HydroWeb": # lname, xlist, ylist, leledif, lEGM08, lEGM96, satellite = get_HydroWeb() # print ("lname: ",len(lname)) # else: # lname, xlist, ylist, leledif, lEGM08, lEGM96, satellite = get_HydroWeb() # print (len(lname)) syear, smon, sday = pm.starttime() eyear, emon, eday = pm.endtime() start_dt = datetime.date(syear, smon, sday) end_dt = datetime.date(eyear, emon, eday) start = 0 last = (end_dt - start_dt).days # print (start,last) #------- inputlist = [] for day in np.arange(start, last): target_dt = start_dt + datetime.timedelta(days=day) yyyy = '%04d' % (target_dt.year) mm = '%02d' % (target_dt.month) dd = '%02d' % (target_dt.day) # print (yyyy,mm,dd) #,obs_dir inputlist.append([yyyy, mm, dd]) # write text files parallel p = Pool(pm.cpu_nums() * pm.para_nums()) p.map(write_txt, inputlist) p.terminate() # map(write_txt,inputlist) return 0
def make_initial_infl(): nx, ny, gsize = pm.map_dimension() parm_infl = np.ones([ny, nx], np.float32) * pm.initial_infl() start_year, start_month, start_date = pm.starttime( ) # Start year month date yyyy = '%04d' % (start_year) mm = '%02d' % (start_month) dd = '%02d' % (start_date) parm_infl.tofile("./inflation/parm_infl" + yyyy + mm + dd + ".bin") return 0
def cal_monthly_mean_ens(ens_num): #start_year,end_year,ens_num,months=24): # calc monthly mean value for two years start_year=pm.spinup_end_year() end_year,end_month,end_date=pm.starttime() #start_year=pm.start_year() #inputlist[0] #end_year=pm.end_year() #inputlist[1] #ens_num=inputlist[2] months=24 #inputlist[3] #threshold=inputlist[4] runname=pm.runname(pm.mode()) if runname=="E2O": nx=1440 ny=720 threshold=0.1 else: nx=360 ny=180 threshold=1.0e-8 #os.system("rm -Rf ./CaMa_in/ELSE_GPCC/mean_month/*") mkdir("./CaMa_in/"+runname+"/mean_month") #os.system("rm -Rf ./CaMa_in/ELSE_KIM2009/mean_month/*") #threshold=0.1 start_dt=datetime.date(start_year,1,1) end_dt=datetime.date(end_year,12,31) ens_char="%03d"%(ens_num) for month in np.arange(months): ynow=int(start_year+int(month/12)) ychar="%04d"%(ynow) mchar="%02d"%((month%12)+1) #print ychar, mchar roff_mon=np.zeros([ny,nx],np.float32)#.reshape([180,360]) count=np.zeros([ny,nx],np.float32)#.reshape([180,360]) for day in np.arange(month*30,(month+1)*30): day_num=day-month*30 running_dt=start_dt+datetime.timedelta(days=day) yyyy='%04d' % (running_dt.year) mm='%02d' % (running_dt.month) dd='%02d' % (running_dt.day) roff=np.fromfile(pm.DA_dir()+"/inp/"+runname+"/Roff/Roff__"+str(yyyy)+str(mm)+str(dd)+ens_char+".one",np.float32).reshape([ny,nx]) roff_mon=roff_mon+roff*(roff>threshold) count=count+(roff>threshold) roff_mean=roff_mon/(count+1e-20) roff_mean=roff_mean.astype(np.float32) roff_mean=roff_mean+threshold roff_mean.tofile("./CaMa_in/"+runname+"/mean_month/mean_"+ychar+mchar+ens_char+".bin")
nextxy = np.fromfile(nextxy, np.int32).reshape(2, ny, nx) rivwth = np.fromfile(rivwth, np.float32).reshape(ny, nx) rivhgt = np.fromfile(rivhgt, np.float32).reshape(ny, nx) rivlen = np.fromfile(rivlen, np.float32).reshape(ny, nx) elevtn = np.fromfile(elevtn, np.float32).reshape(ny, nx) lonlat = np.fromfile(lonlat, np.float32).reshape(2, ny, nx) uparea = np.fromfile(uparea, np.float32).reshape(ny, nx) # #higher resolution data # catmxy = pm.CaMa_dir()+"/map/"+pm.mapname()+"/1min/1min.catmxy.bin" # catmxy = np.fromfile(catmxy,np.int16).reshape(2,ny*60,nx*60) #---- rivnum = "../dat/rivnum_" + pm.mapname() + ".bin" rivnum = np.fromfile(rivnum, np.int32).reshape(ny, nx) rivermap = ((nextxy[0] > 0) * (rivnum == 1)) * 1.0 #---- syear, smonth, sdate = pm.starttime() #2004#1991 2004,1,1 # 2003,1,1 # eyear, emonth, edate = pm.endtime() #2005,1,1 # 2005,1,1 # #month=1 #date=1 start_dt = datetime.date(syear, smonth, sdate) end_dt = datetime.date(eyear, emonth, edate) size = 60 start = 0 last = (end_dt - start_dt).days N = int(last) green2 = "greenyellow" green = "green" #------- pname = []
#def sendslack(msg): # slack=Slacker('xoxb-316041665447-hNXDYiTz9PZMITg0gfRGzyrC') # message="` "+os.path.basename(__file__)+"` : "+msg # slack.chat.post_message('#camasim',message); # return 0 #--- #-- #slink("/hydro/covariance/CaMa_simulation/params.py", "params.py") #slink("/hydro/SWOTDA/img_code/read_grdc.py","read_grdc.py") import params as pm import read_grdc as grdc #-- mk_dir(pm.out_dir() + "/figures") mk_dir(pm.out_dir() + "/figures/timeseries") #--read outflow netCDF4-- tag = "%04d-%04d" % (pm.starttime()[0], pm.endtime()[0]) # sfcelv fname = pm.out_dir() + "/CaMa_out/" + pm.input_name() + "/sfcelv" + tag + ".nc" nc_sfcelv = xr.open_dataset(fname) # removed trend line fname = pm.out_dir() + "/CaMa_out/" + pm.input_name( ) + "/rmdtrnd" + tag + ".nc" nc_rmdtrend = xr.open_dataset(fname) # removed seasonality fname = pm.out_dir() + "/CaMa_out/" + pm.input_name( ) + "/rmdsesn" + tag + ".nc" nc_rmdseson = xr.open_dataset(fname) # standardized fname = pm.out_dir() + "/CaMa_out/" + pm.input_name( ) + "/standardized" + tag + ".nc" nc_standz = xr.open_dataset(fname)