Closed taldcroft closed 2 years ago
Here is the code I used to test this PR:
import numpy as np
from kadi.commands import states
tstart = '2020:001:00:00:00'
tstop = '2022:073:00:00:00'
keys = ['pitch', 'off_nom_roll', 'ccd_count', 'fep_count', 'clocking', 'vid_board', 'pcad_mode', 'simpos']
state_data = states.get_states(tstart, tstop, state_keys=keys, merge_identical=True)
state_data_reduce = states.reduce_states(state_data, ['pcad_mode'], all_keys=True, merge_identical=True)
# Convert PCAD States to numbered values (e.g. NPNT --> 0, NMAN --> 1, etc.)
pcad_numbered_states = np.zeros_like(state_data['pcad_mode'])
for n, state in enumerate(set(state_data['pcad_mode'])):
pcad_numbered_states[state_data['pcad_mode'] == state] = n
# Find indices for PCAD state changes (first row for each change)
state_diff = np.diff(pcad_numbered_states.astype(int))
ind = np.abs(np.concatenate(([1,], state_diff))) != 0
# Ensure the data in the reduced states matches the first row for each change in the original table
assert np.all(state_data_reduce['tstart'] == state_data['tstart'][ind])
assert np.all(state_data_reduce['pitch'] == state_data['pitch'][ind])
assert np.all(state_data_reduce['off_nom_roll'] == state_data['off_nom_roll'][ind])
assert np.all(state_data_reduce['ccd_count'] == state_data['ccd_count'][ind])
assert np.all(state_data_reduce['fep_count'] == state_data['fep_count'][ind])
assert np.all(state_data_reduce['clocking'] == state_data['clocking'][ind])
assert np.all(state_data_reduce['vid_board'] == state_data['vid_board'][ind])
assert np.all(state_data_reduce['pcad_mode'] == state_data['pcad_mode'][ind])
assert np.all(state_data_reduce['simpos'] == state_data['simpos'][ind])
# Find indices for each row before PCAD state changes (last states for each group)
ind = np.abs(np.concatenate((state_diff, [1,]))) != 0
# Ensure the ending time for each reduced group of states is the last time for that group
assert np.all(state_data_reduce['tstop'] == state_data['tstop'][ind])
Description
This adds a keyword arg
all_keys
to thereduce_states
function so that whenTrue
all the original state keys are output instead of just those corresponding to the reduction keys.Search "issue I'm running into now is replacing the old commanded states version" in ska-dev on slack for context.
Interface impacts
Adds a keyword arg to the function signature but no change by default.
Testing
Unit tests
Independent check of unit tests by [REVIEWER NAME]
Functional tests
Using the original example from @matthewdahmer :