I am new to creating custom OOT blocks and I'm trying to make a lookup table block. I followed the official tutorial found here.
When I refresh blocks inside GNU Radio Companion and run, it outputs the following error:
Generating: '/home/matterhorn/gnu_radio/lookup_test.py'
Executing: /usr/bin/python3 -u /home/matterhorn/gnu_radio/lookup_test.py
Traceback (most recent call last):
File "/home/matterhorn/gnu_radio/lookup_test.py", line 27, in <module>
from gnuradio import DABPhaseRef
ImportError: cannot import name 'DABPhaseRef' from 'gnuradio' (/usr/lib/python3.10/site-packages/gnuradio/__init__.py)
>>> Done (return code 1)
It seems to me, that GRC cannot see modules in local site.
My question: how can I get GRC to import my module?
Here is the python file:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2023 Staš Bucik.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
import numpy as np
from gnuradio import gr
class lookupTable(gr.sync_block):
"""
docstring for block lookupTable
"""
def __init__(self):
gr.sync_block.__init__(self,
name="lookupTable",
in_sig=None,
out_sig=[(np.complex64, 2048)])
self.kinTable = # long lookup table
self.timePhaseTable = # long lookup table
self.table = []
for k in range(-1024, 1024):
'''if k < -768 or k > 768 or k == 0:
table[k + 1024] = 0. + 0.j
else:
kin = self.getKINParams(k)
h = self.timePhaseTable[kin[1], k - kin[0]]
phase = np.pi * 0.5 * (h + kin[2])
table[k + 1024] = np.exp(1.j * phase)'''
table[k + 1024] = k + 0.j
def getKINParams(self, k):
for row in self.kinTable:
if k >= row[0] and k <= row[1]:
return row[2:]
raise Exception("No KIN parameters found!")
def work(self, input_items, output_items):
output_items[0] = self.table
return len(output_items[0])
Here is the YAML file:
id: DABPhaseRef_lookupTable
label: lookupTable
category: '[DABPhaseRef]'
templates:
imports: from gnuradio import DABPhaseRef
make: DABPhaseRef.lookupTable()
# Make one 'inputs' list entry per input and one 'outputs' list entry per output.
# Keys include:
# * label (an identifier for the GUI)
# * domain (optional - stream or message. Default is stream)
# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...)
# * vlen (optional - data stream vector length. Default is 1)
# * optional (optional - set to 1 for optional inputs. Default is 0)
outputs:
- label: out0
domain: stream
dtype: complex
vlen: 2048
# 'file_format' specifies the version of the GRC yml format used in the file
# and should usually not be changed.
file_format: 1
When I build and install my module it succeeds:
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /usr/local/lib/cmake/gnuradio-DABPhaseRef/gnuradio-DABPhaseRefConfig.cmake
-- Up-to-date: /usr/local/include/gnuradio/DABPhaseRef/api.h
-- Up-to-date: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/__init__.py
-- Up-to-date: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/lookupTable.py
-- Installing: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/__init__.pyc
-- Installing: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/lookupTable.pyc
-- Installing: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/__init__.pyo
-- Installing: /usr/local/lib/python3.10/site-packages/gnuradio/DABPhaseRef/lookupTable.pyo
-- Up-to-date: /usr/local/share/gnuradio/grc/blocks/DABPhaseRef_lookupTable.block.yml
As shown above, python module was installed into local directory (indicated by /usr/local/lib/
).
Edit: I am using Manjaro linux. There is no PYTHONPATH defined. I tried exporting it in .bashrc, adding both paths (local and nonlocal). It did not fix my problem.