|
| 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) |
0 commit comments