Closed rroday closed 2 months ago
Hi @rroday -- thanks for using oce!
@dankelley is more up-to-speed on the various sun functions, as they were written by him, but I think that to make your example work you just need to follow the hint in the error. Note that length(times)
returns a vector of length 1. Also, the help page for sunAngle()
indicates that useRefraction=
is a boolean, i.e. TRUE/FALSE
. So, the following should work:
library(oce)
#> Loading required package: gsw
times <- as.POSIXct(rep("2011-03-03 06:49:00", 4))
sunAngle(times, latitude = c(39, 38, 34, 35), longitude = c(-75, -74, -73, -72),
useRefraction = rep(TRUE, length(times)))
#> $time
#> [1] "2011-03-03 10:49:00 UTC" "2011-03-03 10:49:00 UTC"
#> [3] "2011-03-03 10:49:00 UTC" "2011-03-03 10:49:00 UTC"
#>
#> $azimuth
#> [1] 91.75708 92.52231 93.62700 94.07240
#>
#> $altitude
#> [1] -8.776681 -7.957257 -6.934286 -6.179128
#>
#> $diameter
#> [1] 0.5378894 0.5378894 0.5378894 0.5378894
#>
#> $distance
#> [1] 0.9912818 0.9912818 0.9912818 0.9912818
#>
#> $declination
#> [1] -6.865559 -6.865559 -6.865559 -6.865559
#>
#> $rightAscension
#> [1] -16.12483 -16.12483 -16.12483 -16.12483
Created on 2024-08-02 with reprex v2.1.0
This does look related to #2178, which arose from that SO post, and it looks like we maybe haven't done a CRAN release since then. My example above was using the develop
branch of oce. @rroday, are you able to install oce from source following the instructions at:
https://dankelley.github.io/oce/#installing-oce
and see if that fixes your issue?
(@dankelley; we should think about a CRAN release)
I just altered the "develop" branch (commit 9e408adcd3ab7aa84fbe99f11fd06fc043847e79) so that it now detects if useRefraction
is not a logical value. See reprex below.
library(oce)
#> Loading required package: gsw
times <- as.POSIXct(rep("2011-03-03 06:49:00", 4))
sunAngle(times,
latitude = c(39, 38, 34, 35),
longitude = c(-75, -74, -73, -72),
useRefraction = length(times)
)
#> Error in sunAngle(times, latitude = c(39, 38, 34, 35), longitude = c(-75, : useRefraction must be a logical value
Created on 2024-08-02 with reprex v2.1.1
I see that the docs say that longitude
, latitude
and useRefraction
are made to have the same length as time
. This is not what the code was doing. I will alter the code to do that, because we try to make code follow docs.
I will also add a note that this is useful only in for one use, namely that of constructing time-series of the angles. For other uses, the user ought to set up the arguments to be of equal length (if that makes sense) or to call the function repeatedly. I don't see a clever way of handling the range of possible things a person might want. Say one person wants to determine angles at a certain and certain latitude, but a bunch of longitudes ... and another person wants to use a certain time, some number N of latitudes and some other number M of latitudes ... and on and on. Handling all possibilities would be tricky. This is what expand.grid()
is for ...
Hi Dr. Kelley and Dr. Richards,
Thank you immensely for your timely and thorough responses. I really appreciate you addressing my comments so quickly! I realized that my initial comment had an error. Rather than using "useRefraction = length(times)", I was using "useRefraction = rep(TRUE, length(times))", and was receiving the following error message: Error in sunAngle(as.POSIXct(dtc_final3$detection_timestamp_utc, tz = "UTC"), :
lengths of longitude, latitude and useRefraction must be 1 or the length of time
I'm not sure if this changes things that you have worked on this morning, but I will reinstall the "oce" package and rerun the code. My apologies for the error.
Best, Rachel Roday
On Fri, Aug 2, 2024 at 11:25 AM Dan Kelley @.***> wrote:
I see that the docs say that longitude, latitude and useRefraction are made to have the same length as time. This is not what the code was doing. I will alter the code to do that, because we try to make code follow docs.
I will also add a note that this is useful only in for one use, namely that of constructing time-series of the angles. For other uses, the user ought to set up the arguments to be of equal length (if that makes sense) or to call the function repeatedly. I don't see a clever way of handling the range of possible things a person might want. Say one person wants to determine angles at a certain and certain latitude, but a bunch of longitudes ... and another person wants to use a certain time, some number N of latitudes and some other number M of latitudes ... and on and on. Handling all possibilities would be tricky. This is what expand.grid() is for ...
— Reply to this email directly, view it on GitHub https://github.com/dankelley/oce/issues/2225#issuecomment-2265642224, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASOQWUC3FPHAUVC2DBLTQYDZPOQHFAVCNFSM6AAAAABL4PU7ZCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRVGY2DEMRSGQ . You are receiving this because you were mentioned.Message ID: @.***>
@rroday -- please note that you'll want to install oce from github (as @richardsc noted). I just made some modifications a moment ago, improving the documentation for sunAngle()
to suggest that only 3 possibilities are available:
time
has length exceeding 1, in which case rep()
is used on the other arguments to make them of the same length.sunAngle()
repeatedly, or use expand.grid()
to make same-length parametersHopefully the docs are clear on that now. I think expand.grid()
might be the way you want to go, depending on your purpose.
@rroday if you find it helpful to format the text in comments, check https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax which gives hints. I took the liberty of reformatting your initial comment so I could read it a bit more easily.
@dankelley Fantastic, thanks so much!! And thanks for this link, this is the first issue I've opened on github.
@rroday, in case it's of interest, this function was used a lot in the following paper. I can't remember, but I might have written it just for that occasion.
Hamelin, Kayla M., Daniel E. Kelley, Christopher T. Taggart, and Michael C. James. “Water Mass Characteristics and Solar Illumination Influence Leatherback Turtle Dive Patterns at High Latitudes.” Ecosphere 5, no. 2 (February 2014): 1–20. https://doi.org/10.1890/ES13-00158.1.
@rroday, for fun, I made the following. It shows how the sunrise line (I'm sure there's a name for that) sweeps along Nova Scotia at this time of year. The squiggly contours go away if you set useRefraction
to FALSE. I made this for the "official" sunrise time for Halifax, but the source I have does not give the seconds part, nor does it say what they mean by Halifax (city centre? centroid of environs boundaries?). Also, I'm not 100% sure what sunrise means on that site. Time of seeing edge of sun? Time when centre of sun is at horizon? Etc. So I'm not too worried about why the zero line does not go through my apartment.
@rroday do you think anything more needs to be done on this issue? In the oce project, we ask reporters to close issues, with developers only closing them if discussion has gone silent after having asked the reporters if things are ok. This is a way to avoid developers saying "not an issue" and silencing reporters.
Since I plan to release oce to CRAN on August 16th (when CRAN will again be accepting submissions), I'm keen to fix up this issue, if possible.
Thanks!
Dan
Hi! I'm new to the oce package and I am using the sunAngle function for a dataframe with ~40,000 different time x latitude/longitude combinations. When I use the function on my dataframe, it doesn't like that the lengths of the different parameters don't match (which they do!).
Here is a reproducible bit of code:
Here is my error message:
Error in sunAngle(times, latitude = c(39, 38, 34, 35), longitude = c(-75, : lengths of longitude and useRefraction must match
Someone on stack exchange recommended using Vectorize in the sunAngle function to fix this issue, but I thought I would repost my issue on your git since I am not the original poster on this link: