Exemplo n.º 1
0
 def test_nonexistent_input_file(self):
     # Read in the TAFFmat file under test
     input_file_basename = os.path.join(
         self.test_taffmat_directory,
         'nonexistent_taffmat_file.DAT')
     self.assertFalse(
         taffmat.read_taffmat(input_file_basename))
Exemplo n.º 2
0
    def test_writing_dat_file_slice(self):
        '''
        Write the first 1000 elements of data_array to a new .dat and .hdr
        file.  Then read the new .dat file and make sure it matches the first
        1000 elements of the original data_array
        '''

        slice_output_base_filename = os.path.join(
            self.test_taffmat_directory, 'test_slice_output_taffmat')

        # number_of_samples_in_slice = self.data_array.shape[1]
        number_of_samples_in_slice = 1000
        original_data_array = np.copy(
            self.data_array[:, 0:number_of_samples_in_slice])

        # Write the TAFFmat data slice
        taffmat.write_taffmat_slice(
            self.data_array, self.header_data,
            slice_output_base_filename, 0, number_of_samples_in_slice-1)

        # Read the TAFFmat data slice
        slice_data_array, slice_time_vector, slice_header_data = \
            taffmat.read_taffmat(slice_output_base_filename)

        # Confirm the proper number of samples exist
        self.assertEqual(
            slice_data_array.shape[1],
            number_of_samples_in_slice,
            'Number of samples in slice incorrect.')

        np.testing.assert_array_equal(
            slice_data_array,
            original_data_array,
            'The sliced data array does not equal the original data array.')
Exemplo n.º 3
0
 def test_input_file_with_dat_extension(self):
     # Read in the TAFFmat file under test
     input_file_basename = os.path.join(
         self.test_taffmat_directory,
         'UTEST001.DAT')
     data_array, time_vector, header_data = \
         taffmat.read_taffmat(input_file_basename)
     np.testing.assert_array_equal(
         data_array, self.known_data_array,
         'Incorrectly read data_array using filename with .DAT extension')
Exemplo n.º 4
0
    def setUp(self):
        self.test_taffmat_directory = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            'test_taffmat_files')

        # Read in the TAFFmat file under test
        self.input_base_filename = os.path.join(
            self.test_taffmat_directory, 'UTEST001')
        self.data_array, self.time_vector, self.header_data = \
            taffmat.read_taffmat(self.input_base_filename)
Exemplo n.º 5
0
    def setUp(self):
        self.test_taffmat_directory = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            'test_taffmat_files')

        # Read in the TAFFmat file under test
        self.input_base_filename = os.path.join(
            self.test_taffmat_directory, 'UTEST001')
        self.data_array, self.time_vector, self.header_data = \
            taffmat.read_taffmat(self.input_base_filename)

        # Setup the output_basefilename
        self.output_base_filename = os.path.join(
            self.test_taffmat_directory, 'test_output_taffmat')

        # Write the .dat and .hdr files using taffmat.py
        taffmat.write_taffmat(
            self.data_array, self.header_data, self.output_base_filename)
Exemplo n.º 6
0
    def test_writing_different_dataset_filename(self):
        new_output_base_filename = 'something_different'
        taffmat.write_taffmat(self.data_array,
                              self.header_data,
                              new_output_base_filename)
        data_array, time_vector, header_data = taffmat.read_taffmat(
            new_output_base_filename)
        self.assertEqual(header_data['dataset'],
                         new_output_base_filename.upper())
        new_output_dat, new_output_hdr = \
            self._get_dat_hdr_filenames_from_base(new_output_base_filename)
        try:
            os.remove(new_output_dat)
        except:
            print("Couldn't remove the test dat file.")

        try:
            os.remove(new_output_hdr)
        except:
            print("Couldn't remove the test hdr file.")
Exemplo n.º 7
0
    def setUp(self):
        test_taffmat_directory = os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            'test_taffmat_files')

        # Read in the TAFFmat file under test
        input_file_basename = os.path.join(
            test_taffmat_directory, 'UTEST001')
        self.data_array, self.time_vector, self.header_data = \
            taffmat.read_taffmat(input_file_basename)
        self.beginning_of_raw_data_array = np.array(
            [2959, 6291, 9386, 12121], dtype=np.int16)

        # Read in the known data array and provide the answers
        # for the header file. By having this setup here, we can
        # change to a different test file by simply updating
        # this section instead of searching all through the test code
        known_data_array_input_file = os.path.join(
            test_taffmat_directory, 'utest001_data_array_float64.npy')
        self.known_data_array = np.load(known_data_array_input_file)
        self.known_header = {}
        self.known_header['sampling_frequency_hz'] = 96000
        self.known_header['number_of_series'] = 2
        self.known_header['slope'] = [8e-05, 0.0002]