def test_filter_channels(self):
        with sllib.create_reader(self.path_sl3_v2) as reader:
            reader.add_filter(channels=[9])
            for frame in reader:
                self.assertEqual(frame.channel, 9)

        with sllib.create_reader(self.path_sl3_v2) as reader:
            reader.add_filter(channels=[1, 9])
            for frame in reader:
                self.assertIn(frame.channel, [1, 9])
    def test_enumerate_slg(self):
        with sllib.create_reader(self.path_small) as reader:
            count = 0
            last_time = 0
            first = True
            for frame in reader:
                if first:
                    print(frame)
                    first = False
                count = count + 1
                # self.assertGreaterEqual(frame.flags, 0)
                self.assertIn(frame.headerlen, [48, 52])
                if frame.flags & 0x0001 == 0:
                    # if bit is set then some kind of epoc
                    self.assertGreaterEqual(frame.time1, last_time)
                    last_time = frame.time1

                # test positions
                if frame.altitude < 0:
                    self.assertEqual(frame.altitude, -10000.0)
                else:
                    self.assertGreaterEqual(frame.altitude, 0)
                    self.assertLessEqual(frame.altitude, 300)
                # self.assertGreaterEqual(frame.longitude, 10)
                # self.assertLessEqual(frame.longitude, 15, "bad longitude in frame %d" % (count,))
                # self.assertGreaterEqual(frame.latitude, 50, "bad latitude in frame %d" % (count,))
                # self.assertLessEqual(frame.latitude, 60)

            self.assertEqual(count, 4789)
    def test_first(self):
        with sllib.create_reader(self.path_sl3, True) as reader:
            header = reader.header
            self.assertEqual(header.format, 3)
            x = next(reader)
            assert x
            assert x.offset == 8
            self.assertEqual(x.framesize, 2732, 'bad framesize')
            # print(x.to_dict(format=3))

            self.assertAlmostEqual(x.lower_limit, 98.4, 2)
            self.assertEqual(x.upper_limit, 0.0)

            assert x.frequency == 0
            self.assertAlmostEqual(x.gps_speed, 2.25, 2)
            self.assertAlmostEqual(x.temperature, 2.3, 1)
            # assert x.temperature == 19.350006103515625
            self.assertAlmostEqual(x.longitude, 36.486296, 4)
            self.assertAlmostEqual(x.latitude, 56.5952053, 4)
            assert x.water_speed == 0
            # self.assertAlmostEqual(x.course, 288.83, 1)
            # assert x.altitude == 118.89765930175781
            # self.assertAlmostEqual(x.altitude, 118, 1)
            self.assertAlmostEqual(x.heading_deg, 78.98, 1)
            self.assertEqual(x.flags, 950)  # TODO: Validate !!!
 def test_next_v1(self):
     with sllib.create_reader(fixtures.SL2_V1) as reader:
         x = next(reader)
         assert x
         assert x.offset == 8
         assert x.previous_primary_offset == 0
         assert x.previous_secondary_offset == 0
         assert x.previous_downscan_offset == 8
         assert x.previous_left_sidescan_offset == 0
         assert x.previous_right_sidescan_offset == 0
         assert x.previous_composite_sidescan_offset == 0
         assert x.framesize == 2064
         assert x.previous_framesize == 0
         assert x.channel == 2
         assert x.packetsize == 1920
         assert x.frame_index == 0
         assert x.upper_limit == 0
         assert x.lower_limit == 20.100000381469727
         assert x.frequency == 0
         assert x.water_depth == 7.406000137329102
         assert x.keel_depth == 0
         assert x.gps_speed == 0.6000000238418579
         assert x.temperature == 19.943925857543945
         assert x.lon_enc == 1373761
         assert x.lat_enc == 8163659
         assert x.water_speed == 0.6000000238418579
         assert x.course == 4.817108631134033
         assert x.altitude == 236.18765258789062
         assert x.heading == 0
         assert x.flags == 542  # TODO: Validate this!!!
         assert x.time1 == 99787
 def test_next(self):
     with sllib.create_reader(fixtures.SL2_SMALL) as reader:
         x = next(reader)
         assert x
         assert x.offset == 8
         assert x.previous_primary_offset == 8
         assert x.previous_secondary_offset == 0
         assert x.previous_downscan_offset == 0
         assert x.previous_left_sidescan_offset == 0
         assert x.previous_right_sidescan_offset == 0
         assert x.previous_composite_sidescan_offset == 0
         assert x.framesize == 3216
         assert x.previous_framesize == 0
         assert x.channel == 0
         assert x.packetsize == 3072
         assert x.frame_index == 0
         assert x.upper_limit == 0
         assert x.lower_limit == 19.600000381469727
         assert x.frequency == 8
         assert x.water_depth == 6.622000217437744
         assert x.keel_depth == 0
         assert x.gps_speed == 2.585312843322754
         assert x.temperature == 19.350006103515625
         assert x.lon_enc == 1383678
         assert x.lat_enc == 8147302
         assert x.water_speed == 0
         assert x.course == 3.7873644828796387
         assert x.altitude == 118.89765930175781
         assert x.heading == 0
         assert x.flags == 702  # TODO: Validate this!!!
         assert x.time1 == 5
    def test_corrupt(self):
        with create_reader(fixtures.SL2_CORRUPT_PARTLY, strict=True) as reader:
            first = next(reader)
            self.assertEqual(first.offset, 8)

            with self.assertRaises(OffsetError):
                next(reader)
 def test_header_slg(self):
     with sllib.create_reader(self.path_small) as reader:
         assert reader
         header = reader.header
         assert header
         assert header.format == 1
         assert header.version == 0
         assert header.framesize == 1200
    def test_add_filter_fields(self):
        with create_reader(fixtures.SL2_SMALL) as reader:
            reader.add_filter(has_heading=True)
            count = 0
            for frame in reader:
                count += 1

            self.assertEqual(count, 0, 'wrong number of frames returned')
    def test_filter_flags(self):
        with sllib.create_reader(self.path_sl3_v2) as reader:
            reader.add_filter(flags=702)
            count = 0
            for frame in reader:
                self.assertEqual(frame.flags, 702)
                count += 1

        self.assertEqual(count, 28672)
    def test_read_all_v1(self):
        with sllib.create_reader(self.path_sl3, True) as reader:
            header = reader.header
            self.assertEqual(header.format, 3)
            self.assertEqual(header.version, 1)
            count = 0
            goodCount = 0
            channelcounts = [0] * 10
            box = {
                'lon': {
                    'min': 36.48355597526586,
                    'max': 36.48649433485548
                },
                'lat': {
                    'min': 56.59505156603242,
                    'max': 56.59533938054592
                },
                'depth': {
                    'min': 3.0,
                    'max': 13.0
                }
            }
            for frame in reader:
                count += 1
                if frame.has_tbd1:
                    goodCount += 1
                channelcounts[frame.channel] += 1
                # space
                self.assertGreaterEqual(frame.longitude, box['lon']['min'])
                self.assertLessEqual(frame.longitude, box['lon']['max'])
                self.assertGreaterEqual(frame.latitude, box['lat']['min'])
                self.assertLessEqual(frame.latitude, box['lat']['max'])
                self.assertGreaterEqual(frame.water_depth_m,
                                        box['depth']['min'])
                self.assertLessEqual(frame.water_depth_m, box['depth']['max'])

                # channels
                self.assertLessEqual(frame.channel, 9)
                self.assertLessEqual(frame.frequency, 10)

            self.assertEqual(count, 10124, 'wrong number of frames')
            self.assertEqual(goodCount, 7626,
                             'wrong number of frames with flag set')
            self.assertEqual(channelcounts[0], 2793, 'channel 0')
            self.assertEqual(channelcounts[1], 0, 'channel 1')
            self.assertEqual(channelcounts[2], 2416, 'channel 2')
            self.assertEqual(channelcounts[3], 0, 'channel 3')
            self.assertEqual(channelcounts[4], 0, 'channel 4')
            self.assertEqual(channelcounts[5], 2417, 'channel 5')
            self.assertEqual(channelcounts[6], 0, 'channel 6')
            self.assertEqual(channelcounts[7], 0, 'channel 7')
            self.assertEqual(channelcounts[8], 0, 'channel 8')
            self.assertEqual(channelcounts[9], 2498, 'channel 9')

            filesize = os.path.getsize(self.path_sl3)
            self.assertEqual(reader.tell(), filesize)
 def test_header_sl3(self):
     with sllib.create_reader(self.path_sl3) as reader:
         assert reader
         header = reader.header
         assert header
         assert header.format == 3
         assert header.version == 1
         assert header.framesize == 3200
         fields = reader.fields
         self.assertIn('channel', fields)
    def test_read_all_v2(self):
        filename = self.path_sl3_v2
        with sllib.create_reader(filename, strict=True) as reader:
            header = reader.header
            self.assertEqual(header.format, 3)
            self.assertEqual(header.version, 2)
            count = 0
            goodCount = 0
            channelcounts = [0] * 10
            box = {
                'lon': {
                    'min': -91.2444,
                    'max': -91.24243771237497
                },
                'lat': {
                    'min': 29.654006,
                    'max': 29.657156827530574
                },
                'depth': {
                    'min': 3.0,
                    'max': 13.0
                }
            }
            for frame in reader:
                count += 1
                if frame.channel <= 5:
                    goodCount += 1
                channelcounts[frame.channel] += 1
                # space
                self.assertGreaterEqual(frame.longitude, box['lon']['min'])
                self.assertLessEqual(frame.longitude, box['lon']['max'])
                self.assertGreaterEqual(frame.latitude, box['lat']['min'])
                self.assertLessEqual(frame.latitude, box['lat']['max'])
                # self.assertGreaterEqual(frame.water_depth_m, box['depth']['min'])
                # self.assertLessEqual(frame.water_depth_m, box['depth']['max'])

                # channels
                self.assertLessEqual(frame.channel, 9)
                self.assertLessEqual(frame.frequency, 10)

            self.assertEqual(count, 32768)
            self.assertEqual(goodCount, 16384)
            self.assertEqual(channelcounts[0], 4096, 'channel 0')
            self.assertEqual(channelcounts[1], 4096, 'channel 1')
            self.assertEqual(channelcounts[2], 4096, 'channel 2')
            self.assertEqual(channelcounts[3], 0, 'channel 3')
            self.assertEqual(channelcounts[4], 0, 'channel 4')
            self.assertEqual(channelcounts[5], 4096, 'channel 5')
            self.assertEqual(channelcounts[6], 0, 'channel 6')
            self.assertEqual(channelcounts[7], 8192, 'channel 7')
            self.assertEqual(channelcounts[8], 8192, 'channel 8')
            self.assertEqual(channelcounts[9], 0, 'channel 9')

            filesize = os.path.getsize(filename)
            self.assertEqual(reader.tell(), filesize)
 def test_enumerate_v1(self):
     with sllib.create_reader(fixtures.SL2_V1) as reader:
         assert reader
         count = 0
         prev = None
         for frame in reader:
             count = count + 1
             assert frame
             doframe(self, frame, prev)
             prev = frame
         self.assertEqual(count, 27458)
 def test_enumerate(self):
     with sllib.create_reader(fixtures.SL2_SMALL) as reader:
         assert reader
         self.assertEqual(reader.header.version, 0)
         count = 0
         prev = None
         for frame in reader:
             count = count + 1
             assert frame
             doframe(self, frame, prev)
             prev = frame
         assert count == 4017
    def test_header_sl2(self):

        with open(fixtures.SL2_SMALL, 'rb') as f:
            reader = sllib.Reader(f)
            assert reader
            header = reader.header
            assert header
            assert header.format == 2
            assert header.version == 0
            assert header.framesize == 3200

        with sllib.create_reader(fixtures.SL2_V1) as reader:
            assert reader
            assert reader.header.format == 2
            assert reader.header.version == 1
    def test_southern_hemisphere(self):
        with sllib.create_reader(fixtures.SL2_SOUTHERN1) as reader:
            header = reader.header
            self.assertEqual(header.format, 2)
            self.assertEqual(header.version, 0)
            self.assertEqual(header.framesize, 3200)
            x = next(reader)
            assert x
            assert x.offset == 8
            self.assertEqual(x.previous_primary_offset, 8)
            self.assertEqual(x.previous_secondary_offset, 0)
            self.assertEqual(x.previous_downscan_offset, 0)
            self.assertEqual(x.previous_left_sidescan_offset, 0)
            self.assertEqual(x.previous_right_sidescan_offset, 0)
            self.assertEqual(x.previous_composite_sidescan_offset, 0)
            self.assertEqual(x.framesize, 3216)

            self.assertEqual(x.lon_enc, 12846380)
            self.assertEqual(x.lat_enc, -3719601)

            self.assertAlmostEqual(x.longitude, 115.78921, 5)
            self.assertAlmostEqual(x.latitude, -31.76203, 5)
 def test_add_filter_bad_field(self):
     with create_reader(fixtures.SL2_SMALL) as reader:
         with self.assertRaises(FieldNotFoundError):
             reader.add_filter(spam=True)