-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPySkyX_ks.py
2095 lines (1619 loc) · 76.9 KB
/
PySkyX_ks.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python3.4
import sys
print(sys.executable)
#
# Python library for automating SkyX
#
# Ken Sturrock
# August 05, 2018
#
TSXHost = "127.0.0.1" # You can set this if you want to run the functions remotely
# The "*Remote functions" already handle that internally.
TSXPort = 3040 # 3040 is the default, it can be changed
verbose = False # Set this to "True" for debugging to see the Javascript traffic.
CR = "\n" # A prettier shortcut for a newline.
import time
import socket
import os
import random
import math
import pathlib
def slewToCoords(coords, name):
slew_count = 0
ra = coords[0]
dec = coords[1]
print("Slewing to " + ra + " " + dec)
if TSXSend("sky6RASCOMTele.IsParked()") == "true":
print(" NOTE: Unparking mount.")
TSXSend("sky6RASCOMTele.Unpark()")
if str(TSXSend("SelectedHardware.mountModel") != "Telescope Mount Simulator"):
TSXSend("sky6RASCOMTele.SetTracking(1, 1, 0 ,0)")
TSXSend("sky6RASCOMTele.Asynchronous = true")
TSXSend('sky6RASCOMTele.SlewToRaDec(' + ra + ', ' + dec + ', "' + name + '")')
time.sleep(0.5)
while TSXSend("sky6RASCOMTele.IsSlewComplete") == "0":
if slew_count > 119:
print(" ERROR: Mount appears stuck!")
timeStamp("Sending abort command.")
# sky6RASCOMTele.Abort()
if TSXSend("SelectedHardware.mountModel") != "Telescope Mount Simulator":
time.sleep(5)
timeStamp("Trying to stop sidereal motor.")
TSXSend("sky6RASCOMTele.SetTracking(0, 1, 0 ,0)")
timeStamp("Stopping script.")
sys.exit()
else:
print(" NOTE: Slew in progress.")
slew_count = slew_count + 1
time.sleep(10)
if "Process aborted." in TSXSend("sky6RASCOMTele.IsSlewComplete"):
timeStamp("Script Aborted.")
sys.exit()
TSXSend("sky6RASCOMTele.Asynchronous = false")
print("Completed slew")
TSXSend("sky6RASCOMTele.GetAzAlt()")
mntAz = round(float(TSXSend("sky6RASCOMTele.dAz")), 2)
mntAlt = round(float(TSXSend("sky6RASCOMTele.dAlt")), 2)
print("NOTE: Mount currently at: " + str(mntAz) + " az., " + str(mntAlt) + " alt.")
def openDome():
if TSXSend("sky6Dome.IsConnected") == "0":
TSXSend("sky6Dome.Connect()")
print("Connected Dome")
print("Opening dome...")
TSXSend("sky6Dome.OpenSlit()")
print("Waiting... 30 s remaining")
time.sleep(10)
print("Waiting... 20 s remaining")
time.sleep(10)
print("Waiting... 10 s remaining")
time.sleep(10)
while TSXSend("sky6Dome.IsOpenComplete") == "0":
pass
if TSXSend("sky6Dome.slitState()") == "1" or TSXSend("sky6Dome.slitState()") == "3":
print("Successfully opened dome")
else:
raise Exception("Dome open not successful!")
def closeDome():
if TSXSend("sky6Dome.IsConnected") == "0":
TSXSend("sky6Dome.Connect()")
print("Connected Dome")
print("Closing dome...")
TSXSend("sky6Dome.CloseSlit()")
print("Waiting... 30 s remaining")
time.sleep(10)
print("Waiting... 20 s remaining")
time.sleep(10)
print("Waiting... 10 s remaining")
time.sleep(10)
while TSXSend("sky6Dome.IsCloseComplete") == "0":
pass
if TSXSend("sky6Dome.slitState()") == "2" or TSXSend("sky6Dome.slitState()") == "4":
print("Successfully closed dome")
else:
raise Exception("Dome close not successful!")
def domeDisconnect():
if TSXSend("sky6Dome.IsConnected") == "0":
print("Dome already disconnected")
else:
print("Disconnecting dome")
TSXSend("sky6Dome.Disconnect()")
if TSXSend("sky6Dome.IsConnected") == "0":
print("Sucessfully disconnected dome")
def findDomeHome():
if TSXSend("sky6Dome.IsConnected") == "0":
TSXSend("sky6Dome.Connect()")
print("Connected Dome")
print("Finding home...")
TSXSend("sky6Dome.FindHome()")
print("Waiting... 60 s remaining")
time.sleep(20)
print("Waiting... 40 s remaining")
time.sleep(20)
print("Waiting... 20 s remaining")
time.sleep(20)
print("Dome successfully found home")
def connectMount():
TSXSend("sky6RASCOMTele.Connect()")
if TSXSend("sky6RASCOMTele.IsConnected") == "1":
print("Successfully connected mount")
else:
raise Exception("Unsuccessful mount connection")
print("Finding home...")
TSXSend("sky6RASCOMTele.FindHome()")
if TSXSend("sky6RASCOMTele.IsTracking") == "1":
print("Mout found home, tracking at sidereal rate")
def parkAndDisconnectMount():
print("Parking mount...")
TSXSend("sky6RASCOMTele.Park()")
if TSXSend("sky6RASCOMTele.IsConnected") == "0":
print("Successfully parked and disconnected mount")
else:
raise Exception("Unsuccessful park and disconnect")
def adjAGExposure(origAGExp, origAGDelay, XCoord, YCoord):
#
# Measure the brightness of the selected guide star and suggest tweaks
# if the star is really bright or really dim. Ideally, the star should
# not be saturated, because the star finder wouldn't have suggested it.
#
#
if TSXSend("ccdsoftAutoguider.ImageReduction") != "0":
print(" NOTE: Measuring AG exposure.")
imageDepth = TSXSend('ccdsoftAutoguiderImage.FITSKeyword("BITPIX")')
if "Error = 250" in imageDepth:
print(" ERROR: FITS Keyword BITPIX not found. Assuming 16-bit.")
imageDepth = 16
newXCoord = float(TSXSend('ccdsoftAutoguider.BinX')) * float(XCoord)
newYCoord = float(TSXSend('ccdsoftAutoguider.BinY')) * float(YCoord)
boxSizeVert = int(float(TSXSend("ccdsoftAutoguider.TrackBoxY")) / 2)
boxSizeHoriz = int(float(TSXSend("ccdsoftAutoguider.TrackBoxX")) / 2)
newTop = int(newYCoord - boxSizeVert)
newBottom = int(newYCoord + boxSizeVert)
newLeft = int(newXCoord - boxSizeHoriz)
newRight = int(newXCoord + boxSizeHoriz)
TSXSend("ccdsoftAutoguider.SubframeTop = " + str(newTop))
TSXSend("ccdsoftAutoguider.SubframeLeft = " + str(newLeft))
TSXSend("ccdsoftAutoguider.SubframeBottom = " + str(newBottom))
TSXSend("ccdsoftAutoguider.SubframeRight = " + str(newRight))
TSXSend("ccdsoftAutoguider.Subframe = true")
TSXSend("ccdsoftAutoguider.Delay = 1")
TSXSend("ccdsoftAutoguider.AutoSaveOn = false")
TSXSend("ccdsoftAutoguider.ExposureTime = " + origAGExp)
TSXSend("ccdsoftAutoguider.TakeImage()")
fullWell = math.pow(2, int(imageDepth))
brightestPix = TSXSend("ccdsoftAutoguider.MaximumPixel")
brightness = round((int(brightestPix) / int(fullWell)), 2)
print(" NOTE: AG Brightness: " + str(brightness))
totalTime = float(origAGExp) + float(origAGDelay)
if brightness >= 0.2 and brightness <= 0.8:
print(" NOTE: No guider exposure change recommended.")
return str(origAGExp) + "," + str(origAGDelay)
else:
units = brightness / float(origAGExp)
if brightness > 0.8:
print(" NOTE: Star too bright.")
while brightness > 0.9:
origAGExp = float(origAGExp) / 2
TSXSend("ccdsoftAutoguider.ExposureTime = " + str(origAGExp))
TSXSend("ccdsoftAutoguider.TakeImage()")
fullWell = math.pow(2, int(imageDepth))
brightestPix = TSXSend("ccdsoftAutoguider.MaximumPixel")
brightness = round((int(brightestPix) / int(fullWell)), 2)
print(" NOTE: Exposure: " + str(origAGExp) + " Brightness: " + str(brightness))
units = brightness / float(origAGExp)
newExp = 0.50 / units
if brightness < 0.2:
newExp = 0.3 / units
newExp = round(newExp, 1)
newDelay = float(totalTime) - float(newExp)
newDelay = round(newDelay, 1)
if newDelay < 0:
newDelay = 0
if newExp > (float(origAGExp) * 1.5):
newExp = (float(origAGExp) * 1.5)
print(" NOTE: Recommend AG exposure of " + str(newExp) + " and a delay of " + str(newDelay) + ".")
return str(newExp) + "," + str(newDelay)
else:
print(" NOTE: AG exposure not adjusted because guider is not calibrated.")
return str(origAGExp) + "," + str(origAGDelay)
def atFocus2(target, filterNum):
#
# Focus using @F2. Because @Focus2 will sometimes do annoying stuff
# like choosing a focus star on the wrong side of the meridian,
# we force the mount to jog east or west to get it away from the
# meridian if needed.
#
if targHA(target) < 0.75 and targHA(target) > -0.75:
print(" NOTE: Target is near the meridian.")
if TSXSend("SelectedHardware.mountModel") != "Telescope Mount Simulator":
TSXSend('sky6RASCOMTele.DoCommand(11, "")')
if TSXSend("sky6RASCOMTele.DoCommandOutput") == "1":
TSXSend('sky6RASCOMTele.Jog(420, "E")')
print(" NOTE: OTA is west of the meridian pointing east.")
print(" NOTE: Slewing towards the east, away from meridian.")
else:
TSXSend('sky6RASCOMTele.Jog(420, "W")')
print(" NOTE: OTA is east of the meridian, pointing west.")
print(" NOTE: Slewing towards the west, away from meridian.")
if TSXSend("SelectedHardware.filterWheelModel") != "<No Filter Wheel Selected>":
TSXSend("ccdsoftCamera.filterWheelConnect()")
TSXSend("ccdsoftCamera.FilterIndexZeroBased = " + filterNum)
if TSXSend("ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1":
timeStamp("@Focus2 success (simulated). Position = " + TSXSend("ccdsoftCamera.focPosition"))
print(" NOTE: Returning to target.")
if CLSlew(target, filterNum) == "Fail":
hardPark()
return "Success"
else:
result = TSXSend("ccdsoftCamera.AtFocus2()")
if "Process aborted." in result:
timeStamp("Script Aborted.")
sys.exit()
if "Error" in result:
timeStamp("@Focus2 failed: " + result)
if CLSlew(target, filterNum) == "Fail":
hardPark()
return "Fail"
else:
TSXSend("sky6ObjectInformation.Property(0)")
TSXSend("sky6ObjectInformation.ObjInfoPropOut")
timeStamp("@Focus2 success. Position = " + TSXSend("ccdsoftCamera.focPosition") + ". Star = " \
+ TSXSend("sky6ObjectInformation.ObjInfoPropOut"))
if CLSlew(target, filterNum) == "Fail":
hardPark()
return "Success"
def atFocus2Both(host, target, filterNum):
#
# Butchered version of @Focus2 routine to add a second camera.
#
# The only difference is that it calls the remote @Focus2 routine
# before slewing (both) back to target.
#
# It would probably be a lot easier to just use @Focus3 on the remote
# camera. If you use @Focus2, though, make sure that you calibrate
# the remote @Focus2 to use ther same magnitude stars as the main
# camera uses.
#
if targHA(target) < 0.75 and targHA(target) > -0.75:
print(" NOTE: Target is near the meridian.")
if TSXSend("SelectedHardware.mountModel") != "Telescope Mount Simulator":
TSXSend('sky6RASCOMTele.DoCommand(11, "")')
if TSXSend("sky6RASCOMTele.DoCommandOutput") == "1":
TSXSend('sky6RASCOMTele.Jog(420, "E")')
print(" NOTE: OTA is west of the meridian pointing east.")
print(" NOTE: Slewing towards the east, away from meridian.")
else:
TSXSend('sky6RASCOMTele.Jog(420, "W")')
print(" NOTE: OTA is east of the meridian, pointing west.")
print(" NOTE: Slewing towards the west, away from meridian.")
if TSXSend("SelectedHardware.filterWheelModel") != "<No Filter Wheel Selected>":
TSXSend("ccdsoftCamera.filterWheelConnect()")
TSXSend("ccdsoftCamera.FilterIndexZeroBased = " + filterNum)
if TSXSend("ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1":
timeStamp("@Focus2 success (simulated). Position = " + TSXSend("ccdsoftCamera.focPosition"))
atFocusRemote(host, "Imager", "Two", filterNum)
slewRemote(host, target)
if CLSlew(target, filterNum) == "Fail":
hardPark()
return "Success"
else:
result = TSXSend("ccdsoftCamera.AtFocus2()")
if "Process aborted." in result:
timeStamp("Script Aborted.")
sys.exit()
if "Error" in result:
timeStamp("@Focus2 failed: " + result)
if CLSlew(target, filterNum) == "Fail":
hardPark()
return "Fail"
else:
timeStamp("@Focus2 success. Position = " + TSXSend("ccdsoftCamera.focPosition"))
atFocusRemote(host, "Imager", "Two", filterNum)
slewRemote(host, target)
if CLSlew(target, filterNum) == "Fail":
hardPark()
return "Success"
def atFocus3(target, filterNum):
#
# This function runs @Focus3.
#
# Be aware that, if you're using this function, it's probably because you're
# trying to automate something. In which case, you're probably also dithering
# and you're also probably asleep. Even though @F3 doesn't require a slew back
# to target, this routine includes some code to periodically CLS back to
# your target both to reset the dither pattern and also because bad stuff
# happens and an occasional Return to Zero isn't bad. Until your mount comes
# back around. Specify target as "NoRTZ" to skip the recenter (for example, on
# the initial focus).
#
# The @Focus3 JS command, itself, has two parameters. The "3" can be replaced by
# some other number to tell it how many samples to take & average at each position.
# Don't bother with two samples. Use one sample if your skies are great, five if
# terrible and three for most places. The "true" tells it to select a subframe
# automatically. If you use "false" then you will have to define your own subframe
# or it will focus full-frame. It extracts the step size from the INI which you'll
# have to set with the @F3 dialog box during a previous run.
#
timeStamp("Focusing with @Focus3.")
if TSXSend("SelectedHardware.filterWheelModel") != "<No Filter Wheel Selected>":
TSXSend("ccdsoftCamera.filterWheelConnect()")
TSXSend("ccdsoftCamera.FilterIndexZeroBased = " + filterNum)
if TSXSend("ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1":
timeStamp("@Focus3 success (simulated). Position = " + TSXSend("ccdsoftCamera.focPosition"))
if target != "NoRTZ":
if random.choice('12') == "2":
print(" NOTE: Recentering target.")
if CLSlew(target, filterNum) == "Fail":
hardPark()
else:
print(" NOTE: Not recentering target at this time.")
return "Success"
else:
result = TSXSend("ccdsoftCamera.AtFocus3(3, true)")
if "Process aborted." in result:
timeStamp("Script Aborted.")
sys.exit()
if "Error" in result:
timeStamp("@Focus3 failed: " + result)
if target != "NoRTZ":
if random.choice('12') == "2":
print(" NOTE: Recentering target.")
if CLSlew(target, filterNum) == "Fail":
hardPark()
else:
print(" NOTE: Not recentering target at this time.")
return "Fail"
else:
timeStamp("@Focus3 success. Position = " + TSXSend("ccdsoftCamera.focPosition"))
if target != "NoRTZ":
if random.choice('12') == "2":
print(" NOTE: Recentering target.")
if CLSlew(target, filterNum) == "Fail":
hardPark()
else:
print(" NOTE: Not recentering target at this time.")
return "Success"
def atFocusRemote(host, whichCam, method, filterNum):
#
# This is for focusing a second (or third) remote camera
#
time.sleep(5)
TSXSendRemote(host, "ccdsoftCamera.Asynchronous = false")
if whichCam not in ("Imager", "Guider"):
print(" ERROR: Please specify remote camera as either: Imager or Guider.")
if whichCam == "Imager":
if TSXSendRemote(host, "SelectedHardware.filterWheelModel") != "<No Filter Wheel Selected>":
TSXSendRemote(host, "ccdsoftCamera.filterWheelConnect()")
TSXSendRemote(host, "ccdsoftCamera.FilterIndexZeroBased = " + filterNum)
if whichCam == "Guider":
if TSXSendRemote(host, "SelectedHardware.autoguiderFilterWheelModel") != "<No Filter Wheel Selected>":
TSXSendRemote(host, "ccdsoftAutoguider.filterWheelConnect()")
TSXSendRemote(host, "ccdsoftAutoguider.FilterIndexZeroBased = " + filterNum)
if whichCam == "Imager":
if method == "Three":
timeStamp("Focusing remote imaging camera with @Focus3.")
if (TSXSendRemote(host, "ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1") or \
(TSXSendRemote(host, "SelectedHardware.focuserModel") == "<No Focuser Selected>"):
if TSXSendRemote(host, "ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1":
timeStamp(
"@Focus3 success (simulated). Position = " + TSXSendRemote(host, "ccdsoftCamera.focPosition"))
return "Success"
else:
timeStamp("No remote focuser detected.")
return "Success"
else:
result = TSXSendRemote(host, "ccdsoftCamera.AtFocus3(3, true)")
if "Process aborted." in result:
timeStamp("Script Aborted.")
sys.exit()
if "Error" in result:
timeStamp("Remote @Focus3 failed: " + result)
return "Fail"
else:
timeStamp("@Focus3 success. Position = " + TSXSendRemote(host, "ccdsoftCamera.focPosition"))
time.sleep(5)
return "Success"
if method == "Two":
timeStamp("Focusing remote imaging camera with @Focus2.")
if (TSXSendRemote(host, "ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1") or \
(TSXSendRemote(host, "SelectedHardware.focuserModel") == "<No Focuser Selected>"):
if TSXSendRemote(host, "ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1":
timeStamp(
"@Focus2 success (simulated). Position = " + TSXSendRemote(host, "ccdsoftCamera.focPosition"))
return "Success"
else:
timeStamp("No remote focuser detected.")
return "Success"
else:
result = TSXSendRemote(host, "ccdsoftCamera.AtFocus2()")
if "Process aborted." in result:
timeStamp("Script Aborted.")
sys.exit()
if "Error" in result:
timeStamp("Remote @Focus2 failed: " + result)
return "Fail"
else:
timeStamp("@Focus2 success. Position = " + TSXSendRemote(host, "ccdsoftCamera.focPosition"))
time.sleep(5)
return "Success"
if whichCam == "Guider":
if method == "Three":
timeStamp("Focusing remote guiding camera with @Focus3.")
if (TSXSendRemote(host, "ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1") or \
(TSXSendRemote(host, "SelectedHardware.focuserModel") == "<No Focuser Selected>"):
if TSXSendRemote(host, "ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1":
timeStamp(
"@Focus3 success (simulated). Position = " + TSXSendRemote(host, "ccdsoftCamera.focPosition"))
return "Success"
else:
timeStamp("No remote focuser detected.")
return "Success"
else:
result = TSXSendRemote(host, "ccdsoftAutoguider.AtFocus3(3, true)")
if "Process aborted." in result:
timeStamp("Script Aborted.")
sys.exit()
if "Error" in result:
timeStamp("Remote @Focus3 failed: " + result)
return "Fail"
else:
timeStamp("@Focus3 success. Position = " + TSXSendRemote(host, "ccdsoftAutoguider.focPosition"))
return "Success"
if method == "Two":
timeStamp("Focusing remote guiding camera with @Focus2.")
if (TSXSendRemote(host, "ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1") or \
(TSXSendRemote(host, "SelectedHardware.focuserModel") == "<No Focuser Selected>"):
if TSXSendRemote(host, "ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1":
timeStamp(
"@Focus2 success (simulated). Position = " + TSXSendRemote(host, "ccdsoftCamera.focPosition"))
return "Success"
else:
timeStamp("No remote focuser detected.")
return "Success"
else:
result = TSXSendRemote(host, "ccdsoftAutoguider.AtFocus2()")
if "Process aborted." in result:
timeStamp("Script Aborted.")
sys.exit()
if "Error" in result:
timeStamp("Remote @Focus2 failed: " + result)
return "Fail"
else:
timeStamp("@Focus2 success. Position = " + TSXSendRemote(host, "ccdsoftAutoguider.focPosition"))
return "Success"
timeStamp("Remote focus completed.")
def calcImageScale(whichCam):
#
# Return the image scale for the supplied camera: Imager or Guider.
#
if whichCam not in ("Imager", "Guider"):
print(" ERROR: Please specify camera as either: Imager or Guider.")
return "Fail"
else:
FITSProblem = "No"
tempImage = "No"
if whichCam == "Imager":
camDevice = "ccdsoftCamera"
camImage = "ccdsoftCameraImage"
camAttachment = "AttachToActiveImager()"
else:
camDevice = "ccdsoftAutoguider"
camImage = "ccdsoftAutoguiderImage"
camAttachment = "AttachToActiveAutoguider()"
if "206" in str(TSXSend(camImage + "." + camAttachment)):
print(" NOTE: No current image available.")
tempImage = "Yes"
if "Error" in takeImage(whichCam, "1", "0", "0"):
softPark()
TSXSend(camImage + "." + camAttachment)
if TSXSend(camDevice + ".ImageUseDigitizedSkySurvey") == "1":
FITSProblem = "Yes"
else:
if "250" in str(TSXSend(camImage + '.FITSKeyword("FOCALLEN")')):
print(" NOTE: FOCALLEN keyword not found in FITS header.")
FITSProblem = "Yes"
if "250" in str(TSXSend(camImage + '.FITSKeyword("XPIXSZ")')):
print(" NOTE: XPIXSZ keyword not found in FITS header.")
FITSProblem = "Yes"
if FITSProblem == "Yes":
ImageScale = 1.70
else:
FocalLength = TSXSend(camImage + '.FITSKeyword("FOCALLEN")')
PixelSize = TSXSend(camImage + '.FITSKeyword("XPIXSZ")')
Binning = TSXSend(camImage + '.FITSKeyword("XBINNING")')
#
# This "real" stuff is needed because T-Point loves to automagically
# switch your automated ImageLink settings to 2x2 binning which requires
# us to devide the reported pixel size by the binning and then rescale
# according to the selected imaging binning for the camera
#
realPixelSize = (float(PixelSize) / float(Binning))
realBinning = TSXSend(camDevice + '.BinX')
ImageScale = ((float(realPixelSize) * float(realBinning)) / float(FocalLength)) * 206.3
ImageScale = round(float(ImageScale), 2)
if tempImage == "Yes":
Path = TSXSend(camImage + ".Path")
if os.path.exists(Path):
os.remove(Path)
print(" NOTE: " + whichCam + " image scale is " + str(ImageScale) + " AS/Pixel.")
return ImageScale
def calcSettleLimit():
#
# Calculate a reasonable settle threshold based on image scale
#
timeStamp("Determining guider settle limit.")
AGImageScale = calcImageScale("Guider")
ImageScale = calcImageScale("Imager")
pixelRatio = ImageScale / AGImageScale
pixelRatio = round(pixelRatio, 2)
print(" NOTE: Image scale ratio set to: " + str(pixelRatio) + ".")
settleThreshold = round((pixelRatio * 0.95), 2)
#
# This was done because my Takahashi mounts track like drunk sailors.
#
if TSXSend('ccdsoftCamera.PropStr("m_csObserver")') == "Ken Sturrock":
if "Temma" in TSXSend("SelectedHardware.mountModel"):
settleThreshold = 3
print(" NOTE: Settle range enlarged for Ken's Temmas")
#
# I have no confidence that less than 1/5 of a pixel is a realistic expectation.
# Remember that the settle threshold doesn't affect the guider's performance,
# it just sets how long the script waits before moving on.
#
if settleThreshold < 0.2:
settleThreshold = 0.2
print(" NOTE: Calculated settle limit: " + str(settleThreshold) + " guider pixels.")
return settleThreshold
def camConnect(whichCam):
#
# This function connects the specified camera
#
if whichCam == "Guider":
out = TSXSend("ccdsoftAutoguider.Connect()")
elif whichCam == "Imager":
TSXSend("ccdsoftCamera.Disconnect()")
if str(TSXSend('ccdsoftCamera.PropStr("m_csObserver")')) == "Ken Sturrock":
print(" NOTE: Setting imaging camera to -10.")
TSXSend("ccdsoftCamera.TemperatureSetPoint = -10")
TSXSend("ccdsoftCamera.RegulateTemperature = true")
time.sleep(1)
out = TSXSend("ccdsoftCamera.Connect()")
else:
out = "Unknown Camera: " + whichCam
if out != "0":
timeStamp("Unable to connect: " + whichCam)
return "Fail"
else:
print("Successfully connected camera")
return "Success"
def camDisconnect(whichCam):
#
# This function disconnects the specified camera
#
if whichCam == "Guider":
out = TSXSend("ccdsoftAutoguider.Disconnect()")
elif whichCam == "Imager":
out = TSXSend("ccdsoftCamera.Disconnect()")
else:
out = "Unknown Camera: " + whichCam
if out != "0":
timeStamp("Unable to disconnect: " + whichCam)
return "Fail"
else:
print("Successfully disconnected camera")
return "Success"
def camConnectRemote(host, whichCam):
#
# This function connects the specified camera
#
if whichCam == "Guider":
out = TSXSendRemote(host, "ccdsoftAutoguider.Connect()")
elif whichCam == "Imager":
TSXSendRemote(host, "ccdsoftCamera.Disconnect()")
if str(TSXSend('ccdsoftCamera.PropStr("m_csObserver")')) == "Ken Sturrock":
TSXSendRemote(host, "ccdsoftCamera.TemperatureSetPoint = -10")
TSXSendRemote(host, "ccdsoftCamera.RegulateTemperature = true")
time.sleep(1)
out = TSXSendRemote(host, "ccdsoftCamera.Connect()")
else:
out = "Unknown Camera: " + whichCam
if out != "0":
timeStamp("Unable to connect: " + whichCam)
return "Fail"
else:
return "Success"
def camDisconnectRemote(host, whichCam):
#
# This function disconnects the specified camera
#
if whichCam == "Guider":
out = TSXSendRemote(host, "ccdsoftAutoguider.Disconnect()")
elif whichCam == "Imager":
out = TSXSendRemote(host, "ccdsoftCamera.Disconnect()")
else:
out = "Unknown Camera: " + whichCam
if out != "0":
timeStamp("Unable to disconnect: " + whichCam)
return "Fail"
else:
return "Success"
def cloudWait():
#
# Switch off the sidereal drive and wait five minutes.
# Then, keep checking for stars every five minutes for
# the next 25 minutes.
#
shouldWait = "Yes"
counter = 1
timeStamp("Waiting five minutes. (1 of 5)")
if TSXSend("SelectedHardware.mountModel") != "Telescope Mount Simulator":
TSXSend("sky6RASCOMTele.SetTracking(0, 1, 0 ,0)")
camDisconnect("Guider")
camDisconnect("Imager")
time.sleep(300)
counter = counter + 1
while shouldWait == "Yes" and counter <= 5:
if str(TSXSend("SelectedHardware.mountModel") != "Telescope Mount Simulator"):
TSXSend("sky6RASCOMTele.SetTracking(1, 1, 0 ,0)")
time.sleep(10)
timeStamp("Testing sky for clouds.")
camConnect("Guider")
takeImage("Guider", "5", "0", "NA")
AGStar = findAGStar()
if not "Error" in AGStar:
shouldWait = "No"
timeStamp("Sky appears clear.")
else:
timeStamp("Sky still appears cloudy.")
camDisconnect("Guider")
if TSXSend("SelectedHardware.mountModel") != "Telescope Mount Simulator":
TSXSend("sky6RASCOMTele.SetTracking(0, 1, 0 ,0)")
print(" NOTE: Waiting five minutes. (" + str(counter) + " of 5)")
time.sleep(300)
if shouldWait == "Yes":
print(" NOTE: Attempting to continue.")
camConnect("Guider")
camConnect("Imager")
if str(TSXSend("SelectedHardware.mountModel") != "Telescope Mount Simulator"):
TSXSend("sky6RASCOMTele.SetTracking(1, 1, 0 ,0)")
time.sleep(10)
def CLSlew(target, filterNum):
#
# This uses Closed Loop Slew to precisely center the target.
#
# There is a hack, however, because it uses regular slew to "pre-slew" to the
# target before evoking Closed Loop Slew. This is done because I own a slow
# mount which might time out with a regular CLS. In practice, it adds no real
# time penalty, so I do it for all mounts. The 10 second delay is also a
# Temma mitigation stratedgy to make sure that the mount really has stopped
# moving before the image is taken.
#
# Finally, you guessed it, the resynch is important for a poor-pointing mount
# like my Takahashi.
#
slew(target)
timeStamp("Attempting precise positioning with CLS.")
if TSXSend("SelectedHardware.filterWheelModel") != "<No Filter Wheel Selected>":
TSXSend("ccdsoftCamera.filterWheelConnect()")
TSXSend("ccdsoftCamera.FilterIndexZeroBased = " + filterNum)
if TSXSend("ccdsoftCamera.ImageUseDigitizedSkySurvey") == "1":
timeStamp("CLS to " + target + " success (simulated).")
return "Success"
else:
camDelay = TSXSend("ccdsoftCamera.Delay")
TSXSend("ccdsoftCamera.Delay = 10")
CLSResults = TSXSend("ClosedLoopSlew.exec()")
if "failed" in CLSResults:
if "651" in CLSResults:
CLSResults = "Not Enough Stars in the Photo. Error = 651"
print(" ERROR: " + CLSResults)
timeStamp("CLS to " + target + " failed.")
TSXSend("ccdsoftCamera.Delay = " + camDelay)
return "Fail"
else:
TSXSend('sky6StarChart.Find("Z 90")')
TSXSend('sky6StarChart.Find("' + target + '")')
iScale = TSXSend("ImageLinkResults.imageScale")
timeStamp("CLS to " + target + " success (" + iScale + " AS/pixel).")
TSXSend("ccdsoftCamera.Delay = " + camDelay)
if "Temma" in TSXSend("SelectedHardware.mountModel"):
reSynch()
return "Success"
def dither():
#
# This function dithers the mount based on image scale and declination
#
# It does not "guide to the destination". You must stop guiding and then
# restart it after.
#
timeStamp("Calculating dither distance.")
imageScale = calcImageScale("Imager")
if imageScale != "Fail":
maxMove = (imageScale * 6)
ditherXsec = maxMove * random.uniform(0.1, 1)
ditherYsec = maxMove * random.uniform(0.1, 1)
TSXSend("sky6ObjectInformation.Property(55)")
targDec = TSXSend("sky6ObjectInformation.ObjInfoPropOut")
targRads = abs(float(targDec)) * (3.14159 / 180)
radsValue = math.cos(targRads)
decFactor = (1 / radsValue)
if decFactor > 10:
decFactor = 10
ditherYsec = ditherYsec * decFactor
ditherXMin = ditherXsec * 0.01666666666
ditherYMin = ditherYsec * 0.01666666666
NorS = random.choice([True, False])
if NorS == True:
NorS = "N"
else:
NorS = "S"
EorW = random.choice([True, False])
if EorW == True:
EorW = "E"
else:
EorW = "W"
TSXSend('sky6RASCOMTele.Jog(' + str(ditherXMin) + ', "' + str(NorS) + '")')
time.sleep(1)
TSXSend('sky6RASCOMTele.Jog(' + str(ditherYMin) + ', "' + str(EorW) + '")')
time.sleep(1)
timeStamp("Dithered: " + str(round(ditherXsec, 1)) + " AS (" + str(NorS) + "), " + str(
round(ditherYsec, 1)) + " AS (" + str(EorW) + ")")
time.sleep(5)
if TSXSend('ccdsoftCamera.PropStr("m_csObserver")') == "Ken Sturrock":
if "Temma" in TSXSend("SelectedHardware.mountModel"):
print(" NOTE: Pausing 30 seconds to take-up backlash for Ken's Temmas.")
time.sleep(30)
def findAGStar():
#
# This incredible mess is a straight copy of JS code into a "here document".
#
# If you want to grok what it's doing, check out the "diagnostic" version in
# the original bash/JS script set JS_Codons directory.
#
# This code includes ideas (and code) from Ken Sturrock, Colin McGill and
# Kym Haines. Although it's probably not recognizable by any of us.
#
# Someday, I may re-write it into Python, but maybe not. Just cover your eyes
# and trust the force.
#
AGFindResults = TSXSend('''
var CAGI = ccdsoftAutoguiderImage; CAGI.AttachToActiveAutoguider();
CAGI.ShowInventory(); var X = CAGI.InventoryArray(0), Y =
CAGI.InventoryArray(1), Mag = CAGI.InventoryArray(2), FWHM =
CAGI.InventoryArray(4), Elong = CAGI.InventoryArray(8); var disMag =
CAGI.InventoryArray(2), disFWHM = CAGI.InventoryArray(4), disElong =
CAGI.InventoryArray(8); var Width = CAGI.WidthInPixels, Height =
CAGI.HeightInPixels; function median(values) { values.sort( function(a,b)
{return a - b;} ); var half = Math.floor(values.length/2); if(values.length
% 2) { return values[half]; } else { return (values[half-1] + values[half])
/ 2.0; } } function QMagTest(ls) { var Ix = 0, Iy = 0, Isat = 0, Msat =
0.0; for (Ix = Math.max(0,Math.floor(X[ls]-FWHM[ls]*2+.5)); Ix <
Math.min(Width-1,X[ls]+FWHM[ls]*2); Ix++ ) { for (Iy =
Math.max(0,Math.floor(Y[ls]-FWHM[ls]*2+.5)); Iy <
Math.min(Height-1,Y[ls]+FWHM[ls]*2); Iy++ ) { if (ImgVal[Iy][Ix] > Msat)
Msat = ImgVal[Iy][Ix]; if (ImgVal[Iy][Ix] > GuideMax) Isat++; } } if (Isat
> 1) { ADUFail = ADUFail + 1; return false; } else { return true; } } var
FlipY = "No", out = "", Brightest = 0, newX = 0, newY = 0,
counter = X.length, failCount = 0, magLimit = 0, k = 0; var passedLS = 0,
ADUFail = 0, medFWHM = median(disFWHM), medMag = median(disMag), medElong =
median(disElong), baseMag = medMag; var halfTBX =
(ccdsoftAutoguider.TrackBoxX / 2) + 5, halfTBY =
(ccdsoftAutoguider.TrackBoxY / 2) + 5, distX = 0, distY = 0, pixDist = 0;
var ImgVal = new Array(Height), Ix = 0, Iy = 0, GuideBits =
CAGI.FITSKeyword("BITPIX"), GuideCamMax = Math.pow(2,GuideBits)-1, GuideMax
= GuideCamMax * 0.9; for (Ix = 0; Ix < Height; Ix++) { ImgVal[Ix] =