Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add acisfp_setpoint state #161

Merged
merged 3 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/commands_states.rst
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ classes which affect the keys.

.. Run kadi.commands.states.print_state_keys_transition_classes_docs() to generate this list.

``acisfp_setpoint``
- :class:`~kadi.commands.states.ACISFP_SetPointTransition`

``aoephem1``, ``aoephem2``, ``aoratio``, ``aoargper``, ``aoeccent``, ``ao1minus``, ``ao1plus``, ``aomotion``, ``aoiterat``, ``aoorbang``, ``aoperige``, ``aoascend``, ``aosini``, ``aoslr``, ``aosqrtmu``
- :class:`~kadi.commands.states.EphemerisTransition`

Expand Down
48 changes: 48 additions & 0 deletions kadi/commands/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
from __future__ import division, print_function, absolute_import

import re
import collections
import itertools
import inspect
Expand Down Expand Up @@ -979,6 +980,41 @@ def set_transitions(cls, transitions, cmds, start, stop):
transitions[date].update(si_mode='TE_' + tlmsid[2:7])


class ACISFP_SetPointTransition(BaseTransition):
"""
Implement transitions for ACIS focal plane temperature setpoint state.

Looks for ACISPKT commands with TLMSID like ``WSFTNEG<number>``, where the
ACIS FP setpoint temperature is ``-<number>``.
"""
command_attributes = {'type': 'ACISPKT'}
state_keys = ['acisfp_setpoint']
default_value = -121.0

@classmethod
def set_transitions(cls, transitions, cmds, start, stop):
"""
Set transitions for a Table of commands ``cmds``.

:param transitions_dict: global dict of transitions (updated in-place)
:param cmds: commands (CmdList)
:param start: start time for states
:param stop: stop time for states

:returns: None
"""
state_cmds = cls.get_state_changing_commands(cmds)
for cmd in state_cmds:
tlmsid = cmd['tlmsid']
date = cmd['date']

if tlmsid.startswith('WSFTNEG'):
match = re.search(r'(\d+)$', tlmsid)
if not match:
raise ValueError(f'unable to parse command {tlmsid}')
transitions[date].update(acisfp_setpoint=-float(match.group(1)))


###################################################################
# State transitions processing code
###################################################################
Expand Down Expand Up @@ -1414,6 +1450,18 @@ def get_continuity(date=None, state_keys=None, lookbacks=(7, 30, 180, 1000)):
return continuity


def interpolate_states(states, times):
"""Interpolate ``states`` table at given times.

:param states: states (np.recarray)
:param times: times (np.array or list)

:returns: ``states`` view at ``times``
"""
indexes = np.searchsorted(states['tstop'], times)
return states[indexes]


def _unique(seq):
"""Return unique elements of ``seq`` in order"""
seen = set()
Expand Down
27 changes: 27 additions & 0 deletions kadi/commands/tests/test_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,3 +1246,30 @@ def test_get_pitch_from_mid_maneuver():
assert np.all(exp['datestop'] == sts['datestop'])
assert np.all(exp['pcad_mode'] == sts['pcad_mode'])
assert np.all(np.isclose(exp['pitch'], sts['pitch'], rtol=0, atol=1e-8))


def test_acisfp_setpoint_state():
sts = states.get_states('1999-01-01', '2004-01-01', state_keys='acisfp_setpoint')
assert repr(sts).splitlines() == [
'<Table length=5>',
' datestart datestop acisfp_setpoint trans_keys ',
' str21 str21 float64 object ',
'--------------------- --------------------- --------------- ---------------',
'1999:001:12:00:00.000 2003:130:05:07:28.341 -121.0 ',
'2003:130:05:07:28.341 2003:130:19:09:28.930 -130.0 acisfp_setpoint',
'2003:130:19:09:28.930 2003:132:14:22:33.782 -121.0 acisfp_setpoint',
'2003:132:14:22:33.782 2003:133:22:04:22.425 -130.0 acisfp_setpoint',
'2003:133:22:04:22.425 2004:001:12:00:00.000 -121.0 acisfp_setpoint']

sts = states.get_states('2018-01-01', '2020-03-01', state_keys='acisfp_setpoint')
assert repr(sts).splitlines() == [
'<Table length=6>',
' datestart datestop acisfp_setpoint trans_keys ',
' str21 str21 float64 object ',
'--------------------- --------------------- --------------- ---------------',
'2018:001:12:00:00.000 2018:249:20:16:04.603 -121.0 ',
'2018:249:20:16:04.603 2018:250:07:19:51.657 -126.0 acisfp_setpoint',
'2018:250:07:19:51.657 2018:294:22:29:00.000 -121.0 acisfp_setpoint',
'2018:294:22:29:00.000 2020:048:20:59:22.304 -121.0 acisfp_setpoint',
'2020:048:20:59:22.304 2020:049:13:05:52.537 -126.0 acisfp_setpoint',
'2020:049:13:05:52.537 2020:061:12:00:00.000 -121.0 acisfp_setpoint']