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

Image refactoring #214

Merged
merged 16 commits into from
Dec 4, 2024
Merged

Image refactoring #214

merged 16 commits into from
Dec 4, 2024

Conversation

roussel-ryan
Copy link
Collaborator

refactor image processing and fitting class to be more general / easier to debug

  • creates a base ImageFit abstract class that contains image validation and allows for subclasses to modify the image fitting method
  • implements the ImageProjectionFit subclass that uses the ProjectionFit class to fit the x/y projections
  • moves all image processing into a single call inside the ImageProcessing class
  • replaces object properties with explicit calls to functions that do computation
  • makes MethodBase a pydantic class that also contains use_priors field to specify the use of priors instead of using a field in ProjectionFit to specify this (defaults to false)

…er to debug

- creates a base ImageFit abstract class that contains image validation and allows for subclasses to modify the image fitting method
- implements the ImageProjectionFit subclass that uses the ProjectionFit class to fit the x/y projections
- moves all image processing into a single call inside the ImageProcessing class
- replaces object properties with explicit calls to functions that do computation
- makes MethodBase a pydantic class that also contains `use_priors` field to specify the use of priors instead of using a field in ProjectionFit to specify this (defaults to false)
@nneveu
Copy link
Member

nneveu commented Nov 27, 2024

Theres a similar PR draft open on this? Do you want to combine?

@roussel-ryan
Copy link
Collaborator Author

Are you referring to #199 ?

@nneveu
Copy link
Member

nneveu commented Nov 27, 2024

I was thinking of #128. Maybe that's too old enough we want to just close it?

@roussel-ryan
Copy link
Collaborator Author

Yes, that PR is out of date, we should close it

@roussel-ryan roussel-ryan marked this pull request as ready for review December 2, 2024 16:18
@nneveu nneveu requested a review from eloiseyang December 2, 2024 19:34
Copy link
Collaborator

@eloiseyang eloiseyang left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. My main question for everyone is whether or not the bounding box penalty is useful in the general case. I think LCLS-Tools should be a general code base for physics and HLA applications that integrates easily with ML applications, but shouldn't include automation in its foundation. In my view, base class ImageFit should just package fitting with the relevant output parameters for a fit, and validation can occur in a class extending ImageFit.

If you have other thoughts, let me know. I'm open to discussion. Thanks again!

from matplotlib import pyplot as plt, patches


def plot_image_projection_fit(fit_object, results, n_stds=3):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see this is in the plotting folder, but the other files in this folder appear to be more for PyDM integration than generic plotting. I remember we decided not to include plotting functions while I was merging Chris G's contributions. @nneveu any thoughts?

@roussel-ryan
Copy link
Collaborator Author

thanks for the comments @eloiseyang, I'm working on removing the bounding box stuff now and will update the PR tomorrow morning

Copy link
Collaborator

@eloiseyang eloiseyang left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, looks good to me.

Looks like a test in test_sc_cryomodule.py is failing, though you didn't change that one in a way that would make the test fail. It looks like the test here picks a random cryomodule to verify. It probably passed once by chance, but is failing again. I'll take a look myself and let you know.

Edit:

I found the issue, there's two unexpected leading whitespaces in dictionary keys in the test tests/unit_tests/lcls_tools/superconducting/test_sc_cryomodule.py.

self.assertTrue(
hl.is_harmonic_linearizer, msg=f"{hl} is_harmonic_linearizer is not true"
)

def test_is_harmonic_linearizer_false(self):
cm = MACHINE.cryomodules[f"{randint(1, 35):02d}"]
cm = MACHINE.cryomodules[f"{randint(1, 35): 02d}"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

There shouldn't be a space between the colon and the number here. This changes the format string from
01 to 01. The dictionary MACHINE.cryomodules doesn't expect a leading space in its key names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok I addressed it, lets see if the tests pass

@@ -22,5 +22,5 @@ def test_pv_prefix(self):
self.assertEqual(cm.pv_prefix, "ACCL:L0B:0100:")

def test_num_cavities(self):
cm = MACHINE.cryomodules[f"{randint(1, 35):02d}"]
cm = MACHINE.cryomodules[f"{randint(1, 35): 02d}"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, there's one more down the line I didn't point out. I think the test will pass after this change.

@roussel-ryan roussel-ryan merged commit 91e650e into main Dec 4, 2024
3 checks passed
@roussel-ryan roussel-ryan deleted the image_refactoring branch February 18, 2025 20:23
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.

3 participants