Tools for preprocessing DICOM metadata imported using `dicomtools.core` into in a `pandas.DataFrame` in preparation for training RandomForest classifier to predict series type.

exclude_other[source]

exclude_other(df)

get_series_fp[source]

get_series_fp(fn)

compute_plane[source]

compute_plane(row)

Computes the plane of imaging from the direction cosines provided in the ImageOrientationPatient field. The format of the values in this field is: [x1, y1, z1, x2, y2, z2], which correspond to the direction cosines for the first row and column of the image pixel data.

detect_contrast[source]

detect_contrast(row)

row = {'SeriesDescription': 'ax t1 +c', 'ContrastBolusAgent': 'Gadavist'}
row1 = {'SeriesDescription': 'ax t1', 'ContrastBolusAgent': np.nan}
row2 = {'SeriesDescription': 'ax t1', 'ContrastBolusAgent': 'Gadavist'} # example of discordant SD
row3 = {'SeriesDescription': 'AX T1 POST', 'ContrastBolusAgent': np.nan} # also discordant

assert detect_contrast(row) == 1
assert detect_contrast(row1) == 0
assert detect_contrast(row2) == 1
assert detect_contrast(row3) == 1

rm_extra_info[source]

rm_extra_info(t)

Remove extraneous info in closures

assert rm_extra_info('ax t1 <mpr>') == 'ax t1'
assert rm_extra_info('adc (mm^2/s)') == 'adc'
assert rm_extra_info('ax t1 [date]') == 'ax t1'
def test_find_seq(sd, targ): assert _find_seq(sd) == targ

test_find_seq('ax t1 +c', 't1')
test_find_seq('ax t1 flair +c', 't1')
test_find_seq('ax t2 +c', 't2')
test_find_seq('ax t2 flair', 'flair')
test_find_seq('ax t2 gre', 'swi')
test_find_seq('ax swi', 'swi')
test_find_seq('ax susc', 'swi')
test_find_seq('adc', 'adc')
test_find_seq('eadc', 'other')
test_find_seq('ax dwi', 'dwi')
test_find_seq('ax diffusion', 'dwi')
test_find_seq('ax spgr +c', 'spgr')
test_find_seq('localizer', 'loc')
assert _extract_label('ax t1 +c') == 't1'
assert _extract_label('ax t1 +c [date]') == 't1'
assert _extract_label('<MPR Thick Range>') == 'unknown'

extract_labels[source]

extract_labels(df)

Extract candidate labels from Series Descriptions and computed plane

make_binary_cols[source]

make_binary_cols(df, cols)

rescale_cols[source]

rescale_cols(df, cols)

get_dummies[source]

get_dummies(df, cols=['ScanningSequence', 'SequenceVariant', 'ScanOptions'], prefix=['seq', 'var', 'opt'])

preprocess[source]

preprocess(df, keepers=['fname', 'PatientID', 'StudyInstanceUID', 'StudyID', 'SeriesInstanceUID', 'SeriesNumber', 'SeriesDescription', 'AcquisitionNumber', 'InstanceNumber', 'ImageOrientationPatient', 'ScanningSequence', 'SequenceVariant', 'ScanOptions', 'MRAcquisitionType', 'AngioFlag', 'SliceThickness', 'RepetitionTime', 'EchoTime', 'EchoTrainLength', 'PixelSpacing', 'ContrastBolusAgent', 'InversionTime', 'DiffusionBValue'], dummies=['ScanningSequence', 'SequenceVariant', 'ScanOptions'], d_prefixes=['seq', 'var', 'opt'], binarize=['MRAcquisitionType', 'AngioFlag', 'ContrastBolusAgent', 'DiffusionBValue'], rescale=['SliceThickness', 'RepetitionTime', 'EchoTime', 'EchoTrainLength', 'PixelSpacing', 'InversionTime'])

Preprocess metadata for Random Forest classifier to predict sequence type