def calc_QOIs(df): """ Calculate derived quantities (IN PLACE) """ df['wspd'], df['wdir'] = calc_wind(df) df['u*'] = (df['uw']**2 + df['vw']**2)**0.25 df['TKE'] = 0.5 * (df['uu'] + df['vv'] + df['ww']) ang = np.arctan2(df['v'], df['u']) df['TI'] = df['uu'] * np.cos(ang)**2 + 2 * df['uv'] * np.sin(ang) * np.cos( ang) + df['vv'] * np.sin(ang)**2 df['TI'] = np.sqrt(df['TI']) / df['wspd']
def load_sowfa_data(dpath, times, heights, interval='1h', window_size='10min'): """ Load and process data of a particular SOWFA simulation Data loaded includes: - Planar averages - Virutal tower data - Source history data """ # Load planar average data # ------------------------ fpath = os.path.join(dpath, 'postProcessing/planarAverages') df_pavg = reader_planar_average(fpath) # Calculate 10-min averages and quantities of interest df_pavg_10min = df_pavg.unstack().resample('10min').mean().stack() calc_QOIs(df_pavg_10min) # Calculate hourly averages df_pavg_60min = df_pavg_10min.unstack().resample('60min').mean().stack() # Load virtual tower data # ----------------------- fpath = os.path.join(dpath, 'postProcessing/probe1') df_prob = reader_probe(fpath) df_prob['wspd'], df_prob['wdir'] = calc_wind(df_prob) # Calculate 10-min statistics and quantities of interest df_prob_10min = calc_stats(df_prob) calc_QOIs(df_prob_10min) # Calculate hourly averages df_prob_60min = df_prob_10min.unstack().resample('60min').mean().stack() # Calculate frequency spectrum df_prob_hgts = interpolate_to_heights(df_prob, heights) df_prob_hgts = reindex_if_needed(df_prob_hgts) df_prob_spectra = calc_spectra(df_prob_hgts, times, heights, interval, window_size) # Load source history data # ------------------------ fpath = os.path.join(dpath, 'postProcessing/sourceHistory') df_srch = reader_source_history(fpath) # Rescale budget components rescale_budget_components(df_srch) # Calculate 10-min and hourly averages df_srch_10min = df_srch.unstack().resample('10min').mean().stack() df_srch_60min = df_srch.unstack().resample('60min').mean().stack() return df_prob_10min, df_prob_60min, df_prob_spectra, df_pavg_10min, df_pavg_60min, df_srch, df_srch_10min, df_srch_60min
def load_tower_reference_spectra(fpath, times, heights, interval, window_size): """ Load TTU tower 1-Hz data and compute spectra """ # Load data tower = pd.read_csv(fpath, parse_dates=True, index_col=['datetime', 'height']) # Calculate some QoI tower['wspd'], tower['wdir'] = calc_wind(tower) tower['theta'] = theta(tower['Ts'], tower['p']) # Interpolate data to specified heights tower_hgt = interpolate_to_heights(tower, heights) # Reindex if needed tower_hgt = reindex_if_needed(tower_hgt) # Compute spectra tower_spectra = calc_spectra(tower_hgt, times, heights, interval, window_size) return tower_spectra
def load_wrf_reference_data(dpath): """ Load WRF reference data from SOWFA input files """ # Load wrf field data # ------------------ wrf_pavg_10min = load_sowfa_input_file(os.path.join(dpath, 'fieldTable')) # Drop value at z=0 wrf_pavg_10min = wrf_pavg_10min.loc[( slice(None), wrf_pavg_10min.index.get_level_values(1) > 0), :] # Calculate wind speed and direction wrf_pavg_10min['wspd'], wrf_pavg_10min['wdir'] = calc_wind(wrf_pavg_10min) # Calculate hourly averages wrf_pavg_60min = wrf_pavg_10min.unstack().resample('60min').mean().stack() return wrf_pavg_10min, wrf_pavg_60min
def load_wrf_reference_data(dpath): """ Load WRF reference data from SOWFA input files """ # Load wrf field data # ------------------ wrf_pavg_10min = load_sowfa_input_file(os.path.join(dpath, 'fieldTable')) # Drop value at z=0 wrf_pavg_10min = wrf_pavg_10min.loc[( slice(None), wrf_pavg_10min.index.get_level_values(1) > 0), :] # Calculate wind speed and direction wrf_pavg_10min['wspd'], wrf_pavg_10min['wdir'] = calc_wind(wrf_pavg_10min) # Calculate hourly averages wrf_pavg_60min = wrf_pavg_10min.unstack().resample('60min').mean().stack() # Load wrf forcing data # --------------------- wrf_srch_10min = load_sowfa_input_file(os.path.join(dpath, 'forcingTable')) # Drop value at z=0 wrf_srch_10min = wrf_srch_10min.loc[( slice(None), wrf_srch_10min.index.get_level_values(1) > 0), :] # Rename columns and rescale budget components wrf_srch_10min.rename({ 'u': 'Fu', 'v': 'Fv', 'w': 'Fw', 'theta': 'Ft' }, axis='columns', inplace=True) rescale_budget_components(wrf_srch_10min) # Calculate hourly averages wrf_srch_60min = wrf_srch_10min.unstack().resample('60min').mean().stack() return wrf_pavg_10min, wrf_pavg_60min, wrf_srch_10min, wrf_srch_60min
def load_wrf_reference_data(fpath): """ Load WRF reference data """ # Load data with xarray xa = xarray.open_dataset(fpath) # Convert to pandas dataframe wrf = xa.to_dataframe() # Convert to standard names wrf.rename({ 'U': 'u', 'V': 'v', 'W': 'w', 'UST': 'u*' }, axis='columns', inplace=True) # Compute wind speed and wind direction wrf['wspd'], wrf['wdir'] = calc_wind(wrf) return wrf
ny = len(wrfout.south_north) dx = wrfout.DX/1000.0 dy = wrfout.DY/1000.0 x = np.arange(0,nx)*dx y = np.arange(0,nx)*dy xy,yx = np.meshgrid(x,y) t2 = wrfout.T2.where(land_mask == 1.0) u10 = wrfout.U10.where(land_mask == 1.0) v10 = wrfout.V10.where(land_mask == 1.0) sfcP = wrfout.PSFC.where(land_mask == 1.0) temp = np.squeeze(wrfout.T) z_f = (np.squeeze(wrfout.PH) + np.squeeze(wrfout.PHB))/9.8 - np.squeeze(wrfout.HGT) zs_f = 0.5*(z_f[1:,:,:]+z_f[:-1,:,:]) vel10,dir10 = calc_wind(wrfout,u='U10',v='V10') vel10 = vel10.where(land_mask == 1.0) dir10 = dir10.where(land_mask == 1.0) top_ind = 18 bot_ind = 0 u = wrfout.U[top_ind,:,:].data v = wrfout.V[top_ind,:,:].data u = 0.5*(u[:,1:] + u[:,:-1]) v = 0.5*(v[1:,:] + v[:-1,:]) wdir1km = 180. + np.degrees(np.arctan2(u, v)) obs_dir = '/glade/u/home/hawbecke/Research/Chesapeake/Data/Obs/' awos_ds = xr.open_dataset('{}AWOS_2019to2020.nc'.format(obs_dir))