コード例 #1
0
ファイル: c.tune.py プロジェクト: hyungjun/detect
def save_csv(var, ldat):
  """
  var: rvort, dt, wmeanlow, wmeanup
  """
  ldat   = sort(ldat)
  lendat = len(ldat)

  dunit  = {"rvort":"s-1",
            "dt"   :"K",
            "wLow_Up":"m/s",
            "pgrad":"Pa/1000km"
           }

  sout = "frac/%s(%s),%s\n"%(model,var,dunit[var])
  for i,dat in enumerate(ldat):
    frac = (i+1)/float(lendat)
    sout = sout + "%f,%f\n"%(frac,dat)

  #
  odir   = "/media/disk2/out/obj.valid/c.%s"%(var)
  ctrack_func.mk_dir(odir)
  oname  = odir + "/%s.%s.%04d-%04d.%s.csv"%(var,model,iYear,eYear,"ASAS")

  f = open(oname,"w");  f.write(sout);  f.close()
  print oname
コード例 #2
0
def Load_file(spath,gzflag=True):

  #print "Load_file", spath.split("/")[-1],spath.split("/")[-1][8:8+2],spath.split("/")[-1][10:10+2],spath.split("/")[-1][12:12+5]
  if gzflag == False:
    h4   = SD.SD(spath)

  else:
    f = gzip.open(spath, "rb")
    dat  = f.read()
    f.close()

    fname= spath.split("/")[-1][:-3]

    year = int(spath.split("/")[-3])
    mon  = int(spath.split("/")[-2])
    odir = odir_root + "/%04d/%02d"%(year,mon)
    tpath= odir + "/%s"%(fname)
    ctrack_func.mk_dir(odir)
    f    = open(tpath, "wb")
    f.write(dat)
    f.close()

    h4   = SD.SD(tpath)
    os.remove(tpath)
  return h4
コード例 #3
0
ファイル: obt2saone.py プロジェクト: nbykutsumi/PMM
def obt2saone_days(iyear,imon,iday,eyear,emon,eday):
  miss            = -9999.
  aDat,aLat,aLon,aDtime  = get_dat_days(iyear,imon,iday,eyear,emon,eday)
  
  idtime = datetime(iyear,imon,iday,0)
  edtime = datetime(iyear,emon,eday,0) + timedelta(days=1)
  ddtime = edtime - idtime
  dH     = int(ddtime.total_seconds() / 3600.)
  ldtime = [idtime + timedelta(hours=H) for H in range(dH)]
  
  for dtime in ldtime:
    ii     = searchsorted(aDtime, dtime)
    ei     = searchsorted(aDtime, dtime+timedelta(hours=1))
  
    adat   = aDat[ii:ei]
    alat   = aLat[ii:ei]
    alon   = aLon[ii:ei]
    adtime = aDtime[ii:ei]
    if len(adtime) ==0:
      print "***************************************"
      print "No data for",dtime
      print "Make Dummy"
      print "***************************************"
      a2pr   = ones([ny,nx],float32)*(-9999.)
    else:
      #lout   = pmm_fsub.obt2saone(adat, alon, alat)
      lout   = pmm_fsub.obt2saone(adat.T, alon.T, alat.T)
      a2sum  = lout[0].T
      a2num  = lout[1].T
      a2pr   = ma.masked_where(a2num==0.0, a2sum)/a2num
      a2pr   = a2pr /60./60. # mm/h-->mm/s
      a2pr   = a2pr.filled(miss)
      a2pr   = a2pr[50:130]  # 40S-40N

    #--------------------
    # write file
    #--------------------
    Y = dtime.year
    M = dtime.month
    D = dtime.day
    H = dtime.hour
    #ofname = "PR.%04d.%02d.%02d.%02d.sa.one"%(Y,M,D,H)
    ofname = "%s.%04d.%02d.%02d.%02d.sa.one"%(prjname.split(".")[0],Y,M,D,H)
    ctrack_func.mk_dir( os.path.join(odir_root, "%04d"%(Y), "%02d"%(M)))
    opath  = os.path.join(odir_root,"%04d"%(Y),"%02d"%(M),ofname)
    a2pr.tofile(opath)
    print opath
コード例 #4
0
ファイル: agg.pr.front.obj.py プロジェクト: nbykutsumi/dtanl
        a2pr_bcf_temp = a2pr_bcf_temp.filled(0.0)
        #--- add -----------
        a2pr_bcf_mon  = a2pr_bcf_mon + a2pr_bcf_temp

        #************************************************
        # aggregate precip : non-baroclinic front
        #-------------------------
        a2pr_nobc_temp = ma.masked_where(a2terr_nobc ==miss, a2pr)
        a2pr_nobc_temp = a2pr_nobc_temp.filled(0.0)
        #--- add -----------
        a2pr_nobc_mon  = a2pr_nobc_mon + a2pr_nobc_temp

    #********************************
    #-- for monthly data front ------
    dir_ptot_mon   = "/media/disk2/out/JRA25/sa.one.%s/6hr/tenkizu/front/agg/%04d/%02d"%(sresol,year,mon)
    ctrack_func.mk_dir(dir_ptot_mon)
    #--
    #-- count : front -
    name_count_front_mon = dir_ptot_mon + "/count.front.rad%04dkm.M1_%s_M2_%s.sa.one"%(countrad, thfmask1, thfmask2)
    a2count_front_mon = ma.masked_where(a2orog>thorog, a2count_front_mon).filled(miss)
    a2count_front_mon = ma.masked_where(a2gradorogmask>thgradorog, a2count_front_mon).filled(miss)
    a2count_front_mon.tofile(name_count_front_mon)

    #-- count : baroclinic front -
    name_temp = dir_ptot_mon + "/count.bcf.rad%04dkm.M1_%s_M2_%s.thbc_%04.2f.sa.one"%(countrad, thfmask1, thfmask2, thbc*1000*100)
    a2temp    = a2count_bcf_front_mon
    a2temp    = ma.masked_where(a2orog>thorog, a2temp).filled(miss)
    a2temp    = ma.masked_where(a2gradorogmask>thgradorog, a2temp).filled(miss)
    a2temp.tofile(name_temp)

    #-- count : non-baroclinic front -
コード例 #5
0
ファイル: dif.wfpr.py プロジェクト: nbykutsumi/dtanl
#-----
ddir  = {}
dname = {}
for era in lera:
  for var in lvar:
    ddir[era, var]  =  ddir_root[era] + "/%s"%(var)
#--------------------------
# dif dirs
#--------------------------
#difdir_root = "/media/disk2/out/CMIP5/day/%s/dif/%s/%04d-%04d.%04d-%04d/tracks/dura%02d/wfpr"%(model, dexpr["fut"], diyear["his"], deyear["his"], diyear["fut"], deyear["fut"], thdura)
difdir_root  = ddir_root["dif"]

ddifdir = {}
for difvar in ldifvar:
  ddifdir[difvar] = difdir_root + "/%s"%(difvar)
  func.mk_dir(ddifdir[difvar])
#---
#**********************
# input names for each class
#----------------------
dname  = {}
for class_lb in lclass[1:]:
  for era in lera:
    expr = dexpr[era]
    for var in lvar:
      for iclass in lclass:
        if iclass == 0:
          dname[class_lb, era, var, iclass] =  ddir[era, var] + "/acc.%s.p%05.2f.cmin%04d.c%02d.%02d.r%04d.nw%02d_%s_day_%s_%s_%s.bn"%(var, xth, cmin, class_lb, nclass, crad, nwbin, season, model, expr, ens )
        else:
          dname[class_lb, era, var, iclass] =  ddir[era, var] + "/%s.p%05.2f.cmin%04d.c%02d.%02d.r%04d.nw%02d_%s_day_%s_%s_%s.bn"%(var, xth, cmin, iclass, nclass, crad, nwbin, season, model, expr, ens )
            
コード例 #6
0
ファイル: testcape.py プロジェクト: nbykutsumi/dtanl
 for var in ["ta", "hus", "pa"]:
   for h in lh:
     ddir_6hr[var]  = "/media/disk2/data/CMIP5/bn/%s/6hrLev/%s/%s/%s"%(var, model, expr, ens)
     dname_6hr[var, h] = ddir_6hr[var] + "/%04d/%s_6hrLev_%s_%s_%s_%04d%02d%02d%02d.bn"%(year, var, model, expr, ens, year, mon, day, h)
     da3_6hr[var, h]   = fromfile(dname_6hr[var, h], float32).reshape(nz6h, ny, nx)
 #--- ps -----------------
 for var in ["ps"]:
   for h in lh:
     ddir_6hr[var]  = "/media/disk2/data/CMIP5/bn/%s/6hrLev/%s/%s/%s"%(var, model, expr, ens)
     dname_6hr[var,h] = ddir_6hr[var] + "/%04d/%s_6hrLev_%s_%s_%s_%04d%02d%02d%02d.bn"%(year, var, model, expr, ens, year, mon, day, h)
     da2_6hr[var,h]   = fromfile(dname_6hr[var, h], float32).reshape(ny, nx)
 #--- pap : output ------
 for outvar in ["pap", "capep"]:
   ddir_day[outvar]  = "/media/disk2/data/CMIP5/bn/%s/day/%s/%s/%s/%04d"%(outvar, model, expr, ens, year)
   dname_day[outvar] = ddir_day[outvar] + "/%s_day_%s_%s_%s_%04d%02d%02d00.bn"%(outvar, model, expr, ens, year, mon, day)
   ctrack_func.mk_dir(ddir_day[outvar])
   print ddir_day[outvar]
   print dname_day[outvar]
 #*******************************************
 nresol = 5
 ddir   = {}
 dname  = {}
 da3    = {}
 da2    = {}
 da1    = {}
 
 
 #-- wap ---
 #for var in ["wap"]:
 #  ddir[var]  = "/media/disk2/data/CMIP5/bn/%s/day/NorESM1-M/historical/r1i1p1"%(var)
 #  dname[var] = ddir[var] + "/1990/%s_day_NorESM1-M_historical_r1i1p1_1990010100.bn"%(var)
コード例 #7
0
      #--- label ------------
      plt.clabel(CS, levels[::2], inline=1, fontsize=18, fmt="%d")
      #plt.clabel(CS, inline=1, fontsize=18, fmt="%03d")
  
      #-- axis ticks -------
      #plt.rc("xtick", labelsize=18)
      #plt.rc("ytick", labelsize=18)
  
      plt.xticks(fontsize=18)
      plt.yticks(fontsize=18)
  
      #-- title ------------
      axcont.set_title( "%s season:%s maskrad:%04dkm %04d-%04d"%(ftype, season, dist_mask, iyear, eyear))
      #-- save -------------
      pictdir   = "/media/disk2/out/chart/ASAS/front/agg/%04d-%04d/%s/pict"%(iyear,eyear,season)
      ctrack_func.mk_dir(pictdir)
      if window == "no":
        figname   = pictdir + "/cont.dist.%s.maskrad.%04d-%04d.%s.%s.%s.png"%(vtype, iyear,eyear,season,region,ftype)
      elif window in ["in","out"]:
        figname   = pictdir + "/cont.dist.%s.maskrad.%s.%04dkm.%04d-%04d.%s.%s.%s.png"%(vtype, window, dist_mask, iyear,eyear,season,region,ftype)

      if (ftype == "warm")&(revflag==True):
        figname = figname.split(".png")[0] + ".REV.png"

      figcont.savefig(figname)
      print figname
  
    #***********************************************
    #** figure grad *******
    plt.clf()
    figplot   = plt.figure()
コード例 #8
0
ファイル: mk.front.obj.py プロジェクト: nbykutsumi/dtanl
orogname     = "/media/disk2/data/JRA25/sa.one.125/const/topo/topo.sa.one"
gradorogname = "/media/disk2/data/JRA25/sa.one.125/const/topo/maxgrad.0200km.sa.one"
a2orog     = fromfile(orogname, float32).reshape(ny,nx)
a2gradorog = fromfile(gradorogname, float32).reshape(ny,nx)

#******************************************************
for year in lyear:
  for mon in lmon:
    #-----------
    sodir_t_root    = "/media/disk2/out/JRA25/sa.one.%s/6hr/front.t"%(sresol)
    sodir_t         = sodir_t_root + "/%04d%02d"%(year, mon)

    #sodir_q_root    = "/media/disk2/out/JRA25/sa.one.%s/6hr/front.q"%(sresol)
    #sodir_q         = sodir_q_root + "/%04d%02d"%(year, mon)

    ctrack_func.mk_dir(sodir_t)
    #ctrack_func.mk_dir(sodir_q)
    #-----------
    eday  = calendar.monthrange(year,mon)[1]
    #-----------
    for day in range(iday, eday+1):
      for hour in lhour:
        stime   = "%04d%02d%02d%02d"%(year, mon, day, hour)
        ##******************************************************
        ##-- q: mixing ratio --------------------------
        #qname    = "/media/disk2/data/JRA25/sa.one.%s/6hr/SPFH/%04d%02d/anl_p.SPFH.%04dhPa.%04d%02d%02d%02d.sa.one"%(sresol,year, mon, plev*0.01, year, mon, day, hour)
        #a2q      = fromfile(qname, float32).reshape(ny,nx)
        #a2gradq  = dtanl_fsub.mk_a2grad_abs_saone(a2q.T).T
        #a2gradq  = a2gradq *1000.0*100.0   # [kg/kg (100km)-1]
        
        #-- t: ---------------------------------------
コード例 #9
0
            a2nbc       = front_func.complete_front_q_saone(a2fbc, a2nbc1, a2nbc2, thfmask1q, thfmask2q, a2maxorog, a2gradorog, thorog_front, thgradorog, thgrids, miss)
    
          #-- count baloclinic front loc --
          if ftype == "t":
            a2loc = a2fbc
          elif ftype == "q":
            a2loc = a2nbc
          #-------------------
          a2temp         = ma.masked_where(a2loc ==miss, a2one).filled(miss)
    
          a2countterr    = ctrack_fsub.mk_8gridsmask_saone(a2temp.T, miss).T
          a2count_tmp    = ma.masked_where(a2countterr ==miss, a2one).filled(0.0)
  
          a2count_mon = a2count_mon + a2count_tmp
      #********************************
      #-- for monthly data front ------
      odir_mon   = "/media/disk2/out/JRA25/sa.one.%s/6hr/front.%s/agg/%04d/%02d"%(sresol,ftype,year,mon)
      ctrack_func.mk_dir(odir_mon)
      #----------
      if ftype == "t":
        thfmask1, thfmask2  = thfmask1t, thfmask2t
      elif ftype == "q":
        thfmask1, thfmask2  = thfmask1q, thfmask2q
      #----------
      name_temp = odir_mon + "/count.front.%s.3deg.M1_%s_M2_%s.sa.one"%(ftype, thfmask1, thfmask2)
      a2temp    = a2count_mon
      a2temp    = ma.masked_where(a2maxorog>thorog_front, a2temp).filled(miss)
      #a2temp    = ma.masked_where(a2gradorog>thgradorog, a2temp).filled(miss)
      a2temp.tofile(name_temp)
      print name_temp
コード例 #10
0
ファイル: mk.mnum.map.jra.py プロジェクト: nbykutsumi/dtanl
[imon, emon]  = ctrack_para.ret_im_em(season)
lmon          = ctrack_para.ret_lmon(season)
mons          = ctrack_para.ret_mons(season)
dpgradrange   = ctrack_para.ret_dpgradrange()
cmin          = dpgradrange[0][0]
#----------------------
lclass        = dpgradrange.keys()
nclass        = len(lclass) -1

#***************************************
#  names for input
#---------------------------------------
pgrad_dir_root   = "/media/disk2/out/JRA25/sa.one/6hr/pgrad"

densdir          = "/media/disk2/out/JRA25/sa.one/const/cyclone/dura%02d"%(thdura)
ctrack_func.mk_dir(densdir)
#----------------------
# output name
#----------------------
ddensname    = {}
ddensname_up = {}
for iclass in lclass:
  ddensname[iclass]     = densdir + "/cdens.c%02d.%s.sa.one"%(iclass, season)
  ddensname_up[iclass]  = densdir + "/acc.cdens.c%02d.%s.sa.one"%(iclass, season)
  print ddensname[iclass]

#-----------------
# dummy
#-----------------
da2dens    = {}
da2dens_up = {}
コード例 #11
0
pgraddir_root   = "/media/disk2/out/JRA25/sa.one.%s/6hr/pgrad"%(model)
lifedir_root    = "/media/disk2/out/JRA25/sa.one.%s/6hr/life"%(model)
nextposdir_root = "/media/disk2/out/JRA25/sa.one.%s/6hr/nextpos"%(model)
lastposdir_root = "/media/disk2/out/JRA25/sa.one.%s/6hr/lastpos"%(model)
iposdir_root    = "/media/disk2/out/JRA25/sa.one.%s/6hr/ipos"%(model)
#
tdir_root       = "/media/disk2/data/JRA25/sa.one.%s/6hr/TMP"%(model)
udir_root       = "/media/disk2/data/JRA25/sa.one.%s/6hr/UGRD"%(model)
vdir_root       = "/media/disk2/data/JRA25/sa.one.%s/6hr/VGRD"%(model)
#
sstdir_root     = "/media/disk2/data/JRA25/sa.one.anl_p25/mon/WTMPsfc"
#
#sodir_root      = "/media/disk2/out/JRA25/sa.one.%s/6hr/tc/%02dh/%04d-%04d/%s/pict"%(model, thdura, iyear, eyear, season)
sodir_root      = "/media/disk2/out/obj.valid/tc.tracklines"
sodir           = sodir_root + "/%04d-%04d"%(iyear,eyear)
ctrack_func.mk_dir(sodir_root)
ctrack_func.mk_dir(sodir)
#** land sea mask -------------------
landseadir      = "/media/disk2/data/JRA25/sa.one.anl_land/const/landsea"
landseaname     = landseadir + "/landsea.sa.one"
a2landsea       = fromfile(landseaname, float32).reshape(ny,nx)

#************************************
dtrack     = {}
for iclass in lclass:
  dtrack[iclass] = []
#-------
a2lastflag    = ones([ny,nx],float32)*miss
initflag      = -1
#------------------------------------
for year in range(iyear, eyear+1):
コード例 #12
0
ファイル: mk.mnum.map.py プロジェクト: nbykutsumi/dtanl
 nwbin    = len(dlwbin.keys())
 for i in dlwbin.keys():
   abin = array(dlwbin[i])*100.0/60.0/60.0/24.0
   dlwbin[i] = abin
 #***************************************
 #  names for input
 #---------------------------------------
 datadir     = "/media/disk2/out/CMIP5/day/%s/%s/%s/tracks/dura%02d/%02d-%02d/c%02d/cmin%04d"%(model, expr, ens, thdura, im, em, nclass, cmin)
 outdir      = datadir
 #
 #ctrack_func.mk_dir(outdir)
 #-----------
 # number of events
 #-----------
 outdir_num = outdir + "/num"
 ctrack_func.mk_dir(outdir_num)
 if (dnumname =={}):
   dnumname  = {}
   for iclass in [-1] +lclass:
     dnumname[iclass ] = outdir_num + "/num.p%05.2f.cmin%04d.c%02d.%02d.r%04d.nw%02d_%s_%s_%s_%s_%s.bn"%(xth, cmin, iclass, nclass, crad*0.001, nwbin, season, "day", model, expr, ens)
 
 #-----------
 # number of events , annual data
 #-----------
 for year in range(iy, ey+1):
   outdir_num_ann = outdir + "/num/%04d"%(year)
   ctrack_func.mk_dir(outdir_num_ann)
   for iclass in [-1] +lclass:
     dnumname[year, iclass ] = outdir_num_ann + "/num.p%05.2f.cmin%04d.c%02d.%02d.r%04d.nw%02d_%s_%s_%s_%s_%s.bn"%(xth, cmin, iclass, nclass, crad*0.001, nwbin, season, "day", model, expr, ens)
 
 #-----------
コード例 #13
0
da2regmask = {}
for region in lregion:
  #lllat, lllon, urlat, urlon = ctrack_para.ret_tcregionlatlon(region) 
  lllat, lllon, urlat, urlon = ctrack_para.ret_excregionlatlon(region) 
  da2regmask[region]  = ctrack_func.mk_region_mask(lllat, urlat, lllon, urlon, nx, ny, lat_first, lon_first, dlat, dlon) 
#----------------
dmfreq_jra  = {}
dmfreq_obj  = {}
#----------------
for mon in lmon:
  #***************************
  # JRA25 
  #---------------------------
  thfmask1t, thfmask2t, thfmask1q, thfmask2q   = front_para.ret_thfmasktq("anl_p")
  idir_jra        = "/media/disk2/out/JRA25/sa.one.%s/6hr/front.%s/agg/%04d-%04d.%s"%("anl_p","t",iyear,eyear,mon)
  ctrack_func.mk_dir(idir_jra)
  iname_jra       = idir_jra + "/freq.front.%s.rad%04dkm.M1_%s_M2_%s.sa.one"%("t", countrad, thfmask1t, thfmask2t)

  a2freq_jra_mon  = fromfile(iname_jra, float32).reshape(ny,nx) 

  for region in lregion:
    a2freq_jra_temp = ma.masked_where(da2regmask[region] !=1.0, a2freq_jra_mon)
    dmfreq_jra[region, mon] = a2freq_jra_temp.mean()

  #****************************
  # multi resolition 
  #----------------------------
  for model in lmodel:
    #-------------------
    thfmask1t, thfmask2t, thfmask1q, thfmask2q   = front_para.ret_thfmasktq(model)
    ens   = cmip_para.ret_ens(model, expr, "psl") 
コード例 #14
0
ファイル: f.tune.py プロジェクト: hyungjun/detect
    elif tqtype == "q":
        ftype = [1, 2, 4]

    sout = "M1,M2,RMSE\n"
    for M1, M2 in [[M1, M2] for M1 in lM1 for M2 in lM2]:
        iDay = 1
        eDay = calendar.monthrange(Year, Mon)[1]
        #    eDay     = 2    # test
        sDtime = datetime(Year, Mon, iDay, 0)
        eDtime = datetime(Year, Mon, eDay, 18)
        dDtime = timedelta(hours=tstep)
        ch = chart()
        a2chart = ch.mk_a2count(sDTime=sDtime, eDTime=eDtime, dDTime=dDtime, ftype=ftype, rad=rad, probability=True)
        a2chart = upscale(a2chart)
        a2ra = mk_a2count(sDtime, eDtime, M1, M2, rad, thgrids, probability=True)
        a2chart = ma.masked_where(a2domain == miss, a2chart)
        a2ra = ma.masked_where(a2domain == miss, a2ra)

        rmse = sqrt(mean((a2ra - a2chart) ** 2.0))
        sout = sout + "%e,%e,%e\n" % (M1, M2, rmse)
        print Year, Mon, "M1=", M1, "M2=", M2
    # ---------
    outDir = "/media/disk2/out/obj.valid/front.para/%s.%s" % (model, res)
    ctrack_func.mk_dir(outDir)
    outPath = os.path.join(outDir, "%s.RMSE.%04d.%02d.csv" % (tqtype, Year, Mon))
    f = open(outPath, "w")
    f.write(sout)
    f.close()
    print "Save", outPath
コード例 #15
0
ファイル: mk.daily.py プロジェクト: nbykutsumi/dtanl
lvar   = ["VVEL"]
lplev  = array([850,500])*100.
#lplev  = array([250])*100.
#lplev  = array([925,850,700,500,300])*100.
#sresol = "anl_p"
sresol = "anl_chipsi"
ny,nx  = 180,360
idir_root = "/media/disk2/data/JRA25/sa.one.%s/6hr"%(sresol)
odir_root = "/media/disk2/data/JRA25/sa.one.%s/day"%(sresol)
#---------------------------------
for year in range(iyear,eyear+1):
  for mon in lmon:
    eday  = calendar.monthrange(year,mon)[1]
    for var in lvar:
      #--- readme.txt ------------
      ctrack_func.mk_dir("/%s/%s"%(odir_root,var))
      f   = open(odir_root + "/%s/readme.txt"%(var), "w")
      stxt= "data in this directory was created from 6hourly data using mk.daily.py"
      f.write(stxt);  f.close()
      #---------------------------
      for plev in lplev:
        #---------------------
        a2day     = zeros([ny,nx],float32)
        for day in range(iday,eday+1):
          print year,mon,day,plev
          for hour in lhour:
            idir  = idir_root + "/%s/%04d%02d"%(var,year,mon)
            iname = idir + "/%s.%s.%04dhPa.%04d%02d%02d%02d.sa.one"%(sresol,var,plev*0.01,year,mon,day,hour)
            a2in  = fromfile(iname, float32).reshape(ny,nx)
            a2day = a2day + a2in
          #-------
コード例 #16
0
ファイル: mk.dif.mw.map.py プロジェクト: nbykutsumi/dtanl
ddir_root["dif"] = "/media/disk2/out/CMIP5/day/%s/dif/%s/%04d-%04d.%04d-%04d/tracks/dura%02d/%02d-%02d/c%02d/cmin%04d"%(model, dexpr["fut"], diyear["his"], deyear["his"], diyear["fut"], deyear["fut"], thdura, imon, emon, nclass, cmin)

#ddir_root["his"] = "/media/disk2/out/CMIP5/day/%s/%s/%s/tracks/dura%02d/wfpr"%(model, dexpr["his"], ens, thdura)
#
#ddir_root["fut"] = "/media/disk2/out/CMIP5/day/%s/%s/%s/tracks/dura%02d/wfpr"%(model, dexpr["fut"], ens, thdura)

#ddir_root["dif"] = "/media/disk2/out/CMIP5/day/%s/dif/%s/%04d-%04d.%04d-%04d/tracks/dura%02d/wfpr"%(model, dexpr["fut"], iyear_his, eyear_his, iyear_fut, eyear_fut, thdura)
#-----
ddir  = {}
dname = {}
for era in lera + ["dif"]:
  for var in ldirvar + ["mnum"]:
    #----
    ddir[era, var]  =  ddir_root[era] + "/%s"%(var)
    #---
    func.mk_dir(ddir[era, var])

#**********************
# names for each class
#----------------------
dname  = {}
for era in lera:
  expr = dexpr[era]
  for var in ldirvar + ["mnum"]:
    for iclass in lclass + [-1]:
      dname[era, var, iclass] =  ddir[era, var] + "/%s.p%05.2f.cmin%04d.c%02d.%02d.r%04d.nw%02d_%s_day_%s_%s_%s.bn"%(var, xth, cmin, iclass, nclass, crad, nwbin, season, model, expr, ens )
#-----------
# names for acc
#-----------
for era in lera:
  expr  = dexpr[era]
コード例 #17
0
ファイル: tag.cmip.py プロジェクト: nbykutsumi/dtanl
  frontdir_t_root = cmiproot + "/front.t"
  #******************
  # Time Loop
  #------------------
  a1dtime,a1tnum  = cmip_func.ret_times(iyear,eyear,lmon,sunit,scalendar,stepday,model=model)
  for dtime, tnum in map(None, a1dtime, a1tnum):

    year,mon,day,hour = dtime.year, dtime.month, dtime.day, dtime.hour 
    stime             = "%04d%02d%02d%02d00"%(year, mon, day, hour)
    print year, mon, day, hour

    #****************
    #-- readme
    if ((year == iyear)&(mon==lmon[0])&(day==1)&(hour==0)):
      readmedir  = "/media/disk2/out/CMIP5/sa.one.%s.%s/6hr/tag"%(model,expr)
      ctrack_func.mk_dir(readmedir)
      readmename = readmedir + "/readme.tag.txt"
      sreadme    =""" 
          #-- tag   ------------------
          a2tag       = zeros([ny,nx],int32)
          a2tag       = a2tag + ma.masked_where(a2trr_tc  ==miss, a2oneint).filled(0)
          a2tag       = a2tag + ma.masked_where(a2trr_c   ==miss, a2oneint).filled(0)*10
          a2tag       = a2tag + ma.masked_where(a2trr_fbc ==miss, a2oneint).filled(0)*100
          a2tag       = a2tag + ma.masked_where(a2trr_nbc ==miss, a2oneint).filled(0)*1000
          """
      f = open(readmename, "w")
      f.write(sreadme)
      f.close()
    #****************
    #---- dir ------------------
    pgraddir    = pgraddir_root   + "/%04d%02d"%(year, mon)
コード例 #18
0
for season in lseason:
  lM  = ctrack_para.ret_lmon(season)
  iM  = lM[0]
  eM  = lM[-1]
  iD  = 1
  eD  = calendar.monthrange(Y,eM)[1]
  iDTime = datetime(Y,iM,iD,0)
  eDTime = datetime(Y,eM,eD,0)
  dDTime = timedelta(seconds=60*60*24)

  v850  = ra.time_ave("vgrd", iDTime, eDTime, dDTime, 850)
  u250  = ra.time_ave("ugrd", iDTime, eDTime, dDTime, 250)

  v850_org = v850.copy()
  v850[0:int(ny*0.5)] = -v850_org[0:int(ny*0.5)] 

  v850 = ma.masked_less(v850, thlow)
  u250 = ma.masked_less(u250, thup)
  mf   = ma.masked_where(u250.mask, v850)
  mf   = mf*0.0
 
  oDir   = "/home/utsumi/temp/MoistFront"
  ctrack_func.mk_dir(oDir)
  vname  = oDir + "/v.%s.png"%(season)
  uname  = oDir + "/u.%s.png"%(season)
  condname = oDir + "/cond.%s.png"%(season)
  Fig.DrawMap(v850, a1lat, a1lon, BBox, vname)
  Fig.DrawMap(u250, a1lat, a1lon, BBox, uname)
  Fig.DrawMap(mf  , a1lat, a1lon, BBox, condname)

コード例 #19
0
ファイル: regional_crad-p.py プロジェクト: nbykutsumi/dtanl
lonlatinfo     = ctrack_para.ret_lonlatinfo(model)
[lon_first, lat_first, dlon, dlat] = lonlatinfo
#
dpgradrange    = ctrack_para.ret_dpgradrange()
lclass         = dpgradrange.keys()
nclass         = len(lclass) -1
#
dlwbin         = ctrack_para.ret_dlwbin()
liw            = dlwbin.keys()
nwbin          = len(liw)


#*****************************************************
dir_root       = "/media/disk2/out/CMIP5/day/%s/%s/%s/tracks/dura%02d/wfpr"%(model, expr, ens, thdura)
pictdir        = dir_root + "/pict/c%02dclasses"%(nclass)
func.mk_dir(pictdir)
#*****************************************************
#  read orography
#----------------------
orogdir_root = "/media/disk2/data/CMIP5/bn/orog/fx/%s/%s/r0i0p0"%(model, expr)
orogname     = orogdir_root + "/orog_fx_%s_%s_r0i0p0.bn"%(model, expr)
a2orog         = fromfile(orogname, float32).reshape(ny,nx)
#*****************************************************
# set region
#-----------------------------------------------------
dbound   = ctrack_para.ret_dbound()
lreg     = dbound.keys()

#**********************************************
# names
#----------------------------------------------
コード例 #20
0
    #eday = iday
    for day in range(iday, eday+1):
      for hour in lhour:
        lfigname  = []
        #------------------
        if singleday == True:
          if day != iday:
            continue
        #************************
        if (day == iday):
          cbarflag= "True"
        ##************************
        frontdir      = "/media/disk2/out/JRA25/sa.one.%s/6hr/tenkizu/%02dh/%04d%02d/front"%(resol,thdura, year, mon)
        tenkizudir    = "/media/disk2/out/JRA25/sa.one.%s/6hr/tenkizu/%02dh/%04d%02d"%(resol,thdura, year, mon)
        jraprecdir    = "/media/disk2/out/JRA25/sa.one.%s/6hr/tenkizu/%02dh/%04d%02d"%(resol,thdura, year, mon)
        ctrack_func.mk_dir(frontdir) 

        #************************
        # chart front
        chartname = "/media/disk2/out/chart/ASAS/front/%04d%02d/fig/front.ASAS.%04d.%02d.%02d.%02d.png"%(year,mon,year,mon,day,hour)
        charttemp = "/media/disk2/out/chart/ASAS/front/%04d%02d/fig/front.ASAS.%04d.%02d.%02d.%02d.temp.png"%(year,mon,year,mon,day,hour)
        plt.clf()
        figchart  = plt.figure(dpi=100, figsize=(subsize_x/100.,subsize_y/100.))
        axchart   = figchart.add_axes([0,0,1.0,1.0])
        a2chart   = mpimg.imread(chartname)
        a2chart   = a2chart[150:-150,30:-30]
        plt.imshow(a2chart)
        plt.savefig(charttemp) 
        print charttemp

コード例 #21
0
ファイル: drat.season.match.py プロジェクト: nbykutsumi/PMM
def mk_plot_III(da1v, da1std, ltag, region):
  figplot  = plt.figure(figsize=(6,3))
  axplot   = figplot.add_axes([0.1, 0.15, 0.87, 0.62])
  #**** sdate **********
  #lsdate    = range(1,12+1)
  lsdate    = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
  lx  =  arange(len(lsdate))
  dcolor = ret_dcolor()
  #*********************
  #------------
  for i,tag in enumerate(ltag):
    lv   = da1v[tag]
    lstd = da1std[tag]
    if tag =="plain":
      continue
    axplot.bar(lx-0.5+0.2*i, lv, width=0.2, color=dcolor[tag]) 
    axplot.errorbar(lx-0.5 +0.2*i +0.1, lv, lstd, color=dcolor[tag], linewidth=0, elinewidth=1.0, ecolor="k")
  #**** plain ***********
  axplot.plot(lx, lv, "-o", color=dcolor["plain"])
  axplot.errorbar(lx, lv, lstd, linewidth=0., elinewidth=2, ecolor=dcolor["plain"])
  #**** zero-line *******
  axplot.plot([-1,len(lM)+2],[0,0],"-",color="k",linewidth=1.0)

  #**** x-ticks *********
  axplot.xaxis.set_ticks(lx[0::2], minor=True)
  axplot.xaxis.set_ticks(lx[0::2])
  axplot.xaxis.set_ticklabels( lsdate[0::2], minor=False, fontsize=22)
  #**** y-ticks *********
  for tick in axplot.yaxis.get_major_ticks():
    tick.label.set_fontsize(18)

  #**** axis limit ******
  #axplot.set_ylim(bottom=0)
  ltmp = []
  for tag in ltag:
    ltmp =  ltmp+da1v[tag]
  ylim_max     = max(ltmp) *1.2
  axplot.set_ylim(top=ylim_max)
  #-----------------------
  axplot.set_xlim([-0.5,11.5])

  #**** grid ************
  #plt.grid(b=True, which="major", linestyle="-",  linewidth=0.3)
  #plt.grid(b=True, which="minor", linestyle="--", linewidth=0.3)

  #**** title ***********
  #ssuptitle  = "  %s"%(regionname)
  #plt.suptitle(ssuptitle,fontsize=23)

  stitle = "d.rat [mm/h] %s %s minus %s %04d-%04d"%(region, prtype1, prtype2, iY, eY)
  plt.title(stitle, fontsize=10)

  #*********************
  season   = "ALL"

  sdir_root, sdir, amtname1, amtname2, ratname1, ratname2, sumname1, sumname2, numname = ret_name_clim(prtype1, prtype2, tag, para_tag, iY, eY, season)

  figdir  = sdir + "/pict.PMM"
  figname = figdir + "/drat.season.%s-%s.%s.png"%(prtype1,prtype2,region)

  ctrack_func.mk_dir(figdir)
  figplot.savefig(figname)
  print figname
コード例 #22
0
ファイル: mk.sum.scales.py プロジェクト: nbykutsumi/dtanl
for era in ["his","fut"]:
  ddir_root[era] = "/media/disk2/out/CMIP5/day/%s/%s/%s/tracks/dura%02d/%02d-%02d/c%02d/cmin%04d"%(model, dexpr[era], ens, thdura, imon, emon, nclass, cmin )

ddir_root["dif"] = "/media/disk2/out/CMIP5/day/%s/dif/%s/%04d-%04d.%04d-%04d/tracks/dura%02d/%02d-%02d/c%02d/cmin%04d"%(model, dexpr["fut"], diyear["his"], deyear["his"], diyear["fut"], deyear["fut"], thdura, imon, emon, nclass, cmin)

#-----

ddir  = {}
dname = {}
for era in ["his", "fut", "dif"]:
  for dirvar in ldirvar + ["mnum","mp","sp_season"]:
    #----
    ddir[era, dirvar]  =  ddir_root[era] + "/%s"%(dirvar)
    #---
    func.mk_dir(ddir[era, dirvar])

#**********************
# names for each class
#----------------------
dname  = {}
for dirvar in ldirvar:
  for var in dlvar[dirvar]:
    for iclass in lclass + [-1]:
      dname[dirvar, var, iclass] =  ddir[era, dirvar] + "/up.%s.p%05.2f.cmin%04d.up%02d.c00.%02d.r%04d.nw%02d_%s_day_%s_%s_%s.bn"%(var, xth, cmin, iclass, nclass, crad, nwbin, season, model, expr, ens )
#**********************
# name for various data
#----------------------
ddatname = {}
for era in lera+["dif"]:
  for var in ["mnum", "mp", "sp_season"]:
コード例 #23
0
    for var in lvar:
      #ctlname    = idir_root + "/%s/%04d/%s.ctl"%(stype, iyear, stype)
      #idir      = idir_root  +  "/%s/%04d%02d"%(stype, year, mon)

      ctlname    = idir_root + "/%s/%04d/%s.ctl"%(stype, iyear, stype)
      idir      = idir_root  +  "/%s/%04d%02d"%(stype, year, mon)
      #-----
      if model == "org":
        odir_root =  "/media/disk2/data/JRA25/sa.one.anl_p/%s"%(tstp)
      else:
        odir_root =  "/media/disk2/data/JRA25/sa.one.%s/%s"%(model, tstp)
      #-----
      odir_temp = odir_root  +  "/%s"%(var)
      odir      = odir_temp  +  "/%04d%02d"%(year, mon)
      #-- make directory ---
      ctrack_func.mk_dir(odir_root)
      ctrack_func.mk_dir(odir_temp)
      ctrack_func.mk_dir(odir)
    
    
      #-- discription file ----------------
      #< dims >
      sout   = "lev %d\nlat %d\nlon %d"%(nz_fin, ny_fin, nx_fin)
      f      = open( odir + "/dims.txt", "w")
      f.write(sout)
      f.close()
    
      #< lat >
      sout   = "\n".join(map( str, a1lat_fin))
      f      = open( odir + "/lat.txt", "w")
      f.write(sout)
コード例 #24
0
ファイル: dif.prec.stat.py プロジェクト: nbykutsumi/dtanl
     #-----------------
     dtv_p[reg, iclass] = func.ret_tv_difmean(dlp[reg, "fut",iclass], dlp[reg, "his",iclass])
     dtv_sp[reg, iclass] = func.ret_tv_difmean(dlsp[reg, "fut",iclass], dlsp[reg, "his",iclass])
     print iclass, dtv_p[reg, iclass]
     #-----------------
     # calc difference of regional mean
     #-----------------
     dfc_p[reg, iclass] = (mean(dlp[reg, "fut", iclass]) - mean(dlp[reg, "his", iclass]))/mean(dlp[reg,"his",iclass]) * 100.0
     dfc_sp[reg, iclass] = (mean(dlsp[reg, "fut", iclass]) - mean(dlsp[reg, "his", iclass]))/mean(dlsp[reg,"his",iclass]) * 100.0
 
 #****************************************
 # write csv
 #----------------------------------------
 csvdir = csvdir_root 
 
 func.mk_dir(csvdir)
 
 #------------
 for reg in lreg:
   #--------
   # name
   #--------
   statname_p  = csvdir + "/prec.stat.%s.p%05.2f.cn%02d.r%04d._%s_day_%s_%s_%s.csv"%(reg, xth, nclass, crad, season, model, dexpr[era], ens)
   statname_sp  = csvdir + "/tot-prec.stat.%s.p%05.2f.cn%02d.r%04d._%s_day_%s_%s_%s.csv"%(reg, xth, nclass, crad, season, model, dexpr[era], ens)
   #--------
   sstat_p = "class,his,fut,frac.chng,t\n"
   sstat_sp = "class,his,fut,frac.chng,t\n"
   for iclass in lclass:
     sstat_p  = sstat_p  + "%s,%s,%s,%s,%s"%( iclass, dp_reg[reg, "his", iclass], dp_reg[reg, "fut", iclass], dfc_p[reg, iclass], dtv_p[reg, iclass]) + "\n"
     sstat_sp = sstat_sp + "%s,%s,%s,%s,%s"%( iclass, dsp_reg[reg, "his", iclass], dsp_reg[reg, "fut", iclass], dfc_sp[reg, iclass], dtv_sp[reg, iclass]) + "\n"
   #--------
コード例 #25
0
ファイル: cdens.py プロジェクト: nbykutsumi/dtanl
#----------
dpgradrange  = ctrack_para.ret_dpgradrange()
lclass       = dpgradrange.keys()
nclass       = len(lclass) -1
#**********************
#  names for each class
#----------------------
outdir_root     = "/media/disk2/out/CMIP5/6hr/%s/%s/%s/tracks/map"%(model, expr, ens)

ddens_area_name  = {}
dtrack_name      = {}
doutdir          = {}
for year in range(iyear, eyear+1) + [0]: 
  #---------------------------
  doutdir[year]  = outdir_root + "/%04d"%(year)
  func.mk_dir(doutdir[year])

  #---------------------------
  for iclass in lclass:
    ddens_area_name[year, iclass]  = doutdir[year]  + "/dens.area.dura%02d.nc%02d.c%02d_%s_%s_%s_%s_%s.bn"%(thdura, nclass, iclass, season, tstp, model, expr, ens)
    dtrack_name[year, iclass]      = doutdir[year]  + "/track.grid.dura%02d.nc%02d.c%02d_%s_%s_%s_%s_%s.bn"%(thdura, nclass, iclass, season, tstp, model, expr, ens)
#**********************
#  names for each upper side of the class
#----------------------
outdir     = "/media/disk2/out/CMIP5/6hr/%s/%s/%s/tracks/map"%(model, expr, ens)

ddens_area_u_name  = {}
dtrack_u_name      = {}
doutdir            = {}
for year in range(iyear, eyear+1) + [0]:
  #---------------------------
コード例 #26
0
    # ---------------
    iyear, eyear = dyrange[expr]
    ens = cmip_para.ret_ens(model, expr, "psl")
    sunit, scalendar = cmip_para.ret_unit_calendar(model, expr)
    ny_bn, nx_bn = cmip_para.ret_nynx_cmip(model)
    # ****************************************************
    # dir_root
    # ---------------
    psldir_bn_root = "/media/disk2/data/CMIP5/bn.%s.%s/psl" % (model, expr)
    psldir_one_root = "/media/disk2/data/CMIP5/sa.one.%s.%s/psl" % (model, expr)
    pslmeandir_root = "/media/disk2/data/CMIP5/bn.%s.%s/psl.my.mean" % (model, expr)
    orogdir_root = "/media/disk2/data/CMIP5/sa.one.%s.%s/orog" % (model, expr)

    # -- out ---
    pgraddir_root = "/media/disk2/out/CMIP5/bn.sa.one.%s.%s/6hr/pgrad" % (model, expr)
    ctrack_func.mk_dir(pgraddir_root)
    # ****************************************************
    # lat, lon data
    # ----------------------
    a1lat_bn = ret_a1lat_bn(psldir_bn_root)
    a1lon_bn = ret_a1lon_bn(psldir_bn_root)
    a1lat_one = arange(-89.5, 89.5 + 0.001, 1.0)
    a1lon_one = arange(0.5, 359.5 + 0.001, 1.0)

    # ****************************************************
    #  orog data
    # --------------
    orogdir = orogdir_root
    orogname = orogdir + "/orog.%s.sa.one" % (model)
    a2orog = fromfile(orogname, float32).reshape(ny_one, nx_one)
    # **************************************************
コード例 #27
0
      idir       = idir_root + "/%04d"%(year)
      iname      = idir + "/num.t.front.%s.%s.rad%04dkm.M1_%s_M2_%s.%04d.%02d.sa.one"%(model,ens, countrad, thfmask1t, thfmask2t, year, mon)
      a2count_tmp= fromfile(iname, float32).reshape(ny,nx)
      a2count    = a2count + a2count_tmp

  #****************************
  # write
  #-----------------
  totaltime = cmip_para.ret_totaldays_cmip(iyear,eyear,season,sunit=sunit,scalendar=scalendar) *4.0
  a2freq   = a2count / totaltime
  odir_root= idir_root
  odir     = odir_root + "/%04d-%04d.%s"%(iyear,eyear,season)

  oname    = odir + "/freq.t.front.%s.%s.rad%04dkm.M1_%4.2f_M2_%3.1f.%04d-%04d.%s.sa.one"%(model,ens, countrad, thfmask1t, thfmask2t, iyear,eyear,season)
  #--- write -----
  ctrack_func.mk_dir(odir)
  a2freq.tofile(oname)
  print oname

  #***************
  # figure
  #---------------
  if figflag == True:
    #--- shade       ------
    thorog     = ctrack_para.ret_thorog()
    orogname   = "/media/disk2/data/CMIP5/sa.one.%s.%s/orog/orog.%s.sa.one"%(model,expr,model)
    a2orog     = fromfile(orogname, float32).reshape(ny,nx)
    a2one    = ones([ny,nx],float32)
    a2shade  = ma.masked_where( a2orog >=thorog, a2one).filled(miss)

    if sum3x3flag == True:
コード例 #28
0
ファイル: dif.dens.py プロジェクト: nbykutsumi/dtanl
ddir_root["his"] = "/media/disk2/out/CMIP5/6hr/%s/historical/%s/tracks/map"%(model, ens)
ddir_root["dif"] = "/media/disk2/out/CMIP5/6hr/%s/dif/%s/tracks/map"%(model, ens)
csvdir_root      = "/media/disk2/out/CMIP5/6hr/%s/dif/%s/tracks/csv"%(model, ens)
#-------------
ddir  = {}
for era in ["his", "fut"]:
  #------------
  iyear = diyear[era]
  eyear = deyear[era]
  #------------
  for year in range(iyear, eyear+1) + [0]:
    ddir[era, year]  = ddir_root[era] + "/%04d"%(year)
#---
ddir["dif"] = ddir_root["dif"] + "/%04d.%04d-%04d.%04d"%(diyear["his"], deyear["his"], diyear["fut"], deyear["fut"])
#
func.mk_dir(ddir["dif"])
#**********************
# names for each class
#----------------------
ddensname  = {}
for era in ["his", "fut"]:
  #------------
  iyear = diyear[era]
  eyear = deyear[era]
  #------------
  for year in range(iyear, eyear+1) + [0]:
    for iclass in lclass:
      ddensname[era, year, iclass]     = ddir[era, year]  + "/dens.area.dura%02d.nc%02d.c%02d_%s_6hr_%s_%s_%s.bn"%(thdura, nclass, iclass, season, model, dexpr[era], ens)
#----------------
# name for dif
#----------------
コード例 #29
0
   thfmask2   = thfmask2t    # sample for "t"
 elif ftype   == "q":
   thfmask1   = thfmask1q    # sample for "q"
   thfmask2   = thfmask2q    # sample for "q"
 #-----------------------------
 #-----------------------------
 miss_out  = -9999.0
 ny  = 180
 nx  = 360
 highsidedist  = ctrack_para.ret_highsidedist()
 
 stime         = "%04d%02d%02d%02d"%(year, mon, day, hour)
 sodir         = "/home/utsumi/temp/tenkizu"
 cbardir       = sodir
 
 ctrack_func.mk_dir(sodir)
 
 dlat    = 1.0
 dlon    = 1.0
 a1lat   = arange(-89.5, 89.5  + dlat*0.1, dlat)
 a1lon   = arange(0.5,   359.5 + dlon*0.1, dlon)
 
 meridians = 10.0
 
 resol    = "anl_p"
 #-----------------------------
 #-----------------------------
 miss_out  = -9999.0
 ny  = 180
 nx  = 360
 highsidedist  = ctrack_para.ret_highsidedist()
コード例 #30
0
    da2num_occ  = {}
    da2num_stat = {}
    da2num_all  = {}
    for thdist in lthdist:
      da2num_warm[thdist] = zeros([ny,nx], float32) 
      da2num_cold[thdist] = zeros([ny,nx], float32) 
      da2num_occ[thdist]  = zeros([ny,nx], float32) 
      da2num_stat[thdist] = zeros([ny,nx], float32) 
      da2num_all[thdist]  = zeros([ny,nx], float32) 
    #---
    a2num_plain = zeros([ny,nx], float32) 
    #----------------------------
    odir_root  = "/media/disk2/out/chart/%s/front/agg/%04d/%02d"%(region, year, mon)
    #-- out dir -----------------
    rfreqdir     = odir_root + "/rfreq"
    ctrack_func.mk_dir(rfreqdir)
    
    figdir      = rfreqdir

    #----------------
    locdir  = locdir_root  + "/%04d%02d"%(year,mon)
    #----------------
    eday = calendar.monthrange(year, mon)[1]
    #eday = iday
    for day in range(iday, eday+1):
      print mon, day
      for hour in lhour:
        #---------------------
        if ((year==iyear)&(mon==1)&(day==1)):
          continue
        if ((year==eyear)&(mon==12)&(day==31)):