Skip to content

Commit 2f2d7d9

Browse files
authored
Merge pull request #283 from DiamondLightSource/improve-xrf-tomo
Improve xrf tomo
2 parents 69cfff5 + db84d46 commit 2f2d7d9

6 files changed

Lines changed: 152 additions & 24 deletions

File tree

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,18 @@
2323
dif: 1000 # A difference between the outlier value and the median value of neighbouring pixels.
2424
save_result: true
2525
# --- Center of Rotation auto-finding. Required for reconstruction bellow. ---
26-
- method: find_center_vo
27-
module_path: httomolibgpu.recon.rotation
26+
- method: find_center
27+
module_path: tomopy.recon.rotation
2828
parameters:
29-
ind: null # A vertical slice (sinogram) index to calculate CoR, `mid` can be used for middle
30-
average_radius: 0 # Average several sinograms to improve SNR, one can try 3-5 range
31-
cor_initialisation_value: null # Use if an approximate CoR is known
32-
smin: -50
33-
smax: 50
34-
srad: 6.0
35-
step: 0.5
36-
ratio: 0.5
37-
drop: 20
29+
ind: null
30+
init: <INITCOR>
31+
tol: 0.5
32+
mask: true
33+
ratio: 1.0
34+
sinogram_order: false
3835
id: centering
3936
side_outputs:
40-
cor: centre_of_rotation # A side output of the method, here a CoR scalar value
37+
cor: centre_of_rotation
4138
# --- Reconstruction method. ---
4239
- method: FBP2d_astra
4340
module_path: httomolibgpu.recon.algorithm
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# --- Standard tomography loader for NeXus files. ---
2+
- method: standard_tomo
3+
module_path: httomo.data.hdf.loaders
4+
parameters:
5+
data_path: auto
6+
image_key_path: auto
7+
rotation_angles: auto
8+
preview:
9+
detector_x: # horizontal data previewing/cropping.
10+
# when null, the full data dimension is used, i.e., no previewing
11+
start: null
12+
stop: null
13+
detector_y: # vertical data previewing/cropping.
14+
# when null, the full data dimension is used, i.e., no previewing
15+
start: null
16+
stop: null
17+
darks: null
18+
flats: null
19+
- method: remove_outlier
20+
module_path: httomolibgpu.misc.corr
21+
parameters:
22+
kernel_size: 3 # The size of the 3D neighbourhood surrounding the voxel. Odd integer.
23+
dif: 1000 # A difference between the outlier value and the median value of neighbouring pixels.
24+
save_result: true
25+
- method: find_center
26+
module_path: tomopy.recon.rotation
27+
parameters:
28+
ind: null
29+
init: <INITCOR>
30+
tol: 0.5
31+
mask: true
32+
ratio: 1.0
33+
sinogram_order: false
34+
id: centering
35+
side_outputs:
36+
cor: centre_of_rotation
37+
# --- Reconstruction method. ---
38+
- method: OSEM3d_tomobar
39+
module_path: httomolibgpu.recon.algorithm
40+
parameters:
41+
center: ${{centering.side_outputs.centre_of_rotation}}
42+
detector_pad: false
43+
recon_size: null
44+
recon_mask_radius: 0.95
45+
iterations: 20
46+
subsets_number: 12
47+
regularisation_type: PD_TV
48+
regularisation_parameter: 0.01
49+
regularisation_iterations: 30
50+
regularisation_half_precision: true
51+
nonnegativity: true
52+
# --- Calculate global statistics on the reconstructed volume, required for data rescaling. ---
53+
- method: calculate_stats
54+
module_path: httomo.methods
55+
parameters: {}
56+
id: statistics
57+
side_outputs:
58+
glob_stats: glob_stats
59+
# --- Rescaling the data using min/max obtained from `calculate_stats`. ---
60+
- method: rescale_to_int
61+
module_path: httomolibgpu.misc.rescale
62+
parameters:
63+
perc_range_min: 0.0
64+
perc_range_max: 100.0
65+
bits: 32
66+
glob_stats: ${{statistics.side_outputs.glob_stats}}
67+
# --- Saving data into images. ---
68+
- method: save_to_images
69+
module_path: httomolib.misc.images
70+
parameters:
71+
subfolder_name: images
72+
axis: auto
73+
file_format: tif # `tif` or `jpeg` can be used.
74+
asynchronous: true

i14/notebooks/xrf_tomo_align_initial.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"inpath = \"\"\n",
2626
"outpath_nexus = None\n",
2727
"outpath_shifts = None\n",
28+
"outpath_cor = None\n",
2829
"alignment_section = \"all\"\n",
2930
"alignment_band = 15\n",
3031
"cropping = \"auto\"\n",
@@ -895,6 +896,24 @@
895896
"np.savetxt(outpath_shifts, shifts+delta_shifts, delimiter=\" \")\n",
896897
"np.savetxt(outpath_limits, [cmin, cmax], delimiter=\" \")"
897898
]
899+
},
900+
{
901+
"cell_type": "markdown",
902+
"id": "16c977de-ca7b-4afb-a564-780df133334b",
903+
"metadata": {},
904+
"source": [
905+
"## Saving estimated centre of rotation to a TXT file"
906+
]
907+
},
908+
{
909+
"cell_type": "code",
910+
"execution_count": null,
911+
"id": "a1784c75-6b2a-4e48-84d3-315d70311562",
912+
"metadata": {},
913+
"outputs": [],
914+
"source": [
915+
"np.savetxt(outpath_cor, np.array([(cmax-cmin)/2]))"
916+
]
898917
}
899918
],
900919
"metadata": {

i14/schema/xrfTomoSchema.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
"alignmentSection": {
4242
"type": "string",
43-
"enum": ["all", "top", "middle", "bottom"],
43+
"enum": ["all", "top", "middle", "bottom"],
4444
"title": "Section for alignment",
4545
"description": "The section of the projections to be used for the initial alignment."
4646
},
@@ -59,6 +59,12 @@
5959
"type": "number",
6060
"title": "Centre of rotation",
6161
"description": "Optional value for centre of rotation for the tomographic reconstruction, using Vo centering method if not provided."
62+
},
63+
"reconsMethod" : {
64+
"type": "string",
65+
"enum": ["FBP", "OLEM"],
66+
"title": "Reconstruction Method",
67+
"description": "The method to be used for reconstruction. FBP is default. OLEM might provide smoother results."
6268
}
6369
},
6470
"required": ["outputFolder", "multiScan", "multiEdge"],

i14/schema/xrfTomoUISchema.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,18 @@
7171
]
7272
},
7373
{
74-
"type": "Control",
75-
"scope": "#/properties/cor"
76-
},
74+
"type": "HorizontalLayout",
75+
"elements": [
76+
{
77+
"type": "Control",
78+
"scope": "#/properties/cor"
79+
},
80+
{
81+
"type": "Control",
82+
"scope": "#/properties/reconsMethod"
83+
}
84+
]
85+
},
7786
{
7887
"type": "Control",
7988
"scope": "#/properties/outputFolder"

i14/templates/xrf-tomo-template.yaml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ spec:
2525
- name: outputFolder
2626
value: "testing"
2727
- name: multiScan
28-
value: '[{"multiScan":{"start":423844,"end":423947,"excluded":[423908,423909,423911,423916,423917,423935,423936,423937,423940,423942,423943,423944,423945]}}]'
28+
value: '[{"multiScan":{"start":436147,"end":436230,"excluded":[]}}]'
2929
- name: multiEdge
30-
value: '[{"edgeElement":"Pb","edgeTransition":"La"},{"edgeElement":"Br","edgeTransition":"Ka"}]'
30+
value: '[{"edgeElement":"Tl","edgeTransition":"La"},{"edgeElement":"Ga","edgeTransition":"Ka"}]'
3131
- name: elementToAlign
32-
value: "Pb"
32+
value: "Tl"
3333
- name: transitionToAlign
3434
value: "La"
3535
- name: alignmentSection
@@ -40,6 +40,8 @@ spec:
4040
value: true
4141
- name: cor
4242
value: "null"
43+
- name: reconsMethod
44+
value: "FBP"
4345
volumeClaimTemplates:
4446
- metadata:
4547
name: tmp
@@ -57,16 +59,24 @@ spec:
5759
volumeMounts:
5860
- name: session
5961
mountPath: "{{`{{ workflow.parameters.visitdir }}`}}"
60-
- name: tmp
61-
mountPath: /tmp
6262
command: [bash]
6363
source: |
6464
OUTPUT="{{`{{ workflow.parameters.visitdir }}`}}"/processing/workflows/"{{`{{ workflow.parameters.outputFolder }}`}}"
65+
METHOD="{{`{{ workflow.parameters.reconsMethod }}`}}"
6566
mkdir -p $OUTPUT
6667
echo '{{ .Files.Get "notebooks/xrf_tomo_align_initial.ipynb" | b64enc }}' | base64 -d > $OUTPUT/align_initial.ipynb
6768
echo '{{ .Files.Get "notebooks/xrf_tomo_align_and_normalise.ipynb" | b64enc }}' | base64 -d > $OUTPUT/align_and_normalise.ipynb
6869
echo '{{ .Files.Get "notebooks/xrf_tomo_plotting.ipynb" | b64enc }}' | base64 -d > $OUTPUT/plotting.ipynb
69-
echo '{{ .Files.Get "configs/httomo_config_fbp.yaml" | b64enc }}' | base64 -d > $OUTPUT/httomo.yaml
70+
echo '{{ .Files.Get "configs/httomo_config_OLEM.yaml" | b64enc }}' | base64 -d > $OUTPUT/httomo_OLEM.yaml
71+
echo '{{ .Files.Get "configs/httomo_config_FBP.yaml" | b64enc }}' | base64 -d > $OUTPUT/httomo_FBP.yaml
72+
if [ "$METHOD" = "OLEM" ]; then
73+
mv $OUTPUT/httomo_OLEM.yaml $OUTPUT/httomo.yaml
74+
rm $OUTPUT/httomo_FBP.yaml
75+
fi
76+
if [ "$METHOD" = "FBP" ]; then
77+
mv $OUTPUT/httomo_FBP.yaml $OUTPUT/httomo.yaml
78+
rm $OUTPUT/httomo_OLEM.yaml
79+
fi
7080
volumes:
7181
- name: session
7282
hostPath:
@@ -138,6 +148,7 @@ spec:
138148
-p inpath "tomo_xrf_${START}_${END}_${EDGE}.nxs" \
139149
-p outpath_nexus "${EDGE}_aligned_initial.nxs" \
140150
-p outpath_shifts "${EDGE}_shifts.txt" \
151+
-p outpath_cor "${EDGE}_cor.txt" \
141152
-p alignment_section "{{`{{ workflow.parameters.alignmentSection }}`}}" \
142153
-p alignment_band "{{`{{ workflow.parameters.alignmentBand }}`}}"
143154
--prepare-only
@@ -149,6 +160,10 @@ spec:
149160
- name: tmp
150161
mountPath: /tmp
151162
outputs:
163+
parameters:
164+
- name: initcor
165+
valueFrom:
166+
path: "{{`{{ workflow.parameters.visitdir }}`}}/processing/workflows/{{`{{ workflow.parameters.outputFolder }}`}}/{{`{{ workflow.parameters.elementToAlign }}`}}-{{`{{ workflow.parameters.transitionToAlign }}`}}_cor.txt"
152167
artifacts:
153168
- name: align_initial
154169
path: "{{`{{ workflow.parameters.visitdir }}`}}/processing/workflows/{{`{{ workflow.parameters.outputFolder }}`}}/_assets/align_initial.html"
@@ -265,8 +280,9 @@ spec:
265280
inputs:
266281
parameters:
267282
- name: edge
283+
- name: initcor
268284
script:
269-
image: ghcr.io/diamondlightsource/httomo:2.5
285+
image: ghcr.io/diamondlightsource/httomo:3.2.1
270286
env:
271287
- name: CUPY_CACHE_DIR
272288
value: /tmp/.cupy/kernel_cache
@@ -284,8 +300,10 @@ spec:
284300
TRANSITION="{{`{{= sprig.mustFromJson(inputs.parameters.edge).edgeTransition }}`}}"
285301
mkdir -p $OUTPUT/httomo_output
286302
303+
COR_ESTIMATE="{{`{{ inputs.parameters.initcor }}`}}"
304+
[[ $COR_ESTIMATE != "null" ]] && sed -i 's/<INITCOR>/'"${COR_ESTIMATE}"'/' $OUTPUT/httomo.yaml
287305
COR="{{`{{ workflow.parameters.cor }}`}}"
288-
[[ $COR != "null" ]] && sed -i 's/${{`{{centering.side_outputs.centre_of_rotation}}`}}/'"${COR}"'/' $OUTPUT/httomo.yaml
306+
[[ $COR != "null" ]] && sed -i 's/${{`{{centering.side_outputs.centre_of_rotation}}`}}/'"${COR}"'/' $OUTPUT/httomo.yaml
289307
290308
cmd=(/opt/conda/bin/mpirun -n 1 /opt/conda/bin/python -m httomo run)
291309
cmd+=("--output-folder-name=${ELEMENT}-${TRANSITION}")
@@ -418,6 +436,7 @@ spec:
418436
inputs:
419437
parameters:
420438
- name: edge
439+
- name: initcor
421440
dag:
422441
tasks:
423442
- name: alignment
@@ -432,6 +451,8 @@ spec:
432451
parameters:
433452
- name: edge
434453
value: "{{`{{ inputs.parameters.edge }}`}}"
454+
- name: initcor
455+
value: "{{`{{ inputs.parameters.initcor }}`}}"
435456
dependencies: [alignment]
436457

437458
- name: xrf-tomo-pipeline
@@ -463,6 +484,8 @@ spec:
463484
parameters:
464485
- name: edge
465486
value: "{{`{{ item }}`}}"
487+
- name: initcor
488+
value: "{{`{{ tasks.generate-shifts.outputs.parameters.initcor }}`}}"
466489
withParam: "{{`{{ workflow.parameters.multiEdge }}`}}"
467490

468491
- name: show-results

0 commit comments

Comments
 (0)