Skip to content

Commit

Permalink
Merge pull request #32 from analogdevicesinc/tfcollins/py-reorg
Browse files Browse the repository at this point in the history
Reorganize python bindings
  • Loading branch information
SrikanthPagadarai authored Jan 17, 2024
2 parents 544f7e7 + 036c198 commit 7e7c24a
Show file tree
Hide file tree
Showing 27 changed files with 1,420 additions and 679 deletions.
8 changes: 1 addition & 7 deletions .github/scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,4 @@ apt-get update
apt-get install -y sudo
sudo apt-get update
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections
sudo apt-get install -q -y cmake tar bzip2 gzip build-essential libfftw3-dev python3-pip doxygen graphviz

if [ -z "$1" ]; then
SU="sudo"
fi
$SU pip3 install -r requirements_test.txt
$SU pip3 install -r requirements_doc.txt
sudo apt-get install -q -y cmake tar bzip2 gzip build-essential libfftw3-dev python3-pip doxygen graphviz
2 changes: 1 addition & 1 deletion .github/scripts/install_genalyzer.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
mkdir -p build
cd build
cmake .. -DPYTHON_BINDINGS=ON
cmake ..
make -j4
sudo make install
sudo ldconfig
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/deploy-pypi-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ jobs:
bash ./.github/scripts/install_dependencies.sh USER
bash ./.github/scripts/install_genalyzer.sh
sudo rm -rf build
mkdir build && cd build && cmake .. -DPYTHON_BINDINGS=ON && cd ..
pip install setuptools wheel twine build
- name: Update to dev version and build test release
run: |
pip install invoke
invoke bumpversion-test
cd build/bindings/python
cd bindings/python
python -m build
- uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- name: Install dependencies
run: |
bash ./.github/scripts/install_dependencies.sh
pip install -r requirements_doc.txt
- name: Build doc
run: |
Expand All @@ -40,6 +41,7 @@ jobs:
- name: Install dependencies
run: |
bash ./.github/scripts/install_dependencies.sh
pip install -r requirements_doc.txt
- name: Build doc
run: |
Expand Down
13 changes: 4 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ jobs:
cp build/src/libgenalyzer_plus_plus.a* libs/
cp bindings/c/include/cgenalyzer.h libs/
cp bindings/c/include/cgenalyzer_advanced.h libs/
cp bindings/python/genalyzer.py libs/
cp bindings/python/genalyzer_advanced.py libs/
cp bindings/matlab/genalyzer.m libs/
- name: Archive generated SOs
Expand Down Expand Up @@ -81,8 +79,6 @@ jobs:
cp build/src/libgenalyzer_plus_plus.a* libs/
cp bindings/c/include/cgenalyzer.h libs/
cp bindings/c/include/cgenalyzer_advanced.h libs/
cp bindings/python/genalyzer.py libs/
cp bindings/python/genalyzer_advanced.py libs/
cp bindings/matlab/genalyzer.m libs/
- name: Archive generated SOs
Expand Down Expand Up @@ -110,7 +106,7 @@ jobs:
run: |
mkdir -p build
cd build
cmake .. -DPYTHON_BINDINGS=ON -DBUILD_TESTS_EXAMPLES=ON -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
cmake .. -DBUILD_TESTS_EXAMPLES=ON -DCOVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
make -j4
make coverage
Expand Down Expand Up @@ -157,11 +153,10 @@ jobs:
run: |
bash ./.github/scripts/install_dependencies.sh
bash ./.github/scripts/install_genalyzer.sh
pip install -r requirements_test.txt
- name: Test
run: |
cd build/bindings/python
sudo pip3 install .
cd ../../..
cd bindings/python
pytest -vs tests
pip install ".[tools]"
python -m pytest -vs tests
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/Modules)

option(BUILD_DOC "Generate documentation" OFF)
option(BUILD_TESTS_EXAMPLES "Build tests and examples" OFF)
option(PYTHON_BINDINGS "Generate python bindings" OFF)
option(COVERAGE "Enable coverage tracing when testing" OFF)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
Expand Down
3 changes: 0 additions & 3 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
add_subdirectory(c)
if(PYTHON_BINDINGS)
add_subdirectory(python)
endif()
50 changes: 0 additions & 50 deletions bindings/python/CMakeLists.txt

This file was deleted.

16 changes: 9 additions & 7 deletions bindings/python/examples/compute_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
f = glob.glob(os.path.join(loc, test_dir, "test_fft_tone_1655478044632.json"))
a = open(f[0])
data = json.load(a)
if data['num_tones'] == 1:
freq_list = [data['freq']]
if data["num_tones"] == 1:
freq_list = [data["freq"]]
else:
freq_list = data['freq']
freq_list = data["freq"]

qwfi = data['test_vecq_i']
qwfi = data["test_vecq_i"]
qwfi = [int(i) for i in qwfi]
qwfq = data['test_vecq_q']
qwfq = data["test_vecq_q"]
qwfq = [int(i) for i in qwfq]
c = genalyzer.config_fftz(data['npts'], data['qres'], data['navg'], data['nfft'], data['win']-1)
c = genalyzer.config_fftz(
data["npts"], data["qres"], data["navg"], data["nfft"], data["win"] - 1
)
fft_out_i, fft_out_q = genalyzer.fftz(qwfi, qwfq, c)
plt.plot(fft_out_i[:1000])
plt.plot(fft_out_q[:1000])
genalyzer.config_free(c)
genalyzer.config_free(c)
16 changes: 9 additions & 7 deletions bindings/python/examples/do_fourier_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
f = glob.glob(os.path.join(loc, test_dir, "test_fft_tone_1655478044632.json"))
a = open(f[0])
data = json.load(a)
if data['num_tones'] == 1:
freq_list = [data['freq']]
if data["num_tones"] == 1:
freq_list = [data["freq"]]
else:
freq_list = data['freq']
freq_list = data["freq"]

qwfi = data['test_vecq_i']
qwfi = data["test_vecq_i"]
qwfi = [int(i) for i in qwfi]
qwfq = data['test_vecq_q']
qwfq = data["test_vecq_q"]
qwfq = [int(i) for i in qwfq]
c = genalyzer.config_fftz(data['npts'], data['qres'], data['navg'], data['nfft'], data['win']-1)
c = genalyzer.config_fftz(
data["npts"], data["qres"], data["navg"], data["nfft"], data["win"] - 1
)
fft_out_i, fft_out_q = genalyzer.fftz(qwfi, qwfq, c)
fft_out = [val for pair in zip(fft_out_i, fft_out_q) for val in pair]
genalyzer.config_fa(freq_list[0], c)
all_results = genalyzer.get_fa_results(fft_out, c)
pprint.pprint(all_results)
sfdr = genalyzer.get_fa_single_result("sfdr", fft_out, c)
genalyzer.config_free(c)
print(sfdr)
print(sfdr)
28 changes: 15 additions & 13 deletions bindings/python/examples/do_fourier_analysis_pluto.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,35 @@
f = glob.glob(os.path.join(loc, test_dir, "test_Pluto_DDS_data_1658159639196.json"))
a = open(f[0])
data = json.load(a)
if data['num_tones'] == 1:
freq_list = [data['freq']]
if data["num_tones"] == 1:
freq_list = [data["freq"]]
else:
freq_list = data['freq']
freq_list = data["freq"]

qwfi = data['test_vec_i']
qwfi = data["test_vec_i"]
qwfi = [int(i) for i in qwfi]
qwfq = data['test_vec_q']
qwfq = data["test_vec_q"]
qwfq = [int(i) for i in qwfq]

# configure
c = genalyzer.config_fftz(data['npts'], data['qres'], data['navg'], data['nfft'], data['win']-1)
genalyzer.config_set_sample_rate(data['fs'], c)
c = genalyzer.config_fftz(
data["npts"], data["qres"], data["navg"], data["nfft"], data["win"] - 1
)
genalyzer.config_set_sample_rate(data["fs"], c)
genalyzer.config_fa(freq_list[0], c)

# compute FFT
fft_out_i, fft_out_q = genalyzer.fftz(qwfi, qwfq, c)
fft_out = [val for pair in zip(fft_out_i, fft_out_q) for val in pair]

# plot FFT
fft_cp = np.empty(data['nfft'], dtype=np.complex128)
fft_cp = np.empty(data["nfft"], dtype=np.complex128)
fft_cp.real = [fft_out[i] for i in range(len(fft_out)) if i % 2 != 0]
fft_cp.imag = [fft_out[i] for i in range(len(fft_out)) if i % 2 != 1]
fft_cp = np.roll(np.absolute(fft_cp), round(0.5*data['nfft']))
f = np.linspace(start=-0.5*data['fs'], stop=0.5*data['fs'], num=data['nfft'])
fft_cp = np.roll(np.absolute(fft_cp), round(0.5 * data["nfft"]))
f = np.linspace(start=-0.5 * data["fs"], stop=0.5 * data["fs"], num=data["nfft"])
plt.clf()
plt.plot(f, 10*np.log10(np.square(fft_cp)))
plt.plot(f, 10 * np.log10(np.square(fft_cp)))
plt.ylim([-140, 0])
plt.xlabel("frequency [Hz]")
plt.ylabel("PSD [dBFs]")
Expand All @@ -45,7 +47,7 @@
sfdr = genalyzer.get_fa_single_result("sfdr", fft_out, c)

# display results
print('SFDR - ', sfdr)
print("SFDR - ", sfdr)

# free memory
genalyzer.config_free(c)
genalyzer.config_free(c)
38 changes: 20 additions & 18 deletions bindings/python/examples/do_fourier_analysis_pluto_auto.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This example shows how to use the Fourier analysis functions with data
# This example shows how to use the Fourier analysis functions with data
# from a PlutoSDR. The data is read from a JSON file. The Fourier analysis
# is configured to automatically find the tones in the data.

Expand All @@ -12,19 +12,21 @@
f = glob.glob(os.path.join(loc, test_dir, "test_Pluto_DDS_data_1658159639196.json"))
a = open(f[0])
data = json.load(a)
if data['num_tones'] == 1:
freq_list = [data['freq']]
if data["num_tones"] == 1:
freq_list = [data["freq"]]
else:
freq_list = data['freq']
freq_list = data["freq"]

qwfi = data['test_vec_i']
qwfi = data["test_vec_i"]
qwfi = [int(i) for i in qwfi]
qwfq = data['test_vec_q']
qwfq = data["test_vec_q"]
qwfq = [int(i) for i in qwfq]

# configure
c = genalyzer.config_fftz(data['npts'], data['qres'], data['navg'], data['nfft'], data['win']-1)
genalyzer.config_set_sample_rate(data['fs'], c)
c = genalyzer.config_fftz(
data["npts"], data["qres"], data["navg"], data["nfft"], data["win"] - 1
)
genalyzer.config_set_sample_rate(data["fs"], c)

# Find tones
genalyzer.gn_config_fa_auto(ssb_width=120, c=c)
Expand All @@ -37,21 +39,21 @@
all_results = genalyzer.get_fa_results(fft_out, c)

# plot FFT
fft_cp = np.empty(data['nfft'], dtype=np.complex128)
fft_cp = np.empty(data["nfft"], dtype=np.complex128)
fft_cp.real = [fft_out[i] for i in range(len(fft_out)) if i % 2 != 0]
fft_cp.imag = [fft_out[i] for i in range(len(fft_out)) if i % 2 != 1]
fft_cp = np.roll(np.absolute(fft_cp), round(0.5*data['nfft']))
f = np.linspace(start=-0.5*data['fs'], stop=0.5*data['fs'], num=data['nfft'])
dbfs_data = 10*np.log10(np.square(fft_cp))
fft_cp = np.roll(np.absolute(fft_cp), round(0.5 * data["nfft"]))
f = np.linspace(start=-0.5 * data["fs"], stop=0.5 * data["fs"], num=data["nfft"])
dbfs_data = 10 * np.log10(np.square(fft_cp))
plt.clf()
plt.plot(f, dbfs_data)

# Add markers for the harmonics
harmonic_keys = ['A', '2A','dc']
harmonic_keys = ["A", "2A", "dc"]
for key in harmonic_keys:
freq = all_results[f'{key}:freq']
amp = all_results[f'{key}:mag_dbfs']
plt.plot(freq, amp, 'ro')
freq = all_results[f"{key}:freq"]
amp = all_results[f"{key}:mag_dbfs"]
plt.plot(freq, amp, "ro")


plt.ylim([-140, 0])
Expand All @@ -65,7 +67,7 @@

# display results
pprint.pprint(all_results)
print('SFDR - ', sfdr)
print("SFDR - ", sfdr)

# free memory
genalyzer.config_free(c)
genalyzer.config_free(c)
2 changes: 1 addition & 1 deletion bindings/python/examples/do_histogram_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
hist = genalyzer.histz(qwf, c)
ha_results = genalyzer.get_ha_results(hist, c)
pprint.pprint(ha_results)
genalyzer.config_free(c)
genalyzer.config_free(c)
2 changes: 1 addition & 1 deletion bindings/python/examples/do_waveform_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
qwf = genalyzer.quantize(awf, c)
wfa_results = genalyzer.get_wfa_results(qwf, c)
pprint.pprint(wfa_results)
genalyzer.config_free(c)
genalyzer.config_free(c)
Loading

0 comments on commit 7e7c24a

Please sign in to comment.