Skip to content

Commit

Permalink
Fixes #59, Fixes #63: fix dtype of bad/mags/obs tables
Browse files Browse the repository at this point in the history
  • Loading branch information
javierggt committed Jan 29, 2021
1 parent cf27cb6 commit b69a529
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 8 additions & 3 deletions agasc/scripts/update_obs_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,19 @@ def update_obs_table(filename, obs_status_override, dry_run=False):
if not update:
return

obs_dtype = np.dtype([
('obsid', np.int32),
('agasc_id', np.int32),
('ok', np.int32),
('comments', '<U80')])
if obs_status:
t = list(zip(*[[oi, ai, np.uint(obs_status[(oi, ai)]['ok']), obs_status[(oi, ai)]['comments']]
for oi, ai in obs_status]))
obs_status = table.Table(t, names=['obsid', 'agasc_id', 'ok', 'comments'])
obs_status = table.Table(t, names=obs_dtype.names,
dtype=[obs_dtype[name] for name in obs_dtype.names])
else:
logger.info('creating empty obs table')
dtype = [('obsid', int), ('agasc_id', int), ('ok', np.uint), ('comments', '<U80')]
obs_status = table.Table(dtype=dtype)
obs_status = table.Table(dtype=obs_dtype)

if not dry_run:
obs_status.write(str(filename), format='hdf5', path='obs', append=True, overwrite=True)
Expand Down
18 changes: 11 additions & 7 deletions agasc/supplement/magnitudes/update_mag_supplement.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def update_supplement(agasc_stats, filename, include_all=True):
if False, only OK entries marked 'selected_*'
:return:
"""
mags_dtype = [('agasc_id', np.int32),
('mag_aca', np.float32),
('mag_aca_err', np.float32),
('last_obs_time', np.float64)]

if include_all:
outliers_new = agasc_stats[
(agasc_stats['n_obsids_ok'] > 0)
Expand All @@ -223,8 +228,10 @@ def update_supplement(agasc_stats, filename, include_all=True):
]
outliers_new['mag_aca'] = outliers_new['mag_obs']
outliers_new['mag_aca_err'] = outliers_new['mag_obs_err']
names = ['agasc_id', 'mag_aca', 'mag_aca_err', 'last_obs_time']
outliers_new = outliers_new[names].as_array()

outliers_new = outliers_new[mags_dtype.names].as_array()
if outliers_new.dtype != mags_dtype:
outliers_new = outliers_new.astype(mags_dtype)

outliers = None
new_stars = None
Expand All @@ -246,9 +253,7 @@ def update_supplement(agasc_stats, filename, include_all=True):
i_new = i_new[current['last_obs_time'] != new['last_obs_time']]
# overwrite current values with new values (and calculate diff to return)
updated_stars = np.zeros(len(outliers_new[i_new]),
dtype=[('agasc_id', np.int64),
('mag_aca', np.float64),
('mag_aca_err', np.float64)])
dtype=mags_dtype)
updated_stars['mag_aca'] = (outliers_new[i_new]['mag_aca'] -
outliers_current[i_cur]['mag_aca'])
updated_stars['mag_aca_err'] = (outliers_new[i_new]['mag_aca_err'] -
Expand All @@ -267,8 +272,7 @@ def update_supplement(agasc_stats, filename, include_all=True):
if outliers is None:
outliers = outliers_new
new_stars = outliers_new['agasc_id']
updated_stars = np.array([], dtype=[('agasc_id', np.int64), ('mag_aca', np.float64),
('mag_aca_err', np.float64)])
updated_stars = np.array([], dtype=mags_dtype)

mode = 'r+' if filename.exists() else 'w'
with tables.File(filename, mode) as h5:
Expand Down

0 comments on commit b69a529

Please sign in to comment.