def test_bulk_shear_no_depth(): """Test bulk shear with observed sounding and no depth given. Issue #568.""" data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC') u, v = bulk_shear(data['pressure'], data['u_wind'], data['v_wind'], heights=data['height']) truth = [20.225018939, 22.602359692] * units('knots') assert_almost_equal(u.to('knots'), truth[0], 8) assert_almost_equal(v.to('knots'), truth[1], 8)
def test_bulk_shear_no_depth(): """Test bulk shear with observed sounding and no depth given. Issue #568.""" data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC') u, v = bulk_shear(data['pressure'], data['u_wind'], data['v_wind'], height=data['height']) truth = [20.225018939, 22.602359692] * units('knots') assert_almost_equal(u.to('knots'), truth[0], 8) assert_almost_equal(v.to('knots'), truth[1], 8)
def test_bulk_shear(): """Test bulk shear with observed sounding.""" data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC') u, v = bulk_shear(data['pressure'], data['u_wind'], data['v_wind'], heights=data['height'], depth=6000 * units('meter')) truth = [29.899581266946115, -14.389225800205509] * units('knots') assert_almost_equal(u.to('knots'), truth[0], 8) assert_almost_equal(v.to('knots'), truth[1], 8)
def test_bulk_shear(): """Test bulk shear with observed sounding.""" data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC') u, v = bulk_shear(data['pressure'], data['u_wind'], data['v_wind'], height=data['height'], depth=6000 * units('meter')) truth = [29.899581266946115, -14.389225800205509] * units('knots') assert_almost_equal(u.to('knots'), truth[0], 8) assert_almost_equal(v.to('knots'), truth[1], 8)
def test_bulk_shear_elevated(): """Test bulk shear with observed sounding and a base above the surface.""" data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC') u, v = bulk_shear(data['pressure'], data['u_wind'], data['v_wind'], heights=data['height'], bottom=data['height'][0] + 3000 * units('meter'), depth=3000 * units('meter')) truth = [0.9655943923302139, -3.8405428777944466] * units('m/s') assert_almost_equal(u, truth[0], 8) assert_almost_equal(v, truth[1], 8)
def test_bulk_shear_elevated(): """Test bulk shear with observed sounding and a base above the surface.""" data = get_upper_air_data(datetime(2016, 5, 22, 0), 'DDC') u, v = bulk_shear(data['pressure'], data['u_wind'], data['v_wind'], height=data['height'], bottom=data['height'][0] + 3000 * units('meter'), depth=3000 * units('meter')) truth = [0.9655943923302139, -3.8405428777944466] * units('m/s') assert_almost_equal(u, truth[0], 8) assert_almost_equal(v, truth[1], 8)
gamma_water = -((T - water_temperature) / z).to('degC/km') df[f'{int(p.magnitude)}_hPa_Γwater'] = [gamma_water.magnitude] # Calculate RH rh = mpcalc.relative_humidity_from_dewpoint(T, Td) df[f'{int(p.magnitude)}_hPa_RH'] = [rh.magnitude * 100] # Add u and v components df[f'{int(p.magnitude)}_hPa_u'] = [u.magnitude] df[f'{int(p.magnitude)}_hPa_v'] = [v.magnitude] # Derive bulk shear (except at first level) if p != p_data[0]: u_shear, v_shear = mpcalc.bulk_shear(p_data, u_data, v_data, bottom=p_data[0], depth=p_data[0] - p_data[i]) bulk_shear = mpcalc.wind_speed(u_shear, v_shear) df[f'{int(p_data[0].magnitude)}-{int(p.magnitude)}_hPa_shear'] = [ bulk_shear.magnitude ] # Append to main dataset dataset = dataset.append(df) # Load in model ai_model = joblib.load('../models/LES_Band_Position_Model_KNN(n=2)_LO1_LatLon') # Get predictions from machine learning model predictions = pd.DataFrame()
def bulk_shear(self, depth=6 * units.kilometer): return mpcalc.bulk_shear(self.p, self.u, self.v, self.z, depth=depth)
def process_skewt(self): # Calculation index_p100 = get_pressure_level_index(self.p_i, 100) lcl_p, lcl_t = mpcalc.lcl(self.p_i[0], self.t_i[0], self.td_i[0]) lfc_p, lfc_t = mpcalc.lfc(self.p_i, self.t_i, self.td_i) el_p, el_t = mpcalc.el(self.p_i, self.t_i, self.td_i) prof = mpcalc.parcel_profile(self.p_i, self.t_i[0], self.td_i[0]).to('degC') cape, cin = mpcalc.cape_cin(self.p_i, self.t_i, self.td_i, prof) mucape, mucin = mpcalc.most_unstable_cape_cin(self.p_i, self.t_i, self.td_i) pwat = mpcalc.precipitable_water(self.td_i, self.p_i) i8 = get_pressure_level_index(self.p_i, 850) i7 = get_pressure_level_index(self.p_i, 700) i5 = get_pressure_level_index(self.p_i, 500) theta850 = mpcalc.equivalent_potential_temperature(850 * units('hPa'), self.t_i[i8], self.td_i[i5]) theta500 = mpcalc.equivalent_potential_temperature(500 * units('hPa'), self.t_i[i5], self.td_i[i5]) thetadiff = theta850 - theta500 k = self.t_i[i8] - self.t_i[i5] + self.td_i[i8] - (self.t_i[i7] - self.td_i[i7]) a = ((self.t_i[i8] - self.t_i[i5]) - (self.t_i[i8] - self.td_i[i5]) - (self.t_i[i7] - self.td_i[i7]) - (self.t_i[i5] - self.td_i[i5])) sw = c_sweat(np.array(self.t_i[i8].magnitude), np.array(self.td_i[i8].magnitude), np.array(self.t_i[i5].magnitude), np.array(self.u_i[i8].magnitude), np.array(self.v_i[i8].magnitude), np.array(self.u_i[i5].magnitude), np.array(self.v_i[i5].magnitude)) si = showalter_index(self.t_i[i8], self.td_i[i8], self.t_i[i5]) li = lifted_index(self.t_i[0], self.td_i[0], self.p_i[0], self.t_i[i5]) srh_pos, srh_neg, srh_tot = mpcalc.storm_relative_helicity(self.u_i, self.v_i, self.alt, 1000 * units('m')) sbcape, sbcin = mpcalc.surface_based_cape_cin(self.p_i, self.t_i, self.td_i) shr6km = mpcalc.bulk_shear(self.p_i, self.u_i, self.v_i, heights=self.alt, depth=6000 * units('m')) wshr6km = mpcalc.wind_speed(*shr6km) sigtor = mpcalc.significant_tornado(sbcape, delta_height(self.p_i[0], lcl_p), srh_tot, wshr6km)[0] # Plotting self.ax.set_ylim(1050, 100) self.ax.set_xlim(-40, 50) self.plot(self.p_i, self.t_i, 'r', linewidth=1) self.plot(self.p_i[:self.dp_idx], self.td_i[:self.dp_idx], 'g', linewidth=1) self.plot_barbs(self.p_i[:index_p100], self.u_i[:index_p100] * 1.94, self.v_i[:index_p100] * 1.94) self.plot(lcl_p, lcl_t, 'ko', markerfacecolor='black') self.plot(self.p_i, prof, 'k', linewidth=2) if cin.magnitude < 0: chi = -1 * cin.magnitude self.shade_cin(self.p_i, self.t_i, prof) elif cin.magnitude > 0: chi = cin.magnitude self.shade_cin(self.p_i, self.t_i, prof) else: chi = 0. self.shade_cape(self.p_i, self.t_i, prof) self.plot_dry_adiabats(linewidth=0.5) self.plot_moist_adiabats(linewidth=0.5) self.plot_mixing_lines(linewidth=0.5) plt.title('Skew-T Plot \nStation: {} Time: {}'.format(self.st, self.time.strftime('%Y.%m.%d %H:%M')), fontsize=14, loc='left') # Add hodograph ax = self._fig.add_axes([0.95, 0.71, 0.17, 0.17]) h = Hodograph(ax, component_range=50) h.add_grid(increment=20) h.plot_colormapped(self.u_i[:index_p100], self.v_i[:index_p100], self.alt[:index_p100], linewidth=1.2) # Annotate parameters # Annotate names namelist = ['CAPE', 'CIN', 'MUCAPE', 'PWAT', 'K', 'A', 'SWEAT', 'LCL', 'LFC', 'EL', 'SI', 'LI', 'T850-500', 'θse850-500', 'SRH', 'STP'] xcor = -50 ycor = -90 spacing = -9 for nm in namelist: ax.text(xcor, ycor, '{}: '.format(nm), fontsize=10) ycor += spacing # Annotate values varlist = [cape, chi, mucape, pwat, k, a, sw, lcl_p, lfc_p, el_p, si, li, self.t_i[i8] - self.t_i[i5], thetadiff, srh_tot, sigtor] xcor = 10 ycor = -90 for v in varlist: if hasattr(v, 'magnitude'): v = v.magnitude ax.text(xcor, ycor, str(np.round_(v, 2)), fontsize=10) ycor += spacing # Annotate units unitlist = ['J/kg', 'J/kg', 'J/kg', 'mm', '°C', '°C', '', 'hPa', 'hPa', 'hPa', '°C', '°C', '°C', '°C'] xcor = 45 ycor = -90 for u in unitlist: ax.text(xcor, ycor, ' {}'.format(u), fontsize=10) ycor += spacing
skew.plot_barbs(p[ix], u[ix], v[ix]) skew.ax.set_ylim(1075, 100) skew.ax.set_ylabel('Pressure (hPa)') lcl_pressure, lcl_temperature = mpcalc.lcl(p[0], T[0], Td[0]) #LCL pwat = mpcalc.precipitable_water(Td, p, 500 * units.hectopascal).to('in') #PWAT cape, cin = mpcalc.most_unstable_cape_cin(p[:], T[:], Td[:]) #MUCAPE cape_sfc, cin_sfc = mpcalc.surface_based_cape_cin(p, T, Td) #SBCAPE prof = mpcalc.parcel_profile(p, T[0], Td[0]).to('degC') #parcel profile equiv_pot_temp = mpcalc.equivalent_potential_temperature(p, T, Td) #equivalent potential temperature el_pressure, el_temperature = mpcalc.el(p, T, Td) #elevated level lfc_pressure, lfc_temperature = mpcalc.lfc(p, T, Td) #LFC #calculates shear u_threekm_bulk_shear, v_threekm_bulk_shear = mpcalc.bulk_shear(p, u, v, hgt, bottom = min(hgt), depth = 3000 * units.meter) threekm_bulk_shear = mpcalc.get_wind_speed(u_threekm_bulk_shear, v_threekm_bulk_shear) u_onekm_bulk_shear, v_onekm_bulk_shear = mpcalc.bulk_shear(p, u, v, hgt, bottom = min(hgt), depth = 1000 * units.meter) onekm_bulk_shear = mpcalc.get_wind_speed(u_onekm_bulk_shear, v_onekm_bulk_shear) #shows the level of the LCL, LFC, and EL. skew.ax.text(T[0].magnitude, p[0].magnitude + 5, str(int(np.round(T[0].to('degF').magnitude))), fontsize = 'medium', horizontalalignment = 'left', verticalalignment = 'top', color = 'red') skew.ax.text(Td[0].magnitude, p[0].magnitude + 5, str(int(np.round(Td[0].to('degF').magnitude))), fontsize = 'medium', horizontalalignment = 'right', verticalalignment = 'top', color = 'green') skew.ax.text(lcl_temperature.magnitude + 5, lcl_pressure.magnitude, "---- LCL", fontsize = 'medium', verticalalignment = 'center') skew.ax.text(Td[0].magnitude - 10, p[0].magnitude, 'SFC: {}hPa ----'.format(p[0].magnitude), fontsize = 'medium', horizontalalignment = 'right', verticalalignment = 'center', color = 'black') if str(lfc_temperature.magnitude) != 'nan': #checks to see if LFC/EL exists. If not, skip. skew.ax.text(lfc_temperature.magnitude + 5, lfc_pressure.magnitude, "---- LFC", fontsize = 'medium', verticalalignment = 'center') skew.ax.text(el_temperature.magnitude + 5, el_pressure.magnitude, "---- EL", fontsize = 'medium', verticalalignment = 'center') skew.plot(p, prof, 'k-', linewidth=1) #plots parcel profile