DICOMDownloader
DICOMDownloader is Fyron's DICOMweb acquisition helper. It downloads individual series or full studies, writes DICOM or NIfTI outputs, and returns result metadata that can be stored beside a cohort table.
When To Use It
- download a known
StudyInstanceUID/SeriesInstanceUID, - batch-download imaging rows from a CSV/DataFrame,
- fetch a full study when the relevant series is not known yet,
- create reproducible manifests before local image processing.
Use Imaging after files are already local. Use DICOM SEG for segmentation objects and Synthetic Export for generated intensity volumes.
Core Concepts
| Concept | Meaning |
|---|---|
StudyInstanceUID | DICOM study identifier. Required for study and series downloads. |
SeriesInstanceUID | DICOM series identifier. Required when downloading one known series. |
download_id | Deterministic SHA-256 identifier derived from the study UID alone or from study_uid_series_uid. |
output_format | "dicom" preserves source slices; "nifti" converts each series into a NIfTI volume. |
| reference DICOM | Optional single source .dcm retained beside a NIfTI output for metadata/provenance. |
study_layout | Full-study output style: hierarchical uses per-series folders; flat stores all series in one study folder. |
| result table | DataFrame with UIDs, download_id, output path, format, and error text. |
API Contract
| Topic | Contract |
|---|---|
| Input shape | Study/series UID strings for single downloads, or a DataFrame/CSV manifest for batch downloads. |
| Required columns/files | Batch manifests need study UID and, for series downloads, series UID columns; output directories must be writable. |
| Return shape | Single downloads return result metadata; batch helpers return a DataFrame with paths, identifiers, status, and errors. |
| Saved artifacts | DICOM folders, NIfTI files, optional reference DICOM files, manifests, and results CSV files. |
| Failure modes | Missing UIDs, DICOMweb authentication/server errors, conversion failures, existing-file conflicts, or invalid output layout. |
The download_id can be reproduced without contacting the server:
from fyron.dicom import DICOMDownloader
download_id = DICOMDownloader.download_id(
study_uid="1.2.3",
series_uid="1.2.3.4",
)Required Inputs
| Input | Needed for | Notes |
|---|---|---|
| DICOMweb URL | all downloads | May come from DICOM_WEB_URL. |
| study UID | single study/series | StudyInstanceUID. |
| series UID | series download | Optional for full-study mode. |
| output directory | all downloads | Destination folder. |
Optional Inputs
| Input | Use |
|---|---|
| credentials/session | authenticated PACS/DICOMweb |
output_format | "dicom" or "nifti" |
save_reference_dicom | keep one source DICOM slice beside each NIfTI output |
reference_dicom_name | custom file name for the retained metadata DICOM |
skip_existing | resumable jobs |
write_manifest | reproducibility metadata |
results_csv | batch job audit output |
Minimal Example
from fyron import DICOMDownloader
downloader = DICOMDownloader(
dicom_web_url="https://pacs.example.org/dicomweb",
output_format="dicom",
)
result = downloader.download_series(
study_uid="1.2.3",
series_uid="1.2.3.4",
output_dir="dicom_out",
)
result.download_id
result.path
result.errorNIfTI With One Metadata DICOM
When output_format="nifti", Fyron normally converts through a temporary DICOM folder and keeps only the NIfTI output. If you also need a source DICOM header for later metadata checks, set save_reference_dicom=True:
from fyron import DICOMDownloader
downloader = DICOMDownloader(
dicom_web_url="https://pacs.example.org/dicomweb",
output_format="nifti",
save_reference_dicom=True,
reference_dicom_name="reference.dcm",
)
result = downloader.download_series(
study_uid="1.2.3",
series_uid="1.2.3.4",
output_dir="downloads",
)The series folder then contains:
downloads/{download_id}/
1.2.3.4.nii.gz
reference.dcmUse this when downstream tools work with NIfTI but you still want one original DICOM file for PatientID, acquisition metadata, frame of reference, or audit checks. If an existing NIfTI is skipped with skip_existing=True, Fyron does not contact the DICOMweb server and cannot backfill the reference file; rerun with skip_existing=False to create it.
For repeated download jobs, prefer constructor-level configuration:
downloader = DICOMDownloader(
dicom_web_url="https://pacs.example.org/dicomweb",
output_format="nifti",
save_reference_dicom=True,
reference_dicom_name="meta.dcm",
)For one-off DataFrame downloads, you can override the reference-DICOM behavior directly on the batch call without mutating the downloader:
results = downloader.download_from_dataframe(
df=imaging_df,
output_dir="downloads",
save_reference_dicom=True,
reference_dicom_name="meta.dcm",
)download_from_df(...) accepts the same arguments. Older scripts that use keep_reference_dicom=True still run with a DeprecationWarning, but new code should use save_reference_dicom=True.
Batch Example
results = downloader.download_from_df(
imaging_df,
output_dir="dicom_out",
study_uid_col="study_instance_uid",
series_uid_col="series_instance_uid",
save_reference_dicom=True,
reference_dicom_name="meta.dcm",
results_csv="dicom_results.csv",
)The input DataFrame should contain one row per requested series unless download_full_study=True.
| Column | Meaning |
|---|---|
study_instance_uid | Study UID used for every request. |
series_instance_uid | Series UID used for per-series downloads. |
| optional label column | Can be used as study_folder_name_col for human-readable full-study folders. |
Study Versus Series Downloads
| Mode | Use when | Folder naming |
|---|---|---|
download_series | You already know the relevant series. | {output_dir}/{download_id} |
download_study | You need all series in a study or do not know the target series. | {output_dir}/{study_download_id} or custom study_folder_name |
download_from_df | A cohort CSV/DataFrame contains UIDs. | One row per result in the returned result table. |
Use output_format="dicom" when later writing DICOM SEG because SEG export needs source-referenced DICOM slices. Use output_format="nifti" when the next step is local image processing, BOA-like processing, or array-based analysis. Use output_format="nifti", save_reference_dicom=True when the analysis should run on NIfTI but metadata provenance still needs one original source DICOM.
Research Decision: DICOM Or NIfTI
| Choice | Use when | Artifact to save |
|---|---|---|
output_format="dicom" | You need source slices, DICOM SEG, or detailed acquisition metadata. | DICOM folder and result CSV |
output_format="nifti" | Downstream image processing works on arrays/volumes. | NIfTI and result CSV |
save_reference_dicom=True | You want NIfTI processing plus one original DICOM header for provenance. | reference.dcm beside the NIfTI |
Always keep the returned result table. It is the bridge between cohort rows, download_id, study/series UIDs, and local files.
CLI Workflow
fyron dicom-download \
--csv imaging.csv \
--study-col study_instance_uid \
--series-col series_instance_uid \
--output-dir dicom_out \
--save-reference-dicom \
--results-csv dicom_results.csvFunction Table
| Function | Required | Optional | Returns |
|---|---|---|---|
DICOMDownloader(...) | URL or env var | auth, output format, compression, workers, reference DICOM | downloader |
download_series(...) | study UID, series UID, output dir | skip existing | DicomResult |
download_study(...) | study UID, output dir | layout, manifests, folder name | list of DicomResult |
download_from_df(...) | DataFrame, output dir | UID columns, full-study mode, CSV output, one-call reference DICOM override | DataFrame/result table |
Return Values
DicomResult contains:
| Field | Meaning |
|---|---|
study_uid | Requested study UID. |
series_uid | Requested or discovered series UID; None only for study-level failures. |
download_id | Deterministic identifier used for result matching. |
path | Output folder path. |
format | dicom or nifti. |
error | None on success or a formatted error string. |
Common Pitfalls
- Use
output_format="dicom"when later writing DICOM SEG; SEG needs original source images. - Keep result manifests with the study cohort.
- Confirm UID columns before a batch download; UID mixups are expensive.
- Start with one test series before scaling to many studies.
- For BOA-style downstream extraction, keep a stable mapping between
download_id, patient ID, study UID, and series UID.
Related Modules
- DICOM for the overview.
- Imaging for local DICOM/NIfTI reading and QC.
- Audit & Provenance for reproducibility manifests.