Skip to content

Commit 0e4564f

Browse files
committed
Hack to avoid including AstroLib due to it breaking compat
1 parent 3039e7a commit 0e4564f

8 files changed

Lines changed: 466 additions & 6 deletions

File tree

Project.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ authors = ["Eric B. Ford, Christian Gilbertson, Joe Ninan, Michael L. Palumbo II
44
version = "0.2.0"
55

66
[deps]
7-
AstroLib = "c7932e45-9af1-51e7-9da9-f004cd3a462b"
87
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
98
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
109
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
@@ -37,7 +36,6 @@ TemporalGPs = "e155a3c4-0841-43e1-8b83-a0e4f03cc18f"
3736
ThreadedIterables = "11d239b0-c0b9-11e8-1935-d5cfa53abb03"
3837

3938
[compat]
40-
AstroLib = "0.4"
4139
CSV = "0.7, 0.8"
4240
DSP = "0.5, 0.6"
4341
DataFrames = "0.20, 0.21, 0.22"
@@ -60,12 +58,12 @@ Query = "1.0"
6058
RvSpectMLBase = "0.2"
6159
Scalpels = "0.1"
6260
SpecialFunctions = "0.10, 1.0, 1.1"
63-
StaticArrays = "0.12, 1.0"
61+
StaticArrays = "0.8, 0.9, 0.10, 0.11, 0.12, 1"
6462
StatsBase = "0.33"
6563
Stheno = "0.6"
66-
TemporalGPs = "0.3"
64+
TemporalGPs = "0.3, 0.4, 0.5"
6765
ThreadedIterables = "0.2"
68-
julia = "1.6"
66+
julia = "1.5, 1.6"
6967

7068
[extras]
7169
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/RvSpectML.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export Scalpels
3535
using LinearAlgebra, Statistics
3636
using DataFrames, Query
3737
using Dates
38-
using AstroLib # For solar position
38+
#using AstroLib # For solar position
39+
include("astrolib/astrolib.jl")
3940
# Packages that are being used and likely can be shared
4041
# using Distributions, Interpolations, MultivariateStats, PDMats
4142
# Packages we might use soon

src/astrolib/astrolib.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# AstroLib.jl[https://github.com/JuliaAstro/AstroLib.jl] was breaking compatability with other packages
2+
# So this is a hack to include the just needed functions and avoid extra dependancies
3+
4+
module AstroLib
5+
6+
using Dates
7+
const JULIANCENTURY = 36_525
8+
const ct2lst_c = (280.46061837, 360.98564736629, 0.000387933, 38710000.0)
9+
include("jdcnv.jl")
10+
const J2000 = Int(jdcnv(2000, 01, 01, 12)) # 2451545
11+
12+
include("sec2rad.jl")
13+
include("ct2lst.jl")
14+
export ct2lst
15+
include("hadec2altaz.jl")
16+
export hadec2altaz
17+
include("sunpos.jl")
18+
export sunpos
19+
20+
end

src/astrolib/ct2lst.jl

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# This file is a part of AstroLib.jl. License is MIT "Expat".
2+
# Copyright (C) 2016 Mosè Giordano.
3+
4+
function ct2lst(long::T, jd::T) where {T<:AbstractFloat}
5+
t0 = jd - J2000
6+
t = t0 / JULIANCENTURY
7+
# Compute GST in seconds.
8+
θ = ct2lst_c[1] + (ct2lst_c[2]*t0) + t*t*(ct2lst_c[3] - t / ct2lst_c[4])
9+
return mod((θ + long)/15, 24)
10+
end
11+
12+
"""
13+
ct2lst(longitude, jd) -> local_sidereal_time
14+
ct2lst(longitude, tz, date) -> local_sidereal_time
15+
16+
### Purpose ###
17+
18+
Convert from Local Civil Time to Local Mean Sidereal Time.
19+
20+
### Arguments ###
21+
22+
The function can be called in two different ways. The only argument common to
23+
both methods is `longitude`:
24+
25+
* `longitude`: the longitude in degrees (east of Greenwich) of the place for which the local
26+
sidereal time is desired. The Greenwich mean sidereal time (GMST) can be found by setting
27+
longitude = `0`.
28+
29+
The civil date to be converted to mean sidereal time can be specified either by
30+
providing the Julian days:
31+
32+
* `jd`: this is number of Julian days for the date to be converted.
33+
34+
or the time zone and the date:
35+
36+
* `tz`: the time zone of the site in hours, positive East of the
37+
Greenwich meridian (ahead of GMT). Use this parameter to easily
38+
account for Daylight Savings time (e.g. -4=EDT, -5 = EST/CDT).
39+
* `date`: this is the local civil time with type `DateTime`.
40+
41+
### Output ###
42+
43+
The local sidereal time for the date/time specified in hours.
44+
45+
### Method ###
46+
47+
The Julian days of the day and time is question is used to determine the number
48+
of days to have passed since 2000-01-01. This is used in conjunction with the
49+
GST of that date to extrapolate to the current GST; this is then used to get the
50+
LST. See Astronomical Algorithms by Jean Meeus, p. 84 (Eq. 11-4) for the
51+
constants used.
52+
53+
### Example ###
54+
55+
Find the Greenwich mean sidereal time (GMST) on 2008-07-30 at 15:53 in
56+
Baltimore, Maryland (longitude=-76.72 degrees). The timezone is EDT or tz=-4
57+
58+
```jldoctest
59+
julia> using AstroLib, Dates
60+
61+
julia> lst = ct2lst(-76.72, -4, DateTime(2008, 7, 30, 15, 53))
62+
11.356505172312609
63+
64+
julia> sixty(lst)
65+
3-element StaticArrays.SArray{Tuple{3},Float64,1,3} with indices SOneTo(3):
66+
11.0
67+
21.0
68+
23.418620325392112
69+
```
70+
71+
Find the Greenwich mean sidereal time (GMST) on 2015-11-24 at 13:21 in
72+
Heidelberg, Germany (longitude=08° 43' E). The timezone is CET or tz=1.
73+
Provide `ct2lst` only with the longitude of the place and the number of
74+
Julian days.
75+
76+
```jldoctest
77+
julia> using AstroLib, Dates
78+
79+
julia> longitude=ten(8, 43); # Convert longitude to decimals.
80+
81+
julia> jd = jdcnv(DateTime(2015, 11, 24, 13, 21) - Dates.Hour(1));
82+
# Get number of Julian days. Remember to subtract the time zone in
83+
# order to convert local time to UTC.
84+
85+
julia> lst = ct2lst(longitude, jd) # Calculate Greenwich Mean Sidereal Time.
86+
17.140685171005316
87+
88+
julia> sixty(lst)
89+
3-element StaticArrays.SArray{Tuple{3},Float64,1,3} with indices SOneTo(3):
90+
17.0
91+
8.0
92+
26.466615619137883
93+
```
94+
95+
### Notes ###
96+
97+
Code of this function is based on IDL Astronomy User's Library.
98+
"""
99+
ct2lst(long::Real, jd::Real) = ct2lst(promote(float(long), float(jd))...)
100+
101+
function ct2lst(long::T, tz::T, date::DateTime) where {T<:AbstractFloat}
102+
# In order to handle time zones, package "TimeZones.jl" is much better, but
103+
# here we need only to add the time zone to UTC time. All time zones I know
104+
# are either integer, or ±30 or ±45 minutes, so it should be safe enough to
105+
# convert hours to minutes and subtract minutes from "time".
106+
date = date - Dates.Minute(round(Int, tz*60))
107+
return ct2lst(long, jdcnv(date))
108+
end
109+
110+
ct2lst(long::Real, tz::Real, date::DateTime) =
111+
ct2lst(promote(float(long), float(tz))..., date)

src/astrolib/hadec2altaz.jl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# This file is a part of AstroLib.jl. License is MIT "Expat".
2+
# Copyright (C) 2016 Mosè Giordano.
3+
4+
function _hadec2altaz(ha::T, dec::T, lat::T, ws::Bool) where {T<:AbstractFloat}
5+
sh, ch = sincos(deg2rad(ha))
6+
sd, cd = sincos(deg2rad(dec))
7+
sl, cl = sincos(deg2rad(lat))
8+
9+
x = -ch*cd*sl + sd*cl
10+
y = -sh*cd
11+
z = ch*cd*cl + sd*sl
12+
r = hypot(x, y)
13+
14+
# Now get altitude, azimuth
15+
az = rad2deg(mod2pi(atan(y, x)))
16+
alt = rad2deg(atan(z, r))
17+
# Convert azimuth to West from South, if desired
18+
if ws
19+
az = mod(az + 180, 360)
20+
end
21+
return alt, az
22+
end
23+
24+
"""
25+
hadec2altaz(ha, dec, lat[, ws=true]) -> alt, az
26+
27+
### Purpose ###
28+
29+
Convert Hour Angle and Declination to Horizon (Alt-Az) coordinates.
30+
31+
### Explanation ###
32+
33+
Can deal with the NCP singularity. Intended mainly to be used by program
34+
`eq2hor`.
35+
36+
### Arguments ###
37+
38+
Input coordinates may be either a scalar or an array, of the same dimension.
39+
40+
* `ha`: the local apparent hour angle, in degrees. The hour angle is the time
41+
that right ascension of 0 hours crosses the local meridian. It is
42+
unambiguously defined.
43+
* `dec`: the local apparent declination, in degrees.
44+
* `lat`: the local geodetic latitude, in degrees, scalar or array.
45+
* `ws` (optional boolean keyword): if true, the output azimuth is measured West
46+
from South. The default is to measure azimuth East from North.
47+
48+
`ha` and `dec` can be given as a 2-tuple `(ha, dec)`.
49+
50+
### Output ###
51+
52+
2-tuple `(alt, az)`
53+
54+
* `alt`: local apparent altitude, in degrees.
55+
* `az`: the local apparent azimuth, in degrees.
56+
57+
The output coordinates are always floating points and have the same type (scalar
58+
or array) as the input coordinates.
59+
60+
### Example ###
61+
62+
Arcturus is observed at an apparent hour angle of 336.6829 and a declination of
63+
19.1825 while at the latitude of +43° 4' 42''. What are the local altitude and
64+
azimuth of this object?
65+
66+
```jldoctest
67+
julia> using AstroLib
68+
69+
julia> alt, az = hadec2altaz(336.6829, 19.1825, ten(43, 4, 42))
70+
(59.08617155005685, 133.3080693440254)
71+
```
72+
73+
### Notes ###
74+
75+
`altaz2hadec` converts Horizon (Alt-Az) coordinates to Hour Angle and
76+
Declination.
77+
78+
Code of this function is based on IDL Astronomy User's Library.
79+
"""
80+
hadec2altaz(ha::Real, dec::Real, lat::Real; ws::Bool=false) =
81+
_hadec2altaz(promote(float(ha), float(dec), float(lat))..., ws)
82+
83+
hadec2altaz(hadec::Tuple{Real, Real}, lat::Real; ws::Bool=false) =
84+
hadec2altaz(hadec..., lat, ws=ws)
85+
86+
function hadec2altaz(ha::AbstractArray{R}, dec::AbstractArray{<:Real},
87+
lat::AbstractArray{<:Real}; ws::Bool=false) where {R<:Real}
88+
@assert length(ha) == length(dec) == length(lat)
89+
typeha = float(R)
90+
alt = similar(ha, typeha)
91+
az = similar(ha, typeha)
92+
for i in eachindex(ha)
93+
alt[i], az[i] = hadec2altaz(ha[i], dec[i], lat[i], ws=ws)
94+
end
95+
return alt, az
96+
end

src/astrolib/jdcnv.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This file is a part of AstroLib.jl. License is MIT "Expat".
2+
# Copyright (C) 2016 Mosè Giordano.
3+
4+
"""
5+
jdcnv(date) -> julian_days
6+
7+
### Purpose ###
8+
9+
Convert proleptic Gregorian Calendar date in UTC standard to number of Julian
10+
days.
11+
12+
### Explanation ###
13+
14+
Takes the given proleptic Gregorian date in UTC standard and returns the number
15+
of Julian calendar days since epoch `-4713-11-24T12:00:00`.
16+
17+
### Argument ###
18+
19+
* `date`: date in proleptic Gregorian Calendar. Each element can be either a `DateTime` or
20+
anything that can be converted directly to `DateTime`.
21+
22+
### Output ###
23+
24+
Number of Julian days, as a floating point.
25+
26+
### Example ###
27+
28+
Find the Julian days number at 2016 August 23, 03:39:06.
29+
30+
```jldoctest
31+
julia> using AstroLib, Dates
32+
33+
julia> jdcnv(DateTime(2016, 08, 23, 03, 39, 06))
34+
2.4576236521527776e6
35+
36+
julia> jdcnv(2016, 08, 23, 03, 39, 06)
37+
2.4576236521527776e6
38+
39+
julia> jdcnv("2016-08-23T03:39:06")
40+
2.4576236521527776e6
41+
```
42+
43+
### Notes ###
44+
45+
This is the inverse of `daycnv`.
46+
47+
`get_juldate` returns the number of Julian days for current time. It is
48+
equivalent to `jdcnv(now(Dates.UTC))`.
49+
50+
For the conversion of Julian date to number of Julian days, use `juldate`.
51+
"""
52+
const jdcnv = Dates.datetime2julian
53+
jdcnv(date...) = jdcnv(DateTime(date...))

src/astrolib/sec2rad.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This file is a part of AstroLib.jl. License is MIT "Expat".
2+
# Copyright (C) 2016 Mosè Giordano.
3+
4+
"""
5+
sec2rad(sec) -> radians
6+
7+
### Purpose ###
8+
9+
Convert from seconds to radians.
10+
11+
### Argument ###
12+
13+
* `sec`: number of seconds.
14+
15+
### Output ###
16+
17+
The number of radians corresponding to `sec`.
18+
19+
### Example ###
20+
21+
```jldoctest
22+
julia> using AstroLib
23+
24+
julia> sec2rad(3600 * 30)
25+
0.5235987755982988
26+
```
27+
28+
### Notes ###
29+
30+
Use `rad2sec` to convert radians to seconds.
31+
"""
32+
sec2rad(sec::Real) = deg2rad(sec / 3600)

0 commit comments

Comments
 (0)