sjoerdk / dicomtrolley

Retrieve medical images via WADO, MINT, RAD69 and DICOM-QR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add downloader option to ignore errors

sjoerdk opened this issue · comments

  • dicomtrolley version: 3

Description

trolley.download([targets]) will raise an exception if anything goes wrong downloading any of the targets. In addition, trolley.download[series] will raise an exception if any of the slices in series cannot be downloaded.

This behaviour is correct and usually what you want. Partial downloads with exceptions should generally be avoided. There are certain situations however when you would want to download 'any slice that you can' even if part of the data is corrupted. This is useful when debugging or if you know that the corrupted part of the data is not of interest and fixing this in the DICOM server would be slow or difficult.

Suggested solution

Add an option somewhere to force download and ignore errors.
Questions to answer:

  • What should this option be named? Force? What is the rsync option called?
  • rad69 already has a similar system. See whether this can be generalized
  • Where should this option live? In trolley.download()? or downloader init?
    Notes:
  • This option should not be default.

Potentially leave this option out completely to not clutter the API.

Instead, create a Storage class that instead of saving to disk, calls a callback with each dataset as argument. This can then be reasonably easily use in some custom code that just excepts whatever exception you want.

Or just use fetch_all_datasets with an except clause. That requires no new code..

pseudo code:

for ds in trolley.fetch_all_datasets(studies):  # obtain Dataset for each instance
    try:
         ds.save_as(f'/tmp/{ds.SOPInstanceUID}.dcm')
    except WhateverError as e:
         print(f"Skipping {ds} because of {e}")

Done