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

43 sofast as a service #61

Merged
merged 9 commits into from
Apr 2, 2024
Merged

Conversation

bbean23
Copy link
Collaborator

@bbean23 bbean23 commented Mar 29, 2024

This is part 1 of 2, which extracts pieces of the SofastGUI into another class. The goal is to have a common interface to Sofast, which can be wrapped with other GUIs, scripts, or web interfaces.

closes #43
to be continued in #60

@bbean23 bbean23 added the enhancement New feature or request label Mar 29, 2024
@bbean23 bbean23 requested a review from braden6521 March 29, 2024 18:32
@bbean23 bbean23 self-assigned this Mar 29, 2024
@bbean23 bbean23 mentioned this pull request Mar 29, 2024
@bbean23
Copy link
Collaborator Author

bbean23 commented Mar 29, 2024

In order to more easily view the pieces pulled out of SofastGUI into SofastService, I've also created PR #62

@bbean23 bbean23 force-pushed the 43-sofast-as-a-service branch 2 times, most recently from e92357f to b720656 Compare March 29, 2024 18:59
@@ -133,6 +111,17 @@ def _plot_image(self, ax: plt.Axes, image: np.ndarray, title: str = '', xlabel:
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)

@functools.cached_property
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a cool decorator, didn't know that existed!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right?! Pretty nifty. Also extremely susceptible to bugs if not used with care since by definition it produces hidden side effects.

self.service.run_gray_levels_cal(
calibration_class=cal_type,
calibration_hdf5_path_name_ext=file,
on_calibrating=on_calibrating,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe the input "on_calibrating" should be "on_captured," (or the other way around). It doesn't look like SofastService doesn't have an "on_calibrating" input.

Suggested change
on_calibrating=on_calibrating,
on_captured=on_calibrating,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know how you even saw this. Nice catch! Thanks!

def load_gray_levels_cal(self, hdf5_file_path_name_ext: str) -> None:
"""Loads saved results of a projector-camera intensity calibration"""
# Load file
cal_type = h5.load_hdf5_datasets(['Calibration/calibration_type'], hdf5_file_path_name_ext)['calibration_type']
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is 100% my error that got propagated (I don't use the "Load Gray Levels" button very often apparently). But the ImageCalibration class actually saves/loads to HDF files as "ImageCalibration/calibration_type".
See:

datasets = ['ImageCalibration/calibration_type']

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. Fixed!

@braden6521
Copy link
Collaborator

@bbean23, these improvements look great! There are just a couple bugs I found; if you could address those when you get a chance that would be great.

Not necessary for this PR, but this reminds me of something that I've been meaning to bring up with everyone. SofastGUI, since it is a GUI, isn't unit-tested. Is there a way to do this? If not, should it live in the opencsp/... folder or somewhere else? (putting it in contrib/ doesn't feel right, so IDK). Let me know what you think, but no action necessary for this PR.

@braden6521
Copy link
Collaborator

@bbean23, I had some thoughts about SofastService.py. This is a bit late into your development, so sorry I didn't think of this earlier. Also feel free to disregard, this is just something to think about.

  1. Do we want to consider naming SofastService.py to SofastFringeService.py because it is specific to SofastFringe (as opposed to SofastFixed?)
  2. Is it worth considering merging SofastService.py and SystemSofastFringe.py into one class? I say this because it feels like there is a lot in common between the two classes. You are more knowledgeable about SofastService and you future plans for it, however, so it is totally your call. Another option which might be a better idea (also totally up to you but the more I think about it, the more I think this should happen) is to merge parts of SofastService into SystemSofastFringe. For example, SofastService.run_gray_levels_cal() kinda seems like it belongs in SystemSofastFringe because functions like capture_fringe_images() and run_camera_exposure_calibration() already live in SystemSofastFringe. (Which would totally be my fault because I originally put run_gray_levels_cal() in SofastGUI for some reason).

@bbean23
Copy link
Collaborator Author

bbean23 commented Apr 1, 2024

@bbean23, I had some thoughts about SofastService.py. This is a bit late into your development, so sorry I didn't think of this earlier. Also feel free to disregard, this is just something to think about.

1. Do we want to consider naming SofastService.py to SofastFringeService.py because it is specific to SofastFringe (as opposed to SofastFixed?)

2. Is it worth considering merging SofastService.py and SystemSofastFringe.py into one class? I say this because it feels like there is a lot in common between the two classes. You are more knowledgeable about SofastService and you future plans for it, however, so it is totally your call. Another option which might be a better idea (also totally up to you but the more I think about it, the more I think this should happen) is to merge parts of SofastService into SystemSofastFringe. For example, `SofastService.run_gray_levels_cal()` kinda seems like it belongs in SystemSofastFringe because functions like `capture_fringe_images()` and `run_camera_exposure_calibration()` already live in SystemSofastFringe. (Which would totally be my fault because I originally put `run_gray_levels_cal()` in SofastGUI for some reason).

[4:05 PM] Ben
So starting with 1:

I was also considering this. Ideally SofastService will apply to both SofastFringe and SofastFixed so that it can be a singular interface to the various Sofast algorithms, but maybe that is the wrong way to think about it.

What do you think?

[4:08 PM] Braden

Yeah, that would be great if it applied to both actually. If that's the vision for it, then I'd agree it should remain SofastService.py.

[4:20 PM] Ben
Cool. And you know, maybe later we'll decide differently and have to refactor haha

Now for 2:

Would it be better to put those methods (run_gray_levels_cal) in SofastSystemFringe now, or when SofastService is extended to also work with SofastSystemFixed?

I'd say that if there is a method that is specific to SofastSystemFringe or SofastSystemFixed, then that method should go in that class. I haven't worked with SofastSystemFixed yet, but I'm assuming it doesn't have a gray levels calibration?

[4:28 PM] Braden
Hmm, I'd say whatever is easiest for you right now. The more I'm thinking about it, the more I think that run_gray_levels_cal() should have been in SystemSofastFringe all along. And yes, it's not needed for SofastFixed, only SofastFringe, so I think it's save to say it doesn't belong in SofastService. If it doesn't mess up your momentum too much, I'd vote for moving it now.

[4:29 PM] Ben
Sounds good. I'll go ahead and integrate that change

@bbean23
Copy link
Collaborator Author

bbean23 commented Apr 2, 2024

@braden6521 I made some changes while I was writing unit tests. Will you please take a look at them? They're all in the commit 7edc3e1. Thanks!

@bbean23 bbean23 force-pushed the 43-sofast-as-a-service branch from 7edc3e1 to 79653ba Compare April 2, 2024 02:08
Copy link
Collaborator

@braden6521 braden6521 left a comment

Choose a reason for hiding this comment

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

@bbean23, this all looks good; approved!
I even gave it a test in the optics lab today and everything seems to be working fine.

@bbean23 bbean23 force-pushed the 43-sofast-as-a-service branch from 79653ba to 4010a60 Compare April 2, 2024 18:42
@bbean23
Copy link
Collaborator Author

bbean23 commented Apr 2, 2024

Thanks for the review, Braden! I just rebased on top of develop and will merge once the checks are completed.

@bbean23 bbean23 merged commit 3bc6dbe into sandialabs:develop Apr 2, 2024
4 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants