def show_hours(date_s, Ftype): IDIR = Cfg[Ftype]['I_DIR'] ODIR = Cfg[Ftype]['O_DIR_H'] AERA = Cfg[Ftype]['L2S'] TimeList = [] DictData = {} for i in range(24): dateT1 = date_s + relativedelta(hours=i) TimeList.append(dateT1) for aera in AERA.keys(): Line = [] shortname = Cfg[Ftype]['L2S'][aera].decode('utf-8') ymd = date_s.strftime('%Y%m%d') FileName = urljoin(IDIR, aera, 'hours', ymd + '.txt') print FileName if os.path.isfile(FileName) and os.path.getsize(FileName) != 0: ary = np.loadtxt(FileName, dtype=dtype, skiprows=1).reshape((-1,)) else: for i in range(24): t_str = '%s %s %f %f %f %d' % (ymd, '00:00:00', np.nan, np.nan, np.nan, 9999) Line.append([each.strip() for each in t_str.split()]) ary = np.core.records.fromarrays(np.array(Line).transpose(), names=','.join(dname_Nan), formats=','.join(dtype_Nan)) DictData[shortname] = ary # print DictData if not os.path.isdir(ODIR): os.makedirs(ODIR) # 平均值 DictMean = {} color_dict = {} for eachkey in DictData.keys(): DictMean[eachkey] = DictData[eachkey]['mean'] print 'TimeList', len(TimeList), eachkey, len(DictMean[eachkey]) DictVar = {} for eachkey in DictData.keys(): DictVar[eachkey] = DictData[eachkey]['var'] print 'TimeList', len(TimeList), eachkey, len(DictVar[eachkey]) DictTitle1 = {'xlabel': 'x %s' % ymd, 'ylabel': 'mean', 'title': 'gga'} DictTitle2 = {'xlabel': 'x %s' % ymd, 'ylabel': 'Var', 'title': 'gga'} # ymd = time.strftime('%Y%m%d', time.localtime()) Outimg1 = urljoin(ODIR, ymd + '_mean') Outimg2 = urljoin(ODIR, ymd + '_var') ds_PUB_LIB.draw_time_fig(TimeList, DictMean, Outimg1, DictTitle1, 'H') ds_PUB_LIB.draw_time_fig(TimeList, DictVar, Outimg2, DictTitle2, 'H')
def show_day(Ftype, Ftime): IDIR = Cfg[Ftype]['I_DIR'] ODIR = Cfg[Ftype]['O_DIR_D'] AERA = Cfg[Ftype]['L2S'] TimeList = [] DictData = {} date_s, date_e = ymd2date(Ftime) while date_s <= date_e: TimeList.append(date_s) date_s = date_s + relativedelta(days=1) for aera in AERA.keys(): shortname = Cfg[Ftype]['L2S'][aera].decode('utf-8') print shortname FileList = [] date_s, date_e = ymd2date(Ftime) while date_s <= date_e: ymd = date_s.strftime('%Y%m%d') FileName = urljoin(IDIR, aera, 'days', ymd + '.txt') FileList.append(FileName) date_s = date_s + relativedelta(days=1) data = combine_day(FileList) DictData[shortname] = data if not os.path.isdir(ODIR): os.makedirs(ODIR) print DictData # 平均值 DictMean = {} for eachkey in DictData.keys(): DictMean[eachkey] = DictData[eachkey]['mean'] print 'TimeList', len(TimeList), eachkey, len(DictMean[eachkey]) print len(TimeList), len(DictData[eachkey]) # 偏差 DictVar = {} for eachkey in DictData.keys(): DictVar[eachkey] = DictData[eachkey]['var'] print 'TimeList', len(TimeList), eachkey, len(DictVar[eachkey]) DictTitle1 = {'xlabel': 'x %s' % ymd, 'ylabel': 'mean', 'title': 'gga'} DictTitle2 = {'xlabel': 'x %s' % ymd, 'ylabel': 'Var', 'title': 'gga'} # ymd = time.strftime('%Y%m%d', time.localtime()) Outimg1 = urljoin(ODIR, ymd + '_mean') Outimg2 = urljoin(ODIR, ymd + '_var') ds_PUB_LIB.draw_time_fig(TimeList, DictMean, Outimg1, DictTitle1, 'D') ds_PUB_LIB.draw_time_fig(TimeList, DictVar, Outimg2, DictTitle2, 'D')
def main(): # 获取参数 xArg = sys.argv[1:] # 参数个数目前为2个 args_nums = len(xArg) if args_nums != 3: print 'input error: args nums is three!' return # 获取处理文件时间和文件类型 Ftime = xArg[0] Ftype = xArg[1] Frate = xArg[2] I_DIR = Cfg[Ftype]['I_DIR'] O_DIR = Cfg[Ftype]['O_DIR'] AERA = Cfg[Ftype]['L2S'] DictData = {} for siteName in AERA.keys(): date_s, date_e = ymd2date(Ftime) ShortName = Cfg[Ftype]['L2S'][siteName].decode('utf-8') I_FILE = urljoin(I_DIR, Ftype, siteName, 'time_series_' + Frate + '.txt') SiteData = ReadFile(I_FILE, date_s, date_e) print siteName if len(SiteData) != 0: DictData[ShortName] = SiteData # 平均值 DictMean = {} for eachkey in DictData.keys(): DictMean[eachkey] = DictData[eachkey]['mean'] print DictMean stime = date_s.strftime('%Y%m%d') etime = date_e.strftime('%Y%m%d') DictTitle = {'xlabel': '%s-%s' % (stime, etime), 'ylabel': 'mean', 'title': '%s' % Ftype} O_FILE = urljoin(O_DIR, Ftype, stime + '_' + etime) TimeList = [] for x in xrange(len(SiteData)): dateT = datetime.strptime(SiteData['time'][x], "%Y-%m-%d %H:%M:%S") print dateT TimeList.append(dateT) ds_PUB_LIB.draw_time_fig(TimeList, DictMean, O_FILE, DictTitle, Frate)