Skip to content

Commit

Permalink
Convert datetime to julian automatically in sunpos
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner committed Dec 9, 2024
1 parent 9040efe commit b298eb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/sunpos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function sunpos(jd::AbstractVector{J}; radians::Bool=false) where {J<:Real}
return ra, dec, longmed, oblt
end

sunpos(dt::DateTime; radians::Bool=false) =
sunpos(datetime2julian(dt); radians)
sunpos(dt::AbstractVector{<:DateTime}; radians::Bool=false) =
sunpos(datetime2julian.(dt); radians)

"""
sunpos(jd[, radians=false]) -> ra, dec, elong, obliquity
Expand All @@ -84,8 +89,8 @@ Compute the right ascension and declination of the Sun at a given date.
### Arguments ###
* `jd`: the Julian date of when you want to calculate Sun position. It can be
either a scalar or a vector. Use `jdcnv` to get the Julian date for a given
date and time.
either a scalar or a vector. If `jd` is a `Dates.DateTime` it will be
automatically converted.
* `radians` (optional boolean keyword): if set to `true`, all output quantities
are given in radians. The default is `false`, so all quantities are given in
degrees.
Expand Down
2 changes: 2 additions & 0 deletions test/utils-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,13 @@ end
@test dec 14.909699471099517
@test lon 40.31067053890748
@test obl 23.440840980112657
@test (ra, dec, lon, obl) === @inferred(sunpos(DateTime(1982, 5, 1)))
ra, dec, lon, obl = @inferred(sunpos(jdcnv.([DateTime(2016, 5, 10)]), radians=true))
@test ra [0.8259691339090751]
@test dec [0.3085047454107549]
@test lon [0.8687853454154388]
@test obl [0.40901175207670365]
@test (ra, dec, lon, obl) == @inferred(sunpos([DateTime(2016, 5, 10)], radians=true))
ra, dec, lon, obl = @inferred(sunpos([2457531]))
@test ra [59.71655864208797]
@test dec [20.52127006818727]
Expand Down

0 comments on commit b298eb5

Please sign in to comment.