Skip to content

Commit

Permalink
In base_tcs.py update find_target_simbad query
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanmartim committed Jan 23, 2025
1 parent 7a28ef1 commit 0ed8b8b
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions python/lsst/ts/observatory/control/base_tcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 0ed8b8b

Please sign in to comment.