Coder Social home page Coder Social logo

Comments (3)

adokter avatar adokter commented on August 21, 2024 1

@iskandari could you look into this and the suggestion by @peterdesmet of transfering to suntools?

from biorad.

peterdesmet avatar peterdesmet commented on August 21, 2024

Not familiar with this issue, but if bioRad provides a more sensible output than suntools, than it might be good to update suntools. @adokter or @pieterh, could you look into this and potentially transfer this issue to https://github.com/adokter/suntools/issues?

from biorad.

iskandari avatar iskandari commented on August 21, 2024

@grapemanJac thanks for highlighting this nuance with tibbles, which I just found out are actually just lists:

 typeof(dat)
[1] "list"

You are not able to extract a timezone using lubridate::tz() because you are passing a tibble object instead of a POSIXct object, so you have to go one level deeper:

dat <- tibble(Date = seq(as.POSIXct("2023-08-01 00:00:00",
                                    format = "%Y-%m-%d 00:00:00",
                                    tz = "Australia/Perth",
                                    force_tz = TRUE),
                         as.POSIXct("2023-08-05 00:00:00",
                                    format = "%Y-%m-%d 00:00:00",
                                    tz = "Australia/Perth",
                                    force_tz = TRUE),
                         by = '1 day'))

tz(dat[1,1])
[1] "UTC"
Warning message:
tz(): Don't know how to compute timezone for object of class tbl_df/tbl/data.frame; returning "UTC"

For example, any of these work:

tz(dat$Date)
[1] "Australia/Perth"

dat[1,1]$Date
[1] "2023-08-01 AWST"

tz(dat[1,1]$Date)
[1] "Australia/Perth"

tz(dat$Date[1])
[1] "Australia/Perth"

So this can be easily remedied in dplyr::mutate() by extracting the tz directly from the Date vector:

#Roebuck, AU

dat <- dat %>% mutate(Sunrise = bioRad::sunrise(Date, lon = 122.48, lat = -17.846, tz=tz(Date), force_tz = TRUE),
                      Sunset = bioRad::sunset(Date, lon = 122.48, lat = -17.846, tz=tz(Date), force_tz = TRUE))

dat
# A tibble: 5 × 3
  Date                Sunrise             Sunset             
  <dttm>              <dttm>              <dttm>             
1 2023-08-01 00:00:00 2023-08-01 06:19:31 2023-08-01 17:33:35
2 2023-08-02 00:00:00 2023-08-02 06:19:06 2023-08-02 17:33:52
3 2023-08-03 00:00:00 2023-08-03 06:18:40 2023-08-03 17:34:10
4 2023-08-04 00:00:00 2023-08-04 06:18:13 2023-08-04 17:34:27
5 2023-08-05 00:00:00 2023-08-05 06:17:45 2023-08-05 17:34:44

from biorad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.