Skip to content

Commit

Permalink
Add criteria to restrict queried table size
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanmartim committed Jan 27, 2025
1 parent cee03eb commit 5a93760
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions python/lsst/ts/observatory/control/base_tcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import logging
import typing
import warnings
from functools import partial
from os.path import splitext

import astropy.units as u
Expand Down Expand Up @@ -1687,43 +1688,40 @@ 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}")

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()
Expand Down

0 comments on commit 5a93760

Please sign in to comment.