Skip to content

Commit

Permalink
collecting all the infos for the config. this refs #234
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed Dec 6, 2024
1 parent cc61fcf commit f2448ae
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ibeatles/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "7.1.0.dev1+d202409172024"
__version__ = "7.1.0.dev99+d202412061910"
2 changes: 1 addition & 1 deletion src/ibeatles/session/session_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def save_to_file(self, config_file_name=None):

if config_file_name:
output_file_name = config_file_name
session_dict = self.parent.session_dict
session_dict = self.session_dict

with open(output_file_name, "w") as json_file:
json.dump(session_dict, json_file)
Expand Down
136 changes: 136 additions & 0 deletions src/ibeatles/step6/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from NeuNorm.normalization import Normalization

from src.ibeatles.session import SessionKeys, SessionSubKeys
from src.ibeatles import DataType, FileType
from src.ibeatles.step6 import ParametersToDisplay
from src.ibeatles.step6.get import Get
Expand All @@ -15,6 +16,7 @@
from src.ibeatles.utilities.export import format_kropff_dict, format_kropff_table
from src.ibeatles.utilities.get import Get as UtilitiesGet
from src.ibeatles.fitting import FittingKeys
from src.ibeatles.utilities.time import get_current_time_in_special_file_name_format


class Export:
Expand Down Expand Up @@ -335,3 +337,137 @@ def hdf5(self, output_folder: str = None):
"integrated normalized radiographs"
)
integrated_image_group.create_dataset("2D array", data=integrated_image)

def config_for_cli(self, output_folder: str = None):

_current_time = get_current_time_in_special_file_name_format()

output_folder = os.path.abspath(output_folder)
output_file_name = create_full_export_file_name(
os.path.join(output_folder, f"config_{_current_time}"), FileType.json
)

logging.info(
f"Exporting configuration to be used by the command line version (CLI) -> {output_file_name}"
)

# o_get = Get(parent=self.parent)
# strain_mapping_dict = o_get.strain_mapping_dictionary()

session_dict = self.parent.session_dict

raw_data_dir = session_dict[DataType.sample][SessionSubKeys.current_folder]
_, raw_data_extension = os.path.splitext(session_dict[DataType.sample][SessionSubKeys.list_files][0])

open_beam_data_dir = session_dict[DataType.ob][SessionSubKeys.current_folder]
open_beam_data_extension = raw_data_extension

list_normalization_roi = session_dict[DataType.normalization][SessionSubKeys.roi]
normalization_sample_background = []
for _roi in list_normalization_roi:
_state, x0, y0, width, height, _type = _roi
if (type == 'background') and _state:
normalization_sample_background.append({"x0": x0, "y0": y0,
"width": width, "height": height})

moving_average_active = session_dict[SessionKeys.reduction][SessionSubKeys.activate]
moving_average_dimension = session_dict[SessionKeys.reduction][SessionSubKeys.dimension]
moving_average_size = {'y': session_dict[SessionKeys.reduction][SessionSubKeys.size]["y"],
'x': session_dict[SessionKeys.reduction][SessionSubKeys.size]["x"]}
if moving_average_dimension == '3D':
moving_average_size['z'] = session_dict[SessionKeys.reduction][SessionSubKeys.size["z"]]

moving_average_type = session_dict[SessionKeys.reduction][SessionSubKeys.type]

if session_dict[SessionKeys.reduction][SessionSubKeys.process_order] == 'option1':
processing_order = "Moving average, Normalization"
else:
processing_order = "Normalization, Moving average"

analysis_material_element = self.parent.ui.material_name.text()

pixel_binning = {'x0': session_dict[SessionKeys.bin][SessionSubKeys.roi[1]],
'y0': session_dict[SessionKeys.bin][SessionSubKeys.roi[2]],
'width': session_dict[SessionKeys.bin][SessionSubKeys.roi[3]],
'height': session_dict[SessionKeys.bin][SessionSubKeys.roi[4]],
'bin_size': session_dict[SessionKeys.bin][SessionSubKeys.roi[5]],
}

fitting_lambda_range = session_dict[SessionKeys.fitting][SessionSubKeys.lambda_range_index]
x_axis = session_dict[SessionKeys.fitting][SessionSubKeys.x_axis]
lambda_min = x_axis[fitting_lambda_range[0]]*1e-10
lambda_max = x_axis[fitting_lambda_range[1]]*1e-10

if self.parent.ui.d0_value.checked():
strain_mapping_d0 = float(self.parent.ui.d0_value.text())
else:
strain_mapping_d0 = float(self.parent.ui.d0_user_value.text())

quality_threshold = 0.8

distance_source_detector_in_m = session_dict[SessionKeys.instrument][SessionSubKeys.distance_source_detector]
detector_offset_in_us = session_dict[SessionKeys.instrument][SessionSubKeys.detector_offset]

normalized_data_dir = os.path.join(output_folder, f"normalized_{_current_time}")
analysis_results_dir = os.path.join(output_folder, f"analysis_{_current_time}")
strain_results_dir = os.path.join(output_folder, f"strain_{_current_time}")

config = {
"raw_data": {
"raw_data_dir": raw_data_dir,
"raw_data_extension": raw_data_extension,
},
"open_beam": {
"open_beam_data_dir": open_beam_data_dir,
"open_beam_data_extension": open_beam_data_extension,
},
"normalization": {
"sample_background": normalization_sample_background,
"moving_average": {
"active": moving_average_active,
"dimension": moving_average_dimension,
"size": moving_average_size,
"type": moving_average_type,
},
"processing_order": processing_order,
},
"analysis": {
"material": {
"element": analysis_material_element,
},
"pixel_binning": pixel_binning,
"fitting": {
"lambda_min": lambda_min,
"lambda_max": lambda_max,
},
"strain_mapping": {
"d0": strain_mapping_d0,
"quality_threshold": 0.8,
"visualization": {
"interpolation_method": "nearest",
"colormap": "viridis",
"alpha": 0.5,
"display_fit_quality": True
},
"output_file_config": {
"strain_map_format": "png",
"fitting_grid_format": "pdf",
"figure_dpi": 300,
"csv_format": {
"delimiter": ",",
"include_metadata_header": True,
"metadata_comment_char": "#",
"na_rep": "null"
}
},
"save_intermediate_results": False
},
"distance_source_detector_in_m": distance_source_detector_in_m,
"detector_offset_in_us": detector_offset_in_us,
},
"output": {
"normalized_data_dir": normalized_data_dir,
"analysis_results_dir": analysis_results_dir,
"strain_results_dir": strain_results_dir,
}
}
6 changes: 6 additions & 0 deletions src/ibeatles/step6/strain_mapping_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ def export_all_hdf5(self):
output_folder = o_export.select_output_folder()
o_export.hdf5(output_folder=output_folder)

def action_configuration_for_cli_clicked(self):
o_export = Export(parent=self,
grand_parent=self.parent)
output_folder = o_export.select_output_folder()
o_export.config_for_cli(output_folder=output_folder)

def fitting_algorithm_changed(self):
self.update_display()

Expand Down
24 changes: 24 additions & 0 deletions src/ibeatles/ui/ui_strainMapping.ui
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@
<addaction name="actionExportImagesAll"/>
<addaction name="separator"/>
<addaction name="menuTable_and_integrated_image"/>
<addaction name="separator"/>
<addaction name="action_configuration_for_cli"/>
</widget>
<addaction name="menuExport"/>
</widget>
Expand Down Expand Up @@ -591,6 +593,11 @@
<string>integrated image ...</string>
</property>
</action>
<action name="action_configuration_for_cli">
<property name="text">
<string>configuration for cli ...</string>
</property>
</action>
</widget>
<resources/>
<connections>
Expand Down Expand Up @@ -914,6 +921,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>action_configuration_for_cli</sender>
<signal>triggered()</signal>
<receiver>MainWindow</receiver>
<slot>action_configuration_for_cli_clicked()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>538</x>
<y>428</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>fitting_algorithm_changed()</slot>
Expand All @@ -934,5 +957,6 @@
<slot>export_images_all_tiff()</slot>
<slot>interpolation_cmap_method_changed()</slot>
<slot>display_hidden_plot_changed()</slot>
<slot>action_configuration_for_cli_clicked()</slot>
</slots>
</ui>
9 changes: 9 additions & 0 deletions src/ibeatles/utilities/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import datetime

TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S"


def get_current_time_in_special_file_name_format():
"""format the current date and time into something like 04m_07d_2022y_08h_06mn """
current_time = datetime.datetime.now().strftime("%mm_%dd_%Yy_%Hh_%Mmn")
return current_time

0 comments on commit f2448ae

Please sign in to comment.