def evolution_ana(initTime=[], fhour=0, atime=6, data_source='CIMISS', model='GRAPES_GFS', func=None, func_other_args={}, max_workers=6, show='tab', output_dir='./temp/', tab_size=(30, 18), keep_temp=False): systime = datetime.datetime.now() temp_path = './temp/' + systime.strftime('%M%S%f') + '/' isExists = os.path.exists(temp_path) if not isExists: os.makedirs(temp_path) pool = mp.Pool(processes=max_workers) for idx, iinit in enumerate(initTime): func_args = copy.deepcopy(func_other_args) func_args['initTime'] = iinit func_args['fhour'] = fhour func_args['atime'] = atime func_args['model'] = model func_args['data_source'] = data_source func_args['map_ratio'] = 14 / 9 func_args['lw_ratio'] = [14, 9] func_args['output_dir'] = temp_path + str(idx) + '_' + model x = pool.apply_async(func, kwds=func_args) #x.get() # for debug timer.sleep(1) pool.close() pool.join() pic_all = os.listdir(temp_path) if len(pic_all) == 0: shutil.rmtree(temp_path) return pic_all = sorted(pic_all, key=lambda i: int(i.split('_')[0])) if (show == 'tab'): png_name = 'evolution_ana_{}.png'.format(func.__name__) utl.save_tab(temp_path=temp_path, pic_all=pic_all, tab_size=tab_size, output_dir=output_dir, png_name=png_name, keep_temp=keep_temp) if (show == 'animation'): gif_name = 'evolution_ana_{}.gif'.format(func.__name__) utl.save_animation(temp_path=temp_path, pic_all=pic_all, output_dir=output_dir, gif_name=gif_name, keep_temp=keep_temp)
def compare(func=None, initTime=None, fhour=24, output_dir='./temp/', models=['ECMWF', 'GRAPES_GFS', 'NCEP_GFS', 'GRAPES_3KM'], tab_size=(30, 18), show='tab', func_other_args={}, max_workers=6, keep_temp=False): systime = datetime.datetime.now() temp_path = './temp/' + systime.strftime('%M%S%f') + '/' isExists = os.path.exists(temp_path) if not isExists: os.makedirs(temp_path) pool = mp.Pool(processes=max_workers) for idx, imodel in enumerate(models): func_args = copy.deepcopy(func_other_args) func_args['initTime'] = initTime.strftime('%Y%m%d%H')[2:10] func_args['fhour'] = fhour func_args['model'] = imodel func_args['map_ratio'] = 14 / 9 func_args['output_dir'] = temp_path + str(idx) + '_' + imodel pool.apply_async(func, kwds=func_args) timer.sleep(1) pool.close() pool.join() pic_all = os.listdir(temp_path) if len(pic_all) == 0: shutil.rmtree(temp_path) return # png_name = 'compare_{}.png'.format(func.__name__) # utl.save_tab(temp_path=temp_path,pic_all=pic_all,tab_size=tab_size,output_dir=output_dir,png_name=png_name) pic_all = sorted(pic_all, key=lambda i: int(i.split('_')[0])) if (show == 'tab'): png_name = 'compare_{}.png'.format(func.__name__) utl.save_tab(temp_path=temp_path, pic_all=pic_all, tab_size=tab_size, output_dir=output_dir, png_name=png_name, keep_temp=keep_temp) if (show == 'animation'): gif_name = 'compare_{}.gif'.format(func.__name__) utl.save_animation(temp_path=temp_path, pic_all=pic_all, output_dir=output_dir, gif_name=gif_name, keep_temp=keep_temp)
def stability(target_time=None, latest_init_time=None, ninit=4, init_interval=12, model='GRAPES_GFS', func=None, func_other_args={}, max_workers=6, show='tab', output_dir='./temp/', tab_size=(30, 18), keep_temp=False): systime = datetime.datetime.now() temp_path = './temp/' + systime.strftime('%M%S%f') + '/' isExists = os.path.exists(temp_path) if not isExists: os.makedirs(temp_path) if (target_time != None): target_time = datetime.datetime.strptime(target_time, '%y%m%d%H') if (latest_init_time != None): latest_init_time = datetime.datetime.strptime(latest_init_time, '%y%m%d%H') if latest_init_time is None: # 获得最近的一次模式起报时间 latest_init_time = utl.get_latest_init_time_model() else: latest_init_time = datetime.datetime(latest_init_time.year, latest_init_time.month, latest_init_time.day, latest_init_time.hour) # 如果target_time为空,则取latest_init_time+36 if target_time is None: target_time = latest_init_time + datetime.timedelta(hours=36) target_time = datetime.datetime(target_time.year, target_time.month, target_time.day, target_time.hour) if target_time < latest_init_time: print( 'target_time({:%Y%m%d%H}) < latest_init_time({:%Y%m%d%H})'.format( target_time, latest_init_time)) return initTime = latest_init_time fhour = int((target_time - latest_init_time).total_seconds() / 60 / 60) pool = mp.Pool(processes=max_workers) for i in range(ninit): func_args = copy.deepcopy(func_other_args) func_args['initTime'] = (initTime - datetime.timedelta( hours=init_interval * i)).strftime('%Y%m%d%H')[2:10] func_args['fhour'] = fhour + init_interval * i func_args['model'] = model func_args['map_ratio'] = 14 / 9 func_args['lw_ratio'] = [14, 9] func_args['output_dir'] = temp_path + str(i) + '_' + model if func_args['fhour'] < 0: continue pool.apply_async(func, kwds=func_args) timer.sleep(1) pool.close() pool.join() pic_all = os.listdir(temp_path) if len(pic_all) == 0: shutil.rmtree(temp_path) return # png_name = 'stability_{}.png'.format(func.__name__) # utl.save_tab(temp_path=temp_path,pic_all=pic_all,tab_size=tab_size,output_dir=output_dir,png_name=png_name) pic_all = sorted(pic_all, key=lambda i: int(i.split('_')[0])) if (show == 'tab'): png_name = 'stability_{}.png'.format(func.__name__) utl.save_tab(temp_path=temp_path, pic_all=pic_all, tab_size=tab_size, output_dir=output_dir, png_name=png_name, keep_temp=keep_temp) if (show == 'animation'): gif_name = 'stability_{}.gif'.format(func.__name__) utl.save_animation(temp_path=temp_path, pic_all=pic_all, output_dir=output_dir, gif_name=gif_name, keep_temp=keep_temp)
def structure3D(func=None, levs=[{ 'uv_lev': 925 }, { 'uv_lev': 850 }, { 'uv_lev': 700 }, { 'uv_lev': 500 }], initTime=None, fhour=24, model='GRAPES_GFS', func_other_args={}, max_workers=6, show='tab', output_dir='./temp/', tab_size=(30, 18), keep_temp=False): systime = datetime.datetime.now() temp_path = './temp/' + systime.strftime('%M%S%f') + '/' isExists = os.path.exists(temp_path) if not isExists: os.makedirs(temp_path) pool = mp.Pool(processes=max_workers) for idx, ilev in enumerate(levs): func_args = copy.deepcopy(func_other_args) func_args = {**func_args, **ilev} func_args['initTime'] = initTime func_args['fhour'] = fhour func_args['model'] = model func_args['map_ratio'] = 14 / 9 func_args['lw_ratio'] = [14, 9] func_args['output_dir'] = temp_path + str(idx) + '_' + model pool.apply_async(func, kwds=func_args) timer.sleep(1) pool.close() pool.join() pic_all = os.listdir(temp_path) if len(pic_all) == 0: shutil.rmtree(temp_path) return pic_all = sorted(pic_all, key=lambda i: int(i.split('_')[0])) if (show == 'tab'): png_name = 'structure3D_{}.png'.format(func.__name__) utl.save_tab(temp_path=temp_path, pic_all=pic_all, tab_size=tab_size, output_dir=output_dir, png_name=png_name, keep_temp=keep_temp) if (show == 'animation'): gif_name = 'structure3D_{}.gif'.format(func.__name__) utl.save_animation(temp_path=temp_path, pic_all=pic_all, output_dir=output_dir, gif_name=gif_name, keep_temp=keep_temp)
def vercompare(anl_time=None, ninit=4, init_interval=12, model='GRAPES_GFS', func=None, func_other_args={}, max_workers=6, show='tab', output_dir='./temp/', tab_size=(30, 18), keep_temp=False): if (anl_time != None): anl_time = datetime.datetime.strptime(anl_time, '%y%m%d%H') systime = datetime.datetime.now() temp_path = './temp/' + systime.strftime('%M%S%f') + '/' isExists = os.path.exists(temp_path) if not isExists: os.makedirs(temp_path) initTime = None fhour = None if anl_time is None: # 获得最近的一次000时效预报数据 initTime = utl.get_latest_init_time_model() fhour = 0 else: # fhour固定为0,此时对于如ecwmf只有anl_time=08/20时才会找得到 initTime = datetime.datetime(anl_time.year, anl_time.month, anl_time.day, anl_time.hour) fhour = 0 pool = mp.Pool(processes=max_workers) for i in range(ninit): func_args = copy.deepcopy(func_other_args) func_args['initTime'] = (initTime - datetime.timedelta( hours=init_interval * i)).strftime('%Y%m%d%H')[2:10] func_args['fhour'] = fhour + init_interval * i func_args['model'] = model func_args['map_ratio'] = 14 / 9 func_args['lw_ratio'] = [14, 9] func_args['output_dir'] = temp_path + str(i) + '_' + model if func_args['fhour'] < 0: continue pool.apply_async(func, kwds=func_args) timer.sleep(1) pool.close() pool.join() pic_all = os.listdir(temp_path) if len(pic_all) == 0: shutil.rmtree(temp_path) return # png_name = 'vercompare_{}.png'.format(func.__name__) # utl.save_tab(temp_path=temp_path,pic_all=pic_all,tab_size=tab_size,output_dir=output_dir,png_name=png_name) pic_all = sorted(pic_all, key=lambda i: int(i.split('_')[0])) if (show == 'tab'): png_name = 'vercompare_{}.png'.format(func.__name__) utl.save_tab(temp_path=temp_path, pic_all=pic_all, tab_size=tab_size, output_dir=output_dir, png_name=png_name, keep_temp=keep_temp) if (show == 'animation'): gif_name = 'vercompare_{}.gif'.format(func.__name__) utl.save_animation(temp_path=temp_path, pic_all=pic_all, output_dir=output_dir, gif_name=gif_name, keep_temp=keep_temp)