def test_altimeter_to_sea_level_pressure_hpa(): """Test the altimeter to sea level pressure function with hectopascals.""" altim = 1013 * units.hectopascal elev = 500 * units.m temp = 0 * units.degC res = altimeter_to_sea_level_pressure(altim, elev, temp) truth = 1016.246 * units.hectopascal assert_almost_equal(res, truth, 3)
def test_altimiter_to_sea_level_pressure_inhg(): """Test the altimeter to sea level pressure function with inches of mercury.""" altim = 29.8 * units.inHg elev = 500 * units.m temp = 30 * units.degC res = altimeter_to_sea_level_pressure(altim, elev, temp) truth = 1006.089 * units.hectopascal assert_almost_equal(res, truth, 3)
def test_altimeter_to_sea_level_pressure_hpa(array_type): """Test the altimeter to sea level pressure function with hectopascals.""" mask = [False, True, False, True] altim = array_type([1000., 1005., 1010., 1013], 'hectopascal', mask=mask) elev = array_type([2000., 1500., 1000., 500.], 'meter', mask=mask) temp = array_type([-3., -2., -1., 0.], 'degC') res = altimeter_to_sea_level_pressure(altim, elev, temp) truth = array_type([1009.963556, 1013.119712, 1015.885392, 1016.245615], 'hectopascal', mask=mask) assert_array_almost_equal(res, truth, 3)
def download_alldata(startts=datetime.datetime(2012, 8, 1), endts=datetime.datetime(2012, 9, 1)): """An alternative method that fetches all available data. Service supports up to 24 hours worth of data at a time.""" # timestamps in UTC to request data for #startts = datetime.datetime(2012, 8, 1) #endts = datetime.datetime(2012, 9, 1) interval = datetime.timedelta(hours=24) service = SERVICE + "data=all&tz=Etc/UTC&format=comma&latlon=yes&elev=yes&trace=0.0001&" now = startts while now < endts: thisurl = service thisurl += now.strftime("year1=%Y&month1=%m&day1=%d&") thisurl += (now + interval).strftime("year2=%Y&month2=%m&day2=%d&") print("Downloading: %s" % (now, )) data = download_data(thisurl) df = pd.read_csv(data, skiprows=5, header=0, parse_dates=['valid'], na_values=['M'], low_memory=False) # Convert wx codes to numeric values for plotting purposes df['present_weather'] = wx_code_to_numeric(df['wxcodes'].fillna('')) # Convert cloud cover strings to numeric values for plotting purposes df['cloud_cover'] = df.skyc1.fillna('').apply(get_cloud_cover) # Compute the u (eastward_wind) and v(northward_wind) components df['eastward_wind'], df['northward_wind'] = mpcalc.wind_components( df.sknt.values * units.knots, df.drct.values * units.degree) # Compute the MSLP from the Altimeter reading using MetPy calculation df['air_pressure_at_sea_level'] = mpcalc.altimeter_to_sea_level_pressure( df.alti.values * units.inHg, df.elevation.values * units.meters, df.tmpf.values * units.degF).to('hPa') # Save CSV version of archive and new variables df.to_csv(f'surface_data_{now:%Y%m%d}.csv', index=False) #outfn = "surface_data_%s.txt" % (now.strftime("%Y%m%d"),) #with open(outfn, "w") as fh: # fh.write(data) now += interval