From 83c98c27dde9a163d71702f92b2dd976ea11f619 Mon Sep 17 00:00:00 2001 From: Alex-J-Brown Date: Thu, 3 Jul 2025 18:11:20 +0200 Subject: [PATCH 1/4] Added markers for sources with gaia XP spectra --- hcam_finder/finders.py | 43 +++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/hcam_finder/finders.py b/hcam_finder/finders.py index adeacb7..95a1e7a 100644 --- a/hcam_finder/finders.py +++ b/hcam_finder/finders.py @@ -272,21 +272,48 @@ 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, cone_radius=11*u.arcmin, min_target_radius=3*u.arcsec): + 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) + results_table = Gaia.cone_search(coo, radius=cone_radius).get_results() + xp_spectra_sources = results_table['SOURCE_ID', 'ra', 'dec'][results_table['has_xp_continuous']] + 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 @@ -581,6 +608,8 @@ def _check_image_load(self, t): else: self.draw_ccd() self.targetMarker() + if has_astroquery: + self.xp_markers() finally: self.fitsimage.onscreen_message(None) From 35d40fb68f87934af2899ee7dfbf3622148c1478 Mon Sep 17 00:00:00 2001 From: Alex-J-Brown Date: Fri, 4 Jul 2025 12:53:36 +0200 Subject: [PATCH 2/4] Added load catalog button --- hcam_finder/finders.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/hcam_finder/finders.py b/hcam_finder/finders.py index 95a1e7a..bf595fc 100644 --- a/hcam_finder/finders.py +++ b/hcam_finder/finders.py @@ -70,6 +70,10 @@ ] ) +catalog_archives = [ + ("Gaia", "XP continuous") +] + @u.quantity_input(px_val=u.pix) @u.quantity_input(px_scale=u.arcsec / u.pix) @@ -206,6 +210,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 +239,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 @@ -307,7 +330,8 @@ def xp_markers(self, cone_radius=11*u.arcmin, min_target_radius=3*u.arcsec): if current_tag.isdigit(): self.canvas.delete_object_by_tag(current_tag) results_table = Gaia.cone_search(coo, radius=cone_radius).get_results() - xp_spectra_sources = results_table['SOURCE_ID', 'ra', 'dec'][results_table['has_xp_continuous']] + + xp_spectra_sources = results_table['source_id', 'ra', 'dec'][results_table['has_xp_continuous']] for id, ra, dec in xp_spectra_sources: coord = SkyCoord(ra, dec, unit=(u.deg, u.deg)) if coord.separation(coo) < min_target_radius: @@ -578,6 +602,18 @@ 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() + + def load_image(self): self.fitsimage.onscreen_message("Getting image; please wait...") # offload to non-GUI thread to keep viewer somewhat responsive? @@ -608,8 +644,6 @@ def _check_image_load(self, t): else: self.draw_ccd() self.targetMarker() - if has_astroquery: - self.xp_markers() finally: self.fitsimage.onscreen_message(None) From 5f61a63a1d1c083a2cc88731a27262617ea81351 Mon Sep 17 00:00:00 2001 From: Alex-J-Brown Date: Fri, 4 Jul 2025 14:06:48 +0200 Subject: [PATCH 3/4] Added xp_sampled and "no catalog" option --- hcam_finder/finders.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/hcam_finder/finders.py b/hcam_finder/finders.py index bf595fc..fa99e77 100644 --- a/hcam_finder/finders.py +++ b/hcam_finder/finders.py @@ -71,7 +71,9 @@ ) catalog_archives = [ - ("Gaia", "XP continuous") + ("Null", "No catalog", "no_catalog"), + ("Gaia", "XP continuous", "has_xp_continuous"), + ("Gaia", "XP sampled", "has_xp_sampled") ] @@ -316,7 +318,11 @@ def targetMarker(self): coo = SkyCoord(self.targCoords.value(), unit=(u.hour, u.deg)) self.drawMarker(coo, color="blue") - def xp_markers(self, cone_radius=11*u.arcmin, min_target_radius=3*u.arcsec): + 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 @@ -329,14 +335,15 @@ def xp_markers(self, cone_radius=11*u.arcmin, min_target_radius=3*u.arcsec): for current_tag in current_tags: if current_tag.isdigit(): self.canvas.delete_object_by_tag(current_tag) - results_table = Gaia.cone_search(coo, radius=cone_radius).get_results() + 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['has_xp_continuous']] - 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)) + 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)) def window_string(self): @@ -611,7 +618,8 @@ def set_and_load_catalog(self): self.ra.set(coo.ra.deg) self.dec.set(coo.dec.deg) # self.load_image() - self.xp_markers() + + self.xp_markers(catalog=self.catalogSelect.value()) def load_image(self): From ab5fbde41e5d8e8cda288719ff6362f1d97f9331 Mon Sep 17 00:00:00 2001 From: Alex-J-Brown Date: Mon, 4 Aug 2025 17:08:58 +0200 Subject: [PATCH 4/4] bugfix --- hcam_finder/finders.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hcam_finder/finders.py b/hcam_finder/finders.py index fa99e77..c22f99a 100644 --- a/hcam_finder/finders.py +++ b/hcam_finder/finders.py @@ -650,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: