From 0ed8b8bc318482547bcfae69fb20fdacb0733222 Mon Sep 17 00:00:00 2001 From: David Sanmartim Date: Thu, 23 Jan 2025 18:39:35 -0300 Subject: [PATCH 1/6] In base_tcs.py update find_target_simbad query --- .../lsst/ts/observatory/control/base_tcs.py | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/python/lsst/ts/observatory/control/base_tcs.py b/python/lsst/ts/observatory/control/base_tcs.py index 0d1a7de2..a7df17ce 100644 --- a/python/lsst/ts/observatory/control/base_tcs.py +++ b/python/lsst/ts/observatory/control/base_tcs.py @@ -1682,41 +1682,47 @@ async def find_target_simbad( customSimbad = Simbad() - customSimbad.add_votable_fields("distance_result", "fluxdata(V)") + customSimbad.add_votable_fields("mesdistance", "V") customSimbad.TIMEOUT = self.long_long_timeout radec = self.radec_from_azel(az=az, el=el) - _ra = radec.ra.to_string(u.deg, decimal=True) - _dec = radec.dec.to_string(u.deg, decimal=True, alwayssign=True) - r = Angle(radius * u.deg).to_string(u.deg, decimal=True) - - criteria = ( - f"region(circle,ICRS,{_ra} {_dec},{r}d) & " - f"Vmag > {mag_limit} & Vmag < {mag_limit+mag_range} & " - "cat = HD" - ) - + # Execute the query_region asynchrnously loop = asyncio.get_event_loop() - try: result_table = await loop.run_in_executor( - None, customSimbad.query_criteria, criteria + None, customSimbad.query_region, radec, radius * u.deg ) except Exception as e: - self.log.exception("Querying Simbad failed. {criteria=}") - raise RuntimeError(f"Query {criteria=} failed: {e!r}") + self.log.exception("Querying Simbad failed.") + raise RuntimeError(f"Query region for {radec} failed: {e!r}") - if result_table is None: - raise RuntimeError(f"No result from query: {criteria}.") + if result_table is None or len(result_table) == 0: + raise RuntimeError(f"No results found for region around {radec}.") - result_table.sort("FLUX_V") + # 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}." + ) - target_main_id = str(result_table["MAIN_ID"][0]) + # Sort by V magnitude + result_table.sort("V") + target_main_id = str(result_table["main_id"][0]).strip() radec_icrs = ICRS( - ra=Angle(result_table[0]["RA"], unit=u.hourangle), - dec=Angle(result_table[0]["DEC"], unit=u.deg), + ra=Angle(result_table[0]["ra"], unit=u.hourangle), + dec=Angle(result_table[0]["dec"], unit=u.deg), ) self.object_list_add(f"{target_main_id}".rstrip(), radec_icrs) From 42b05cb4d4dad23b926c321077dc67b31618b4a5 Mon Sep 17 00:00:00 2001 From: David Sanmartim Date: Mon, 27 Jan 2025 10:52:31 -0300 Subject: [PATCH 2/6] Fix radec units. --- python/lsst/ts/observatory/control/base_tcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/lsst/ts/observatory/control/base_tcs.py b/python/lsst/ts/observatory/control/base_tcs.py index a7df17ce..9f36e4ce 100644 --- a/python/lsst/ts/observatory/control/base_tcs.py +++ b/python/lsst/ts/observatory/control/base_tcs.py @@ -1721,7 +1721,7 @@ async def find_target_simbad( target_main_id = str(result_table["main_id"][0]).strip() radec_icrs = ICRS( - ra=Angle(result_table[0]["ra"], unit=u.hourangle), + 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) From cee03eb29969083b94040aa28ba2aed1cb179db0 Mon Sep 17 00:00:00 2001 From: David Sanmartim Date: Mon, 27 Jan 2025 11:05:15 -0300 Subject: [PATCH 3/6] Add news fragment --- doc/news/DM-48561.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/news/DM-48561.bugfix.rst diff --git a/doc/news/DM-48561.bugfix.rst b/doc/news/DM-48561.bugfix.rst new file mode 100644 index 00000000..2341e3be --- /dev/null +++ b/doc/news/DM-48561.bugfix.rst @@ -0,0 +1 @@ +Updated the `find_target_simbad` method in `base_tcs.py` to comply with Simbad queries in astroquery version 0.4.8. From 5a937608efc4c187c223ad392f653d867db2052a Mon Sep 17 00:00:00 2001 From: David Sanmartim Date: Mon, 27 Jan 2025 17:43:00 -0300 Subject: [PATCH 4/6] 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() From 1f7d6af25e14b6950c4f4292618c486960eb8bde Mon Sep 17 00:00:00 2001 From: David Sanmartim Date: Tue, 28 Jan 2025 13:01:47 -0300 Subject: [PATCH 5/6] Improving query based on CDS developer comments --- python/lsst/ts/observatory/control/base_tcs.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/lsst/ts/observatory/control/base_tcs.py b/python/lsst/ts/observatory/control/base_tcs.py index 2d8d4e51..f6c30fa0 100644 --- a/python/lsst/ts/observatory/control/base_tcs.py +++ b/python/lsst/ts/observatory/control/base_tcs.py @@ -1683,14 +1683,14 @@ async def find_target_simbad( customSimbad = Simbad() - customSimbad.add_votable_fields("mesdistance", "V") + customSimbad.add_votable_fields("V", "rvz_redshift", "ident") customSimbad.TIMEOUT = self.long_long_timeout 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%'" + f"V>{mag_limit} AND V<{mag_limit + mag_range} AND ident.id LIKE 'HD%'" ) query_callable = partial( @@ -1700,7 +1700,6 @@ async def find_target_simbad( criteria=criteria, ) - # Execute the query_region asynchrnously loop = asyncio.get_event_loop() try: result_table = await loop.run_in_executor(None, query_callable) @@ -1715,16 +1714,16 @@ async def find_target_simbad( result_table.sort("V") # Pick the first (brightest) match - target_main_id = str(result_table["main_id"][0]) + target_ident_id = str(result_table["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) + self.object_list_add(f"{target_ident_id}".rstrip(), radec_icrs) - return f"{target_main_id}".rstrip() + return f"{target_ident_id}".rstrip() async def find_target_local_catalog( self, From f1b589a80c96dfbcd02f6f81d22a17fb248f6910 Mon Sep 17 00:00:00 2001 From: David Sanmartim Date: Tue, 28 Jan 2025 13:04:32 -0300 Subject: [PATCH 6/6] Removing unnecessary comments --- python/lsst/ts/observatory/control/base_tcs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/lsst/ts/observatory/control/base_tcs.py b/python/lsst/ts/observatory/control/base_tcs.py index f6c30fa0..0e5ef7a4 100644 --- a/python/lsst/ts/observatory/control/base_tcs.py +++ b/python/lsst/ts/observatory/control/base_tcs.py @@ -1710,10 +1710,8 @@ 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}.") - # Sort by V magnitude result_table.sort("V") - # Pick the first (brightest) match target_ident_id = str(result_table["id"][0]) radec_icrs = ICRS(