Ejemplo n.º 1
0
 def test_get_dicom_data(self):
     """Verify retrieval of DICOM / DICONDE data"""
     import dicom
     diconde_folder = os.path.join(os.path.dirname(__file__), 'support_files')
     for root, dirs, files in os.walk(diconde_folder):
         for fname in files:
             dicom_data_file = os.path.join(root, fname)
             basename, ext = os.path.splitext(dicom_data_file)
             # Simple check to ensure we're looking at DICOM files
             if ext.lower() == '.dcm':
                 dicom_data = dicom.read_file(dicom_data_file)
                 dicom_arr = dicom_data.pixel_array
                 retrieved_data = dataio.get_dicom_data(dicom_data_file)
                 self.assertTrue(np.array_equal(dicom_arr, retrieved_data))
Ejemplo n.º 2
0
 def test_get_dicom_data(self):
     """Verify retrieval of DICOM / DICONDE data"""
     import dicom
     diconde_folder = os.path.join(os.path.dirname(__file__),
                                   'support_files')
     for root, dirs, files in os.walk(diconde_folder):
         for fname in files:
             dicom_data_file = os.path.join(root, fname)
             basename, ext = os.path.splitext(dicom_data_file)
             # Simple check to ensure we're looking at DICOM files
             if ext.lower() == '.dcm':
                 dicom_data = dicom.read_file(dicom_data_file)
                 dicom_arr = dicom_data.pixel_array
                 retrieved_data = dataio.get_dicom_data(dicom_data_file)
                 self.assertTrue(np.array_equal(dicom_arr, retrieved_data))
Ejemplo n.º 3
0
def read_data(filename, filetype=None):
    """Attempts to import the specified file based on the provided filetype, or automatically guesses the file format
    based on the file extension if no filetype is given.  Returns the data as a NumPy array if successfully imported as
    a NumPy array if the file contained a single dataset or as a dict if multiple datasets were found."""
    tof_counter = 0
    amp_counter = 0
    waveform_counter = 0
    data = {}
    if filetype is None:
        filetype = get_file_type(filename)
    if filetype is not None and filetype in available_file_types():
        if filetype == 'nditoolbox':
            data = dataio.get_data(filename)
        if filetype == 'winspect':
            raw_data = dataio.get_winspect_data(filename)
            # Handle any files that may have stored multiple datasets of
            # a given type(s)
            for dataset in raw_data:
                dataset_key = os.path.basename(filename)
                if dataset.data_type == 'waveform':
                    dataset_key = 'waveform' + str(waveform_counter)
                    waveform_counter +=1
                elif dataset.data_type == 'amplitude':
                    dataset_key = 'amplitude' + str(amp_counter)
                    amp_counter += 1
                elif dataset.data_type == 'tof': #TODO -confirm SDT files use tof
                    dataset_key = 'tof' + str(tof_counter)
                    tof_counter += 1
                data[dataset_key] = dataset.data
        if filetype == 'csv':
            data = dataio.get_txt_data(filename)
        if filetype == 'image':
            data = dataio.get_img_data(filename, flatten=True)
        if filetype == 'dicom':
            data = dataio.get_dicom_data(filename)
        if filetype == 'utwin':
            raw_data = dataio.get_utwin_data(filename)
            for k in raw_data.keys():
                for idx in range(len(raw_data[k])):
                    data[k + str(idx)] = raw_data[k][idx]
    return data