Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more flexible way to calculate air quality stats #389

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jack-davison
Copy link
Collaborator

@jack-davison jack-davison commented Aug 5, 2024

This is a suggestion to implement #388.

Users can create their own air quality statistics objects with aqStat() and then provide them, as a list, to calcAQStats() which will actually carry them out. Can flexibly build up stats of interest:

devtools::load_all()
#> ℹ Loading openair

calcAQStats(mydata = openair::mydata,
            list(
              # mean hourly ozone
              aqStat("o3", "mean", "hour"),
              # max hourly ozone
              aqStat("o3", "max", "hour"),
              # max rolling 8-hourly ozone
              aqStat("o3", "max", "hour", roll = 8),
              # number of 8-hourly ozone above 100
              aqStat("o3", "limit", "hour", roll = 8, limit = 100),
              # number of maximum daily 8-hourly ozone above 100
              aqStat(
                "o3",
                "limit",
                "hour",
                roll = 8,
                roll.avg.time = "day",
                limit = 100
              )
            )) |>
  dplyr::glimpse()
#> Rows: 8
#> Columns: 6
#> $ date                          <dttm> 1998-01-01, 1999-01-01, 2000-01-01, 200…
#> $ o3.mean.hour                  <dbl> 5.533947, 6.431897, 6.619295, 7.072555, …
#> $ o3.max.hour                   <dbl> 38, 52, 48, 58, 52, 70, 42, 42
#> $ o3.max.hour.roll8             <dbl> 31.875, 44.625, 42.500, 47.125, 45.250, …
#> $ o3.limit.hour.roll8.100       <int> 0, 0, 0, 0, 0, 0, 0, 0
#> $ o3.limit.hour.maxdayroll8.100 <int> 0, 0, 0, 0, 0, 0, 0, 0

Created on 2024-08-05 with reprex v2.1.1

Todo:

  • tonarrow option?
  • implement type (e.g., to split by site)
  • other periods (e.g., "month")
  • error handling if only one aqStat passed, not in a list
  • allow data capture

@jack-davison jack-davison self-assigned this Aug 5, 2024
@jack-davison jack-davison added enhancement Ideas for new features for openair utilities 🛠 Openair data utilities, e.g., timeAverage labels Aug 5, 2024
@jack-davison jack-davison changed the title feat: initial commit of new aqstats function feat: more flexible way to calculate air quality stats Aug 5, 2024
@jack-davison jack-davison linked an issue Aug 5, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for new features for openair utilities 🛠 Openair data utilities, e.g., timeAverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More flexible AQ Stats
1 participant