diff --git a/hcam_finder/finders.py b/hcam_finder/finders.py index adeacb7..c22f99a 100644 --- a/hcam_finder/finders.py +++ b/hcam_finder/finders.py @@ -70,6 +70,12 @@ ] ) +catalog_archives = [ + ("Null", "No catalog", "no_catalog"), + ("Gaia", "XP continuous", "has_xp_continuous"), + ("Gaia", "XP sampled", "has_xp_sampled") +] + @u.quantity_input(px_val=u.pix) @u.quantity_input(px_scale=u.arcsec / u.pix) @@ -206,6 +212,12 @@ def __init__(self, master, fitsimage, logger): ) self.pa.grid(row=row, column=column, sticky=tk.W) + if has_astroquery: + row += 1 + catalogList = [archive[1] for archive in catalog_archives] + self.catalogSelect = w.Choice(self, catalogList, width=20) + self.catalogSelect.grid(row=row, column=column, sticky=tk.W) + column += 1 row = 0 self.query = tk.Button( @@ -229,6 +241,19 @@ def __init__(self, master, fitsimage, logger): ) self.launchButton.grid(row=row, column=column, sticky=tk.W) + if has_astroquery: + row += 4 + self.loadCatalogButton = tk.Button( + self, + width=14, + fg="black", + bg=g.COL["main"], + text="Load Catalog", + command=self.set_and_load_catalog, + ) + self.loadCatalogButton.grid(row=row, column=column, sticky=tk.W) + + self.imfilepath = None self.logger = logger @@ -272,21 +297,54 @@ def have_decimal_coords(self): if all(decimals): ret_val = True return ret_val + + def drawMarker(self, sky_coords, color, tag="Target"): + g = get_root(self).globals + image = self.fitsimage.get_image() + # 3 arcsecond radius target marker + x, y = image.radectopix(sky_coords.ra.deg, sky_coords.dec.deg) + size = wcs.calc_radius_xy(image, x, y, 3 / 3600) + circ = Circle(x, y, size, fill=True, linewidth=3, color=color, fillalpha=0.3) + + self.canvas.delete_object_by_tag(tag) + self.canvas.add(circ, tag=tag, redraw=True) + def targetMarker(self): g = get_root(self).globals if self.have_decimal_coords(): coo = SkyCoord(self.targCoords.value(), unit=u.deg) else: coo = SkyCoord(self.targCoords.value(), unit=(u.hour, u.deg)) - image = self.fitsimage.get_image() + self.drawMarker(coo, color="blue") + + def xp_markers(self, catalog, cone_radius=11*u.arcmin, min_target_radius=3*u.arcsec): + catalog_dict = { + "XP continuous": "has_xp_continuous", + "XP sampled": "has_xp_sampled" + } + from astroquery.gaia import Gaia + Gaia.ROW_LIMIT = -1 + g = get_root(self).globals + if self.have_decimal_coords(): + coo = SkyCoord(self.targCoords.value(), unit=u.deg) + else: + coo = SkyCoord(self.targCoords.value(), unit=(u.hour, u.deg)) + + current_tags = self.canvas.get_tags() + for current_tag in current_tags: + if current_tag.isdigit(): + self.canvas.delete_object_by_tag(current_tag) + if catalog != "No catalog": + results_table = Gaia.cone_search(coo, radius=cone_radius).get_results() + + xp_spectra_sources = results_table['source_id', 'ra', 'dec'][results_table[catalog_dict[catalog]]] + for id, ra, dec in xp_spectra_sources: + coord = SkyCoord(ra, dec, unit=(u.deg, u.deg)) + if coord.separation(coo) < min_target_radius: + continue + self.drawMarker(coord, color='red', tag=str(id)) - # 3 arcsecond radius target marker - x, y = image.radectopix(coo.ra.deg, coo.dec.deg) - size = wcs.calc_radius_xy(image, x, y, 3 / 3600) - circ = Circle(x, y, size, fill=True, linewidth=3, color="blue", fillalpha=0.3) - self.canvas.delete_object_by_tag("Target") - self.canvas.add(circ, tag="Target", redraw=True) def window_string(self): raise NotImplementedError @@ -551,6 +609,19 @@ def set_and_load(self): self.dec.set(coo.dec.deg) self.load_image() + + def set_and_load_catalog(self): + if self.have_decimal_coords(): + coo = SkyCoord(self.targCoords.value(), unit=u.deg) + else: + coo = SkyCoord(self.targCoords.value(), unit=(u.hour, u.deg)) + self.ra.set(coo.ra.deg) + self.dec.set(coo.dec.deg) + # self.load_image() + + self.xp_markers(catalog=self.catalogSelect.value()) + + def load_image(self): self.fitsimage.onscreen_message("Getting image; please wait...") # offload to non-GUI thread to keep viewer somewhat responsive? @@ -579,6 +650,10 @@ def _check_image_load(self, t): self.logger.error(msg=errmsg) self.fitsimage.onscreen_message(errmsg) else: + current_tags = self.canvas.get_tags() + for current_tag in current_tags: + if current_tag.isdigit(): + self.canvas.delete_object_by_tag(current_tag) self.draw_ccd() self.targetMarker() finally: