Exemple #1
0
    def test_opening_existing_filename_overwrite(self, filename):
        """
        Tests that we can overwrite an existing filename if we use the overwrite parameter.
        """
        # create a blank file
        f = open(filename, mode='w')
        f.close()

        sample_rate = 1.e6
        baseline = 0.2
        n = 5000

        data_should_be = np.zeros(n) + baseline

        create_specified_data(filename=filename,
                              n=n,
                              sample_rate=sample_rate,
                              baseline=baseline,
                              noise_scale=0.0,
                              events=[],
                              overwrite=True)

        _test_params_equality(self,
                              filename=filename,
                              data_should_be=data_should_be,
                              sample_rate=sample_rate)
Exemple #2
0
    def test_noise_no_events(self, filename):
        """
        Tests that noise is added correctly.
        """
        sample_rate = 1.e5
        baseline = 1.0
        n = 100000
        noise_scale = 1.

        create_specified_data(filename=filename, n=n, sample_rate=sample_rate, baseline=baseline,
                              noise_scale=noise_scale, events=[])

        reader = get_reader_from_filename(filename)
        data_all = reader.get_all_data()
        data = data_all[0]
        reader.close()

        self.assertEqual(n, data.size, "Unexpected array size. Wanted {0}, got {1}.".format(n, data.size))
        decimal = 1
        mean = np.mean(data)
        self.assertAlmostEqual(baseline, mean, decimal,
                               "Unexpected baseline. Wanted {0}, got {1}. Tested to {2} decimals.".format(baseline,
                                                                                                          mean,
                                                                                                          decimal))
        decimal = 1
        std_dev = np.std(data)
        self.assertAlmostEqual(noise_scale, std_dev, decimal,
                               msg="Unexpected stddev. Wanted{0}, got {1}. Tested to {2} decimals.".format(noise_scale,
                                                                                                           std_dev,
                                                                                                           decimal))
Exemple #3
0
    def test_no_noise_specified_events(self, filename):
        """
        Tests that with no noise and specified events we get the right matrix
        """
        sample_rate = 1.e6
        baseline = 1.0
        n = 5000

        events = [[100, 200., -.5], [1000, 500, -1.0], [3000, 1000, .2]]

        data_should_be = np.zeros(n) + baseline

        # add in the events to the data_should_be
        for event in events:
            data_should_be[event[0]:event[0] + event[1]] += event[2]

        create_specified_data(filename=filename,
                              n=n,
                              sample_rate=sample_rate,
                              baseline=baseline,
                              noise_scale=0.0,
                              events=events)

        _test_params_equality(self,
                              filename=filename,
                              data_should_be=data_should_be,
                              sample_rate=sample_rate)
Exemple #4
0
    def test_simple_baseline(self, filename):
        """
        Tests that a no noise, no event returns just a baseline.
        """
        sample_rate = 1.e6
        baseline = 0.2
        n = 5000

        data_should_be = np.zeros(n) + baseline

        create_specified_data(filename=filename, n=n, sample_rate=sample_rate, baseline=baseline, noise_scale=0.0,
                              events=[])

        _test_params_equality(self, filename=filename, data_should_be=data_should_be, sample_rate=sample_rate)
Exemple #5
0
    def test_opening_existing_filename_overwrite(self, filename):
        """
        Tests that we can overwrite an existing filename if we use the overwrite parameter.
        """
        # create a blank file
        f = open(filename, mode='w')
        f.close()

        sample_rate = 1.e6
        baseline = 0.2
        n = 5000

        data_should_be = np.zeros(n) + baseline

        create_specified_data(filename=filename, n=n, sample_rate=sample_rate, baseline=baseline, noise_scale=0.0,
                              events=[], overwrite=True)

        _test_params_equality(self, filename=filename, data_should_be=data_should_be, sample_rate=sample_rate)
Exemple #6
0
    def test_no_noise_specified_events(self, filename):
        """
        Tests that with no noise and specified events we get the right matrix
        """
        sample_rate = 1.e6
        baseline = 1.0
        n = 5000

        events = [[100, 200., -.5], [1000, 500, -1.0], [3000, 1000, .2]]

        data_should_be = np.zeros(n) + baseline

        # add in the events to the data_should_be
        for event in events:
            data_should_be[event[0]:event[0] + event[1]] += event[2]

        create_specified_data(filename=filename, n=n, sample_rate=sample_rate, baseline=baseline, noise_scale=0.0,
                              events=events)

        _test_params_equality(self, filename=filename, data_should_be=data_should_be, sample_rate=sample_rate)
Exemple #7
0
    def test_simple_baseline(self, filename):
        """
        Tests that a no noise, no event returns just a baseline.
        """
        sample_rate = 1.e6
        baseline = 0.2
        n = 5000

        data_should_be = np.zeros(n) + baseline

        create_specified_data(filename=filename,
                              n=n,
                              sample_rate=sample_rate,
                              baseline=baseline,
                              noise_scale=0.0,
                              events=[])

        _test_params_equality(self,
                              filename=filename,
                              data_should_be=data_should_be,
                              sample_rate=sample_rate)
Exemple #8
0
    def test_noise_no_events(self, filename):
        """
        Tests that noise is added correctly.
        """
        sample_rate = 1.e5
        baseline = 1.0
        n = 100000
        noise_scale = 1.

        create_specified_data(filename=filename,
                              n=n,
                              sample_rate=sample_rate,
                              baseline=baseline,
                              noise_scale=noise_scale,
                              events=[])

        reader = get_reader_from_filename(filename)
        data_all = reader.get_all_data()
        data = data_all[0]
        reader.close()

        self.assertEqual(
            n, data.size,
            "Unexpected array size. Wanted {0}, got {1}.".format(n, data.size))
        decimal = 1
        mean = np.mean(data)
        self.assertAlmostEqual(
            baseline, mean, decimal,
            "Unexpected baseline. Wanted {0}, got {1}. Tested to {2} decimals."
            .format(baseline, mean, decimal))
        decimal = 1
        std_dev = np.std(data)
        self.assertAlmostEqual(
            noise_scale,
            std_dev,
            decimal,
            msg="Unexpected stddev. Wanted{0}, got {1}. Tested to {2} decimals."
            .format(noise_scale, std_dev, decimal))
Exemple #9
0
    def test_output_filename_correct(self, filename):
        create_specified_data(filename, n=100, sample_rate=10)

        self.assertTrue(os.path.exists(filename))
Exemple #10
0
    def test_output_filename_correct(self, filename):
        create_specified_data(filename, n=100, sample_rate=10)

        self.assertTrue(os.path.exists(filename))