def read_icnctraj_sub(set_name, time_pt, clams, time0, timef): basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/' if clams == True: start_str = 'cirrus_tst' end_str = '_trim_extract_clams.nc' rho = [] icnc = [] t = [] rhi = [] for file_id in np.arange(1, 27): filename = start_str + general_prefix( time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str traj = xr.open_dataset(basedir + filename) vals = traj['RHO'].sel(time=slice(time0, timef)).values.flatten() rho.extend(vals) vals = (traj['ICN_hom'] + traj['ICN_het'] + traj['ICN_pre']).sel( time=slice(time0, timef)).values.flatten() icnc.extend(vals) vals = traj['T'].sel(time=slice(time0, timef)).values.flatten() t.extend(vals) vals = traj['RHI'].sel(time=slice(time0, timef)).values.flatten() rhi.extend(vals) else: start_str = 'traj_tst' end_str = '_trim_extract_dt.nc' rho = [] icnc = [] t = [] rhi = [] for file_id in np.arange(1, 27): filename = start_str + general_prefix( time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str traj = xr.open_dataset(basedir + filename) vals = traj['rho'].sel(time=slice(time0, timef)).values.flatten() rho.extend(vals) vals = traj['qni'].sel(time=slice(time0, timef)).values.flatten() icnc.extend(vals) vals = traj['t'].sel(time=slice(time0, timef)).values.flatten() t.extend(vals) p = traj['p'].sel(time=slice(time0, timef)).values.flatten() qv = traj['qv'].sel(time=slice(time0, timef)).values.flatten() vals = calc_RHi(vals, p, qv) rhi.extend(vals) rho = np.array(rho) icnc = np.array(icnc) t = np.array(t) rhi = np.array(rhi) # Filter out instances where the ICNC value is not 0 or nan icnc, t, rhi = filter_icnc_temp(icnc, rho, t, rhi) print(icnc.shape, t.shape, rhi.shape) print(np.nanmin(np.log10(icnc)), np.nanmean(np.log10(icnc)), np.nanmax(np.log10(icnc))) print(np.nanmin(rhi), np.nanmean(rhi), np.nanmax(rhi)) return t, rhi, icnc
def read_qseditraj(set_name, time_pt, clams): basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/' if clams == True: start_str = 'cirrus_tst' end_str = '_trim_extract_clams.nc' qsedi = [] qsedo = [] t = [] rhi = [] for file_id in np.arange(1, 27): filename = start_str + general_prefix( time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str traj = xr.open_dataset(basedir + filename) vals = 10**6 * traj['qsedi'].values.flatten() qsedi.extend(vals) vals = 10**7 * traj['qsedo'].values.flatten() qsedo.extend(vals) vals = traj['T'].values.flatten() t.extend(vals) vals = traj['RHI'].values.flatten() rhi.extend(vals) else: start_str = 'traj_tst' end_str = '_trim_extract.nc' qsedi = [] qsedo = [] t = [] rhi = [] for file_id in np.arange(1, 27): filename = start_str + general_prefix( time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str traj = xr.open_dataset(basedir + filename) vals = 10**6 * traj['qsedi'].values.flatten() qsedi.extend(vals) vals = 10**6 * traj['qsedo'].values.flatten() qsedo.extend(vals) vals = traj['t'].values.flatten() t.extend(vals) p = traj['p'].values.flatten() qv = traj['qv'].values.flatten() vals = calc_RHi(vals, p, qv) rhi.extend(vals) qsedi = np.array(iwc) t = np.array(t) rhi = np.array(rhi) # Filter out instances where the IWC value is not 0 or nan iwc, t, rhi = filter_iwc_temp(iwc, t, rhi) print(qsedi.shape, t.shape, rhi.shape) print(np.nanmin(np.log10(qsedi)), np.nanmean(np.log10(qsedi)), np.nanmax(np.log10(qsedi))) print(np.nanmin(rhi), np.nanmean(rhi), np.nanmax(rhi)) return t, rhi, qsedi
def read_icnctraj_all(set_name, time_pt): basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/' start_str = 'traj_tst' end_str = '.nc' rho = [] icnc = [] t = [] rhi = [] for file_id in np.arange(1, 6): filename = start_str + general_prefix( time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str traj = xr.open_dataset(basedir + filename) vals = traj['rho'].values.flatten() rho.extend(vals) vals = traj['qni'].values.flatten() icnc.extend(vals) vals = traj['t'].values.flatten() t.extend(vals) p = traj['p'].values.flatten() qv = traj['qv'].values.flatten() vals = calc_RHi(vals, p, qv) rhi.extend(vals) rho = np.array(rho) icnc = np.array(icnc) t = np.array(t) rhi = np.array(rhi) # Filter out instances where the ICNC value is not 0 or nan icnc, t, rhi = filter_icnc_temp(icnc, rho, t, rhi) print(icnc.shape, t.shape, rhi.shape) print(np.nanmin(np.log10(icnc)), np.nanmean(np.log10(icnc)), np.nanmax(np.log10(icnc))) print(np.nanmin(rhi), np.nanmean(rhi), np.nanmax(rhi)) return t, rhi, icnc
def read_iwctraj_all(set_name, time_pt, outflow): basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/' start_str = 'traj_tst' end_str = '.nc' iwc = [] t = [] rhi = [] for file_id in np.arange(1, 6): filename = start_str + general_prefix( time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str traj = xr.open_dataset(basedir + filename) vals = 10**6 * traj['qi'].values.flatten() iwc.extend(vals) vals = traj['t'].values.flatten() t.extend(vals) p = traj['p'].values.flatten() qv = traj['qv'].values.flatten() vals = calc_RHi(vals, p, qv) rhi.extend(vals) iwc = np.array(iwc) t = np.array(t) rhi = np.array(rhi) # Filter out instances where the IWC value is not 0 or nan if outflow == True: iwc, t, rhi = filter_iwc_temp_outflow(iwc, t, rhi) else: iwc, t, rhi = filter_iwc_temp_insitu(iwc, t, rhi) print(iwc.shape, t.shape, rhi.shape) print(np.nanmin(np.log10(iwc)), np.nanmean(np.log10(iwc)), np.nanmax(np.log10(iwc))) print(np.nanmin(rhi), np.nanmean(rhi), np.nanmax(rhi)) return t, rhi, iwc
def time_to_datetime(set_name, time_pt, clams): basedir = '/work/bb1018/b380873/traj_output/' + set_name + '/' start_str = 'traj_tst' end_str = '_trim_extract.nc' base_time = datetime(2017, 8, 6, 0, 0) traj = xr.open_dataset(basedir + start_str + general_prefix(time_pt, 8) + '_p001' + end_str) traj_times = traj['rtime'] real_times = np.array( [base_time + timedelta(seconds=int(t.values)) for t in traj_times]) for file_id in np.arange(1, 31): print(file_id) traj = xr.open_dataset(basedir + start_str + general_prefix(time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + end_str) traj['time'] = real_times traj.to_netcdf(basedir + start_str + general_prefix(time_pt, 8) + '_p' + traj_prefix(file_id) + str(file_id) + '_trim_extract_dt.nc')
# We have <file_num> files and 3826 frequencies. I don't know where the latter number comes from. PSD_ff_mean = np.zeros((file_num, 3826)) PSD_Pxx_mean = np.zeros((file_num, 3826)) if PSDcalc == True: PSD_ff = [[] for i in np.arange(file_num)] PSD_Pxx = [[] for i in np.arange(file_num)] for j in np.arange(1, file_num + 1): print(j) # Read in the temperature from the trajectory file above. # Its dimension will be [time steps, trajectory id]. #traj_file = basedir + 'traj_tst00000450_p' + file_prefix(j) + str(j) + '_trim.nc' #traj_T_series = xr.open_dataset(traj_file).t.values #traj_Tfluc_series = traj_T_series.T - np.nanmean(traj_T_series,axis=1) #traj_w_series = xr.open_dataset(traj_file).w_v.values traj_file = basedir + 'cirrus_tst00000450_p' + traj_prefix(j) + str( j) + '_trim_clams.nc' #traj_T_series = xr.open_dataset(traj_file)['T'].values traj_w_series = xr.open_dataset(traj_file)['w_v'].values # Store the PSDs for multiple temperature time series. freqs = int(traj_T_series.shape[0] / 2 + 1) traj_id = traj_T_series.shape[1] #all_PSD = np.zeros((2,traj_id,freqs)) # Iterate over the trajectories and save their PSDs. for i in np.arange(traj_id): # Generate an instance of Class traj_psd with temp = input temperature time series. #traj_obj = traj_psd(temp=traj_T_series[:7651,i]) # Generate an instance of Class_traj_psd with temp = input vertical velocity series.