Skip to content

Commit

Permalink
Merge pull request #31 from braden6521/surface_params
Browse files Browse the repository at this point in the history
Merging changes to Sofast HDF5 IO interface.
  • Loading branch information
braden6521 authored Mar 20, 2024
2 parents 3838295 + 19afc0c commit 5c3a408
Show file tree
Hide file tree
Showing 21 changed files with 468 additions and 400 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import os
from os.path import join
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 as Measurement,
)
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.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.SpatialOrientation import SpatialOrientation
from opencsp.common.lib.deflectometry.Surface2DParabolic import Surface2DParabolic
from opencsp.common.lib.opencsp_path.opencsp_root_path import opencsp_code_dir
import opencsp.common.lib.render.figure_management as fm
import opencsp.common.lib.render_control.RenderControlAxis as rca
import opencsp.common.lib.render_control.RenderControlFigure as rcfg
import opencsp.common.lib.render_control.RenderControlMirror as rcm
import opencsp.common.lib.tool.log_tools as lt
import opencsp.common.lib.tool.file_tools as ft


def example_driver():
Expand All @@ -44,9 +46,11 @@ def example_driver():
file_ensemble = join(sample_data_dir, 'Ensemble_lab_6x4.json')

# Define save dir
dir_save = join(os.path.dirname(__file__), 'data/output/facet_ensemble')
if not os.path.exists(dir_save):
os.makedirs(dir_save)
dir_save = join(dirname(__file__), 'data/output/facet_ensemble')
ft.create_directories_if_necessary(dir_save)

# Set up logger
lt.logger(join(dir_save, 'log.txt'))

# Load data
camera = Camera.load_from_hdf(file_camera)
Expand All @@ -58,12 +62,9 @@ def example_driver():
# Define facet data
facet_data = [DefinitionFacet.load_from_json(file_facet)] * ensemble_data.num_facets

# Define surface data (plano)
# surface_data = [dict(surface_type='plano', robust_least_squares=False, downsample=20)] * ensemble_data.num_facets
# Define surface data (parabolic)
# Define surface data
surface_data = [
dict(
surface_type='parabolic',
Surface2DParabolic(
initial_focal_lengths_xy=(100.0, 100.0),
robust_least_squares=False,
downsample=20,
Expand All @@ -88,12 +89,10 @@ def example_driver():

# Calculate focal length from parabolic fit
for idx in range(sofast.num_facets):
if surface_data[idx]['surface_type'] == 'parabolic':
surf_coefs = sofast.data_characterization_facet[idx].surf_coefs_facet
focal_lengths_xy = [1 / 4 / surf_coefs[2], 1 / 4 / surf_coefs[5]]
print('Parabolic fit focal lengths:')
print(f' X {focal_lengths_xy[0]:.3f} m')
print(f' Y {focal_lengths_xy[1]:.3f} m')
surf_coefs = sofast.data_characterization_facet[idx].surf_coefs_facet
focal_lengths_xy = [1 / 4 / surf_coefs[2], 1 / 4 / surf_coefs[5]]
lt.info(f'Facet {idx:d} xy focal lengths (meters): '
f'{focal_lengths_xy[0]:.3f}, {focal_lengths_xy[1]:.3f}')

# Get optic representation
ensemble: FacetEnsemble = sofast.get_optic()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import os
from os.path import join
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 as Measurement,
)
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.app.sofast.lib.DisplayShape import DisplayShape as Display
from opencsp.app.sofast.lib.DefinitionFacet import DefinitionFacet
from opencsp.app.sofast.lib.SpatialOrientation import SpatialOrientation
from opencsp.common.lib.deflectometry.Surface2DParabolic import Surface2DParabolic
from opencsp.common.lib.opencsp_path.opencsp_root_path import opencsp_code_dir
import opencsp.common.lib.render.figure_management as fm
import opencsp.common.lib.render_control.RenderControlAxis as rca
import opencsp.common.lib.render_control.RenderControlFigure as rcfg
import opencsp.common.lib.tool.log_tools as lt
import opencsp.common.lib.tool.file_tools as ft


def example_driver():
Expand All @@ -40,9 +42,11 @@ def example_driver():
file_facet = join(sample_data_dir, 'Facet_NSTTF.json')

# Define save dir
dir_save = join(os.path.dirname(__file__), 'data/output/single_facet')
if not os.path.exists(dir_save):
os.makedirs(dir_save)
dir_save = join(dirname(__file__), 'data/output/single_facet')
ft.create_directories_if_necessary(dir_save)

# Set up logger
lt.logger(join(dir_save, 'log.txt'))

# Load data
camera = Camera.load_from_hdf(file_camera)
Expand All @@ -52,9 +56,8 @@ def example_driver():
facet_data = DefinitionFacet.load_from_json(file_facet)

# Define surface definition (parabolic surface)
surface_data = dict(
surface_type='parabolic',
initial_focal_lengths_xy=(300.0, 300),
surface = Surface2DParabolic(
initial_focal_lengths_xy=(300., 300.),
robust_least_squares=True,
downsample=10,
)
Expand All @@ -66,15 +69,13 @@ def example_driver():
sofast = Sofast(measurement, camera, display)

# Process
sofast.process_optic_singlefacet(facet_data, surface_data)
sofast.process_optic_singlefacet(facet_data, surface)

# Calculate focal length from parabolic fit
if surface_data['surface_type'] == 'parabolic':
surf_coefs = sofast.data_characterization_facet[0].surf_coefs_facet
focal_lengths_xy = [1 / 4 / surf_coefs[2], 1 / 4 / surf_coefs[5]]
print('Parabolic fit focal lengths:')
print(f' X {focal_lengths_xy[0]:.3f} m')
print(f' Y {focal_lengths_xy[1]:.3f} m')
surf_coefs = sofast.data_characterization_facet[0].surf_coefs_facet
focal_lengths_xy = [1 / 4 / surf_coefs[2], 1 / 4 / surf_coefs[5]]
lt.info(f'Facet xy focal lengths (meters): '
f'{focal_lengths_xy[0]:.3f}, {focal_lengths_xy[1]:.3f}')

# Get optic representation
facet: Facet = sofast.get_optic()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from os.path import join
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
Expand All @@ -11,10 +12,13 @@
from opencsp.app.sofast.lib.SpatialOrientation import SpatialOrientation
from opencsp.common.lib.camera.Camera import Camera
from opencsp.common.lib.csp.Facet import Facet
from opencsp.common.lib.deflectometry.Surface2DParabolic import Surface2DParabolic
from opencsp.common.lib.opencsp_path.opencsp_root_path import opencsp_code_dir
import opencsp.common.lib.render.figure_management as fm
import opencsp.common.lib.render_control.RenderControlAxis as rca
import opencsp.common.lib.render_control.RenderControlFigure as rcfg
import opencsp.common.lib.tool.log_tools as lt
import opencsp.common.lib.tool.file_tools as ft


def example_driver():
Expand All @@ -36,9 +40,11 @@ def example_driver():
file_calibration = join(sample_data_dir, 'image_calibration.h5')

# Save directory
dir_save = join(os.path.dirname(__file__), 'data/output/undefined_facet')
if not os.path.exists(dir_save):
os.makedirs(dir_save)
dir_save = join(dirname(__file__), 'data/output/undefined_facet')
ft.create_directories_if_necessary(dir_save)

# Set up logger
lt.logger(join(dir_save, 'log.txt'))

# Load data
camera = Camera.load_from_hdf(file_camera)
Expand All @@ -47,9 +53,8 @@ def example_driver():
calibration = ImageCalibrationScaling.load_from_hdf(file_calibration)

# Define surface definition (parabolic surface)
surface_data = dict(
surface_type='parabolic',
initial_focal_lengths_xy=(300.0, 300),
surface = Surface2DParabolic(
initial_focal_lengths_xy=(300., 300.),
robust_least_squares=True,
downsample=10,
)
Expand All @@ -62,15 +67,13 @@ def example_driver():
sofast.params.mask_keep_largest_area = True

# Process
sofast.process_optic_undefined(surface_data)
sofast.process_optic_undefined(surface)

# Calculate focal length from parabolic fit
if surface_data['surface_type'] == 'parabolic':
surf_coefs = sofast.data_characterization_facet[0].surf_coefs_facet
focal_lengths_xy = [1 / 4 / surf_coefs[2], 1 / 4 / surf_coefs[5]]
print('Parabolic fit focal lengths:')
print(f' X {focal_lengths_xy[0]:.3f} m')
print(f' Y {focal_lengths_xy[1]:.3f} m')
surf_coefs = sofast.data_characterization_facet[0].surf_coefs_facet
focal_lengths_xy = [1 / 4 / surf_coefs[2], 1 / 4 / surf_coefs[5]]
lt.info(f'Facet xy focal lengths (meters): '
f'{focal_lengths_xy[0]:.3f}, {focal_lengths_xy[1]:.3f}')

# Get optic representation
facet: Facet = sofast.get_optic()
Expand Down
Binary file not shown.
Loading

0 comments on commit 5c3a408

Please sign in to comment.