Esempio n. 1
0
def _test_number_of_events_help(name):
    # Need to seed, otherwise each process will generate the same random data!
    np.random.seed()
    # Check that setting the event rate gives correct number of events.
    seconds = 5.
    sample_rate = 1.e6
    baseline = 1.
    event_rate = 50.
    event_duration = stats.norm(loc=100.e-6, scale=5.e-6)
    event_depth = stats.norm(loc=-1., scale=.05)
    noise = stats.norm(scale=0.02)
    # create a list of file_names so we can average the number of events.
    if os.path.exists(name):
        os.remove(name)
    n_e_r = create_random_data(filename=name, seconds=seconds, sample_rate=sample_rate,
                               baseline=baseline, noise=noise,
                               event_rate=event_rate, event_durations=event_duration,
                               event_depths=event_depth)

    save_file_name = name[:-len('.h5')] + '_Events.h5'
    if os.path.exists(save_file_name):
        os.remove(save_file_name)
    event_database = find_events([name], save_file_names=[save_file_name])[0]

    ed = EventDatabase(event_database)

    n_events_found = ed.get_event_count()

    os.remove(name)
    ed.close()
    os.remove(event_database)

    return n_e_r, n_events_found, name
Esempio n. 2
0
    def test_event_params(self, filename):
        """
        Tests that setting the event depth and duration give correct values.
        """
        seconds = 5.
        sample_rate = 1.e6
        baseline = 10.
        event_rate = 100.
        event_duration_loc = 1.e-4
        event_duration_scale = 5.e-6
        event_duration = stats.norm(loc=event_duration_loc, scale=event_duration_scale)
        event_depth_loc = -1.
        event_depth_scale = .05
        event_depth = stats.norm(loc=-1., scale=.05)
        noise = stats.norm(scale=0.01)

        n_events_returned = create_random_data(filename, seconds=seconds, sample_rate=sample_rate,
                                               baseline=baseline, event_rate=event_rate,
                                               event_durations=event_duration, event_depths=event_depth,
                                               noise=noise)

        save_file_name = filename[:-len('.h5')] + 'Events.h5'
        if os.path.exists(save_file_name):
            os.remove(save_file_name)
        event_database = find_events([filename], save_file_names=[save_file_name])[0]

        ed = EventDatabase(event_database)

        count = ed.get_event_count()
        count_should_be = event_rate * seconds
        diff = abs(count - count_should_be)
        self.assertLessEqual(diff, 100, "Unexpected number of events. "
                                        "Expected {0}, was {1}.".format(count_should_be, count))

        table_sample_rate = ed.get_sample_rate()
        durations = [x['event_length'] / table_sample_rate for x in ed.get_event_table().iterrows()]
        depths = [x['current_blockage'] for x in ed.get_event_table().iterrows()]

        mean_duration = np.mean(durations)
        self.assertAlmostEqual(event_duration_loc, mean_duration, 5, "Unexpected mean event duration.  "
                                                                     "Wanted {0}, got {1}.".format(event_duration_loc,
                                                                                                   mean_duration))

        mean_depth = np.mean(depths)
        self.assertAlmostEqual(event_depth_loc, mean_depth, 1, "Unexpected mean event depth. "
                                                               "Wanted {0}, got {1}.".format(event_depth_loc,
                                                                                             mean_depth))

        ed.close()
        os.remove(event_database)
Esempio n. 3
0
def _test_number_of_events_help(name):
    # Need to seed, otherwise each process will generate the same random data!
    np.random.seed()
    # Check that setting the event rate gives correct number of events.
    seconds = 5.
    sample_rate = 1.e6
    baseline = 1.
    event_rate = 50.
    event_duration = stats.norm(loc=100.e-6, scale=5.e-6)
    event_depth = stats.norm(loc=-1., scale=.05)
    noise = stats.norm(scale=0.02)
    # create a list of file_names so we can average the number of events.
    if os.path.exists(name):
        os.remove(name)
    n_e_r = create_random_data(filename=name,
                               seconds=seconds,
                               sample_rate=sample_rate,
                               baseline=baseline,
                               noise=noise,
                               event_rate=event_rate,
                               event_durations=event_duration,
                               event_depths=event_depth)

    save_file_name = name[:-len('.h5')] + '_Events.h5'
    if os.path.exists(save_file_name):
        os.remove(save_file_name)
    event_database = find_events([name], save_file_names=[save_file_name])[0]

    ed = EventDatabase(event_database)

    n_events_found = ed.get_event_count()

    os.remove(name)
    ed.close()
    os.remove(event_database)

    return n_e_r, n_events_found, name
Esempio n. 4
0
    def test_event_params(self, filename):
        """
        Tests that setting the event depth and duration give correct values.
        """
        seconds = 5.
        sample_rate = 1.e6
        baseline = 10.
        event_rate = 100.
        event_duration_loc = 1.e-4
        event_duration_scale = 5.e-6
        event_duration = stats.norm(loc=event_duration_loc,
                                    scale=event_duration_scale)
        event_depth_loc = -1.
        event_depth_scale = .05
        event_depth = stats.norm(loc=-1., scale=.05)
        noise = stats.norm(scale=0.01)

        n_events_returned = create_random_data(filename,
                                               seconds=seconds,
                                               sample_rate=sample_rate,
                                               baseline=baseline,
                                               event_rate=event_rate,
                                               event_durations=event_duration,
                                               event_depths=event_depth,
                                               noise=noise)

        save_file_name = filename[:-len('.h5')] + 'Events.h5'
        if os.path.exists(save_file_name):
            os.remove(save_file_name)
        event_database = find_events([filename],
                                     save_file_names=[save_file_name])[0]

        ed = EventDatabase(event_database)

        count = ed.get_event_count()
        count_should_be = event_rate * seconds
        diff = abs(count - count_should_be)
        self.assertLessEqual(
            diff, 100, "Unexpected number of events. "
            "Expected {0}, was {1}.".format(count_should_be, count))

        table_sample_rate = ed.get_sample_rate()
        durations = [
            x['event_length'] / table_sample_rate
            for x in ed.get_event_table().iterrows()
        ]
        depths = [
            x['current_blockage'] for x in ed.get_event_table().iterrows()
        ]

        mean_duration = np.mean(durations)
        self.assertAlmostEqual(
            event_duration_loc, mean_duration, 5,
            "Unexpected mean event duration.  "
            "Wanted {0}, got {1}.".format(event_duration_loc, mean_duration))

        mean_depth = np.mean(depths)
        self.assertAlmostEqual(
            event_depth_loc, mean_depth, 1, "Unexpected mean event depth. "
            "Wanted {0}, got {1}.".format(event_depth_loc, mean_depth))

        ed.close()
        os.remove(event_database)