Skip to content

Commit

Permalink
working on creating the json file. this refs #33
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanBilheux committed Jul 29, 2024
1 parent dcaf14d commit a8a654b
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 83 deletions.
41 changes: 41 additions & 0 deletions __code/batch_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __code.parent import Parent
from __code import DataType


class BatchHandler(Parent):

def create_config_file(self):

# input files
list_raw_files = self.parent.input_files[DataType.raw]
list_ob_files = self.parent.input_files[DataType.ob]
list_dc_files = self.parent.input_files[DataType.dc]

# crop region
crop_left, crop_right, crop_top, crop_bottom = list(self.parent.cropping.result)

## filter #1
# gamma filtering flag
gamma_filtering_flag = self.parent.gamma_filtering_ui.value

# beam fluctuation correction flag and region
beam_fluctuation_flag = self.parent.beam_fluctuation_ui.value
bf_left, bf_right, bf_top, bf_bottom = list(self.parent.beam_fluctuation_roi.value)

# tilt value
tilt_value = self.parent.tilt_options_ui.value

## filter #2
# remove negative values
remove_negative_values_flag = self.parent.remove_negative_ui.value

# ring removal
bm3d_flag = self.parent.ring_removal_ui.children[0].value
tomopy_v0_flag = self.parent.ring_removal_ui.children[1].value
ketcham_flag = self.parent.ring_removal_ui.children[2].value

# range of slices to reconstruct
top_slice, bottom_slice = list(self.parent.z_range_selection.result)



28 changes: 14 additions & 14 deletions __code/laminographyui_batch_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
from __code.workflow.filters import Filters
from __code.workflow.sinogram import Sinogram
from __code.workflow.select_z_range import SelectZRange

from __code.laminography_event_handler import LaminographyEventHandler
from __code.batch_handler import BatchHandler

from __code.file_folder_browser import FileFolderBrowser
from __code.display import Display
Expand All @@ -59,7 +61,8 @@

class LaminographyUi:


# the widgets of the laminography settings 2 tabs
laminography_settings_ui = {}

working_dir = {DataType.raw: "",
DataType.ob: "",
Expand Down Expand Up @@ -181,15 +184,22 @@ def define_parameters(self):
self.display_section_title(name="Define laminography parameters")
self.laminography_settings(batch_mode=True)

def run_reconstruction_in_batch_mode(self):
# create json config
def launch_batch_job(self):
o_batch = BatchHandler(parent=self)
o_batch.create_config_file()

# launch command
pass








# HELPER FOR BATCH JOBDS =============================================================================

def tilt_correction_options(self):
o_tilt = Tilt(parent=self)
o_tilt.display_batch_options()
Expand All @@ -201,17 +211,7 @@ def load(self):
def display_section_title(self, name=''):
display(HTML('<hr style=height:5px; border:none; color:#333;background-color:#333>' +
'<h1>' + name + '</h1>'))












def load_and_display_data(self):
o_load = Load(parent=self)
o_load.load_and_display_data()
Expand Down
10 changes: 5 additions & 5 deletions __code/workflow/ring_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class RingRemoval(Parent):

def ring_removal_options(self):
self.ring_removal_ui = widgets.VBox([widgets.Checkbox(value=False,
self.parent.ring_removal_ui = widgets.VBox([widgets.Checkbox(value=False,
description="BM3D",
disabled=True),
widgets.Checkbox(value=False,
Expand All @@ -28,12 +28,12 @@ def ring_removal_options(self):
description="Ketcham")],
layout={'width': 'max-content'},
)
display(self.ring_removal_ui)
display(self.parent.ring_removal_ui)

def apply_ring_removal_options(self):

# bm3d
if self.ring_removal_ui.children[0].value:
if self.parent.ring_removal_ui.children[0].value:
t0 = timeit.default_timer()
print("Running strikes removal using BM3D ...")
import bm3d_streak_removal as bm3d
Expand All @@ -47,7 +47,7 @@ def apply_ring_removal_options(self):
self.proj_ring_removal_1 = self.parent.proj_tilt_corrected

# tomopy, Vo
if self.ring_removal_ui.children[1].value:
if self.parent.ring_removal_ui.children[1].value:
t0 = timeit.default_timer()
print("Running strikes removal using Vo ...")
self.proj_ring_removal_2 = tomopy.remove_all_stripe(self.proj_ring_removal_1,
Expand All @@ -60,7 +60,7 @@ def apply_ring_removal_options(self):
self.proj_ring_removal_2 = self.proj_ring_removal_1

# ketcham
if self.ring_removal_ui.children[2].value:
if self.parent.ring_removal_ui.children[2].value:
t0 = timeit.default_timer()
print("Running strikes removal using Ketcham ...")
self.proj_ring_removal_3 = remove_ring_artifact(arrays=self.proj_ring_removal_2,
Expand Down
4 changes: 2 additions & 2 deletions __code/workflow/tilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,13 +533,13 @@ def plot_comparisons(algo_selected, color_range, col, row, zoom_x, zoom_y):
display(self.test_tilt)

def display_batch_options(self):
tilt_options_ui = widgets.VBox([
self.parent.tilt_options_ui = widgets.VBox([
widgets.Label("Tilt value (degrees)",
layout=widgets.Layout(width='200px'),
),
widgets.FloatSlider(min=-90,
max=90,
value=0)
])
display(tilt_options_ui)
display(self.parent.tilt_options_ui)

93 changes: 31 additions & 62 deletions laminography_batch_mode.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1f446846073b43f9a7e36ac84dbeb977",
"model_id": "6cfa71c468cb4821a3f364f1a1bc81a8",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -272,7 +272,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6f89cb02d2c447d3a769afdfbab307f8",
"model_id": "e065f15930d3461c903a53f47fd54120",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -286,7 +286,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b331ffcd07db4b8bbec02a6947bccd2e",
"model_id": "f98efaddb4a74d78b02203dd8601e874",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -300,7 +300,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9c5101d7c13c4714b22306c4f49c6914",
"model_id": "372cc2ba8e684171b659f103762a4b89",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -326,7 +326,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8e67934313e64e96b4bff8eddc792436",
"model_id": "dd6ed8ce51a74a09b50c941415a77321",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -352,7 +352,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a4cdfb314b0c4530ba49aefe3cfdb8f2",
"model_id": "b732529c693b4a3ab92b61b570b7c77a",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -378,7 +378,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2f961d08caf7475a8ec9ebc486ed40ea",
"model_id": "bfe56494e805434da68084d4ff1f470a",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -404,7 +404,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7cae08afaae845daaf313dda29251706",
"model_id": "deb64efcb8d2473aaee210046ac9de55",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -430,7 +430,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "45fe996e96ee48c49f4ac274a709b76f",
"model_id": "efcb988441274d7db1105a9be633b3fa",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -456,7 +456,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4bce8e306e554aff90b199765112f89c",
"model_id": "bc8ed50d68dc4315b9b5dddc0b5a6ac6",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -482,7 +482,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "547686c7258c40ddbc10b79a53bd0ce5",
"model_id": "066979773eff4844810bea5aa2086192",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -506,39 +506,41 @@
"output_type": "display_data"
},
{
"ename": "AttributeError",
"evalue": "'LaminographyUi' object has no attribute 'proj_mlog'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn [8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mo_imars3dui\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdefine_parameters\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/git/iMars3d_notebooks/__code/laminographyui_batch_mode.py:182\u001b[0m, in \u001b[0;36mLaminographyUi.define_parameters\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 179\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mselect_range_of_slices(batch_mode\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 181\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdisplay_section_title(name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDefine laminography parameters\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 182\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlaminography_settings\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/git/iMars3d_notebooks/__code/laminographyui_batch_mode.py:426\u001b[0m, in \u001b[0;36mLaminographyUi.laminography_settings\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 425\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mlaminography_settings\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m--> 426\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mo_event_laminography_settings \u001b[38;5;241m=\u001b[39m \u001b[43mLaminographyEventHandler\u001b[49m\u001b[43m(\u001b[49m\u001b[43mparent\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 427\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mo_event_laminography_settings\u001b[38;5;241m.\u001b[39mset_settings()\n",
"File \u001b[0;32m~/git/iMars3d_notebooks/__code/laminography_event_handler.py:49\u001b[0m, in \u001b[0;36mLaminographyEventHandler.__init__\u001b[0;34m(self, parent)\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparent \u001b[38;5;241m=\u001b[39m parent\n\u001b[1;32m 48\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mz_top, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mz_bottom \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparent\u001b[38;5;241m.\u001b[39mz_range_selection\u001b[38;5;241m.\u001b[39mresult)\n\u001b[0;32m---> 49\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_proj_mlog \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparent\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mproj_mlog\u001b[49m[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mz_top: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mz_bottom, :, :]\n\u001b[1;32m 50\u001b[0m [\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnbr_angles, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnbr_row, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnbr_col] \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mshape(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_proj_mlog)\n",
"\u001b[0;31mAttributeError\u001b[0m: 'LaminographyUi' object has no attribute 'proj_mlog'"
]
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "94fd7305e81e412c9c445d1c1500348e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Tab(children=(HBox(children=(FloatSlider(value=20.0, max=90.0, step=0.01), Label(value='°'))), VBox(children=(…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"o_imars3dui.define_parameters()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1890dd75",
"cell_type": "markdown",
"id": "dd0b5a36",
"metadata": {},
"outputs": [],
"source": []
"source": [
"# Launch batch job "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "94f225d3",
"metadata": {},
"outputs": [],
"source": []
"source": [
"o_imars3dui.launch_batch_job()"
]
},
{
"cell_type": "code",
Expand All @@ -556,39 +558,6 @@
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "a866d81d",
"metadata": {},
"source": [
"### Set up paremeters "
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "3b881150",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f48c868ec027446997d07f95db245f21",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Tab(children=(HBox(children=(FloatSlider(value=20.0, max=90.0, step=0.01), Label(value='°'))), VBox(children=(…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"o_imars3dui.laminography_settings()"
]
},
{
"cell_type": "markdown",
"id": "85815b10",
Expand Down

0 comments on commit a8a654b

Please sign in to comment.