Skip to content

Commit

Permalink
Merge pull request #166 from sot/shiny-tests
Browse files Browse the repository at this point in the history
SHINY: update dates for Chandra.Time 4.0+
  • Loading branch information
taldcroft authored Jun 25, 2020
2 parents 5b54f2c + ed1525e commit 6a8931c
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 45 deletions.
12 changes: 6 additions & 6 deletions kadi/cmds/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_find():
cs = cmds._find('2012:029', '2012:030')
cs = cmds._find('2012:029:12:00:00', '2012:030:12:00:00')
assert isinstance(cs, Table)
assert len(cs) == 147
assert np.all(cs['timeline_id'][:10] == 426098447)
Expand All @@ -15,21 +15,21 @@ def test_find():
assert cs['date'][-1] == '2012:030:11:00:01.285'
assert cs['tlmsid'][-1] == 'CTXBON'

cs = cmds._find('2012:029', '2012:030', type='simtrans')
cs = cmds._find('2012:029:12:00:00', '2012:030:12:00:00', type='simtrans')
assert len(cs) == 2
assert np.all(cs['date'] == ['2012:030:02:00:00.000', '2012:030:08:27:02.000'])

cs = cmds._find('2012:015', '2012:030', type='acispkt', tlmsid='wsvidalldn')
cs = cmds._find('2012:015:12:00:00', '2012:030:12:00:00', type='acispkt', tlmsid='wsvidalldn')
assert len(cs) == 3
assert np.all(cs['date'] == ['2012:018:01:16:15.798', '2012:020:16:51:17.713',
'2012:026:05:28:09.000'])

cs = cmds._find('2011:001', '2014:001', msid='aflcrset')
cs = cmds._find('2011:001:12:00:00', '2014:001:12:00:00', msid='aflcrset')
assert len(cs) == 2494


def test_filter():
cs = cmds.filter('2012:029', '2012:030')
cs = cmds.filter('2012:029:12:00:00', '2012:030:12:00:00')
assert isinstance(cs, cmds.CmdList)
assert len(cs) == 147
assert np.all(cs['timeline_id'][:10] == 426098447)
Expand All @@ -38,7 +38,7 @@ def test_filter():
assert cs['date'][-1] == '2012:030:11:00:01.285'
assert cs['tlmsid'][-1] == 'CTXBON'

cs = cmds.filter('2012:029', '2012:030', type='simtrans')
cs = cmds.filter('2012:029:12:00:00', '2012:030:12:00:00', type='simtrans')
assert len(cs) == 2
assert np.all(cs['date'] == ['2012:030:02:00:00.000', '2012:030:08:27:02.000'])
assert np.all(cs['pos'] == [75624, 73176]) # from params
Expand Down
15 changes: 8 additions & 7 deletions kadi/commands/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def test_find():
cs = commands._find('2012:029', '2012:030')
cs = commands._find('2012:029:12:00:00', '2012:030:12:00:00')
assert isinstance(cs, Table)
assert len(cs) == 147
assert np.all(cs['timeline_id'][:10] == 426098447)
Expand All @@ -21,21 +21,22 @@ def test_find():
assert cs['date'][-1] == '2012:030:11:00:01.285'
assert cs['tlmsid'][-1] == 'CTXBON'

cs = commands._find('2012:029', '2012:030', type='simtrans')
cs = commands._find('2012:029:12:00:00', '2012:030:12:00:00', type='simtrans')
assert len(cs) == 2
assert np.all(cs['date'] == ['2012:030:02:00:00.000', '2012:030:08:27:02.000'])

cs = commands._find('2012:015', '2012:030', type='acispkt', tlmsid='wsvidalldn')
cs = commands._find('2012:015:12:00:00', '2012:030:12:00:00',
type='acispkt', tlmsid='wsvidalldn')
assert len(cs) == 3
assert np.all(cs['date'] == ['2012:018:01:16:15.798', '2012:020:16:51:17.713',
'2012:026:05:28:09.000'])

cs = commands._find('2011:001', '2014:001', msid='aflcrset')
cs = commands._find('2011:001:12:00:00', '2014:001:12:00:00', msid='aflcrset')
assert len(cs) == 2494


def test_get_cmds():
cs = commands.get_cmds('2012:029', '2012:030')
cs = commands.get_cmds('2012:029:12:00:00', '2012:030:12:00:00')
assert isinstance(cs, commands.CommandTable)
assert len(cs) == 147
assert np.all(cs['timeline_id'][:10] == 426098447)
Expand All @@ -44,7 +45,7 @@ def test_get_cmds():
assert cs['date'][-1] == '2012:030:11:00:01.285'
assert cs['tlmsid'][-1] == 'CTXBON'

cs = commands.get_cmds('2012:029', '2012:030', type='simtrans')
cs = commands.get_cmds('2012:029:12:00:00', '2012:030:12:00:00', type='simtrans')
assert len(cs) == 2
assert np.all(cs['date'] == ['2012:030:02:00:00.000', '2012:030:08:27:02.000'])
assert np.all(cs['pos'] == [75624, 73176]) # from params
Expand All @@ -61,7 +62,7 @@ def test_get_cmds():


def test_get_cmds_zero_length_result():
cmds = commands.get_cmds(date='2017:001')
cmds = commands.get_cmds(date='2017:001:12:00:00')
assert len(cmds) == 0
assert cmds.colnames == ['idx', 'date', 'type', 'tlmsid', 'scs',
'step', 'timeline_id', 'vcdu', 'params']
Expand Down
38 changes: 22 additions & 16 deletions kadi/commands/tests/test_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_acis():
Test all ACIS states include vid_board for late-2017
"""
state_keys = ['clocking', 'power_cmd', 'fep_count', 'si_mode', 'vid_board']
rc, rk = compare_states('2017:280', '2017:360', state_keys, state_keys)
rc, rk = compare_states('2017:280:12:00:00', '2017:360:12:00:00', state_keys, state_keys)


def test_cmd_line_interface(tmpdir):
Expand Down Expand Up @@ -117,11 +117,12 @@ def test_quick():
+ ['letg', 'hetg']
+ ['simpos', 'simfa_pos'])
continuity = {'letg': 'RETR', 'hetg': 'RETR'} # Not necessarily set within 7 days
rc, rk = compare_states('2018:235', '2018:245', state_keys, continuity=continuity)
rc, rk = compare_states('2018:235:12:00:00', '2018:245:12:00:00', state_keys,
continuity=continuity)

# Now test using start/stop pair with start/stop and no supplied cmds or continuity.
# This also tests the API kwarg order: datestart, datestop, state_keys, ..)
sts = states.get_states('2018:235', '2018:245', state_keys, reduce=False)
sts = states.get_states('2018:235:12:00:00', '2018:245:12:00:00', state_keys, reduce=False)
rk = states.reduce_states(sts, state_keys, merge_identical=True)
assert len(rc) == len(rk)

Expand All @@ -135,7 +136,7 @@ def test_acis_raw_mode():
"""Test ACIS raw-mode SI modes"""
# Minimal test that they are found in a period of time known to have
# raw mode commanding.
kstates = states.get_states(start='2017:189', stop='2017:197',
kstates = states.get_states(start='2017:189:12:00:00', stop='2017:197:12:00:00',
state_keys=['si_mode'])
assert 'TN_000B4' in kstates['si_mode']
assert 'TN_000B6' in kstates['si_mode']
Expand Down Expand Up @@ -164,7 +165,8 @@ def test_states_2017():
+ ['q1', 'q2', 'q3', 'q4', 'pcad_mode', 'dither', 'ra', 'dec', 'roll']
+ ['letg', 'hetg']
+ ['simpos', 'simfa_pos'])
rcstates, rkstates = compare_states('2017:060', '2017:260', state_keys, compare_dates=False)
rcstates, rkstates = compare_states('2017:060:12:00:00', '2017:260:12:00:00',
state_keys, compare_dates=False)

# Check state datestart. There are 4 known discrepancies of 0.001 sec
# due to a slight difference in the start time for NSUN maneuvers. Cmd_states
Expand All @@ -190,7 +192,8 @@ def test_pitch_2017():
Make sure that pitch matches to within 0.5 deg in all samples, and 0.05 deg during
NPNT.
"""
rcstates, rkstates = get_states_test('2017:060', '2017:160', ['pcad_mode', 'pitch'])
rcstates, rkstates = get_states_test('2017:060:12:00:00', '2017:160:12:00:00',
['pcad_mode', 'pitch'])

rcstates['tstop'] = DateTime(rcstates['datestop']).secs
rkstates['tstop'] = DateTime(rkstates['datestop']).secs
Expand Down Expand Up @@ -365,9 +368,9 @@ def test_get_continuity_vs_states():
Functional test: continuity for a certain date should be the same as the last states
when fed in cmds up through that date.
"""
date0 = '2017:014'
date0 = '2017:014:12:00:00'
# Get last state up through `date0`. Hardwire the lookback here to 21 days.
cmds = commands.get_cmds('2016:360', date0)
cmds = commands.get_cmds('2016:360:12:00:00', date0)
sts = states.get_states(cmds=cmds)
sts0 = sts[-1]

Expand Down Expand Up @@ -406,13 +409,13 @@ def test_get_states_with_cmds_and_start_stop():
def test_get_continuity_keys():
"""Test that output has only the desired state keys. Also test that one can
provide a string instead of list of state keys"""
continuity = states.get_continuity('2017:014', 'clocking')
continuity = states.get_continuity('2017:014:12:00:00', 'clocking')
assert set(continuity) == set(['clocking', '__dates__'])


def test_get_continuity_fail():
with pytest.raises(ValueError) as err:
states.get_continuity('2017:014', 'letg', lookbacks=[3])
states.get_continuity('2017:014:12:00:00', 'letg', lookbacks=[3])
assert 'did not find transitions' in str(err)


Expand Down Expand Up @@ -467,15 +470,15 @@ def test_reduce_states_cmd_states():
Test that simple get_states() call with defaults gives the same results
as calling cmd_states.fetch_states().
"""
cs = cmd_states.fetch_states('2018:235', '2018:245', allow_identical=True)
cs = cmd_states.fetch_states('2018:235:12:00:00', '2018:245:12:00:00', allow_identical=True)
cs = Table(cs)

state_keys = (set(cmd_states.STATE0)
- set(['datestart', 'datestop', 'trans_keys', 'tstart', 'tstop']))

# Default setting is reduce states with merge_identical=False, which is the same
# as cmd_states.
ksr = states.get_states('2018:235', '2018:245', state_keys)
ksr = states.get_states('2018:235:12:00:00', '2018:245:12:00:00', state_keys)

assert len(ksr) == len(cs)

Expand Down Expand Up @@ -956,7 +959,8 @@ def test_backstop_scs84():
"""
SCS 84 has not changed from DISA since 2006 due to a change in operations.
"""
sts = states.get_states(start='2017:001', stop='2017:300', state_keys=['scs84'])
sts = states.get_states(start='2017:001:12:00:00', stop='2017:300:12:00:00',
state_keys=['scs84'])
assert len(sts) == 1
assert sts[0]['scs84'] == 'DISA'
assert sts[0]['datestart'] == '2017:001:12:00:00.000'
Expand Down Expand Up @@ -1239,7 +1243,7 @@ def test_continuity_with_no_transitions_SPM():
key set if not needed. Part of fix for #125.
"""
cont = states.get_continuity('2017:001', state_keys=['sun_pos_mon'])
cont = states.get_continuity('2017:001:12:00:00', state_keys=['sun_pos_mon'])
assert cont == {'sun_pos_mon': 'DISA',
'__dates__': {'sun_pos_mon': '2017:001:04:23:55.764'}}

Expand Down Expand Up @@ -1271,7 +1275,8 @@ def test_get_pitch_from_mid_maneuver():


def test_acisfp_setpoint_state():
sts = states.get_states('1999-01-01', '2004-01-01', state_keys='acisfp_setpoint')
sts = states.get_states('1999-01-01 12:00:00', '2004-01-01 12:00:00',
state_keys='acisfp_setpoint')
assert repr(sts).splitlines() == [
'<Table length=5>',
' datestart datestop acisfp_setpoint trans_keys ',
Expand All @@ -1283,7 +1288,8 @@ def test_acisfp_setpoint_state():
'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')
sts = states.get_states('2018-01-01 12:00:00', '2020-03-01 12:00:00',
state_keys='acisfp_setpoint')
assert repr(sts).splitlines() == [
'<Table length=6>',
' datestart datestop acisfp_setpoint trans_keys ',
Expand Down
2 changes: 1 addition & 1 deletion kadi/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@ def get_state_times_bools(cls, msidset):
| (msidset['c1sqax'].vals != 'ENAB'))

# Telemetry indicates a safemode around 1999:221 which isn't real
bogus_tstart = DateTime('1999:225').secs
bogus_tstart = DateTime('1999:225:12:00:00').secs
if msidset.tstart < bogus_tstart:
ok = msidset.times < bogus_tstart
safe_mode[ok] = False
Expand Down
2 changes: 1 addition & 1 deletion kadi/occweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_url(page, timeout=TIMEOUT):


def get_ifot(event_type, start=None, stop=None, props=[], columns=[], timeout=TIMEOUT, types={}):
start = DateTime('1998:001' if start is None else start)
start = DateTime('1998:001:12:00:00' if start is None else start)
stop = DateTime(stop)
event_props = '.'.join([event_type] + props)

Expand Down
15 changes: 8 additions & 7 deletions kadi/tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ def test_interval_pads():


def test_query_event_intervals():
intervals = (events.manvrs & events.tsc_moves).intervals('2012:001', '2012:002')
intervals = (events.manvrs & events.tsc_moves).intervals('2012:001:12:00:00',
'2012:002:12:00:00')
assert intervals == [('2012:001:18:21:31.715', '2012:001:18:22:04.515'),
('2012:002:02:53:03.804', '2012:002:02:54:50.917')]


def test_basic_query():
rad_zones = events.rad_zones.filter('2013:001', '2013:007')
rad_zones = events.rad_zones.filter('2013:001:12:00:00', '2013:007:12:00:00')
assert str(rad_zones).splitlines() == [
'<RadZone: 1852 2013:003:16:19:36 2013:004:02:21:34 dur=36.1 ksec>',
'<RadZone: 1853 2013:006:08:22:22 2013:006:17:58:48 dur=34.6 ksec>']
Expand All @@ -97,7 +98,7 @@ def test_basic_query():
'2013:006:08:22:22.982 2013:006:17:58:48.982 473847810.166 473882396.166 34586.000 1853 1853 2013:006:13:58:21.389' # noqa
]

rad_zones = events.rad_zones.filter('2013:001', '2013:002')
rad_zones = events.rad_zones.filter('2013:001:12:00:00', '2013:002:12:00:00')
assert len(rad_zones) == 0
assert len(rad_zones.table) == 0

Expand All @@ -123,7 +124,7 @@ def test_get_obsid():
for model in models.values():
if model.__name__ == 'SafeSun':
continue # Doesn't work for SafeSun because of bad OBC telem
model_obj = model.objects.filter(start__gte='2002:010')[0]
model_obj = model.objects.filter(start__gte='2002:010:12:00:00')[0]
obsid = model_obj.get_obsid()
obsid_obj = events.obsids.filter(obsid__exact=obsid)[0]
model_obj_start = DateTime(getattr(model_obj, model_obj._get_obsid_start_attr)).date
Expand All @@ -146,14 +147,14 @@ def test_intervals_filter():
Test setting filter keywords in the EventQuery object itself.
"""
ltt_bads = events.ltt_bads
start, stop = '2000:121', '2000:134'
start, stop = '2000:121:12:00:00', '2000:134:12:00:00'

# 2000-04-30 00:00:00 | ELBI_LOW | R
# 2000-04-30 00:00:00 | EPOWER1 | R
# 2000-05-01 00:00:00 | 3SDTSTSV | Y
# 2000-05-13 00:00:00 | 3SDP15V | 1

lines = sorted(str(ltt_bads().filter('2000:121', '2000:134')).splitlines())
lines = sorted(str(ltt_bads().filter('2000:121:12:00:00', '2000:134:12:00:00')).splitlines())
assert (lines
== ['<LttBad: start=2000:121:00:00:00.000 msid=ELBI_LOW flag=R>',
'<LttBad: start=2000:121:00:00:00.000 msid=EPOWER1 flag=R>',
Expand Down Expand Up @@ -188,7 +189,7 @@ def test_get_overlaps():
overlap_starts, overlap_stops = zip(*overlaps)
overlap_starts, overlap_stops = np.array(overlap_starts), np.array(overlap_stops)

x = events.manvrs.filter('2000:001', '2000:002')
x = events.manvrs.filter('2000:001:12:00:00', '2000:002:12:00:00')
indices = x._get_full_overlaps(overlap_starts, overlap_stops, datestarts, datestops)
assert np.all(indices == [0, 1, 2])

Expand Down
2 changes: 1 addition & 1 deletion kadi/tests/test_occweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_put_get_user_none():

@pytest.mark.skipif('not HAS_OCCWEB')
def test_ifot_fetch():
events = occweb.get_ifot('LOADSEG', start='2008:001', stop='2008:003')
events = occweb.get_ifot('LOADSEG', start='2008:001:12:00:00', stop='2008:003:12:00:00')
assert len(events) == 1
assert events[0]['tstart'] == '2008:002:21:00:00.000'

Expand Down
8 changes: 4 additions & 4 deletions manual_test_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_ingest():
# sure the LazyVals will re-read.
data_root_tmp = Ska.File.TempDir()
data_root = data_root_tmp.name
update_cmds.main(['--start', '2011:340', '--stop', '2012:100',
update_cmds.main(['--start', '2011:340:12:00:00', '--stop', '2012:100:12:00:00',
'--data-root', data_root])

# Some chicken-n-egg
Expand All @@ -39,7 +39,7 @@ def test_ingest():
if hasattr(cmds.pars_dict, '_val'):
del cmds.pars_dict._val

cmds_at_once = cmds.filter('2012:010', '2012:090')
cmds_at_once = cmds.filter('2012:010:12:00:00', '2012:090:12:00:00')
pars_at_once = {v: k for k, v in cmds.pars_dict.items()}

# Second part of funkiness to be able to use two different data root values
Expand All @@ -53,12 +53,12 @@ def test_ingest():
if hasattr(cmds.pars_dict, '_val'):
del cmds.pars_dict._val

stop0 = DateTime('2012:001')
stop0 = DateTime('2012:001:12:00:00')
for dt in range(0, 100, 1):
update_cmds.main(['--stop', (stop0 + dt).date,
'--data-root', data_root])

cmds_per_day = cmds.filter('2012:010', '2012:090')
cmds_per_day = cmds.filter('2012:010:12:00:00', '2012:090:12:00:00')
pars_per_day = {v: k for k, v in cmds.pars_dict.items()}

for name in ('date', 'type', 'tlmsid', 'scs', 'step', 'timeline_id'):
Expand Down
2 changes: 1 addition & 1 deletion validate/gratings/compare_grating_moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from kadi import events
from Chandra.Time import DateTime

kadi_moves = events.grating_moves.filter(start='2000:160', stop='2014:008',
kadi_moves = events.grating_moves.filter(start='2000:160:12:00:00', stop='2014:008:12:00:00',
grating__contains='ETG').table
mta_moves = Table.read('mta_grating_moves.dat', format='ascii',
converters={'START_TIME': [ascii.convert_numpy(np.str)],
Expand Down
2 changes: 1 addition & 1 deletion validate/gratings/plot_grating.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# msidset = fetch.Msidset(msids, '2013:357:10:00:00', '2013:357:10:15:00')
# msidset = fetch.Msidset(msids, '2000:001:10:00:00', '2000:010:10:15:00')
# msidset = fetch.Msidset(msids, '2001:145:16:40:00', '2001:145:16:46:00')
# msidset = fetch.Msidset(msids, '2001:188', '2001:191')
# msidset = fetch.Msidset(msids, '2001:188:12:00:00', '2001:191:12:00:00')
msidset = fetch.Msidset(msids, '2000:048:08:09:19.544', '2000:048:08:14:36.344')


Expand Down

0 comments on commit 6a8931c

Please sign in to comment.