Skip to content

Commit

Permalink
add comments explaining types
Browse files Browse the repository at this point in the history
  • Loading branch information
jchate6 committed Feb 11, 2025
1 parent 9e7df52 commit 5454e6a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
9 changes: 5 additions & 4 deletions tom_catalogs/harvesters/simbad.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tom_catalogs.harvester import AbstractHarvester

from astroquery.simbad import Simbad
from astropy.table import Table


class SimbadHarvester(AbstractHarvester):
Expand All @@ -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')
Expand Down
22 changes: 17 additions & 5 deletions tom_catalogs/tests/harvesters/test_simbad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 5454e6a

Please sign in to comment.