From 5454e6af84cf0613e562cd625f8e2b9a1d06a431 Mon Sep 17 00:00:00 2001 From: Joey Chatelain Date: Tue, 11 Feb 2025 11:57:33 -0800 Subject: [PATCH] add comments explaining types --- tom_catalogs/harvesters/simbad.py | 9 ++++---- tom_catalogs/tests/harvesters/test_simbad.py | 22 +++++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tom_catalogs/harvesters/simbad.py b/tom_catalogs/harvesters/simbad.py index bbc62199..709f6ced 100644 --- a/tom_catalogs/harvesters/simbad.py +++ b/tom_catalogs/harvesters/simbad.py @@ -1,6 +1,7 @@ from tom_catalogs.harvester import AbstractHarvester from astroquery.simbad import Simbad +from astropy.table import Table class SimbadHarvester(AbstractHarvester): @@ -16,10 +17,10 @@ def __init__(self, *args, **kwargs): self.simbad.add_votable_fields('pmra', 'pmdec', 'ra', 'dec', 'main_id', 'parallax', 'distance') def query(self, term): - self.catalog_data = self.simbad.query_object(term) - # astroquery <0.4.10, > 0.4.7 has issues joining the distance field. This workaround tries the query a 2nd time - # without the distance field when that issue is experienced. - + self.catalog_data: Table = self.simbad.query_object(term) + # astroquery <0.4.10, > 0.4.7 has issues joining the distance field, failing to find any results. + # This workaround checks if the query result is an ampty table and then tries the query a 2nd time without the + # distance field. if not self.catalog_data: self.simbad.reset_votable_fields() self.simbad.add_votable_fields('pmra', 'pmdec', 'ra', 'dec', 'main_id', 'parallax') diff --git a/tom_catalogs/tests/harvesters/test_simbad.py b/tom_catalogs/tests/harvesters/test_simbad.py index 3245899d..4533079b 100644 --- a/tom_catalogs/tests/harvesters/test_simbad.py +++ b/tom_catalogs/tests/harvesters/test_simbad.py @@ -9,16 +9,28 @@ class TestSimbadHarvester(TestCase): def setUp(self): self.broker = SimbadHarvester() - table_data = {'main_id': ['M 31'], 'ra': [10.684708333333333], - 'dec': [41.268750000000004], 'pmra': ['--'], 'pmdec': ['--'], - 'mesdistance.dist': [761.0], 'mesdistance.unit': ['kpc ']} + table_data = {'main_id': ['M 31'], + 'ra': [10.684708333333333], + 'dec': [41.268750000000004], + 'pmra': ['--'], + 'pmdec': ['--'], + 'mesdistance.dist': [761.0], + 'mesdistance.unit': ['kpc ']} self.broker.catalog_data = Table(table_data) - self.empty_table_data = {'main_id': [], 'ra': [], 'dec': [], 'pmra': [], 'pmdec': [], - 'plx_value': [], 'mesdistance.dist': [], 'mesdistance.unit': []} + self.empty_table_data = {'main_id': [], + 'ra': [], + 'dec': [], + 'pmra': [], + 'pmdec': [], + 'plx_value': [], + 'mesdistance.dist': [], + 'mesdistance.unit': []} def test_query_failure(self): self.broker.simbad.query_object = Mock(return_value=Table(self.empty_table_data)) self.broker.query('M31') + # Check that the empty table was returned and is falsey so it would trigger the MissingDataException in the + # AbstractHarvester self.assertFalse(self.broker.catalog_data) def test_to_target(self):