From 08477de1ff330bfeccf078ce2c71733e816b17bf Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Sat, 20 Mar 2021 12:12:09 -0400 Subject: [PATCH 1/2] Allow building from scratch with start date of 1999:001 to get everything --- NOTES.build | 13 +------------ kadi/events/models.py | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/NOTES.build b/NOTES.build index 23b8a9f0..453672fa 100644 --- a/NOTES.build +++ b/NOTES.build @@ -11,7 +11,7 @@ rm -rf kadi/events/migrations # 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=1999:001 --stop=2000:001 kadi_update_events --start=2000:001 kadi_update_cmds --start=2000:001 @@ -22,14 +22,3 @@ kadi_update_cmds --start=2000:001 % 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?) diff --git a/kadi/events/models.py b/kadi/events/models.py index e0a7c360..cc79afbb 100644 --- a/kadi/events/models.py +++ b/kadi/events/models.py @@ -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__)) @@ -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'], @@ -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'] From fb8f96bb5672b64a9b8cc81760cfb6d5ef58f8cc Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Sat, 20 Mar 2021 12:31:16 -0400 Subject: [PATCH 2/2] Improve NOTES.build --- NOTES.build | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/NOTES.build b/NOTES.build index 453672fa..cab7d178 100644 --- a/NOTES.build +++ b/NOTES.build @@ -1,24 +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:001 --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 + +################################################################# +# 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 +