def aveCLnum(iYM, eYM, icl): clName = dclShortName[icl] sDir = "/tank/utsumi/CLOUDTYPE/WNPAC/num" lYM = util.ret_lYM(iYM, eYM) a2out = zeros([ny,nx], int32) for YM in lYM: Year, Mon = YM sPath = sDir + "/num.%04d%02d.%s.%dx%d"%(Year,Mon,clName,ny,nx) a2out = a2out + fromfile(sPath, int32).reshape(ny,nx) a2out = a2out / len(lYM) return ma.masked_where(a2dommask==-9999., a2out)
def accDat(dattype,iYM, eYM, binPr, sumnum="num"): dfunc = {"sum":loadSum ,"num":loadNum } ddtype= {"sum":"float32" ,"num":"int32" } accDat = zeros([ncltype, ny, nx], ddtype[sumnum]) lYM = util.ret_lYM(iYM,eYM) for (Year,Mon) in lYM: accDat = accDat + dfunc[sumnum](dattype,Year,Mon,binPr) return accDat
def ret_gNameLatLon(domain): iYM = [2005,4] eYM = [2014,9] lYM = util.ret_lYM(iYM, eYM) lYM = [YM for YM in lYM if YM[1] not in [1,2,3,11,12]] lYM = lYM[::-1] #-- load gauge data daPrcp = {} dLat = {} dLon = {} lgName = [] for YM in lYM: Year,Mon = YM try: lgNameTmp = dgName[domain, Year, Mon] except KeyError: continue for gName in lgNameTmp: if gName not in lgName: lgName.append(gName) dLat[gName], dLon[gName] = gv.dlatlon[domain,gName] return lgName, dLat, dLon
from numpy import * from datetime import datetime, timedelta from collections import deque from gv_fsub import * import GPMGV import numpy as np import myfunc.util as util import matplotlib.pyplot as plt import sys, os calc = True #calc = False iYM = [2005,4] #iYM = [2014,10] eYM = [2014,10] lYM = util.ret_lYM(iYM, eYM) lYM = [YM for YM in lYM if YM[1] not in [1,2,3,11,12]] print lYM #thdist = 2.5 # km thdist = 5 # km minNum = 3 prdName = 'L2A25' nh = 40 gv = GPMGV.GPMGV() gv.load_sitelist_reclassified() dgName = gv.ret_ddomYM2gName() ldomain = gv.domains #ldomain = ['FLORIDA-STJ','FLORIDA-SFL-N','N.Carolina-IPHEx_Duke','N.Carolina-IPHEx_NASA','KWAJALEIN-KWA']
def ret_num(iYM,eYM,rtype): lYM = util.ret_lYM(iYM,eYM) a3dat= zeros([nz,ny,nx],int32) for Year,Mon in lYM: a3dat = a3dat + ret_num_single(Year,Mon,rtype) return a3dat
def ret_sumnum(sumnum,iYM,eYM,rtype): lYM = util.ret_lYM(iYM,eYM) a2dat= zeros([ny,nx],int32) for Year,Mon in lYM: a2dat = a2dat + ret_sumnum_single(sumnum,Year,Mon,rtype) return a2dat
region = line[0] nwName = line[1] nwCode = line[2] domain = line[3] gCode = line[4] lat = float(line[5]) lon = float(line[6]) sYear = int(line[7]) sMon = int(line[8]) eYear = int(line[9]) eMon = int(line[10]) key = domain lYM = util.ret_lYM([sYear,sMon],[eYear,eMon]) if len(line)>11: lnoYM = map(YYYYMM2YM, line[12:]) ltmp = [YM for YM in lYM if YM not in lnoYM ] lYM = ltmp # initialize if key not in lkey: lkey.append(key) dYM[key] = lYM dnwCode[key] = nwCode dlat[key]= [lat] dlon[key]= [lon] else:
from numpy import * import myfunc.util as util import os, sys, socket import matplotlib.pyplot as plt import matplotlib from scipy import stats matplotlib.use('Agg') iYM = [1997,12] eYM = [2013,11] #eYM = [2006,11] dMon= 1 lYM = util.ret_lYM(iYM, eYM)[::dMon] hostname = socket.gethostname() if hostname =="mizu": rootDir = "/home/utsumi/mnt/wellshare" elif hostname=="well": rootDir = "/media/disk2/share" rootDir = os.path.join(rootDir, "HCELL/SUMNUM/Type") #lrtype = ["strat","conv","other","all"] lrtype = ["all"] ny = 148 nx = 180 miss= -9999. Lat = arange(-37+0.25,37-0.25+0.01,0.5) Lon = arange(0+1.0,360-1.0+0.01,2.0)
def loadMonthly(self, ID, iYM=False, eYM=False): srcPath = self.ret_pathMonthly(ID)[2] f=open(srcPath, "r") lines = f.readlines() f.close() lYM = deque([]) ldat = deque([]) for sline in lines: line = sline.strip().split(",") Year = int(line[0]) Mon = int(line[1]) dat = float(line[2]) DTime = datetime(Year,Mon,1,0) lYM.append([Year,Mon]) ldat.append(dat) lYM = array(lYM) ldat= array(ldat) #-- record period -- if type(iYM)==bool: lYMout = lYM ldatout = ldat else: iDTimeOut = datetime(iYM[0], iYM[1],1,0) eDTimeOut = datetime(eYM[0], eYM[1],1,0) iDTimeDat = datetime(lYM[0][0],lYM[0][1],1,0) eDTimeDat = datetime(lYM[-1][0],lYM[-1][1],1,0) iYMDat = [lYM[0][0], lYM[0][1]] eYMDat = [lYM[-1][0],lYM[-1][1]] iYMOut = iYM eYMOut = eYM lYMout = util.ret_lYM(iYM, eYM) ldatout= ones(len(lYMout))*self.miss_out if eDTimeDat < iDTimeOut: #print "case1" pass elif ((iDTimeDat<=iDTimeOut)\ &(iDTimeOut<=eDTimeDat)\ &(eDTimeDat<=eDTimeOut)): #print "case2" ldatout[:len(util.ret_lYM(iYMOut,eYMDat))] = ldat[-len(util.ret_lYM(iYMOut,eYMDat)):] elif ((iDTimeOut<=iDTimeDat)&(eDTimeDat<=eDTimeOut)): #print "case3" ldatout[len(util.ret_lYM(iYMOut,iYMDat))-1:len(util.ret_lYM(iYMOut,iYMDat))-1 + len(ldat)] = ldat elif ((iDTimeOut<=iDTimeDat)\ &(iDTimeDat<=eDTimeOut)\ &(eDTimeOut<=eDTimeDat)): #print "case4" ldatout[-len(util.ret_lYM(iYMDat,eYMOut)):] = ldat[:len(util.ret_lYM(iYMDat,eYMOut))] elif eDTimeOut < iDTimeDat: #print "case5" pass elif ((iDTimeDat<=iDTimeOut)&(eDTimeOut<=eDTimeDat)): #print "case6" ldatout = ldat[len(util.ret_lYM(iYMDat,iYMOut))-1:len(util.ret_lYM(iYMDat,iYMOut))-1 + len(lYMout)] else: print "Check!! in loadMonthly" sys.exit() #---------------- return lYMout, ldatout