Exemplo n.º 1
0
    def test_time_validation(self):
        trivial_selector = iisr_io.SeriesSelector()
        start_selector = iisr_io.SeriesSelector(
            start_time=datetime(2015, 6, 6))
        stop_selector = iisr_io.SeriesSelector(stop_time=datetime(2015, 6, 8))
        start_stop_selector = iisr_io.SeriesSelector(
            start_time=datetime(2015, 6, 6), stop_time=datetime(2015, 6, 8))

        dtime = datetime(2015, 1, 1)
        self.assertTrue(trivial_selector.validate_time_mark(dtime))
        self.assertFalse(start_selector.validate_time_mark(dtime))
        self.assertTrue(stop_selector.validate_time_mark(dtime))
        self.assertFalse(start_stop_selector.validate_time_mark(dtime))

        dtime = datetime(2015, 6, 7)
        self.assertTrue(trivial_selector.validate_time_mark(dtime))
        self.assertTrue(start_selector.validate_time_mark(dtime))
        self.assertTrue(stop_selector.validate_time_mark(dtime))
        self.assertTrue(start_stop_selector.validate_time_mark(dtime))

        dtime = datetime(2015, 8, 6)
        self.assertTrue(trivial_selector.validate_time_mark(dtime))
        self.assertTrue(start_selector.validate_time_mark(dtime))
        self.assertFalse(stop_selector.validate_time_mark(dtime))
        self.assertFalse(start_stop_selector.validate_time_mark(dtime))
Exemplo n.º 2
0
 def series_filter(self) -> iisr_io.SeriesSelector:
     filter_parameters = {}
     if self.frequencies is not None:
         filter_parameters['frequencies'] = self.frequencies
     if self.channels is not None:
         filter_parameters['channels'] = self.channels
     return iisr_io.SeriesSelector(**filter_parameters)
Exemplo n.º 3
0
    def test(self):
        trivial_filter = iisr_io.SeriesSelector()

        valid_params = {
            'frequencies': [Frequency(155.5, 'MHz'),
                            Frequency(159.5, 'MHz')],
            'channels': [Channel(0), Channel(2)],
            'pulse_lengths': [TimeUnit(200, 'us'),
                              TimeUnit(700, 'us')],
            'pulse_types': None,
        }
        specific_filter = iisr_io.SeriesSelector(**valid_params)

        for fr, ch, len_ in it.product([155500, 159500], [0, 2], [200, 700]):
            raw_params = get_test_raw_parameters(freq=fr,
                                                 pulse_len=len_,
                                                 channel=ch)
            self.assertTrue(trivial_filter.validate_parameters(raw_params))
            self.assertTrue(specific_filter.validate_parameters(raw_params),
                            'fr={}, ch={}, len_={}'.format(fr, ch, len_))

        for fr, ch, len_ in it.product([154000, 159400], [1, 3], [900]):
            raw_params = get_test_raw_parameters(freq=fr,
                                                 pulse_len=len_,
                                                 channel=ch)
            self.assertTrue(trivial_filter.validate_parameters(raw_params))
            self.assertFalse(specific_filter.validate_parameters(raw_params),
                             'fr={}, ch={}, len_={}'.format(fr, ch, len_))

        # Channel and type
        valid_params = {
            'channels': [Channel(0), Channel(1)],
            'pulse_types': 'long',
        }
        specific_filter = iisr_io.SeriesSelector(**valid_params)
        for fr, ch, len_ in it.product([155500, 159500], [0, 2], [200, 700]):
            raw_params = get_test_raw_parameters(freq=fr,
                                                 pulse_len=len_,
                                                 channel=ch)

            self.assertEqual(ch == 0,
                             specific_filter.validate_parameters(raw_params),
                             'fr={}, ch={}, len_={}'.format(fr, ch, len_))
Exemplo n.º 4
0
    def test_read_with_selector(self):
        valid_params = {
            'frequencies': [Frequency(155.5, 'MHz')],
            'channels': [Channel(0), Channel(2)],
            'pulse_lengths': [TimeUnit(200, 'us')],
            'pulse_types': ['long'],
        }
        filter_ = iisr_io.SeriesSelector(**valid_params)

        test_parameters = []
        for fr, ch, len_ in it.product([155.5, 159.5], [0, 2], [200, 700]):
            test_parameters.append(
                get_test_parameters(freq=fr, pulse_len=len_, channel=ch))

        with tempfile.TemporaryDirectory() as dirname:
            test_filepath = Path(dirname) / DUMMY_FILE_NAME

            with iisr_io.open_data_file(test_filepath, 'w') as data_file:
                for param in test_parameters:
                    n_samples = param.n_samples
                    test_quad_i = np.random.randint(-2**15 + 1, 2**15,
                                                    n_samples)
                    test_quad_q = np.random.randint(-2**15 + 1, 2**15,
                                                    n_samples)
                    test_quadratures = test_quad_i + 1j * test_quad_q

                    series = iisr_io.TimeSeries(DEFAULT_DATETIME, param,
                                                test_quadratures)
                    package = iisr_io.TimeSeriesPackage(
                        DEFAULT_DATETIME, [series])
                    data_file.write(package)

            # Check if selector correct
            with iisr_io.open_data_file(test_filepath,
                                        series_selector=filter_) as reader:
                series_list = list(reader)

            self.assertEqual(len(series_list), 2)
            for series in series_list:
                self.assertEqual(series.parameters.frequency,
                                 valid_params['frequencies'][0])
                self.assertIn(series.parameters.channel,
                              valid_params['channels'])
                self.assertEqual(series.parameters.pulse_length,
                                 valid_params['pulse_lengths'][0])
                self.assertEqual(series.parameters.pulse_type,
                                 valid_params['pulse_types'][0])