Пример #1
0
def SWOT_observation_error():
	"""observation error of WSE depending on the L*W of each pixel
	used sigma*(1/l)*(1/w) l=k*L, w=q*W  Rodrigaz et al 2017:
	According to CaMa k=0.25, q=0.85"""
	fname=pm.DA_dir()+"/out/"+pm.experiment()+"/assim_out/obs/obs_err.bin"
	if os.path.isfile(fname):
		return 0
	else:
		nx,ny,gsize = pm.map_dimension()
		k=1.00 # assume nearest part to the unit catchment
		q=1.00 # used 1.0 -> river width variability is 30%
		ovs_err = 0.10
		rivlen=np.fromfile(pm.CaMa_dir()+"/map/glb_15min/rivlen.bin",np.float32).reshape(ny,nx)
		rivwth=np.fromfile(pm.CaMa_dir()+"/map/glb_15min/rivwth_gwdlr.bin",np.float32).reshape(ny,nx)
		nextx=(np.fromfile(pm.CaMa_dir()+"/map/glb_15min/nextxy.bin",np.int32).reshape(2,ny,nx)[0]!=-9999)*1.0
		rivlen=1.0 #rivlen*1.0e-3 #used as one kilometer
		rivwth=rivwth*1.0e-3
		area=(k*rivlen)*(q*rivwth)
		obs_err=ovs_err*(1/(k*rivlen+1.0e-20))*(1/(q*rivwth+1.0e-20))*nextx
		#obs_err=pm.ovs_err()*(1/(area+1.0e-20))*nextx
		# if water area < 1.0 km2 -> 0.25
		obs_err=obs_err*(area>=1.0)*1.0+0.25*(1/(k*rivlen+1.0e-20))*(1/(q*rivwth+1.0e-20))*nextx*(area<1.0)*1.0
		obs_err=ma.masked_where(area<0.625,obs_err).filled(0.25) # 25cm for < 1km^2 water area
		obs_err=obs_err*nextx
		obs_err=obs_err.astype(np.float32)
		# obs_err0=obs_err[iy,ix]
		fname=pm.DA_dir()+"/out/"+pm.experiment()+"/assim_out/obs/obs_err.bin"
		obs_err.tofile(fname)
		return 0
Пример #2
0
def observation_error():
    """observation error of WSE depending on the L*W of each pixel
    used sigma*(1/l)*(1/w) l=k*L, w=q*W  Rodrigaz et al 2017:
    According to CaMa k=0.25, q=0.85"""
    k = 1.00  # assume nearest part to the unit catchment
    q = 1.00  # used 1.0 -> river width variability is 30%
    rivlen = np.fromfile(pm.CaMa_dir() + "/map/glb_15min/rivlen.bin",
                         np.float32).reshape(720, 1440)
    rivwth = np.fromfile(pm.CaMa_dir() + "/map/glb_15min/rivwth_gwdlr.bin",
                         np.float32).reshape(720, 1440)
    nextx = (np.fromfile(pm.CaMa_dir() + "/map/glb_15min/nextxy.bin",
                         np.int32).reshape(2, 720, 1440)[0] != -9999) * 1.0
    rivlen = 1.0  #rivlen*1.0e-3 #used as one kilmeter
    rivwth = rivwth * 1.0e-3
    area = (k * rivlen) * (q * rivwth)
    obs_err = pm.ovs_err() * (1 / (k * rivlen + 1.0e-20)) * (
        1 / (q * rivwth + 1.0e-20)) * nextx
    #obs_err=pm.ovs_err()*(1/(area+1.0e-20))*nextx
    # if water area < 1.0 km2 -> 0.25
    obs_err = obs_err * (area >= 1.0) * 1.0 + 0.25 * (
        1 / (k * rivlen + 1.0e-20)) * (1 / (q * rivwth + 1.0e-20)) * nextx * (
            area < 1.0) * 1.0
    obs_err = ma.masked_where(area < 0.625, obs_err).filled(
        0.25)  # 25cm for < 1km^2 water area
    obs_err = obs_err * nextx
    obs_err = obs_err.astype(np.float32)
    obs_err.tofile("./obs_err.bin")
    return 0
Пример #3
0
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
Пример #4
0
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
Пример #5
0
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
Пример #6
0
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   
Пример #7
0
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
Пример #8
0
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
Пример #9
0
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
Пример #10
0
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
Пример #11
0
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
Пример #12
0
    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
Пример #13
0
    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 #
Пример #14
0
            llcrnrlon=west,
            urcrnrlon=east,
            lat_ts=0,
            resolution='c')
#m.drawcoastlines( linewidth=0.3, color='k' )
m.fillcontinents(color=land, lake_color=water)
m.drawmapboundary(fill_color=water)
m.drawparallels(np.arange(south, north + 0.1, 20),
                labels=[1, 0, 0, 0],
                fontsize=10,
                linewidth=0.1)
m.drawmeridians(np.arange(west, east + 0.1, 40),
                labels=[0, 0, 0, 1],
                fontsize=10,
                linewidth=0.1)
fname = pm.CaMa_dir() + "/map/glb_15min/outclm.bin"
trueforo = np.fromfile(fname, np.float32).reshape([2, 720, 1440])[0]
river = (trueforo > 100.) * 1.0
ratio = np.ma.fix_invalid(ratio).data
ratio = ratio * river
data = ratio[npix:spix, wpix:epix]
im = m.imshow(np.flipud(data),
              vmin=1e-20,
              vmax=1,
              interpolation="nearest",
              cmap=cmap,
              zorder=100)
#im = m.imshow(np.flipud(ai),vmin=1e-20, vmax=1,interpolation="nearest",cmap=cmap,zorder=100)
cbar = m.colorbar(im, "right", size="2%")
cbar.set_label("annual mean AI")
plt.title("annual mean Assimilation Index ")  #+yyyy+"-"+mm+"-"+dd)
Пример #15
0
def latlon_river(rivername,ix,iy,mapname="glb_06min",nYY=1800,nXX=3600):
    global lllat, urlat, lllon, urlon
    lonlat = pm.CaMa_dir()+"/map/glb_"+mapname[-5::]+"/lonlat.bin"
    lonlat = np.fromfile(lonlat,np.float32).reshape(2,nYY,nXX)
    llon=lonlat[0,iy-1,ix-1]
    llat=lonlat[1,iy-1,ix-1]
    adj=20.0
    lllat, urlat, lllon, urlon = max(llat-adj,-90.),min(llat+adj,90.),max(llon-adj,-180.),min(llon+adj,180.)
    if rivername=="LENA":
        lllat = 50.
        urlat = 80.
        lllon = 100.
        urlon = 145.
    if rivername=="NIGER":
        lllat = 0.
        urlat = 25.
        lllon = -10.
        urlon = 15.
    if rivername=="AMAZONAS" or rivername=="AMAZON":
        lllat = -20.
        urlat = 10.
        lllon = -80.
        urlon = -45.
    if rivername=="MEKONG":
        lllat = 10.
        urlat = 35.
        lllon = 90.
        urlon = 120.
    if rivername=="MISSISSIPPI":
        lllat = 20.
        urlat = 50.
        lllon = -115.
        urlon = -75.
    if rivername=="OB":
        lllat = 40.
        urlat = 70.
        lllon = 55.
        urlon = 95.
    if rivername=="CONGO":
        lllat = -15.
        urlat = 10.
        lllon = 10.
        urlon = 35.
    if rivername=="INDUS":
        lllat = 20.
        urlat = 40.
        lllon = 60.
        urlon = 80.
    if rivername=="VOLGA":
        lllat = 40.
        urlat = 65.
        lllon = 30.
        urlon = 70.
    if rivername=="NILE":
        lllat = -5.
        urlat = 30.
        lllon = 20.
        urlon = 40.
    if rivername=="YUKON":
        lllat = 55.
        urlat = 75.
        lllon = -165.
        urlon = -130.
    #if rivername not in ["LENA","NIGER","CONGO","OB","MISSISSIPPI","MEKONG","AMAZONAS","INDUS"]:
    #    adj=20.
    #    lllat, urlat, lllon, urlon = max(llat-adj,-90.),min(llat+adj,90.),max(llon-adj,-180.),min(llon+adj,180.)

    return lllat, urlat, lllon, urlon
Пример #16
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"
Пример #17
0
      os.remove(dst)
      os.symlink(src,dst)
    else:
      raise
#--
def make_yearlist(syear,smon,sday,N=365):
    start_dt=datetime.date(syear,smon,sday)
    fname="year_day.txt"
    f=open(fname,"w")
    for day in np.arange(0,N):
        nw_dt = start_dt + datetime.timedelta(days=day)
        yyyy,mm,dd = nw_dt.year, nw_dt.month, nw_dt.day
        yyyymmdd = "%04d%02d%02d\n"%(yyyy,mm,dd)
        f.write(yyyymmdd)
    f.close()
#--
slink("../gosh/params.py", "params.py")
import params as pm
# define values
N=366 #2004
exp="E2O_womc_anomalyDA_if3.0"
outdir=pm.DA_dir()+"/out/"+exp
# mkdir stat
mk_dir(outdir+"/assim_out/stat")
# make list of days
#make_yearlist(2004,1,1,N=366)
# compile
#os.system("ifort calc_stat.f90 -o calc_stat -O3 -assume byterecl -heap-arrays  -g -traceback -free -parallel")
# run calc_stat
os.system("./calc_stat "+str(N)+" "+str(pm.ens_mem())+" "+outdir+" "+pm.CaMa_dir())