-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsourcemap.py
More file actions
783 lines (631 loc) · 31.3 KB
/
sourcemap.py
File metadata and controls
783 lines (631 loc) · 31.3 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 23 14:42:12 2015
@author: Matthew Siebert
"""
import numpy as np
import datetime
from tail import tail
from novas import compat as novas
from novas.compat import eph_manager
from pyqtgraph.Qt import QtGui, QtCore
from GUI_Form import GUI_Form
import sys
class SourceMap():
"""An instance contains information needed in the mapping of various
radio sources given by a sourcelist. Also includes methods and fields useful
for the source map gui application.
"""
def __init__(self, afile):
"""Constructor reads the source list file and initilizes fields to contain
coordinate data for the sources.
Args:
afile (str): A path to the file containing the sourcelist to be
displayed
"""
#read the file and acquire lines of data
thefile = open(afile, 'r')
self.datafile = thefile
self.lines = self.datafile.readlines()
for aline in self.lines:
if aline.rstrip() == '':
self.lines.remove(aline)
#fields to contain coordinate data of all sources
self.azpoints = []
self.elpoints = []
self.time = datetime.datetime.utcnow()
#fields to contain coordinate data of clicked source
self.toggletrack = False
self.clicksource = ""
self.clickazpoint = ''
self.clickelpoint = ''
self.clickazpoints = []
self.clickelpoints = []
self.clickra = ''
self.clickdec = ''
#fields to contain coordinate data of selected sources
self.selectedsources = []
self.sel_azpoints = []
self.sel_elpoints = []
#fields to contain coordinate data of added sources
self.added_sources = []
self.add_azpoints = []
self.add_elpoints = []
#fields to contain coordinate data of solar system bodies
self.toggle_ephem = True
self.ephems = []
self.ephem_azpoints = []
self.ephem_elpoints = []
self.ephem_colors = []
#fields to contain coordinate data of the antenna and target source
self.toggletrack_ant = False
self.antazpoint = 181
self.antazpoints = []
self.antelpoints = []
self.antelpoint = 45
self.cmdazpoint = 0
self.cmdelpoint = 0
self.skdfile = ''
self.skdline = 0
self.wrappoint = 0
self.azoff = 0
self.eloff = 0
self.usr_azoff = ''
self.usr_eloff = ''
self.azoffset_data = [0]
self.eloffset_data = [0]
self.striptime = [0]
self.togglestrips = False
self.azbias1 = ''
self.azbias2 = ''
self.elbias = ''
self.subdx = ''
self.subdy = ''
self.subdz = ''
self.subdpx = ''
self.subdpy = ''
self.deltdt = ''
self.dut1 = ''
self.deltat = ''
self.tdk = ''
self.dewpt = ''
self.rh = ''
self.pmb = ''
self.target = ''
self.tarsource = ''
self.tarra = ''
self.tardec = ''
self.tarazpoint = ''
self.tarelpoint = ''
self.onsource = ''
self.inttime = ''
self.npairs = ''
self.npoints = ''
self.duration = ''
self.freq = ''
self.rec = ''
self.bsw = ''
self.dfreq = ''
self.dbl = ''
self.fsw = ''
self.foffs = ''
self.vc = ''
self.ifoff = ''
self.ifoffa = ''
self.radecoff = ''
self.azel = ''
self.cal = ''
self.lorf = ''
self.lomult = ''
#fields useful for gui application
self.namelist = []
self.allsources = []
self.location = novas.OnSurface(latitude = 42.62322,
longitude = -71.488210, height = 56.241)
self.speed = 1
self.paused = False
self.uthrs = 0
self.jd_tt = ''
self.LST = ''
self.togglegrid = False
self.equ_grid_constra = [[],[],[],[],[],[],[],[],[],[],[],[]]
self.equ_grid_constdec = [[],[],[],[],[],[],[],[],[],[],[],[]]
def map_livetime(self):
"""Acquires the current time and lines of the datafile that include
sources with their coordinates.
"""
self.acquire_allsources()
jd_start, jd_end, number = eph_manager.ephem_open()
self.update()
def set_time(self, time):
"""Sets the three time parameters of the source map (univeral time in
hours, julian date, and local sidereal time) appropriately given a
datetime object.
Args:
time (datetime.datetime): The time to be used in synchronizing
all time parameters of the SourceMap.
"""
ut = str(time)
self.uthrs = ((float(ut.split()[1].split(":")[0]) +
(float(ut.split()[1].split(":")[1]) +
float(ut.split()[1].split(":")[2])/60)/60))
self.jd_tt = novas.julian_date(time.year, time.month, time.day, self.uthrs)
gst = novas.sidereal_time(int(self.jd_tt), self.jd_tt%1, 68)
self.LST = gst - (71.488210/15)*.9972695666
if self.LST < 0:
self.LST = 23.934444444 + self.LST
def update(self):
""" Updates the time of the SourceMap for the current map state
(paused, unpaused/live, unpaused/timelapse). Then updates the coordinates
of each source, the coordinates of the solar system bodies, the antenna
status, and the strip chart data according to this time.
"""
self.azpoints = []
self.elpoints = []
self.sel_azpoints = []
self.sel_elpoints = []
self.add_azpoints = []
self.add_elpoints = []
self.ephem_azpoints = []
self.ephem_elpoints = []
#don't change time if application is paused
if self.paused:
self.time = self.time
#use live time if timelapse speed is 0
elif not self.paused and self.speed == 0:
self.time = datetime.datetime.utcnow()
#speed up time if timelapse speed is nonzero
else:
self.time = self.time + datetime.timedelta(0,10*self.speed)
#calculate the julian date and lst
self.set_time(self.time)
#update solar system body coordinates if user has them turned on
if self.toggle_ephem:
self.update_ephem()
#update antenna status and strip charts
self.update_antenna()
if self.togglestrips:
self.update_strips()
#update all source coordinates given the updated time
for source in self.allsources:
if not source.split()[0] == self.clicksource and len(source.split()) < 10:
self.azpoints.append(self.get_source_coords(source)[1])
self.elpoints.append(self.get_source_coords(source)[2])
elif source.split()[0] == self.clicksource:
self.clicksource, self.clickazpoint, self.clickelpoint = \
self.get_source_coords(source)
if self.toggletrack:
self.clickazpoints.append(self.clickazpoint)
self.clickelpoints.append(self.clickelpoint)
if len(source.split()) > 9 and self.toggle_ephem:
self.ephem_azpoints.append(self.get_source_coords(source)[1])
self.ephem_elpoints.append(self.get_source_coords(source)[2])
self.ephem_colors.append(source.split()[-3:])
for source in self.selectedsources:
self.sel_azpoints.append(self.get_source_coords(source)[1])
self.sel_elpoints.append(self.get_source_coords(source)[2])
for source in self.added_sources:
self.add_azpoints.append(self.get_source_coords(source)[1])
self.add_elpoints.append(self.get_source_coords(source)[2])
def get_source_coords(self, source):
"""Uses pynovas to convert from ra and dec (given in the source list)
to azimuth and elevation at Haystack. This is done for the current time
of the map.
Args:
source (str): A string in the format of a source in the sourcelist.
Returns:
name (str): name of the source with these coordinates
az (float): azimuth (degrees) of source
el (float): elevation (degrees) of source
"""
name = source.split()[0]
ra = source.split()[1] + " " + source.split()[2] + " " + source.split()[3]
dec = source.split()[4] + " " + source.split()[5] + " " + source.split()[6]
#acquire ra and dec of the source. There is a typo in the sourcelist
if not ra.split()[2] == "01.37s":
ra1, ra2, ra3 = (float(ra.split()[0]),
float(ra.split()[1]),
float(ra.split()[2]))
else:
ra1, ra2, ra3 = (float(ra.split()[0]),
float(ra.split()[1]),
float(ra.split()[2][0:5]))
dec1, dec2, dec3 = (float(dec.split()[0]),
float(dec.split()[1]),
float(dec.split()[2]))
rahrs = (ra1 + (ra2 + ra3/60)/60)
if dec1 > 0:
decdeg = dec1 + (dec2 + dec3/60)/60
else:
decdeg = dec1 - (dec2 + dec3/60)/60
new_rahrs = rahrs
new_decdeg = decdeg
#calculate the true to date ra and dec
rtodeg = np.pi/180
if len(source.split()) < 10:
years_since2000 = ((self.time.year - 2000)
+ float(self.time.month)/12
+ float(self.time.day
+ float(self.time.hour)/24)/self.year_days())
#see Radio Astronomy by John D. Kraus pg. 2-25
new_rahrs = (rahrs + (.000853944 + .000371081*np.sin(rahrs*15*rtodeg)
*np.tan(decdeg*rtodeg))*years_since2000)%24
new_decdeg = decdeg + .005566194*np.cos(rahrs*15*rtodeg)*years_since2000
#update fields used to display true to date ra and dec
degree_sign= u'\N{DEGREE SIGN}'
if source.split()[0] == self.clicksource:
updated_source = self.to_source_format(new_rahrs, new_decdeg, source.split()[0])
self.clickra = (updated_source.split()[1] + "h " + updated_source.split()[2] +
"m " + "%.2f" %float(updated_source.split()[3]) + "s")
self.clickdec = (updated_source.split()[4] + "%s " %degree_sign
+ updated_source.split()[5]
+ "' " + "%.2f" %float(updated_source.split()[6]) + "\"")
if source.split()[0] == self.target:
updatedtar_source = self.to_source_format(new_rahrs, new_decdeg, source.split()[0])
self.tarsource = source
self.tarra = (updatedtar_source.split()[1] + "h " + updatedtar_source.split()[2] +
"m " + "%.2f" %float(updatedtar_source.split()[3]) + "s")
self.tardec = (updatedtar_source.split()[4] + "%s " % degree_sign
+ updatedtar_source.split()[5]
+ "' " + "%.2f" %float(updatedtar_source.split()[6]) + "\"")
#find azimuth and elevation for a given ra and dec and haystack's location
horiz, equ = novas.equ2hor(self.jd_tt, 68, 1, 0, self.location,
new_rahrs, new_decdeg, ref_option=0, accuracy=0)
az = horiz[1]
el = 90 - horiz[0]
return name, az, el
def year_days(self):
"""Calculates the number of days in the current year.
Returns:
int: 365 if not a leapyear, 366 if a leapyear
"""
i = self.time.year
if i%4 == 0:
if i%100 == 0:
if i%400 == 0:
yeardays = 366
else:
yeardays =365
else:
yeardays = 366
else:
yeardays = 365
return yeardays
def get_source_coordsgrid(self, coords, time):
"""Converts equatorial coordinates to horizontal coordinates at a
specific time.
Args:
coords (tuple (float,float)): A ra (hours) and a dec (degrees) to be
converted to az and el.
time (datetime.datetime): Contains the specific datetime object
to be used in coordinate conversion.
Returns:
az (float): azimuth (degrees)
el (float): elevation (degrees)
This is necessary when calculating the ra and dec gridlines
because ra and dec values are systematically determined and supplied
in tuples (not specified by a sourcelist).
"""
rahrs = coords[0]
decdeg = coords[1]
# calculate the time parameters associated with the given time
ut = str(time)
uthrs = (float(ut.split()[1].split(":")[0]) +
(float(ut.split()[1].split(":")[1]) +
float(ut.split()[1].split(":")[2])/60)/60)
ajd_tt = novas.julian_date(time.year, time.month, time.day, uthrs)
#find azimuth and elevation for a given ra and dec and haystack's location
horiz, equ = novas.equ2hor(ajd_tt, 65, 0, 0, self.location,
rahrs, decdeg, ref_option=0, accuracy=0)
az = horiz[1]
el = 90 - horiz[0]
return az, el
def update_ephem(self):
"""Using pynovas, updates the equatorial positions of the solar system
bodies given a time. Also asigns each solar system body a color, therefore,
after calling split(), the solar system body sources are always longer than
regular sources.
"""
#the solar system bodies are the last 10 sources
self.allsources = self.allsources[:-10]
#create sources containing solar system body coordinate and color information
#add them to a list of sources
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[0])
self.allsources.append(self.to_source_format(ra,dec,"Mercury") + " 255 120 0")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[1])
self.allsources.append(self.to_source_format(ra,dec,"Venus") + " 255 211 155")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[2])
self.allsources.append(self.to_source_format(ra,dec,"Mars") + " 255 0 0")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[3])
self.allsources.append(self.to_source_format(ra,dec,"Jupiter") + " 160 82 45")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[4])
self.allsources.append(self.to_source_format(ra,dec,"Saturn") + " 192 255 62")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[5])
self.allsources.append(self.to_source_format(ra,dec,"Uranus") + " 142 255 255")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[6])
self.allsources.append(self.to_source_format(ra,dec,"Neptune") + " 153 50 204")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[7])
self.allsources.append(self.to_source_format(ra,dec,"Pluto") + " 0 0 204")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[8])
self.allsources.append(self.to_source_format(ra,dec,"Sun") + " 255 255 0")
ra, dec, dis = novas.astro_planet(self.jd_tt, self.ephems[9])
self.allsources.append(self.to_source_format(ra,dec,"Moon") + " 205 201 201")
def update_antenna(self):
"""Tails the end of a three files that suppliy various information regarding
antenna status and the target source. Assigns these values to variables.
This will eventually process messages instead of a files.
"""
cmdfile = open('/tcu/rt/acu-cmd', 'r')
cmdlines = tail(cmdfile, lines = 36)
statfile = open('/tcu/rt/acu-status', 'r')
antlines = tail(statfile, lines = 14)
stat2file = open('/tcu/rt/status', 'r')
stats = tail(stat2file, lines = 108)
statlines = stats.split('\n')
#target source
if len (statlines[6].split()) == 3:
self.target = statlines[6].split()[2]
self.tarsource = ""
#find the target in the source list and determine the ra and dec
for source in self.allsources:
if source.split()[0].lower() == self.target.lower():
self.tarsource = source
#reset target source to default if it was not in the source list
az = 0
el = 0
if self.tarsource == "":
self.target = ""
#otherwise calculate the position on the map
else:
self.target, az, el = \
self.get_source_coords(self.tarsource)
self.tarazpoint = float(statlines[89].split()[2])
self.tarelpoint = float(statlines[90].split()[2])
self.cmdazpoint = float(cmdlines.split()[21])*(180/np.pi)
if self.cmdazpoint < 0:
self.cmdazpoint = 360 + self.cmdazpoint
elif self.cmdazpoint > 360:
self.cmdazpoint = self.cmdazpoint - 360
self.cmdelpoint = float(cmdlines.split()[30])*(180/np.pi)
self.antazpoint = float(antlines.split()[21])*(180/np.pi)
if self.antazpoint < 0:
self.antazpoint = 360 + self.antazpoint
elif self.antazpoint > 360:
self.antazpoint = self.antazpoint - 360
self.antelpoint = float(antlines.split()[33])*(180/np.pi)
if self.toggletrack_ant:
self.antazpoints.append(self.antazpoint)
self.antelpoints.append(self.antelpoint)
# self.skdfile = '/tcu/schedules/' + statlines[48].split('/')[2]
#TODO: set skdfile properly and display live schedule
self.skdfile = "(null)"
self.skdline = statlines[49].split()[2]
self.wrappoint = float(antlines.split()[21])
#calculate the offsets in antenna position
self.azoff = self.antazpoint - self.cmdazpoint
self.eloff = self.antelpoint - self.cmdelpoint
if len(statlines[31].split()) == 5:
self.usr_azoff = statlines[31].split()[3]
self.usr_eloff = statlines[31].split()[4]
self.onsource = statlines[59].split()[2]
#obtain various status information
self.azbias1 = statlines[65].split()[2]
self.azbias2 = statlines[66].split()[2]
self.elbias = statlines[67].split()[2]
self.subdx = statlines[76].split()[2]
self.subdy = statlines[77].split()[2]
self.subdz = statlines[78].split()[2]
self.subdpx = statlines[79].split()[2]
self.subdpy = statlines[80].split()[2]
self.deltdt = statlines[61].split()[2]
self.dut1 = statlines[62].split()[2]
self.deltat = statlines[63].split()[2]
self.tdk = statlines[71].split()[2] + " " + statlines[71].split()[3]
self.dewpt = statlines[72].split()[2] + " " + statlines[72].split()[3]
self.rh = statlines[73].split()[2]
self.pmb = statlines[74].split()[2] + " " + statlines[74].split()[3]
self.inttime = statlines[13].split()[3]
self.npairs = statlines[14].split()[2]
self.npoints = statlines[15].split()[2]
self.duration = statlines[16].split()[2]
self.freq = statlines[3].split()[2]
self.rec = statlines[4].split()[2]
self.bsw = statlines[17].split()[3]
self.dfreq = statlines[45].split()[3]
self.dbl = statlines[46].split()[3]
self.fsw = statlines[19].split()[3]
self.foffs = statlines[20].split()[3] + " " + statlines[20].split()[4] + " " +statlines[20].split()[5]
self.vc = statlines[23].split()[3] + " " + statlines[23].split()[4] + " " + statlines[23].split()[5] + " " + statlines[23].split()[6]
if len (statlines[24].split()) == 4:
self.ifoff = statlines[24].split()[3]
self.ifoffa = statlines[25].split()[3]
self.radecoff = statlines[26].split()[4] + " " + statlines[26].split()[5] + " " + statlines[26].split()[6]
self.azel = statlines[27].split()[2] + " " + statlines[27].split()[3]
self.cal = statlines[28].split()[2]
self.lorf = statlines[29].split()[2] + " " + statlines[29].split()[3]
self.lomult = statlines[30].split()[3]
def update_strips(self):
"""Called after update_antenna therefore it updates the strip chart
data with latest offset data.
"""
self.azoffset_data.append(self.azoff)
self.eloffset_data.append(self.eloff)
self.striptime.append(self.striptime[-1] + 1)
# self.striptime.append(self.LST)
def choose_source(self, name):
"""Changes the source to be highlighted and updates the necessary fields.
Args:
name (str): The name of the source to be highlighted.
This method is only called when the user clicks on a source.
"""
self.clicksource = name
self.clickazpoint = 0.0
self.clickelpoint = 0.0
self.clickazpoints = []
self.clickelpoints = []
for source in self.allsources:
if source.split()[0] == self.clicksource:
self.clicksource, self.clickazpoint, self.clickelpoint = self.get_source_coords(source)
self.clickazpoints.append(self.clickazpoint)
self.clickelpoints.append(self.clickelpoint)
def to_source_format(self, rahrs, decdeg, name):
"""Converts a name, a right ascension, and a declination into a string
with correct source formatting.
Args:
rahrs (float): ra (hours)
decdeg (float): dec (degrees)
name (str): The name to be assigned to this source
Returns:
str: A string in the format of a source in the sourcelist
This is useful for creating sources for ephemeride data, and updating
equatorial coordinates for other sources.
"""
#convert hours into dms
ramin = (rahrs%1)*60
rasec = (ramin%1)*60
rahrs = int(rahrs)
ramin = int(ramin)
#convert degrees into dms
decmin = (np.abs(decdeg)%1)*60
decsec = (decmin%1)*60
decdeg = int(decdeg)
decmin = int(decmin)
return ("%s " %(name) + str(rahrs) + " " + str(ramin) + " " + str(rasec) + " "
+ str(decdeg) + " " + str(decmin) + " " + str(decsec) + " " + "2000 " + "0.0")
def get_const_ragrid(self):
"""Constructs data for a grid with 12 constant right ascension values
to be overlayed and updated as time changes.
Returns:
ra_azpoints (nested list (float)): 12 lists of azimuth points, each list
corresponding to a constant value of right ascension
ra_elpoints (nested list (float)): 12 lists of elevation points, each list
corresponding to a constant value of right ascension
Each list in ra_azpoints will be plotted against the corresponding list
in ra_elpoints. This will be called periodically so thatthe gridlines
reflect the current time of the map.
"""
ra_azpoints = [[],[],[],[],[],[],[],[],[],[],[],[]]
ra_elpoints = [[],[],[],[],[],[],[],[],[],[],[],[]]
#convert these values to azimuth and elevation and add them to the nested list
for k in range(0, len(self.equ_grid_constra)):
for source in self.equ_grid_constra[k]:
ra_azpoints[k].append(self.get_source_coordsgrid(source, self.time)[0])
ra_elpoints[k].append(self.get_source_coordsgrid(source, self.time)[1])
return ra_azpoints, ra_elpoints
def get_const_decgrid(self):
"""Constructs data for a grid with 12 constant declination values to be
overlayed. These do not change with time so they do not need to be
updated.
Returns:
dec_azpoints (nested list (float)): 12 lists of azimuth points, each list
corresponding to a constant value of declination
dec_elpoints (nested list (float)): 12 lists of elevation points, each list
corresponding to a constant value of declination
Each list in dec_azpoints will be plotted against the corresponding list
in dec_elpoints.
"""
dec_azpoints = [[],[],[],[],[],[],[],[],[],[],[],[]]
dec_elpoints = [[],[],[],[],[],[],[],[],[],[],[],[]]
now = datetime.datetime.now()
atime = datetime.datetime(now.year, now.month, now.day, 12, 0, 0)
#convert these values to azimuth and elevation and add them to the nested list
for k in range(0,len(self.equ_grid_constdec)):
for source in self.equ_grid_constdec[k]:
dec_azpoints[k].append(self.get_source_coordsgrid(source, atime)[0])
dec_elpoints[k].append(self.get_source_coordsgrid(source, atime)[1])
temp = dec_azpoints[:]
temp2 = dec_elpoints[:]
redo = []
redo2 = []
#account for the fact that if azimuth changes from 0 to 360 or vice versa,
#the plotcurve will draw a line across the screen
for k in range(0,len(temp)):
for i in range(0, len(temp[k])-1):
if temp[k][i] >300 and temp[k][i+1] < 50:
dec_azpoints[k] = dec_azpoints[k][:i+1]
dec_elpoints[k] = dec_elpoints[k][:i+1]
redo.append(temp[k][i+1:])
redo2.append(temp2[k][i+1:])
if temp[k][i] < 50 and temp[k][i+1] > 300:
dec_azpoints[k] = dec_azpoints[k][:i+1]
dec_elpoints[k] = dec_elpoints[k][:i+1]
dec_azpoints.append(temp[k][i+1:])
dec_elpoints.append(temp2[k][i+1:])
for k in range(0, len(redo)):
for i in range(0,len(redo[k])-1):
if redo[k][i] < 50 and redo[k][i+1] > 300:
dec_azpoints.append(redo[k][:i+1])
dec_elpoints.append(redo2[k][:i+1])
dec_azpoints.append(redo[k][i+1:])
dec_elpoints.append(redo2[k][i+1:])
return dec_azpoints, dec_elpoints
def acquire_allsources(self):
"""Iterates through source list and acquires all lines containing a
source with coordinates. Also adds on solar system bodies using the same format
and creates lists of equatorial coordinates needed for grid calculation.
"""
for aline in self.lines:
if self.is_dataline(aline):
self.allsources.append(aline)
self.namelist.append(aline.split()[0])
#create a list of all solar system body objects
self.ephems = [novas.make_object(0, 1, 'Mercury', None), novas.make_object(0, 2, 'Venus', None),
novas.make_object(0, 4, 'Mars', None), novas.make_object(0, 5, 'Jupiter', None),
novas.make_object(0, 6, 'Saturn', None), novas.make_object(0, 7, 'Uranus', None),
novas.make_object(0, 8, 'Neptune', None), novas.make_object(0, 9, 'Pluto', None),
novas.make_object(0, 10, 'Sun', None), novas.make_object(0, 11, 'Moon', None)]
#add temorary solar system body sources to allsources
self.allsources.append("Mercury 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Venus 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Mars 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Jupiter 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Saturn 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Uranus 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Neptune 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Pluto 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Sun 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
self.allsources.append("Moon 0 0 0.0 +0 0 0.0 2000 0.0 0 0 0")
def my_range(start, end, step):
while start <= end:
yield start
start += step
#create lists of fake source coordinates that can be used to find gridlines
#for constant right ascension and declination
for k in range(0, len(self.equ_grid_constra)):
for i in my_range(-90, 90, 1.5):
self.equ_grid_constra[k].append([2*k, i])
for k in range(0,len(self.equ_grid_constdec)):
for i in my_range(0, 24, .025):
self.equ_grid_constdec[k].append([i, -90 + k*15])
def is_dataline(self, aline):
"""Determines whether a given line in a source list contains a source
and its coordinates.
Args:
aline (str): a line from a sourcelist that may contain a source
with coordinate information.
Returns:
bool: True if line contains a source, False if the line contains
other information
"""
if len(aline.split()) == 9 and aline.split()[7] == "2000":
return True
else:
return False
if __name__ == '__main__':
#create an application
app = app = QtGui.QApplication([])
app.setGraphicsSystem('raster')
fileChoice = QtGui.QFileDialog.getOpenFileName(filter = "*.lst")
if not fileChoice == '':
#create instance of SourceMap and collect coordinate data
newmap = SourceMap(fileChoice)
newmap.map_livetime()
#setup the gui
gui = GUI_Form(newmap)
#connect timer so plot continuously updates
timer = QtCore.QTimer()
timer.timeout.connect(gui.update)
timer.start(0)
#start Qt event loop unless running in interactive mode.
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()