rmweather
An R package to conduct meteorological/weather normalisation on air quality so trends and interventions can be investigated in a robust way.
https://github.com/skgrange/rmweather
Category: Natural Resources
Sub Category: Air Quality
Last synced: about 23 hours ago
JSON representation
Repository metadata
Tools to Conduct Meteorological Normalisation on Air Quality Data
- Host: GitHub
- URL: https://github.com/skgrange/rmweather
- Owner: skgrange
- License: gpl-3.0
- Created: 2018-03-19T08:21:40.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-02-20T23:39:33.000Z (2 months ago)
- Last Synced: 2025-04-10T05:04:49.160Z (17 days ago)
- Language: R
- Homepage:
- Size: 1.78 MB
- Stars: 50
- Watchers: 4
- Forks: 8
- Open Issues: 0
- Releases: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
README.md
rmweather
Introduction
rmweather is an R package to conduct meteorological/weather normalisation on air quality so trends and interventions can be investigated in a robust way. For those who are aware of my previous research, rmweather is the "Mk.II" package of normalweatherr. rmweather does less than normalweatherr, but it is faster and easier to use.
Installation
rmweather is available from CRAN and can be installed in the normal way:
# Install rmweather from CRAN
install.packages("rmweather")
Development version
To install the development version of rmweather, the remotes package will need to be installed first. Then:
# Load helper package
library(remotes)
# Install rmweather
install_github("skgrange/rmweather")
Example usage
rmweather contains example data from London which can be used to show the meteorological normalisation procedure. The example data are daily means of NO2 and NOx observations at London Marylebone Road. The accompanying surface meteorological data are from London Heathrow, a major airport located 23 km west of Central London.
Most of rmweather's functions begin with rmw_
so are easy to track and find help for. In this example, we have used dplyr and the pipe (%>%
and pronounced as "then") for clarity. The example takes about 30 seconds on my (laptop) system and the model has an R2 value of 76 %.
# Load packages
library(dplyr)
library(rmweather)
library(ranger)
# Have a look at rmweather's example data, from london
head(data_london)
# Prepare data for modelling
# Only use data with valid wind speeds, no2 will become the dependent variable
data_london_prepared <- data_london %>%
filter(variable == "no2",
!is.na(ws)) %>%
rmw_prepare_data(na.rm = TRUE)
# Grow/train a random forest model and then create a meteorological normalised trend
list_normalised <- rmw_do_all(
data_london_prepared,
variables = c(
"date_unix", "day_julian", "weekday", "air_temp", "rh", "wd", "ws",
"atmospheric_pressure"
),
n_trees = 300,
n_samples = 300,
verbose = TRUE
)
# What units are in the list?
names(list_normalised)
# Check model object's performance
rmw_model_statistics(list_normalised$model)
# Plot variable importances
list_normalised$model %>%
rmw_model_importance() %>%
rmw_plot_importance()
# Check if model has suffered from overfitting
rmw_predict_the_test_set(
model = list_normalised$model,
df = list_normalised$observations
) %>%
rmw_plot_test_prediction()
# How long did the process take?
list_normalised$elapsed_times
# Plot normalised trend
rmw_plot_normalised(list_normalised$normalised)
# Investigate partial dependencies, if variable is NA, predict all
data_pd <- rmw_partial_dependencies(
model = list_normalised$model,
df = list_normalised$observations,
variable = NA
)
# Plot partial dependencies
data_pd %>%
filter(variable != "date_unix") %>%
rmw_plot_partial_dependencies()
The meteorologically normalised trend produced is below.
Examples and citations
For usage examples see:
Grange, S. K., Carslaw, D. C., Lewis, A. C., Boleti, E., and Hueglin, C. (2018). Random forest meteorological normalisation models for Swiss PM10 trend analysis. Atmospheric Chemistry and Physics 18.9, pp. 6223--6239.
Grange, S. K. and Carslaw, D. C. (2019). Using meteorological normalisation to detect interventions in air quality time series. Science of The Total Environment 653, pp. 578--588.
The use of rmweather for prediction or counterfactual/business as usual scenarios
A second usage of rmweather became established in 2020 to help researchers quantify the effects of the COVID-19 related restrictions on air quality. Briefly, the approach involves the training of random forest models to explain pollutant concentrations based on meteorological and time variables for a training period, say, between 2018 and 2019. After the training period, the model is used in predictive-mode using the experienced meteorological conditions. The predicted time series can be thought of as a counterfactual or business-as-usual (BAU) scenario which the observed time series can be compared with. Critically, an approach like this accounts for the meteorological conditions observed in 2020, which in many locations was unusual and complicates simple analyses. The meteorological sampling and normalisation step is not required for this analysis, but this has been confused in the literature.
Examples of counterfactural modelling
Grange, S. K., Lee, J. D., Drysdale, W. S., Lewis, A. C., Hueglin, C., Emmenegger, L., and Carslaw, D. C. (2021). COVID-19 lockdowns highlight a risk of increasing ozone pollution in European urban areas. Atmospheric Chemistry and Physics 21.5, pp. 4169--4185.
Wang, Y., Wen, Y., Wang, Y., Zhang, S., Zhang, K. M., Zheng, H., Xing, J., Wu, Y., and Hao, J. (2020). Four-Month Changes in Air Quality during and after the COVID-19 Lockdown in Six Megacities in China. Environmental Science and Technology Letters 7.11, pp. 802--808.
Fenech, S., Aquilina, N. J., Ryan, V. (2021) COVID-19-Related Changes in NO2 and O3 Concentrations and Associated Health Effects in Malta. Frontiers in Sustainable Cities 3.631280, pp. 1--12.
Shi, Z., Song, C., Liu, B., Lu, G., Xu, J., Van Vu, T., Elliott, R. J. R., Li, W., Bloss, W. J., and Harrison, R. M. (2021).
Abrupt but smaller than expected changes in surface air quality attributable to COVID-19 lockdowns. Science Advances 7.3, eabd6696.
See also
Owner metadata
- Name: Stuart Grange
- Login: skgrange
- Email:
- Kind: user
- Description: An environmental and data scientist with an air quality focus. Programmatic skills and atmospheric knowledge are used to answer tricky questions.
- Website: http://skgrange.github.io/
- Location: Dübendorf, Switzerland
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/8771129?u=7eb49d6263395936a62865e574434136c6b89971&v=4
- Repositories: 30
- Last ynced at: 2024-06-11T15:38:24.771Z
- Profile URL: https://github.com/skgrange
GitHub Events
Total
- Watch event: 3
- Push event: 3
Last Year
- Watch event: 3
- Push event: 3
Committers metadata
Last synced: 6 days ago
Total Commits: 147
Total Committers: 2
Avg Commits per committer: 73.5
Development Distribution Score (DDS): 0.401
Commits in past year: 12
Committers in past year: 2
Avg Commits per committer in past year: 6.0
Development Distribution Score (DDS) in past year: 0.5
Name | Commits | |
---|---|---|
skgrange | s****e@g****m | 88 |
skgrange | s****e@g****m | 59 |
Committer domains:
Issue and Pull Request metadata
Last synced: 2 days ago
Total issues: 5
Total pull requests: 0
Average time to close issues: 14 days
Average time to close pull requests: N/A
Total issue authors: 5
Total pull request authors: 0
Average comments per issue: 1.0
Average comments per pull request: 0
Merged pull request: 0
Bot issues: 0
Bot pull requests: 0
Past year issues: 0
Past year pull requests: 0
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 0
Past year pull request authors: 0
Past year average comments per issue: 0
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- skgrange (1)
- mmmilkbottle (1)
- ghost (1)
- Medgar21 (1)
- maxbre (1)
Top Pull Request Authors
Top Issue Labels
Top Pull Request Labels
Package metadata
- Total packages: 1
-
Total downloads:
- cran: 268 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 10
- Total maintainers: 1
cran.r-project.org: rmweather
Tools to Conduct Meteorological Normalisation and Counterfactual Modelling for Air Quality Data
- Homepage: https://github.com/skgrange/rmweather
- Documentation: http://cran.r-project.org/web/packages/rmweather/rmweather.pdf
- Licenses: GPL-3 | file LICENSE
- Latest release: 0.2.62 (published 2 months ago)
- Last Synced: 2025-04-25T12:30:35.414Z (2 days ago)
- Versions: 10
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 268 Last month
-
Rankings:
- Stargazers count: 8.084%
- Forks count: 9.117%
- Average: 23.979%
- Dependent packages count: 29.797%
- Dependent repos count: 35.455%
- Downloads: 37.44%
- Maintainers (1)
Dependencies
- R >= 3.2.0 depends
- dplyr >= 1.0.1 imports
- ggplot2 * imports
- lubridate * imports
- magrittr * imports
- pdp * imports
- purrr * imports
- ranger * imports
- stringr * imports
- strucchange * imports
- tibble * imports
- tidyr * imports
- viridis * imports
- openair * suggests
- testthat * suggests
- r-hub/actions/checkout v1 composite
- r-hub/actions/platform-info v1 composite
- r-hub/actions/run-check v1 composite
- r-hub/actions/setup v1 composite
- r-hub/actions/setup-deps v1 composite
- r-hub/actions/setup-r v1 composite
Score: 10.19988156558993