From 5a937608efc4c187c223ad392f653d867db2052a Mon Sep 17 00:00:00 2001 From: David Sanmartim Date: Mon, 27 Jan 2025 17:43:00 -0300 Subject: [PATCH] Add criteria to restrict queried table size --- .../lsst/ts/observatory/control/base_tcs.py | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/python/lsst/ts/observatory/control/base_tcs.py b/python/lsst/ts/observatory/control/base_tcs.py index 9f36e4ce..2d8d4e51 100644 --- a/python/lsst/ts/observatory/control/base_tcs.py +++ b/python/lsst/ts/observatory/control/base_tcs.py @@ -27,6 +27,7 @@ import logging import typing import warnings +from functools import partial from os.path import splitext import astropy.units as u @@ -1687,12 +1688,22 @@ async def find_target_simbad( radec = self.radec_from_azel(az=az, el=el) + # Build the ADQL-like criteria for V magnitude + HD catalog + criteria = ( + f"V>{mag_limit} AND V<{mag_limit + mag_range} " f"AND main_id LIKE 'HD%'" + ) + + query_callable = partial( + customSimbad.query_region, + coordinates=radec, + radius=radius * u.deg, + criteria=criteria, + ) + # Execute the query_region asynchrnously loop = asyncio.get_event_loop() try: - result_table = await loop.run_in_executor( - None, customSimbad.query_region, radec, radius * u.deg - ) + result_table = await loop.run_in_executor(None, query_callable) except Exception as e: self.log.exception("Querying Simbad failed.") raise RuntimeError(f"Query region for {radec} failed: {e!r}") @@ -1700,30 +1711,17 @@ async def find_target_simbad( if result_table is None or len(result_table) == 0: raise RuntimeError(f"No results found for region around {radec}.") - # Filter by V magnitude - good_mag = (result_table["V"] > mag_limit) & ( - result_table["V"] < (mag_limit + mag_range) - ) - result_table = result_table[good_mag] - - # Further filter for HD objects (prefix "HD") - hd_mask = [str(name).startswith("HD") for name in result_table["main_id"]] - result_table = result_table[hd_mask] - - if len(result_table) == 0: - raise RuntimeError( - f"No 'HD' object in Simbad catalog with magnitude between" - f" {mag_limit} and {mag_limit+mag_range}." - ) - # Sort by V magnitude result_table.sort("V") - target_main_id = str(result_table["main_id"][0]).strip() + + # Pick the first (brightest) match + target_main_id = str(result_table["main_id"][0]) radec_icrs = ICRS( ra=Angle(result_table[0]["ra"], unit=u.deg), dec=Angle(result_table[0]["dec"], unit=u.deg), ) + self.object_list_add(f"{target_main_id}".rstrip(), radec_icrs) return f"{target_main_id}".rstrip()