davidcarslaw / openair

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

Refine and refactor UKAQ import functions #347

Closed jack-davison closed 1 year ago

jack-davison commented 1 year ago

This PR fixes #346 plus more. Three key changes are contained within:

library(openair)

importAURN(data_type = "annual")
#> # A tibble: 129 × 38
#>    uka_code code  site    date                   o3 o3_capture o3.summer_capture
#>    <fct>    <chr> <chr>   <dttm>              <dbl>      <dbl>             <dbl>
#>  1 UKA00399 ABD   Aberde… 2009-01-01 00:00:00  42.0      0.944             0.990
#>  2 UKA00513 ABD7  Aberde… 2009-01-01 00:00:00  NA       NA                NA    
#>  3 UKA00451 ACTH  Auchen… 2009-01-01 00:00:00  55.5      0.975             0.953
#>  4 UKA00137 AH    Aston … 2009-01-01 00:00:00  63.8      0.968             0.976
#>  5 UKA00541 ARM6  Armagh… 2009-01-01 00:00:00  NA       NA                NA    
#>  6 UKA00236 BAR2  Barnsl… 2009-01-01 00:00:00  NA       NA                NA    
#>  7 UKA00353 BAR3  Barnsl… 2009-01-01 00:00:00  43.3      0.969             0.997
#>  8 UKA00306 BATH  Bath R… 2009-01-01 00:00:00  NA       NA                NA    
#>  9 UKA00212 BEL2  Belfas… 2009-01-01 00:00:00  37.8      0.936             0.907
#> 10 UKA00238 BEX   London… 2009-01-01 00:00:00  NA       NA                NA    
#> # ℹ 119 more rows
#> # ℹ 31 more variables: o3.daily.max.8hour <dbl>, o3.aot40v <int>,
#> #   o3.aot40f <int>, somo35 <dbl>, somo35_capture <dbl>, no <dbl>,
#> #   no_capture <dbl>, no2 <dbl>, no2_capture <dbl>, nox <dbl>,
#> #   nox_capture <dbl>, so2 <dbl>, so2_capture <dbl>, co <dbl>,
#> #   co_capture <dbl>, pm10 <dbl>, pm10_capture <dbl>, nv10 <dbl>,
#> #   nv10_capture <dbl>, v10 <dbl>, v10_capture <dbl>, pm2.5 <dbl>, …

importAURN(
  data_type = "annual",
  site = c("my1", "kc1"),
  year = 2020,
  pollutant = c("no2", "pm2.5"),
)
#> # A tibble: 2 × 8
#>   uka_code code  site  date                  no2 no2_capture pm2.5 pm2.5_capture
#>   <fct>    <chr> <chr> <dttm>              <dbl>       <dbl> <dbl>         <dbl>
#> 1 UKA00253 KC1   Lond… 2020-01-01 00:00:00  20.6       0.994  8.05         0.996
#> 2 UKA00315 MY1   Lond… 2020-01-01 00:00:00  43.7       0.968  9.00         0.787

importAURN(
  data_type = "annual",
  site = c("my1", "kc1"),
  year = 2020,
  pollutant = c("no2", "pm2.5"),
  to_narrow = TRUE
)
#> # A tibble: 4 × 6
#>   code  site                   date                species value data_capture
#>   <chr> <chr>                  <dttm>              <chr>   <dbl>        <dbl>
#> 1 KC1   London N. Kensington   2020-01-01 00:00:00 no2     20.6         0.994
#> 2 KC1   London N. Kensington   2020-01-01 00:00:00 pm2.5    8.05        0.996
#> 3 MY1   London Marylebone Road 2020-01-01 00:00:00 no2     43.7         0.968
#> 4 MY1   London Marylebone Road 2020-01-01 00:00:00 pm2.5    9.00        0.787

Created on 2023-05-26 with reprex v2.0.2

library(openair)

importAQE(year = 2022, data_type = "daqi")
#> # A tibble: 138,363 × 7
#>    code  site             pollutant date                concentration poll_index
#>    <chr> <chr>            <chr>     <dttm>                      <dbl>      <int>
#>  1 AB001 VofWH Abingdon … no2       2022-01-01 00:00:00         10.3           1
#>  2 BAI2  Birmingham Airp… no2       2022-01-01 00:00:00         12.0           1
#>  3 BAI2  Birmingham Airp… o3        2022-01-01 00:00:00         59             2
#>  4 BAI2  Birmingham Airp… pm10      2022-01-01 00:00:00         16             1
#>  5 BAI2  Birmingham Airp… pm2.5     2022-01-01 00:00:00         10             1
#>  6 BAI2  Birmingham Airp… so2       2022-01-01 00:00:00          3.04          1
#>  7 BAR11 Barnsley A628 R… no2       2022-01-01 00:00:00         22.1           1
#>  8 BAR9  Barnsley A635 K… pm10      2022-01-01 00:00:00         27             2
#>  9 BN1   Barnet Tally Ho  no2       2022-01-01 00:00:00         26.2           1
#> 10 BN1   Barnet Tally Ho  pm10      2022-01-01 00:00:00         25             2
#> # ℹ 138,353 more rows
#> # ℹ 1 more variable: measurement_period <chr>

Created on 2023-05-26 with reprex v2.0.2

Notes:

davidcarslaw commented 1 year ago

Great stuff, Jack