Attached is some sample R code for accessing the 2017 EQUATES CMAQ daily average output netcdf file located in this Google Drive folder. The script shows how to:
- open the netcdf file
- extract the variable names and units, as well as the date and model grid information
- read in the daily average PM2.5 data and calculate the annual mean PM2.5 for each grid cell
- plot the annual average PM2. 5 data on a map
sample_Rcode_for_EQUATES_CMAQ_data.txt (5.0 KB)
5 Likes
Here’s the same excellent example adapted to use the terra package instead of the rgdal and raster packages, and eliminating the M3 package which seems to have gone away.
sample_Rcode_for_EQUATES_CMAQ_data_revised_v2.txt (9.4 KB)
(revised to use the same sample NetCDF file as the original)
(revised again to fix a problem with the leaflet image)
5 Likes
Wow, this is fantastic @DaveDixon. Thank you so much for sharing!! 
2 Likes
Prof. Jenise Swall just updated the M3 package (14-Jun-2024) so I’ve updated the example to restore the M3 methods, which greatly simplify the code. I’ve also documented what changed with the leaflet example at the end.
sample_Rcode_for_EQUATES_CMAQ_data_rev1_v2.txt (5.9 KB)
1 Like