-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathskycalcdisp.py
executable file
·3704 lines (3091 loc) · 122 KB
/
skycalcdisp.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/env python
# Oh, this is sneaky -- this one can pop a window linking to my
# very own annotated DScat ...
# skycalcgui.py - a GUI version of skycalc which can display
# a map of the sky built with PGPLOT graphics.
#
# copyright John Thorstensen, Dartmouth College, 2005 January.
#
# Anyone may use this program for non-commercial purposes,
# and copy it and alter it as they like, but this banner must
# be preserved, and my name must be preserved in window titles,
# i.e. proper credit must be given.
ppgplot_failure_msg = """Sorry, skycalcdisp.py isn't going to run.
It was unable to import the ppgplot and/or numarray modules.
These must be installed and accessible in order for the display to
run. The non-display version, skycalcgui.py, doesn't use these
two modules, and may work.
Depending on how ppgplot was compiled, it may be possible to
run this by changing the "from numarray import *" to "from
Numeric import *". It's worth a try, anyway.
The program will now stop.
"""
import sys
import string
import _skysub
from cooclasses import *
try :
from ppgplot import *
from numarray import *
except :
print ppgplot_failure_msg
sys.exit()
from Tkinter import *
from tkFileDialog import askopenfilename
from copy import deepcopy
# from pyraf import iraf # this breaks the connection between the main
# window and its variables. Too bad!
# from iraf import imred,specred,splot
import os
# Graphics section .... needs to be included to get all those
# global classes into the namespace.
BRIGHTSTARFILE = os.path.join(sys.prefix, "share/skycalc/brightest.dat")
def skyproject(ha,dec,lat) :
# does tan z/2 projection.
# ha -> hrs, dec, lat -> deg
# returns x, y for plot.
alt = _skysub.altit(dec,ha,lat)
coalt = (90 - alt[0]) / _skysub.DEG_IN_RADIAN
r = tan(coalt/2.)
az = alt[1] / _skysub.DEG_IN_RADIAN
y = r * cos(az)
x = r * sin(az)
if lat > 0. :
return [x,y]
else :
return [-1.*x,-1.*y] # reverse in south.
# bright = [] # define this globally to avoid reading it over and
# over.
def readbright() :
brlist = []
inf = open(BRIGHTSTARFILE,"r")
for l in inf.readlines() :
x = string.split(l)
ra = float(x[0])
dec = float(x[1])
mag = float(x[2])
name = l[27:37]
brlist = brlist + [[name,ra,dec,mag]]
return brlist
bright = readbright() # execute it.
def plotstars(bright,location,sidt) :
# Given a previously created plot for location and JD, plots the
# bright stars, which are handed in as name, ra, and dec.
starx = []
stary = [] # to hand back for a cursor find ...
for o in bright :
ha = sidt - o[1]
xy = skyproject(ha,o[2],location[1])
starx = starx + [xy[0]]
stary = stary + [xy[1]]
size = 0.1 + 0.3 * (4.5 - o[3])
pgsch(size)
pgpt(array([xy[0]]),array([xy[1]]),17)
pgsch(1.)
return [starx,stary]
def findnearest(x,y,xar,yar) :
# routine finds nearest star to given coords
# doesn't rescale axes, so not perfect.
# Sure is easy to code in Python ...
dists = []
if len(xar) == 0 :
print "Can't find nearest -- empty list!"
return None
for i in range(0,len(xar)) :
dists = dists + [sqrt((xar[i] - x)**2 + (yar[i] - y)**2)]
dmin = min(dists)
return dists.index(dmin)
def drawclock(time,x,y,radius,zabr,dst_inuse) :
# uses pgplot to draw a little clock face for time in decimal
# hours. Clock is centered at x, y, with radius.
# For application here, x-axis parity is assumed reversed, i.e.
# large x to left. High y is assumed to be up.
while time < 0. :
time = time + 24.
while time > 24. :
time = time - 24.
if time >= 12. :
pm = 1
else :
pm = 0
while time > 12. :
time = time - 12.
circx = []
circy = []
for t in arange(0.,60.0001,2.) :
circx = circx + [-1. * sin(t / _skysub.TWOPI)]
circy = circy + [cos(t/_skysub.TWOPI)]
circx = array(circx) * radius
circy = array(circy) * radius
circx = circx + x
circy = circy + y
pgline(circx,circy)
hhandx = -0.55 * radius * sin((time / 12.) * _skysub.TWOPI)
hhandy = 0.55 * radius * cos((time / 12.) * _skysub.TWOPI)
min = 60. * (time - int(time))
# print "min = %f" % min
mhandx = -0.85 * radius * sin((min / 60.) * _skysub.TWOPI)
mhandy = 0.85 * radius * cos((min / 60.) * _skysub.TWOPI)
pgmove(x,y)
pgslw(3)
pgdraw(x + hhandx, y + hhandy)
pgslw(1)
pgmove(x,y)
pgdraw(x + mhandx, y + mhandy)
pgline(circx,circy)
for i in range(0,12) :
ang = _skysub.TWOPI * (i / 12.)
sa = sin(ang)
ca = cos(ang)
pgmove(x + -0.91 * radius * sa, y + 0.91 * radius * ca)
pgdraw(x + -1. * radius * sa, y + radius * ca)
# make description string for label
if dst_inuse == 1 :
decstr = zabr + "DT "
else :
decstr = zabr + "ST "
if pm == 0 :
decstr = decstr + "AM"
else :
decstr = decstr + "PM"
pgptxt(x,y-1.35 * radius,0.,0.5,decstr)
def mooncirc(jd,lat,longit) :
# computes topocentric ra, dec, illumination angle, and PA of
# the cusps of the moon's illumination.
sidt = _skysub.lst(jd,longit)
moonpos = _skysub.lpmoon(jd,lat,sidt)
# print "moon: ",
# print moonpos
sunpos = _skysub.lpsun(jd)
# print " sun: ",
# print sunpos
codecsun = (90. - sunpos[1]) / _skysub.DEG_IN_RADIAN
codecmoon = (90. - moonpos[1]) / _skysub.DEG_IN_RADIAN
dra = sunpos[0] - moonpos[0]
while dra < -12. :
dra = dra + 24.
while dra > 12. :
dra = dra - 24.
dra = dra / _skysub.HRS_IN_RADIAN
# Spherical law of cosines gives moon-sun separation
moonsun = arccos(cos(codecsun) * cos(codecmoon) +
sin(codecsun) * sin(codecmoon) * cos(dra))
# spherical law of sines + law of cosines needed to get
# sine and cosine of pa separately; this gets quadrant etc.!
pasin = sin(dra) * sin(codecsun) / sin(moonsun)
pacos = (cos(codecsun) - cos(codecmoon) * cos(moonsun)) / \
(sin(codecmoon) * sin(moonsun))
pa = arctan2(pasin,pacos)
# print "pa of arc from moon to sun is %5.2f deg." % (pa * _skysub.DEG_IN_RADIAN)
cusppa = pa - _skysub.PI/2. # line of cusps ...
luna = _skysub.lun_age(jd)
jdfull = _skysub.flmoon(luna[1],2) # jd of full on this lunation
# print "lunation %d, jdfull %f" % (luna[1],jdfull)
# print "moonsun before ... %f, lunar age %f" % (moonsun,luna[0])
if jd > jdfull :
moonsun = moonsun * -1.
# print "moonsun after %6.2f, cusp pa %5.1f" % \
# (moonsun * _skysub.DEG_IN_RADIAN, cusppa * _skysub.DEG_IN_RADIAN)
return [moonpos[0],moonpos[1],moonsun,cusppa,pa]
# print "moonsun %6.2f deg, pa of arc from moon to sun = %6.2f\n" % \
# (moonsun * _skysub.DEG_IN_RADIAN, pa * DEG_IN_RADIAN)
def roughradectoxy(racent,deccent,x,y,scale) :
# takes a central ra and dec, and a set of x y offsets along
# ra and dec respectively, together with a scale factor (how many
# degrees to a unit), and delivers a list of ra and decs corresponding
# to x and y. Uses crude "graph paper" approximation, not tangent plane.
cosdec = cos(deccent / _skysub.DEG_IN_RADIAN)
raout = []
decout = []
for i in range(0,len(x)) :
raout = raout + [racent + scale * x[i] / (15. * cosdec)]
decout = decout + [deccent + scale * y[i]]
return [raout,decout]
def moonedges(jd, lat, longit) :
# delivers a list of two lists -- one is ra,decs of a set of points on the
# illuminated lunar limb, the other is the ra, decs of a set of points on
# the terminator.
# revision uses a different approach -- compute
# the limb and terminator in a system which is aligned with the
# line of cusps, and then rotate the resulting arrays into
# position using matrix multiplication. Much cleaner.
mooninfo = mooncirc(jd,lat,longit)
# pgbeg("/xterm")
# pgsvp(0.1,0.9,0.1,0.9)
# pgwnad(1.,-1.,-1.,1.)
moonsun = mooninfo[2]
while moonsun < 0. :
moonsun = moonsun + _skysub.TWOPI
# print "moonsun = %f" % moonsun
limbx = []
limby = []
termx = []
termy = []
drange = _skysub.PI / 10.
for p in arange(0.,_skysub.PI+0.001,drange) :
# set up limb and terminator with x-axis along cusp line,
# limb of moon in top half-plane
limbx = limbx + [cos(p)]
limby = limby + [sin(p)]
termx = termx + [cos(p)] # need a 2nd copy later
termy = termy + [sin(p) * cos(moonsun)]
# cos(moonsun) takes care of phase angle
pa = mooninfo[4] # pa from moon to sun
# print "moonsun %f = %f deg" % (moonsun, moonsun * _skysub.DEG_IN_RADIAN)
# print "pa = %f = %f deg" % (pa, pa * _skysub.DEG_IN_RADIAN)
turnmoon = array([[cos(pa),sin(pa)],[-1. * sin(pa),cos(pa)]])
# rotation matrix to turn moon to appropriate pa
limb = array([limbx,limby])
# this is easy! Just lay the x and y on top of each other in a
# matrix, and ...
# multiply them and
limb = matrixmultiply(turnmoon, limb)
# strip out the x and y as separate arrays and
limbx = limb[0]
limby = limb[1]
# do the same for the terminator, and finally
term = array([termx,termy])
term = matrixmultiply(turnmoon,term)
termx = term[0]
termy = term[1]
# Now, how large to draw the moon symbol? Unfortunately,
# scaling this with zenith distance requires us to know the
# zenith dist of the moon right here ...
coszover2 = cos((90. - obs.altmoon) / (2. * _skysub.DEG_IN_RADIAN))
moonscale = 3. * coszover2
# print "scale ... %f" % moonscale
limbradec = roughradectoxy(mooninfo[0],mooninfo[1],limbx,limby,moonscale)
termradec = roughradectoxy(mooninfo[0],mooninfo[1],termx,termy,moonscale)
# print "limbx"
# print limbx
# print "limby"
# print limby
# print "termx"
# print termx
# print "termy"
# print termy
#
# print "limbradec:"
# print limbradec
# print "termradec:"
# print termradec
# hamoon = sidt - mooninfo[0]
xlimb = []
ylimb = []
xterm = [] # x of terminator, not the computer terminal type!
yterm = []
for i in range(0,len(limbradec[0])) :
ha = obs.sidereal.val - limbradec[0][i]
xy = skyproject(ha,limbradec[1][i],lat)
xlimb = xlimb + [xy[0]]
ylimb = ylimb + [xy[1]]
for i in range(0,len(termradec[0])) :
ha = obs.sidereal.val - termradec[0][i]
xy = skyproject(ha,termradec[1][i],lat)
xterm = xterm + [xy[0]]
yterm = yterm + [xy[1]]
return [xlimb,ylimb,xterm,yterm]
def has_index(item,list) : # Python doesn't have this obvious function.
try :
n = list.index(item)
return 1
except ValueError :
return 0
def planetmags(jd) :
# **** NOTE NOTE NOTE **** comp_el(jd) must be called before this
# routine.
# returns the magnitudes of the planets in a list;
# [merc,venus,earth,mars,jupiter,saturn]
# Does position calculations in ecliptic, since only
# relative positions matter. Somewhat approximate.
earthxyz = array(_skysub.planetxyz(3,jd))
# print "earthxyz:",earthxyz
V0 = [None,-0.42,-4.40,-3.86,-1.52,-9.40,-9.22,-7.19,-6.87,-1.0]
# From Astronomical Almanac, 2003, p. E88. V mag of planet when
# full face on at unit distance from both sun and earth. Saturn
# has been goosed up a bit b/c Almanac quantity didn't have rings
# in it ...
mags = [None] # leave a blank at zeroth index
for i in range(1,10) :
if i != 3 : # skip the earth
xyz = array(_skysub.planetxyz(i,jd))
xyzmodulus = sqrt(dot(xyz,xyz))
pl2earth = earthxyz - xyz
pl2earthmodulus = sqrt(dot(pl2earth,pl2earth))
xyznegnorm = -1. * xyz / xyzmodulus
pl2earthnorm = pl2earth / pl2earthmodulus
phasefac = 0.5 * (dot(xyznegnorm,pl2earthnorm) + 1.)
# we want the cosine of the phase ultimately, and the dot gives it...
# actually, 1/2 of cosine phase plus one. This is simply the
# illuminated fraction, nothing more elaborate.
mag = V0[i] + 2.5*log10(phasefac) + 5*log10(xyzmodulus*pl2earthmodulus)
mags = mags + [mag]
else :
mags = mags + [None] # not doing earth.
return mags
def computeplanets_mag(jd,longit,lat,doprint = 0) :
label = [None,'Mercury','Venus',None,'Mars','Jupiter','Saturn',
'Uranus','Neptune','Pluto']
_skysub.comp_el(jd)
if doprint == 1 :
print "Planets for ",
print_all(jd)
print "UT."
mags = planetmags(jd)
planetpos = py_get_planets(jd,longit,lat,doprint)
planets = [None] # blank for position zero
for i in range(1,10) :
if i != 3 :
planets = planets + [[label[i],planetpos[i][0],planetpos[i][1],mags[i]]]
else :
planets = planets + [None]
return planets
def plotplanets(planets,location,sidt) :
planx = []
plany = [] # to hand back for a cursor find ...
pgsci(7) # yellow
for i in range(1,7) :
if i != 3 :
o = planets[i]
ha = sidt - o[1]
xy = skyproject(ha,o[2],location[1])
planx = planx + [xy[0]]
plany = plany + [xy[1]]
size = 0.1 + 0.3 * (4.5 - o[3])
pgsch(size)
pgpt(array([xy[0]]),array([xy[1]]),17)
pgsch(0.8)
pgptxt(xy[0]+0.03,xy[1]+0.01,0,0.5,o[0])
pgsch(1.)
pgsci(1) # white
return [planx,plany]
def localtime(jd,stdz,use_dst) :
# does what it says, returns zone time in hours.
date = _skysub.new_date_time()
dow = _skysub.caldat(jd,date)
yr = _skysub.date_time_y_get(date)
jdbe = _skysub.find_dst_bounds(yr,stdz,use_dst)
# print "jdbe: ",jdbe
z = _skysub.zone(use_dst,stdz,jd,jdbe[0],jdbe[1])
# print "z = ",z
if z == stdz :
dst_in_use = 0
else :
dst_in_use = 1
# print "dst in use: ",dst_in_use
jdloc = jd - z / 24.
# print "jd ",jd," jdloc ",jdloc
dow = _skysub.caldat(jdloc,date)
time = _skysub.date_time_h_get(date) + _skysub.date_time_mn_get(date) / 60. + \
_skysub.date_time_s_get(date) / 3600.
# print "returning local time ",time
return [time,dst_in_use]
def twilightcolor(altsun, ztwilight) :
# pgscr(0,R,G,B) sets background color for plot -- use it
# to indicate twilight. Routine hands back a tuple of
# (R,G,B) normalized 0 to 1.
# The formulae below give a little step at 18 degree twilight,
# followed by a steep ramp to 5 mag of twilight, followed by a
# gentler ramp up to full daylight.
if altsun < -18. : # total darkness
return (0.,0.,0.) # black
if altsun > -0.8 : # sun is UP
return (0.24, 0.48, 0.55) # bluish.
if ztwilight > 5. :
fac = (ztwilight - 5) / 10.
return (0.2 + fac * 0.04 ,0.27 + fac * .21, 0.44 + fac * 0.11)
else :
fac = (ztwilight+4) / 9.
return (0.20 * fac, 0.27 * fac, 0.44 * fac)
def plotsky(plotter, buttonpush = 0) :
# if buttonpush is 1, and the plotter is off, it opens;
# if buttonpush is 1, and the plotter is on, it closes.
date = _skysub.new_date_time() # used for some stuff
planets = computeplanets_mag(obs.jd,obs.longit,obs.lat,0)
if pgqinf('state') == 'CLOSED' :
pgbeg(plotter)
pgask(1)
pgscr(0,0.,0.,0.) # force a black border ...
pgeras() # key is to pgscr and then erase.
elif buttonpush == 1 : # toggle to off
pgask(0)
pgend()
return
#(rback,gback,bback) = twilightcolor(obs.altsun,obs.ztwilight)
#pgscr(0.,rback,gback,bback)
pgsvp(0.00,1.00,0.00,1.00)
asp = 1.30
# pgsclp(0)
ymin = -0.8
ymax = 0.8
xmin = ymin * asp # horizontal rectangle
xmax = ymax * asp
xcen = 0.
ycen = 0.
pgwnad(xmax,xmin,ymin,ymax)
# don't need the whole sky
x = arange(0.,2.*_skysub.PI+0.05,0.05)
circx = sin(x)
circy = cos(x)
halfwid = (ymax - ymin) / 2.
pgwnad(xmax,xmin,ymin,ymax)
(rback,gback,bback) = twilightcolor(obs.altsun,obs.ztwilight)
pgscr(0.,rback,gback,bback)
if plotter == "/xterm" :
pgpage()
elif plotter == "/xwin" :
pgeras()
# location[2] = stdz, location[3] = use_dst
# print "jd passed to localtime -> ",
# print_all(jd)
# print ""
localt = localtime(obs.jd, obs.stdz, obs.use_dst)
# print "localtime returns ", localt
pgsci(5)
drawclock(localt[0],xcen - 1.1 * halfwid,
ycen + 0.8125 * halfwid, 0.15 * halfwid,obs.zone_abbrev,localt[1])
# location[8] is zabr, localt[1] is 1/0 for dst.
pgsci(2)
pgscr(18,0.6,0.0,0.) # dark red circles to avoid busy-ness
pgsci(18)
if halfwid > 0.5 : # Don't try to put direction labels on zooms ... yet
pgsch(2)
if obs.lat > 0. :
toptext = 'N'
bottext = 'S'
lefttext = 'E'
rightext = 'W'
else :
toptext = 'S'
bottext = 'N'
lefttext = 'W'
rightext = 'E'
pgptxt(xcen,ycen - 0.98 * halfwid,0.,0.5,bottext)
pgptxt(xcen,ycen + 0.94 * halfwid,0.,0.5,toptext)
pgptxt(xcen + 1.2 * halfwid,ycen,0.,0.5,lefttext)
pgptxt(xcen - 1.2 * halfwid,ycen,0.,0.5,rightext)
pgsch(1)
pgline(circx,circy)
pgline(circx,circy)
pgsls(4)
pgline(0.57735 * circx, 0.57735 * circy) # 2 airmasses
pgline(0.70711 * circx, 0.70711 * circy) # 3 airmasses
pgline(0.7746 * circx, 0.7746 * circy) # 4 airmasses (sec z actually)
# pgsls(4)
pgsls(1)
for h in arange(-6.,6.5,2.) : # hour angle marks
xarr = []
yarr = []
for d in arange(90.,-90.1,-5.) : # every 5 deg in dec
alt = _skysub.altit(d,h,obs.lat) # clip it ...
if alt[0] > 0. :
xy = skyproject(h,d,obs.lat)
xarr = xarr + [xy[0]]
yarr = yarr + [xy[1]]
pgline(array(xarr),array(yarr))
xarr = [] # plot equator
yarr = []
for h in arange(-6.,6.01,0.5) :
xy = skyproject(h,0.,obs.lat)
xarr = xarr + [xy[0]]
yarr = yarr + [xy[1]]
pgline(array(xarr),array(yarr))
pgsls(1)
pgsci(3)
xobj = []
yobj = []
sidt = obs.sidereal.val # just for shorthand
pgsch(0.8)
for o in objs2000.keys() :
ha = sidt - objs2000[o][0]
xy = skyproject(ha,objs2000[o][1],obs.lat)
xobj = xobj + [xy[0]]
yobj = yobj + [xy[1]]
pgptxt(xy[0],xy[1],0.,0.5,o)
pgsch(1.)
pgsci(1)
# bright = readbright() # now done globally
starxy = plotstars(bright,[obs.longit,obs.lat],sidt)
planxy = plotplanets(planets,[obs.longit,obs.lat],sidt)
# draw in an actual moon!
stuff = moonedges(obs.jd,obs.lat,obs.longit)
pgsci(7)
pgline(array(stuff[0]),array(stuff[1]))
pgline(array(stuff[2]),array(stuff[3]))
pgsci(1)
xysun = skyproject(obs.hasun.val,obs.SunCoords.dec.val,obs.lat)
# put day, twilight, time orientation under clock.
if obs.altsun > -0.8 :
statstring = "DAYTIME"
elif obs.altsun > -18. :
statstring = "TWILIGHT"
else :
statstring = "NIGHTTIME"
pgsci(5)
pgptxt(xcen - 1.1*halfwid, ycen + 0.55*halfwid,0.,0.5,statstring)
# locald = localdatestr(obs.jd,obs.longit,obs)
locald = obs.calstring(stdz = obs.stdz,
use_dst = obs.use_dst, style = 1, \
print_day = 1, daycomma = 0, dayabbrev = 1)
pgptxt(xcen - 1.2*halfwid,ycen - 0.9*halfwid,0.,1.0,locald)
pgptxt(xcen - 1.2*halfwid,ycen - 0.95 * halfwid,0.,1.0,obs.obs_name)
pgsci(1)
# plot the sun
pgsch(2.0)
pgsci(7) # yellow
pgpt(array([xysun[0]]),array([xysun[1]]),9)
pgsci(1)
pgsch(1.)
# plot the current position - in blue.
pgsch(4.0)
pgsci(11)
xy = skyproject(obs.hanow.val,obs.CoordsOfDate.dec.val,obs.lat)
pgpt(array([xy[0]]),array([xy[1]]))
pgsch(1.0)
pgsci(1)
#### END end End of Graphics graphics GRAPHICS section #####
infields = ('objname','RA','dec','equinox','date','time','Time is:',\
'timestep','obs_name','longit','lat', \
'stdz', 'use_dst', 'zone_name', 'zone_abbrev', \
'elevsea','elevhoriz', 'siteabbrev')
# 0 = objname,
# 1 = RA; 2 = dec; 3 = equinox; date = 4, time = 5,
# Time is: = 6, timestep = 7,
# 8 = obs_name, 9 = longit, 10 = lat, 11 = stdz, 12 = use_dst,
# 13 = zone_name, 14 = zone_abbrev,
# 15 = elevsea, 16 = elevhoriz, 17 = siteabbrev
# These are all in text-entry widgets EXCEPT:
# - 'Time is:' is controlled by a radio button
# - site_abbrev is controlled by a separate radio-button panel
outfields = ('sidereal','ha','airmass','alt_az','parallactic','jd', \
'sunradec','sunaltaz','ztwilight','moonphase','moonradec','moonaltaz', \
'illumfrac','lunsky','moon-obj ang.','baryjd','baryvcor','constel',
'planet_proxim')
# 0 = sidereal; 1 = ha; 2 = airmass; 3 = alt_az; 4 = parallactic;
# 5 = jd; 6 = sunradec; 7 = sunaltaz; 8 = ztwilight;
# 9 = moonphase; 10 = moonradec; 11 = moonaltaz; 12 = illumfrac;
# 13 = lunsky; 14 = moon-obj angle; 15 = baryjd; 16 = baryvcor
# 17 = constel; 18 = planet proximity flag
almfields = ('Sunset','Twilight Ends','Night center','Twilight Begins','Sunrise',\
'Moon:','Moon:')
# 0 = sunset, 1 = eve twi, 3 = night center, 4 = morn. twilight, 5 = sunrise,
# 6, 7 = moon rise and/or set in time order.
coofields = ('Current RA:','Current dec:','equinox:',
'Proper motion','PM is:','input epoch','RA (pm only)',
'Dec (pm only)','equinox:',
'Ecliptic latitude','Ecliptic longitude','Galactic latitude',
'Galactic longitude','parallax factors')
# 0, 1, 2 -> Current RA, dec, and equinox
# 3 -> proper motion (two fields)
# 4 -> 1 = proper motion is dX/dt, 0 = proper motion is dalpha/dt
# 5 -> actual epoch of input coords
# 6, 7, 8 -> PM adjusted RA, and dec, and input equinox repeated
# 9, 10 -> ecliptic latitude and longitude
# 11, 12 -> Galactic latitude and longitude
# 13 -> parallax factors in X and Y
helptext = """
GENERAL
This program computes astronomical circumstances, given
the target's celestial location, the date and time, and
the site parameters. The graphical user interface (GUI)
is a front end for routines taken from the text-based
'skycalc' program. The program is intended for users
who are familiar with the concepts involved; it is
not intended as a tutorial on time-and-the-sky.
Most input parameters are read from the fields in the
left-hand column of the main window. Parameters which
can be straightforwardly used as input are rendered in
white. All the output parameters are refreshed whenever
a calculation is made.
At startup, the program sets the input date and time using
the computer's clock, and sets the coordinates to the
zenith at the default site (presently Kitt Peak).
MAKING COMPUTATION HAPPEN
You can refresh all the output fields by:
(a) Typing a carriage return in an input field;
(b) Stepping the time forward or backward with
the left and right arrow keys (or a carriage
return in the "timestep" field;
(c) Pressing 'Refresh output', 'Set to now',
or 'UT <-> Local'. This last converts the
input time format but leaves the time unchanged;
(d) Selecting a new object from the (optional) target
list menu;
(e) Selecting a new site from the site menu.
SPECIFYING A SITE
The site menu has parameters for several major
observatories. But note:
- If you want a site NOT on the menu, you must first
select "Other (allow user entries)" on the site menu.
Otherwise, the site parameters are overwritten when you
refresh. Site parameters are rendered with a slight
pink tinge to draw attention to this distinction.
Once you've done this, simply enter your site's
parameters. NOTE: the longitude units default to HMS
positive westward, which is NOT STANDARD. You can
specify units and direction explicitly, for example
"-111 36.9 d e" will enter Kitt Peak's longitude
in the form used in the "Astronomical Almanac".
LOADING TARGETS BY NAME FROM A LIST
It can be very handy to select objects by name from an
(optional) object list. To do this, prepare a file with
one object per line in this form:
name_no_blanks rahh mm ss decdd mm ss equinox
for example,
4U2129+47 21 29 36.2 47 04 08 1950
The 'read object list' button will pop up the list.
Select the object by double-clicking on its name.
The "dismiss" button clears the list and destroys
the window. You can load multiple target lists;
dismissing a list dismisses only the objects on that
list. Overlapping names are checked for and handled.
WHAT'S WITH THE COLORS?
Data fields which can be used for input are rendered
in off-white. Pale pink is for site parameters, which
can be adjusted when the site menu enables it.
Other than that, color is used to draw attention to
various conditions:
- yellow, orange, red : these indicate increasingly
problematic conditions (twilight, hour angle,
airmass, or proximity to the moon). The Reference
Manual gives details. For the moon, these colors are
used when the moon is < 25 degrees from the
input position (i.e., it means the moon's proximity
may be a problem).
- Light blue means daylight for the sun. For the moon it
signals that the moonlight prediction is between non-
negligible and fairly strong. It is only used when the
moon is more than 25 degrees from the object.
- Light purple is used to flag quite bright moonlight (more
than 19.5 V mag per square arcsec) at angles more than
25 degrees from the moon.
The reason for not using yellow, orange, and red in
these moonlit conditions is to reserve these colors for
when the moon is close to the object -- easy to overlook
in planning. Since the sky is always bright around full moon,
using red for the ordinary bright sky would be "crying wolf".
STUFF TO KEEP IN MIND:
- If a window has a "Hide" button, use it when you want
to close the window. Windows with "Hide" buttons have
processes which are always running, and killing the window
destroys the process.
- For most windows, if they get "buried alive" behind
another window, clicking their button on the main window
will raise them. Exceptions are object lists and text
output windows, for which you can have more than one at
a time.
- The Hourly Airmass window has a "Dump to file" button,
which appends a text version of the information to a
text file called "skycalc.out". The file will appear
in whatever directory the program started in, probably
your top directory if you launched with a pull-down menu.
- The "Step time" button advances the input time by the
"timestep" parameter and refreshes the output. Left
and Right arrow keys typed anywhere in the main window
move the time backward and forward. Typing a carriage
return into the "timestep" field also advances the time.
A variety of units are recognized for the timestep:
5 s - 5 seconds
10 m - 10 minutes [minutes are the default]
1.5 h - an hour and a half
2 d - 2 days
1 t - 1 sidereal day, think "transit" for mnemonic
2 w - 2 weeks
1 l - one lunation (mean synodic month). This is
useful for examining conditions at e.g. successive
new moon dates. The jump is 29.53 days.
- The "Time is: UT Local" radiobuttons affect how the
input time is interpreted when the computation is done.
Switching this doesn't have any effect until the output is
refreshed. Switching this and refreshing will change the
output values, unless UT and local time are identical.
The "UT <-> local" button, by contrast, converts the
input time fields to the SAME time in the other system
(and switches the radiobutton so the change will stick).
The output is refreshed, but nothing should change (except
for tiny roundoff effects, e.g. azimuth at zenith).
- The "objname" field is updated when an object is loaded
from the menu, or you can change it by hand. It is not
changed automatically when you change the RA and dec;
in that case it's up to you to change it. If you do have
an object list loaded, you can enter an object's name
in this field to load its coordinates if it's easier than
finding it on the list and double-clicking.
- You can input RA, dec, etc. with or without colons (":")
separating the field, or as decimal hours or degrees.
If there are two or more fields the input is interepreted
as sexigesimal (i.e., 60-based like HH MM SS). If you
enter a negative dec, you must not leave any space between
the minus sign and the first digit of the degrees.
You can enter RA as degrees, minutes, and seconds, or as
decimal degrees, if you put a "d" at the end, separated by
a space, e.g. "275.3828 d" or "275 22 58 d".
- Entering a jd in the "jd" field and hitting return will
set the time to agree with the entered JD. This is a
rare exception to the distinction between input and
output variables. The field is whitened for this reason.
OTHER WINDOWS ...
- The "Nightly almanac" window displays times of sunrise
and -set, twilight, and moonrise and set.
- The "Alt. Coords" window displays current coords and
optionally computes a proper motion correction. See
the reference manual for details.
- The 'Planets' window gives low-precision planetary positions.
- The Planetarium display (toggled on and off with the
Planetarium button) generates a map of the sky.
- The 'Text Tasks' window handles several calculations which
can produce tables, including seasonal observability and
generating ephemerides for periodic phenomena (e.g. binary
star eclipses).
MORE INFORMATION
If you want more detail, pop up the Reference Manual
window. It has detailed descriptions of the various
fields, explains the warning color scheme, and so on.
There is also a cursory HTML manual, and a very detailed
manual for the text-based skycalc program, which shares
much code with this version.
OTHER FORMS OF THIS PROGRAM
This program encapsulates some of the most widely-used
functionality of the text-based "skycalc" program. Many
features have been left out; if you need some other
time-and-the-sky calculation, it may be in skycalc.
LEGALITIES.
This program is copyright 2005, by the author, John
Thorstensen (Dartmouth College). Permission is hereby
granted for all non-profit use, especially educational
and scientific users. I do ask that my credit line
remain prominently displayed.
Portions of the interface code are adapted from
"Programming Python" by Mark Lutz (O'Reilly).
There are no warranties of any kind.
John Thorstensen, Dartmouth College
john dot thorstensen at dartmouth dot edu
"""
referenceman = """
---- REFERENCE MANUAL ----
ALL THE FIELDS:
--- INPUT VARIABLES ---
objname - Used to label text-file output and for the
user's benifit. Loads automatically when objects are
double-clicked on the object list, or can be set by
hand. When an object list has been loaded, you can
fetch an object's coordinates by entering its name here
with a carriage return; if the object isn't on the list, a
"NOT FOUND" will appear in the objname field.
RA - Right ascension, defaults to hours, minutes, and
seconds. Fields can be delineated by spaces or colons.
You can also enter plain decimal hours. If there are
two fields or more, it is interpreted as HH:MM:SS.
You can enter RA in degrees if you put a " d" (space
and d) at the end of the input, e.g. "275.3828 d" or
"275 22 58.1 d"
dec - Declination, generally in degrees, minutes, and
seconds separated by colons or spaces. The same input
apply as for RA. For negative declinations there cannot
be any space between the negative sign and the first
digit of the degrees.
equinox - The equinox (often incorrectly called "epoch")
of the input coordinates, in decimal years. One special
hook -- if you enter "date", the equinox is forced to
agree with the date and time (will change the direction
of the input coordinates, unless they're already in the
equinox of date). This feature enables a
backdoor computation of the Julian epoch (which is
2000.0 + the number of 365.25 day intervals since
J2000 = JD 2451545.0).
date - The input date as year, month, day. The day of
the week is not used on input, but when a refresh happens
it is forced to agree with the year, month, and day.
The month can be specified as e.g. "Apr", "April", or
"4". Dates outside of the range 1901 to 2099 are rejected.
time - The time in hours, minutes, and seconds. The same
formats are acceptable here as for RA and dec, e.g.
17 32 33, 17:32:33, 17.53, 17:32, and so on. However,
entering e.g. "3.25" for 3:15 will truncate to
"3 00 00".
NOTE ON DAYLIGHT SAVINGS TIME: If the "use_dst" flag
lower down is not zero, local time will be interpreted
as daylight savings when it is in effect. See the
notes on the "use_dst" flag below.
Time is: - A button which controls whether the input time
will be interpreted as local time or UT. Changing this
does not cause a refresh. Use the control button
"UT <-> local" to convert the time and switch the input
values to specify the same actual time in the other system.
timestep - How far to step the time when the "Step the time"
button is pressed, a right- or left-arrow key is pressed,
or when a carriage return is typed in this particular input