Пример #1
0
 def test_get_txt_data(self):
     """Verify retrieval of ASCII delimited data"""
     sample_data_file = os.path.join(os.path.dirname(__file__), 'support_files',
                                     '1.25 from hole Single Column.asc')
     assert(os.path.exists(sample_data_file))
     import_params = {'delimiter': None}
     expected_data = np.loadtxt(sample_data_file, delimiter=import_params['delimiter'])
     retrieved_data = dataio.get_txt_data(sample_data_file, **import_params)
     self.assertTrue(np.array_equal(expected_data, retrieved_data))
Пример #2
0
 def test_get_txt_data(self):
     """Verify retrieval of ASCII delimited data"""
     sample_data_file = os.path.join(os.path.dirname(__file__),
                                     'support_files',
                                     '1.25 from hole Single Column.asc')
     assert (os.path.exists(sample_data_file))
     import_params = {'delimiter': None}
     expected_data = np.loadtxt(sample_data_file,
                                delimiter=import_params['delimiter'])
     retrieved_data = dataio.get_txt_data(sample_data_file, **import_params)
     self.assertTrue(np.array_equal(expected_data, retrieved_data))
Пример #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