Beispiel #1
0
    def test_default(self):
        lines = LINES.copy()
        expected_results = RESULTS.copy()

        # Use SBE45 temp and salinity for test. Omit pressure, as we're after
        # surface specific gravity.
        ssg = SeawaterSpecificGravityTransform(
            temp_field='FlowthroughTemp',
            salinity_field='Salinity',
            specific_gravity_name='SpecGravity')
        parse = ParseTransform(definition_path=self.device_filename)

        # value_dict = {}
        # timestamp_dict = {}

        while lines:
            record = parse.transform(lines.pop(0))
            result = ssg.transform(record)
            expected = expected_results.pop(0)
            logging.debug('Got result: %s', result)
            logging.debug('Expected result: %s\n', expected)

            logging.info('Comparing result:\n%s\nwith expected:\n%s',
                         result.fields, expected)
            self.assertRecursiveAlmostEqual(result.fields, expected)
Beispiel #2
0
    def test_error(self):
        p = ParseTransform(field_patterns=[
            '{LF:nc},{LFDepth:of},{LFValid:od},{HF:nc},{HFDepth:of},{HFValid:od},{SoundSpeed:og},{Latitude:f},{Longitude:f}'
        ])
        q = QCFilterTransform(bounds='LFDepth:0:6000,HFDepth:0:5000')

        record = 'knud 2017-11-04T05:12:21.981359Z'
        self.assertEqual(
            q.transform(record),
            'Record passed to QCFilterTransform was neither a dict nor a DASRecord. Type was <class \'str\'>: knud 2017-11-04T05:12:21.981359Z'
        )

        record = p.transform(
            'knud 2017-11-04T05:12:21.981359Z 3.5kHz,5146.29,0,,,,1500,-39.583558,-37.466183'
        )
        self.assertEqual(q.transform(record),
                         'HFDepth: non-numeric value: "None"')
Beispiel #3
0
  def test_default(self):
    lines = LINES.copy()
    expected_results = RESULTS.copy()

    # Use port wind speed, output in m/s
    tw = TrueWindsTransform(course_field='CourseTrue',
                            speed_field='SpeedKt',
                            heading_field='HeadingTrue',
                            wind_dir_field='PortRelWindDir',
                            update_on_fields=['PortRelWindDir'],
                            wind_speed_field='PortRelWindSpeed',
                            true_dir_name='PortTrueWindDir',
                            true_speed_name='PortTrueWindSpeed',
                            apparent_dir_name='PortApparentWindDir',
                            convert_speed_factor=0.5144)
    parse = ParseTransform(
      field_patterns=[
        'PUS,{:nc},{PortRelWindDir:g},{PortRelWindSpeed:g},M,{PortSoundSpeed:g},{PortSonicTemp:g},{PortStatus:d},{Checksum:nc}',
        '$INHDT,{HeadingTrue:f},T*{CheckSum:x}',
        '$INRMC,{GPSTime:f},{GPSStatus:w},{Latitude:nlat},{NorS:w},{Longitude:nlat},{EorW:w},{SpeedKt:f},{CourseTrue:f},{GPSDate:w},{MagneticVar:of},{MagneticVarEorW:ow},{Mode:w}*{Checksum:x}',
      ])

    value_dict = {}
    timestamp_dict = {}

    while lines:
      record = parse.transform(lines.pop(0))

      result_list = tw.transform(record)
      self.assertEqual(type(result_list), list)
      result = result_list[0] if len(result_list) else None
      
      expected = expected_results.pop(0)
      logging.debug('Got result: %s', result)
      logging.debug('Expected result: %s\n', expected)

      if not result or not expected:
        self.assertIsNone(result)
        self.assertIsNone(expected)
      else:
        logging.debug('Comparing result:\n%s\nwith expected:\n%s',
                      result.fields, expected)
        self.assertRecursiveAlmostEqual(result.fields, expected)
Beispiel #4
0
    def test_error(self):
        p = ParseTransform(field_patterns=[
            '{LF:nc},{LFDepth:of},{LFValid:od},{HF:nc},{HFDepth:of},{HFValid:od},{SoundSpeed:og},{Latitude:f},{Longitude:f}'
        ])
        q = ValueFilterTransform(bounds='LFDepth:0:6000,HFDepth:0:5000',
                                 log_level=logging.INFO)
        with self.assertLogs(level='INFO') as cm:
            test_str = 'knud 2017-11-04T05:12:21.981359Z 3.5kHz,5146.29,0,,,,1500,-39.583558,-37.466183'
            record = p.transform(test_str)
            record_copy = p.transform(test_str)
            del record_copy['fields']['HFDepth']
            self.assertEqual(q.transform(record), q.transform(record_copy))

        q = ValueFilterTransform(bounds='LFDepth:0:6000,HFDepth:0:5000',
                                 log_level=logging.WARNING)
        with self.assertLogs(level='WARNING') as cm:
            test_str = 'knud 2017-11-04T05:12:21.981359Z 3.5kHz,5146.29,0,,,,1500,-39.583558,-37.466183'
            record = p.transform(test_str)
            record_copy = p.transform(test_str)
            del record_copy['fields']['HFDepth']
            self.assertEqual(q.transform(record), q.transform(record_copy))

        with self.assertLogs(level='WARNING') as cm:
            record = 'knud 2017-11-04T05:12:21.981359Z'
            self.assertEqual(q.transform(record), None)
            self.assertEqual(cm.output, [
                'WARNING:root:Record passed to ValueFilterTransform was neither a dict nor a '
                "DASRecord. Type was <class 'str'>: knud 2017-11-04T05:12:21.981359Z"
            ])

        with self.assertRaises(ValueError):
            ValueFilterTransform(bounds='LFDepth:0:6000,HFDepth:0:5000',
                                 log_level='a string')
Beispiel #5
0
    def test_default(self):
        p = ParseTransform(
            field_patterns=['{Units:d}:{GravValue:d} {GravError:d}'])
        q = ValueFilterTransform(bounds='GravValue:22000:23000,GravError::2')

        record = p.transform('grv1 2017-11-04T05:12:21.273413Z 01:022013 00')
        self.assertEqual(q.transform(record), record)

        record = p.transform('grv1 2017-11-04T05:12:21.273413Z 01:022013 -5')
        self.assertEqual(q.transform(record), record)

        record = p.transform('grv1 2017-11-04T05:12:21.273413Z 01:023013 00')
        record_copy = p.transform(
            'grv1 2017-11-04T05:12:21.273413Z 01:023013 00')
        del record_copy['fields']['GravValue']
        self.assertEqual(q.transform(record), q.transform(record_copy))

        record = p.transform('grv1 2017-11-04T05:12:21.273413Z 01:023013 03')
        record_copy = p.transform(
            'grv1 2017-11-04T05:12:21.273413Z 01:023013 03')
        del record_copy['fields']['GravValue']
        del record_copy['fields']['GravError']
        self.assertEqual(q.transform(record), q.transform(record_copy))
Beispiel #6
0
    def test_default(self):
        p = ParseTransform(
            field_patterns=['{Units:d}:{GravValue:d} {GravError:d}'])
        q = QCFilterTransform(bounds='GravValue:22000:23000,GravError::2')

        record = p.transform('grv1 2017-11-04T05:12:21.273413Z 01:022013 00')
        self.assertIsNone(q.transform(record))

        record = p.transform('grv1 2017-11-04T05:12:21.273413Z 01:022013 -5')
        self.assertIsNone(q.transform(record))

        record = p.transform('grv1 2017-11-04T05:12:21.273413Z 01:023013 00')
        self.assertEqual(q.transform(record),
                         'GravValue: 23013 > upper bound 23000')

        record = p.transform('grv1 2017-11-04T05:12:21.273413Z 01:023013 03')

        self.assertEqual(
            q.transform(record).split(';').sort(),
            'GravValue: 23013 > upper bound 23000; GravError: 3 > upper bound 2'
            .split(';').sort())
Beispiel #7
0
      if new_args.regex_filter:
        transforms.append(RegexFilterTransform(new_args.regex_filter))
      if new_args.qc_filter:
        transforms.append(QCFilterTransform(new_args.qc_filter))
      if new_args.parse_nmea:
        transforms.append(
          ParseNMEATransform(
            message_path=all_args.parse_nmea_message_path,
            sensor_path=all_args.parse_nmea_sensor_path,
            sensor_model_path=all_args.parse_nmea_sensor_model_path,
            time_format=all_args.time_format)
        )
      if new_args.parse:
        transforms.append(
          ParseTransform(
            definition_path=all_args.parse_definition_path,
            return_json=all_args.parse_to_json,
            return_das_record=all_args.parse_to_das_record)
        )
      if new_args.aggregate_xml:
        transforms.append(XMLAggregatorTransform(new_args.aggregate_xml))

      if new_args.max_min:
        transforms.append(MaxMinTransform())

      if new_args.count:
        transforms.append(CountTransform())

      if new_args.to_json:
        transforms.append(ToJSONTransform())

      if new_args.to_json_pretty: