def test_sanity(self):
        """Sanity check that the numbers coming out make sense."""
        check = SANITY_CHECK.copy()
        expected_results = SANITY_RESULTS.copy()

        tw = TrueWindsTransform(course_field='CourseTrue',
                                speed_field='Speed',
                                heading_field='HeadingTrue',
                                wind_dir_field='RelWindDir',
                                wind_speed_field='RelWindSpeed',
                                true_dir_name='PortTrueWindDir',
                                true_speed_name='PortTrueWindSpeed',
                                apparent_dir_name='PortApparentWindDir')

        while check:
            fields = check.pop(0)
            record = DASRecord(data_id='truw', fields=fields)
            result = tw.transform(record)
            if type(result) is list:
                if len(result):
                    result = result[0]
                else:
                    result is None
            expected = expected_results.pop(0)
            logging.info('sanity result: %s', result)
            logging.info('sanity expected: %s', expected)
            self.assertRecursiveAlmostEqual(result.fields, expected)

        return
    def test_default(self):
        lines = LINES.copy()
        expected_results = RESULTS.copy()

        # Use port wind speed, output in m/s
        tw = TrueWindsTransform(data_id='truw',
                                course_fields='S330CourseTrue',
                                speed_fields='S330Speed',
                                heading_fields='S330HeadingTrue',
                                wind_dir_fields='MwxPortRelWindDir',
                                wind_speed_fields='MwxPortRelWindSpeed',
                                convert_speed_factor=0.5144)
        parse = ParseNMEATransform()

        while lines:
            record = parse.transform(lines.pop(0))
            result = tw.transform(record)
            expected = expected_results.pop(0)
            if expected:
                self.assertEqual(result.data_id, 'truw')
                self.assertEqual(result.message_type, None)
                self.assertEqual(result.timestamp, expected['timestamp'])
                self.assertAlmostEqual(result.fields['ApparentWindDir'],
                                       expected['fields']['ApparentWindDir'],
                                       delta=0.00001)
                self.assertAlmostEqual(result.fields['TrueWindDir'],
                                       expected['fields']['TrueWindDir'],
                                       delta=0.00001)
                self.assertAlmostEqual(result.fields['TrueWindSpeed'],
                                       expected['fields']['TrueWindSpeed'],
                                       delta=0.00001)
                self.assertDictEqual(result.metadata, expected['metadata'])
            else:
                self.assertIsNone(result)
        return
Beispiel #3
0
    def test_field_dict(self):
        parse = ParseNMEATransform()

        recip = RecipTransform()
        port_winds = TrueWindsTransform(
            course_field='S330CourseTrue',
            speed_field='S330Speed',
            heading_field='S330HeadingTrue',
            wind_dir_field='MwxPortRelWindDir',
            wind_speed_field='MwxPortRelWindSpeed',
            true_dir_name='PortTrueWindDir',
            true_speed_name='PortTrueWindSpeed',
            apparent_dir_name='PortApparentWindDir',
            convert_speed_factor=0.5144)
        stbd_winds = TrueWindsTransform(
            course_field='S330CourseTrue',
            speed_field='S330Speed',
            heading_field='S330HeadingTrue',
            wind_dir_field='MwxStbdRelWindDir',
            wind_speed_field='MwxStbdRelWindSpeed',
            true_dir_name='StbdTrueWindDir',
            true_speed_name='StbdTrueWindSpeed',
            apparent_dir_name='StbdApparentWindDir',
            convert_speed_factor=0.5144)

        # Test using DASRecords as input
        t = ComposedDerivedDataTransform(
            transforms=[recip, port_winds, stbd_winds])

        field_values = {}
        # Build the field dict
        for i in range(len(LINES)):
            line = LINES[i]
            record = parse.transform(line)
            if not record:
                continue

            for field, value in record.fields.items():
                if not field in field_values:
                    field_values[field] = []
                field_values[field].append([record.timestamp, value])

        results = t.transform(field_values)
        self.assertRecursiveAlmostEqual(results, FIELD_DICT_RESULT)
        """
Beispiel #4
0
    def test_das_record(self):
        """Test using DASRecords as input."""

        parse = ParseNMEATransform()

        recip = RecipTransform()
        port_winds = TrueWindsTransform(
            course_field='S330CourseTrue',
            speed_field='S330Speed',
            heading_field='S330HeadingTrue',
            wind_dir_field='MwxPortRelWindDir',
            wind_speed_field='MwxPortRelWindSpeed',
            true_dir_name='PortTrueWindDir',
            true_speed_name='PortTrueWindSpeed',
            apparent_dir_name='PortApparentWindDir',
            convert_speed_factor=0.5144)
        stbd_winds = TrueWindsTransform(
            course_field='S330CourseTrue',
            speed_field='S330Speed',
            heading_field='S330HeadingTrue',
            wind_dir_field='MwxStbdRelWindDir',
            wind_speed_field='MwxStbdRelWindSpeed',
            true_dir_name='StbdTrueWindDir',
            true_speed_name='StbdTrueWindSpeed',
            apparent_dir_name='StbdApparentWindDir',
            convert_speed_factor=0.5144)
        t = ComposedDerivedDataTransform(
            transforms=[recip, port_winds, stbd_winds])

        for i in range(len(LINES)):
            line = LINES[i]
            record = parse.transform(line)
            result = t.transform(record)

            expected = DAS_RECORD_RESULTS[i]

            logging.info('Input fields: %s', record.fields)
            logging.info('Got result: %s', result)
            logging.info('Expected result: %s', expected)
            if not result or not expected:
                self.assertIsNone(result)
                self.assertIsNone(expected)
            else:
                self.assertRecursiveAlmostEqual(result.fields, expected)
Beispiel #5
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)
    def test_sanity(self):
        """Sanity check that the numbers coming out make sense."""
        check = SANITY_CHECK.copy()
        expected_results = SANITY_RESULTS.copy()

        tw = TrueWindsTransform(data_id='truw',
                                course_fields='CourseTrue',
                                speed_fields='Speed',
                                heading_fields='HeadingTrue',
                                wind_dir_fields='RelWindDir',
                                wind_speed_fields='RelWindSpeed')

        while check:
            fields = check.pop(0)
            record = DASRecord(data_id='truw', fields=fields)
            result = tw.transform(record)
            logging.debug('sanity result: %s', result)
            expected_fields = expected_results.pop(0)
            self.assertDictEqual(result.fields, expected_fields)

        return
    def test_nmea(self):
        lines = LINES.copy()
        expected_results = RESULTS.copy()
        nmea_results = NMEA_RESULTS.copy()

        # Use port wind speed, output in m/s
        tw = TrueWindsTransform(data_id='truw',
                                course_fields='S330CourseTrue',
                                speed_fields='S330Speed',
                                heading_fields='S330HeadingTrue',
                                wind_dir_fields='MwxPortRelWindDir',
                                wind_speed_fields='MwxPortRelWindSpeed',
                                convert_speed_factor=0.5144,
                                output_nmea=True)
        parse = ParseNMEATransform()

        while lines:
            record = parse.transform(lines.pop(0))
            result = tw.transform(record)
            nmea_expected = nmea_results.pop(0)
            self.assertEqual(result, nmea_expected)

            # Now check that parsing into a DASRecord works as expected
            das_result = parse.transform(result)
            expected = expected_results.pop(0)
            if das_result is None:
                self.assertEqual(das_result, expected)
            else:
                das_fields = das_result.fields
                exp_fields = expected['fields']
                self.assertAlmostEqual(das_fields['TrueWindDir'],
                                       exp_fields['TrueWindDir'],
                                       delta=0.001)
                self.assertAlmostEqual(das_fields['TrueWindSpeed'],
                                       exp_fields['TrueWindSpeed'],
                                       delta=0.001)
                self.assertAlmostEqual(das_fields['ApparentWindDir'],
                                       exp_fields['ApparentWindDir'],
                                       delta=0.001)
        return
    def test_default(self):
        lines = LINES.copy()
        expected_results = RESULTS.copy()

        # Use port wind speed, output in m/s
        tw = TrueWindsTransform(course_field='S330CourseTrue',
                                speed_field='S330Speed',
                                heading_field='S330HeadingTrue',
                                wind_dir_field='MwxPortRelWindDir',
                                update_on_fields=['MwxPortRelWindDir'],
                                wind_speed_field='MwxPortRelWindSpeed',
                                true_dir_name='PortTrueWindDir',
                                true_speed_name='PortTrueWindSpeed',
                                apparent_dir_name='PortApparentWindDir',
                                convert_speed_factor=0.5144)
        parse = ParseNMEATransform()

        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 #9
0
    def test_no_timestamps(self):
        lines = LINES.copy()
        expected_results = NO_TIMESTAMP_RESULTS.copy()

        # Use port wind speed, output in m/s
        tw = TrueWindsTransform(course_field='S330CourseTrue',
                                speed_field='S330Speed',
                                heading_field='S330HeadingTrue',
                                wind_dir_field='MwxPortRelWindDir',
                                update_on_fields=['MwxPortRelWindDir'],
                                wind_speed_field='MwxPortRelWindSpeed',
                                true_dir_name='PortTrueWindDir',
                                true_speed_name='PortTrueWindSpeed',
                                apparent_dir_name='PortApparentWindDir',
                                convert_speed_factor=0.5144)
        parse = ParseNMEATransform()

        value_dict = {}
        timestamp_dict = {}

        while lines:
            record = parse.transform(lines.pop(0))
            for field in record.fields:
                value_dict[field] = record.fields[field]
                timestamp_dict[field] = record.timestamp

            result = tw.transform(value_dict)
            expected = expected_results.pop(0)
            logging.info('Got result: %s', result)
            logging.info('Expected result: %s', expected)

            if not result or not expected:
                self.assertIsNone(result)
                self.assertIsNone(expected)
            else:
                self.assertRecursiveAlmostEqual(result, expected)