summaryrefslogtreecommitdiff
path: root/gr-digital/python/digital/utils
diff options
context:
space:
mode:
Diffstat (limited to 'gr-digital/python/digital/utils')
-rw-r--r--gr-digital/python/digital/utils/alignment.py12
-rw-r--r--gr-digital/python/digital/utils/gray_code.py16
-rw-r--r--gr-digital/python/digital/utils/mod_codes.py1
-rw-r--r--gr-digital/python/digital/utils/tagged_streams.py23
4 files changed, 30 insertions, 22 deletions
diff --git a/gr-digital/python/digital/utils/alignment.py b/gr-digital/python/digital/utils/alignment.py
index f3ad3781e2..e9292a4bcc 100644
--- a/gr-digital/python/digital/utils/alignment.py
+++ b/gr-digital/python/digital/utils/alignment.py
@@ -41,6 +41,8 @@ This module contains functions for aligning sequences.
(100, -20)
"""
+from __future__ import division
+from __future__ import unicode_literals
import random
@@ -63,7 +65,7 @@ def compare_sequences(d1, d2, offset, sample_indices=None):
"""
max_index = min(len(d1), len(d2)+offset)
if sample_indices is None:
- sample_indices = range(0, max_index)
+ sample_indices = list(range(0, max_index))
correct = 0
total = 0
for i in sample_indices:
@@ -84,8 +86,8 @@ def random_sample(size, num_samples=def_num_samples, seed=None):
if num_samples > size:
indices = set(range(0, size))
else:
- if num_samples > size/2:
- num_samples = num_samples/2
+ if num_samples > size / 2:
+ num_samples = num_samples / 2
indices = set([])
while len(indices) < num_samples:
index = rndm.randint(0, size-1)
@@ -119,8 +121,8 @@ def align_sequences(d1, d2,
best_offset = None
best_compared = None
best_correct = None
- pos_range = range(0, min(len(d1), max_offset))
- neg_range = range(-1, -min(len(d2), max_offset), -1)
+ pos_range = list(range(0, min(len(d1), max_offset)))
+ neg_range = list(range(-1, -min(len(d2), max_offset), -1))
# Interleave the positive and negative offsets.
int_range = [item for items in zip(pos_range, neg_range) for item in items]
for offset in int_range:
diff --git a/gr-digital/python/digital/utils/gray_code.py b/gr-digital/python/digital/utils/gray_code.py
index 926a1ded10..ad88274087 100644
--- a/gr-digital/python/digital/utils/gray_code.py
+++ b/gr-digital/python/digital/utils/gray_code.py
@@ -1,25 +1,27 @@
#!/usr/bin/env python
#
# Copyright 2011 Free Software Foundation, Inc.
-#
+#
# This file is part of GNU Radio
-#
+#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
-#
+#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
+from __future__ import division
+from __future__ import unicode_literals
class GrayCodeGenerator(object):
"""
Generates and caches gray codes.
@@ -41,7 +43,7 @@ class GrayCodeGenerator(object):
if len(self.gcs) < length:
self.generate_new_gray_code(length)
return self.gcs[:length]
-
+
def generate_new_gray_code(self, length):
"""
Generates new gray code and places into cache.
@@ -49,7 +51,7 @@ class GrayCodeGenerator(object):
while len(self.gcs) < length:
if self.i == self.lp2:
# if i is a power of two then gray number is of form 1100000...
- result = self.i + self.i/2
+ result = self.i + self.i // 2
else:
# if not we take advantage of the symmetry of all but the last bit
# around a power of two.
diff --git a/gr-digital/python/digital/utils/mod_codes.py b/gr-digital/python/digital/utils/mod_codes.py
index f55fe41b8b..586ab1999a 100644
--- a/gr-digital/python/digital/utils/mod_codes.py
+++ b/gr-digital/python/digital/utils/mod_codes.py
@@ -21,6 +21,7 @@
#
# Constants used to represent what coding to use.
+from __future__ import unicode_literals
GRAY_CODE = 'gray'
SET_PARTITION_CODE = 'set-partition'
NO_CODE = 'none'
diff --git a/gr-digital/python/digital/utils/tagged_streams.py b/gr-digital/python/digital/utils/tagged_streams.py
index 4b393bfc20..68267a293e 100644
--- a/gr-digital/python/digital/utils/tagged_streams.py
+++ b/gr-digital/python/digital/utils/tagged_streams.py
@@ -1,27 +1,30 @@
#!/usr/bin/env python
#
# Copyright 2013 Free Software Foundation, Inc.
-#
+#
# This file is part of GNU Radio
-#
+#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
-#
+#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
# DEPRECATED -- Marked for removal in 3.8
+from __future__ import print_function
+from __future__ import division
+from __future__ import unicode_literals
from gnuradio import gr
import pmt
@@ -30,9 +33,9 @@ def make_lengthtags(lengths, offsets, tagname='length', vlen=1):
assert(len(offsets) == len(lengths))
for offset, length in zip(offsets, lengths):
tag = gr.tag_t()
- tag.offset = offset/vlen
+ tag.offset = offset / vlen
tag.key = pmt.string_to_symbol(tagname)
- tag.value = pmt.from_long(length/vlen)
+ tag.value = pmt.from_long(length / vlen)
tags.append(tag)
return tags
@@ -75,7 +78,7 @@ def count_bursts(data, tags, lengthtagname, vlen=1):
if pos in lengths:
if in_packet:
print("Got tag at pos {0} current packet_pos is {1}".format(pos, packet_pos))
- raise StandardError("Received packet tag while in packet.")
+ raise Exception("Received packet tag while in packet.")
packet_pos = -1
packet_length = lengths[pos]
in_packet = True
@@ -127,9 +130,9 @@ def packets_to_vectors(packets, lengthtagname, vlen=1):
for packet in packets:
data.extend(packet)
tag = gr.tag_t()
- tag.offset = offset/vlen
+ tag.offset = offset // vlen
tag.key = pmt.string_to_symbol(lengthtagname)
- tag.value = pmt.from_long(len(packet)/vlen)
+ tag.value = pmt.from_long(len(packet) // vlen)
tags.append(tag)
offset = offset + len(packet)
return data, tags