Skip to content

Commit c11f809

Browse files
authored
Update QC report and workflow to produce necessary qa items during main run (#63)
* use niivue to dynamically render report with rotating heads * serve nifti's to niivue over http * scan niivue preview added to full report * generating svg's for comparison w/ good ole nipype * add entrypoint for qa reports * standardize commands * refactored from defaced dir to bids dir to make qa usage more clear * clean up toml and fix import
1 parent 9423167 commit c11f809

File tree

12 files changed

+1949
-1315
lines changed

12 files changed

+1949
-1315
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ options:
7878
Options: 't1' (included T1w template), 'mni' (MNI template), or 'pet'
7979
(averaged PET image).
8080
--open_browser Open browser to show QA reports after completion
81+
--qa-port QA_PORT Port for NIfTI preview server (default: 8000)
8182
```
8283
8384
Working example usage:
@@ -106,6 +107,68 @@ Example usage with template anatomical:
106107
petdeface /inputfolder /outputfolder --use_template_anat t1 --n_procs 16
107108
```
108109

110+
### Quality Assessment (QA) Reports
111+
112+
PETdeface includes a comprehensive quality assessment system that generates reports to help validate defacing results. The QA system creates both SVG reports and interactive NIfTI viewers.
113+
114+
#### QA Report Location
115+
116+
QA reports are automatically generated in the input BIDS directory under `derivatives/petdeface/qa/`. This includes:
117+
- SVG reports showing before/after defacing comparisons
118+
- Interactive HTML viewers for 3D NIfTI visualization
119+
- An index page linking to all available reports
120+
121+
#### Running QA Reports
122+
123+
**Automatic QA generation:**
124+
```bash
125+
petdeface /inputfolder /outputfolder --open_browser
126+
```
127+
128+
**Manual QA generation using the separate QA tool:**
129+
```bash
130+
petdeface-qa /inputfolder --open-browser --start-server
131+
```
132+
133+
#### NIfTI Preview Server
134+
135+
For 3D NIfTI visualization, PETdeface can start a local HTTP server to serve NIfTI files. This is required due to browser security restrictions.
136+
137+
**Start with server:**
138+
```bash
139+
petdeface-qa /inputfolder --start-server --open-browser
140+
```
141+
142+
**Custom port:**
143+
```bash
144+
petdeface-qa /inputfolder --start-server --qa-port 8080
145+
```
146+
147+
#### QA Tool Options
148+
149+
The `petdeface-qa` command provides the following options:
150+
151+
```bash
152+
usage: petdeface-qa [-h] bids_dir [--output-dir OUTPUT_DIR]
153+
[--open-browser] [--start-server] [--qa-port QA_PORT]
154+
155+
Generate SVG QA reports for PET deface workflow.
156+
157+
positional arguments:
158+
bids_dir BIDS directory containing the defaced dataset (with derivatives/petdeface)
159+
160+
options:
161+
-h, --help show this help message and exit
162+
--output-dir OUTPUT_DIR, --output_dir OUTPUT_DIR
163+
Output directory for HTML files (default: derivatives/petdeface/qa/)
164+
--open-browser Open browser automatically
165+
--start-server Start local HTTP server for NIfTI file access (required for NIfTI viewers)
166+
--qa-port QA_PORT, --qa_port QA_PORT
167+
Port for NIfTI preview server (default: 8000)
168+
```
169+
170+
**Note**: The NIfTI preview server is required for 3D visualization due to browser CORS restrictions. Keep the terminal running while viewing NIfTI files.
171+
109172
### Docker Usage
110173

111174
Requirements:

docs/modules.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ petdeface.petdeface module
2626
--------------------------
2727

2828
.. automodule:: petdeface.petdeface
29+
:members:
30+
:undoc-members:
31+
:show-inheritance:
32+
33+
petdeface.qa module
34+
------------------
35+
36+
.. automodule:: petdeface.qa
2937
:members:
3038
:undoc-members:
3139
:show-inheritance:

docs/usage.rst

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ options:
127127
Options: 't1' (included T1w template), 'mni' (MNI template), or 'pet'
128128
(averaged PET image).
129129
--open_browser Following defacing this flag will open the browser to view the defacing results
130+
--qa-port QA_PORT Port for NIfTI preview server (default: 8000)
130131

131132
Docker Based
132133
------------
@@ -205,4 +206,76 @@ Example usage with template anatomical:
205206

206207
.. code-block:: bash
207208
208-
petdeface /inputfolder /outputfolder --use_template_anat t1 --n_procs 16
209+
petdeface /inputfolder /outputfolder --use_template_anat t1 --n_procs 16
210+
211+
Quality Assessment (QA) Reports
212+
------------------------------
213+
214+
PETdeface includes a comprehensive quality assessment system that generates reports to help validate defacing results. The QA system creates both SVG reports and interactive NIfTI viewers.
215+
216+
QA Report Location
217+
~~~~~~~~~~~~~~~~~
218+
219+
QA reports are automatically generated in the input BIDS directory under ``derivatives/petdeface/qa/``. This includes:
220+
221+
- SVG reports showing before/after defacing comparisons
222+
- Interactive HTML viewers for 3D NIfTI visualization
223+
- An index page linking to all available reports
224+
225+
Running QA Reports
226+
~~~~~~~~~~~~~~~~~
227+
228+
**Automatic QA generation:**
229+
230+
.. code-block:: bash
231+
232+
petdeface /inputfolder /outputfolder --open_browser
233+
234+
**Manual QA generation using the separate QA tool:**
235+
236+
.. code-block:: bash
237+
238+
petdeface-qa /inputfolder --open-browser --start-server
239+
240+
NIfTI Preview Server
241+
~~~~~~~~~~~~~~~~~~~
242+
243+
For 3D NIfTI visualization, PETdeface can start a local HTTP server to serve NIfTI files. This is required due to browser security restrictions.
244+
245+
**Start with server:**
246+
247+
.. code-block:: bash
248+
249+
petdeface-qa /inputfolder --start-server --open-browser
250+
251+
**Custom port:**
252+
253+
.. code-block:: bash
254+
255+
petdeface-qa /inputfolder --start-server --qa-port 8080
256+
257+
QA Tool Options
258+
~~~~~~~~~~~~~~
259+
260+
The ``petdeface-qa`` command provides the following options:
261+
262+
.. code-block:: bash
263+
264+
usage: petdeface-qa [-h] bids_dir [--output-dir OUTPUT_DIR]
265+
[--open-browser] [--start-server] [--qa-port QA_PORT]
266+
267+
Generate SVG QA reports for PET deface workflow.
268+
269+
positional arguments:
270+
bids_dir BIDS directory containing the defaced dataset (with derivatives/petdeface)
271+
272+
options:
273+
-h, --help show this help message and exit
274+
--output-dir OUTPUT_DIR, --output_dir OUTPUT_DIR
275+
Output directory for HTML files (default: derivatives/petdeface/qa/)
276+
--open-browser Open browser automatically
277+
--start-server Start local HTTP server for NIfTI file access (required for NIfTI viewers)
278+
--qa-port QA_PORT, --qa_port QA_PORT
279+
Port for NIfTI preview server (default: 8000)
280+
281+
**Note**: The NIfTI preview server is required for 3D visualization due to browser CORS restrictions. Keep the terminal running while viewing NIfTI files.

petdeface/pet.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
class WeightedAverageInputSpec(BaseInterfaceInputSpec):
1414
pet_file = File(exists=True, desc="Dynamic PET", mandatory=True)
15+
sidecar_file = File(
16+
exists=True,
17+
desc="Optional sidecar JSON file for timing info. If not provided, uses sidecar from pet_file.",
18+
mandatory=False,
19+
)
1520

1621

1722
class WeightedAverageOutputSpec(TraitedSpec):
@@ -47,9 +52,18 @@ def _run_interface(self, runtime):
4752
img = nib.load(pet_file)
4853
data = img.get_fdata()
4954

50-
meta = ReadSidecarJSON(
51-
in_file=pet_file, bids_dir=bids_dir, bids_validate=False
52-
).run()
55+
# Use optional sidecar file if provided, otherwise use pet_file's sidecar
56+
if hasattr(self.inputs, "sidecar_file") and self.inputs.sidecar_file:
57+
sidecar_file = self.inputs.sidecar_file
58+
sidecar_bids_dir = os.path.dirname(sidecar_file)
59+
meta = ReadSidecarJSON(
60+
in_file=sidecar_file, bids_dir=sidecar_bids_dir, bids_validate=False
61+
).run()
62+
else:
63+
# Default behavior: use pet_file's sidecar
64+
meta = ReadSidecarJSON(
65+
in_file=pet_file, bids_dir=bids_dir, bids_validate=False
66+
).run()
5367

5468
frames_start = np.array(meta.outputs.out_dict["FrameTimesStart"])
5569
frames_duration = np.array(meta.outputs.out_dict["FrameDuration"])

0 commit comments

Comments
 (0)