Problem 3:
Contents
Problem 3:¶
ATM350 Homework 3, Spring 2023¶
In the directory /data1/nysm, there exists a file named latest.csv that consists of the past hour’s worth of NYS Mesonet data at intervals of five minutes. Create a q3.ipynb notebook that does the following (see below):
Imports¶
import pandas as pd
Part a:¶
Read the data into a Pandas Dataframe
df = pd.read_csv('/data1/nysm/latest.csv').set_index('time')
Examine the Dataframe
df
station | temp_2m [degC] | temp_9m [degC] | relative_humidity [percent] | precip_incremental [mm] | precip_local [mm] | precip_max_intensity [mm/min] | avg_wind_speed_prop [m/s] | max_wind_speed_prop [m/s] | wind_speed_stddev_prop [m/s] | ... | snow_depth [cm] | frozen_soil_05cm [bit] | frozen_soil_25cm [bit] | frozen_soil_50cm [bit] | soil_temp_05cm [degC] | soil_temp_25cm [degC] | soil_temp_50cm [degC] | soil_moisture_05cm [m^3/m^3] | soil_moisture_25cm [m^3/m^3] | soil_moisture_50cm [m^3/m^3] | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
time | |||||||||||||||||||||
2023-04-06 16:30:00 UTC | ADDI | 11.6 | 11.7 | 66.3 | 0.0 | 7.78 | 0.0 | 3.1 | 6.1 | 1.2 | ... | -2.0 | 0.0 | 0.0 | 0.0 | 9.6 | 7.7 | 6.2 | 0.58 | 0.44 | 0.44 |
2023-04-06 16:35:00 UTC | ADDI | 11.5 | 11.6 | 67.1 | 0.0 | 7.78 | 0.0 | 3.1 | 6.1 | 1.3 | ... | -2.0 | 0.0 | 0.0 | 0.0 | 9.7 | 7.7 | 6.2 | 0.58 | 0.44 | 0.44 |
2023-04-06 16:40:00 UTC | ADDI | 11.5 | 11.5 | 67.8 | 0.0 | 7.78 | 0.0 | 2.8 | 4.6 | 0.7 | ... | -2.0 | 0.0 | 0.0 | 0.0 | 9.6 | 7.7 | 6.2 | 0.58 | 0.44 | 0.44 |
2023-04-06 16:45:00 UTC | ADDI | 11.6 | 11.6 | 67.9 | 0.0 | 7.78 | 0.0 | 2.6 | 4.1 | 0.6 | ... | -1.0 | 0.0 | 0.0 | 0.0 | 9.7 | 7.7 | 6.2 | 0.58 | 0.44 | 0.44 |
2023-04-06 16:50:00 UTC | ADDI | 11.7 | 11.7 | 67.6 | 0.0 | 7.78 | 0.0 | 2.1 | 3.9 | 0.7 | ... | -2.0 | 0.0 | 0.0 | 0.0 | 9.7 | 7.7 | 6.2 | 0.58 | 0.44 | 0.44 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-04-06 17:10:00 UTC | YORK | 11.3 | 10.9 | 58.3 | 0.0 | 6.26 | 0.0 | 3.2 | 5.7 | 1.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 9.9 | 8.4 | 7.1 | 0.39 | 0.34 | 0.38 |
2023-04-06 17:15:00 UTC | YORK | 11.3 | 10.9 | 56.8 | 0.0 | 6.26 | 0.0 | 3.7 | 5.6 | 0.7 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 10.0 | 8.5 | 7.1 | 0.39 | 0.34 | 0.38 |
2023-04-06 17:20:00 UTC | YORK | 11.3 | 10.9 | 56.7 | 0.0 | 6.26 | 0.0 | 3.4 | 4.9 | 0.7 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 10.1 | 8.4 | 7.1 | 0.39 | 0.33 | 0.38 |
2023-04-06 17:25:00 UTC | YORK | 11.4 | 11.0 | 55.5 | 0.0 | 6.26 | 0.0 | 3.0 | 4.4 | 0.6 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 10.1 | 8.5 | 7.1 | 0.39 | 0.34 | 0.38 |
2023-04-06 17:30:00 UTC | YORK | 11.3 | 10.9 | 53.8 | 0.0 | 6.26 | 0.0 | 3.4 | 4.9 | 0.6 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 10.1 | 8.4 | 7.1 | 0.39 | 0.33 | 0.38 |
1638 rows × 29 columns
Part b:¶
Create objects corresponding to the following variables:
2m temperature, 9m temperature, relative humidity, five-minute accumulated precip (which is referenced as precip_incremental [mm]), daily accumulated precip (which is referenced as precip_local [mm]), and peak wind speed (max_wind_speed_prop [m/s]).
t2m = df['temp_2m [degC]']
t9m = df['temp_9m [degC]']
rh = df['relative_humidity [percent]']
prcp = df['precip_incremental [mm]']
pDay = df['precip_local [mm]']
pkwd = df['max_wind_speed_prop [m/s]']
Part c:¶
Convert temperatures to F, precip to inches, and wind speeds to knots (look up the conversions on the web).
t2m = t2m * 1.8 + 32
t9m = t9m * 1.8 + 32
prcp = prcp / 25.4
pDay = pDay / 25.4
pkwd = pkwd * 1.94384
Part d:¶
Print out the max, min, and mean values of the temperature, RH, and wind speed objects (e.g., ”the max temperature in the past hour for all NYS Mesonet sites was xx.x F and the min temperature was xx.x F”) and max values for the precip objects.
print(f"The maximum 2m temp in the past hour for all NYS Mesonet sites was {t2m.max():.1f}°F")
print(f"The minimum 2m temp in the past hour for all NYS Mesonet sites was {t2m.min():.1f}°F")
print(f"The mean 2m temp in the past hour for all NYS Mesonet sites was {t2m.mean():.1f}°F")
print ()
print(f"The maximum 9m temp in the past hour for all NYS Mesonet sites was {t9m.max():.1f}°F")
print(f"The minimum 9m temp in the past hour for all NYS Mesonet sites was {t9m.min():.1f}°F")
print(f"The mean 9m temp in the past hour for all NYS Mesonet sites was {t9m.mean():.1f}°F")
The maximum 2m temp in the past hour for all NYS Mesonet sites was 74.8°F
The minimum 2m temp in the past hour for all NYS Mesonet sites was 42.8°F
The mean 2m temp in the past hour for all NYS Mesonet sites was 55.3°F
The maximum 9m temp in the past hour for all NYS Mesonet sites was 73.8°F
The minimum 9m temp in the past hour for all NYS Mesonet sites was 41.9°F
The mean 9m temp in the past hour for all NYS Mesonet sites was 54.8°F
print(f"The maximum RH in the past hour for all NYS Mesonet sites was {rh.max():.1f}%")
print(f"The minimum RH in the past hour for all NYS Mesonet sites was {rh.min():.1f}%")
print(f"The mean RH in the past hour for all NYS Mesonet sites was {rh.mean():.1f}%")
The maximum RH in the past hour for all NYS Mesonet sites was 97.9%
The minimum RH in the past hour for all NYS Mesonet sites was 34.7%
The mean RH in the past hour for all NYS Mesonet sites was 67.4%
print(f"The maximum 5-minute precip in the past hour for all NYS Mesonet sites was {prcp.max():.2f} in.")
print ()
print(f"The maximum 24-hour precip in the past hour for all NYS Mesonet sites was {pDay.max():.2f} in.")
The maximum 5-minute precip in the past hour for all NYS Mesonet sites was 0.01 in.
The maximum 24-hour precip in the past hour for all NYS Mesonet sites was 1.57 in.
print(f"The maximum 5-minute peak wind speed for all NYS Mesonet sites was {pkwd.max():.1f} kts")
print(f"The minimum 5-minute peak wind speed for all NYS Mesonet sites was {pkwd.min():.1f} kts")
print(f"The mean 5-minute peak wind speed for all NYS Mesonet sites was {pkwd.mean():.1f} kts")
The maximum 5-minute peak wind speed for all NYS Mesonet sites was 27.4 kts
The minimum 5-minute peak wind speed for all NYS Mesonet sites was 1.6 kts
The mean 5-minute peak wind speed for all NYS Mesonet sites was 10.6 kts
Part e:¶
Output a dataframe that contains only those rows in the original dataframe that had non-zero snow depth.
sdpt = df['snow_depth [cm]']
sdpt = sdpt > 0.0 # Some sites, due to settling of the ground, may report negative values!
df[sdpt]
station | temp_2m [degC] | temp_9m [degC] | relative_humidity [percent] | precip_incremental [mm] | precip_local [mm] | precip_max_intensity [mm/min] | avg_wind_speed_prop [m/s] | max_wind_speed_prop [m/s] | wind_speed_stddev_prop [m/s] | ... | snow_depth [cm] | frozen_soil_05cm [bit] | frozen_soil_25cm [bit] | frozen_soil_50cm [bit] | soil_temp_05cm [degC] | soil_temp_25cm [degC] | soil_temp_50cm [degC] | soil_moisture_05cm [m^3/m^3] | soil_moisture_25cm [m^3/m^3] | soil_moisture_50cm [m^3/m^3] | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
time | |||||||||||||||||||||
2023-04-06 16:35:00 UTC | BATA | 9.7 | 9.2 | 61.8 | 0.0 | 6.50 | 0.0 | 7.1 | 10.1 | 1.3 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 9.6 | 7.7 | 6.3 | 0.34 | 0.28 | 0.29 |
2023-04-06 16:35:00 UTC | BEAC | 21.2 | 20.3 | 65.1 | 0.0 | 0.29 | 0.0 | 2.8 | 3.8 | 0.5 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 11.6 | 8.2 | 7.8 | 0.28 | 0.25 | 0.21 |
2023-04-06 16:40:00 UTC | BEAC | 21.4 | 20.4 | 64.5 | 0.0 | 0.29 | 0.0 | 3.1 | 5.0 | 0.7 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 11.7 | 8.2 | 7.8 | 0.28 | 0.25 | 0.21 |
2023-04-06 16:45:00 UTC | BEAC | 21.8 | 20.6 | 63.9 | 0.0 | 0.29 | 0.0 | 4.0 | 5.5 | 0.7 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 11.7 | 8.2 | 7.8 | 0.28 | 0.25 | 0.21 |
2023-04-06 16:50:00 UTC | BEAC | 22.1 | 20.8 | 62.6 | 0.0 | 0.29 | 0.0 | 3.7 | 5.2 | 0.7 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 11.9 | 8.2 | 7.8 | 0.28 | 0.25 | 0.21 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2023-04-06 16:45:00 UTC | WGAT | 6.5 | 8.6 | 68.4 | 0.0 | 5.19 | 0.0 | 0.7 | 1.3 | 0.3 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 0.1 | 0.2 | 0.6 | 0.21 | 0.30 | 0.12 |
2023-04-06 16:50:00 UTC | WGAT | 6.7 | 8.7 | 67.9 | 0.0 | 5.19 | 0.0 | 0.6 | 1.5 | 0.3 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 0.1 | 0.2 | 0.6 | 0.21 | 0.30 | 0.12 |
2023-04-06 16:55:00 UTC | WGAT | 7.0 | 8.6 | 67.4 | 0.0 | 5.19 | 0.0 | 0.8 | 2.3 | 0.5 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 0.1 | 0.2 | 0.6 | 0.21 | 0.30 | 0.13 |
2023-04-06 17:00:00 UTC | WGAT | 7.7 | 8.6 | 68.7 | 0.0 | 5.19 | 0.0 | 0.8 | 2.7 | 0.5 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 0.1 | 0.2 | 0.6 | 0.21 | 0.30 | 0.13 |
2023-04-06 17:30:00 UTC | WGAT | 7.1 | 7.8 | 67.7 | 0.0 | 5.19 | 0.0 | 0.6 | 1.5 | 0.4 | ... | 1.0 | 0.0 | 0.0 | 0.0 | 0.1 | 0.2 | 0.6 | 0.21 | 0.30 | 0.12 |
442 rows × 29 columns