def try_caltra_ridge_rev(k=0): # Create a mapping from datetime objects to filenames basetime = datetime.datetime(2016, 9, 30, 12) basetime_str = basetime.strftime('%Y%m%d_%H') datadir = '/export/cloud/NCASweather/ben/nawdex/mi-ar482/{}/'.format( basetime_str) timestep = datetime.timedelta(hours=6) hoursafterinit = [42, 72, 96, 96] hoursuntil = [156, 156, 156, 156] times = [ basetime + timestep * i for i in range(hoursafterinit[k] / 6, hoursuntil[k] / 6 + 1) ] print times[0] #creates mapping from selected outflow time until selected end time mapping = {} for t in times: leadtimehr = np.int((t - basetime).total_seconds()) / 3600 fn = 'prodm_op_gl-mn_{0}_d{1:03d}_thgrid.pp'.\ format(basetime_str, 12 * (leadtimehr / 12)) mapping[t] = datadir + fn if k != 3: trainp_th = np.load( '/glusterfs/msc/users_2018/bn826011/NAWDEX/IOP67ridge/' + times[0].strftime("%m%d_%H") + '.npy') #trajectory input on theta levels else: trainp_th = np.load( '/glusterfs/msc/users_2018/bn826011/NAWDEX/IOP67ridge/' + times[0].strftime("%m%d_%H") + '_ridge2.npy') levels = ('air_potential_temperature', [trainp_th[0, 2] + 5 * i for i in range(3)]) # three isentropic levels including that of the first data point print levels tracers = [ 'altitude', 'x_wind', 'y_wind', 'upward_air_velocity', 'air_pressure' ] #need these for circulation integrals traout = caltra.caltra(trainp_th, mapping, fbflag=1, nsubs=12, tracers=tracers, levels=levels) # 12 steps between files = 30 mins apart traout.save( '/glusterfs/msc/users_2018/bn826011/NAWDEX/IOP67ridge/{}_TrajectoryEnsemble_forward' .format(basetime_str) + str(k + 1)) return traout
def inflow_caltra(k=0, levs=3, hoursafterinit=[42, 36, 42, 24], folder='IOP3/T42', strapp=''): # Create a mapping from datetime objects to filenames basetime = [ datetime.datetime(2016, 9, 22, 12), datetime.datetime(2016, 9, 26, 12), datetime.datetime(2016, 9, 30, 12), datetime.datetime(2016, 10, 03, 12) ] basetime_str = basetime[k].strftime('%Y%m%d_%H') #datadir = '/export/cloud/migrated-NCASweather/ben/nawdex/mi-ar482/{}/'.format(basetime_str) datadir = '/storage/silver/NCAS-Weather/ben/nawdex/mi-ar482/{}/'.format( basetime_str) timestep = datetime.timedelta(hours=6) times = [ basetime[k] + timestep * i for i in range(hoursafterinit[k] / 6 + 1) ] print times[-1] #creates mapping up to and including selected outflow time mapping = {} for t in times: leadtimehr = np.int((t - basetime[k]).total_seconds()) / 3600 fn = [datadir + 'prodm_op_gl-mn_{0}_d{1:03d}_thgrid.pp'.\ format(basetime_str, 12 * (leadtimehr / 12)), datadir + 'prodm_op_gl-mn_{0}_c{1:03d}.pp'.\ format(basetime_str, 6 * (leadtimehr / 6))] # new addition of c to mapping mapping[t] = fn #datadir + fn #trainp_th = np.load('/glusterfs/msc/users_2018/bn826011/NAWDEX/Final/' + folder + '/inflow/' + basetime_str + strapp + 'initial_grid.npy') trainp_th = np.load( '/storage/silver/scenario/bn826011/WCB_outflow/Final/' + folder + '/inflow/' + basetime_str + strapp + 'initial_grid.npy') #trajectory input on theta levels tracers = [ 'air_potential_temperature', 'air_pressure', 'derived_pv', 'dPV_tot', 'adv_only_PV', 'dPV_LW', 'dPV_mic', 'dPV_conv', 'dPV_adv', 'dPV_SW', 'dPV_ph1', 'dPV_bl', 'dPV_cld', 'dPV_mass' ] # 'specific_humidity', 'mass_fraction_of_cloud_ice_in_air', 'mass_fraction_of_cloud_liquid_water_in_air', 'derived_pv'] #need these for circulation integrals traout = caltra.caltra(trainp_th, mapping, fbflag=-1, nsubs=12, tracers=tracers) # 12 steps between files = 30 mins apart traout.save('/storage/silver/scenario/bn826011/WCB_outflow/Final/' + folder + '/inflow/{}_3DTrajectoryEnsemble_dPV'.format(basetime_str) + strapp) return traout
def backward_isentropic_trajectories_from_outflow(): """Calculate isentropic backward trajectories around boundary of the outflow """ traout = caltra.caltra(trainp, mapping, fbflag=-1, tracers=tracers, levels=('air_potential_temperature', [320])) return
def try_caltra_rev(k = 0, levs = 3, hoursafterinit = [42, 36, 42, 24], hoursuntil = [90, 78, 156, 84], filtersize = 30, folder = 'IOP3/contours_2019', strapp = '', theta_max = 315): # Create a mapping from datetime objects to filenames basetime = [datetime.datetime(2016, 9, 22, 12), datetime.datetime(2016, 9, 26, 12), datetime.datetime(2016, 9, 30, 12), datetime.datetime(2016, 10, 03, 12)] basetime_str = basetime[k].strftime('%Y%m%d_%H') datadir = '/export/cloud/migrated-NCASweather/ben/nawdex/mi-ar482/{}/'.format(basetime_str) timestep = datetime.timedelta(hours=6) #hoursafterinit = [42, 42, 42, 72, 96]#42 #hoursuntil = [78, 78, 78, 108] times = [basetime[k] + timestep * i for i in range(hoursafterinit[k]/6, hoursuntil[k]/6 + 1)] print times[0] #creates mapping from selected outflow time until selected end time print 7 mapping = {} for t in times: leadtimehr = np.int((t - basetime[k]).total_seconds()) / 3600 fn = 'prodm_op_gl-mn_{0}_d{1:03d}_thgrid.pp'.\ format(basetime_str, 12 * (leadtimehr / 12)) mapping[t] = datadir + fn #trainp_th = np.load('outflow/T42_mfs' + str(filtersize) + '/' + times[0].strftime("%m%d_%H") + '.npy') #trainp_th = np.load('/glusterfs/msc/users_2018/bn826011/NAWDEX/Final/' + folder + '/' + times[0].strftime("%m%d_%H") + strapp + '.npy') trainp_th = np.load('/storage/silver/scenario/bn826011/WCB_outflow/Final/' + folder + '/' + times[0].strftime("%m%d_%H") + strapp + '.npy') #trainp_th = np.load('/storage/silver/scenario/bn826011/WCB_outflow/Final/' + folder + 2) #trajectory input on theta levels if len(trainp_th[0]) >= 3: # the input file has already been given theta levels levels = ('air_potential_temperature', [trainp_th[0, 2] + 5*i for i in range(levs)]) # three isentropic levels including that of the first data point else: levels = ('air_potential_temperature', [theta_max - 5*i for i in range(levs)]) trainp_th_new = np.concatenate([trainp_th, np.transpose([theta_max*np.ones_like(trainp_th[:, 0])])], axis = 1) for i in range(1, levs): trainp_th_new = np.concatenate([trainp_th_new, np.concatenate([trainp_th, np.transpose([(theta_max - 5*i)*np.ones_like(trainp_th[:, 0])])], axis = 1)], axis = 0) trainp_th = trainp_th_new print levels tracers = ['altitude', 'x_wind', 'y_wind', 'upward_air_velocity', 'air_pressure'] #need these for circulation integrals traout = caltra.caltra(trainp_th, mapping, fbflag=1, nsubs = 12, tracers = tracers, levels=levels) # 12 steps between files = 30 mins apart #np.save('outflow/{}_trajectories.npy'.format(basetime_str), traout) #saving it as a numpy file removes functionality oof trajectory ensemble class, making it effectively useless, yay! #traout.save('outflow/T42_mfs' + str(filtersize) + '/{}_TrajectoryEnsemble_forward'.format(basetime_str)) #traout.save('/glusterfs/msc/users_2018/bn826011/NAWDEX/Final/' + folder + '/{}_TrajectoryEnsemble_forward'.format(basetime_str) + strapp) traout.save('/storage/silver/scenario/bn826011/WCB_outflow/Final/' + folder + '/{}_TrajectoryEnsemble_forward'.format(basetime_str) + strapp) return traout
def main(forecast, filename): # Get the input positions cubes = forecast.set_lead_time(hours=36) trainp = get_startpoints(cubes) # Calculate trajectories mapping = forecast._loader._files traout = caltra.caltra(trainp, mapping, fbflag=-1, tracers=tracers) # Save the trajectories traout.to_pickle(filename)
def try_caltra(k = 0, levs = 3, hoursafterinit = [42, 36, 42, 24], filtersize = 30, folder = 'IOP3/T42', strapp = ''): # Create a mapping from datetime objects to filenames basetime = [datetime.datetime(2016, 9, 22, 12), datetime.datetime(2016, 9, 26, 12), datetime.datetime(2016, 9, 30, 12), datetime.datetime(2016, 10, 03, 12)] basetime_str = basetime[k].strftime('%Y%m%d_%H') #datadir = '/export/cloud/migrated-NCASweather/ben/nawdex/mi-ar482/{}/'.format(basetime_str) datadir = '/storage/silver/NCAS-Weather/ben/nawdex/mi-ar482/{}/'.format(basetime_str) timestep = datetime.timedelta(hours=6) #hoursafterinit = [42, 42, 42, 72, 96]#42 times = [basetime[k] + timestep * i for i in range(hoursafterinit[k]/6 + 1)] print times[-1] #creates mapping up to and including selected outflow time mapping = {} for t in times: leadtimehr = np.int((t - basetime[k]).total_seconds()) / 3600 fn = [datadir + 'prodm_op_gl-mn_{0}_d{1:03d}_thgrid.pp'.\ format(basetime_str, 12 * (leadtimehr / 12)), datadir + 'prodm_op_gl-mn_{0}_c{1:03d}.pp'.\ format(basetime_str, 6 * (leadtimehr / 6))] # new addition of c to mapping mapping[t] = fn#datadir + fn #trainp_th = np.load('outflow/T42_mfs' + str(filtersize) + '/' + times[-1].strftime("%m%d_%H") + '.npy') #trainp_th = np.load('/glusterfs/msc/users_2018/bn826011/NAWDEX/Final/' + folder + '/' + times[-1].strftime("%m%d_%H") + strapp + '.npy') trainp_th = np.load('/storage/silver/scenario/bn826011/WCB_outflow/Final/' + folder + '/inflow/' + basetime_str + strapp + 'initial_grid_thlevs.npy') #trajectory input on theta levels levels = ('air_potential_temperature', [trainp_th[0, 2] + 5*i for i in range(levs)]) # three isentropic levels including that of the first data point #levels = ('air_potential_temperature', [325]) print levels tracers = ['altitude', 'x_wind', 'y_wind', 'upward_air_velocity', 'air_pressure', 'derived_pv', 'dPV_tot', 'adv_only_PV', 'dPV_LW', 'dPV_mic', 'dPV_conv', 'dPV_adv', 'dPV_SW', 'dPV_ph1', 'dPV_bl', 'dPV_cld', 'dPV_mass'] #need these for circulation integrals traout = caltra.caltra(trainp_th, mapping, fbflag=-1, nsubs = 12, tracers = tracers, levels=levels) # 12 steps between files = 30 mins apart #np.save('outflow/{}_trajectories.npy'.format(basetime_str), traout) #saving it as a numpy file removes functionality oof trajectory ensemble class, making it effectively useless, yay! #traout.save('outflow/T42_mfs' + str(filtersize) + '/{}_TrajectoryEnsemble_backward'.format(basetime_str)) #traout.save('/glusterfs/msc/users_2018/bn826011/NAWDEX/Final/' + folder + '/{}_TrajectoryEnsemble_backward'.format(basetime_str) + strapp) #traout.save('/storage/silver/scenario/bn826011/WCB_outflow/Final/' + folder + '/{}_TrajectoryEnsemble_backward'.format(basetime_str) + strapp) traout.save('/storage/silver/scenario/bn826011/WCB_outflow/Final/' + folder + '/inflow/{}_2DTrajectoryEnsemble_dPV'.format(basetime_str) + strapp) return traout
def forward_trajectories(forecast): """Calculate 48 hour forward trajectories from low levels Start trajectories from all points below 2km """ cubes = forecast.set_lead_time(hours=48) z = convert.calc('altitude', cubes) theta = convert.calc('air_potential_temperature', cubes) theta_adv = convert.calc('advection_only_theta', cubes) pv = convert.calc('ertel_potential_vorticity', cubes) lon, lat = grid.true_coords(pv) glon, glat = grid.get_xy_grids(pv) time = grid.get_datetime(pv) nz, ny, nx = pv.shape eqlats = rossby_waves.eqlats cs = iris.Constraint(time=time) with iris.FUTURE.context(cell_datetime_objects=True): eqlat = eqlats.extract(cs)[0] # Interpolate to the theta and PV surfaces eqlat = interpolate.main(eqlat, ertel_potential_vorticity=2) eqlat = interpolate.main(eqlat, potential_temperature=theta.data.flatten()) # Define the start points trainp = [] for k in range(nz): print(k) for j in range(ny): for i in range(nx): if (theta_adv.data[k, j, i] < 300 < theta.data[k, j, i] and pv.data[k, j, i] < 2 and lat[j, i] > eqlat.data[k * ny * nx + j * nx + i]): trainp.append([glon[j, i], glat[j, i], z.data[k, j, i]]) trainp = np.array(trainp) plot.pcolormesh(pv[33], vmin=0, vmax=10, cmap='cubehelix_r', pv=pv[33]) plt.scatter(trainp[:, 0], trainp[:, 1]) plt.show() # Calculate the trajectories tracers = ['air_potential_temperature', 'air_pressure'] traout = caltra.caltra(trainp, mapping, fbflag=-1, tracers=tracers) # Save the trajectories traout.save(datadir + 'backward_trajectories.pkl')