Skip to content

Commit

Permalink
More sensible API
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Jan 24, 2021
1 parent ae6ec6c commit 05d6769
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
16 changes: 6 additions & 10 deletions agasc/agasc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@

MAG_CATID_SUPPLEMENT = 128

# Number of stars above which get_stars() will read the entire AGASC and process
# in memory instead of using tables.read_where. Around 5000 is the cross-over
# in speed (empirically on a Mac with SSD drive).
GET_STARS_METHOD_THRESHOLD = 5000


def load_supplement():
supplement = {}
Expand Down Expand Up @@ -355,7 +350,8 @@ def _get_rows_read_entire(ids_1d, dates_1d, agasc_file):
return rows


def get_stars(ids, agasc_file=None, dates=None, fix_color1=True, use_mag_est=False):
def get_stars(ids, agasc_file=None, dates=None, read_entire_agasc=5000, fix_color1=True,
use_mag_est=False):
"""
Get AGASC catalog entries for star ``ids`` at ``dates``.
Expand All @@ -367,9 +363,8 @@ def get_stars(ids, agasc_file=None, dates=None, fix_color1=True, use_mag_est=Fal
the HDF5 ``tables.read_where()`` function to get one star at a time from the
HDF5 file, or by reading the entire table into memory and doing the search
by making a dict index by AGASC ID. Tests indicate that the latter is faster
for about 5000 or more stars, so this function will choose the method based
on the ``GET_STARS_METHOD_THRESHOLD`` module constant which is set at 5000.
If necessary you can change that module constant.
for about 5000 or more stars, so this function will read the entire AGASC if
the number of stars is greater than ``read_entire_agasc``.
Unlike the similar ``get_star`` function, this adds a ``DATE`` column
indicating the date at which the star coordinates (RA_PMCORR, DEC_PMCORR)
Expand Down Expand Up @@ -411,6 +406,7 @@ def get_stars(ids, agasc_file=None, dates=None, fix_color1=True, use_mag_est=Fal
:param dates: Dates for proper motion (scalar or array) (default=Now)
:param fix_color1: set COLOR1=COLOR2 * 0.85 for stars with V-I color (default=True)
:param use_mag_est: Use estimated mag from AGASC supplement where available (default=False)
:param read_entire_agasc: Number of stars above which to read the entire AGASC (default=5000)
:returns: astropy Table of AGASC entries, or Table Row of one entry for scalar input
"""

Expand All @@ -423,7 +419,7 @@ def get_stars(ids, agasc_file=None, dates=None, fix_color1=True, use_mag_est=Fal
ids, dates = np.broadcast_arrays(ids, dates_in)
ids_1d, dates_1d = np.atleast_1d(ids), np.atleast_1d(dates)

if len(ids_1d) < GET_STARS_METHOD_THRESHOLD:
if len(ids_1d) < read_entire_agasc:
rows = _get_rows_read_where(ids_1d, dates_1d, agasc_file)
method = 'tables_read_where'
else:
Expand Down
8 changes: 1 addition & 7 deletions agasc/tests/test_agasc_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,7 @@ def test_get_stars_many():
stars = agasc.get_agasc_cone(0, 0, radius=0.5)
agasc_ids = stars['AGASC_ID']
stars1 = agasc.get_stars(agasc_ids, dates='2020:001') # read_where method

orig_threshold = agasc.GET_STARS_METHOD_THRESHOLD
try:
agasc.GET_STARS_METHOD_THRESHOLD = 1
stars2 = agasc.get_stars(agasc_ids, dates='2020:001') # read entire AGASC
finally:
agasc.GET_STARS_METHOD_THRESHOLD = orig_threshold
stars2 = agasc.get_stars(agasc_ids, dates='2020:001', read_entire_agasc=1) # read entire AGASC

assert stars1.get_stars_method == 'tables_read_where'
assert stars2.get_stars_method == 'read_entire_agasc'
Expand Down

0 comments on commit 05d6769

Please sign in to comment.