def point_fcst( model='ECMWF', output_dir=None, t_range=[0,60], t_gap=3, points={'lon':[116.3833], 'lat':[39.9], 'altitude':[1351]}, initTime=None,day_back=0, extra_info={ 'output_head_name':' ', 'output_tail_name':' ', 'point_name':' '} ): #+get all the directories needed try: dir_rqd=[utl.Cassandra_dir(data_type='surface',data_source=model,var_name='T2m'), utl.Cassandra_dir(data_type='surface',data_source=model,var_name='u10m'), utl.Cassandra_dir(data_type='surface',data_source=model,var_name='v10m'), utl.Cassandra_dir(data_type='surface',data_source=model,var_name='RAIN'+str(t_gap).zfill(2))] except KeyError: raise ValueError('Can not find all required directories needed') #-get all the directories needed if(initTime == None): initTime = get_latest_initTime(dir_rqd[0]) #initTime=utl.filename_day_back_model(day_back=day_back,fhour=0)[0:8] directory=dir_rqd[0][0:-1] fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [initTime+'.'+str(fhour).zfill(3) for fhour in fhours] t2m=utl.get_model_points_gy(dir_rqd[0], filenames, points,allExists=False) u10m=utl.get_model_points_gy(dir_rqd[1], filenames, points,allExists=False) v10m=utl.get_model_points_gy(dir_rqd[2], filenames, points,allExists=False) rn=utl.get_model_points_gy(dir_rqd[3], filenames, points,allExists=False) sta_graphics.draw_point_fcst(t2m=t2m,u10m=u10m,v10m=v10m,rn=rn, model=model, output_dir=output_dir, points=points, extra_info=extra_info )
def point_fcst_rn_according_to_3D_field_box_line(output_dir=None, t_range=[6, 60], t_gap=6, points={ 'lon': [116.3833], 'lat': [39.9] }, initTime=None, obs_ID=54511, extra_info={ 'output_head_name': ' ', 'output_tail_name': ' ', 'point_name': ' ', 'drw_thr': True }, **kwargs): try: dir_rqd = utl.Cassandra_dir(data_type='surface', data_source='ECMWF_ENSEMBLE', var_name='RAIN' + str(t_gap).zfill(2) + '_RAW') except KeyError: raise ValueError('Can not find all required directories needed') #-get all the directories needed if (initTime == None): initTime = get_latest_initTime(dir_rqd) #initTime=utl.filename_day_back_model(day_back=day_back,fhour=0)[0:8] if (t_range[1] > 72): fhours = np.append(np.arange(t_range[0], 72, t_gap), np.arange(72, t_range[1], 6)) else: fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [initTime + '.' + str(fhour).zfill(3) for fhour in fhours] rn = utl.get_model_points_gy(dir_rqd, filenames, points, allExists=False) rn.attrs['model'] = 'ECMWF_ENSEMBLE' Ensemble_graphics.box_line_rn(rn=rn, points=points, extra_info=extra_info, output_dir=output_dir)
def point_fcst_according_to_3D_field( model='ECMWF', output_dir=None, t_range=[0,60], t_gap=3, points={'lon':[116.3833], 'lat':[39.9], 'altitude':[1351]}, initTime=None,obs_ID=54511,day_back=0, extra_info={ 'output_head_name':' ', 'output_tail_name':' ', 'point_name':' ', 'drw_thr':True, 'levels_for_interp':[1000, 950, 925, 900, 850, 800, 700, 600, 500]} ): try: dir_rqd=[utl.Cassandra_dir(data_type='high',data_source=model,var_name='HGT',lvl=''), utl.Cassandra_dir(data_type='high',data_source=model,var_name='UGRD',lvl=''), utl.Cassandra_dir(data_type='high',data_source=model,var_name='VGRD',lvl=''), utl.Cassandra_dir(data_type='high',data_source=model,var_name='TMP',lvl=''), utl.Cassandra_dir(data_type='surface',data_source=model,var_name='RAIN'+str(t_gap).zfill(2))] except KeyError: raise ValueError('Can not find all required directories needed') #-get all the directories needed if(initTime == None): initTime = get_latest_initTime(dir_rqd[0][0:-1]+'/850') #initTime=utl.filename_day_back_model(day_back=day_back,fhour=0)[0:8] directory=dir_rqd[0][0:-1] fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [initTime+'.'+str(fhour).zfill(3) for fhour in fhours] HGT_4D=get_model_3D_grids(directory=directory,filenames=filenames,levels=extra_info['levels_for_interp'], allExists=False) directory=dir_rqd[1][0:-1] U_4D=get_model_3D_grids(directory=directory,filenames=filenames,levels=extra_info['levels_for_interp'], allExists=False) directory=dir_rqd[2][0:-1] V_4D=get_model_3D_grids(directory=directory,filenames=filenames,levels=extra_info['levels_for_interp'], allExists=False) directory=dir_rqd[3][0:-1] TMP_4D=get_model_3D_grids(directory=directory,filenames=filenames,levels=extra_info['levels_for_interp'], allExists=False) rn=utl.get_model_points_gy(dir_rqd[4], filenames, points,allExists=False) directory=dir_rqd[3][0:-1] coords_info_2D=utl.get_model_points_gy(directory+str(extra_info['levels_for_interp'][0])+'/', points=points,filenames=filenames,allExists=False) delt_xy=HGT_4D['lon'].values[1]-HGT_4D['lon'].values[0] mask = (HGT_4D['lon']<(points['lon']+2*delt_xy))&(HGT_4D['lon']>(points['lon']-2*delt_xy))&(HGT_4D['lat']<(points['lat']+2*delt_xy))&(HGT_4D['lat']>(points['lat']-2*delt_xy)) HGT_4D_sm=HGT_4D['data'].where(mask,drop=True) U_4D_sm=U_4D['data'].where(mask,drop=True) V_4D_sm=V_4D['data'].where(mask,drop=True) TMP_4D_sm=U_4D['data'].where(mask,drop=True) lon_md=np.squeeze(HGT_4D_sm['lon'].values) lat_md=np.squeeze(HGT_4D_sm['lat'].values) alt_md=np.squeeze(HGT_4D_sm.values*10).flatten() time_md=np.squeeze(HGT_4D_sm['forecast_period'].values) coords = np.zeros((len(time_md),len(extra_info['levels_for_interp']),len(lat_md),len(lon_md),4)) coords[...,0]=time_md.reshape((len(time_md),1,1,1)) coords[...,2] = lat_md.reshape((1,1,len(lat_md),1)) coords[...,3] = lon_md.reshape((1,1,1,len(lon_md))) coords = coords.reshape((alt_md.size,4)) coords[:,1]=alt_md interpolator_U = LinearNDInterpolator(coords,U_4D_sm.values.reshape((U_4D_sm.values.size)),rescale=True) interpolator_V = LinearNDInterpolator(coords,V_4D_sm.values.reshape((V_4D_sm.values.size)),rescale=True) interpolator_TMP = LinearNDInterpolator(coords,TMP_4D_sm.values.reshape((TMP_4D_sm.values.size)),rescale=True) coords2 = np.zeros((len(time_md),1,1,1,4)) coords2[...,0]=time_md.reshape((len(time_md),1,1,1)) coords2[...,1]=points['altitude'][0] coords2[...,2] = points['lat'][0] coords2[...,3] = points['lon'][0] coords2 = coords2.reshape((time_md.size,4)) U_interped=np.squeeze(interpolator_U(coords2)) V_interped=np.squeeze(interpolator_V(coords2)) TMP_interped=np.squeeze(interpolator_TMP(coords2)) U_interped_xr=coords_info_2D.copy() U_interped_xr['data'].values=U_interped.reshape(U_interped.size,1,1) V_interped_xr=coords_info_2D.copy() V_interped_xr['data'].values=V_interped.reshape(V_interped.size,1,1) TMP_interped_xr=coords_info_2D.copy() TMP_interped_xr['data'].values=TMP_interped.reshape(TMP_interped.size,1,1) sta_graphics.draw_point_fcst(t2m=TMP_interped_xr,u10m=U_interped_xr,v10m=V_interped_xr,rn=rn, model=model, output_dir=output_dir, points=points, extra_info=extra_info )
def Station_Synthetical_Forecast_From_Cassandra( model='ECMWF', output_dir=None, t_range=[0,84], t_gap=3, points={'lon':[116.3833], 'lat':[39.9]}, initTime=None, draw_VIS=True,drw_thr=False, extra_info={ 'output_head_name':' ', 'output_tail_name':' ', 'point_name':' '} ): #+get all the directories needed try: dir_rqd=[ "ECMWF_HR/10_METRE_WIND_GUST_IN_THE_LAST_3_HOURS/", "ECMWF_HR/10_METRE_WIND_GUST_IN_THE_LAST_6_HOURS/", "ECMWF_HR/TCDC/", "ECMWF_HR/LCDC/", "ECMWF_HR/UGRD_100M/", "ECMWF_HR/VGRD_100M/", "NWFD_SCMOC/VIS/", utl.Cassandra_dir( data_type='surface',data_source=model,var_name='RAIN03'), utl.Cassandra_dir( data_type='surface',data_source=model,var_name='RAIN06'), utl.Cassandra_dir( data_type='surface',data_source=model,var_name='T2m'), utl.Cassandra_dir( data_type='surface',data_source=model,var_name='u10m'), utl.Cassandra_dir( data_type='surface',data_source=model,var_name='v10m'), ] except KeyError: raise ValueError('Can not find all required directories needed') try: dir_opt=[ utl.Cassandra_dir( data_type='surface',data_source=model,var_name='Td2m') ] name_opt=['Td2m'] except: dir_opt=[ utl.Cassandra_dir(data_type='surface',data_source=model,var_name='rh2m') ] name_opt=['rh2m'] #+get all the directories needed if(initTime == None): last_file={model:get_latest_initTime(dir_rqd[0]), 'SCMOC':get_latest_initTime(dir_rqd[6]), } else: last_file={model:initTime[0], 'SCMOC':initTime[1], } y_s={model:int('20'+last_file[model][0:2]), 'SCMOC':int('20'+last_file['SCMOC'][0:2])} m_s={model:int(last_file[model][2:4]), 'SCMOC':int(last_file['SCMOC'][2:4])} d_s={model:int(last_file[model][4:6]), 'SCMOC':int(last_file['SCMOC'][4:6])} h_s={model:int(last_file[model][6:8]), 'SCMOC':int(last_file['SCMOC'][6:8])} fhours = np.arange(t_range[0], t_range[1], t_gap) for ifhour in fhours: if (ifhour == fhours[0] ): time_all=datetime(y_s['SCMOC'],m_s['SCMOC'],d_s['SCMOC'],h_s['SCMOC'])+timedelta(hours=int(ifhour)) else: time_all=np.append(time_all,datetime(y_s['SCMOC'],m_s['SCMOC'],d_s['SCMOC'],h_s['SCMOC'])+timedelta(hours=int(ifhour))) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] t2m=utl.get_model_points_gy(dir_rqd[9], filenames, points,allExists=False) if(name_opt[0] == 'rh2m'): rh2m=utl.get_model_points_gy(dir_opt[0], filenames, points,allExists=False) Td2m=mpcalc.dewpoint_rh(t2m['data'].values*units('degC'),rh2m['data'].values/100.) p_vapor=(rh2m['data'].values/100.)*6.105*(math.e**((17.27*t2m['data'].values/(237.7+t2m['data'].values)))) if(name_opt[0] == 'Td2m'): Td2m=utl.get_model_points_gy(dir_opt[0], filenames, points,allExists=False) rh2m=mpcalc.relative_humidity_from_dewpoint(t2m['data'].values* units('degC'), Td2m['data'].values* units('degC')) p_vapor=(np.array(rh2m))*6.105*(math.e**((17.27*t2m['data'].values/(237.7+t2m['data'].values)))) Td2m=np.array(Td2m['data'].values)* units('degC') u10m=utl.get_model_points_gy(dir_rqd[10], filenames, points,allExists=False) v10m=utl.get_model_points_gy(dir_rqd[11], filenames, points,allExists=False) wsp10m=(u10m['data']**2+v10m['data']**2)**0.5 AT=1.07*t2m['data'].values+0.2*p_vapor-0.65*wsp10m-2.7 if((t_range[1]) > 72): fhours = np.arange(6, t_range[1], 6) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] r03=utl.get_model_points_gy(dir_rqd[8], filenames, points,allExists=False) else: r03=utl.get_model_points_gy(dir_rqd[7], filenames, points,allExists=False) fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [last_file['SCMOC']+'.'+str(fhour).zfill(3) for fhour in fhours] VIS=utl.get_model_points_gy(dir_rqd[6], filenames, points,allExists=False,fill_null=True,Null_value=-0.001) if(last_file['SCMOC'] == last_file[model] and t_range[1] > 72): fhours = np.append(np.arange(3,72,3),np.arange(72, (t_range[1]), 6)) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] filenames2 = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] if(last_file['SCMOC'] != last_file[model] and t_range[1] > 60): fhours = np.append(np.arange(3,60,3),np.arange(60, (t_range[1]), 6)) filenames = [last_file[model]+'.'+str(fhour+12).zfill(3) for fhour in fhours] filenames2 = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] if(last_file['SCMOC'] != last_file[model] and t_range[1] <= 60): fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [last_file[model]+'.'+str(fhour+12).zfill(3) for fhour in fhours] filenames2 = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] if(last_file['SCMOC'] == last_file[model] and t_range[1] <= 72): fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] filenames2 = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] TCDC=utl.get_model_points_gy(dir_rqd[2], filenames2, points,allExists=False) LCDC=utl.get_model_points_gy(dir_rqd[3], filenames2, points,allExists=False) u100m=utl.get_model_points_gy(dir_rqd[4], filenames2, points,allExists=False) v100m=utl.get_model_points_gy(dir_rqd[5], filenames2, points,allExists=False) wsp100m=(u100m['data']**2+v100m['data']**2)**0.5 if(fhours[-1] < 120): gust10m=utl.get_model_points_gy(dir_rqd[0], filenames, points,allExists=False) if(fhours[-1] > 120): if(last_file['SCMOC'] == last_file[model]): fhours = np.arange(0, t_range[1], 6) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] if(last_file['SCMOC'] != last_file[model]): fhours = np.arange(0, t_range[1], 6) filenames = [last_file[model]+'.'+str(fhour+12).zfill(3) for fhour in fhours] gust10m=utl.get_model_points_gy(dir_rqd[1], filenames, points,allExists=False) sta_graphics.draw_Station_Synthetical_Forecast_From_Cassandra( t2m=t2m,Td2m=Td2m,AT=AT,u10m=u10m,v10m=v10m,u100m=u100m,v100m=v100m, gust10m=gust10m,wsp10m=wsp10m,wsp100m=wsp100m,r03=r03,TCDC=TCDC,LCDC=LCDC, draw_VIS=draw_VIS,VIS=VIS,drw_thr=drw_thr, time_all=time_all, model=model,points=points, output_dir=output_dir,extra_info=extra_info)
def Station_Snow_Synthetical_Forecast_From_Cassandra( model='ECMWF', output_dir=None, t_range=[0,84], t_gap=3, points={'lon':[116.3833], 'lat':[39.9]}, initTime=None, draw_VIS=True,drw_thr=False, extra_info={ 'output_head_name':' ', 'output_tail_name':' ', 'point_name':' '} ): #+get all the directories needed try: dir_rqd=[ "ECMWF_HR/10_METRE_WIND_GUST_IN_THE_LAST_3_HOURS/", "ECMWF_HR/10_METRE_WIND_GUST_IN_THE_LAST_6_HOURS/", "ECMWF_HR/SNOD/", "ECMWF_HR/SDEN/", "ECMWF_HR/UGRD_100M/", "ECMWF_HR/VGRD_100M/", "NWFD_SCMOC/VIS/", "NCEP_GFS_HR/SNOD/", "ECMWF_HR/SNOW06/", utl.Cassandra_dir( data_type='surface',data_source=model,var_name='T2m'), utl.Cassandra_dir( data_type='surface',data_source=model,var_name='u10m'), utl.Cassandra_dir( data_type='surface',data_source=model,var_name='v10m'), 'ECMWF_ENSEMBLE/RAW/SNOW06/' ] except KeyError: raise ValueError('Can not find all required directories needed') try: dir_opt=[ utl.Cassandra_dir( data_type='surface',data_source=model,var_name='Td2m') ] name_opt=['Td2m'] except: dir_opt=[ utl.Cassandra_dir(data_type='surface',data_source=model,var_name='rh2m') ] name_opt=['rh2m'] #+get all the directories needed if(initTime == None): last_file={model:get_latest_initTime(dir_rqd[0]), 'SCMOC':get_latest_initTime(dir_rqd[6]), } else: last_file={model:initTime[0], 'SCMOC':initTime[1], } y_s={model:int('20'+last_file[model][0:2]), 'SCMOC':int('20'+last_file['SCMOC'][0:2])} m_s={model:int(last_file[model][2:4]), 'SCMOC':int(last_file['SCMOC'][2:4])} d_s={model:int(last_file[model][4:6]), 'SCMOC':int(last_file['SCMOC'][4:6])} h_s={model:int(last_file[model][6:8]), 'SCMOC':int(last_file['SCMOC'][6:8])} fhours = np.arange(t_range[0], t_range[1], t_gap) for ifhour in fhours: if (ifhour == fhours[0] ): time_all=datetime(y_s['SCMOC'],m_s['SCMOC'],d_s['SCMOC'],h_s['SCMOC'])+timedelta(hours=int(ifhour)) else: time_all=np.append(time_all,datetime(y_s['SCMOC'],m_s['SCMOC'],d_s['SCMOC'],h_s['SCMOC'])+timedelta(hours=int(ifhour))) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] t2m=utl.get_model_points_gy(dir_rqd[9], filenames, points,allExists=False) if(name_opt[0] == 'rh2m'): rh2m=utl.get_model_points_gy(dir_opt[0], filenames, points,allExists=False) Td2m=mpcalc.dewpoint_rh(t2m['data'].values*units('degC'),rh2m['data'].values/100.) p_vapor=(rh2m['data'].values/100.)*6.105*(math.e**((17.27*t2m['data'].values/(237.7+t2m['data'].values)))) if(name_opt[0] == 'Td2m'): Td2m=utl.get_model_points_gy(dir_opt[0], filenames, points,allExists=False) rh2m=mpcalc.relative_humidity_from_dewpoint(t2m['data'].values* units('degC'), Td2m['data'].values* units('degC')) p_vapor=(np.array(rh2m))*6.105*(math.e**((17.27*t2m['data'].values/(237.7+t2m['data'].values)))) Td2m=np.array(Td2m['data'].values)* units('degC') #SN06_ensm=utl.get_model_points_gy(dir_rqd[12], filenames, points,allExists=False) ''' for i in range(0,len(SN06_ensm['forecast_period'])): SN06_std=np.std(np.squeeze(SN06_ensm['data'].values[i,:])) SN06_mean=np.mean(np.squeeze(SN06_ensm['data'].values[i,:])) if(i == 0): SN06_01=norm.pdf(0.01, SN06_mean, SN06_std) SN06_10=norm.pdf(0.1, SN06_mean, SN06_std) SN06_25=norm.pdf(0.25, SN06_mean, SN06_std) SN06_50=norm.pdf(0.5, SN06_mean, SN06_std) SN06_75=norm.pdf(0.75, SN06_mean, SN06_std) SN06_90=norm.pdf(0.9, SN06_mean, SN06_std) SN06_99=norm.pdf(0.99, SN06_mean, SN06_std) if(i > 0): SN06_01=[SN06_01,norm.pdf(0.01, SN06_mean, SN06_std)] SN06_10=[SN06_10,norm.pdf(0.1, SN06_mean, SN06_std)] SN06_25=[SN06_25,norm.pdf(0.25, SN06_mean, SN06_std)] SN06_50=[SN06_50,norm.pdf(0.5, SN06_mean, SN06_std)] SN06_75=[SN06_75,norm.pdf(0.75, SN06_mean, SN06_std)] SN06_90=[SN06_90,norm.pdf(0.9, SN06_mean, SN06_std)] SN06_99=[SN06_99,norm.pdf(0.99, SN06_mean, SN06_std)] SN06_ensm_stc={ 'SN06_01'=SN06_01 'SN06_10'=SN06_10 'SN06_25'=SN06_25 'SN06_50'=SN06_50 'SN06_75'=SN06_75 'SN06_90'=SN06_90 'SN06_99'=SN06_99 } ''' u10m=utl.get_model_points_gy(dir_rqd[10], filenames, points,allExists=False) v10m=utl.get_model_points_gy(dir_rqd[11], filenames, points,allExists=False) wsp10m=(u10m['data']**2+v10m['data']**2)**0.5 AT=1.07*t2m['data'].values+0.2*p_vapor-0.65*wsp10m-2.7 #https://en.wikipedia.org/wiki/Wind_chill TWC=13.12+0.6215*t2m['data'].values-11.37*(wsp10m**0.16)+0.3965*t2m['data'].values*(wsp10m**0.16) fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [last_file['SCMOC']+'.'+str(fhour).zfill(3) for fhour in fhours] VIS=utl.get_model_points_gy(dir_rqd[6], filenames, points,allExists=False,fill_null=True,Null_value=-0.001) if(last_file['SCMOC'] == last_file[model] and t_range[1] > 72): fhours = np.append(np.arange(3,72,3),np.arange(72, (t_range[1]), 6)) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] filenames2 = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] if(last_file['SCMOC'] != last_file[model] and t_range[1] > 60): fhours = np.append(np.arange(3,60,3),np.arange(60, (t_range[1]), 6)) filenames = [last_file[model]+'.'+str(fhour+12).zfill(3) for fhour in fhours] filenames2 = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] if(last_file['SCMOC'] != last_file[model] and t_range[1] <= 60): fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [last_file[model]+'.'+str(fhour+12).zfill(3) for fhour in fhours] filenames2 = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] if(last_file['SCMOC'] == last_file[model] and t_range[1] <= 72): fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] filenames2 = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] SNOD1=utl.get_model_points_gy(dir_rqd[2], filenames2, points,allExists=False) SNOD2=utl.get_model_points_gy(dir_rqd[7], filenames2, points,allExists=False) SDEN=utl.get_model_points_gy(dir_rqd[3], filenames2, points,allExists=False) SN06=utl.get_model_points_gy(dir_rqd[8], filenames2, points,allExists=False) u100m=utl.get_model_points_gy(dir_rqd[4], filenames2, points,allExists=False) v100m=utl.get_model_points_gy(dir_rqd[5], filenames2, points,allExists=False) wsp100m=(u100m['data']**2+v100m['data']**2)**0.5 if(fhours[-1] < 120): gust10m=utl.get_model_points_gy(dir_rqd[0], filenames, points,allExists=False) if(fhours[-1] > 120): if(last_file['SCMOC'] == last_file[model]): fhours = np.arange(0, t_range[1], 6) filenames = [last_file[model]+'.'+str(fhour).zfill(3) for fhour in fhours] if(last_file['SCMOC'] != last_file[model]): fhours = np.arange(0, t_range[1], 6) filenames = [last_file[model]+'.'+str(fhour+12).zfill(3) for fhour in fhours] gust10m=utl.get_model_points_gy(dir_rqd[1], filenames, points,allExists=False) sta_graphics.draw_Station_Snow_Synthetical_Forecast_From_Cassandra( TWC=TWC,AT=AT,u10m=u10m,v10m=v10m,u100m=u100m,v100m=v100m, gust10m=gust10m,wsp10m=wsp10m,wsp100m=wsp100m,SNOD1=SNOD1,SNOD2=SNOD2,SDEN=SDEN,SN06=SN06, draw_VIS=draw_VIS,VIS=VIS,drw_thr=drw_thr, time_all=time_all, model=model,points=points, output_dir=output_dir,extra_info=extra_info)
def point_uv_gust_tmp_rh_rn_fcst(output_dir=None, t_range=[0, 60], t_gap=3, points={ 'lon': [116.3833], 'lat': [39.9], 'altitude': [1351] }, initTime=None, day_back=0, extra_info={ 'output_head_name': ' ', 'output_tail_name': ' ', 'point_name': ' ' }, **kwargs): #+get all the directories needed try: dir_rqd = [ utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='T2m'), utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='u10m'), utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='v10m'), utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='rh2m'), utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='RAIN' + str(t_gap).zfill(2)), utl.Cassandra_dir(data_type='surface', data_source='OBS', var_name='PLOT_GUST') ] except KeyError: raise ValueError('Can not find all required directories needed') #-get all the directories needed if (initTime == None): initTime = MICAPS_IO.get_latest_initTime(dir_rqd[0]) #initTime=utl.filename_day_back_model(day_back=day_back,fhour=0)[0:8] gust_sta = MICAPS_IO.get_station_data(directory=dir_rqd[5], dropna=True, cache=False) datetime_sta = pd.to_datetime(str( gust_sta.time[0])).replace(tzinfo=None).to_pydatetime() datetime_model_initTime = datetime.strptime('20' + initTime, '%Y%m%d%H') u10_his_md = [] v10_his_md = [] wsp_his_sta_point = [] model_filenames_his = None for iinit in range(0, 240, 12): for ifhour in range(0, 87, 3): for iobs in range(0, 168, 1): initTime_his = datetime_model_initTime - timedelta(hours=iinit) validTime_his = initTime_his + timedelta(hours=ifhour) staTime_his = datetime_sta - timedelta(hours=iobs) if (staTime_his == validTime_his): model_filename_his = initTime_his.strftime( '%Y%m%d%H')[2:10] + '.' + str(ifhour).zfill(3) sta_filename_his = validTime_his.strftime( '%Y%m%d%H') + '0000.000' data_md1 = MICAPS_IO.get_model_grid( dir_rqd[1], filename=model_filename_his) if (data_md1 is None): continue data_md2 = MICAPS_IO.get_model_grid( dir_rqd[1], filename=model_filename_his) if (data_md2 is None): continue data_sta = MICAPS_IO.get_station_data( directory=dir_rqd[5], filename=sta_filename_his, dropna=True, cache=True) if (data_sta is None): continue u10_his_md.append(data_md1) v10_his_md.append(data_md2) wsp_his_sta_interp = utl.sta_to_point_interpolation( points=points, sta=data_sta, var_name='Gust_speed') wsp_his_sta_point.append(wsp_his_sta_interp[:]) u10_his_md = xr.concat(u10_his_md, dim='time') v10_his_md = xr.concat(v10_his_md, dim='time') wsp_his_md = (u10_his_md**2 + v10_his_md**2)**0.5 wsp_his_md_point = wsp_his_md.interp(lon=('points', points['lon']), lat=('points', points['lat'])) model = LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False) x = np.squeeze(wsp_his_md_point['data'].values).reshape(-1, 1) y = np.squeeze(wsp_his_sta_point).reshape(-1, 1) model.fit(x, y) if (model.coef_ < 0.2): f2 = np.polyfit(np.squeeze(x), np.squeeze(y), 2) model2 = np.poly1d(f2) fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [initTime + '.' + str(fhour).zfill(3) for fhour in fhours] t2m = utl.get_model_points_gy(dir_rqd[0], filenames, points, allExists=False) u10m = utl.get_model_points_gy(dir_rqd[1], filenames, points, allExists=False) v10m = utl.get_model_points_gy(dir_rqd[2], filenames, points, allExists=False) rh = utl.get_model_points_gy(dir_rqd[3], filenames, points, allExists=False) rn = utl.get_model_points_gy(dir_rqd[4], filenames, points, allExists=False) gust10m_predict = u10m.copy() if (model.coef_ > 0.2): gust10m_predict['data'].values = np.squeeze( model.predict( np.squeeze((u10m['data'].values**2 + v10m['data'].values**2)**0.5).reshape(-1, 1))).reshape( -1, 1, 1) else: gust10m_predict['data'].values = np.squeeze( model2( np.squeeze((u10m['data'].values**2 + v10m['data'].values**2)**0.5))).reshape(-1, 1, 1) sta_graphics.draw_point_uv_tmp_rh_rn_gust_fcst(t2m=t2m, u10m=u10m, v10m=v10m, rh=rh, rn=rn, gust=gust10m_predict, model='中央气象台中短期指导', output_dir=output_dir, points=points, extra_info=extra_info)
def point_uv_ecgust_tmp_rh_rn_fcst(output_dir=None, t_range=[0, 60], t_gap=3, points={ 'lon': [116.3833], 'lat': [39.9], 'altitude': [1351] }, initTime=None, day_back=0, extra_info={ 'output_head_name': ' ', 'output_tail_name': ' ', 'point_name': ' ' }, **kwargs): #+get all the directories needed try: dir_rqd = [ utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='T2m'), utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='u10m'), utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='v10m'), utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='rh2m'), utl.Cassandra_dir(data_type='surface', data_source='中央气象台中短期指导', var_name='RAIN' + str(t_gap).zfill(2)), utl.Cassandra_dir(data_type='surface', data_source='ECMWF', var_name='10M_GUST_3H') ] except KeyError: raise ValueError('Can not find all required directories needed') #-get all the directories needed if (initTime == None): initTime = MICAPS_IO.get_latest_initTime(dir_rqd[0]) initTime2 = MICAPS_IO.get_latest_initTime(dir_rqd[-1]) #initTime=utl.filename_day_back_model(day_back=day_back,fhour=0)[0:8] fhours = np.arange(t_range[0], t_range[1], t_gap) fhours2 = np.arange(t_range[0], t_range[1] + 12, t_gap) filenames = [initTime + '.' + str(fhour).zfill(3) for fhour in fhours] filenames2 = [initTime2 + '.' + str(fhour).zfill(3) for fhour in fhours2] t2m = utl.get_model_points_gy(dir_rqd[0], filenames, points, allExists=False) u10m = utl.get_model_points_gy(dir_rqd[1], filenames, points, allExists=False) v10m = utl.get_model_points_gy(dir_rqd[2], filenames, points, allExists=False) rh = utl.get_model_points_gy(dir_rqd[3], filenames, points, allExists=False) rn = utl.get_model_points_gy(dir_rqd[4], filenames, points, allExists=False) gust = utl.get_model_points_gy(dir_rqd[5], filenames2, points, allExists=False) sta_graphics.draw_point_uv_tmp_rh_rn_gust_fcst(t2m=t2m, u10m=u10m, v10m=v10m, rh=rh, rn=rn, gust=gust, model='中央气象台中短期指导', output_dir=output_dir, points=points, extra_info=extra_info)
def point_fcst_tmp_according_to_3D_field_box_line( output_dir=None, t_range=[0,60], t_gap=3, points={'lon':[116.3833], 'lat':[39.9], 'altitude':[1351]}, initTime=None,obs_ID=54511,day_back=0, extra_info={ 'output_head_name':' ', 'output_tail_name':' ', 'point_name':' ', 'drw_thr':True, 'levels_for_interp':[1000, 925, 850, 700, 500,300,200]} ): try: dir_rqd=[utl.Cassandra_dir(data_type='high',data_source='ECMWF_ENSEMBLE',var_name='HGT_RAW',lvl=''), utl.Cassandra_dir(data_type='high',data_source='ECMWF_ENSEMBLE',var_name='TMP_RAW',lvl='')] #utl.Cassandra_dir(data_type='surface',data_source=model,var_name='RAIN'+str(t_gap).zfill(2)+'_RAW')] except KeyError: raise ValueError('Can not find all required directories needed') #-get all the directories needed if(initTime == None): initTime = get_latest_initTime(dir_rqd[0][0:-1]+'/850') #initTime=utl.filename_day_back_model(day_back=day_back,fhour=0)[0:8] directory=dir_rqd[0][0:-1] if(t_range[1] > 72): fhours = np.append(np.arange(t_range[0], 72, t_gap),np.arange(72,t_range[1],6)) else: fhours = np.arange(t_range[0], t_range[1], t_gap) filenames = [initTime+'.'+str(fhour).zfill(3) for fhour in fhours] HGT_4D=get_model_3D_grids(directory=directory,filenames=filenames,levels=extra_info['levels_for_interp'], allExists=False) directory=dir_rqd[0][0:-1] directory=dir_rqd[1][0:-1] TMP_4D=get_model_3D_grids(directory=directory,filenames=filenames,levels=extra_info['levels_for_interp'], allExists=False) #rn=utl.get_model_points_gy(dir_rqd[4], filenames, points,allExists=False) directory=dir_rqd[1][0:-1] coords_info_2D=utl.get_model_points_gy(directory+str(extra_info['levels_for_interp'][0])+'/', points=points,filenames=filenames,allExists=False) delt_xy=HGT_4D['lon'].values[1]-HGT_4D['lon'].values[0] mask = (HGT_4D['lon']<(points['lon']+2*delt_xy))&(HGT_4D['lon']>(points['lon']-2*delt_xy))&(HGT_4D['lat']<(points['lat']+2*delt_xy))&(HGT_4D['lat']>(points['lat']-2*delt_xy)) HGT_4D_sm=HGT_4D['data'].where(mask,drop=True) TMP_4D_sm=TMP_4D['data'].where(mask,drop=True) lon_md=np.squeeze(HGT_4D_sm['lon'].values) lat_md=np.squeeze(HGT_4D_sm['lat'].values) alt_md=np.squeeze(HGT_4D_sm.values*10).flatten() time_md=np.squeeze(HGT_4D_sm['forecast_period'].values) number_md=np.squeeze(HGT_4D_sm['number'].values) ''' coords = np.zeros((len(time_md),len(number_md),len(extra_info['levels_for_interp']),len(lat_md),len(lon_md),5)) coords[...,0]=time_md.reshape((len(time_md),1,1,1,1)) coords[...,1]=number_md.reshape((1,len(number_md),1,1,1)) coords[...,3] = lat_md.reshape((1,1,1,len(lat_md),1)) coords[...,4] = lon_md.reshape((1,1,1,1,len(lon_md))) coords = coords.reshape((alt_md.size,5)) coords[:,2]=alt_md interpolator_TMP = LinearNDInterpolator(coords,TMP_4D_sm.values.reshape((TMP_4D_sm.values.size)),rescale=True) coords2 = np.zeros((len(time_md),len(number_md),1,1,1,5)) coords2[...,0]=time_md.reshape((len(time_md),1,1,1,1)) coords2[...,1]=number_md.reshape(1,(len(number_md),1,1,1)) coords2[...,2]=points['altitude'][0] coords2[...,3] = points['lat'][0] coords2[...,4] = points['lon'][0] coords2 = coords2.reshape((time_md.size,5)) TMP_interped=np.squeeze(interpolator_TMP(coords2)) ''' TMP_interped=np.zeros((len(time_md),len(number_md))) for it in range(0,len(time_md)): for inum in range(0,len(number_md)): alt_md=np.squeeze(HGT_4D_sm.values[it,inum,:,:,:]*10).flatten() coords = np.zeros((len(extra_info['levels_for_interp']),len(lat_md),len(lon_md),3)) coords[...,1] = lat_md.reshape((1,len(lat_md),1)) coords[...,2] = lon_md.reshape((1,1,len(lon_md))) coords = coords.reshape((alt_md.size,3)) coords[:,0]=alt_md interpolator_TMP = LinearNDInterpolator(coords,TMP_4D_sm.values[it,inum,:,:,:].reshape((TMP_4D_sm.values[it,inum,:,:,:].size)),rescale=True) coords2 = np.zeros((1,1,1,3)) coords2[...,0]=points['altitude'][0] coords2[...,1] = points['lat'][0] coords2[...,2] = points['lon'][0] coords2 = coords2.reshape((1,3)) TMP_interped[it,inum]=np.squeeze(interpolator_TMP(coords2)) TMP_interped_xr=coords_info_2D.copy() TMP_interped_xr['data'].values[:,:,0,0]=TMP_interped TMP_interped_xr.attrs['model']='ECMWF_ENSEMBLE' Ensemble_graphics.box_line_temp(TMP=TMP_interped_xr, points=points, extra_info=extra_info,output_dir=output_dir)