Skip to content

Commit

Permalink
Updated sofastFringe examples to use Spatial Orientation object.
Browse files Browse the repository at this point in the history
  • Loading branch information
braden6521 committed Mar 29, 2024
1 parent 358ed5a commit de95ab2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
13 changes: 3 additions & 10 deletions example/sofast_fringe/example_process_facet_ensemble.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from os.path import join, dirname

import matplotlib

from opencsp.app.sofast.lib.DisplayShape import DisplayShape as Display
from opencsp.app.sofast.lib.DefinitionEnsemble import DefinitionEnsemble
from opencsp.app.sofast.lib.DefinitionFacet import DefinitionFacet
from opencsp.app.sofast.lib.ImageCalibrationScaling import ImageCalibrationScaling
from opencsp.app.sofast.lib.MeasurementSofastFringe import MeasurementSofastFringe
from opencsp.app.sofast.lib.ProcessSofastFringe import ProcessSofastFringe as Sofast
from opencsp.app.sofast.lib.SpatialOrientation import SpatialOrientation
from opencsp.app.sofast.lib.visualize_setup import visualize_setup
from opencsp.common.lib.camera.Camera import Camera
from opencsp.common.lib.csp.FacetEnsemble import FacetEnsemble
from opencsp.common.lib.deflectometry.Surface2DParabolic import Surface2DParabolic
Expand Down Expand Up @@ -39,13 +36,15 @@ def example(dir_save: str):
file_measurement = join(sample_data_dir, 'measurement_ensemble.h5')
file_camera = join(sample_data_dir, 'camera.h5')
file_display = join(sample_data_dir, 'display_distorted_2d.h5')
file_orientation = join(sample_data_dir, 'spatial_orientation.h5')
file_calibration = join(sample_data_dir, 'image_calibration.h5')
file_facet = join(sample_data_dir, 'Facet_lab_6x4.json')
file_ensemble = join(sample_data_dir, 'Ensemble_lab_6x4.json')

# Load data
camera = Camera.load_from_hdf(file_camera)
display = Display.load_from_hdf(file_display)
orientation = SpatialOrientation.load_from_hdf(file_orientation)
measurement = MeasurementSofastFringe.load_from_hdf(file_measurement)
calibration = ImageCalibrationScaling.load_from_hdf(file_calibration)
ensemble_data = DefinitionEnsemble.load_from_json(file_ensemble)
Expand All @@ -62,7 +61,7 @@ def example(dir_save: str):
measurement.calibrate_fringe_images(calibration)

# Instantiate sofast object
sofast = Sofast(measurement, camera, display)
sofast = Sofast(measurement, orientation, camera, display)

# Update search parameters
sofast.params.mask_hist_thresh = 0.83
Expand All @@ -88,12 +87,6 @@ def example(dir_save: str):
mirror_control = rcm.RenderControlMirror(centroid=True, surface_normals=True, norm_res=1)
axis_control_m = rca.meters()

# Visualize setup
fig_record = fm.setup_figure_for_3d_data(figure_control, axis_control_m, title='')
spatial_ori: SpatialOrientation = sofast.data_geometry_facet[0].spatial_orientation
visualize_setup(display, camera, spatial_ori.v_screen_optic_screen, spatial_ori.r_optic_screen, ax=fig_record.axis)
fig_record.save(dir_save, 'physical_setup_layout', 'png')

# Plot scenario
fig_record = fm.setup_figure_for_3d_data(figure_control, axis_control_m, title='Facet Ensemble')
ensemble.draw(fig_record.view, mirror_control)
Expand Down
13 changes: 3 additions & 10 deletions example/sofast_fringe/example_process_single_facet.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from os.path import join, dirname

import matplotlib

from opencsp.app.sofast.lib.DisplayShape import DisplayShape as Display
from opencsp.app.sofast.lib.DefinitionFacet import DefinitionFacet
from opencsp.app.sofast.lib.ImageCalibrationScaling import ImageCalibrationScaling
from opencsp.app.sofast.lib.MeasurementSofastFringe import MeasurementSofastFringe
from opencsp.app.sofast.lib.ProcessSofastFringe import ProcessSofastFringe as Sofast
from opencsp.app.sofast.lib.SpatialOrientation import SpatialOrientation
from opencsp.app.sofast.lib.visualize_setup import visualize_setup
from opencsp.common.lib.camera.Camera import Camera
from opencsp.common.lib.csp.Facet import Facet
from opencsp.common.lib.deflectometry.Surface2DParabolic import Surface2DParabolic
Expand Down Expand Up @@ -36,12 +33,14 @@ def example(dir_save: str):
file_measurement = join(sample_data_dir, 'measurement_facet.h5')
file_camera = join(sample_data_dir, 'camera.h5')
file_display = join(sample_data_dir, 'display_distorted_2d.h5')
file_orientation = join(sample_data_dir, 'spatial_orientation.h5')
file_calibration = join(sample_data_dir, 'image_calibration.h5')
file_facet = join(sample_data_dir, 'Facet_NSTTF.json')

# Load data
camera = Camera.load_from_hdf(file_camera)
display = Display.load_from_hdf(file_display)
orientation = SpatialOrientation.load_from_hdf(file_orientation)
measurement = MeasurementSofastFringe.load_from_hdf(file_measurement)
calibration = ImageCalibrationScaling.load_from_hdf(file_calibration)
facet_data = DefinitionFacet.load_from_json(file_facet)
Expand All @@ -53,7 +52,7 @@ def example(dir_save: str):
measurement.calibrate_fringe_images(calibration)

# Instantiate sofast object
sofast = Sofast(measurement, camera, display)
sofast = Sofast(measurement, orientation, camera, display)

# Process
sofast.process_optic_singlefacet(facet_data, surface)
Expand All @@ -70,12 +69,6 @@ def example(dir_save: str):
figure_control = rcfg.RenderControlFigure(tile_array=(1, 1), tile_square=True)
axis_control_m = rca.meters()

# Visualize setup
fig_record = fm.setup_figure_for_3d_data(figure_control, axis_control_m, title='')
spatial_ori: SpatialOrientation = sofast.data_geometry_facet[0].spatial_orientation
visualize_setup(display, camera, spatial_ori.v_screen_optic_screen, spatial_ori.r_optic_screen, ax=fig_record.axis)
fig_record.save(dir_save, 'physical_setup_layout', 'png')

# Plot slope map
fig_record = fm.setup_figure(figure_control, axis_control_m, title='')
facet.plot_orthorectified_slope(res=0.002, clim=7, axis=fig_record.axis)
Expand Down
15 changes: 4 additions & 11 deletions example/sofast_fringe/example_process_undefined_shape.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from os.path import join, dirname

import matplotlib

from opencsp.app.sofast.lib.visualize_setup import visualize_setup
from opencsp.app.sofast.lib.ImageCalibrationScaling import ImageCalibrationScaling
from opencsp.app.sofast.lib.MeasurementSofastFringe import MeasurementSofastFringe
from opencsp.app.sofast.lib.ProcessSofastFringe import ProcessSofastFringe as Sofast
Expand Down Expand Up @@ -35,11 +32,13 @@ def example(dir_save):
file_measurement = join(sample_data_dir, 'measurement_facet.h5')
file_camera = join(sample_data_dir, 'camera.h5')
file_display = join(sample_data_dir, 'display_distorted_2d.h5')
file_orientation = join(sample_data_dir, 'spatial_orientation.h5')
file_calibration = join(sample_data_dir, 'image_calibration.h5')

# Load data
camera = Camera.load_from_hdf(file_camera)
display = Display.load_from_hdf(file_display)
orientation = SpatialOrientation.load_from_hdf(file_orientation)
measurement = MeasurementSofastFringe.load_from_hdf(file_measurement)
calibration = ImageCalibrationScaling.load_from_hdf(file_calibration)

Expand All @@ -50,7 +49,7 @@ def example(dir_save):
measurement.calibrate_fringe_images(calibration)

# Instantiate sofast object
sofast = Sofast(measurement, camera, display)
sofast = Sofast(measurement, orientation, camera, display)
sofast.params.mask_keep_largest_area = True

# Process
Expand All @@ -68,12 +67,6 @@ def example(dir_save):
figure_control = rcfg.RenderControlFigure(tile_array=(1, 1), tile_square=True)
axis_control_m = rca.meters()

# Visualize setup
fig_record = fm.setup_figure_for_3d_data(figure_control, axis_control_m, title='')
spatial_ori: SpatialOrientation = sofast.data_geometry_facet[0].spatial_orientation
visualize_setup(display, camera, spatial_ori.v_screen_optic_screen, spatial_ori.r_optic_screen, ax=fig_record.axis)
fig_record.save(dir_save, 'physical_setup_layout', 'png')

# Plot slope map
fig_record = fm.setup_figure(figure_control, axis_control_m, title='')
facet.plot_orthorectified_slope(res=0.002, clim=7, axis=fig_record.axis)
Expand All @@ -85,7 +78,7 @@ def example(dir_save):

def example_driver():
# Define save dir
save_path = join(dirname(__file__), 'data/output/single_facet')
save_path = join(dirname(__file__), 'data/output/undefined_shape')
ft.create_directories_if_necessary(save_path)

# Set up logger
Expand Down

0 comments on commit de95ab2

Please sign in to comment.