Skip to content

Commit

Permalink
Merge pull request #2 from scitran-apps/v1.1.0
Browse files Browse the repository at this point in the history
Account for fieldname diff in non-default config
  • Loading branch information
lmperry authored Feb 1, 2017
2 parents bf97fe9 + 02f46bc commit 4946827
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# Builds the container.

CONTAINER=scitran/dcm-convert
CONTAINER=scitran/dcm-convert:v1.1.0
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
docker build --no-cache --tag $CONTAINER $DIR
56 changes: 14 additions & 42 deletions dcm-convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@ def dicom_convert(fp, outbase=None):
# CONFIG: If there is a config file then load that, else load the manifest and read the default values.
if os.path.exists('/flywheel/v0/config.json'):
config_file = '/flywheel/v0/config.json'
MANIFEST=False
else:
config_file = '/flywheel/v0/manifest.json'
MANIFEST=True

with open(config_file, 'r') as jsonfile:
config = json.load(jsonfile)
config = config.pop('config')

if MANIFEST:
convert_montage = config['convert_montage']['default']
convert_nifti = config['convert_nifti']['default']
convert_png = config['convert_png']['default']
else:
convert_montage = config['convert_montage']
convert_nifti = config['convert_nifti']
convert_png = config['convert_png']


# CONVERSION
log.info('converting dicom file %s' % fp)
Expand All @@ -49,57 +60,18 @@ def dicom_convert(fp, outbase=None):
final_results = []
# create nifti and Montage
if ds.scan_type != 'screenshot':
if config['convert_montage']['default']:
if convert_montage:
log.info('performing non screenshot conversion, montage')
final_results += scidata.write(ds, ds.data, outbase=outbase + '_montage', filetype='montage', voxel_order='LPS') # always LPS
if config['convert_nifti']['default']:
if convert_nifti:
log.info('performing non screenshot conversion, nifti')
final_results += scidata.write(ds, ds.data, outbase=outbase + '_nifti', filetype='nifti') # no reorder

elif ds.scan_type == 'screenshot':
if config['convert_png']['default']:
if convert_png:
log.info('performing screenshot conversion, png')
final_results += scidata.write(ds, ds.data, outbase=outbase + '_png', filetype='png')


# Write metadata file
output_files = os.listdir(os.path.dirname(outbase))
files = []
if len(output_files) > 0:
for f in output_files:

fdict = {}
fdict['name'] = f

if f.endswith('nifti.nii.gz'):
ftype = 'nifti'

elif f.endswith('bvec'):
ftype = 'bvec'

elif f.endswith('bval'):
ftype = 'bval'

elif f.endswith('montage.zip'):
ftype = 'montage'

elif f.endswith('.png'):
ftype = 'screenshot'

else:
ftype = 'None'

fdict['type'] = ftype
files.append(fdict)

metadata = {}
metadata['acquisition'] = {}
metadata['acquisition']['files'] = files

with open(os.path.join(os.path.dirname(outbase),'.metadata.json'), 'w') as metafile:
json.dump(metadata, metafile)
else:
log.info('No output files generated.')
return final_results

if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": "https://github.com/scitran-apps/dcm-convert",
"license": "Apache-2.0",
"flywheel": "0",
"version": "1.0.0",
"version": "1.1.0",
"config": {
"convert_montage": {
"description": "Convert selected DICOM archive to MONTAGE format. (Default=true)",
Expand All @@ -34,6 +34,6 @@
}
},
"custom": {
"docker-image": "scitran/dcm-convert:v1.0.0"
"docker-image": "scitran/dcm-convert:v1.1.0"
}
}

0 comments on commit 4946827

Please sign in to comment.