-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAstrolabe.py
executable file
·1556 lines (1298 loc) · 48.6 KB
/
Astrolabe.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 python3
# coding: utf-8
# # Astrolabe
#
# A python replacement to the good old astrolabe.for
# draw ``astrolabe'' grids (coordinates and an airmass overlay)
#
# usage:
# Astrolabe.py
# debug version, runs with hardcoded parametres
# Astrolabe.py CGIobs code [projection] [view]
# for a given observatory by code
# Astrolabe.py CGIcoo long lat [projection] [view]
# for a given observatory by coordinates
# Astrolabe.py CGIband long [projection] [view]
# for a band
# code: 3digits (incl leading zero) code in observatory.dat
# 072 Brussels; 272 Munich; 144 VLT; 132 La Silla...
# long, lat: coordinates, W>0, N>0
# projection: stereographic; anything else is polar
# view: outside; anything else is inside
#
#
# version: sometime in early 92? early version for La Silla
# version: Apr94, cleaned code
# version: Jun96. kjm made code more "user friendly"
# version: Feb20. oh ported to python
# input:
# stars: in hr.dat ; each line:
#
# ii, ij, ra, ram, ras, dec, dm, ds, vmag
# if ram=ras=0, the program considers that ra and dec are
# given in degrees
# if ij>0, the star is a solid circle, open otherwise
# ignore the ii - it is not useful.
# observatory
# |ctio -30.0957800 70.4853600 2235.0000000 CTIO, Chile
#----------------------------------------------------------------------
import numpy as np
import matplotlib
matplotlib.use('Agg') # no Display; must be before pyplot
import matplotlib.pyplot as plt
import sys
import os
from astropy.time import Time
from astropy.io import ascii
debug = False
doRete = True
doPlate = True
doRule = True
#======================================================================
if 0: # for webtool
astpath = '/home/ohainaut/public_html/astrolabe/'
outpath = '/home/ohainaut/public_html/outsideWorld/'
pubweb = 'https://www.eso.org/~ohainaut/outsideWorld/'
astweb = 'https://www.eso.org/~ohainaut/astrolabe/'
logfile = '/home/ohainaut/public_html/log/astrolabe.log'
obsFile = astpath+ 'src/observatory.dat'
obsCleanFile = astpath+ 'src/obsClean.dat'
starFile = astpath+ 'src/hr.dat'
constFile = astpath + 'src/const.dat'
landFile = astpath+ 'src/landold.dat'
else: # for local
astpath = os.path.dirname(__file__)
outpath = './'
pubweb = './'
astweb = './'
obsFile = astpath+'/observatory.dat'
obsCleanFile = astpath+'/obsClean.dat'
logfile = 'astrolabe.log'
starFile = astpath+'/hr.dat'
constFile = astpath+'/const.dat'
landFile = astpath+'/landold.dat'
#===========================================================================
#===========================================================================
#===========================================================================
def d2r(decd):
# subroutine to convert Declination into plot radius
# input: decd declination in degress
# output: radius in plot units
if stereo:
r = np.tan( np.radians( (90.+decd)/2. )) * d2rnorm
#+dec shoudl be -dec, but we move everything to S ->*-1
# max: 173
else:
r = ( 90.+decd) *d2rnorm #decd in [-90,northlim]
return r
#===========================================================================
def altaz2hadec(zr,azr): # zr and azr in rad
# spherical trigo: converts ZenithDist, Azimuth
# into HA (radians), Dec (dec)
cosz = np.cos(zr)
sinDec = np.sin(np.radians(xlat))*cosz \
+ np.cos(np.radians(xlat))*np.sin(zr)*np.cos(azr)
Decr = np.arcsin(sinDec)
Dec = np.degrees(Decr)
sinHA = -np.sin(azr)*np.sin(zr)/np.cos(Decr)
cosHA = (cosz - sinDec*np.sin(np.radians(xlat))) \
/ np.cos(Decr)/np.cos(np.radians(xlat))
HAr = np.arctan2(sinHA, cosHA)
return HAr, Dec
#======================================================================
def suncoord(Lr):
#Lr: longitude of the Sun in Rad
#returns RAr, Dec of the sun
X = np.cos(Lr) # position of the sun
Y = np.cos(epsr)*np.sin(Lr)
Z = np.sin(epsr)*np.sin(Lr)
R = np.sqrt(1.0-Z*Z)
deltaSun = np.degrees(np.arctan(Z/R)) #// in degrees
RASun = (24./180.)*np.degrees(np.arctan2(Y,(X+R))) #// in hours
RASunr = np.radians(15.*RASun)
return RASunr, deltaSun
#======================================================================
def sunlong(JD):
#Returns Sun longitude from Julian Day
# number of Julian centuries since Jan 1, 2000, 12 UT
T = (JD-2451545.0) / 36525.
# mean anomaly, degree
M = 357.52910 + 35999.05030*T - 0.0001559*T*T - 0.00000048*T*T*T
# mean longitude, degree
L0 = 280.46645 + 36000.76983*T + 0.0003032*T*T
# Sun's equation of center
DL = (1.914600 - 0.004817*T - 0.000014*T*T)*np.sin(np.radians(M))+\
(0.019993 - 0.000101*T)*np.sin(np.radians(2*M)) + 0.000290*np.sin(np.radians(3*M))
# true longitude, degree
L = L0 + DL
return np.radians(L)
#===========================================================================
def plotAlmucantar(cosz, color):
# plot a full almucantar corresponding to cosz
zr = np.arccos(cosz)
wHAr, wDec = altaz2hadec(zr, rad)
HAr = wHAr[ wDec*isouth < northlim*isouth]
Dec = wDec[ wDec*isouth < northlim*isouth]
ax.plot(HAr, d2r(Dec*isouth) ,c=color, linewidth=linew)
return HAr, Dec
#===========================================================================
def plotHalfmucantar(cosz, lw):
# plot a partial almucantar corresponding to cosz
zr = np.arccos(cosz)
HAr, Dec = altaz2hadec(zr, rad)
if isouth > 0:
w1x = HAr[ deg > 30 ]
w1y = Dec[ deg > 30 ]
w1d = deg[ deg > 30 ]
w2x = HAr[ deg < -30 ]
w2y = Dec[ deg < -30 ]
w2d = deg[ deg < -30 ]
wHAr = np.concatenate((w1x, w2x), axis=None)
wDec = np.concatenate((w1y, w2y), axis=None)
wd = np.concatenate((w1d, w2d), axis=None)
else:
w1x = HAr[ deg > -150 ]
w1y = Dec[ deg > -150 ]
w1d = deg[ deg > -150 ]
wHAr = w1x[ w1d < 150 ]
wDec = w1y[ w1d < 150 ]
wd = w1d[ w1d < 150 ]
HAr = wHAr[ wDec*isouth < northlim*isouth]
Dec = wDec[ wDec*isouth < northlim*isouth]
ax.plot(HAr, d2r(Dec*isouth) ,c=airmasscol, linewidth=lw)
return wHAr, wDec
#==============================================================================
def xy2ad(x,y):
# finds the RA, radius for a position in X,Y
a = np.arctan2(x,y)
r = np.sqrt(x**2+y**2)
return a,r
#------------------------------------------------------------------------------
def write_legend_line(x,y,label,side):
a,r = xy2ad(x,y)
plt.text(a,r,label,
color=legendc,
fontsize=legends,
horizontalalignment=side,
verticalalignment='top')
#----------------------------------------------------------------------
def write_legend(iwhat):
dy = 8
side = 'left'
# writes the labels in the corner
x = -200. * tradOrient*isouth*iwhat
y = 200.
write_legend_line(x,y,'www.eso.org/~ohainaut/bin/astrolabe.cgi',side)
y -= dy
a,r = xy2ad(x,y)
write_legend_line(x,y,'ohainaut@eso.org',side)
side = 'right'
x = 200. * tradOrient*isouth*iwhat
y = 200.
a,r = xy2ad(x,y)
write_legend_line(x,y,'Long, Lat: '+longlatlabel,side)
y -= dy
if iwhat < 0:
write_legend_line(x,y,'Name: {} ({})'.format(obsname, obs),side)
else:
write_legend_line(x,y,'Name: '+rete,side)
y -= dy
if stereo:
wlab = 'stereographic'
else:
wlab = 'polar'
write_legend_line(x,y,'Projection: '+wlab,side)
y -= dy
if tradOrient > 0:
wlab = 'outside'
else:
wlab = 'inside'
write_legend_line(x,y,'Orientation: '+wlab,side)
y -= dy
if isouth > 0:
wlab = 'S'
else:
wlab = 'N'
write_legend_line(x,y,'Hemisphere: '+wlab,side)
y -= dy
write_legend_line(x,y,'Limit dec={}deg'.format(northlim),side)
#crosses at the corners
side = 'center'
xx = [-200,200]
yy = [-200,200]
for x in xx:
for y in yy:
write_legend_line(x,y,'+',side)
#==============================================================================
def plot_milkyway():
#- galactic disc
import astropy.units as u
from astropy.coordinates import SkyCoord
glong = np.arange(-180,181,1)
# Bulge
linew = linew_thin
linea = linea_transp
for i in np.arange(-10,11,1):
glat = glong*0.+ 2*i* np.exp ( -(glong/30.)**2 ) #<- bulge flare
glx = SkyCoord(l=glong*u.degree, b=glat*u.degree, frame='galactic')
gra = glx.transform_to('icrs').ra.degree
gde = glx.transform_to('icrs').dec.degree
linew = linew_thin
linea = linea_normal
ax.plot(np.radians(gra),d2r(gde*isouth),c=glxcol, linewidth=linew, alpha=linea)
# +10 and -10
for i in np.arange(-10,11,10):
if i == 0:
linew = linew_medium
else:
linew = linew_thin
glat = glong*0.+ i
glx = SkyCoord(l=glong*u.degree, b=glat*u.degree, frame='galactic')
gra = glx.transform_to('icrs').ra.degree
gde = glx.transform_to('icrs').dec.degree
ax.plot(np.radians(gra),d2r(gde*isouth),c=glxcol, linewidth=linew, alpha=linea)
# galactic long tickmarks
glat = np.arange(3,-1,-3)
linew = linew_thin
for i in np.arange(0,360,15):
glong = glat*0. + i
glx = SkyCoord(l=glong*u.degree, b=glat*u.degree, frame='galactic')
gra = glx.transform_to('icrs').ra.degree
gde = glx.transform_to('icrs').dec.degree
ax.plot(np.radians(gra),d2r(gde*isouth),c=glxcol, linewidth=linew, alpha=linea)
if d2r(gde[0]) +2. < outring: # only if in view, label tick
ax.text(np.radians(gra[0]),
d2r(gde[0]*isouth) +2.,
'{:3d}'.format(int(glong[0])),
rotation= -tradOrient*gra[0]* isouth +180.,
horizontalalignment='center',
verticalalignment='center',
color=glxcol,
fontsize=5
)
#======================================================================
def plot_ecliptic():
#==== ECLIPTIC
# old simple ecliptic
if False:
xinc = 23.439
delta = xinc*np.sin(rad) *isouth ##
linew = linew_thin
ax.plot(rad,d2r(delta),c='g', linewidth=linew)
#months on ecliptic
myd = np.arange(0,12)*30.+9 # offset so that eqx happens on ~21
myr = xinc * np.sin(np.radians(myd)) *isouth ##
ax.scatter(np.radians(myd),d2r(myr),s=10,c='g')
for i in np.arange(0,len(Month)):
ax.text(np.radians(myd[i]),
d2r(myr[i])+7, ## myr already has been multiplied by isouth
Month[i],color='g',
rotation=-tradOrient*myd[i]*isouth + 180.,
horizontalalignment='center',
verticalalignment='center',
fontsize=7)
# 15 day ticks on ecliptic
myd = np.arange(0,360,5)+9
myr = xinc * np.sin(np.radians(myd)) *isouth ##
ax.scatter(np.radians(myd),d2r(myr),s=.5,c='g')
# FULL ecliptic
# ecliptic circle
linew = linew_thin
linea = linea_normal
Lr = np.radians(np.arange(0.,360.1,1.)) # longitude of the sun
RASunr, deltaSun = suncoord(Lr)
deltaSun = deltaSun * isouth
ax.plot(RASunr,d2r(deltaSun),
c=solcol, linewidth=linew, alpha=linea)
ax.plot(RASunr,d2r(deltaSun)+0.25,
c=solcol, linewidth=linew, alpha=linea)
#ecliptic longitude ticks
Li = np.arange(0,360)
L = Li*1.
Lr = np.radians(L) # longitude of the sun
RASunr, deltaSun = suncoord(Lr)
deltaSun = deltaSun * isouth
for i in Li: # 360 deg
if i % 30 == 0:
Sl=8
ax.text(RASunr[i], d2r(deltaSun[i])-Sl-2,
'{:03d}'.format(i),
color=solcol, fontsize=5,
horizontalalignment='center',
verticalalignment='center',
rotation=-tradOrient*i*isouth+180.)
elif i % 10 == 0:
Sl=5
elif i % 5 == 0:
Sl=3
else:
Sl = 2
ax.plot([RASunr[i],RASunr[i]],
[d2r(deltaSun[i]),d2r(deltaSun[i])-Sl],
c=solcol, linewidth=linew, alpha=linea)
# Ecliptic Calendar
for i in np.arange(0,len(SunJD)):
SLab = SunDay[i]
SJD = SunJD[i]
Lr = sunlong(SJD)
RASunr, deltaSun = suncoord(Lr)
deltaSun = deltaSun * isouth
# ecliptic calendar tick marks every 5d
ax.plot([RASunr,RASunr],
[d2r(deltaSun)+0,d2r(deltaSun)+5.],
c=solcol, linewidth=linew, alpha=linea)
# label the tickmarks
ax.text(RASunr, d2r(deltaSun)+8,
SLab,
color=solcol, fontsize=8,
horizontalalignment='center',
verticalalignment='center',
rotation= -tradOrient*np.degrees(RASunr)* isouth+180.)
# little tick marks between calendar dates
if i == 0:
RASunr0, deltaSun0 = suncoord(sunlong(SunJD[-1]))
deltaSun0 = deltaSun0 * isouth
#print(SunJD[-1], SunJD[len(SunJD)-1], RASunr0, RASunr)
# ecliptic calendar
if RASunr-RASunr0 < -2.: # catch the 23:59 - 00:00 crossing
RASunr0 -= 2.*np.pi
if RASunr-RASunr0 > 2.: # and in the other direction
RASunr0 += 2.*np.pi
for j in np.arange(1,int(SunStep)): # interpollate little ticks
RASunrj = RASunr0 + j*(RASunr-RASunr0)/SunStep
deltaSunj = deltaSun0 + j*(deltaSun-deltaSun0)/SunStep
ax.plot([RASunrj,RASunrj],
[d2r(deltaSunj),d2r(deltaSunj)+2],
c=solcol, linewidth=linew, alpha=linea)
RASunr0 = RASunr*1. # keep current value for next i, for interpollation
deltaSun0 = deltaSun*1.
#======================================================================
def plot_stars():
#==== STARS
#- constellation
# read the constellation files
constData = ascii.read(constFile, delimiter=',')
print( "Nr of constellation points:",len(constData))
#Const,HR1,RA1,Dec1,Mag1,HR2,RA2,Dec2,Mag2
racav = 0. # init, will be the average coords of the stars in constellation
decav = 0.
iicav = 0
lacav = "XX"
for i in np.arange(0, len(constData)):
if constData['Dec1'][i] *isouth < northlim*isouth and \
constData['Dec2'][i] *isouth < northlim*isouth: # is the line visible
if constData['Const'][i] != lacav: # new constellation name
if iicav > 0: # we finished a constellation that had lines
# let's label it
racav = racav/2./iicav
decav = decav/2./iicav*isouth
ax.text(np.radians(racav),d2r(decav), lacav,
color=colg,
rotation = -tradOrient*racav*isouth + 180.,
horizontalalignment='center',
verticalalignment='center')
iicav = 0 # and re-init the averages
racav = 0.
decav = 0.
racav += constData['RA1'][i] + constData['RA2'][i]
decav += constData['Dec1'][i] + constData['Dec2'][i]
iicav += 1
lacav = constData['Const'][i]
#-draw the constellation line
ax.plot([np.radians(constData['RA1'][i]), np.radians(constData['RA2'][i])],
[d2r(constData['Dec1'][i] *isouth), d2r(constData['Dec2'][i] *isouth)],
alpha=0.5, linewidth=.5,color=colk)
#- stars
starData = np.genfromtxt(starFile) # read star data file
# ii, ik, ra, junk, junk, dec, junk, junk, vmag
starRA = starData[:,2]
starDec = starData[:,5]
starMag = starData[:,8]
starSize = 15 - 3*starMag
wrad = d2r(starDec *isouth )
selRAr = np.radians(starRA[wrad < outring])
selrad = wrad[wrad < outring]
selsize = starSize[wrad < outring]
ax.scatter(selRAr, selrad,
c=colk, s=selsize,
linewidth=0,
alpha=1.)
#- alternate source of stars
if False:
ax.scatter(np.radians(constData['RA1']), d2r(constData['Dec1'] *isouth),
c=colk, s=starSize,
linewidth=0,
alpha=0.7)
#======================================================================
def plot_landold():
#- landold standard fields
landData = np.loadtxt(landFile,
dtype={'names': ('j1','j2','rh','rm','rs','dd','dm','ds','j3','name'),
'formats':(float,float,float,float,
float,float,float,float,float,'|S15')})
landData = ascii.read(landFile, delimiter=' ')
# ii, ik, RAH, RAM, RAS, DDE, DM, DS, j, ID
landRA = 15.*(landData['col3'] + landData['col4']/60. + landData['col5']/3600.)
landDec = landData['col6']
landID = landData['col10']
ax.scatter(np.radians(landRA), d2r(landDec *isouth),
c=colr, s=10, alpha=0.5)
for i in np.arange(0,len(landID)):
ax.text(np.radians(landRA[i]),
d2r( landDec[i]*isouth) +15.,landID[i],color=colr,
rotation=landRA[i]+90,
fontsize=5,
horizontalalignment='center',
verticalalignment='center')
#======================================================================
def plot_rete():
# MAIN GRID PLOT - RETE
if True :
ax.set_xticks([])
ax.set_yticks([])
ax.grid(False)
#!!! polar expects y_limits to be so that center < edge
# limits(-90,30) will work, limits(90,-30) will not
# ===> all declinations are multiplied by isouth
# to reverse all Northern plots
ax.set_ylim(0, outring +20.)
ax.set_theta_direction(-isouth*tradOrient)
ax.set_theta_zero_location("N")
write_legend(1) # write stuff in the corners - 1=rete
# Galactic disk - first, so that everything else ovewrites it.
plot_milkyway()
# RA tick
linew= linew_thin
linea = linea_normal
calrad = outring + 10 # radius of the calendar
for i in np.arange(0,360, 2.5):
myr = np.array([calrad,calrad -5])
myd = [i,i]
ax.plot(np.radians(myd),(myr),c=colk, linewidth=linew, alpha=linea)
myr = np.array([calrad,calrad -2])
myd = [i+1.25,i+1.25] #5min
ax.plot(np.radians(myd),(myr),c=colk, linewidth=linew, alpha=linea)
if debug:
print( 'dbg')
plt.savefig(outpath+'debug.pdf')
exit(1)
# radial lines
linew = linew_thin
for h in hours:
# RA lines
dm=-50*isouth
if h % 2 == 0:
dm = -80*isouth
else:
dm = -90*isouth
linew = linew_medium
myd = np.array([h, h])*15.
myr = np.array([dm, northlim]) *isouth ##
ax.plot(np.radians(myd),d2r(myr),c=colg, linewidth=linew, alpha=linea)
# RA labels
if h % 6 == 0:
ralabel = 'RA= {:02d}'.format(h)
ax.text(np.radians(h*15),
calrad -13.,
'UT for calendar',
color=calcol,
rotation=-tradOrient*h*15*isouth +180,
horizontalalignment='center',
verticalalignment='center',
fontsize=5)
else:
ralabel = '{:02d}'.format(h)
ax.text(np.radians(h*15),
calrad -6,
ralabel,
color=colk,
rotation=-tradOrient*h*15*isouth +180,
horizontalalignment='center',
verticalalignment='center',
fontsize=10)
# Declination circles
for r in np.arange(-80, northlim*isouth +1, 10):
if r == 0:
linew = linew_thick # thicker equator
else:
linew = linew_thin
myr = deg*0+ r
ax.plot(rad,d2r(myr), c=colg, linewidth=linew, alpha=linea)
#label
for r in np.arange(-60, northlim*isouth, 30):
ax.text(np.radians(180.),d2r(r),
'$\delta$={:+d}$^o$'.format(int(r*isouth)),
color=colk,
rotation=0.,
horizontalalignment='center',
verticalalignment='top',
fontsize=7)
#Outer ring
ax.plot(rad,rad*0+ outring, c=colk, linewidth=linew, alpha=linea)
ax.plot(rad,rad*0+ calrad , c=colk, linewidth=linew, alpha=linea)
# the star catalogue and the constellations
plot_stars()
# the Ecliptic and its calendar
plot_ecliptic()
#======================================================================
def plot_plate():
# OVERLAY PLOT - MATER & PLATE
#!!! polar expects y_limits to be so that center < edge
# limits(-90,30) will work, limits(90,-30) will not
# ===> all declinations are multiplied by isouth
# to reverse all Northern plots
ax.set_xticks([])
ax.set_yticks([])
ax.grid(False)
ax.set_ylim(0., outring +20.)
ax.set_theta_direction(isouth*tradOrient)
ax.set_theta_zero_location("N")
write_legend(-1) # write stuff in the corners, -1 for mater
linea = linea_normal
#---------------------------------------------------------------
#- Azimuth grid
linea = linea_normal
linec = colb
for az in np.arange(0,360,5):
if az % 90 == 0:
linew = linew_thick
else:
linew = linew_thin
if az % 90 == 0:
zr = np.radians(np.arange(90.,-.01,-3.))
elif az % 15 == 0:
zr = np.radians(np.arange(90.,14.,-3.))
else:
zr = np.radians(np.arange(90.,86,-3.))
azr = np.radians(az)
wHAr, wDec = altaz2hadec(zr, azr)
HAr = wHAr[ wDec*isouth < northlim*isouth]
Dec = wDec[ wDec*isouth < northlim*isouth]
ax.plot(HAr, d2r(Dec*isouth) , c=linec, linewidth=linew, alpha=linea)
#labels
if az % 15 == 0:
zr = np.radians(np.arange(90.,-.01,-3.))
x0 = np.cos(HAr[0])*d2r(Dec[0]*isouth)
x1 = np.cos(HAr[1])*d2r(Dec[1]*isouth)
y0 = np.sin(HAr[0])*d2r(Dec[0]*isouth)
y1 = np.sin(HAr[1])*d2r(Dec[1]*isouth)
labang = -tradOrient*np.degrees(np.arctan2( (y1-y0), isouth*(x1-x0)))
if az == 90. or az == 270.:
labang = -labang
if isouth < 0:
labang += 180
xl = x0 - 3.*(x1-x0)
yl = y0 - 3.*(y1-y0)
rl = np.sqrt(xl*xl+yl*yl)
azl = np.arctan2(yl,xl)
if az == 90:
letter = "E"
else:
letter = "W"
ax.text(azl,rl,
letter,
rotation=labang,
fontsize = 20,
color=colb,
horizontalalignment='center',
verticalalignment='center')
if az < 180:
labang = -labang -90
else:
labang = -labang +90
labrad = d2r(Dec[2]*isouth)
if labrad < outring:
ax.text(HAr[2], labrad,
'{:03.0f}'.format(az),
rotation=labang,
fontsize = 6,
horizontalalignment='center',
verticalalignment='center')
#- ZD grid--------------------------------------------------
# airmass 2
z = 60.
linew = linew_thick
_ = plotAlmucantar(np.cos(np.radians(z)), zdcol)
# altitude almucanars
linew = linew_thin
for z in np.arange(15,90.,15.):
wh, wdelta = plotAlmucantar(np.cos(np.radians(z)), zdcol)
if isouth < 0:
myi = 0
else:
myi = int(len(wh)/2)
ax.text(wh[myi], d2r(wdelta[myi]*isouth+0.),
' h={:2d}$^o$ '.format(int(90-z)),
color=linec,
fontsize=4,
rotation=180.,
horizontalalignment='right',
verticalalignment='top')
#- airmass grid
linew = linew_thin
linea = linea_normal
linec = collb
for secz in np.array([1.1,1.2,1.3,1.6,1.8,2.5,3.,5., 7.]):
cosz = 1./secz
wh, wdelta = plotAlmucantar(cosz, airmasscol)
if isouth < 0:
myi = 0
else:
myi = int(len(wh)/2)
ax.text(wh[myi],d2r(wdelta[myi]*isouth),
' z={:2.1f} '.format(secz),
color=linec,
fontsize=4,
rotation=180.,
horizontalalignment='left',
verticalalignment='top')
#- Horizon
linea = linea_normal
z = 90.
linew = 3.
_ = plotAlmucantar(np.cos(np.radians(z)), airmasscol)
#- Twilights
myhlabel = ['Horizon', 'Civil Twilight', 'Nautical Twilight', 'Astronomical Twilight']
z = [90., 96., 102., 108.]
for i in np.arange(0,len(z)):
wh, wdelta = plotHalfmucantar( np.cos(np.radians(z[i])), linew )
myi = int(len(wh)/2)
ax.text(wh[myi],
d2r(wdelta[myi]*isouth)+4.,
myhlabel[i],color=linec,
fontsize=4,
horizontalalignment='center',
verticalalignment='center')
linew -= .7
#- white circle to mask the tails of twilights
myr = rad*0 + outring
ax.plot(rad,myr, color='white', linewidth=12)
#- Solar Time Circle
# (formarly UT)
linew = linew_thin
linea = linea_normal
colut = solcol
#- Solar time ticks
rin = outring -5
for m in np.arange(0, 1440): #minutes
myd = np.radians(np.array([m,m])/4.) # degrees, then rad
if m % 60 == 0:
myr = np.array([rin+7, rin]) ##
elif m % 10 == 0:
myr = np.array([rin+5, rin]) ##
elif m % 5 == 0:
myr = np.array([rin+3, rin]) ##
else:
myr = np.array([rin+2, rin]) ##
ax.plot(myd,myr,c=colut, linewidth=linew, alpha=linea)
#- circles
linew = linew_medium
myr = rad*0 + rin -5.
ax.plot(rad,myr, color=colut, linewidth=0.3)
myr = rad*0 + rin
ax.plot(rad,myr, color=colut, linewidth=0.3)
#- Hours labels
for h in hours:
if h == 12: # special marker for sidereal time
ax.plot([np.radians(h*15. + 180.)],
[rin +8.],
marker='^',
color=colk)
else:
ax.text(np.radians(h*15. + 180.),
rin +8.,
'{:02d}'.format(h),
rotation=tradOrient*isouth*h*15. ,
color=colut,
horizontalalignment='center',
verticalalignment='center',
fontsize=8)
#- "Solar Time" label
for i in [90,180,270]:
lang = i - tradOrient*isouth * 3.
ax.text(np.radians(lang),
rin+7.,
'Solar',
rotation= tradOrient*isouth*lang + 180,
color=colut,
horizontalalignment='center',
verticalalignment='center',
fontsize=5)
lang = i + tradOrient* isouth * 3.
ax.text(np.radians(lang),
rin+7.,
'Time',
rotation= tradOrient*isouth*lang + 180,
color=colut,
horizontalalignment='center',
verticalalignment='center',
fontsize=5 )
#- "Sid Time" label
lang = - tradOrient*isouth * 4.
ax.text(np.radians(lang),
rin+7.,
'Sidereal',
rotation= tradOrient*isouth*lang + 180,
color=colk,
horizontalalignment='center',
verticalalignment='center',
fontsize=5)
lang = + tradOrient* isouth * 3.
ax.text(np.radians(lang),
rin+7.,
'Time',
rotation= tradOrient*isouth*lang + 180,
color=colk,
horizontalalignment='center',
verticalalignment='center',
fontsize=5)
#- Longitude circle
collong = colg
offlong = xlong
rin = outring -10.
for d in np.arange(-179,181):
myd = -np.radians(d+180. -offlong) # degrees, then rad; 0 at bottom; # change orientation
if d % 30 == 0:
myr = np.array([rin-2, rin+5.]) ##
if d != 180:
ax.text(myd, rin-5,
'{:3d}$^o$'.format(d),
rotation= - tradOrient*isouth*(d -offlong),
color=collong,
horizontalalignment='center',
verticalalignment='center',
fontsize=8)
elif d % 10 == 0:
myr = np.array([rin, rin+5.]) ##
elif d % 5 == 0:
myr = np.array([rin +2., rin+5.]) ##
else:
myr = np.array([rin +3, rin+5.]) ##
ax.plot([myd,myd],myr,c=colk, linewidth=linew, alpha=linea)
lang = 180 +offlong - 6*isouth*tradOrient
ax.text(np.radians(lang),
rin-2.,
'Observatory',
rotation= tradOrient*isouth*lang + 180,
color=collong,
horizontalalignment='center',
verticalalignment='center',
fontsize=5)
lang = 180 +offlong +6 * isouth*tradOrient
ax.text(np.radians(lang),
rin-2.,
'longitude',
rotation= tradOrient*isouth*lang + 180,
color=collong,
horizontalalignment='center',
verticalalignment='center',
fontsize=5 )
lang = 155 + offlong
ax.text(np.radians(lang),
rin-2.,
'West',
rotation= tradOrient*isouth*lang + 180,
color=collong,
horizontalalignment='center',
verticalalignment='center',
fontsize=5 )
lang = 205 + offlong
ax.text(np.radians(lang),
rin-2.,
'East',
rotation= tradOrient*isouth*lang + 180,
color=collong,
horizontalalignment='center',
verticalalignment='center',
fontsize=5 )
#- circle
myr = rad*0 + rin +5.
ax.plot(rad,myr, color=collong, linewidth=0.3)
myr = rad*0 + rin
ax.plot(rad,myr, color=collong, linewidth=0.3)
#- Observatory name
ax.text(np.radians(180.),
outring*0.55 ,
obsname,
rotation=180,
color=collb,
horizontalalignment='center',
verticalalignment='center',
fontsize=20 )
#- Observatory coords
ax.text(np.radians(180.),
outring*0.65,
longlatlabel,
rotation=180,
color=colb,
horizontalalignment='center',
verticalalignment='center',
fontsize=10 )
if band: #scan and plot relevant observatories
with open(obsCleanFile) as in_file:
#- Observatory name
for line in in_file:
lobs,w = line.split("%")
lobsname = w.rstrip()
lobsCode, lobslat, lobslong, lobsalt = lobs.split()
if lobsCode[0] != '#':
wlat = float(lobslat)
wlong = -(float(lobslong) -offlong)
if abs(wlat-xlat) <= xlatband:
longr = np.radians(wlong +180.)