def __init__(self, infile_coords='GWsky_coords'): """Creating a class in which the instance attributes are based on the dictionary "GWsky_coords" by default. GWsky_coords is created and pickled by the "config_values" module and will be deleted when the "SkyCoverageGUI" will be closed. It contains the keys: "ra", "dec". ra and dec represents the central location of a FoV. Starting sky coordinates: self.input_ra: right ascension [deg] self.input_dec: declination [deg] """ self.infile_coords = infile_coords self.entries_GWsky_new = [] # new entries during the FoV sequence self.user = UserValues() # compositions self.lvc = LVCskymap() self.query = Query() self.airmass = Airmass() self.moon = Moon() with open(infile_coords, 'rb') as data: coords_GWsky = pickle.load(data) for k, v in coords_GWsky.items(): setattr(self, k, v)
def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() # get trasparency windows self.wait_visibility() self.wm_attributes('-alpha', trasparency) self.title("Load a new skymap") self.attributes("-topmost", True) self.label_1 = Label(self, text="LVC skymap", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, pady=0) # default: input skymap skymap_input = StringVar(self, value=self.user.get_skymap()) self.entry_new_skymap = Entry(self, width=30, justify=CENTER, textvariable=skymap_input) self.entry_new_skymap.grid(row=0, padx=15, column=1) #Btns self.show = Button(self, text='Load', command=self.new_skymap) self.show.grid(column=2, row=0, sticky=W, padx=2, pady=5) self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=5, row=0, sticky=E, padx=2, pady=5)
def __init__(self): self.user = UserValues() #comp. self.skymap = self.user.get_skymap() print(self.skymap) # TEST self.nside = self.user.get_nside() self.is_3d = Is3d(self.skymap) #comp --> eredita self.tfield, self.header = self.is_3d.get_header() self.prob, self.distmu, self.distsigma, self.distnorm = self.is_3d.get_values( self.tfield)
def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() # putting the entry value(s) in a list self.entries_GWsky = [] self.wait_visibility() self.wm_attributes('-alpha', 0.8) # transparency self.title(" Starting FoV") self.attributes("-topmost", True) self.label_1 = Label(self, text="RA (°) DEC (°)", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, pady=0) # default: sky coords of maximum probability pixel fov_coords = str(self.user.get_ra_max_pixel()), str( self.user.get_dec_max_pixel()) max_pixel_default = StringVar(self, value=fov_coords) self.entry_1 = Entry(self, width=30, justify=CENTER, textvariable=max_pixel_default) self.entry_1.grid(row=0, padx=15, column=1) self.entryScroll = Scrollbar(self, orient=HORIZONTAL, command=self.__scrollHandler) self.entryScroll.grid(row=1, column=1, sticky=E + W) self.entry_1['xscrollcommand'] = self.entryScroll.set #Btn self.show = Button(self, text='Show', command=self.show_starting_fov) self.show.grid(column=2, row=0, sticky=W, padx=2, pady=5) self.checkbox = Button(self, text="Not show", command=self.no_show_starting_fov) self.checkbox.grid(column=3, row=0, sticky=E, padx=2, pady=5) self.close = Button(self, text="Obs", fg='dark green', command=self.obs) self.close.grid(column=4, row=0, sticky=W, padx=2, pady=5) self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=5, row=0, sticky=E, padx=2, pady=5)
def pinpoint(self, ra_transient, dec_transient, label): """Finding in which confidence level the source falls. Input parameters --------------- ra_transient, dec_transient : float sky coordinates in degrees label : string id source transient """ # (re)initialization: skymap/nside self.user = UserValues() skymap = self.user.get_skymap() nside = int(self.user.get_nside()) # getting probability array prob = moc.read_prob(skymap) # user input values: from/to/resolution from_percentage = float(self.entry_from.get())/100.0 to_percentage = float(self.entry_to.get())/100.0 resolution_percentage = float(self.entry_grid.get())/100.0 # from sky coords to ipix ipix = healpixIpix.find_ipix(ra_transient, dec_transient, nside) find = "n" while from_percentage <= to_percentage or find =="y": ipixs = moc.ipixs_in_percentage(prob, from_percentage) is_there = ipix in ipixs # is the ipix within the MOC contour plot defined by user? if is_there != True: # ipix not found from_percentage = from_percentage + resolution_percentage else: find = "y" # ipix found res_yes = ("The sky coord" + " " + "ra="+str(ra_transient)+"°," + ' ' + "dec="+str(dec_transient)+"°"+" " + "(label:" + label+")" \ "lies within the" + " " + str(from_percentage*100)+'%' + " " + "c.l.\n" +"["+skymap+"]") MSG.pinpoint_find(label, res_yes) return find # ipix not found [from_percentage -- to_percentage] from_percentage = to_percentage res_no = ("The sky coord" + " " + "ra="+str(ra_transient)+"°," + ' ' + "dec="+str(dec_transient)+"°"+" " + "(label:" + label+")" \ + " " + "is not localized within the" + " " + str(from_percentage*100)+'%' + " " + "c.l.\n" +"["+skymap+"]") MSG.pinpoint_nofind(label, res_no)
def in_skymap(self): """Checking if an object falls in a given probability level defined by an user. List of sources are inserted in 'self.entry_sources'.""" aladin.md(self.entry_folder.get()) # creating folder defined by user aladin.remove(self.entry_folder.get() + '~1') # removing multiple copy of the folder # TO DO BETTER # (re)initialization: skymap/nside self.user = UserValues() skymap = self.user.get_skymap() nside = int(self.user.get_nside()) # getting probability array prob = moc.read_prob(skymap) # user input: MOC confidence level in percentage percentage = float(self.entry_percentage.get())/100.0 # splitting the entries labels, ra_transients, dec_transients = self.__split_entries_3() for ra_transient, dec_transient, label in zip( ra_transients, dec_transients, labels): # aladin stack organization: draw source position/move in folder aladin.draw_newtool(label) aladin.draw_source(ra_transient, dec_transient, label) aladin.mv(label, self.entry_folder.get()) # from sky coords to ipix ipixs = moc.ipixs_in_percentage(prob, percentage) try: ipix = healpixIpix.find_ipix(ra_transient, dec_transient, nside) is_there = ipix in ipixs # is the ipix within the MOC contour plot defined by user? if is_there is True: # ipix found res_true = ("The sky coord" + " " + "ra="+str(ra_transient)+"°," + " " + "dec="+str(dec_transient)+"°" + " " + \ "(labels: " + label+")" + " " + "lies within the" + " " + str(percentage*100)+'%' + " " + "c.l.\n" +"["+skymap+"]") MSG.in_skymap_true(label, res_true) else: res_false = ("The sky coord" + " " + "ra="+str(ra_transient)+"°," + " " +"dec="+str(dec_transient)+"°" + " " + \ "(labels: " + label+")" + " " + "is outside the" + " " + str(percentage*100)+'%' + " " + "c.l.\n" + "["+skymap+"]") MSG.in_skymap_false(label, res_false) except ValueError as value_error: MSG.value_error(value_error)
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 __cond_distance_source(self, label, r, dp_dr): """Plot of the conditional distance distribution along the line of sight.""" # (re)initialization: skymap self.user = UserValues() skymap=self.user.get_skymap() fig, ax = plt.subplots() ax.plot(r, dp_dr) title_string = label + ':' + ' '+ ' \n conditional distance distribution along the line of sight \n' + '['+skymap+']' ax.set_title(title_string,fontsize=10) ax.set_xlabel('distance (Mpc)') ax.set_ylabel('prob Mpc$^{-1}$') plt.show()
def __init__(self, infile_coords='GWsky_coords'): """Creating a class in which the instance attributes are based on the dictionary "GWsky_coords" by default. GWsky_coords is created and pickled by the "config_values" module and will be deleted when the "SkyCoverageGUI" will be closed. It contains the keys: "ra", "dec". ra and dec represents the central location of a FoV. Starting sky coordinates: self.input_ra: right ascension [deg] self.input_dec: declination [deg] """ self.infile_coords = infile_coords self.entries_GWsky_new =[] # new entries during the FoV sequence self.user = UserValues() # compositions self.lvc = LVCskymap() self.query = Query() self.airmass = Airmass() self.moon = Moon() with open(infile_coords, 'rb') as data: coords_GWsky = pickle.load(data) for k, v in coords_GWsky.items(): setattr(self, k, v)
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 __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)
def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() # putting the entry value(s) in a list self.entries_GWsky=[] self.wait_visibility() self.wm_attributes('-alpha', 0.8) # transparency self.title(" Starting FoV") self.attributes("-topmost", True) self.label_1 = Label(self, text="RA (°) DEC (°)", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, pady=0) # default: sky coords of maximum probability pixel fov_coords = str(self.user.get_ra_max_pixel()), str(self.user.get_dec_max_pixel()) max_pixel_default = StringVar(self, value=fov_coords) self.entry_1 = Entry(self, width=30, justify=CENTER, textvariable=max_pixel_default) self.entry_1.grid(row=0, padx=15, column=1) self.entryScroll = Scrollbar(self, orient=HORIZONTAL, command=self.__scrollHandler) self.entryScroll.grid(row=1, column=1, sticky=E+W) self.entry_1['xscrollcommand'] = self.entryScroll.set #Btn self.show = Button(self, text='Show', command=self.show_starting_fov) self.show.grid(column=2, row=0, sticky=W, padx=2, pady=5) self.checkbox = Button(self, text="Not show", command=self.no_show_starting_fov) self.checkbox.grid(column=3,row=0, sticky=E, padx=2, pady=5) self.close = Button(self, text="Obs", fg='dark green', command=self.obs) self.close.grid(column=4,row=0, sticky=W, padx=2, pady=5) self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=5,row=0, sticky=E, padx=2, pady=5)
class StartingFoV(Toplevel): """Starting a sequence from a list of FoV(s). The window contains 1 keyboard entries and 3 Buttons. entry: ra_1 dec_1 ra_2 dec_2 ra_3 dec_3 ... ra_n dec_n [deg] By default: sky coords of maximum probability pixel Btns: Show : draw user-defined FoV footprint(s) in Aladin Plane(s) No show : no draw user-defined FoV footprint(s) in Aladin Plane(s) Close : close the widget """ def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() # putting the entry value(s) in a list self.entries_GWsky=[] self.wait_visibility() self.wm_attributes('-alpha', 0.8) # transparency self.title(" Starting FoV") self.attributes("-topmost", True) self.label_1 = Label(self, text="RA (°) DEC (°)", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, pady=0) # default: sky coords of maximum probability pixel fov_coords = str(self.user.get_ra_max_pixel()), str(self.user.get_dec_max_pixel()) max_pixel_default = StringVar(self, value=fov_coords) self.entry_1 = Entry(self, width=30, justify=CENTER, textvariable=max_pixel_default) self.entry_1.grid(row=0, padx=15, column=1) self.entryScroll = Scrollbar(self, orient=HORIZONTAL, command=self.__scrollHandler) self.entryScroll.grid(row=1, column=1, sticky=E+W) self.entry_1['xscrollcommand'] = self.entryScroll.set #Btn self.show = Button(self, text='Show', command=self.show_starting_fov) self.show.grid(column=2, row=0, sticky=W, padx=2, pady=5) self.checkbox = Button(self, text="Not show", command=self.no_show_starting_fov) self.checkbox.grid(column=3,row=0, sticky=E, padx=2, pady=5) self.close = Button(self, text="Obs", fg='dark green', command=self.obs) self.close.grid(column=4,row=0, sticky=W, padx=2, pady=5) self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=5,row=0, sticky=E, padx=2, pady=5) #Actions def __scrollHandler(self, *L): """Scroll entry in starting FoV window.""" op, howMany = L[0], L[1] if op == 'scroll': units = L[2] self.entry_1.xview_scroll(howMany, units) elif op == 'moveto': self.entry_1.xview_moveto(howMany) def __split_entries(self): """Splitting the entries in ra and dec; # odd: ra and # even: dec.""" current_fov_coords = self.entry_1.get().replace(';',' ').replace(',',' ').split() fov_center_ra = current_fov_coords[0::2] fov_center_dec = current_fov_coords[1::2] return current_fov_coords, fov_center_ra, fov_center_dec def show_starting_fov(self): """Drawing the FoV footprint(s) in the Aladin plane(s). By default: sky coords (ra[deg], dec[deg]) of maximum probability pixel.""" show_sky_coverage = SkyCoverage() current_fov_coords, fov_center_ra, fov_center_dec = self.__split_entries() try: for ra_starting, dec_starting in zip (fov_center_ra, fov_center_dec): aladin.get_FoV(float(ra_starting), float(dec_starting)) show_sky_coverage.pick_coverage(float(ra_starting), float(dec_starting)) except ValueError as value_error: tkMessageBox.showerror ('Error', value_error) self.entries_GWsky.extend(current_fov_coords) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky, data) self.entries_GWsky=[] # re-init. def no_show_starting_fov(self): """No Draw the FoV footprint(s) in the Aladin plane(s); useful to re-initialize the sequence.""" self.entries_GWsky=[] # re-init. current_fov_coords, fov_center_ra, fov_center_dec = self.__split_entries() self.entries_GWsky.extend(current_fov_coords) with open('GWsky_entries', 'wb') as data: return pickle.dump(self.entries_GWsky, data) def obs(self): """Inizializing observability window.""" observability = Observability() def close_window(self): self.destroy()
class LoadSkymap(Toplevel): """Loading a new skymap.""" def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() # get trasparency windows self.wait_visibility() self.wm_attributes('-alpha', trasparency) self.title("Load a new skymap") self.attributes("-topmost", True) self.label_1 = Label(self, text="LVC skymap", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, pady=0) # default: input skymap skymap_input = StringVar(self, value=self.user.get_skymap()) self.entry_new_skymap = Entry(self, width=30, justify=CENTER, textvariable=skymap_input) self.entry_new_skymap.grid(row=0, padx=15, column=1) #Btns self.show = Button(self, text='Load', command=self.new_skymap) self.show.grid(column=2, row=0, sticky=W, padx=2, pady=5) self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=5, row=0, sticky=E, padx=2, pady=5) def new_skymap(self): """Loading a new LVC skymap.""" try: aladin.send_file(self.entry_new_skymap.get()) aladin.rename(self.entry_new_skymap.get()) except ValueError as value_error: tkMessageBox.showerror('Load a new skymap', value_error) except IOError as io_error: tkMessageBox.showerror('Load a new skymap', io_error) def update_GWsky_config(): """Updating GWsky_config file: coords max probability pixel and nside.""" prob = hp.read_map(self.entry_new_skymap.get(), verbose=False) # update nside npix = len(prob) nside = hp.npix2nside(npix) # update coord. maximum prob pixel ipix_max = np.argmax(prob) prob[ipix_max] theta, phi = hp.pix2ang(nside, ipix_max) ra_max = round(np.rad2deg(phi), 5) dec_max = round(np.rad2deg(0.5 * np.pi - theta), 5) with open('GWsky_config', 'rb') as data: config_GWsky = pickle.load(data) config_GWsky['skymap'], config_GWsky['nside'],config_GWsky['ra_max_pixel'],config_GWsky['dec_max_pixel']=\ self.entry_new_skymap.get(), nside, ra_max, dec_max with open('GWsky_config', 'wb') as data: pickle.dump(config_GWsky, data) update_GWsky_config() def close_window(self): return self.destroy()
import tkMessageBox import tkFont except ImportError: from tkinter import * from tkinter import font, messagebox import healpy as hp import numpy as np from aladinSAMP import AladinScriptCommands aladin = AladinScriptCommands() from config_values import UserValues # global variable: level of trasparency window user = UserValues() trasparency = user.get_win_trasparency() class LoadSkymap(Toplevel): """Loading a new skymap.""" def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() # get trasparency windows self.wait_visibility() self.wm_attributes('-alpha', trasparency) self.title("Load a new skymap")
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()
class LVCskymap(object): """A set of methods for working with LVC healpix (3d) skymaps.""" def __init__(self): self.user = UserValues() #comp. self.skymap = self.user.get_skymap() print(self.skymap) # TEST self.nside = self.user.get_nside() self.is_3d = Is3d(self.skymap) #comp --> eredita self.tfield, self.header = self.is_3d.get_header() self.prob, self.distmu, self.distsigma, self.distnorm = self.is_3d.get_values( self.tfield) ## def vertices(self, ra_center, dec_center, fov_base, fov_height): ## """Finding the vertices of a FoV given the central location (ra[deg], dec[deg]) ## and the FoV size (FoV_base [deg], FoV_height [deg]).""" ## ## vert_ra, vert_dec = [], [] # ra list, dec list ## ## ra_center_rad, dec_center_rad = radians(ra_center), radians(dec_center) ## ## fov_base_rad, fov_height_rad = radians(fov_base), radians(fov_height) ## ## x = [-fov_base_rad/2, fov_base_rad/2, ## fov_base_rad/2, -fov_base_rad/2] ## ## y = [fov_height_rad/2, fov_height_rad/2, ## -fov_height_rad/2, -fov_height_rad/2] ## ## for i, j in zip(x, y): ## arg = -i/(cos(dec_center_rad)-j*sin(dec_center_rad)) ## v_ra = degrees( (ra_center_rad+atan(arg)) ) ## ## vert_ra.append(v_ra) ## ## v_dec = degrees( (asin((sin(dec_center_rad)+j*cos(dec_center_rad))/(1+i**2+j**2)**0.5)) ) ## ## vert_dec.append(v_dec) ## ## # test: field-of-view footprint vs vertices function ## aladin.draw_circle(vert_ra[0], vert_dec[0], size = '15arsec') ## aladin.draw_circle(vert_ra[1], vert_dec[1], size = '15arsec') ## aladin.draw_circle(vert_ra[2], vert_dec[2], size = '15arsec') ## aladin.draw_circle(vert_ra[3], vert_dec[3], size = '15arsec') ## ## #print round(vert_ra[0],6), round(vert_dec[0],6), round(vert_ra[1],6), round(vert_dec[1],6),round(vert_ra[2],6), round(vert_dec[2],6), round(vert_ra[3],6), round(vert_dec[3],6) ## print vert_ra[0], vert_ra[1], vert_ra[3], vert_ra[2], vert_dec[0], vert_dec[1], vert_dec[3], vert_dec[2] ## return vert_ra[0], vert_ra[1], vert_ra[3], vert_ra[2], vert_dec[0], vert_dec[1], vert_dec[3], vert_dec[2] ## print vert_ra[0], vert_ra[1], vert_ra[3], vert_ra[2], vert_dec[0], vert_dec[1], vert_dec[3], vert_dec[2] def vertices(self, ra_center, dec_center, fov_base, fov_height): """Finding the vertices of a FoV given the central location (ra[deg], dec[deg]) and the FoV size (FoV_base [deg], FoV_height [deg]).""" vert_ra, vert_dec = [], [] # ra list, dec list ra_center_rad, dec_center_rad = radians(ra_center), radians(dec_center) fov_base_rad, fov_height_rad = radians( (fov_base + 0.00069) / 2.0), radians( (fov_height + 0.00069) / 2.0) #0.0017119592190950605 x = [-fov_base_rad, fov_base_rad, fov_base_rad, -fov_base_rad] y = [fov_height_rad, fov_height_rad, -fov_height_rad, -fov_height_rad] ## Dato un FOV quadrato di lato L e orientato come dicevo nella mia mail precedente, es: ## deg2rad=pi/180; ## ## L=3*deg2rad; ## ## In coord. ortogonali i vertici del quadrato in senso orario partendo da quello in alto a sx, assumendo #che l'origine sia nel punto centrale del FOV, sono: ## ## ## X1=(-L/2,L/2,L/2,-L/2); ## ## Y1=(L/2,L/2,-L/2,-L/2); ## ## ##In coord. angolari diventano: ## ## ##arg1=-X1/(cos(d0)-Y1*sin(d0)); ## ##a1=(a0+atan(arg1))/deg2rad ## ##d1=(asin( (sin(d0)+Y1*cos(d0))/(1+X1.^2+Y1.^2).^0.5))/deg2rad ## ##dove (a0,d0) sono le coordinate del centro del FOV ## ##Ho fatto delle prove con Aladin e a me torna ma fai un check... for i, j in zip(x, y): arg = -i / (cos(dec_center_rad) - j * sin(dec_center_rad)) v_ra = degrees((ra_center_rad + atan(arg))) vert_ra.append(v_ra) v_dec = degrees( (asin((sin(dec_center_rad) + j * cos(dec_center_rad)) / (1 + i**2 + j**2)**0.5))) vert_dec.append(v_dec) # test: field-of-view footprint vs vertices function #aladin.draw_circle(vert_ra[0], vert_dec[0], size = '5arcmin') #aladin.draw_circle(vert_ra[1], vert_dec[1], size = '5arcmin') #aladin.draw_circle(vert_ra[2], vert_dec[2], size = '5arcmin') #aladin.draw_circle(vert_ra[3], vert_dec[3], size = '5arcmin') #print round(vert_ra[0],6), round(vert_dec[0],6), round(vert_ra[1],6), round(vert_dec[1],6),round(vert_ra[2],6), round(vert_dec[2],6), round(vert_ra[3],6), round(vert_dec[3],6) #print vert_ra[0], vert_ra[1], vert_ra[3], vert_ra[2], vert_dec[0], vert_dec[1], vert_dec[3], vert_dec[2] return vert_ra[0], vert_ra[1], vert_ra[3], vert_ra[2], vert_dec[ 0], vert_dec[1], vert_dec[3], vert_dec[2] #print vert_ra[0], vert_ra[1], vert_ra[3], vert_ra[2], vert_dec[0], vert_dec[1], vert_dec[3], vert_dec[2] def __ipix_sum(self, ra_vertices, dec_vertices): """Return the ipix sum inside a polygon.""" theta = 0.5 * np.pi - np.deg2rad(dec_vertices) phi = np.deg2rad(ra_vertices) xyz = hp.ang2vec(theta, phi) ipix_poly = hp.query_polygon(self.nside, xyz) ipix_sum_polygon = self.prob[ipix_poly].sum() return ipix_sum_polygon def prob_in_box(self, ra, dec, width, height): """Return the probability inside a box.""" v1_ra, v2_ra, v3_ra, v4_ra, v1_dec, v2_dec, v3_dec, v4_dec = self.vertices( ra, dec, width, height) ra_vertices, dec_vertices = ([v1_ra, v2_ra, v4_ra, v3_ra], [v1_dec, v2_dec, v4_dec, v3_dec]) probability_fov_box = self.__ipix_sum(ra_vertices, dec_vertices) return '%.1e' % probability_fov_box def prob_in_circle(self, ra, dec, radius): """Return the probability inside a circle.""" theta = 0.5 * np.pi - np.deg2rad(dec) phi = np.deg2rad(ra) radius = np.deg2rad(radius) xyz = hp.ang2vec(theta, phi) ipix_disc = hp.query_disc(self.nside, xyz, radius) probability_fov_disc = self.prob[ipix_disc].sum() return '%.1e' % probability_fov_disc def conditional_distance_linesight(self, ra, dec): """Conditional distance distribution along the line of sight of a FoV center: see https://arxiv.org/pdf/1605.04242v3.pdf - section 4.4 for more details.""" if self.tfield == 4: # 3d skymap theta = 0.5 * np.pi - np.deg2rad(dec) phi = np.deg2rad(ra) ipix = hp.ang2pix(self.nside, theta, phi) line_end = self.header['DISTMEAN'] + (self.header['DISTSTD'] * 4) r = np.linspace(0, line_end) dp_dr = r**2 * self.distnorm[ipix] * norm( self.distmu[ipix], self.distsigma[ipix]).pdf(r) return r, dp_dr else: r = "nan" dp_dr = "nan" return r, dp_dr
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)
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 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 SkyCoverage(object): """Moving the FoV-footprint coverage by choosing a starting pointing.""" SHIFT_CORRECTION = 0.00001 # A shift correction of 0.00001 is added # --> to escape math error during the FoV sequence def __init__(self, infile_coords='GWsky_coords'): """Creating a class in which the instance attributes are based on the dictionary "GWsky_coords" by default. GWsky_coords is created and pickled by the "config_values" module and will be deleted when the "SkyCoverageGUI" will be closed. It contains the keys: "ra", "dec". ra and dec represents the central location of a FoV. Starting sky coordinates: self.input_ra: right ascension [deg] self.input_dec: declination [deg] """ self.infile_coords = infile_coords self.entries_GWsky_new = [] # new entries during the FoV sequence self.user = UserValues() # compositions self.lvc = LVCskymap() self.query = Query() self.airmass = Airmass() self.moon = Moon() with open(infile_coords, 'rb') as data: coords_GWsky = pickle.load(data) for k, v in coords_GWsky.items(): setattr(self, k, v) def ra0ra1(self, A, dec0, dec1): """From the angular distance: cos(A) = sin(Dec1)sin(Dec2)+cos(Dec1)cos(Dec2)cos(ra1-ra2) --> cos(ra1-ra2) = [cos(A)-sin(dec0)sin(dec1)]/[cos(dec0)cos(dec1)].""" dec0, dec1, A = radians(dec0), radians(dec1), radians(A) cos_ra0_ra1 = (cos(A) - sin(dec0) * sin(dec1)) / (cos(dec0) * cos(dec1)) ra0ra1 = degrees(acos(cos_ra0_ra1)) return round(ra0ra1, 5) def __updating_center_coords(self, ra, dec): """Getting/Updating FoV-center (ra, dec) in the dict named by default "GWsky_coords". . For each tile across the sky the file is updated.""" "" with open('GWsky_coords', 'rb') as data: coords_GWsky = pickle.load(data) coords_GWsky['input_ra'], coords_GWsky['input_dec'] = ra, dec with open('GWsky_coords', 'wb') as data: pickle.dump(coords_GWsky, data) def __are_all_same(self, items): """Check if all elements of a list are the same.""" return all(x == items[0] for x in items) def __fov_stats(self, ra, dec, table, integrated_prob, distance_grid, ansatz_distribution, moon_illumination, sep_fov_moon): """Managing the descriptive statistic window. If the airmass is outside the default range [airmass_min, airmass_max] the window is not opened otherwise the window is shown.""" airmass_values, datestrings = self.airmass.airmass_step(ra, dec) same = self.__are_all_same(airmass_values) if same == True: tkMessageBox.showerror('Warning', "airmass outside the range of {1 - 5.8}") aladin.remove_FoV(ra, dec) aladin.remove("C_" + str(ra) + "/" + str(dec)) else: time_step = [dateutil.parser.parse(s) for s in datestrings] self.__updating_center_coords(ra, dec) fov_statistics = FoVstatistics() fov_statistics.plot_stats(time_step, airmass_values, ra, dec, table, integrated_prob, distance_grid, ansatz_distribution, moon_illumination, sep_fov_moon) #print airmass_values, datestrings def update_pointings_file(self, infile, ra, dec, prob_fov): """The central location (ra[deg], dec[deg]) and the integrated probability of a selected FoV are saved locally in an external file. By default the file is named "GWsky_pointings.txt".""" with open(infile, 'a') as pointing: pointing.write( str(ra) + ' ' + str(dec) + ' ' + str(prob_fov) + '\n') def __query_shape(self, ra, dec, fov_shape): """Return the catalog query according with the defined-user FoV shape: (1) box and (2) circle. """ if self.user.get_fov_shape() != 2: # box FoV query_result = self.query.query_box(ra, dec, self.user.get_fov_width(), self.user.get_fov_height(), self.user.get_catalog(), self.user.get_column_1(), self.user.get_column_2(), self.user.get_filter_1(), self.user.get_filter_2()) else: # circle FoV query_result = self.query.query_circle(ra, dec, self.user.get_fov_radius(), self.user.get_catalog(), self.user.get_column_1(), self.user.get_column_2(), self.user.get_filter_1(), self.user.get_filter_2()) return query_result def __prob_shape(self, ra, dec, fov_shape): """Return the integrated probability according with the defined-user FoV shape: (1) box and (2) circle.""" if self.user.get_fov_shape() != 2: # box FoV prob_fov = self.lvc.prob_in_box(ra, dec, self.user.get_fov_width(), self.user.get_fov_height()) else: # circle FoV prob_fov = self.lvc.prob_in_circle(ra, dec, self.user.get_fov_radius()) return prob_fov def pick_coverage(self, ra, dec): """Setting GWsky: with statistic window (A); without statistic window (D).""" if self.user.get_GWsky_basic() == "A": # full version query_result = self.__query_shape( ra, dec, self.user.get_fov_shape()) # query prob_fov = self.__prob_shape( ra, dec, self.user.get_fov_shape()) # integrated prob moon_illumination = self.moon.illumination() # moon_illumination sep_fov_moon = self.moon.from_fov(ra, dec) * u.deg # moon_dist sep_fov_moon = sep_fov_moon.round(1) # TEST------------------------------------------------------# fov_sep = Utils.separation( self.input_ra, self.input_dec, # ra, dec) # print( 'The distance between 2 consecutive FoV centers is', # fov_sep.round(6)) # #-----------------------------------------------------------# r, dp_dr = self.lvc.conditional_distance_fov_center(ra, dec) self.__fov_stats(ra, dec, query_result, prob_fov, r, dp_dr, moon_illumination, sep_fov_moon) # Stats win elif self.user.get_GWsky_basic( ) == "D": # basic version-> no Stats win prob_fov = self.__prob_shape(ra, dec, self.user.get_fov_shape()) # query # TEST------------------------------------------------------# #fov_sep = Utils.separation(self.input_ra, self.input_dec, # # ra, dec) # #print ('The distance between 2 consecutive FoV centers is',# # fov_sep.round(6)) # #-----------------------------------------------------------# self.update_pointings_file("GWsky_pointings.txt", ra, dec, prob_fov) def intercardinal_distance(self, ra, dec, shift_up_down, shift_right_left): """Moving from the fixed cardinal direction using the bi-directional windows; shift_up_down ↕ and/or shift_right_left ↔.""" if shift_right_left > 0: shift_east_west = self.ra0ra1( (shift_right_left - self.SHIFT_CORRECTION), (dec + self.user.get_fov_height() + shift_up_down), (dec + self.user.get_fov_height() + shift_up_down)) dist = ra + shift_east_west elif shift_right_left < 0: shift_east_west = self.ra0ra1( (shift_right_left + self.SHIFT_CORRECTION), (dec + self.user.get_fov_height() + shift_up_down), (dec + self.user.get_fov_height() + shift_up_down)) dist = ra - shift_east_west else: dist = ra return dist def load_entries(self, infile_entries): """Opening the file in which the input entries are stored: ra_1 dec_1 ra_2 dec_2 ... ra_n dec_n By default the file is named "GWsky_entries". "GWsky_entries" is created from the "show_starting_fov" method in "StartingFoV" class. A error message invites users to press the "Start FoV" button before carrying out any""" try: with open(infile_entries, 'rb') as data: entries_GWsky = pickle.load(data) return entries_GWsky except IOError as io_error: message = "Press the button 'Start FoV' and choose a starting position; \ by default the sky position of the max probability pixel is shown" tkMessageBox.showerror('Error', message) def north(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in North direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔ """ entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[ 1::2] for ra_start, dec_start in zip(fov_center_ra, fov_center_dec): dist = self.intercardinal_distance(float(ra_start), float(dec_start), shift_up_down, shift_right_left) north_pointing = [ (dist), (float(dec_start) + self.user.get_fov_height() + shift_up_down) ] ra, dec = north_pointing[0], north_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra, dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def south(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in South direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[ 1::2] for ra_start, dec_start in zip(fov_center_ra, fov_center_dec): dist = self.intercardinal_distance(float(ra_start), float(dec_start), shift_up_down, shift_right_left) south_pointing = [ (dist), (float(dec_start) - self.user.get_fov_height() - shift_up_down) ] ra, dec = south_pointing[0], south_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra, dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def east(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in East direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔. A shift correction of 0.00001 is added to escape math error.""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[ 1::2] for ra_start, dec_start in zip(fov_center_ra, fov_center_dec): ra_distance = self.ra0ra1( (self.user.get_fov_width() - self.SHIFT_CORRECTION + shift_right_left), float(dec_start), float(dec_start)) east_pointing = [(float(ra_start) + ra_distance), (float(dec_start) + shift_up_down)] ra, dec = east_pointing[0], east_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra, dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def west(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in West direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔. A shift correction of 0.00001 is added to escape math error.""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[ 1::2] for ra_start, dec_start in zip(fov_center_ra, fov_center_dec): ra_distance = self.ra0ra1( (self.user.get_fov_width() - self.SHIFT_CORRECTION + shift_right_left), float(dec_start), float(dec_start)) west_pointing = [(float(ra_start) - ra_distance), (float(dec_start) + shift_up_down)] ra, dec = west_pointing[0], west_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra, dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data)
class Pinpoint(Toplevel): """The class is designed to determine in which level of probability a source is localized.""" def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") # get trasparency windows from global variable self.wait_visibility() self.wm_attributes('-alpha', trasparency) self.title(" Pinpoint Localization") self.attributes("-topmost", True) # label 1 self.label_1 = Label(self, text=" In which level of probability the source(s) falls/fall", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, pady=0) # showing example entries help_string = ("source_3 085.91935 +33.34139; source_4 073.87703 +23.36612 ") help_string_default = StringVar(self, value=help_string) self.entry_pin = Entry(self, width=30, justify=CENTER, textvariable=help_string_default) self.entry_pin.grid(row=0, padx=15, column=1) # label 2 self.label_2 = Label(self, text=" from ", bg="slate grey") self.label_2.grid(row=0, column=3, sticky=E, pady=0) from_default = StringVar(self, value="10") # default self.entry_from = Entry(self, width=5, justify=CENTER, textvariable=from_default) self.entry_from.grid(row=0, column=4, columnspan=8, pady=2, sticky='WE') # label 3 self.label_3 = Label(self, text=" to ", bg="slate grey") self.label_3.grid(row=0, column=20, sticky=E, pady=0) to_default = StringVar(self, value="90") # default self.entry_to = Entry(self, width=5, justify=CENTER, textvariable=to_default) self.entry_to.grid(row=0, column=25, columnspan=8, pady=2, sticky='WE') # label 4 self.label_4 = Label(self, text=" grid ", bg="slate grey") self.label_4.grid(row=0, column=40, sticky=E, pady=0) grid_default = StringVar(self, value="10") # default self.entry_grid = Entry(self, width=5, justify=CENTER, textvariable=grid_default) self.entry_grid.grid(row=0, column=45, columnspan=8, pady=2, sticky='WE') # label 4 folder = "pinpoint" # default folder_default = StringVar(self, value=folder) self.entry_folder = Entry(self, width=20, justify=CENTER, textvariable=folder_default) self.entry_folder.grid(row=1, padx=2, column=0) # label 3.1 self.label_3 = Label(self, text=" Folder:",justify=LEFT, bg="slate grey") self.label_3.grid(row=1, column=0, sticky=W, pady=0) self.entryScroll = Scrollbar(self, orient=HORIZONTAL, command=self.__scrollHandler) self.entryScroll.grid(row=1, column=1, sticky=E+W) self.entry_pin['xscrollcommand'] = self.entryScroll.set # -------------Btns--------------# # Do self.show = Button(self, text='Do', command=self.pinpoint_for) self.show.grid(column=55, row=0, sticky=W, padx=2, pady=5) # Close self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=70,row=0, sticky=W, padx=2, pady=5) #Actions def __scrollHandler(self, *L): """Scroll entry.""" op, howMany = L[0], L[1] if op == 'scroll': units = L[2] self.entry_pin.xview_scroll(howMany, units) elif op == 'moveto': self.entry_pin.xview_moveto(howMany) def __split_entries_3(self): """Splitting the entries in 'id source', 'ra' and 'dec'.""" entry_sources = self.entry_pin.get().replace(';',' ').replace(',',' ').split() # TRY TO DO BETTER: numpy!!! # defined lists label = entry_sources[::3] source_ra = entry_sources[1::3] source_dec = entry_sources[2::3] # Check if the lists are of the same length if len(label)==len(source_ra)==len(source_dec): return label[0::], source_ra[0::], source_dec[0::] else: msg_err = 'ENTER: id source ra[deg] dec[deg]' MSG.split_entries_3(msg_err) def pinpoint_for(self): """Finding in which confidence level the sources fall. List of sources are inserted in 'self.entry_pin'.""" aladin.md(self.entry_folder.get()) # creating folder defined by user aladin.remove(self.entry_folder.get() + '~1') # removing multiple copy of the folder ## TRY TO DO BETTER!!!! # splitting the entries labels, ra_transients, dec_transients = self.__split_entries_3() for ra_transient, dec_transient, label in zip( ra_transients, dec_transients, labels): # aladin stack organization: draw source position/move in folder aladin.draw_newtool(label) aladin.draw_source(ra_transient, dec_transient, label) aladin.mv(label, self.entry_folder.get()) try: self.pinpoint(ra_transient, dec_transient, label) except ValueError as value_error: MSG.value_error(value_error) def pinpoint(self, ra_transient, dec_transient, label): """Finding in which confidence level the source falls. Input parameters --------------- ra_transient, dec_transient : float sky coordinates in degrees label : string id source transient """ # (re)initialization: skymap/nside self.user = UserValues() skymap = self.user.get_skymap() nside = int(self.user.get_nside()) # getting probability array prob = moc.read_prob(skymap) # user input values: from/to/resolution from_percentage = float(self.entry_from.get())/100.0 to_percentage = float(self.entry_to.get())/100.0 resolution_percentage = float(self.entry_grid.get())/100.0 # from sky coords to ipix ipix = healpixIpix.find_ipix(ra_transient, dec_transient, nside) find = "n" while from_percentage <= to_percentage or find =="y": ipixs = moc.ipixs_in_percentage(prob, from_percentage) is_there = ipix in ipixs # is the ipix within the MOC contour plot defined by user? if is_there != True: # ipix not found from_percentage = from_percentage + resolution_percentage else: find = "y" # ipix found res_yes = ("The sky coord" + " " + "ra="+str(ra_transient)+"°," + ' ' + "dec="+str(dec_transient)+"°"+" " + "(label:" + label+")" \ "lies within the" + " " + str(from_percentage*100)+'%' + " " + "c.l.\n" +"["+skymap+"]") MSG.pinpoint_find(label, res_yes) return find # ipix not found [from_percentage -- to_percentage] from_percentage = to_percentage res_no = ("The sky coord" + " " + "ra="+str(ra_transient)+"°," + ' ' + "dec="+str(dec_transient)+"°"+" " + "(label:" + label+")" \ + " " + "is not localized within the" + " " + str(from_percentage*100)+'%' + " " + "c.l.\n" +"["+skymap+"]") MSG.pinpoint_nofind(label, res_no) def close_window(self): """Closing window""" return self.destroy()
class LocalizeSources(Toplevel): """The class is designed to answer if an astrophysical source falls within a specific level of probability (MOC contour plot).""" def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") # get trasparency windows from global variable self.wait_visibility() self.wm_attributes('-alpha', trasparency) self.title(" Localize Sources in probability skymap") self.attributes("-topmost", True) # label 1 self.label_1 = Label(self, text="Is/Are the [ID Source(s) RA (°) DEC (°)]", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, pady=0) # showing example entries help_string = ("source_1 079.91935 +43.34139; source_2 063.87703 +33.36612 ") help_string_default = StringVar(self, value=help_string) self.entry_sources = Entry(self, width=30, justify=CENTER, textvariable=help_string_default) self.entry_sources.grid(row=0, padx=15, column=1) # label 2 self.label_2 = Label(self, text="whithin the", bg="slate grey") self.label_2.grid(row=0, column=3, sticky=E, pady=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=5) # label 3 self.label_2 = Label(self, text="% MOC? ", bg="slate grey") self.label_2.grid(row=0, column=6, sticky=E, pady=0) # label 4 folder = "transients" # default folder_default = StringVar(self, value=folder) self.entry_folder = Entry(self, width=15, justify=CENTER, textvariable=folder_default) self.entry_folder.grid(row=1, padx=2, column=0) # label 3.1 self.label_3 = Label(self, text=" Folder: ",justify=LEFT, bg="slate grey") self.label_3.grid(row=1, column=0, sticky=W, pady=0) self.entryScroll = Scrollbar(self, orient=HORIZONTAL, command=self.__scrollHandler) self.entryScroll.grid(row=1, column=1, sticky=E+W) self.entry_sources['xscrollcommand'] = self.entryScroll.set # -------------Btns--------------# # Ask self.show = Button(self, text='Ask', command=self.in_skymap) self.show.grid(column=7, row=0, sticky=W, padx=2, pady=5) # Pinpoint self.checkbox = Button(self, text="Pinpoint", fg='black', command=self.pinpoint) self.checkbox.grid(column=8,row=0, sticky=E, padx=2, pady=5) # Dist self.checkbox = Button(self, text="Dist", fg='black', command=self.cond_distance_source_for) self.checkbox.grid(column=15,row=0, sticky=E, padx=2, pady=5) # Close self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=25,row=0, sticky=W, padx=2, pady=5) #Actions def __scrollHandler(self, *L): """Scroll entry.""" op, howMany = L[0], L[1] if op == 'scroll': units = L[2] self.entry_sources.xview_scroll(howMany, units) elif op == 'moveto': self.entry_sources.xview_moveto(howMany) def __split_entries_3(self): """Splitting the entries in 'id source', 'ra' and 'dec'.""" entry_sources = self.entry_sources.get().replace(';',' ').replace(',',' ').split() # defined lists label = entry_sources[::3] source_ra = entry_sources[1::3] source_dec = entry_sources[2::3] # Check if the lists are of the same length if len(label)==len(source_ra)==len(source_dec): return label[0::], source_ra[0::], source_dec[0::] else: msg_err = 'ENTER: id source ra[deg] dec[deg]' MSG.split_entries_3(msg_err) def in_skymap(self): """Checking if an object falls in a given probability level defined by an user. List of sources are inserted in 'self.entry_sources'.""" aladin.md(self.entry_folder.get()) # creating folder defined by user aladin.remove(self.entry_folder.get() + '~1') # removing multiple copy of the folder # TO DO BETTER # (re)initialization: skymap/nside self.user = UserValues() skymap = self.user.get_skymap() nside = int(self.user.get_nside()) # getting probability array prob = moc.read_prob(skymap) # user input: MOC confidence level in percentage percentage = float(self.entry_percentage.get())/100.0 # splitting the entries labels, ra_transients, dec_transients = self.__split_entries_3() for ra_transient, dec_transient, label in zip( ra_transients, dec_transients, labels): # aladin stack organization: draw source position/move in folder aladin.draw_newtool(label) aladin.draw_source(ra_transient, dec_transient, label) aladin.mv(label, self.entry_folder.get()) # from sky coords to ipix ipixs = moc.ipixs_in_percentage(prob, percentage) try: ipix = healpixIpix.find_ipix(ra_transient, dec_transient, nside) is_there = ipix in ipixs # is the ipix within the MOC contour plot defined by user? if is_there is True: # ipix found res_true = ("The sky coord" + " " + "ra="+str(ra_transient)+"°," + " " + "dec="+str(dec_transient)+"°" + " " + \ "(labels: " + label+")" + " " + "lies within the" + " " + str(percentage*100)+'%' + " " + "c.l.\n" +"["+skymap+"]") MSG.in_skymap_true(label, res_true) else: res_false = ("The sky coord" + " " + "ra="+str(ra_transient)+"°," + " " +"dec="+str(dec_transient)+"°" + " " + \ "(labels: " + label+")" + " " + "is outside the" + " " + str(percentage*100)+'%' + " " + "c.l.\n" + "["+skymap+"]") MSG.in_skymap_false(label, res_false) except ValueError as value_error: MSG.value_error(value_error) def pinpoint(self): """Initialize Pinpoint class.""" pinpoint_localize = Pinpoint() return pinpoint_localize def cond_distance_source_for(self): """Plot of the conditional distance distribution along the line of sight for a list of sources.""" self.lvc = LVCskymap() # basic module for handling LVC skymaps labels, ra_transients, dec_transients = self.__split_entries_3() plt.ion() for label, ra_transient, dec_transient in zip( labels, ra_transients, dec_transients): try: r, dp_dr = self.lvc.conditional_distance_linesight( float(ra_transient), float(dec_transient)) self.__cond_distance_source(label, r, dp_dr) except ValueError as value_error: MSG.value_error(value_error) def __cond_distance_source(self, label, r, dp_dr): """Plot of the conditional distance distribution along the line of sight.""" # (re)initialization: skymap self.user = UserValues() skymap=self.user.get_skymap() fig, ax = plt.subplots() ax.plot(r, dp_dr) title_string = label + ':' + ' '+ ' \n conditional distance distribution along the line of sight \n' + '['+skymap+']' ax.set_title(title_string,fontsize=10) ax.set_xlabel('distance (Mpc)') ax.set_ylabel('prob Mpc$^{-1}$') plt.show() def close_window(self): """Closing window""" return self.destroy()
class StartingFoV(Toplevel): """Starting a sequence from a list of FoV(s). The window contains 1 keyboard entries and 3 Buttons. entry: ra_1 dec_1 ra_2 dec_2 ra_3 dec_3 ... ra_n dec_n [deg] By default: sky coords of maximum probability pixel Btns: Show : draw user-defined FoV footprint(s) in Aladin Plane(s) No show : no draw user-defined FoV footprint(s) in Aladin Plane(s) Close : close the widget """ def __init__(self): Toplevel.__init__(self, border=8, bg="slate grey") self.user = UserValues() # putting the entry value(s) in a list self.entries_GWsky = [] self.wait_visibility() self.wm_attributes('-alpha', 0.8) # transparency self.title(" Starting FoV") self.attributes("-topmost", True) self.label_1 = Label(self, text="RA (°) DEC (°)", bg="slate grey") self.label_1.grid(row=0, column=0, sticky=E, pady=0) # default: sky coords of maximum probability pixel fov_coords = str(self.user.get_ra_max_pixel()), str( self.user.get_dec_max_pixel()) max_pixel_default = StringVar(self, value=fov_coords) self.entry_1 = Entry(self, width=30, justify=CENTER, textvariable=max_pixel_default) self.entry_1.grid(row=0, padx=15, column=1) self.entryScroll = Scrollbar(self, orient=HORIZONTAL, command=self.__scrollHandler) self.entryScroll.grid(row=1, column=1, sticky=E + W) self.entry_1['xscrollcommand'] = self.entryScroll.set #Btn self.show = Button(self, text='Show', command=self.show_starting_fov) self.show.grid(column=2, row=0, sticky=W, padx=2, pady=5) self.checkbox = Button(self, text="Not show", command=self.no_show_starting_fov) self.checkbox.grid(column=3, row=0, sticky=E, padx=2, pady=5) self.close = Button(self, text="Obs", fg='dark green', command=self.obs) self.close.grid(column=4, row=0, sticky=W, padx=2, pady=5) self.close = Button(self, text="Close", command=self.close_window) self.close.grid(column=5, row=0, sticky=E, padx=2, pady=5) #Actions def __scrollHandler(self, *L): """Scroll entry in starting FoV window.""" op, howMany = L[0], L[1] if op == 'scroll': units = L[2] self.entry_1.xview_scroll(howMany, units) elif op == 'moveto': self.entry_1.xview_moveto(howMany) def __split_entries(self): """Splitting the entries in ra and dec; # odd: ra and # even: dec.""" current_fov_coords = self.entry_1.get().replace(';', ' ').replace( ',', ' ').split() fov_center_ra = current_fov_coords[0::2] fov_center_dec = current_fov_coords[1::2] return current_fov_coords, fov_center_ra, fov_center_dec def show_starting_fov(self): """Drawing the FoV footprint(s) in the Aladin plane(s). By default: sky coords (ra[deg], dec[deg]) of maximum probability pixel.""" show_sky_coverage = SkyCoverage() current_fov_coords, fov_center_ra, fov_center_dec = self.__split_entries( ) try: for ra_starting, dec_starting in zip(fov_center_ra, fov_center_dec): aladin.get_FoV(float(ra_starting), float(dec_starting)) show_sky_coverage.pick_coverage(float(ra_starting), float(dec_starting)) except ValueError as value_error: tkMessageBox.showerror('Error', value_error) self.entries_GWsky.extend(current_fov_coords) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky, data) self.entries_GWsky = [] # re-init. def no_show_starting_fov(self): """No Draw the FoV footprint(s) in the Aladin plane(s); useful to re-initialize the sequence.""" self.entries_GWsky = [] # re-init. current_fov_coords, fov_center_ra, fov_center_dec = self.__split_entries( ) self.entries_GWsky.extend(current_fov_coords) with open('GWsky_entries', 'wb') as data: return pickle.dump(self.entries_GWsky, data) def obs(self): """Inizializing observability window.""" observability = Observability() def close_window(self): self.destroy()
class SkyCoverage(object): """Moving the FoV-footprint coverage by choosing a starting pointing.""" SHIFT_CORRECTION = 0.00001 # A shift correction of 0.00001 is added # --> to escape math error during the FoV sequence def __init__(self, infile_coords='GWsky_coords'): """Creating a class in which the instance attributes are based on the dictionary "GWsky_coords" by default. GWsky_coords is created and pickled by the "config_values" module and will be deleted when the "SkyCoverageGUI" will be closed. It contains the keys: "ra", "dec". ra and dec represents the central location of a FoV. Starting sky coordinates: self.input_ra: right ascension [deg] self.input_dec: declination [deg] """ self.infile_coords = infile_coords self.entries_GWsky_new =[] # new entries during the FoV sequence self.user = UserValues() # compositions self.lvc = LVCskymap() self.query = Query() self.airmass = Airmass() self.moon = Moon() with open(infile_coords, 'rb') as data: coords_GWsky = pickle.load(data) for k, v in coords_GWsky.items(): setattr(self, k, v) def ra0ra1(self, A, dec0, dec1): """From the angular distance: cos(A) = sin(Dec1)sin(Dec2)+cos(Dec1)cos(Dec2)cos(ra1-ra2) --> cos(ra1-ra2) = [cos(A)-sin(dec0)sin(dec1)]/[cos(dec0)cos(dec1)].""" dec0, dec1, A = radians(dec0), radians(dec1), radians(A) cos_ra0_ra1 = ( cos(A)-sin(dec0)*sin(dec1) )/( cos(dec0)*cos(dec1) ) ra0ra1 = degrees( acos(cos_ra0_ra1) ) return round(ra0ra1, 5) def __updating_center_coords(self, ra, dec): """Getting/Updating FoV-center (ra, dec) in the dict named by default "GWsky_coords". . For each tile across the sky the file is updated.""""" with open('GWsky_coords', 'rb') as data: coords_GWsky = pickle.load(data) coords_GWsky['input_ra'], coords_GWsky ['input_dec'] = ra, dec with open('GWsky_coords', 'wb') as data: pickle.dump(coords_GWsky, data) def __are_all_same(self, items): """Check if all elements of a list are the same.""" return all(x == items[0] for x in items) def __fov_stats(self, ra, dec, table, integrated_prob, distance_grid, ansatz_distribution, moon_illumination, sep_fov_moon): """Managing the descriptive statistic window. If the airmass is outside the default range [airmass_min, airmass_max] the window is not opened otherwise the window is shown.""" airmass_values, datestrings = self.airmass.airmass_step(ra, dec) same = self.__are_all_same(airmass_values) if same == True: tkMessageBox.showerror('Warning',"airmass outside the range of {1 - 5.8}") aladin.remove_FoV(ra, dec) aladin.remove("C_" + str( ra ) + "/" + str( dec )) else: time_step = [dateutil.parser.parse(s) for s in datestrings] self.__updating_center_coords(ra,dec) fov_statistics = FoVstatistics() fov_statistics.plot_stats(time_step, airmass_values, ra, dec, table, integrated_prob, distance_grid, ansatz_distribution, moon_illumination, sep_fov_moon) #print airmass_values, datestrings def update_pointings_file(self, infile, ra, dec, prob_fov): """The central location (ra[deg], dec[deg]) and the integrated probability of a selected FoV are saved locally in an external file. By default the file is named "GWsky_pointings.txt".""" with open(infile, 'a') as pointing: pointing.write(str(ra) + ' ' + str(dec)+ ' '+ str(prob_fov)+'\n') def __query_shape(self, ra, dec, fov_shape): """Return the catalog query according with the defined-user FoV shape: (1) box and (2) circle. """ if self.user.get_fov_shape() != 2: # box FoV query_result = self.query.query_box( ra, dec, self.user.get_fov_width(), self.user.get_fov_height(), self.user.get_catalog(), self.user.get_column_1(), self.user.get_column_2(), self.user.get_filter_1(), self.user.get_filter_2()) else: # circle FoV query_result = self.query.query_circle( ra, dec, self.user.get_fov_radius(), self.user.get_catalog(), self.user.get_column_1(), self.user.get_column_2(), self.user.get_filter_1(), self.user.get_filter_2()) return query_result def __prob_shape(self, ra, dec, fov_shape): """Return the integrated probability according with the defined-user FoV shape: (1) box and (2) circle.""" if self.user.get_fov_shape() !=2: # box FoV prob_fov = self.lvc.prob_in_box( ra, dec, self.user.get_fov_width(), self.user.get_fov_height()) else: # circle FoV prob_fov = self.lvc.prob_in_circle( ra, dec, self.user.get_fov_radius()) return prob_fov def pick_coverage(self, ra, dec): """Setting GWsky: with statistic window (A); without statistic window (D).""" if self.user.get_GWsky_basic() == "A": # full version query_result = self.__query_shape(ra, dec, self.user.get_fov_shape()) # query prob_fov = self.__prob_shape(ra, dec, self.user.get_fov_shape()) # integrated prob moon_illumination = self.moon.illumination() # moon_illumination sep_fov_moon = self.moon.from_fov(ra, dec)*u.deg # moon_dist sep_fov_moon = sep_fov_moon.round(1) # TEST------------------------------------------------------# fov_sep = Utils.separation(self.input_ra, self.input_dec, # ra, dec) # print ('The distance between 2 consecutive FoV centers is', # fov_sep.round(6)) # #-----------------------------------------------------------# r, dp_dr = self.lvc.conditional_distance_fov_center(ra, dec) self.__fov_stats(ra, dec, query_result, prob_fov, r, dp_dr, moon_illumination, sep_fov_moon) # Stats win elif self.user.get_GWsky_basic() == "D": # basic version-> no Stats win prob_fov = self.__prob_shape(ra, dec, self.user.get_fov_shape()) # query # TEST------------------------------------------------------# #fov_sep = Utils.separation(self.input_ra, self.input_dec, # # ra, dec) # #print ('The distance between 2 consecutive FoV centers is',# # fov_sep.round(6)) # #-----------------------------------------------------------# self.update_pointings_file("GWsky_pointings.txt", ra, dec, prob_fov) def intercardinal_distance(self, ra, dec, shift_up_down, shift_right_left): """Moving from the fixed cardinal direction using the bi-directional windows; shift_up_down ↕ and/or shift_right_left ↔.""" if shift_right_left > 0: shift_east_west = self.ra0ra1((shift_right_left-self.SHIFT_CORRECTION), (dec + self.user.get_fov_height() + shift_up_down), (dec + self.user.get_fov_height() + shift_up_down)) dist = ra + shift_east_west elif shift_right_left < 0 : shift_east_west = self.ra0ra1((shift_right_left + self.SHIFT_CORRECTION), (dec + self.user.get_fov_height() + shift_up_down), (dec + self.user.get_fov_height() + shift_up_down)) dist = ra - shift_east_west else: dist = ra return dist def load_entries(self, infile_entries): """Opening the file in which the input entries are stored: ra_1 dec_1 ra_2 dec_2 ... ra_n dec_n By default the file is named "GWsky_entries". "GWsky_entries" is created from the "show_starting_fov" method in "StartingFoV" class. A error message invites users to press the "Start FoV" button before carrying out any""" try: with open(infile_entries, 'rb') as data: entries_GWsky = pickle.load(data) return entries_GWsky except IOError as io_error: message = "Press the button 'Start FoV' and choose a starting position; \ by default the sky position of the max probability pixel is shown" tkMessageBox.showerror ('Error', message) def north(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in North direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔ """ entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[1::2] for ra_start, dec_start in zip (fov_center_ra, fov_center_dec): dist = self.intercardinal_distance(float(ra_start), float(dec_start), shift_up_down, shift_right_left) north_pointing = [(dist), (float(dec_start) + self.user.get_fov_height() + shift_up_down)] ra, dec = north_pointing[0], north_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra,dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def south(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in South direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[1::2] for ra_start, dec_start in zip (fov_center_ra, fov_center_dec): dist = self.intercardinal_distance(float(ra_start), float(dec_start), shift_up_down, shift_right_left) south_pointing = [(dist), (float(dec_start) - self.user.get_fov_height() - shift_up_down)] ra, dec = south_pointing[0], south_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra,dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def east(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in East direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔. A shift correction of 0.00001 is added to escape math error.""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[1::2] for ra_start, dec_start in zip (fov_center_ra, fov_center_dec): ra_distance = self.ra0ra1((self.user.get_fov_width() - self.SHIFT_CORRECTION + shift_right_left), float(dec_start), float(dec_start)) east_pointing = [(float(ra_start) + ra_distance), (float(dec_start) + shift_up_down)] ra, dec = east_pointing[0], east_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra,dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data) def west(self, shift_up_down=0, shift_right_left=0): """Moving the FoV tiles in West direction from input sky-position(s). The related bidirectional button permits small shifts from such pre-defined direction: shift_up_down ↕ and/or shift_right_left ↔. A shift correction of 0.00001 is added to escape math error.""" entries_GWsky = self.load_entries("GWsky_entries") fov_center_ra, fov_center_dec = entries_GWsky[0::2], entries_GWsky[1::2] for ra_start, dec_start in zip (fov_center_ra, fov_center_dec): ra_distance = self.ra0ra1((self.user.get_fov_width() - self.SHIFT_CORRECTION + shift_right_left), float(dec_start), float(dec_start)) west_pointing = [(float(ra_start) - ra_distance), (float(dec_start) + shift_up_down)] ra, dec = west_pointing[0], west_pointing[1] aladin.get_FoV(ra, dec) self.pick_coverage(ra, dec) new_sky_pos = [ra,dec] # cycle variables self.entries_GWsky_new.extend(new_sky_pos) with open('GWsky_entries', 'wb') as data: pickle.dump(self.entries_GWsky_new, data)