Skip to content

Commit

Permalink
ADD: Adding new example for pulling together different data sources a…
Browse files Browse the repository at this point in the history
…round BNF
  • Loading branch information
AdamTheisen committed Nov 19, 2024
1 parent 4a64b91 commit 02ce965
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
3 changes: 1 addition & 2 deletions examples/discovery/plot_asos_temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import act

time_window = [datetime(2020, 2, 4, 2, 0), datetime(2020, 2, 10, 10, 0)]
station = 'KORD'
my_asoses = act.discovery.get_asos_data(time_window, station='ORD')
my_asoses = act.discovery.get_asos_data(time_window, station='ORD', regions='IL')

display = act.plotting.TimeSeriesDisplay(my_asoses['ORD'], subplot_shape=(2,), figsize=(15, 10))
display.plot('temp', subplot_index=(0,))
Expand Down
64 changes: 41 additions & 23 deletions examples/workflows/plot_amf3_comparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,58 @@
import numpy as np
import os

# Get Surface Meteorology data
# Get Surface Meteorology data from the ASOS stations
station = '1M4'
time_window = [datetime(2024, 10, 24), datetime(2024, 10, 31)]
time_window = [datetime(2024, 10, 19), datetime(2024, 10, 24)]
ds_asos = act.discovery.get_asos_data(time_window, station=station, regions='AL')[station]
ds_asos = ds_asos.where(~np.isnan(ds_asos.tmpf), drop=True)
ds_asos['tmpf'].attrs['units'] = 'degF'
ds_asos.utils.change_units(variables='tmpf', desired_unit='degC', verbose=True)

# Pull EPA data from AirNow
# You need an account and token from https://docs.airnowapi.org/ first
airnow_token = os.getenv('AIRNOW_API')
if airnow_token is not None and len(airnow_token) > 0:
latlon = '-87.453,34.179,-86.477,34.787'
ds_airnow = act.discovery.get_airnow_bounded_obs(
airnow_token, '2024-10-24T00', '2024-10-31T23', latlon, 'OZONE,PM25', data_type='B'
airnow_token, '2024-10-19T00', '2024-10-24T23', latlon, 'OZONE,PM25', data_type='B'
)
ds_airnow = act.utils.convert_2d_to_1d(ds_airnow, parse='sites')
sites = ds_airnow['sites'].values
airnow = True

# Get NOAA Data
# Get NOAA PSL Data from Courtland
results = act.discovery.download_noaa_psl_data(
site='ctd', instrument='Temp/RH', startdate='20241024', enddate='20241031'
site='ctd', instrument='Temp/RH', startdate='20241019', enddate='20241024'
)
ds_noaa = act.io.read_psl_surface_met(results)

# Place your username and token here
username = os.getenv('ARM_USERNAME')
token = os.getenv('ARM_PASSWORD')

# If the username and token are not set, use the existing sample file
# Download ARM data for the MET, OZONE, and SMPS
if username is not None and token is not None:
# Example to show how easy it is to download ARM data if a username/token are set
results = act.discovery.download_arm_data(
username, token, 'bnfmetM1.b1', '2024-10-24', '2024-10-31'
username, token, 'bnfmetM1.b1', '2024-10-19', '2024-10-24'
)
ds_arm = act.io.arm.read_arm_netcdf(results)

# results = act.discovery.download_arm_data(
# username, token, 'bnfaoso3M1.b1', '2024-10-24', '2024-10-31'
# )
# ds_o3 = act.io.arm.read_arm_netcdf(results)
results = act.discovery.download_arm_data(
username, token, 'bnfaoso3M1.b1', '2024-10-19', '2024-10-24'
)
ds_o3 = act.io.arm.read_arm_netcdf(results, cleanup_qc=True)
ds_o3.qcfilter.datafilter('o3', rm_assessments=['Suspect', 'Bad'], del_qc_var=False)

results = act.discovery.download_arm_data(
username, token, 'bnfaossmpsM1.b1', '2024-10-24', '2024-10-31'
username, token, 'bnfaossmpsM1.b1', '2024-10-19', '2024-10-24'
)
ds_smps = act.io.arm.read_arm_netcdf(results)

# Set up display and plot all the data
display = act.plotting.TimeSeriesDisplay(
{'ASOS': ds_asos, 'ARM': ds_arm, 'EPA': ds_airnow, 'NOAA': ds_noaa},
{'ASOS': ds_asos, 'ARM': ds_arm, 'EPA': ds_airnow, 'NOAA': ds_noaa, 'ARM_O3': ds_o3},
figsize=(12, 10),
subplot_shape=(3,),
)
Expand All @@ -71,21 +75,35 @@
display.day_night_background(dsname='ARM', subplot_index=(0,))

title = 'Comparison of ARM and EPA Ozone Measurements'
display.plot('OZONE_sites_0', dsname='EPA', label='EPA ' + sites[0], subplot_index=(1,))
display.plot('OZONE_sites_1', dsname='EPA', label='EPA2' + sites[1], subplot_index=(1,))
display.plot(
'OZONE_sites_2', dsname='EPA', label='EPA3' + sites[2], subplot_index=(1,), set_title=title
)
display.plot('o3', dsname='ARM_O3', label='ARM', subplot_index=(1,))
if airnow:
display.plot('OZONE_sites_0', dsname='EPA', label='EPA ' + sites[0], subplot_index=(1,))
display.plot('OZONE_sites_1', dsname='EPA', label='EPA' + sites[1], subplot_index=(1,))
display.plot(
'OZONE_sites_2',
dsname='EPA',
label='EPA' + sites[2],
subplot_index=(1,),
set_title=title,
)
display.set_yrng([0, 60], subplot_index=(1,))
display.day_night_background(dsname='ARM', subplot_index=(1,))

title = 'ARM SMPS Concentrations and EPA PM2.5'
display.plot('PM2.5_sites_0', dsname='EPA', label='EPA ' + sites[0], subplot_index=(2,))
display.plot('PM2.5_sites_1', dsname='EPA', label='EPA ' + sites[1], subplot_index=(2,))
display.plot(
'PM2.5_sites_2', dsname='EPA', label='EPA ' + sites[2], subplot_index=(2,), set_title=title
)
if airnow:
display.plot('PM2.5_sites_0', dsname='EPA', label='EPA ' + sites[0], subplot_index=(2,))
display.plot('PM2.5_sites_1', dsname='EPA', label='EPA ' + sites[1], subplot_index=(2,))
display.plot(
'PM2.5_sites_2',
dsname='EPA',
label='EPA ' + sites[2],
subplot_index=(2,),
set_title=title,
)
display.set_yrng([0, 25], subplot_index=(2,))
ax2 = display.axes[2].twinx()
ax2.plot(ds_smps['time'], ds_smps['total_N_conc'], label='ARM SMPS', color='purple')
ax2.set_ylabel('ARM SMPS (' + ds_smps['total_N_conc'].attrs['units'] + ')')
display.day_night_background(dsname='ARM', subplot_index=(2,))
plt.legend()
plt.show()
2 changes: 1 addition & 1 deletion tests/discovery/test_asos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def test_get_ord():
time_window = [datetime(2020, 2, 4, 2, 0), datetime(2020, 2, 12, 10, 0)]
my_asoses = act.discovery.get_asos_data(time_window, station='ORD')
my_asoses = act.discovery.get_asos_data(time_window, station='ORD', regions='IL')
assert 'ORD' in my_asoses.keys()
assert np.all(
np.equal(
Expand Down

0 comments on commit 02ce965

Please sign in to comment.