Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert datetime to julian automatically in sunpos #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=radians)
sunpos(dt::AbstractVector{<:DateTime}; radians::Bool=false) =
sunpos(datetime2julian.(dt); radians)
LilithHafner marked this conversation as resolved.
Show resolved Hide resolved

"""
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
Loading