davidcarslaw / openair

Tools for air quality data analysis
https://davidcarslaw.github.io/openair/
GNU General Public License v2.0
305 stars 113 forks source link

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

Open jack-davison opened 3 months ago

jack-davison commented 3 months ago

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: