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

Improve SPM eclipse enable state #291

Merged
merged 5 commits into from
Aug 24, 2023
Merged

Improve SPM eclipse enable state #291

merged 5 commits into from
Aug 24, 2023

Conversation

taldcroft
Copy link
Member

@taldcroft taldcroft commented Jul 24, 2023

Description

This refactors the handling for the sun_pos_mon state into three separate states. This was needed in order to ensure that continuity is correct for any state query start time.

Fixes #289

Interface impacts

Adds new states battery_connect and eclipse_enable_spm.

Testing

Unit tests

  • Mac

Independent check of unit tests by Jean

  • Linux

Functional tests

Created (in a notebook) a new validator class:

class ValidateSunPosMon(ValidateStateCode):
    state_name = "sun_pos_mon"
    msids = ["aopssupm"]
    plot_attrs = PlotAttrs(title="Sun position monitor", ylabel="Sun position monitor")
    min_violation_duration = 300

    def add_exclude_intervals(self):
        super().add_exclude_intervals()
        self.exclude_ofp_intervals_except(["NRML"])

    @cached_property
    def state_vals(self):
        """Convert ENAB (commanded states) to ACT (telemetry).

        The "ENAB" is an artifact of the backstop history sun position monitor states.
        This method is otherwise equivalent to the ValidateStateCode method.
        """
        states_interp = interpolate_states(self.states, self.tlm["time"])
        state_vals = states_interp[self.state_name]
        state_vals[state_vals == "ENAB"] = "ACT"
        state_vals_raw = convert_state_code_to_raw_val(state_vals, self.state_codes)
        return state_vals_raw

With this the SPM transitions for a 200 day span are mostly OK:

>>> vp = ValidateSunPosMon("2023:200", days=200)
>>> viols = vp.get_violations()
>>> print(viols)
        start                  stop        
--------------------- ---------------------
2023:045:04:46:49.525 2023:045:04:52:17.525  # Safe mode
2023:049:03:38:31.067 2023:049:04:12:08.267  # Safe mode
2023:056:21:59:54.110 2023:056:22:06:11.310  # Real diff between expected penumbra exit and actual?

@taldcroft taldcroft changed the title WIP fix for SPM eclipse enable state Improve SPM eclipse enable state Jul 30, 2023
@taldcroft taldcroft requested review from javierggt and jeanconn July 30, 2023 10:45
kadi/commands/states.py Outdated Show resolved Hide resolved
@@ -711,7 +714,7 @@ class SPMEnableTransition(FixedTransition):

command_attributes = {"tlmsid": "AOFUNCEN"}
command_params = {"aopcadse": 30}
state_keys = ["sun_pos_mon"]
state_keys = SPM_STATE_KEYS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This speaks to a lack of knowledge on my part, but for a non-eclipse transition, are the battery_connect and eclipse_enable_spm keys relevant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tells the code that if you are asking for (e.g.) battery_connect that it should include this class in the processing that looks for potential state-changing commands since battery_connect and sun_pos_mon are coupled in some way. I'm honestly not 100% sure if this is needed but it's generally a good idea for states that work in tandem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's fine. It seemed not necessary in passing but also seems like it would be benign if not really needed (and is tested this way as fine).

Copy link
Contributor

@jeanconn jeanconn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing looks good and code makes sense to me from a "use states and continuity in a sane way to manage these things that are tricky" perspective.

@jeanconn
Copy link
Contributor

Related to "With this the SPM transitions for a 200 day span are mostly OK" -- what knobs would we have to twiddle to in the command google sheet if we ended up with a mismatch or wanted to fix a "mostly ok" that wasn't based on the code being incorrect?

@jeanconn
Copy link
Contributor

Oh, and I guess I shouldn't have Approved with an outstanding Flake 8 issue and it still probably should have that comment fixed.

Copy link
Contributor

@jeanconn jeanconn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll reset my review to "request changes" - I had that one question about relevant states and this needs flake8 update and maybe a fix to that comment.

@taldcroft
Copy link
Member Author

Related to "With this the SPM transitions for a 200 day span are mostly OK" -- what knobs would we have to twiddle to in the command google sheet if we ended up with a mismatch or wanted to fix a "mostly ok" that wasn't based on the code being incorrect?

In the Exclude Intervals sheet of the Chandra Command events spreadsheet, we would add interval(s) to exclude with the key sun_pos_mon.

@taldcroft
Copy link
Member Author

@jeanconn - I think I addressed your comments.

@taldcroft taldcroft merged commit eb58686 into master Aug 24, 2023
@taldcroft taldcroft deleted the fix-spm-eclipse-enable branch August 24, 2023 17:24
This was referenced Sep 18, 2023
@javierggt javierggt mentioned this pull request Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sun_pos_mon state needs sufficient command history
2 participants