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

Presets, Plugin Updates and JCAMP-DX #313

Merged
merged 33 commits into from
Nov 2, 2023
Merged

Conversation

mzieg
Copy link
Member

@mzieg mzieg commented Oct 10, 2023

I probably should have broken this up into more PRs.

  • plugins
    • removed plugin 'dependencies'; increase default plugin Marquee period
    • support events in functional plugins
    • provide self.marquee_message for functional plugins
    • add combobox datatype for plugin fields
    • allow plugin fields to have stylesheets
  • file_io
    • save as JCAMP-DX
    • support loading columnar CSV files which don't happen to include 'Integration Time'
  • added PresetFeature
  • refactoring
    • moved RamanIntensityCorrection, ScanAveragingFeature, BaselineCorrection, BoxcarFeature, IntegrationTimeFeature to ctl
    • docs and cleanup around ScrollStealFilter and MouseWheelFilter
    • simplified Configuration.save

@mzieg mzieg mentioned this pull request Oct 13, 2023
samiebee43 added a commit that referenced this pull request Oct 13, 2023
…rection and BoxcarFeature to ctl; registered GainDBFeature, IntegrationTimeFeature, BaselineCorrection, BoxcarFeature, RamanIntensityCorrection, ScanAveragingFeature to PresetFeature; snapshot commit, still in test
@mzieg mzieg marked this pull request as ready for review October 30, 2023 14:05
@mzieg mzieg changed the title Mzieg followup testing Presets, Plugin Updates and JCAMP-DX Oct 30, 2023
@mzieg mzieg requested a review from samiebee43 October 30, 2023 14:07
@samiebee43
Copy link
Contributor

samiebee43 commented Oct 30, 2023

Yes this is kind of a lot to review at once, but most of it looks good.

Two things stand out to me.

1. Deprecation of plugin dependencies

Appears to be a duplicate of #311 . This can be handled a number of ways, but it may be worthwhile to diff the two branches to see if they differ more than expected. One way to do this would be.

# should contain the largest set of filenames
git diff --name-only mzieg-followup-testing 4.1.0-dev

# should contain a strict subset of filenames, plugin related
git diff --name-only mzieg-4.1.0-plugin-features 4.1.0-dev

# should contain a strict subset of filenames, not plugin related
git diff --name-only mzieg-followup-testing mzieg-4.1.0-plugin-features

Overall, it's a non-issue. If both branches are good, then they can both be merged in any order and the whole thing should be fine, but it's a bit curious that such an overlap happened.

2. Preset Feature API

There's a nice comment that explains the preset feature's API.

class IntegrationTimeFeature:
    def __init__(self):
        ctl.presets.register(self, ["integration_time_ms"])
    def get_preset(self, attr):
        if attr == "integration_time_ms":
            return self.current_ms
    def set_preset(self, attr, value):
        if attr == "integration_time_ms":
            self.set_ms(int(value))

This looks pretty good, it handles situations where we need to do more than update a variable--for example modifying the GUI to match. This is not the soln I had in mind, but that's okay. The main thing I would suggest is to avoid passing attr's, and to explicitly state callbacks in the registration step. Also, avoid passing an array to register--rather call it multiple times.

class IntegrationTimeFeature:
    def __init__(self):
        ctl.presets.register(self, "integration_time_ms", get_integration_time, set_integration_time_ms)

    def get_integration_time_ms(self):
        return self.current_ms

   def set_integration_time_ms(self, value):
       value = int(value)
       # existing definition ... 

For completeness, the solution I had in mind would be to use resolution and search-paths. This would involve creating a parameter construct which represents the kinds of things that we might want to preset, persist, etc. Classes that depend on Enlighten Parameters access those values via a third party every time (kind of like how we access spec from multispec). Setting the value also uses the same third party. The parameter access routine will have some logic to decide whether to load the value from the .ini file, eeprom, a hardcoded default, or from the active preset. It requires that upon selecting a preset, that the GUI is updated to call in new resolutions for each parameter. Parameters perform validation and correction at access time.

class IntegrationTimeFearture:
    def __init__(self):
        pass

    def get_integration_time_ms(self):
        # update GUI if necessary
        # ...

        # get the parameter value, whether it's driven by config, preset, eeprom, etc
        return EnlightenParameters.resolve("integration_time_ms")
        

    def set_integration_time_ms(self, value):
         # save the parameter value, storing changes in config or preset as appropriate.
         EnlightenParameters.save("integration_time_ms", value)

         # update GUI if necessary
         # ...

Upon enabling a preset, we would need to make sure IntegrationTimeFeature is updated by calling get_integration_time_ms to get the latest decision from EnlightenParameters.

Copy link
Contributor

@samiebee43 samiebee43 left a comment

Choose a reason for hiding this comment

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

If this works we should merge it.

There are a lot of helpful changes that makes this seem like it should be the latest point in revision history.


Update, test results

  • Settings Presets section working
  • Local Baseline plugin working
  • Writing jcamp failed
image

I got jcamp using pip install jcamp instead of rebuilding my entire env... might that be the cause?

Copy link
Contributor

@samiebee43 samiebee43 left a comment

Choose a reason for hiding this comment

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

check jcamp save

@mzieg
Copy link
Member Author

mzieg commented Oct 30, 2023

check jcamp save

Can you expand on that? I have definitely saved many .dx files successfully...but that may be because I have ..\jcamp in my PYTHONPATH.

I'll add it to requirements.txt.

@mzieg
Copy link
Member Author

mzieg commented Oct 30, 2023

I'll add it to requirements.txt.

Actually...we should probably fork the version of jcamp that has writefile, and add it as a manual dependency...hmm.

@mzieg
Copy link
Member Author

mzieg commented Oct 30, 2023

class IntegrationTimeFearture:

Nice Halloween pun :-)

@mzieg
Copy link
Member Author

mzieg commented Oct 30, 2023

The main thing I would suggest is to avoid passing attr's, and to explicitly state callbacks in the registration step. Also, avoid passing an array to register--rather call it multiple times.

Updated.

@samiebee43
Copy link
Contributor

Thank you for including that suggestion.

Note: Not that this particularly matters, but the spelling is getter/setter not gettor/settor.

$ export PYTHONPATH=$PYTHONPATH:$PWD/jcamp

This note will be removed when frenchytheasian's pull request is merged into the
main jcamp distribution and released over PyPi.
Copy link
Contributor

Choose a reason for hiding this comment

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

OK. I was wrong, we should probably fork this and merge frenchy's branch to main on our fork.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mzieg
Copy link
Member Author

mzieg commented Nov 1, 2023

getter/setter not gettor/settor

TIL

@mzieg mzieg merged commit bf2a49b into 4.1.0-dev Nov 2, 2023
@mzieg mzieg deleted the mzieg-followup-testing branch November 2, 2023 14:02
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.

2 participants