def get_grdc_loc_dic(name,info = "a"): #--aske the river name and a or b # a - most downsream loc # b - all locations grdc = pm.CaMa_dir() + "/map/"+pm.mapname()+"/grdc_loc.txt" #grdc = pm.CaMa_dir() + "/map/glb_15min/grdc_loc.txt" #grdc = "../data/grdc_loc.txt" f = open(grdc,"r") lines = f.readlines() f.close() station_loc = {} # print station_loc for line in lines: line = filter(None, re.split(" ",line)) grdc_id = line[0] river = line[1] station = line[2] d_info = line[3] station_loc[station] = () #-- lon = float(line[4]) lat = float(line[5]) #-- ix = int(line[6])-1 iy = int(line[7])-1 if info == d_info and info == "a": station_loc[station] = (ix,iy) else: station_loc[station] = (ix,iy) # print station_loc return station_loc
def get_loc_v394(gid): #--ask the river name and a or b # a - most downsream loc # b - all locations #grdc = pm.CaMa_dir() + "/map/glb_15min/grdc_loc.txt" #grdc = "../data/GRDC_alloc.txt" grdc = pm.CaMa_dir() + "/map/"+pm.mapname()+"/grdc_loc.txt" #---- f = open(grdc,"r") lines = f.readlines() f.close() ix=0 iy=0 gid=int(gid) #--- for line in lines[1::]: line = filter(None, re.split(" ",line)) grdc_id = int(line[0]) u_info = line[7] #-- if gid==grdc_id: #print "get_loc_v394", grdc_id ix = int(line[8])-1 iy = int(line[9])-1 return ix,iy
def get_grdc_station_v396(name): #--ask the river name and a or b # all locations #grdc = pm.CaMa_dir() + "/map/glb_15min/grdc_loc.txt" grdc = pm.CaMa_dir() + "/map/"+pm.mapname()+"/grdc_loc.txt" f = open(grdc,"r") lines = f.readlines() f.close() station_loc = [] x_list = [] y_list = [] #--- for line in lines[1::]: #print line line = filter(None, re.split(";",line)) #print line grdc_id = line[0] river = line[1].strip() station = line[2].strip() ix1 = int(line[3])-1 iy1 = int(line[4])-1 ix2 = int(line[5]) #print river if ix2 != -9999: ix2 = ix2-1 iy2 = int(line[6]) if iy2 != -9999: iy2 = iy2-1 if station == name: return ix1,iy1,ix2,iy2
def get_grdc_loc_v396(name): #--ask the river name and a or b # all locations #grdc = pm.CaMa_dir() + "/map/glb_15min/grdc_loc.txt" grdc = pm.CaMa_dir() + "/map/"+pm.mapname()+"/grdc_loc.txt" f = open(grdc,"r") lines = f.readlines() f.close() #-- id_list = [] station_loc = [] x_list = [] y_list = [] #--- for line in lines[1::]: #print line line = filter(None, re.split(";",line)) #print line grdc_id = line[0] river = line[1].strip() station = line[2].strip() ix = int(line[3])-1 iy = int(line[4])-1 ix2 = int(line[5]) #print river if ix2 != -9999: continue if river == name: id_list.append(grdc_id) station_loc.append(station) x_list.append(ix) y_list.append(iy) return id_list,station_loc,x_list,y_list
def swot_data(yyyy,mm,dd): # prepare sythetic observations using # pre-simulated data # river width thershold rivwdth_thr=50.0 #m nx,ny,gsize = pm.map_dimension() ny_swot = min(ny,640) day=SWOT_day(yyyy,mm,dd) SWOTDD="%02d"%(day) fname="../sat/mesh_day"+SWOTDD+".bin" # for glb_15min mesh_in=np.fromfile(fname,np.float32).reshape([ny_swot,nx]) mesh=(mesh_in>=10)*(mesh_in<=60) meshP=mesh-1000*(mesh<0.1) SWOTmesh=np.zeros([ny,nx],np.float32) SWOTmesh[40:680,:]=meshP fname=pm.CaMa_dir()+"/map/"+pm.mapname()+"/rivwth_gwdlr.bin" rivwth=np.fromfile(fname,np.float32).reshape(ny,nx) obs=(SWOTmesh>=1.0)*(rivwth>=rivwdth_thr)*1.0 lname =[] xlist =[] ylist =[] l_wse =[] m_wse =[] s_wse =[] l_sat =[] # leledif, lEGM08, lEGM96, satellite #=================================== # odir="/cluster/data6/menaka/ensemble_org/CaMa_out/E2O003" odir=pm.obs_dir() fname=odir+"/sfcelv"+yyyy+".bin" year=int(yyyy) mon=int(mm) day=int(dd) if calendar.isleap(year): nt=366 else: nt=365 orgfile=np.fromfile(fname,np.float32).reshape([nt,ny,nx]) obs_err=SWOT_observation_error() #----------------------- start_dt=datetime.date(year,1,1) target_dt=datetime.date(year,mon,day) it=(target_dt-start_dt).days for ix in np.arange(nx): for iy in np.arange(ny): if obs[iy,ix] == 1.0: wse=orgfile[it,iy,ix] + err_rand(ix,iy) # print (ix,iy,wse[0]) l_wse.append(wse[0]) xlist.append(ix+1) ylist.append(iy+1) m_wse.append(-9999.0) s_wse.append(-9999.0) l_sat.append("SWOT") return xlist, ylist, l_wse, m_wse, s_wse, l_sat
def grdc_river_name_v396(): #grdc = pm.CaMa_dir() + "/map/glb_15min/grdc_loc.txt" grdc = pm.CaMa_dir() + "/map/"+pm.mapname()+"/grdc_loc.txt" f = open(grdc,"r") lines = f.readlines() f.close() rivername = [] for line in lines[1::]: line = filter(None, re.split(";",line)) grdc_id = line[0] river = line[1].strip() #d_info = line[3] #if d_info == "a": if river not in rivername: rivername.append(river) return rivername
def grdc_river_name(): # get river names grdc = pm.CaMa_dir() + "/map/"+pm.mapname()+"/grdc_loc.txt" #grdc = pm.CaMa_dir() + "/map/glb_15min/grdc_loc.txt" #grdc = "../data/grdc_loc.txt" f = open(grdc,"r") lines = f.readlines() f.close() rivername = [] for line in lines: line = filter(None, re.split(" ",line)) grdc_id = line[0] river = line[1] d_info = line[3] if d_info == "a": rivername.append(river) return rivername
def get_grdc_loc(name,info = "a"): #--ask the river name and a or b # a - most downsream loc # b - all locations grdc = pm.CaMa_dir() + "/map/"+pm.mapname()+"/grdc_loc.txt" #grdc = "../data/grdc_loc.txt" f = open(grdc,"r") lines = f.readlines() f.close() station_loc = [] x_list = [] y_list = [] #--- for line in lines: line = filter(None, re.split(" ",line)) grdc_id = line[0] river = line[1] station = line[2] d_info = line[3] #-- lon = float(line[4]) lat = float(line[5]) #-- ix = int(line[6])-1 iy = int(line[7])-1 if name == river: if info == "a": if d_info=="a": station_loc.append(station) x_list.append(ix) y_list.append(iy) else: station_loc.append(station) x_list.append(ix) y_list.append(iy) return station_loc,x_list,y_list
def get_id(name): #--get GRDC id #grdc = pm.CaMa_dir() + "/map/glb_15min/grdc_loc.txt" #grdc = "../data/grdc_loc.txt" grdc = pm.CaMa_dir() + "/map/"+pm.mapname()+"/grdc_loc.txt" f = open(grdc,"r") lines = f.readlines() f.close() gid=-9999 #--- for line in lines: line = filter(None, re.split(" ",line)) grdc_id = int(line[0]) river = line[1] station = line[2] d_info = line[3] #-- if name == station: gid=grdc_id return gid
def make_anomaly_data(mode=pm.mode()): # make directory for mean sfcelv mkdir("./assim_out/mean_sfcelv/") # copy the anomaly files if mode == 1: # for mean iname = pm.DA_dir() + "/dat/mean_sfcelv_E2O_" + pm.mapname( ) + "_1980-2014.bin" oname = "./assim_out/mean_sfcelv/mean_sfcelv.bin" os.system("cp " + iname + " " + oname) # for std iname = pm.DA_dir() + "/dat/std_sfcelv_E2O_" + pm.mapname( ) + "_1980-2014.bin" oname = "./assim_out/mean_sfcelv/std_sfcelv.bin" os.system("cp " + iname + " " + oname) if mode == 2: # for mean iname = pm.DA_dir() + "/dat/mean_sfcelv_E2O_" + pm.mapname( ) + "_1980-2014.bin" oname = "./assim_out/mean_sfcelv/mean_sfcelv.bin" os.system("cp " + iname + " " + oname) # for std iname = pm.DA_dir() + "/dat/std_sfcelv_E2O_" + pm.mapname( ) + "_1980-2014.bin" oname = "./assim_out/mean_sfcelv/std_sfcelv.bin" os.system("cp " + iname + " " + oname) if mode == 3: # for mean iname = pm.DA_dir() + "/dat/mean_sfcelv_VIC_BC_" + pm.mapname( ) + "_1979-2013.bin" oname = "./assim_out/mean_sfcelv/mean_sfcelv.bin" os.system("cp " + iname + " " + oname) # for std iname = pm.DA_dir() + "/dat/std_sfcelv_VIC_BC_" + pm.mapname( ) + "_1979-2013.bin" oname = "./assim_out/mean_sfcelv/std_sfcelv.bin" os.system("cp " + iname + " " + oname) return 0
RMSE: Root Mean Squre Error """ o = ma.masked_where(o == -9999.0, o).filled(0.0) s = ma.masked_where(o == -9999.0, s).filled(0.0) o = np.compress(o > 0.0, o) s = np.compress(o > 0.0, s) s, o = filter_nan(s, o) # return np.sqrt(np.mean((s-o)**2)) return np.sqrt(np.ma.mean(np.ma.masked_where(o <= 0.0, (s - o)**2))) #========================================================== mk_dir(assim_out + "/figures") mk_dir(assim_out + "/figures/RMSE") #---- fname = pm.CaMa_dir() + "/map/" + pm.mapname() + "/params.txt" f = open(fname, "r") lines = f.readlines() f.close() #------- nx = int(filter(None, re.split(" ", lines[0]))[0]) ny = int(filter(None, re.split(" ", lines[1]))[0]) gsize = float(filter(None, re.split(" ", lines[3]))[0]) lon0 = float(filter(None, re.split(" ", lines[4]))[0]) lat0 = float(filter(None, re.split(" ", lines[7]))[0]) west = float(filter(None, re.split(" ", lines[4]))[0]) east = float(filter(None, re.split(" ", lines[5]))[0]) south = float(filter(None, re.split(" ", lines[6]))[0]) north = float(filter(None, re.split(" ", lines[7]))[0]) #---- nextxy = pm.CaMa_dir() + "/map/" + pm.mapname() + "/nextxy.bin"
input: s: simulated o: observed output: RMSE: Root Mean Squre Error """ o=ma.masked_where(o<=0.0,o).filled(0.0) s=ma.masked_where(o<=0.0,s).filled(0.0) s,o = filter_nan(s,o) # return np.sqrt(np.mean((s-o)**2)) return np.sqrt(np.ma.mean(np.ma.masked_where(o<=0.0,(s-o)**2))) #==================================================================== mk_dir(assim_out+"/figures") mk_dir(assim_out+"/figures/disgraph") #---- fname=pm.CaMa_dir()+"/map/"+pm.mapname()+"/params.txt" f=open(fname,"r") lines=f.readlines() f.close() #------- nx = int(filter(None, re.split(" ",lines[0]))[0]) ny = int(filter(None, re.split(" ",lines[1]))[0]) gsize = float(filter(None, re.split(" ",lines[3]))[0]) #---- syear,smonth,sdate=pm.starttime()#2004#1991 #2003,1,1 # 2009,1,1 # eyear,emonth,edate=pm.endtime() #2005,1,1 #2004,1,1 # 2004,1,1 # 2010,1,1 # 2012,1,1 # 2011,1,1 # #month=1 #date=1 start_dt=datetime.date(syear,smonth,sdate) end_dt=datetime.date(eyear,emonth,edate) size=60
output: RMSE: Root Mean Squre Error """ o = ma.masked_where(o == -9999.0, o).filled(0.0) s = ma.masked_where(o == -9999.0, s).filled(0.0) o = np.compress(o > 0.0, o) s = np.compress(o > 0.0, s) s, o = filter_nan(s, o) return np.sqrt(np.mean((s - o)**2)) #========================================================== mk_dir(assim_out + "/figures") mk_dir(assim_out + "/figures/anomaly") #---- fname = pm.CaMa_dir() + "/map/" + pm.mapname() + "/params.txt" f = open(fname, "r") lines = f.readlines() f.close() #------- nx = int(filter(None, re.split(" ", lines[0]))[0]) ny = int(filter(None, re.split(" ", lines[1]))[0]) gsize = float(filter(None, re.split(" ", lines[3]))[0]) #--- # year=2004 # month=1 # date=1 # start_dt=datetime.date(year,month,date) # size=60 syear, smonth, sdate = pm.starttime() #2004#1991 #2003,1,1 #