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

Sofast Fixed multi facet capability #164

Merged
merged 54 commits into from
Oct 9, 2024

Conversation

braden6521
Copy link
Collaborator

@braden6521 braden6521 commented Aug 22, 2024

  • Added a multi-facet measurement capability to Sofast Fixed
  • Created an abstract processing class for ProcessSofastFixed and ProcessSofastFringe

NOTE:

Depends on #163.

@braden6521 braden6521 self-assigned this Aug 29, 2024
@braden6521 braden6521 added the enhancement New feature or request label Aug 29, 2024
@braden6521 braden6521 marked this pull request as ready for review August 29, 2024 23:14
Copy link
Collaborator

@e10harvey e10harvey left a comment

Choose a reason for hiding this comment

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

Thank you, @braden6521! My main concerns are the absence of bounds checks on facet indices and cleaning some of the constant values up with self documenting variables / enums.

@@ -74,7 +74,7 @@ def generate_dataset(

# Show slope map
mask = sofast.data_image_processing_facet[0].mask_processed
slopes_xy = sofast.data_characterization_facet[0].slopes_facet_xy
slopes_xy = sofast.data_calculation_facet[0].slopes_facet_xy
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: make 0 a Final (https://docs.python.org/3/library/typing.html#typing.Final) local variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Never heard of Final before. That's cool, thanks for the suggestion.

@@ -74,7 +74,7 @@ def generate_dataset(

# Show slope map
mask = sofast.data_image_processing_facet[0].mask_processed
slopes_xy = sofast.data_characterization_facet[0].slopes_facet_xy
slopes_xy = sofast.data_calculation_facet[0].slopes_facet_xy
slopes = np.sqrt(np.sum(slopes_xy**2, 0))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: same as above for 2

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This looks like a duplicate of above?

# ensemble.plot_orthorectified_slope(res=0.002, clim=7, axis=fig_record.axis)
# fig_record.save(dir_save, 'slope_magnitude', 'png')
fig_record = fm.setup_figure(figure_control, axis_control_m, title='')
ensemble.plot_orthorectified_slope(res=0.002, clim=7, axis=fig_record.axis)
Copy link
Collaborator

Choose a reason for hiding this comment

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

unless self-explanatory for a SME please add some docs or self documenting variables for the "0.002" and "7" magic values

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good comment. Documented.

@@ -145,7 +145,7 @@ def example_process_facet_ensemble():
# 3. Log best-fit parabolic focal lengths
# =======================================
for idx in range(sofast.num_facets):
surf_coefs = sofast.data_characterization_facet[idx].surf_coefs_facet
surf_coefs = sofast.data_calculation_facet[idx].surf_coefs_facet
focal_lengths_xy = [1 / 4 / surf_coefs[2], 1 / 4 / surf_coefs[5]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: more magic numbers 1,4,2,5

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

@@ -47,6 +48,8 @@ def __init__(self, points: Vxy, x_min: int, x_max: int, y_min: int, y_max: int)
self._neighbor_dists = np.zeros((self._num_pts, 4)) * np.nan # left, right, up, down

self.search_thresh = 5.0 # pixels
self.max_num_iters: int = 100
Copy link
Collaborator

Choose a reason for hiding this comment

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

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 the comment. These values will likely be updated by the user, so I didn't make them Final. However, they were in desperate need of documentation. I added documentation inline and in the module docstring.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, if these are defaults will the default values be obvious to the user? If not, please add the default to the doc string such as: "(default: 100)".

@@ -206,69 +205,3 @@ def draw(self, view: View3d, facet_style: RenderControlFacet = None, transform:

if facet_style.draw_mirror_curvature:
self.mirror.draw(view, facet_style.mirror_styles, transform * self.mirror._self_to_parent_transform)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for removing these unverified methods

# Get all mirror region vertices
points_xy = Pxy.merge([loop.vertices for loop in facet.mirror.region.loops]) # mirror frame
points_z = facet.mirror.surface_displacement_at(points_xy) # mirror frame
# If the corners aren't in range of the mirror's interpolation function, set to 0
if np.any(np.isnan(points_z)):
lt.warn(f'Could not find corner z values for facet number {facet_idx:d}; filling with zeros.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
lt.warn(f'Could not find corner z values for facet number {facet_idx:d}; filling with zeros.')
lt.warn(f'Could not find corner z values for facet number {facet_idx:03d}; filling with zeros.')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Change made.

while searcher._self_to_parent_transform is not None:
if searcher is target:
return transform
while searcher.parent is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider filing a follow-on issue if these linear searches are expected to be a bottleneck

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good. As we use this capability more, I will keep this in mind.

@@ -0,0 +1,18 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider filing a follow-on issue to randomly generate this test data at runtime.

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 still do not fully understand how to use random numbers in tests. Any suggestions?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's discuss this. Even if it is a more robust test, it may not be straight forward or practical to generate random values.

@@ -0,0 +1,10 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same comment as above. These specific JSON files define the physical shape of the facet being measured. But if there is more opportunity to use randomness in these tests, I could implement it.

# ensemble.plot_orthorectified_slope(res=0.002, clim=7, axis=fig_record.axis)
# fig_record.save(dir_save, 'slope_magnitude', 'png')
res = 0.002 # meter, make the plot with 2mm spatial resolution
clim = 7 # mrad, draw the plot with +/-7mrad scale bars, this mirror has erorrs that extent to about +/-7mrad
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
clim = 7 # mrad, draw the plot with +/-7mrad scale bars, this mirror has erorrs that extent to about +/-7mrad
clim = 7 # mrad, draw the plot with +/-7mrad scale bars, this mirror has erorrs that extend to about +/-7mrad

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch 🤦‍♂️

@@ -47,6 +48,8 @@ def __init__(self, points: Vxy, x_min: int, x_max: int, y_min: int, y_max: int)
self._neighbor_dists = np.zeros((self._num_pts, 4)) * np.nan # left, right, up, down

self.search_thresh = 5.0 # pixels
self.max_num_iters: int = 100
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, if these are defaults will the default values be obvious to the user? If not, please add the default to the doc string such as: "(default: 100)".


# Facet definition
if self.data_facet_def is not None:
for idx_facet, facet_data in enumerate(self.data_facet_def):
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you anticipate any bugs related to values larger than 999, I would strongly suggest adding a bounds check where appropriate to ensure that that largest facet index does not exceed 999, and, if it does, throw an exception stating that this is not permitted. I confirmed that the width specifier does not truncate values larger than 999 in the f-strings, so that should be fine.

@@ -0,0 +1,18 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's discuss this. Even if it is a more robust test, it may not be straight forward or practical to generate random values.

@e10harvey e10harvey merged commit 3fda296 into sandialabs:develop Oct 9, 2024
4 checks passed
@braden6521 braden6521 deleted the sofast_fixed_multi branch December 6, 2024 18:31
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