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

Add AltAzCoords #40

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "1.0.0"

[deps]
AstroAngles = "5c4adb95-c1fc-4c53-b4ea-2a94080c53d2"
AstroLib = "c7932e45-9af1-51e7-9da9-f004cd3a462b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
Expand Down
22 changes: 22 additions & 0 deletions examples/observation_planning.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using SkyCoords, AstroTime, AstroAngles, AstroLib

# First we create the instance of the object in the sky we want to observe
M13 = ICRSCoords(250.423475 |> deg2rad, 36.4613194 |> deg2rad)

# Then we define the observation time and location
# We will use the top of Mount Wilson at 4AM UTC at Nov 8, 2021 which corresponds
# to 8PM the night before local time
mt_wilson = Observatory("Mount Wilson",32.2264,-118.0642,1693.25,-8)
time = from_utc("2021-11-08T04:00")
# We will need the julian date for the conversions, which we can do now
jd = julian(time) |> value

# Now we perform the conversion
altaz = AltAzCoords(M13,jd,mt_wilson)

# We may want to see this result in degrees, which is easy with rad2deg
# For this result, M13 is visible at an elevation of 12 degrees off the horizon
# and at a (true north) compass heading of 305.8, which is WNW.

# FIXME plot over time
# This is a few tenths of a degree off the astropy solution - why the difference?
36 changes: 35 additions & 1 deletion src/SkyCoords.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
__precompile__()

module SkyCoords
using StaticArrays
using StaticArrays, AstroLib

export AbstractSkyCoords,
ICRSCoords,
GalCoords,
FK5Coords,
AltAzCoords,
separation,
position_angle,
offset
Expand Down Expand Up @@ -95,6 +96,39 @@
zrotmat(-z) * yrotmat(theta) * zrotmat(-zeta)
end

# AltAz --> ICRS

# Conversion functions
# FIXME these should be matrix operations?
function AltAzCoords(icrs::ICRSCoords,jd::AbstractFloat,location::Observatory)
hour_angle = 360*ct2lst(location.longitude,jd)/24 - rad2deg(icrs.ra)
if hour_angle < 0
hour_angle = (hour_angle + 360) % 360

Check warning on line 106 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L103-L106

Added lines #L103 - L106 were not covered by tests
end
alt = asin(sin(icrs.dec)*sind(location.latitude) +

Check warning on line 108 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L108

Added line #L108 was not covered by tests
cos(icrs.dec)*cosd(location.latitude)*cosd(hour_angle))
a = acos((sin(icrs.dec) - sin(alt)*sind(location.latitude)) /

Check warning on line 110 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L110

Added line #L110 was not covered by tests
(cos(alt)*cosd(location.latitude)))
if sind(hour_angle) <= 0
az = a

Check warning on line 113 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L112-L113

Added lines #L112 - L113 were not covered by tests
else
az = 2π - a

Check warning on line 115 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L115

Added line #L115 was not covered by tests
end
return AltAzCoords(alt,az)

Check warning on line 117 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L117

Added line #L117 was not covered by tests
end

AltAzCoords(icrs::ICRSCoords,jd::T,lat::T,long::T) where T <: AbstractFloat = AltAzCoords(icrs,jd,Observatory("",lat,long,0,0))

Check warning on line 120 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L120

Added line #L120 was not covered by tests

# This isn't working yet
function ICRSCoords(altaz::AltAzCoords,time,location)
dec = asind(sin(altaz.alt)*sind(location.lat) +

Check warning on line 124 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L123-L124

Added lines #L123 - L124 were not covered by tests
cos(altaz.alt)*cosd(location.lat)*cos(altaz.az))
hour_angle = acosd((sin(altaz.alt)-sind(location.lat)*sind(dec)) /

Check warning on line 126 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L126

Added line #L126 was not covered by tests
(cosd(location.lat)*cos(dec)))
ra = local_sidereal_time(location,time) - hour_angle
return ICRSCoords(dec |> deg2rad,ra |> deg2rad)

Check warning on line 129 in src/SkyCoords.jl

View check run for this annotation

Codecov / codecov/patch

src/SkyCoords.jl#L128-L129

Added lines #L128 - L129 were not covered by tests
end

# -----------------------------------------------------------------------------
# Type-dependent methods

Expand Down
17 changes: 17 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@
FK5Coords{e}(c::T) where {e,T<:AbstractSkyCoords} = convert(FK5Coords{e}, c)
FK5Coords{e,F}(c::T) where {e,F,T<:AbstractSkyCoords} = convert(FK5Coords{e,F}, c)

"""
AltAzCoords(alt, az)

[Horizontal Coordinate System](https://en.wikipedia.org/wiki/Horizontal_coordinate_system)

This coordinate system uses the observer's local horizon as the fundamental plane to define an object in the local sky. The mapping to non-local coordinates requires a location and time. This is useful for planning observations with azimuthal mount telescopes.

# Coordinates
- `alt` - Angle between object and the observer's local horizon in radians (0, π/2)
- `az` - Angle of objectaround horizon, increasing eastward from true north (0, 2π)
"""
struct AltAzCoords{T<:AbstractFloat} <: AbstractSkyCoords
alt::T
az::T
end
AltAzCoords(alt::Real, az::Real) = AltAzCoords(promote(float(alt), float(az))...)

Check warning on line 88 in src/types.jl

View check run for this annotation

Codecov / codecov/patch

src/types.jl#L88

Added line #L88 was not covered by tests
# FIXME constructor from other coordinates

# Scalar coordinate conversions
Base.convert(::Type{T}, c::T) where {T<:AbstractSkyCoords} = c
Expand Down