def getPoint(self, item): """ return object for selected station """ if item not in self.meta: raise KeyError, "wrong data index" gdat=[[int(ln[1]),ln[2:]] for ln in self.dat if ln[0]==item] gdat.sort(key=lambda a: a[0]) m=self.meta[item] return createCliDat(gdat=gdat,meta=m)
def getPoint(self, ind): if type(ind) is str: ind = self.codes[ind] else: ind = int(ind) tm = self.meta[ind] gdat = self.readDataFile(tm['code']) return createCliDat(meta=tm, gdat=gdat, fillValue=-999)
def getPoint(self, item): latInd, lonInd = self.__specifyInd__(item) meta={'ind':self.latlonInd2ind(latInd, lonInd), 'lat':self.latvals[latInd], 'lon':self.lonvals[lonInd], 'dt':self.dt} gdat=[] for year in range(self.firstObservation.year, self.yMax): ln=[-999.99]*12 for mon in range(1,13): f, r = self.getDataObj(year,mon) if r is not None: v=r[self.lev-1,latInd,lonInd] if v < 0 :continue ln[mon-1]=float(v * 10 ** 9) gdat.append([year,ln]) return createCliDat(meta=meta, gdat=gdat, fillValue=-999.99)
def getPoint(self, item): """ self[(latInd,lonInd)] возвращает объект cliData item could be either point index or (latIndex, lonIndex) but not (lat, lon). Use self.latlon2latIndlonInd() """ try: latInd, lonInd = item except TypeError: latInd, lonInd = self.ind2latindlonind(item) except: print self.f.model_id, item raise meta={'ind':self.latlonInd2ind(latInd, lonInd), 'lat':self.latvals[latInd], 'lon':self.lonvals[lonInd], 'dt':self.dt} vals=self.var[:,0,latInd,lonInd] gdat=[] for yn,i in enumerate(range(0,len(vals),12)): tyear=self.startYear+yn lineVals=vals[i:i+12] if len(lineVals)==12: gdat.append([tyear, self.convertArray(lineVals)]) return createCliDat(meta=meta, gdat=gdat)
def getPoint(self, item): """ self[(latInd,lonInd)] возвращает объект cliData item could be either point index or (latIndex, lonIndex) but not (lat, lon). Use self.latlon2latIndlonInd() """ try: latInd, lonInd = item if self.warningShown==False: print 'Warning! (lat, lon) is no more a valid argument. Please check your code and' print 'use latlon2latIndlonInd or closestDot function to get coordinate indexes' self.warningShown = True except TypeError: latInd, lonInd = self.ind2latindlonind(item) except: print self.f.model_id, item raise meta={'ind':self.latlonInd2ind(latInd, lonInd), 'lat':self.latvals[latInd], 'lon':self.lonvals[lonInd], 'dt':self.dt, 'modelId':self.f.model_id} vals=self.var[:,latInd,lonInd] gdat=[] if self.startMonth!=1: # весь огород ниже из-за моделей которые начинают год не с января # нормальный вариант для большинства моделей - тот что в else fyl=12-(self.startMonth-1) for yn,i in enumerate(range(fyl,len(vals)-12,12)): tyear=self.startYear+yn gdline=[self.convertValue(v, year=tyear, month=mn+1) for mn,v in enumerate(vals[i:i+12])] gdat.append([self.startYear+yn+1, gdline]) gdatline=[self.convertValue(v, year=tyear, month=mn+1) for mn,v in enumerate(vals[i+12:])] gdatline=gdatline+[None]*(12-len(gdatline)) gdat.append([self.startYear+yn,gdatline]) else: for yn,i in enumerate(range(0,len(vals),12)): tyear=self.startYear+yn lineVals=vals[i:i+12] if len(lineVals)==12: #TODO: сделать нормальное заполнение пропусками, У некоторыйх модлей (EC_EARTH) в последнем году расчёта только 11 месяцев, пропускаем такие года gdat.append([tyear, self.convertArray(lineVals)]) return createCliDat(meta=meta, gdat=gdat)
def getPoint(self, item): if item not in self.meta: raise KeyError, "wrong data index" if self.cdos[item] is None: fn=os.path.join(self.dataFolder, '%i.mon'%item) with open(fn,'r') as f: lines=f.readlines() dat=np.loadtxt(lines,comments='#', delimiter=';',skiprows=41, dtype={'names':['date','hh:mm','original','calculated','flag'],'formats':['S10','S5','f4', 'f4', 'f4']}) dat=np.array([[int(ym[0]), int(ym[1]), v] for ym,v in zip( [v.split('-') for v in dat['date']] , dat['original'])]) gdat=[] years=list(set(dat[:,0])) for y in years: gdatline=list(dat[dat[:,0]==y][:,2]) assert len(gdatline)==12 gdat.append([y,gdatline]) meta=self.parseMeta(lines) meta['yMin']=min(years) meta['yMax']=max(years) cdo=createCliDat(gdat=gdat,meta=meta) self.cdos[item]=cdo self.meta[item]=meta else: cdo=self.cdos[item] return cdo