-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
169 lines (142 loc) · 7.73 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python
# Copyright 2024 Martin Junius
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ChangeLog
# Version 0.0 / 2024-11-17
# Test with SkyCoord
import sys
import argparse
from datetime import datetime, UTC
# The following libs must be installed with pip
from icecream import ic
# Disable debugging
ic.disable()
# AstroPy
from astropy.coordinates import AltAz, EarthLocation, SkyCoord
from astropy.coordinates import ICRS, FK4, FK5, HADec # Low-level frames
from astropy.coordinates import Angle, Latitude, Longitude # Angles
import astropy.units as u
from astropy.time import Time, TimeDelta
# Local modules
from verbose import verbose, warning, error
VERSION = "0.0 / 2024-xx-xx"
AUTHOR = "Martin Junius"
NAME = "astropy-template"
# Command line options
class Options:
name = "abc" # -n --name
int = 99 # -i --int
def main():
arg = argparse.ArgumentParser(
prog = NAME,
description = "Astropy SkyCoord tests",
epilog = "Version " + VERSION + " / " + AUTHOR)
arg.add_argument("-v", "--verbose", action="store_true", help="verbose messages")
arg.add_argument("-d", "--debug", action="store_true", help="more debug messages")
arg.add_argument("object", nargs="*", help="sky coord \"RA DEC\"")
args = arg.parse_args()
if args.debug:
ic.enable()
ic(sys.version_info)
ic(args)
if args.verbose:
verbose.set_prog(NAME)
verbose.enable()
if args.object:
print("nothing happens ... ;-)")
return
for obj in args.object:
pass
### Test case ###
# NINA:
#
# 2024-11-22T22:06:20.8901|INFO|SequenceItem.cs|
# Run|208|Starting Category: Telescope, Item: Center, Coordinates RA: 03:57:26; Dec: -46° 11' 08"; Epoch: J2000
# 2024-11-22T22:06:20.9889|INFO|TelescopeVM.cs|
# SlewToCoordinatesAsync|926|Slewing from RA: 13:10:34; Dec: -82° 10' 33"; Epoch: JNOW to RA: 03:58:15; Dec: -46° 06' 45"; Epoch: JNOW - Alt: 51° 00' 18"; Az: 135° 44' 08"
# 2024-11-22T22:06:58.2396|INFO|ImageSolver.cs|
# Solve|54|Platesolve successful: Coordinates: RA: 03:56:49; Dec: -46° 10' 35"; Epoch: J2000
# 2024-11-22T22:06:58.2445|INFO|CenteringSolver.cs|
# Center|99|Centering Solver - Scope Position: RA: 03:58:15; Dec: -46° 06' 45"; Epoch: JNOW; Offset: RA: 00:00:00; Dec: 00° 00' 00"; Distance: 00° 00' 00"; Bearing: 00° 00' 00"; Centering Coordinates: RA: 03:58:15; Dec: -46° 06' 45"; Epoch: JNOW; Solved: RA: 03:57:38; Dec: -46° 06' 12"; Epoch: JNOW; Separation RA: 00:00:36; Dec: -00° 00' 33"; Distance: 00° 06' 17"; Bearing: 84° 58' 06"; Threshold: 0.5
#
# 2024-11-22T22:06:59.2706|INFO|TelescopeVM.cs|
# Sync|800|Syncing scope from RA: 03:58:15; Dec: -46° 06' 45"; Epoch: JNOW to RA: 03:57:38; Dec: -46° 06' 12"; Epoch: JNOW
# 2024-11-22T22:07:09.2757|INFO|CenteringSolver.cs|
# Center|132|Slewing to target after sync. Current Position: RA: 03:57:38; Dec: -46° 06' 12"; Epoch: JNOW; Target coordinates: RA: 03:58:15; Dec: -46° 06' 45"; Epoch: JNOW; Offset RA: 00:00:00; Dec: 00° 00' 00"; Distance: 00° 00' 00"; Bearing: 00° 00' 00"
# 2024-11-22T22:07:09.2790|INFO|TelescopeVM.cs|
# SlewToCoordinatesAsync|926|Slewing from RA: 03:57:38; Dec: -46° 06' 12"; Epoch: JNOW to RA: 03:58:15; Dec: -46° 06' 45"; Epoch: JNOW - Alt: 51° 08' 03"; Az: 135° 49' 13"
# 2024-11-22T22:07:30.8207|INFO|ImageSolver.cs|
# Solve|54|Platesolve successful: Coordinates: RA: 03:57:26; Dec: -46° 11' 07"; Epoch: J2000
# 2024-11-22T22:07:30.8318|INFO|CenteringSolver.cs|
# Center|99|Centering Solver - Scope Position: RA: 03:58:15; Dec: -46° 06' 45"; Epoch: JNOW; Offset: RA: 00:00:00; Dec: 00° 00' 00"; Distance: 00° 00' 00"; Bearing: 00° 00' 00"; Centering Coordinates: RA: 03:58:15; Dec: -46° 06' 45"; Epoch: JNOW; Solved: RA: 03:58:15; Dec: -46° 06' 44"; Epoch: JNOW; Separation RA: -00:00:00; Dec: -00° 00' 01"; Distance: 00° 00' 02"; Bearing: -68° 54' 32"; Threshold: 0.5
#
# Autoslew:
# 22:06:21.084: Interface SlewToTargetAsynch
# 22:06:21.084: Starting Slew to RA 03.97h DE -46.11d EPOCH 0000
# 22:06:58.259: Interface setting TargetRightAscension to 3.96 False
# 22:06:58.260: Interface setting TargetDeclination to -46.10 True
# 22:06:58.260: Interface SynchToTarget
# 22:07:09.282: Interface setting TargetRightAscension to 3.97 False
# 22:07:09.283: Interface setting TargetDeclination to -46.11 True
# 22:07:09.283: Interface SlewToTargetAsynch
# 22:07:09.283: Starting Slew to RA 03.97h DE -46.11d EPOCH 0000
obj = "03:57:25.611 -46:11:07.57" # SN 2024abfo
jnow = "03:58:15 -46:06:45" # NINA Epoch: JNOW - Alt: 51° 00' 18"; Az: 135° 44' 08"
autoslew = "03h58m14.52s -46d06m45s" # Autoslew position with Ep: "real"
loc = EarthLocation(lat=-23.23639*u.deg, lon=16.36167*u.deg , height=1825*u.m) # Hakos, Namibia
time = Time("2024-11-22 20:06:20", location=loc)
ic(obj, jnow, autoslew, loc, time)
coord = SkyCoord(obj, unit=(u.hour, u.deg))
ic(coord)
print(f"coord ICRS {coord.to_string("hmsdms")}")
print(f"Autoslew M49 {autoslew}")
print()
# From https://www.cloudynights.com/topic/861776-asiair-small-program-to-convert-from-j2000-to-jnow/
# _fk5 = FK5(equinox=Time(Time(datetime.now(UTC), scale='utc').jd, format="jd", scale="utc"))
# coord_now = SkyCoord(object, frame=FK4, unit=(u.hourangle, u.deg)).transform_to(_fk5)
# ic(_fk5, coord_now)
# print(f"coord now={coord_now.to_string("hmsdms")}")
# ic(coord_now.ra - coord.ra, coord_now.dec - coord.dec)
coord1 = coord.transform_to(FK5(equinox="J2000"))
ic(coord1)
print(f"coord FK5 J2000 {coord1.to_string("hmsdms")}")
coord2 = coord.transform_to(FK5(equinox=Time(time, format="jyear")))
ic(coord2)
print(f"coord FK5 time {coord2.to_string("hmsdms")}")
hadec1 = coord.transform_to(HADec(obstime=time, location=loc))
hadec2 = coord.transform_to(HADec(obstime=time, location=loc,
pressure=1000*u.hPa, temperature=20*u.deg_C,
relative_humidity=0.4, obswl=0.54*u.micron))
lst = time.sidereal_time("mean")
lsta = time.sidereal_time("apparent")
ra1 = lst - hadec1.ha
if ra1 >= 24*u.hourangle:
ra1 -= 24*u.hourangle
ra1a = lsta - hadec1.ha
if ra1a >= 24*u.hourangle:
ra1a -= 24*u.hourangle
ra2 = lst - hadec2.ha
if ra2 >= 24*u.hourangle:
ra2 -= 24*u.hourangle
ic(lst, lsta, ra1, ra1a, ra2)
ic(hadec1, ra1.to_string(unit=u.hour), hadec1.dec.to_string(unit=u.degree))
ic(hadec1, ra1a.to_string(unit=u.hour), hadec1.dec.to_string(unit=u.degree))
ic(hadec2, ra2.to_string(unit=u.hour), hadec2.dec.to_string(unit=u.degree))
print(f"lst mean {lst.to_string(unit=u.hour)}, lst apparent {lsta.to_string(unit=u.hour)}")
print(f"ha {hadec1.ha.to_string(unit=u.degree)}")
print(f"hadec1 time mean {ra1.to_string(unit=u.hour)} {hadec1.dec.to_string(unit=u.degree)}")
print(f"hadec1 time app. {ra1a.to_string(unit=u.hour)} {hadec1.dec.to_string(unit=u.degree)}")
print(f"hadec2 now refr. {ra2.to_string(unit=u.hour)} {hadec2.dec.to_string(unit=u.degree)}")
if __name__ == "__main__":
main()