Skip to content

Commit

Permalink
add a commands_v2 option to star_obs_catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
javierggt committed Apr 25, 2022
1 parent 312baf3 commit 97ca22d
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions agasc/supplement/magnitudes/star_obs_catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
"""The table of star observations"""


def get_star_observations(start=None, stop=None, obsid=None, join_keys=['starcat_date', 'obsid']):
from kadi import commands

with commands.conf.set_temp('commands_version', '2'):
observations = Table(commands.get_observations(start=start, stop=stop, obsid=obsid))
observations = observations[~observations['starcat_date'].mask]
catalogs = commands.get_starcats_as_table(start=start, stop=stop, obsid=obsid, unique=True)
catalogs = catalogs[np.in1d(catalogs['type'], ['BOT', 'GUI'])]
star_obs = join(observations, catalogs, keys=join_keys)
star_obs.rename_columns(['id', 'starcat_date'], ['agasc_id', 'mp_starcat_time'])
star_obs['row'], star_obs['col'] = yagzag_to_pixels(star_obs['yang'], star_obs['zang'])

# Add mag_aca_err column
filename = os.path.join(os.environ['SKA'], 'data', 'agasc', 'proseco_agasc_1p7.h5')
with tables.open_file(filename) as h5:
agasc_ids = h5.root.data.col('AGASC_ID')
mag_errs = h5.root.data.col('MAG_ACA_ERR') * 0.01

tt = Table([agasc_ids, mag_errs], names=['agasc_id', 'mag_aca_err'])
star_obs = table.join(star_obs, tt, keys='agasc_id')

return star_obs, observations, catalogs


def _load_startcat_commands(tstop=None):
"""
Get all star catalog commands. This is a definitive list of commands
Expand Down Expand Up @@ -204,8 +228,11 @@ def _load_observed_catalogs():
STARS_OBS.add_index('mp_starcat_time')


def load(tstop=None):
def load(tstop=None, commands_v2=False):
global STARS_OBS
if STARS_OBS is None:
_load_startcat_commands(tstop)
_load_observed_catalogs()
if commands_v2:
STARS_OBS = get_star_observations(stop=tstop)
else:
_load_startcat_commands(tstop)
_load_observed_catalogs()

0 comments on commit 97ca22d

Please sign in to comment.