sot / kadi

Chandra commands and events
https://sot.github.io/kadi
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

get_continuity fails #258

Closed jeanconn closed 1 year ago

jeanconn commented 1 year ago

This looks similar to https://github.com/sot/kadi/pull/199 only here it looks like maybe the transition to safe mode while already in NSUN is setting things up for an undefined maneuver transition?


In [38]: kadi_states.get_continuity('2022:301:12:42:32.418', scenario='flight')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-38-6a94cda52ee9> in <module>
----> 1 kadi_states.get_continuity('2022:301:12:42:32.418', scenario='flight')

/proj/sot/ska3/flight/lib/python3.8/site-packages/kadi/commands/states.py in get_continuity(date, state_keys, lookbacks, scenario)
   1713                 # the required time range. Without this the time range of cmds is used which
   1714                 # can give unexpected outputs if ``date``` is within a maneuver.
-> 1715                 states = get_states(
   1716                     state_keys=state_key,
   1717                     cmds=cmds,

/proj/sot/ska3/flight/lib/python3.8/site-packages/kadi/commands/states.py in get_states(start, stop, state_keys, cmds, continuity, reduce, merge_identical, scenario)
   1535                 # instead of directly updating the state.  The function might itself
   1536                 # update the state or it might generate downstream transitions.
-> 1537                 value(date, transitions, state, idx)
   1538             elif key != "date":
   1539                 # Normal case of just updating current state

/proj/sot/ska3/flight/lib/python3.8/site-packages/kadi/commands/states.py in callback(cls, date, transitions, state, idx)
   1111 
   1112         # Do the maneuver
-> 1113         cls.add_manvr_transitions(date, transitions, state, idx)
   1114 
   1115 

/proj/sot/ska3/flight/lib/python3.8/site-packages/kadi/commands/states.py in add_manvr_transitions(cls, date, transitions, state, idx)
   1047 
   1048         # Get attitudes for the maneuver at about 5-minute intervals.
-> 1049         atts = Chandra.Maneuver.attitudes(
   1050             curr_att, targ_att, tstart=DateTime(date).secs
   1051         )

/proj/sot/ska3/flight/lib/python3.8/site-packages/Chandra/Maneuver/maneuver.py in attitudes(att1, att2, step, tstart, exact_steps)
    125         times = np.append(np.arange(0.0, Tm, step), Tm)
    126     else:
--> 127         times = np.linspace(0.0, Tm, int(round(Tm / step)) + 1)
    128 
    129     e = get_eigenaxis(manvr_quat.q[:3])

ValueError: cannot convert float NaN to integer

In [39]: %debug
> /proj/sot/ska3/flight/lib/python3.8/site-packages/Chandra/Maneuver/maneuver.py(127)attitudes()
    125         times = np.append(np.arange(0.0, Tm, step), Tm)
    126     else:
--> 127         times = np.linspace(0.0, Tm, int(round(Tm / step)) + 1)
    128 
    129     e = get_eigenaxis(manvr_quat.q[:3])

ipdb> manvr_quat
<Quat q1=nan q2=nan q3=nan q4=nan>
ipdb> u
> /proj/sot/ska3/flight/lib/python3.8/site-packages/kadi/commands/states.py(1049)add_manvr_transitions()
   1047 
   1048         # Get attitudes for the maneuver at about 5-minute intervals.
-> 1049         atts = Chandra.Maneuver.attitudes(
   1050             curr_att, targ_att, tstart=DateTime(date).secs
   1051         )

ipdb> curr_att
[nan, nan, nan, nan]
ipdb> targ_att
[nan, nan, nan, nan]
ipdb> date
'2022:294:16:32:28.000'
jeanconn commented 1 year ago

It seems like one could extend this "skip this one" behavior for targ_att not defined (though the NSM code gives [nan, nan, nan, nan] instead of None) or curr_att still not defined around

https://github.com/sot/kadi/blob/81ff21b98930bffac8efc2dac6c15c74250ffadc/kadi/commands/states.py#L1100

Or don't add a maneuver transition if curr_att is None etc around https://github.com/sot/kadi/blob/81ff21b98930bffac8efc2dac6c15c74250ffadc/kadi/commands/states.py#L1171

I figure the latter makes good sense.

taldcroft commented 1 year ago

Thanks for looking into this. I need to understand it a bit better. Hopefully this won't be a showstopper since it does go away if the start of the commanding for continuity does not fall in the intermediate time.

In [1]: from kadi.commands.states import get_continuity
In [3]: cont = get_continuity('2022:301:12:42:32.418', lookbacks=[6, 30, 180, 1000], scenario="flight")
In [4]: cont = get_continuity('2022:301:12:42:32.418', lookbacks=[8, 30, 180, 1000], scenario="flight")
In [5]: try:
   ...:     cont = get_continuity('2022:301:12:42:32.418', lookbacks=[7, 30, 180, 1000], scenario="flight")
   ...: except Exception:
   ...:     print('dang')
   ...: 
dang