sot / kadi

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

states.get_continuity fails #325

Closed jeanconn closed 1 month ago

jeanconn commented 3 months ago

states.get_continuity('2003:071:11:57:07.899') fails

In [1]: from kadi.commands import states

In [2]: states.get_continuity('2003:071:11:57:07.899')
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
Cell In[2], line 1
----> 1 states.get_continuity('2003:071:11:57:07.899')

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:2305, in get_continuity(date, state_keys, lookbacks, scenario)
   2294 # Get available commanded states for this particular state_key.
   2295 # This may return state values for many more keys (e.g.
   2296 # PCAD-related), and some or all of these might be None if the
   2297 # relevant command never happened.  Fill in continuity as possible
   2298 # from last state (corresponding to the state after the last command
   2299 # in cmds).
   2300 try:
   2301     # Note that we need to specify start and stop to ensure that the
   2302     # states span the required time range. Without this the time
   2303     # range of cmds is used which can give unexpected outputs if
   2304     # ``date``` is within a maneuver.
-> 2305     states = get_states(
   2306         state_keys=state_key,
   2307         cmds=cmds,
   2308         start=start,
   2309         stop=stop,
   2310         continuity={},
   2311         reduce=False,
   2312         scenario=scenario,
   2313     )
   2314 except NoTransitionsError:
   2315     # No transitions within `cmds` for state_key, continue with other keys
   2316     continue

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:2111, in get_states(start, stop, state_keys, cmds, continuity, reduce, merge_identical, scenario)
   2106 for key, value in transition.items():
   2107     if callable(value):
   2108         # Special case of a functional transition that calls a function
   2109         # instead of directly updating the state.  The function might itself
   2110         # update the state or it might generate downstream transitions.
-> 2111         value(date, transitions, state, idx)
   2112     elif key != "date":
   2113         # Normal case of just updating current state
   2114         state[key] = value

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:1129, in SunVectorTransition.update_sun_vector_state(cls, date, transitions, state, idx)
   1127 time = date2secs(date)
   1128 sun_ra, sun_dec = ska_sun.position(time)
-> 1129 state["pitch"] = ska_sun.pitch(ra, dec, sun_ra=sun_ra, sun_dec=sun_dec)
   1130 state["off_nom_roll"] = ska_sun.off_nominal_roll(
   1131     [ra, dec, roll], time, sun_ra=sun_ra, sun_dec=sun_dec
   1132 )

File /proj/sot/ska3/flight/lib/python3.11/site-packages/ska_sun/sun.py:413, in pitch(ra, dec, time, sun_ra, sun_dec, method)
    411 if time is not None:
    412     sun_ra, sun_dec = position(time, method=method)
--> 413 pitch = sph_dist(ra, dec, sun_ra, sun_dec)
    415 return pitch

File /proj/sot/ska3/flight/lib/python3.11/site-packages/numba/core/dispatcher.py:468, in _DispatcherBase._compile_for_args(self, *args, **kws)
    464         msg = (f"{str(e).rstrip()} \n\nThis error may have been caused "
    465                f"by the following argument(s):\n{args_str}\n")
    466         e.patch_message(msg)
--> 468     error_rewrite(e, 'typing')
    469 except errors.UnsupportedError as e:
    470     # Something unsupported is present in the user code, add help info
    471     error_rewrite(e, 'unsupported_error')

File /proj/sot/ska3/flight/lib/python3.11/site-packages/numba/core/dispatcher.py:409, in _DispatcherBase._compile_for_args.<locals>.error_rewrite(e, issue_type)
    407     raise e
    408 else:
--> 409     raise e.with_traceback(None)

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<ufunc 'radians'>) found for signature:

 >>> radians(none)

There are 2 candidate implementations:
   - Of which 2 did not match due to:
   Overload in function 'Numpy_rules_ufunc.generic': File: numba/core/typing/npydecl.py: Line 97.
     With argument(s): '(none)':
    Rejected as the implementation raised a specific error:
      TypingError: can't resolve ufunc radians for types [none]
  raised from /proj/sot/ska3/flight/lib/python3.11/site-packages/numba/core/typing/npydecl.py:106

During: resolving callee type: Function(<ufunc 'radians'>)
During: typing of call at /proj/sot/ska3/flight/lib/python3.11/site-packages/ska_sun/sun.py (364)

File "../../proj/sot/ska3/flight/lib/python3.11/site-packages/ska_sun/sun.py", line 364:
def sph_dist(a1, d1, a2, d2):
    <source elided>
        return 0.0
    a1 = radians(a1)
    ^
jeanconn commented 1 month ago

Here are a couple of other continuity failures (these look like obsid = None problems more than attitude = unknown ones).

In [1]: from kadi.commands import states

In [2]: states.get_continuity(743506575.506)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 states.get_continuity(743506575.506)

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:2305, in get_continuity(date, state_keys, lookbacks, scenario)
   2294 # Get available commanded states for this particular state_key.
   2295 # This may return state values for many more keys (e.g.
   2296 # PCAD-related), and some or all of these might be None if the
   2297 # relevant command never happened.  Fill in continuity as possible
   2298 # from last state (corresponding to the state after the last command
   2299 # in cmds).
   2300 try:
   2301     # Note that we need to specify start and stop to ensure that the
   2302     # states span the required time range. Without this the time
   2303     # range of cmds is used which can give unexpected outputs if
   2304     # ``date``` is within a maneuver.
-> 2305     states = get_states(
   2306         state_keys=state_key,
   2307         cmds=cmds,
   2308         start=start,
   2309         stop=stop,
   2310         continuity={},
   2311         reduce=False,
   2312         scenario=scenario,
   2313     )
   2314 except NoTransitionsError:
   2315     # No transitions within `cmds` for state_key, continue with other keys
   2316     continue

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:2111, in get_states(start, stop, state_keys, cmds, continuity, reduce, merge_identical, scenario)
   2106 for key, value in transition.items():
   2107     if callable(value):
   2108         # Special case of a functional transition that calls a function
   2109         # instead of directly updating the state.  The function might itself
   2110         # update the state or it might generate downstream transitions.
-> 2111         value(date, transitions, state, idx)
   2112     elif key != "date":
   2113         # Normal case of just updating current state
   2114         state[key] = value

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:1658, in ACISTransition.simode_callback(tlmsid, date, transitions, state, idx)
   1655     si_mode = NIL_SIMODES[tlmsid]
   1656     # Value of SIMODE in some cases depends on whether obsid is
   1657     # an odd or even number
-> 1658     if si_mode.startswith("HIE") and state["obsid"] % 2 != 0:
   1659         si_mode = si_mode.replace("HIE", "HIO")
   1661 # All other SI modes: this logic uses the PBLK command to
   1662 # determine the SI mode hex string, which depends in part on
   1663 # whether a bias is being (re)computed.

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

In [3]: states.get_continuity(743506575.506)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 states.get_continuity(743506575.506)

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:2305, in get_continuity(date, state_keys, lookbacks, scenario)
   2294 # Get available commanded states for this particular state_key.
   2295 # This may return state values for many more keys (e.g.
   2296 # PCAD-related), and some or all of these might be None if the
   2297 # relevant command never happened.  Fill in continuity as possible
   2298 # from last state (corresponding to the state after the last command
   2299 # in cmds).
   2300 try:
   2301     # Note that we need to specify start and stop to ensure that the
   2302     # states span the required time range. Without this the time
   2303     # range of cmds is used which can give unexpected outputs if
   2304     # ``date``` is within a maneuver.
-> 2305     states = get_states(
   2306         state_keys=state_key,
   2307         cmds=cmds,
   2308         start=start,
   2309         stop=stop,
   2310         continuity={},
   2311         reduce=False,
   2312         scenario=scenario,
   2313     )
   2314 except NoTransitionsError:
   2315     # No transitions within `cmds` for state_key, continue with other keys
   2316     continue

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:2111, in get_states(start, stop, state_keys, cmds, continuity, reduce, merge_identical, scenario)
   2106 for key, value in transition.items():
   2107     if callable(value):
   2108         # Special case of a functional transition that calls a function
   2109         # instead of directly updating the state.  The function might itself
   2110         # update the state or it might generate downstream transitions.
-> 2111         value(date, transitions, state, idx)
   2112     elif key != "date":
   2113         # Normal case of just updating current state
   2114         state[key] = value

File /proj/sot/ska3/flight/lib/python3.11/site-packages/kadi/commands/states.py:1658, in ACISTransition.simode_callback(tlmsid, date, transitions, state, idx)
   1655     si_mode = NIL_SIMODES[tlmsid]
   1656     # Value of SIMODE in some cases depends on whether obsid is
   1657     # an odd or even number
-> 1658     if si_mode.startswith("HIE") and state["obsid"] % 2 != 0:
   1659         si_mode = si_mode.replace("HIE", "HIO")
   1661 # All other SI modes: this logic uses the PBLK command to
   1662 # determine the SI mode hex string, which depends in part on
   1663 # whether a bias is being (re)computed.

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'
taldcroft commented 1 month ago

Those examples in the recent past are more concerning, thanks for documenting this. I mostly understand this as the ACIS state wanting obsid for continuity but it isn't available at the time of a callback. I found one hack that fixed it but I need to dig more to be sure there isn't a bigger problem of chicken-and-egg happening.

jeanconn commented 1 month ago

Thanks! This came up when I remembered I hadn't stuck that quick "observing fraction" notebook anywhere. I just put it in skanb and added a try-except to get through the couple of times that it was breaking out of get_continuity.

https://github.com/sot/skanb/blob/ddd50a1ae8155fdae4008a39dbc8ccdb03b459d5/misc/observing.ipynb