def get_data_from_dropsonde(file): # file = os.path.join(dropsonde_dir, 'D20150712_201424_PQC.nc') data = xr.open_dataset(file) with warnings.catch_warnings(): warnings.simplefilter("ignore", category=RuntimeWarning) index = data.GPSAlt.values < 4000 ret = {} ret['TIME']=utils.as_datetime(data.time_offset.values[index]) ret['GGLAT']=data.Lat.values[index] ret['GGLON']=data.Lon.values[index] ret['GGALT']=data.GPSAlt.values[index] ret['RHUM']=data.RH.values[index] ret['ATX']=data.Temp.values[index]+273.15 ret['PSX']=data.Press.values[index] ret['DPXC']= data.Dewpt.values[index]+273.15 ret['QV'] = mu.qv_from_p_T_RH(ret['PSX']*100, ret['ATX'], ret['RHUM'])*1000 ret['MR'] = ret['QV']/(1-ret['QV']/1000) ret['TVIR'] = mu.tvir_from_T_w(ret['ATX'], ret['MR']/1000) ret['DENS'] = mu.density_from_p_Tv(ret['PSX']*100, ret['TVIR']) ret['THETA']= mu.theta_from_p_T(ret['PSX'], ret['ATX']) ret['THETAE']= mu.thetae_from_t_tdew_mr_p(ret['ATX'], ret['DPXC'], ret['MR']/1000, ret['PSX']*100) #equiv pot temp, K we can get this if we really want ret['QL'] = np.full_like(ret['PSX'], fill_value=np.nan) ret['THETAL'] = np.full_like(ret['PSX'], fill_value=np.nan) ret['PLWCC']= np.full_like(ret['PSX'], fill_value=np.nan) return ret
def get_data_from_flight(flight_num, start=None, end=None, var_list=[]): flight_file = glob.glob(os.path.join(flight_dir, 'RF{:02d}*.nc'.format(flight_num)))[0] # data = xr.open_dataset(flight_file, decode_times=False) # data['time'] = nc.num2date(data.Time[:],units=data.Time.units) data = xr.open_dataset(flight_file, decode_times=True) dates = utils.as_datetime(data.Time.values) alt = data['GGALT'].values if start is None: start = dates[0] if end is None: end = dates[-1] with warnings.catch_warnings(): warnings.simplefilter("ignore", category=RuntimeWarning) index = np.logical_and(np.logical_and(dates >= start, dates <= end), alt < 3600) [(k, v.long_name) for k,v in data.data_vars.items() if 'Pres' in v.long_name] ret = {} ret['TIME'] = dates[index] for i in var_list: if i == 'ATX': ret[i] = data[i].values[index]+273.15 else: ret[i] = data[i].values[index] ret['DENS'] = mu.density_from_p_Tv(data['PSX'].values[index]*100, data['TVIR'].values[index]+273.15) ret['QL'] = data['PLWCC'].values[index]/ret['DENS'] ret['THETAL'] = mu.get_liquid_water_theta(ret['ATX'], ret['THETA'], ret['QL']) ret['QV'] = data['MR'].values[index]/(1+data['MR'].values[index]/1000) return ret
label, xy=(x, y), xytext=(-20, 20), textcoords='offset points', ha='right', va='bottom', bbox=dict(boxstyle='round,pad=0.5', alpha=0.5), arrowprops=dict(arrowstyle = '->', connectionstyle='arc3,rad=0')) # %% Main execution if __name__ == "__main__": path = r'/home/disk/eos4/jkcm/Data/CSET/LookupTable_all_flights.xls' flight = utils.read_CSET_Lookup_Table(path, rf_num='all', sequences=['d', 'k'], variables=['Date', 'ST', 'ET']) start_times = utils.as_datetime([utils.CSET_date_from_table(d, t) for d, t in zip(flight['Date']['values'], flight['ST']['values'])]) end_times = utils.as_datetime([utils.CSET_date_from_table(d, t) for d, t in zip(flight['Date']['values'], flight['ET']['values'])]) sounding_times = list(zip(flight['rf'], start_times, end_times)) # %% read in data # get flight info for each sounding var_list = ['GGLAT', 'GGLON', 'GGALT', 'RHUM', 'ATX', 'MR', 'THETAE', 'THETA', 'PSX', 'DPXC', 'PLWCC'] soundings = [] lt = LoopTimer(len(sounding_times)) for i in sounding_times: lt.update() soundings.append(get_data_from_flight(i[0], i[1], i[2], var_list)) add_dropsondes = True if add_dropsondes: