-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add `getSunPosition` method * add `getMoonPosition` method * add `getMoonIllumination` method * update docs
- Loading branch information
Showing
14 changed files
with
425 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
""" | ||
getMoonIllumination( | ||
time::Union{Date,DateTime,ZonedDateTime}; | ||
keep=[:fraction, :phase, :angle]) | ||
Calculate moon illumination for the given time. Return a `NamedTuple` or `DataFrame`. | ||
Available variables: | ||
| Variable | Description | | ||
| :--------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| `fraction` | Illuminated fraction of the moon; varies from 0.0 (new moon) to 1.0 (full moon) | | ||
| `phase` | Moon phase; varies from 0.0 to 1.0, described below | | ||
| `angle` | Midpoint angle in radians of the illuminated limb of the moon reckoned eastward from the north point of the disk; the moon is waxing if the angle is negative, and waning if positive | | | ||
Moon phase value should be interpreted like this: | ||
- `0`: New Moon | ||
- *Waxing Crescent* | ||
- `0.25`: First Quarter | ||
- *Waxing Gibbous* | ||
- `0.5`: Full Moon | ||
- *Waning Gibbous* | ||
- `0.75`: Last Quarter | ||
- *Waning Crescent* | ||
# Examples | ||
```julia | ||
using Dates, SunCalc | ||
getMoonIllumination(Date(2000, 07, 01)) | ||
getMoonIllumination(now(), keep=[:fraction]) | ||
``` | ||
""" | ||
function getMoonIllumination( | ||
time::Union{Date,DateTime,ZonedDateTime}; | ||
keep=[:fraction, :phase, :angle]) | ||
|
||
available_var = [:fraction, :phase, :angle] | ||
|
||
@assert all(keep .∈ [available_var]) " | ||
$(keep[Not(keep .∈ [available_var])]) is not a valid variable." | ||
|
||
if isa(time, ZonedDateTime) | ||
time = DateTime(time, UTC) | ||
end | ||
|
||
data = moonIllumination(DateTime(time)) | ||
|
||
return data[keep] | ||
end | ||
|
||
function getMoonIllumination( | ||
time::Union{Vector{Date},Vector{DateTime},Vector{ZonedDateTime}}; | ||
keep=[:fraction, :phase, :angle]) | ||
|
||
available_var = [:fraction, :phase, :angle] | ||
|
||
@assert all(keep .∈ [available_var]) " | ||
$(keep[Not(keep .∈ [available_var])]) is not a valid variable." | ||
|
||
time = map(x -> isa(x, ZonedDateTime) ? DateTime(x, UTC) : x, time) | ||
|
||
data = DataFrame(time=time) | ||
|
||
ill = DataFrame(moonIllumination.(DateTime.(data.time))) | ||
|
||
data = hcat(data, ill[:, keep]) | ||
|
||
return data | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
""" | ||
getMoonPosition( | ||
time::Union{DateTime,ZonedDateTime}, | ||
lat::Real, | ||
lon::Real; | ||
keep=[:altitude, :azimuth, :distance, :parallacticAngle]) | ||
Calculate the sun position for the given time and location. Return a `NamedTuple` | ||
or `DataFrame`. | ||
Available variables: | ||
| Variable | Description | | ||
| :----------------- | :----------------------------------------- | | ||
| `altitude` | Moon altitude above the horizon in radians | | ||
| `azimuth` | Moon azimuth in radians | | ||
| `distance` | Distance to moon in kilometres | | ||
| `parallacticAngle` | Parallactic angle of the moon in radians | | ||
# Examples | ||
```julia | ||
using Dates, SunCalc | ||
getMoonPosition(DateTime(2000, 07, 01, 12, 00, 00), 54, 9) | ||
getMoonPosition(now(), 54, 9; keep=[:altitude]) | ||
``` | ||
""" | ||
function getMoonPosition( | ||
time::Union{DateTime,ZonedDateTime}, | ||
lat::Real, | ||
lon::Real; | ||
keep=[:altitude, :azimuth, :distance, :parallacticAngle]) | ||
|
||
available_var = [:altitude, :azimuth, :distance, :parallacticAngle] | ||
|
||
@assert all(keep .∈ [available_var]) " | ||
$(keep[Not(keep .∈ [available_var])]) is not a valid variable." | ||
|
||
if isa(time, ZonedDateTime) | ||
time = DateTime(time, UTC) | ||
end | ||
|
||
data = moonPosition(time, lat, lon) | ||
|
||
return data[keep] | ||
end | ||
|
||
function getMoonPosition( | ||
time::Union{Vector{DateTime},Vector{ZonedDateTime}}, | ||
lat::Real, | ||
lon::Real; | ||
keep=[:altitude, :azimuth, :distance, :parallacticAngle]) | ||
|
||
available_var = [:altitude, :azimuth, :distance, :parallacticAngle] | ||
|
||
@assert all(keep .∈ [available_var]) " | ||
$(keep[Not(keep .∈ [available_var])]) is not a valid variable." | ||
|
||
time = map(x -> isa(x, ZonedDateTime) ? DateTime(x, UTC) : x, time) | ||
|
||
data = DataFrame(time=time, lat=lat, lon=lon) | ||
|
||
pos = DataFrame(moonPosition.(data.time, data.lat, data.lon)) | ||
|
||
data = hcat(data, pos[:, keep]) | ||
|
||
return data | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
d5dfb90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
d5dfb90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/91062
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: