class Moon(object): def __init__(self): """Getting user-values from config_values module.""" self.user = UserValues() self.aladin = AladinScriptCommands() self.latitude = self.user.get_latitude() self.longitude = self.user.get_longitude() self.altitude = self.user.get_altitude() self.obs_time = Time(self.user.get_obs_time()) self.dt = TimeDelta(7200.0, format='sec') self.step = 0 self.end_step = 11 def get_location(self): observatory = astropy.coordinates.EarthLocation( lat=self.latitude * u.deg, lon=self.longitude * u.deg, height=self.altitude * u.m) return observatory def get_time(self): self.time = Time(self.obs_time) return self.time def moon_on_sky(self): self.get_location() #self.get.time() self.sky_position() def steps(self): """Moon position in step of one hour for an input sky position (ra, dec). 10 steps are performed: step <10; dt = 1h.""" #obs_time = Time(self.obs_time) self.aladin.draw_newtool("Moon") self.time = Time(self.obs_time) self.observatory = self.get_location() while self.step < self.end_step: time_update = self.time + self.step * self.dt position_moon = get_moon(time_update, self.observatory) #val = self.airmass(ra, dec, self.altitude, self.longitude, self.altitude, # time_input) #self.airmass_list.append(val) #self.time_list.append(str(time_input)) self.step += 1 self.aladin.draw_string(position_moon.ra, position_moon.dec, "MOON" + "-->" + str(time_update.isot)) #print str(time_update.isot) #print position_moon.ra, position_moon.ra def illumination(self): """Return the fraction of the moon illumination. Modified version of astroplan project.""" sun = get_sun(self.obs_time) observatory = self.get_location() moon = get_moon(self.obs_time, observatory) #print moon elongation = sun.separation(moon) i = np.arctan2(sun.distance * np.sin(elongation), moon.distance - sun.distance * np.cos(elongation)) k = (1 + np.cos(i)) / 2.0 return round(k.value, 2) def from_fov(self, ra_fov_center, dec_fov_center): """ Return the Moon position over the sky.""" observatory = self.get_location() moon = get_moon(self.obs_time, observatory) distance = Utils.separation(ra_fov_center, dec_fov_center, moon.ra, moon.dec) #print moon.ra*u.deg, moon.dec*u.deg return distance.deg def sky_position(self): """Plot the Moon position on the Aladin plane.""" time = Time(self.obs_time) observatory = self.get_location() position_moon = get_moon(time, observatory) illumination = self.illumination() #self.aladin.draw_string(position_moon.ra, position_moon.dec, "MOON position") self.aladin.draw_moon(position_moon.ra, position_moon.dec, illumination)
class Observability(Toplevel): """Initializi""" def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() self.moc = MOC_confidence_region() self.observatory = astropy.coordinates.EarthLocation( lat=self.user.get_latitude() * u.deg, lon=self.user.get_longitude() * u.deg, height=self.user.get_altitude() * u.m) self.wait_visibility() self.wm_attributes('-alpha', 0.8) # transparency self.title("Observability" + "starting from" + self.user.get_obs_time()) self.attributes("-topmost", True) self.bttn_clicks = 0 # counter ">>" Button # first label self.label_1 = Label(self, text="Show the region in the", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, padx=0) moc_value = 90 # default moc_default = StringVar(self, value=moc_value) self.entry_percentage = Entry(self, width=5, justify=CENTER, textvariable=moc_default) self.entry_percentage.grid(row=0, padx=2, column=1) # second label self.label_2 = Label(self, text="% MOC in which the airmass is ≤", bg="slate grey") self.label_2.grid(row=0, column=2, sticky=E, pady=0) airmass_value = "2.5" # default airmass_default = StringVar(self, value=airmass_value) self.entry_airmass = Entry(self, width=5, justify=CENTER, textvariable=airmass_default) self.entry_airmass.grid(row=0, padx=2, column=3) #Btn self.show = Button(self, text='Show', command=self.moc_obs) self.show.grid(column=4, row=0, sticky=W, padx=2, pady=5) #self.moon = Button(self, text="Sun/Moon", # command=self.close_window) #self.moon.grid(column=5,row=0, sticky=W, padx=2, pady=5) self.forward = Button(self, text=">>", command=self.moc_obs_update) self.forward.grid(column=6, row=0, sticky=E, padx=2, pady=5) self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=7, row=0, sticky=E, padx=2, pady=5) #Actions def update_count(self): """Return the time in step of 1h when the button ">>" is clicked.""" self.bttn_clicks += 1 dt = TimeDelta(3600.0, format='sec') update_time = int(self.bttn_clicks) * dt obs_time = Time(self.user.get_obs_time()) time_update = obs_time + update_time return time_update def from_ipixs_to_moc(self, time_input): """Return ipix table with the associated airmass""" prob = self.moc.read_prob(self.user.get_skymap()) percentage = float(self.entry_percentage.get()) / 100.0 ipixs = self.moc.ipixs_in_percentage(prob, percentage) nside = int(self.user.get_nside()) ra, dec = self.moc.sky_coords(ipixs, nside) sky_coord = SkyCoord(ra=ra * u.deg, dec=dec * u.deg, frame='icrs') altaz = sky_coord.transform_to( AltAz(obstime=time_input, location=self.observatory)) airmass_values = altaz.secz contour_ipix = Table([ra, dec, airmass_values, ipixs], names=('RA[deg]', 'DEC[deg]', 'airmass', 'ipix'), meta={'ipix': 'ipix table'}) # astropy table mask = (contour_ipix['airmass']) >= 1 # clearing obs1 = contour_ipix[mask] mask2 = (obs1['airmass']) <= float( self.entry_airmass.get()) # airmass user values obs = obs1[mask2] # test print obs nside = self.user.get_nside() if len(obs) == 0: tkMessageBox.showinfo('MOC visibility', 'No region for the selected airmass') else: moc_order = self.moc.moc_order(nside) moc = MOC.from_table(obs, 'RA[deg]', 'DEC[deg]', moc_order) # moc creation moc.write('obs_airmass_', format='fits') # fit file return aladin.send_file('obs_airmass_') def moc_obs(self): """Return the MOC region in which the airmass is <= the airmass value defined by the user.""" time_start = self.user.get_obs_time() contour_ipix = self.from_ipixs_to_moc(time_start) percentage = float(self.entry_percentage.get()) / 100.0 aladin.rename('obs_airmass_' + self.entry_airmass.get() + 'MOC_' + str(percentage)) # test print time_start def moc_obs_update(self): """Return the MOC region in which the airmass is <= the airmass value defined by the user.""" time_update = self.update_count() contour_ipix = self.from_ipixs_to_moc(time_update) percentage = float(self.entry_percentage.get()) / 100.0 aladin.rename('obs_airmass_' + self.entry_airmass.get() + 'MOC_' + str(percentage) + '@' + str(time_update.isot)) # test print time_update def close_window(self): self.destroy()
class Airmass(object): """Airmass calculation from 1 to 5.8 by default.""" def __init__(self): """Getting user-values from config_values module.""" self.user = UserValues() self.latitude = self.user.get_latitude() self.longitude = self.user.get_longitude() self.altitude = self.user.get_altitude() self.obs_time = self.user.get_obs_time() self.dt = TimeDelta(3600.0, format='sec') self.airmass_list = [] self.time_list = [] self.step = 0 self.end_step = 11 def airmass(self, ra, dec, lat, lon, height, time_input, airmass_min=1, airmass_max=5.8): """ Airmass calculation at a given time in a particular site for an input sky position (ra, dec) in degrees. The airmass is calculated in the range [airmass_min, airmass_max].""" observatory = astropy.coordinates.EarthLocation( lat=self.latitude * u.deg, lon=self.longitude * u.deg, height=self.altitude * u.m) sky_coord = SkyCoord(ra=ra * u.deg, dec=dec * u.deg, frame='icrs') time = Time(time_input) altaz = sky_coord.transform_to( AltAz(obstime=time, location=observatory)) airmass_value = altaz.secz if airmass_value < airmass_min or airmass_value > airmass_max: airmass_value = "nan" return airmass_value else: airmass_value = round(float(airmass_value), 2) return airmass_value def airmass_step(self, ra, dec): """Airmass calculation in step of one hour for an input sky position (ra, dec) in degrees. 10 steps are performed: step <10; dt = 1h.""" obs_time = Time(self.obs_time) while self.step < self.end_step: time_input = obs_time + self.step * self.dt val = self.airmass(ra, dec, self.altitude, self.longitude, self.altitude, time_input) self.airmass_list.append(val) self.time_list.append(str(time_input)) self.step += 1 return self.airmass_list, self.time_list
class Observability(Toplevel): """Initializi""" def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() self.moc = MOC_confidence_region() self.observatory = astropy.coordinates.EarthLocation( lat=self.user.get_latitude()*u.deg, lon=self.user.get_longitude()*u.deg, height=self.user.get_altitude()*u.m) self.wait_visibility() self.wm_attributes('-alpha',0.8) # transparency self.title("Observability" + "starting from" + self.user.get_obs_time()) self.attributes("-topmost", True) self.bttn_clicks = 0 # counter ">>" Button # first label self.label_1 = Label(self, text="Show the region in the", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, padx=0) moc_value = 90 # default moc_default = StringVar(self, value=moc_value) self.entry_percentage = Entry(self, width=5, justify=CENTER, textvariable=moc_default) self.entry_percentage.grid(row=0, padx=2, column=1) # second label self.label_2 = Label(self, text="% MOC in which the airmass is ≤", bg="slate grey") self.label_2.grid(row=0, column=2, sticky=E, pady=0) airmass_value = "2.5" # default airmass_default = StringVar(self, value=airmass_value) self.entry_airmass = Entry(self, width=5, justify=CENTER, textvariable=airmass_default) self.entry_airmass.grid(row=0, padx=2, column=3) #Btn self.show = Button(self, text='Show', command=self.moc_obs) self.show.grid(column=4, row=0, sticky=W, padx=2, pady=5) #self.moon = Button(self, text="Sun/Moon", # command=self.close_window) #self.moon.grid(column=5,row=0, sticky=W, padx=2, pady=5) self.forward = Button(self, text=">>", command=self.moc_obs_update) self.forward.grid(column=6,row=0, sticky=E, padx=2, pady=5) self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=7,row=0, sticky=E, padx=2, pady=5) #Actions def update_count(self): """Return the time in step of 1h when the button ">>" is clicked.""" self.bttn_clicks += 1 dt = TimeDelta(3600.0, format='sec') update_time = int(self.bttn_clicks) * dt obs_time = Time(self.user.get_obs_time()) time_update = obs_time + update_time return time_update def from_ipixs_to_moc(self, time_input): """Return ipix table with the associated airmass""" prob = self.moc.read_prob(self.user.get_skymap()) percentage = float(self.entry_percentage.get())/100.0 ipixs = self.moc.ipixs_in_percentage(prob, percentage ) nside = int(self.user.get_nside()) ra, dec = self.moc.sky_coords(ipixs, nside) sky_coord = SkyCoord(ra = ra*u.deg,dec=dec*u.deg, frame='icrs') altaz = sky_coord.transform_to(AltAz(obstime=time_input, location=self.observatory)) airmass_values = altaz.secz contour_ipix = Table([ ra, dec, airmass_values, ipixs ], names = ('RA[deg]', 'DEC[deg]', 'airmass', 'ipix'), meta = {'ipix': 'ipix table'}) # astropy table mask = (contour_ipix['airmass']) >= 1 # clearing obs1 = contour_ipix[mask] mask2 = (obs1['airmass']) <= float(self.entry_airmass.get()) # airmass user values obs = obs1[mask2] # test print obs nside = self.user.get_nside() if len(obs)==0: tkMessageBox.showinfo('MOC visibility', 'No region for the selected airmass') else: moc_order = self.moc.moc_order(nside) moc = MOC.from_table( obs, 'RA[deg]', 'DEC[deg]', moc_order ) # moc creation moc.write( 'obs_airmass_', format = 'fits' ) # fit file return aladin.send_file('obs_airmass_') def moc_obs(self): """Return the MOC region in which the airmass is <= the airmass value defined by the user.""" time_start = self.user.get_obs_time() contour_ipix = self.from_ipixs_to_moc(time_start) percentage = float(self.entry_percentage.get())/100.0 aladin.rename('obs_airmass_'+self.entry_airmass.get()+'MOC_'+str(percentage)) # test print time_start def moc_obs_update(self): """Return the MOC region in which the airmass is <= the airmass value defined by the user.""" time_update = self.update_count() contour_ipix = self.from_ipixs_to_moc(time_update) percentage = float(self.entry_percentage.get())/100.0 aladin.rename('obs_airmass_'+self.entry_airmass.get()+'MOC_'+str(percentage)+ '@' + str(time_update.isot)) # test print time_update def close_window(self): self.destroy()