2121from collections import Counter
2222from astropy import units as u
2323from astropy .time import Time
24+ from astropy .coordinates import SkyCoord , EarthLocation , AltAz
2425import re
26+ import json
2527
2628# This funtion needs to be up here so it can be called during 'setup'
2729def formatWds (wds ):
@@ -215,6 +217,37 @@ def hhmmssSubtract(first, second):
215217 return hh + mm + ss
216218
217219
220+ def ddmmssToDeg (coordinate ):
221+ # Check for + or - for Dec, and save so can add back later
222+ leadingSign = ''
223+ if '-' in str (coordinate ):
224+ leadingSign = '-'
225+ elif '+' in str (coordinate ):
226+ leadingSign = '+'
227+
228+ data = float (coordinate )
229+ # Split the float into hh, mm, and ss
230+ # Casting all of the splits into int before string so there are no
231+ # trailing decimal points
232+ # Except seconds are rounded to 2 decimal points
233+ seconds = data % 100
234+ minutes = (data % 10000 - data % 100 ) / 100
235+ degrees = (data % 1000000 - data % 10000 ) / 10000
236+
237+ # Divide through from mmss to decimal
238+ minutes = minutes / 60.0
239+ seconds = seconds / 3600.0
240+ degrees = float (leadingSign + str (degrees ))
241+
242+ degrees = degrees + minutes + seconds
243+ # TODO this isn't the best fix. Why are some of the lats out of range?
244+ if degrees < - 90.0 :
245+ degrees = - 90.0
246+ elif degrees > 90.0 :
247+ degrees = 90.0
248+
249+ return degrees
250+
218251def floatStringToColonSeparated (coordinate ):
219252 # Check for + or - for Dec, and save so can add back later
220253 leadingSign = ''
@@ -422,12 +455,54 @@ def setLocationConstraints(latitude=340000.0, viewWidth=350000.0):#northDec=(340
422455 # Using JPL's latitude, 34.2 deg = 34 deg
423456 northDec = latitude + viewWidth
424457 southDec = latitude - viewWidth
458+
459+ # Check rollover for dec constraints
460+ if northDec > 900000 :
461+ northDec = 900000
462+ if southDec < - 900000 :
463+ southDec = - 900000
425464
426465 # the north dec is the "upper bound", so it's first in the tuple
427466 constraints ['dec' ] = (northDec , southDec )
428467
429468
430- def constrain ():
469+ def addAirmassCol ():
470+ '''
471+ Add a columns to the WDS table which is the calculated airmass for
472+ each object based off of its RA Dec and the location and time of
473+ the constrain.
474+ '''
475+ # Currently does NOT work! TODO
476+ # There is an astropy issue https://github.com/astropy/astropy/issues/5726
477+ # which will be fixed in astropy v1.3.1, but as of 2017-02-15 only
478+ # version 1.3(.0) has been released.
479+
480+ secz = []
481+ # Loop over all the radec angles
482+ for i in range (0 , len (wdsInteresting [raCoors ])):
483+ # Create a SkyCoord object from the RA and Dec
484+ #ra = floatStringToColonSeparated(wdsInteresting[raCoors][i])
485+ #dec = floatStringToColonSeparated(wdsInteresting[decCoors][i])
486+ ra = ddmmssToDeg (wdsInteresting [raCoors ][i ])
487+ dec = ddmmssToDeg (wdsInteresting [decCoors ][i ])
488+ starPos = SkyCoord (ra , dec , unit = (u .hour , u .deg ))
489+
490+ # Create an AltAz frame object
491+ preferences = {}
492+ with open ('WDS_Preferences.json' , 'r' ) as fp :
493+ preferences = json .load (fp )
494+ observing_location = EarthLocation (lat = preferences ['latitude' ], lon = preferences ['longitude' ])
495+ aa = AltAz (location = observing_location )#, obstime=observing_time)
496+
497+
498+ # Add the list as new column to the wds table
499+ raCol = astropy .table .Column (data = ra , name = 'RA' )
500+ wds .add_column (deltaMagCol )
501+
502+ return wds
503+
504+
505+ def constrain (airmass = False ):
431506 '''
432507 Limits the WDS table to only stars that match our criteria.
433508 Creates wdsInteresting and wdsInterestingHere tables which
@@ -442,14 +517,20 @@ def constrain():
442517 global wdsInterestingHere
443518 global constraints
444519
445- # Print what we are constraining with so it seems a bit responsive before the long processing
520+ # Print what we are constraining with so it seems a bit responsive before
521+ # the long processing
446522 print ("Constraining WDS with:" )
447523 print (constraints )
448524
449525 # Reset what wdsInteresting and wdsInterestingHere are so that we
450526 # can get stars which we previously constrained out
451527 wdsInteresting = wdsMaster
452528 wdsInterestingHere = wdsMaster
529+
530+ # If we are told to do so, make an airmass column for the table
531+ #if airmass:
532+ #addAirmassCol()
533+ # TODO add this back in after associated astropy 1.3.1 has been released
453534
454535 # Make a dictionary of limits (just for compactness).
455536 # Contains the boolean expressions with witch the wds table
0 commit comments