Skip to content

Commit eb741f9

Browse files
committed
fixed bug. this refs #316
1 parent cbdc65f commit eb741f9

3 files changed

Lines changed: 289 additions & 18 deletions

File tree

notebooks/__code/_utilities/images.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import dxchange
22
import numpy as np
33
from tqdm import tqdm
4+
from skimage.io import imread
5+
import multiprocessing as mp
46

57

68
def _init_arr_from_stack(list_files, ext=".tiff", slc=None):
@@ -40,3 +42,18 @@ def read_img_stack(list_files: list, ext=".tiff", fliplr=False, flipud=False):
4042
_arr = np.flipud(_arr)
4143
arr[m] = _arr
4244
return arr
45+
46+
47+
def _worker(fl):
48+
return (imread(fl).astype(np.float32)).swapaxes(0, 1)
49+
50+
51+
def load_data_using_multithreading(list_tif: list = None, combine_tof: bool = False) -> np.ndarray:
52+
"""load data using multithreading"""
53+
with mp.Pool(processes=40) as pool:
54+
data = pool.map(_worker, list_tif)
55+
56+
if combine_tof:
57+
return np.array(data).sum(axis=0)
58+
else:
59+
return np.array(data, dtype=np.float32)

notebooks/__code/mcp_chips_corrector/mcp_chips_corrector.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import numpy as np
55
from IPython.display import HTML, display
6-
from NeuNorm.normalization import Normalization
7-
6+
# from NeuNorm.normalization import Normalization
7+
from __code._utilities.images import load_data_using_multithreading
88
from __code.ipywe import fileselector
99

1010

@@ -33,12 +33,9 @@ def load_data(self, folder_selected):
3333

3434
working_list_files = [file for file in full_list_files if "_SummedImg.fits" not in file]
3535

36-
o_norm = Normalization()
37-
o_norm.load(file=working_list_files, notebook=True)
38-
36+
self.working_data = load_data_using_multithreading(list_tif=working_list_files)
3937
self.input_working_folder = folder_selected
4038
self.working_list_files = working_list_files
41-
self.working_data = o_norm.data["sample"]["data"]
4239

4340
# create integrated data set
4441
self.integrated_data = np.sum(self.working_data, axis=0)

notebooks/mcp_chips_corrector.ipynb

Lines changed: 269 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,228 @@
2323
},
2424
{
2525
"cell_type": "code",
26-
"execution_count": null,
26+
"execution_count": 1,
2727
"metadata": {
28+
"execution": {
29+
"iopub.execute_input": "2026-01-15T13:38:22.023213Z",
30+
"iopub.status.busy": "2026-01-15T13:38:22.022989Z",
31+
"iopub.status.idle": "2026-01-15T13:38:25.402060Z",
32+
"shell.execute_reply": "2026-01-15T13:38:25.401476Z",
33+
"shell.execute_reply.started": "2026-01-15T13:38:22.023196Z"
34+
},
2835
"run_control": {
2936
"frozen": false,
3037
"read_only": false
3138
}
3239
},
33-
"outputs": [],
40+
"outputs": [
41+
{
42+
"name": "stderr",
43+
"output_type": "stream",
44+
"text": [
45+
"olefile module not found\n"
46+
]
47+
},
48+
{
49+
"data": {
50+
"text/html": [
51+
"\n",
52+
"<style type=\"text/css\">\n",
53+
".jupyter-widgets select option {font-family: \"Lucida Console\", Monaco, monospace;}\n",
54+
".jupyter-widgets select {width: 98%;}\n",
55+
"div.output_subarea {padding: 0px;}\n",
56+
"div.output_subarea > div {margin: 0.4em;}\n",
57+
"</style>\n"
58+
],
59+
"text/plain": [
60+
"<IPython.core.display.HTML object>"
61+
]
62+
},
63+
"metadata": {},
64+
"output_type": "display_data"
65+
},
66+
{
67+
"data": {
68+
"text/html": [
69+
"\n",
70+
" <style>\n",
71+
" .result_label {\n",
72+
" font-style: bold;\n",
73+
" color: red;\n",
74+
" font-size: 18px;\n",
75+
" }\n",
76+
" </style>\n",
77+
" "
78+
],
79+
"text/plain": [
80+
"<IPython.core.display.HTML object>"
81+
]
82+
},
83+
"metadata": {},
84+
"output_type": "display_data"
85+
},
86+
{
87+
"data": {
88+
"application/vnd.jupyter.widget-view+json": {
89+
"model_id": "b107bd796fc94ce8a289a71344bb6d5a",
90+
"version_major": 2,
91+
"version_minor": 0
92+
},
93+
"text/plain": [
94+
"VBox(children=(HBox(children=(Label(value='Select Instrument', layout=Layout(width='20%')), Select(index=2, la…"
95+
]
96+
},
97+
"metadata": {},
98+
"output_type": "display_data"
99+
},
100+
{
101+
"data": {
102+
"text/html": [
103+
"<style>\n",
104+
"\n",
105+
"/* The following CSS has been adapted from\n",
106+
" http://nbviewer.ipython.org/github/ketch/teaching-numerics-with-notebooks/blob/master/Styling_notebooks.ipynb\n",
107+
" by Aron Ahmadia and David Ketcheson and has been reused under CC BY 4.0\n",
108+
" */\n",
109+
"\n",
110+
"/* main background */\n",
111+
"#site {\n",
112+
" background: #888;\n",
113+
" color: #red;\n",
114+
"}\n",
115+
"\n",
116+
"div.container {\n",
117+
" width: 100% ! important;\n",
118+
"}\n",
119+
"\n",
120+
"div.cell { /* set cell width to about 80 chars */\n",
121+
" width: 95%;\n",
122+
"}\n",
123+
"\n",
124+
"div #notebook { /* centre the content */\n",
125+
"/* background: #fff; /* white background for content */\n",
126+
" background: blue;\n",
127+
" width: 100%;\n",
128+
" margin: auto;\n",
129+
" padding-left: 1em;\n",
130+
" padding-right: 1em;\n",
131+
" background-image: url(\"tile_background.jpg\");\n",
132+
"}\n",
133+
"\n",
134+
"#notebook li { /* More space between bullet points */\n",
135+
" margin-top:0.4em;\n",
136+
"}\n",
137+
"\n",
138+
"/* change background color of running cells */\n",
139+
"div.cell.code_cell.running {\n",
140+
"/* background-color: rgba(164,188,194,.75); */\n",
141+
" background-color: green;\n",
142+
" border-width: 8px\n",
143+
" border-style: solid\n",
144+
" border-color: #111;\n",
145+
"}\n",
146+
"\n",
147+
"/* Put a solid color box around each cell and its output, visually linking them together */\n",
148+
"div.cell.code_cell {\n",
149+
" background-color: rgba(164,188,194,.25); /* Continuum L Gray with alpha 0.25 */\n",
150+
" border-radius: 10px; /* rounded borders */\n",
151+
" padding: 1em;\n",
152+
" margin-top: 1em;\n",
153+
"}\n",
154+
"\n",
155+
"div.text_cell_render{\n",
156+
"\tfont-family: Georgia, Times, 'Times New Roman', serif;\n",
157+
" line-height: 110%;\n",
158+
" font-size: 105%;\n",
159+
" width: 95%;\n",
160+
" margin-left: auto;\n",
161+
" margin-right: auto;\n",
162+
"}\n",
163+
"\n",
164+
"\n",
165+
"/* Formatting for header cells */\n",
166+
".text_cell_render h1 {\n",
167+
"\tfont-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;\n",
168+
" font-weight: 400;\n",
169+
" font-size: 30pt;\n",
170+
" line-height: 100%;\n",
171+
" color: rgb(37,55,70); /* Continuum Blue*/\n",
172+
" margin-bottom: 0.1em;\n",
173+
" margin-top: 0.1em;\n",
174+
" display: block;\n",
175+
"}\n",
176+
".text_cell_render h2 {\n",
177+
"\tfont-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;\n",
178+
" font-weight: 700;\n",
179+
" font-size: 22pt;\n",
180+
" line-height: 100%;\n",
181+
" color: rgb(37,55,70);\n",
182+
" margin-bottom: 0.1em;\n",
183+
" margin-top: 0.1em;\n",
184+
" display: block;\n",
185+
"}\n",
186+
"\n",
187+
".text_cell_render h3 {\n",
188+
"\tfont-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;\n",
189+
" margin-top:12px;\n",
190+
" margin-bottom: 3px;\n",
191+
" font-style: italic;\n",
192+
" color: rgb(37, 55, 70);\n",
193+
"}\n",
194+
"\n",
195+
".text_cell_render h4 {\n",
196+
"\tfont-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;\n",
197+
"}\n",
198+
"\n",
199+
".text_cell_render h5 {\n",
200+
"\tfont-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;\n",
201+
" font-weight: 300;\n",
202+
" font-size: 14pt;\n",
203+
" font-style: italic;\n",
204+
" margin-bottom: .1em;\n",
205+
" margin-top: 0.1em;\n",
206+
" display: block;\n",
207+
"}\n",
208+
"\n",
209+
".text_cell_render h6 {\n",
210+
"\tfont-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;\n",
211+
" font-weight: 300;\n",
212+
" font-size: 10pt;\n",
213+
" margin-bottom: 1px;\n",
214+
" margin-top: 1px;\n",
215+
"}\n",
216+
"\n",
217+
".CodeMirror{\n",
218+
" font-family: \"PT Mono\", fixed;\n",
219+
" font-size: 100%;\n",
220+
"}\n",
221+
"\n",
222+
"#notebook_panel { /* main background */\n",
223+
" background-image: url(\"tile_background.jpg\");\n",
224+
"}\n",
225+
"\n",
226+
"\n",
227+
"\n",
228+
"\n",
229+
"</style>\n"
230+
],
231+
"text/plain": [
232+
"<IPython.core.display.HTML object>"
233+
]
234+
},
235+
"execution_count": 1,
236+
"metadata": {},
237+
"output_type": "execute_result"
238+
}
239+
],
34240
"source": [
35241
"import warnings\n",
36242
"warnings.filterwarnings('ignore')\n",
37243
"\n",
38244
"from __code import system\n",
39245
"from __code.mcp_chips_corrector.mcp_chips_corrector import McpChipsCorrector\n",
40246
"from __code.mcp_chips_corrector.interface import Interface\n",
41-
"system.System.select_working_dir(notebook='mcp_chips_corrector')\n",
247+
"system.System.select_working_dir(notebook='mcp_chips_corrector', instrument=\"VENUS\", ipts=\"IPTS-33699\")\n",
42248
"from __code.__all import custom_style\n",
43249
"custom_style.style()"
44250
]
@@ -52,8 +258,16 @@
52258
},
53259
{
54260
"cell_type": "code",
55-
"execution_count": null,
56-
"metadata": {},
261+
"execution_count": 2,
262+
"metadata": {
263+
"execution": {
264+
"iopub.execute_input": "2026-01-15T13:38:37.459175Z",
265+
"iopub.status.busy": "2026-01-15T13:38:37.458752Z",
266+
"iopub.status.idle": "2026-01-15T13:38:37.530655Z",
267+
"shell.execute_reply": "2026-01-15T13:38:37.529973Z",
268+
"shell.execute_reply.started": "2026-01-15T13:38:37.459160Z"
269+
}
270+
},
57271
"outputs": [],
58272
"source": [
59273
"%gui qt"
@@ -73,14 +287,36 @@
73287
},
74288
{
75289
"cell_type": "code",
76-
"execution_count": null,
290+
"execution_count": 3,
77291
"metadata": {
292+
"execution": {
293+
"iopub.execute_input": "2026-01-15T13:38:40.428955Z",
294+
"iopub.status.busy": "2026-01-15T13:38:40.428790Z",
295+
"iopub.status.idle": "2026-01-15T13:38:40.444112Z",
296+
"shell.execute_reply": "2026-01-15T13:38:40.443533Z",
297+
"shell.execute_reply.started": "2026-01-15T13:38:40.428942Z"
298+
},
78299
"run_control": {
79300
"frozen": false,
80301
"read_only": false
81302
}
82303
},
83-
"outputs": [],
304+
"outputs": [
305+
{
306+
"data": {
307+
"application/vnd.jupyter.widget-view+json": {
308+
"model_id": "4ff99133e5064584bc727901ba24fe28",
309+
"version_major": 2,
310+
"version_minor": 0
311+
},
312+
"text/plain": [
313+
"VBox(children=(HTML(value=\"<b><font color='green'>Select MCP Folder ...</b>\"), VBox(children=(HBox(children=(H…"
314+
]
315+
},
316+
"metadata": {},
317+
"output_type": "display_data"
318+
}
319+
],
84320
"source": [
85321
"o_corrector = McpChipsCorrector(working_dir = system.System.get_working_dir())\n",
86322
"o_corrector.select_folder()"
@@ -95,9 +331,30 @@
95331
},
96332
{
97333
"cell_type": "code",
98-
"execution_count": null,
99-
"metadata": {},
100-
"outputs": [],
334+
"execution_count": 4,
335+
"metadata": {
336+
"execution": {
337+
"iopub.execute_input": "2026-01-15T13:39:22.518890Z",
338+
"iopub.status.busy": "2026-01-15T13:39:22.518671Z",
339+
"iopub.status.idle": "2026-01-15T13:39:24.144699Z",
340+
"shell.execute_reply": "2026-01-15T13:39:24.144036Z",
341+
"shell.execute_reply.started": "2026-01-15T13:39:22.518871Z"
342+
}
343+
},
344+
"outputs": [
345+
{
346+
"data": {
347+
"text/html": [
348+
"<span style=\"font-size: 20px; color:blue\">Check UI that popped up (maybe hidden behind this browser!)</span>"
349+
],
350+
"text/plain": [
351+
"<IPython.core.display.HTML object>"
352+
]
353+
},
354+
"metadata": {},
355+
"output_type": "display_data"
356+
}
357+
],
101358
"source": [
102359
"o_interface = Interface(o_corrector=o_corrector)\n",
103360
"o_interface.show()"
@@ -128,7 +385,7 @@
128385
"name": "python",
129386
"nbconvert_exporter": "python",
130387
"pygments_lexer": "ipython3",
131-
"version": "3.10.8"
388+
"version": "3.12.12"
132389
},
133390
"toc": {
134391
"colors": {
@@ -151,5 +408,5 @@
151408
}
152409
},
153410
"nbformat": 4,
154-
"nbformat_minor": 1
411+
"nbformat_minor": 4
155412
}

0 commit comments

Comments
 (0)