Skip to content

Commit

Permalink
Merge pull request #200 from sot/complete-events
Browse files Browse the repository at this point in the history
Make kadi events complete from start of mission
  • Loading branch information
taldcroft authored Mar 21, 2021
2 parents b8beda3 + fb8f96b commit 593d705
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
33 changes: 17 additions & 16 deletions NOTES.build
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
#################################################################
# From scratch
# Events from scratch
#################################################################

cd ~/git/kadi
export KADI=$PWD
rm -f events3.db3 cmds.h5 cmds.pkl
rm -f events3.db3
rm -rf kadi/events/migrations
./manage.py makemigrations events
./manage.py migrate

# First line is just to see that every model works. One can just drop the
# --stop=2000:001 if you are sure it will work.
kadi_update_events --start=1999:240 --stop=2000:001
kadi_update_events --start=2000:001
kadi_update_cmds --start=2000:001
# Note: use kadi_update_events for the installed version.
python -m kadi.update_events --start=1999:001 --stop=2000:001
python -m kadi.update_events --start=2000:001

#################################################################
# Re-build single table
# Re-build single events table
#################################################################

% export KADI=$PWD
% cp /proj/sot/ska/data/kadi/events.db3 ./
% python -m kadi.update_events --start=1999:001 --model=CAP --delete-from-start

################# Historical note about running in a test env #################
#
# This is not applicable after PR #190.
#
# For commands one MUST do this in a dedicated test env because the pickling
# of UpdatedDict does not work. That object gets a module of __main__ but for
# production it must be kadi.update_cmds. See e.g.
# https://www.stefaanlippens.net/python-pickling-and-dealing-with-attributeerror-
# module-object-has-no-attribute-thing.html
pip install . # to a TEST env!! (Maybe with -e for editable install?)
#################################################################
# Commands from scratch
#################################################################

cd ~/git/kadi
export KADI=$PWD
rm -f cmds.h5 cmds.pkl

# Note: use kadi_update_events for the installed version.
python -m kadi.update_cmds --start=2000:001

18 changes: 15 additions & 3 deletions kadi/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def get_msids_states(cls, start, stop):
# interval that spans a telemetry gap of more than 10 major frames.
times, bools = cls.get_state_times_bools(event_msidset)
states = utils.logical_intervals(times, bools, max_gap=MAX_GAP)
except ValueError:
except (IndexError, ValueError):
if event_time_fuzz is None:
logger.warn('Warning: No telemetry available for {}'
.format(cls.__name__))
Expand Down Expand Up @@ -774,11 +774,16 @@ def get_events(cls, start, stop=None):
Get obsid events from telemetry. A event is defined by a
contiguous interval of the telemetered obsid.
"""
events = []
# Get the event telemetry MSID objects
event_msidset = fetch.Msidset(cls.event_msids, start, stop)
obsid = event_msidset['cobsrqid']

if len(obsid) < 2:
# Not enough telemetry for state_intervals, return no events
return events

states = obsid.state_intervals()
events = []
# Skip the first and last states as they are likely incomplete
for state in states[1:-1]:
event = dict(start=state['datestart'],
Expand Down Expand Up @@ -1521,16 +1526,23 @@ def get_events(cls, start, stop=None):
"""
Get maneuver events from telemetry.
"""
events = []
# Auxiliary information
aux_msidset = fetch.Msidset(['aotarqt1', 'aotarqt2', 'aotarqt3',
'aoatter1', 'aoatter2', 'aoatter3'],
start, stop)

# Need at least 2 samples to get states. Having no samples typically
# happens when building the event tables and telemetry queries are just
# before telemetry starts.
if any(len(aux_msid) < 2 for aux_msid in aux_msidset.values()):
return events

states, event_msidset = cls.get_msids_states(start, stop)
changes = _get_msid_changes(list(event_msidset.values()),
sortmsids={'aofattmd': 1, 'aopcadmd': 2,
'aoacaseq': 3, 'aopsacpr': 4})

events = []
for manvr_prev, manvr, manvr_next in zip(states, states[1:], states[2:]):
tstart = manvr['tstart']
tstop = manvr['tstop']
Expand Down

0 comments on commit 593d705

Please sign in to comment.