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

Under the Open air package, is it possible to convert calendar plots, that show air pollution levels over the month, into ics/iCalendar files? #377

Closed sanajanaparmar closed 4 months ago

sanajanaparmar commented 10 months ago

Feature request

Under the Open air package, is it possible to convert calendar plots, that show air pollution levels over the month, into ics/iCalendar files?

jack-davison commented 10 months ago

Hello!

Could I please ask what your use-case is for this?

Writing ics files using R is not something I've ever done (or, to be honest, seen done!) using R, but a quick Google shows there's at least one R package for doing this:

https://cran.r-project.org/web/packages/calendar/index.html

Best, Jack

jack-davison commented 10 months ago

I've written up some example code that runs calendarPlot(), pulls out the data, and writes the .ics files.

This sort of thing is very much out of scope for {openair} to do natively, but I hope you'll be able to usefully adapt what I've written below.


# install.packages("calendar")
# install.packages("openair")

library(openair)
library(calendar)

dir.create("caltest")
setwd("caltest")

# make calendar plot
cal_obj <- calendarPlot(mydata, "nox", year = 2000, month = 1)

# get data
cal_data <- cal_obj$data

# drop "missing" values
cal_data <- cal_data[!is.na(cal_data$date), ]

# format dates
cal_data$date <- lubridate::as_datetime(cal_data$date)

# make calendar events
events <-
  purrr::map(
    .x = split(cal_data, cal_data$date),
    .f = ~ calendar::ic_event(
      start_time = .x$date,
      end_time = 24,
      summary = paste0("NOx concentration: ", .x$value)
    )
  )

# save calendar events
purrr::iwalk(.x = events,
             .f = ~ calendar::ic_write(ic = .x, file = paste0(.y, ".ics")))
sanajanaparmar commented 10 months ago

Hello Jack,

Thank you so much for your quick response. The way I was looking at this was, if people could download the ics file and super impose with their google calendars, then they would have high AQI days on their calendars.

Thank you so much for giving this a go, I really appreciate it.

Warm regards, Sanjana

From: Jack Davison @.> Sent: Tuesday, January 30, 2024 4:37 AM To: davidcarslaw/openair @.> Cc: Sanjana Parmar @.>; Author @.> Subject: Re: [davidcarslaw/openair] Under the Open air package, is it possible to convert calendar plots, that show air pollution levels over the month, into ics/iCalendar files? (Issue #377)

Hello!

Could I please ask what your use-case is for this?

Writing ics files using R is not something I've ever done (or, to be honest, seen done!) using R, but a quick Google shows there's at least one R package for doing this:

https://cran.r-project.org/web/packages/calendar/index.html

Best, Jack

— Reply to this email directly, view it on GitHubhttps://github.com/davidcarslaw/openair/issues/377#issuecomment-1916431460, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BFV5QZZREHOOPI2TXTHHL23YRC5KZAVCNFSM6AAAAABCPRESFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJWGQZTCNBWGA. You are receiving this because you authored the thread.Message ID: @.***>