Ejemplo n.º 1
0
 def test_evaluate_with_no_broken_rules(self):
     """Test evaluate with is_broken returning False,
     thus resulting in evaluate returning True"""
     when(self.evaluator.rules[0]).is_broken(any()).thenReturn(False)
     when(self.evaluator.rules[1]).is_broken(any()).thenReturn(False)
     data = gen_random_data(-1, 2, self.channels)
     self.assertTrue(self.evaluator.evaluate(data))
Ejemplo n.º 2
0
def random_data(
        encoder=_DefaultEncoder(), low=-1000, high=1000, channel_count=25):
    """Generates random EEG-like data encoded according to the provided encoder.

    Returns
    -------
        packet of data, which decodes into a list of floats in the range low
            to high with channel_count number of items.
    """

    while True:
        sensor_data = gen_random_data(low, high, channel_count)
        yield encoder.encode(sensor_data)
Ejemplo n.º 3
0
def sample_raw_data(
        trigger_seq: List[Tuple[str, str]] = [],
        first_trg_time: int = 100,
        trigger_interval: int = 10,
        daq_type: str = 'TestStream',
        sample_rate: int = 300,
        ch_names: List[str] = ['c1', 'c2', 'c3']) -> Tuple[str, List[float]]:
    """Helper function for creating mock data that looks like the raw_data.csv
    output. Adds trigger data to the TRG column at the specified interval.

    Parameters:
    -----------
        trigger_seq: list of tuples with the stimulus, targetness.
        first_trg_time: first time in the data where a trigger should appear.
        trigger_interval: set interval at which subsequent triggers should be
                    displayed
        daq_type - metadata written to the raw_data file.
        sample_rate - metadata written to the raw_data file for sample rate
            in hz.
    Returns:
    --------
        content: str, trigger_times: list(float)
    """
    # Set up the trigger times
    trigger_times = []
    triggers_by_time = {}
    for i in range(len(trigger_seq)):
        ts = first_trg_time + (i * trigger_interval)
        trigger_times.append(ts)
        trg_val = trigger_seq[i][0]
        triggers_by_time[ts] = trg_val

    # Mock the raw_data file
    sep = '\r\n'
    meta = sep.join([f'daq_type,{daq_type}', 'sample_rate,{sample_rate}'])
    header = 'timestamp,' + ','.join(ch_names) + ',TRG'

    data = []
    n_channels = len(ch_names)
    for i in range(1000):
        timestamp = i + 10.0
        channel_data = list(map(str, gen_random_data(-1000, 1000, n_channels)))
        trg = triggers_by_time.get(timestamp, NONE_VALUES[0])
        data.append(','.join([str(timestamp), *channel_data, trg]))

    content = sep.join([meta, header, *data])
    return content, trigger_times
Ejemplo n.º 4
0
def sample_data(rows: int = 1000, ch_names: List[str] = None) -> str:
    """Creates sample data to be written as a raw_data.csv file

    rows - number of sample rows to generate
    ch_names - channel names
    """
    if not ch_names:
        ch_names = ['c1', 'c2', 'c3']
    # Mock the raw_data file
    sep = '\n'
    meta = sep.join([f'daq_type,LSL', 'sample_rate,256.0'])
    header = 'timestamp,' + ','.join(ch_names) + ',TRG'

    data = []
    for i in range(rows):
        channel_data = gen_random_data(low=-1000,
                                       high=1000,
                                       channel_count=len(ch_names))
        columns = chain([str(i)], map(str, channel_data), ['0.0'])
        data.append(','.join(columns))

    return sep.join([meta, header, *data])
Ejemplo n.º 5
0
 def test_high_voltage_passing_signal(self):
     """Test generated signal that is consistently below threshold"""
     data = gen_random_data(-0.5, 0.5, self.channels)
     self.assertFalse(self.highvoltage_rule.is_broken(data))
Ejemplo n.º 6
0
 def test_high_voltage_failing_signal(self):
     """Test generated signal with one data point above threshold """
     data = gen_random_data(-5, 0, self.channels)
     # ascertain that at least one random datapoint is above threshold to test np.amax edgecase
     data[np.random.randint(self.channels)] = 1.5
     self.assertTrue(self.highvoltage_rule.is_broken(data))
Ejemplo n.º 7
0
 def test_low_voltage_failing_signal(self):
     """Test generated sub threshold signal against low voltage"""
     data = gen_random_data(1, 5, self.channels)
     # ascertain that at least one random datapoint is below threshold to test np.amin edgecase
     data[np.random.randint(self.channels)] = -1.5
     self.assertTrue(self.lowvoltage_rule.is_broken(data))