convert_mri_DICOM_to_NIfTY.py 848 B

1234567891011121314151617181920212223242526272829303132
  1. """Pipeline to convert DICOM to NIfTY."""
  2. import logging
  3. from almirah import index
  4. from almirah import Layout
  5. from almirah import Specification
  6. from almirah.utils.convert import convert
  7. logging.basicConfig(filename="logs/convert_mri_to_NIfTI.log", level=logging.DEBUG)
  8. logging.getLogger().addHandler(logging.StreamHandler())
  9. SRC = ""
  10. DST = ""
  11. source_spec = Specification.create_from_file("configs/specifications/sourcedata.yaml")
  12. src_lay = Layout(root=SRC, specification_name="sourcedata")
  13. bids_spec = Specification.create_from_file("configs/specifications/bids.yaml")
  14. dst_lay = Layout(root=DST, specification_name="bids")
  15. src_lay.index(f"{SRC}/mri")
  16. index.commit()
  17. files = src_lay.query(sourcetype="mri", extension=".dcm")
  18. convert(
  19. files,
  20. "NIfTI",
  21. dst_lay,
  22. logging="DEBUG",
  23. config="configs/converters/dcm2bids.json",
  24. )