kopia lustrzana https://github.com/NanoVNA-Saver/nanovna-saver
Remove everything that is only needed for the GUI.
rodzic
a04d6d9b39
commit
c99333c97b
|
@ -1,9 +0,0 @@
|
|||
# .coveragerc to control coverage.py
|
||||
[run]
|
||||
branch = True
|
||||
source = tests
|
||||
#omit = src/
|
||||
|
||||
[report]
|
||||
fail_under = 90.0
|
||||
show_missing = True
|
|
@ -1,7 +0,0 @@
|
|||
# Default for all text files
|
||||
* text=auto whitespace=trailing-space,tab-in-indent,tabwidth=2
|
||||
*.py text=auto whitespace=trailing-space,tab-in-indent,tabwidth=4
|
||||
|
||||
# Denote all files that are truly binary and should not be modified.
|
||||
*.png binary
|
||||
*.jpg binary
|
|
@ -1,2 +0,0 @@
|
|||
* @mihtjel
|
||||
* @zarath
|
|
@ -1,37 +0,0 @@
|
|||
---
|
||||
name: Bug Report
|
||||
about: Create a report to help NanoVNA-Saver to improve
|
||||
title: "bug: "
|
||||
labels: "bug"
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
# Bug Report
|
||||
|
||||
**NanoVNA-Saver version:**
|
||||
|
||||
<!-- Please specify commit or tag version. -->
|
||||
|
||||
**Current behavior:**
|
||||
|
||||
<!-- Describe how the bug manifests. -->
|
||||
|
||||
**Expected behavior:**
|
||||
|
||||
<!-- Describe what you expect the behavior to be without the bug. -->
|
||||
|
||||
**Steps to reproduce:**
|
||||
|
||||
<!-- Explain the steps required to duplicate the issue, especially if you are able to provide a sample application. -->
|
||||
|
||||
**Related code:**
|
||||
|
||||
<!-- If you are able to illustrate the bug or feature request with an example, please provide it here. -->
|
||||
|
||||
```
|
||||
insert short code snippets here
|
||||
```
|
||||
|
||||
**Other information:**
|
||||
|
||||
<!-- List any other information that is relevant to your issue. Related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->
|
|
@ -1,35 +0,0 @@
|
|||
---
|
||||
name: Feature Request
|
||||
about: Suggest an idea for this project
|
||||
title: "feat: "
|
||||
labels: "enhancement"
|
||||
assignees: ""
|
||||
---
|
||||
|
||||
# Feature Request
|
||||
|
||||
**Describe the Feature Request**
|
||||
|
||||
<!-- A clear and concise description of what the feature request is. Please include if your feature request is related to a problem. -->
|
||||
|
||||
**Describe Preferred Solution**
|
||||
|
||||
<!-- A clear and concise description of what you want to happen. -->
|
||||
|
||||
**Describe Alternatives**
|
||||
|
||||
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
|
||||
|
||||
**Related Code**
|
||||
|
||||
<!-- If you are able to illustrate the bug or feature request with an example, please provide it here. -->
|
||||
|
||||
**Additional Context**
|
||||
|
||||
<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to add, use case, Stack Overflow links, forum links, screenshots, OS if applicable, etc. -->
|
||||
|
||||
**If the feature request is approved, would you be willing to submit a PR?**
|
||||
_(Help can be provided if you need assistance submitting a PR)_
|
||||
|
||||
- [ ] Yes
|
||||
- [ ] No
|
|
@ -1,7 +0,0 @@
|
|||
---
|
||||
name: Codebase improvement
|
||||
about: Provide your feedback for the existing codebase. Suggest a better solution for algorithms, development tools, etc.
|
||||
title: "dev: "
|
||||
labels: "enhancement"
|
||||
assignees: ""
|
||||
---
|
|
@ -1,32 +0,0 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Python version: [if applicable]
|
||||
- NanoVNA-Saver version: [e.g. 0.1.4]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
|
@ -1,6 +0,0 @@
|
|||
---
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: NanoVNA-Saver Community Support
|
||||
url: https://github.com/zarath@gmx.de/nanovna-saver/discussions
|
||||
about: Please ask and answer questions here.
|
|
@ -1,20 +0,0 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
|
@ -1,40 +0,0 @@
|
|||
<!--- Please provide a general summary of your changes in the title above -->
|
||||
|
||||
## Pull Request type
|
||||
|
||||
<!-- Please try to limit your pull request to one type; submit multiple pull requests if needed. -->
|
||||
|
||||
Please check the type of change your PR introduces:
|
||||
|
||||
- [] Bugfix
|
||||
- [] Feature
|
||||
- [] Code style update (formatting, renaming)
|
||||
- [] Refactoring (no functional changes, no API changes)
|
||||
- [] Build-related changes
|
||||
- [] Documentation content changes
|
||||
- [] Other (please describe):
|
||||
|
||||
## What is the current behavior?
|
||||
|
||||
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
|
||||
|
||||
Issue Number: N/A
|
||||
|
||||
## What is the new behavior?
|
||||
|
||||
<!-- Please describe the behavior or changes that are being added by this PR. -->
|
||||
|
||||
-
|
||||
-
|
||||
-
|
||||
|
||||
## Does this introduce a breaking change?
|
||||
|
||||
- [] Yes
|
||||
- [] No
|
||||
|
||||
<!-- If this does introduce a breaking change, please describe the impact and migration path for existing applications below. -->
|
||||
|
||||
## Other information
|
||||
|
||||
<!-- Any other information that is important to this PR, such as screenshots of how the component looks before and after the change. -->
|
|
@ -1,72 +0,0 @@
|
|||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ "main" ]
|
||||
schedule:
|
||||
- cron: '19 8 * * 5'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'python' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
|
||||
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
||||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
||||
|
||||
# - run: |
|
||||
# echo "Run, Build Application using script"
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
|
@ -1,37 +0,0 @@
|
|||
name: Python Coverage
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- development
|
||||
|
||||
jobs:
|
||||
coverage:
|
||||
name: Coverage
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
# os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
os: [ubuntu-latest]
|
||||
# python-version: [3.7, 3.8]
|
||||
python-version: [3.8, 3.9]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python 3
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
- name: Lint with pylint
|
||||
run: |
|
||||
pip install pylint
|
||||
pylint --exit-zero NanoVNASaver
|
||||
- name: Unittests / Coverage
|
||||
run: |
|
||||
pip install pytest-cov
|
||||
pytest --cov=NanoVNASaver
|
|
@ -1,48 +0,0 @@
|
|||
name: Modern Linux Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Install python
|
||||
run: |
|
||||
sudo add-apt-repository ppa:deadsnakes/ppa
|
||||
sudo apt-get update
|
||||
sudo apt install -y python3.11 python3-pip python3.11-venv \
|
||||
python3.11-dev \
|
||||
'^libxcb.*-dev' libx11-xcb-dev \
|
||||
libglu1-mesa-dev libxrender-dev libxi-dev \
|
||||
libxkbcommon-dev libxkbcommon-x11-dev
|
||||
- name: Install dependencies and pyinstall
|
||||
run: |
|
||||
python3.11 -m venv build
|
||||
. build/bin/activate
|
||||
python -m pip install pip==23.3.2 setuptools==69.0.3
|
||||
pip install -r requirements.txt
|
||||
pip install PyInstaller==6.3.0
|
||||
- name: Build binary
|
||||
run: |
|
||||
. build/bin/activate
|
||||
python setup.py -V
|
||||
pyinstaller --onefile \
|
||||
-p src \
|
||||
--add-data "build/lib/python3.11/site-packages/PyQt6/sip.*.so:PyQt6/sip.so" \
|
||||
--add-data "build/lib/python3.11/site-packages/PyQt6/Qt6:PyQt6/Qt6"
|
||||
-n nanovna-saver \
|
||||
nanovna-saver.py
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: NanoVNASaver.linux_modern
|
||||
path: dist/nanovna-saver
|
|
@ -1,35 +0,0 @@
|
|||
name: Mac Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.11
|
||||
- name: Install dependencies and pyinstall
|
||||
run: |
|
||||
python -m pip install pip==23.3.2 setuptools==69.0.3
|
||||
pip install -r requirements.txt
|
||||
pip install PyInstaller==6.3.0
|
||||
- name: Build binary
|
||||
run: |
|
||||
python setup.py -V
|
||||
pyinstaller --onefile -p src -n nanovna-saver nanovna-saver.py
|
||||
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: NanoVNASaver.macos
|
||||
path: dist/nanovna-saver
|
|
@ -1,43 +0,0 @@
|
|||
name: Mac Release App
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.11
|
||||
- name: Get Target Environment
|
||||
id: targetenv
|
||||
run: |
|
||||
echo "arch=`uname -m`" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Install dependencies and pyinstall
|
||||
run: |
|
||||
python -m pip install pip==23.3.2 setuptools==69.0.3
|
||||
pip install -r requirements.txt
|
||||
pip install PyInstaller==6.3.0
|
||||
|
||||
- name: Build binary
|
||||
run: |
|
||||
python setup.py -V
|
||||
pyinstaller --onedir -p src -n NanoVNASaver nanovna-saver.py --window --clean -y -i icon_48x48.icns
|
||||
tar -C dist -zcf ./dist/NanoVNASaver.app-${{ env.arch }}.tar.gz NanoVNASaver.app
|
||||
echo "Created: NanoVNASaver.app-${{ env.arch }}.tar.gz"
|
||||
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: NanoVNASaver.app-${{ env.arch }}.tar.gz
|
||||
path: dist/NanoVNASaver.app-${{ env.arch }}.tar.gz
|
|
@ -1,44 +0,0 @@
|
|||
name: Windows Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [x64, ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.11
|
||||
architecture: ${{ matrix.arch }}
|
||||
- name: Install dependencies and pyinstall
|
||||
run: |
|
||||
python3 -m venv venv
|
||||
.\venv\Scripts\activate
|
||||
python3 -m pip install pip==23.3.2
|
||||
python3 -m pip install -U setuptools setuptools-scm
|
||||
python3 -m pip install -r requirements.txt
|
||||
python3 -m pip install PyInstaller==6.3.0
|
||||
python3 -m pip uninstall -y PyQt6-sip
|
||||
python3 -m pip install PyQt6-sip==13.6.0
|
||||
- name: Build binary
|
||||
run: |
|
||||
.\venv\Scripts\activate
|
||||
python3 setup.py -V
|
||||
pyinstaller --onefile --noconsole -i icon_48x48.ico -p src -n nanovna-saver.exe nanovna-saver.py
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: NanoVNASaver.${{ matrix.arch }}
|
||||
path: dist/nanovna-saver.exe
|
|
@ -1,44 +0,0 @@
|
|||
---
|
||||
name: Stale
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 8 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
name: 🧹 Clean up stale issues and PRs
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🚀 Run stale
|
||||
uses: actions/stale@v3
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
days-before-stale: 90
|
||||
days-before-close: 30
|
||||
remove-stale-when-updated: true
|
||||
stale-issue-label: "stale"
|
||||
exempt-issue-labels: "no-stale,help-wanted"
|
||||
stale-issue-message: >
|
||||
There hasn't been any activity on this issue recently, and in order
|
||||
to prioritize active issues, it will be marked as stale.
|
||||
|
||||
Please make sure to update to the latest version and
|
||||
check if that solves the issue. Let us know if that works for you
|
||||
by leaving a 👍
|
||||
|
||||
Because this issue is marked as stale, it will be closed and locked
|
||||
in 7 days if no further activity occurs.
|
||||
|
||||
Thank you for your contributions!
|
||||
stale-pr-label: "stale"
|
||||
exempt-pr-labels: "no-stale"
|
||||
stale-pr-message: >
|
||||
There hasn't been any activity on this pull request recently, and in
|
||||
order to prioritize active work, it has been marked as stale.
|
||||
|
||||
This PR will be closed and locked in 7 days if no further activity
|
||||
occurs.
|
||||
|
||||
Thank you for your contributions!
|
15
.pylintrc
15
.pylintrc
|
@ -1,15 +0,0 @@
|
|||
[MESSAGES CONTROL]
|
||||
disable=W0614,C0410,C0321,C0111,I0011,C0103
|
||||
# allow _ for ignored variables
|
||||
# allow generic names like a,b,c and i,j,k,l,m,n and x,y,z
|
||||
# allow k,v for key/value
|
||||
# allow e for exceptions, it for iterator
|
||||
# allow w,h for width, height
|
||||
# allow op for operation/operator/opcode
|
||||
# allow t, t0, t1, t2, and t3 for time
|
||||
# allow dt for delta time
|
||||
# allow db for database
|
||||
# allow ls for list
|
||||
good-names=_,a,b,c,dt,db,e,f,fn,fd,i,j,k,v,kv,kw,l,m,n,ls,t,t0,t1,t2,t3,w,h,x,y,z,it,op
|
||||
[MASTER]
|
||||
extension-pkg-allow-list=PyQt6.QtWidgets,PyQt6.QtGui,PyQt6.QtCore
|
|
@ -41,3 +41,4 @@ Contributors
|
|||
* sysjoint-tek <63992872+sysjoint-tek@users.noreply.github.com>
|
||||
* Thomas de Lellis <24543390+t52ta6ek@users.noreply.github.com>
|
||||
* zstadler <zeev.stadler@gmail.com>
|
||||
* tbergkvist <bergkvist.teo@protonmail.com>
|
||||
|
|
322
CONTRIBUTING.rst
322
CONTRIBUTING.rst
|
@ -1,322 +0,0 @@
|
|||
============
|
||||
Contributing
|
||||
============
|
||||
|
||||
Welcome to ``nanovna-saver`` contributor's guide.
|
||||
|
||||
This document focuses on getting any potential contributor familiarized
|
||||
with the development processes, but `other kinds of contributions`_ are also
|
||||
appreciated.
|
||||
|
||||
If you are new to using git_ or have never collaborated in a project previously,
|
||||
please have a look at `contribution-guide.org`_. Other resources are also
|
||||
listed in the excellent `guide created by FreeCodeCamp`_ [#contrib1]_.
|
||||
|
||||
Please notice, all users and contributors are expected to be **open,
|
||||
considerate, reasonable, and respectful**. When in doubt, `Python Software
|
||||
Foundation's Code of Conduct`_ is a good reference in terms of behavior
|
||||
guidelines.
|
||||
|
||||
|
||||
Issue Reports
|
||||
=============
|
||||
|
||||
If you experience bugs or general issues with ``nanovna-saver``, please have a look
|
||||
on the `issue tracker`_. If you don't see anything useful there, please feel
|
||||
free to fire an issue report.
|
||||
|
||||
.. tip::
|
||||
Please don't forget to include the closed issues in your search.
|
||||
Sometimes a solution was already reported, and the problem is considered
|
||||
**solved**.
|
||||
|
||||
New issue reports should include information about your programming environment
|
||||
(e.g., operating system, Python version) and steps to reproduce the problem.
|
||||
Please try also to simplify the reproduction steps to a very minimal example
|
||||
that still illustrates the problem you are facing. By removing other factors,
|
||||
you help us to identify the root cause of the issue.
|
||||
|
||||
|
||||
Documentation Improvements
|
||||
==========================
|
||||
|
||||
You can help improve ``nanovna-saver`` docs by making them more readable and coherent, or
|
||||
by adding missing information and correcting mistakes.
|
||||
|
||||
``nanovna-saver`` documentation should use Sphinx_ as its main documentation compiler.
|
||||
This means that the docs are kept in the same repository as the project code, and
|
||||
that any documentation update is done in the same way was a code contribution.
|
||||
|
||||
.. tip::
|
||||
Please notice that the `GitHub web interface`_ provides a quick way of
|
||||
propose changes in ``nanovna-saver``'s files. While this mechanism can
|
||||
be tricky for normal code contributions, it works perfectly fine for
|
||||
contributing to the docs, and can be quite handy.
|
||||
|
||||
If you are interested in trying this method out, please navigate to
|
||||
the ``docs`` folder in the source repository_, find which file you
|
||||
would like to propose changes and click in the little pencil icon at the
|
||||
top, to open `GitHub's code editor`_. Once you finish editing the file,
|
||||
please write a message in the form at the bottom of the page describing
|
||||
which changes have you made and what are the motivations behind them and
|
||||
submit your proposal.
|
||||
|
||||
When working on documentation changes in your local machine, you can
|
||||
compile them using |tox|_::
|
||||
|
||||
tox -e docs
|
||||
|
||||
and use Python's built-in web server for a preview in your web browser
|
||||
(``http://localhost:8000``)::
|
||||
|
||||
python3 -m http.server --directory 'docs/_build/html'
|
||||
|
||||
|
||||
Code Contributions
|
||||
==================
|
||||
|
||||
.. todo:: Please include a reference or explanation about the internals of the project.
|
||||
|
||||
An architecture description, design principles or at least a summary of the
|
||||
main concepts will make it easy for potential contributors to get started
|
||||
quickly.
|
||||
|
||||
Submit an issue
|
||||
---------------
|
||||
|
||||
Before you work on any non-trivial code contribution it's best to first create
|
||||
a report in the `issue tracker`_ to start a discussion on the subject.
|
||||
This often provides additional considerations and avoids unnecessary work.
|
||||
|
||||
Create an environment
|
||||
---------------------
|
||||
|
||||
Before you start coding, we recommend creating an isolated `virtual
|
||||
environment`_ to avoid any problems with your installed Python packages.
|
||||
This can easily be done via either |virtualenv|_::
|
||||
|
||||
virtualenv <PATH TO VENV>
|
||||
source <PATH TO VENV>/bin/activate
|
||||
|
||||
or Miniconda_::
|
||||
|
||||
conda create -n nanovna-saver python=3 six virtualenv pytest pytest-cov
|
||||
conda activate nanovna-saver
|
||||
|
||||
Clone the repository
|
||||
--------------------
|
||||
|
||||
#. Create an user account on |the repository service| if you do not already have one.
|
||||
#. Fork the project repository_: click on the *Fork* button near the top of the
|
||||
page. This creates a copy of the code under your account on |the repository service|.
|
||||
#. Clone this copy to your local disk::
|
||||
|
||||
git clone git@github.com:YourLogin/nanovna-saver.git
|
||||
cd nanovna-saver
|
||||
|
||||
#. You should run::
|
||||
|
||||
pip install -U pip setuptools -e .
|
||||
|
||||
to be able to import the package under development in the Python REPL.
|
||||
|
||||
.. todo:: if you are not using pre-commit, please remove the following item:
|
||||
|
||||
#. Install |pre-commit|_::
|
||||
|
||||
pip install pre-commit
|
||||
pre-commit install
|
||||
|
||||
``nanovna-saver`` comes with a lot of hooks configured to automatically help the
|
||||
developer to check the code being written.
|
||||
|
||||
Implement your changes
|
||||
----------------------
|
||||
|
||||
#. Create a branch to hold your changes::
|
||||
|
||||
git checkout -b my-feature
|
||||
|
||||
and start making changes. Never work on the main branch!
|
||||
|
||||
#. Start your work on this branch. Don't forget to add docstrings_ to new
|
||||
functions, modules and classes, especially if they are part of public APIs.
|
||||
|
||||
#. Add yourself to the list of contributors in ``AUTHORS.rst``.
|
||||
|
||||
#. When you’re done editing, do::
|
||||
|
||||
git add <MODIFIED FILES>
|
||||
git commit
|
||||
|
||||
to record your changes in git_.
|
||||
|
||||
.. todo:: if you are not using pre-commit, please remove the following item:
|
||||
|
||||
Please make sure to see the validation messages from |pre-commit|_ and fix
|
||||
any eventual issues.
|
||||
This should automatically use flake8_/black_ to check/fix the code style
|
||||
in a way that is compatible with the project.
|
||||
|
||||
.. important:: Don't forget to add unit tests and documentation in case your
|
||||
contribution adds an additional feature and is not just a bugfix.
|
||||
|
||||
Moreover, writing a `descriptive commit message`_ is highly recommended.
|
||||
In case of doubt, you can check the commit history with::
|
||||
|
||||
git log --graph --decorate --pretty=oneline --abbrev-commit --all
|
||||
|
||||
to look for recurring communication patterns.
|
||||
|
||||
#. Please check that your changes don't break any unit tests with::
|
||||
|
||||
tox
|
||||
|
||||
(after having installed |tox|_ with ``pip install tox`` or ``pipx``).
|
||||
|
||||
You can also use |tox|_ to run several other pre-configured tasks in the
|
||||
repository. Try ``tox -av`` to see a list of the available checks.
|
||||
|
||||
Submit your contribution
|
||||
------------------------
|
||||
|
||||
#. If everything works fine, push your local branch to |the repository service| with::
|
||||
|
||||
git push -u origin my-feature
|
||||
|
||||
#. Go to the web page of your fork and click |contribute button|
|
||||
to send your changes for review.
|
||||
|
||||
.. todo:: if you are using GitHub, you can uncomment the following paragraph
|
||||
|
||||
Find more detailed information in `creating a PR`_. You might also want to open
|
||||
the PR as a draft first and mark it as ready for review after the feedbacks
|
||||
from the continuous integration (CI) system or any required fixes.
|
||||
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
|
||||
The following tips can be used when facing problems to build or test the
|
||||
package:
|
||||
|
||||
#. Make sure to fetch all the tags from the upstream repository_.
|
||||
The command ``git describe --abbrev=0 --tags`` should return the version you
|
||||
are expecting. If you are trying to run CI scripts in a fork repository,
|
||||
make sure to push all the tags.
|
||||
You can also try to remove all the egg files or the complete egg folder, i.e.,
|
||||
``.eggs``, as well as the ``*.egg-info`` folders in the ``src`` folder or
|
||||
potentially in the root of your project.
|
||||
|
||||
#. Sometimes |tox|_ misses out when new dependencies are added, especially to
|
||||
``setup.cfg`` and ``docs/requirements.txt``. If you find any problems with
|
||||
missing dependencies when running a command with |tox|_, try to recreate the
|
||||
``tox`` environment using the ``-r`` flag. For example, instead of::
|
||||
|
||||
tox -e docs
|
||||
|
||||
Try running::
|
||||
|
||||
tox -r -e docs
|
||||
|
||||
#. Make sure to have a reliable |tox|_ installation that uses the correct
|
||||
Python version (e.g., 3.7+). When in doubt you can run::
|
||||
|
||||
tox --version
|
||||
# OR
|
||||
which tox
|
||||
|
||||
If you have trouble and are seeing weird errors upon running |tox|_, you can
|
||||
also try to create a dedicated `virtual environment`_ with a |tox|_ binary
|
||||
freshly installed. For example::
|
||||
|
||||
virtualenv .venv
|
||||
source .venv/bin/activate
|
||||
.venv/bin/pip install tox
|
||||
.venv/bin/tox -e all
|
||||
|
||||
#. `Pytest can drop you`_ in an interactive session in the case an error occurs.
|
||||
In order to do that you need to pass a ``--pdb`` option (for example by
|
||||
running ``tox -- -k <NAME OF THE FALLING TEST> --pdb``).
|
||||
You can also setup breakpoints manually instead of using the ``--pdb`` option.
|
||||
|
||||
|
||||
Maintainer tasks
|
||||
================
|
||||
|
||||
Releases
|
||||
--------
|
||||
|
||||
.. todo:: This section assumes you are using PyPI to publicly release your package.
|
||||
|
||||
If instead you are using a different/private package index, please update
|
||||
the instructions accordingly.
|
||||
|
||||
If you are part of the group of maintainers and have correct user permissions
|
||||
on PyPI_, the following steps can be used to release a new version for
|
||||
``nanovna-saver``:
|
||||
|
||||
#. Make sure all unit tests are successful.
|
||||
#. Tag the current commit on the main branch with a release tag, e.g., ``v1.2.3``.
|
||||
#. Push the new tag to the upstream repository_, e.g., ``git push upstream v1.2.3``
|
||||
#. Clean up the ``dist`` and ``build`` folders with ``tox -e clean``
|
||||
(or ``rm -rf dist build``)
|
||||
to avoid confusion with old builds and Sphinx docs.
|
||||
#. Run ``tox -e build`` and check that the files in ``dist`` have
|
||||
the correct version (no ``.dirty`` or git_ hash) according to the git_ tag.
|
||||
Also check the sizes of the distributions, if they are too big (e.g., >
|
||||
500KB), unwanted clutter may have been accidentally included.
|
||||
#. Run ``tox -e publish -- --repository pypi`` and check that everything was
|
||||
uploaded to PyPI_ correctly.
|
||||
|
||||
|
||||
|
||||
.. [#contrib1] Even though, these resources focus on open source projects and
|
||||
communities, the general ideas behind collaborating with other developers
|
||||
to collectively create software are general and can be applied to all sorts
|
||||
of environments, including private companies and proprietary code bases.
|
||||
|
||||
|
||||
.. <-- start -->
|
||||
.. todo:: Please review and change the following definitions:
|
||||
|
||||
.. |the repository service| replace:: GitHub
|
||||
.. |contribute button| replace:: "Create pull request"
|
||||
|
||||
.. _repository: https://github.com/<USERNAME>/nanovna-saver
|
||||
.. _issue tracker: https://github.com/<USERNAME>/nanovna-saver/issues
|
||||
.. <-- end -->
|
||||
|
||||
|
||||
.. |virtualenv| replace:: ``virtualenv``
|
||||
.. |pre-commit| replace:: ``pre-commit``
|
||||
.. |tox| replace:: ``tox``
|
||||
|
||||
|
||||
.. _black: https://pypi.org/project/black/
|
||||
.. _CommonMark: https://commonmark.org/
|
||||
.. _contribution-guide.org: https://www.contribution-guide.org/
|
||||
.. _creating a PR: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request
|
||||
.. _descriptive commit message: https://chris.beams.io/posts/git-commit
|
||||
.. _docstrings: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
|
||||
.. _first-contributions tutorial: https://github.com/firstcontributions/first-contributions
|
||||
.. _flake8: https://flake8.pycqa.org/en/stable/
|
||||
.. _git: https://git-scm.com
|
||||
.. _GitHub's fork and pull request workflow: https://guides.github.com/activities/forking/
|
||||
.. _guide created by FreeCodeCamp: https://github.com/FreeCodeCamp/how-to-contribute-to-open-source
|
||||
.. _Miniconda: https://docs.conda.io/en/latest/miniconda.html
|
||||
.. _MyST: https://myst-parser.readthedocs.io/en/latest/syntax/syntax.html
|
||||
.. _other kinds of contributions: https://opensource.guide/how-to-contribute
|
||||
.. _pre-commit: https://pre-commit.com/
|
||||
.. _PyPI: https://pypi.org/
|
||||
.. _PyScaffold's contributor's guide: https://pyscaffold.org/en/stable/contributing.html
|
||||
.. _Pytest can drop you: https://docs.pytest.org/en/stable/how-to/failures.html#using-python-library-pdb-with-pytest
|
||||
.. _Python Software Foundation's Code of Conduct: https://www.python.org/psf/conduct/
|
||||
.. _reStructuredText: https://www.sphinx-doc.org/en/master/usage/restructuredtext/
|
||||
.. _Sphinx: https://www.sphinx-doc.org/en/master/
|
||||
.. _tox: https://tox.wiki/en/stable/
|
||||
.. _virtual environment: https://realpython.com/python-virtual-environments-a-primer/
|
||||
.. _virtualenv: https://virtualenv.pypa.io/en/stable/
|
||||
|
||||
.. _GitHub web interface: https://docs.github.com/en/repositories/working-with-files/managing-files/editing-files
|
||||
.. _GitHub's code editor: https://docs.github.com/en/repositories/working-with-files/managing-files/editing-files
|
60
Makefile
60
Makefile
|
@ -1,60 +0,0 @@
|
|||
.PHONY: info
|
||||
info:
|
||||
@echo "- type 'make deb' to build a debian package"
|
||||
@echo "- type 'make rpm' to build an (experimental) rpm package"
|
||||
@echo "- you need the debian packages"
|
||||
@echo " fakeroot python3-setuptools python3-stdeb dh-python"
|
||||
@echo
|
||||
|
||||
|
||||
# build a new debian package and create a link in the current directory
|
||||
.PHONY: deb
|
||||
deb: clean
|
||||
@# build the deb package
|
||||
PYBUILD_DISABLE=test python3 setup.py \
|
||||
--command-packages=stdeb.command \
|
||||
sdist_dsc --compat 10 --package3 nanovnasaver --section electronics \
|
||||
bdist_deb
|
||||
@# create a link in the main directory
|
||||
-@ rm nanovnasaver_*_all.deb
|
||||
-@ln `ls deb_dist/nanovnasaver_*.deb | tail -1` .
|
||||
@# and show the result
|
||||
@ls -l nanovnasaver_*.deb
|
||||
|
||||
|
||||
# build a new rpm package and create a link in the current directory
|
||||
.PHONY: rpm
|
||||
rpm: clean
|
||||
@# build the rpm package
|
||||
PYBUILD_DISABLE=test python3 setup.py bdist_rpm
|
||||
@# create a link in the main directory
|
||||
-@ rm NanoVNASaver-*.noarch.rpm
|
||||
@ln `ls dist/NanoVNASaver-*.noarch.rpm | tail -1` .
|
||||
@# and show the result
|
||||
@ls -l NanoVNASaver-*.noarch.rpm
|
||||
|
||||
|
||||
# remove all package build artifacts (keep the *.deb)
|
||||
.PHONY: clean
|
||||
clean:
|
||||
python setup.py clean
|
||||
-rm -rf build deb_dist dist *.tar.gz *.egg*
|
||||
|
||||
|
||||
# remove all package build artefacts
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
-rm -f *.deb *.rpm
|
||||
|
||||
|
||||
# build and install a new debian package
|
||||
.PHONY: debinstall
|
||||
debinstall: deb
|
||||
sudo apt install ./nanovnasaver_*.deb
|
||||
|
||||
|
||||
# uninstall this debian package
|
||||
.PHONY: debuninstall
|
||||
debuninstall:
|
||||
sudo apt purge nanovnasaver
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
[Desktop Entry]
|
||||
Categories=Electronics;Education;
|
||||
Comment[de_DE]=Programm das Daten vom NanoVNA liest, anzeigt und speichert
|
||||
Comment=Tool for reading, displaying and saving data from the NanoVNA
|
||||
Exec=NanoVNASaver
|
||||
GenericName[de_DE]=
|
||||
GenericName=
|
||||
Icon=NanoVNASaver_48x48
|
||||
MimeType=
|
||||
Name[de_DE]=NanoVNASaver
|
||||
Name=NanoVNASaver
|
||||
StartupNotify=true
|
||||
Terminal=false
|
||||
Type=Application
|
||||
X-DBUS-ServiceName=
|
||||
X-DBUS-StartupType=
|
||||
X-KDE-SubstituteUID=false
|
||||
X-KDE-Username=
|
|
@ -1 +0,0 @@
|
|||
icon_48x48.png
|
|
@ -0,0 +1 @@
|
|||
# Code for using NanoVNASaver without the GUI.
|
271
README.rst
271
README.rst
|
@ -1,271 +0,0 @@
|
|||
.. role:: raw-html-m2r(raw)
|
||||
:format: html
|
||||
|
||||
.. image:: https://img.shields.io/github/v/release/NanoVNA-Saver/nanovna-saver.svg
|
||||
:target: https://github.com/NanoVNA-Saver/nanovna-saver/releases/latest
|
||||
:alt: Latest Release
|
||||
|
||||
.. image:: https://img.shields.io/github/license/NanoVNA-Saver/nanovna-saver.svg
|
||||
:target: https://github.com/NanoVNA-Saver/nanovna-saver/blob/master/LICENSE.txt
|
||||
:alt: License
|
||||
|
||||
.. image:: https://img.shields.io/github/downloads/NanoVNA-Saver/nanovna-saver/total.svg
|
||||
:target: https://github.com/NanoVNA-Saver/nanovna-saver/releases/
|
||||
:alt: Downloads
|
||||
|
||||
.. image:: https://img.shields.io/github/downloads/NanoVNA-Saver/nanovna-saver/latest/total
|
||||
:target: https://github.com/NanoVNA-Saver/nanovna-saver/releases/latest
|
||||
:alt: GitHub Releases
|
||||
|
||||
.. image:: https://img.shields.io/badge/paypal-donate-yellow.svg
|
||||
:target: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=T8KTGVDQF5K6E&item_name=NanoVNASaver+Development¤cy_code=EUR&source=url
|
||||
:alt: Donate
|
||||
|
||||
NanoVNASaver
|
||||
============
|
||||
|
||||
A multiplatform tool to save Touchstone files from the NanoVNA,
|
||||
sweep frequency spans in segments to gain more than 101 data
|
||||
points, and generally display and analyze the resulting data.
|
||||
|
||||
|
||||
* Copyright 2019, 2020 Rune B. Broberg
|
||||
* Copyright 2020ff NanoVNA-Saver Authors
|
||||
|
||||
It's developed in **Python 3 (>=3.8)** using **PyQt6**, **numpy** and
|
||||
**scipy**.
|
||||
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
This software connects to a NanoVNA and extracts the data for
|
||||
display on a computer and allows saving the sweep data to Touchstone files.
|
||||
|
||||
:raw-html-m2r:`<a href="#current-features"></a>`
|
||||
|
||||
Current features
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
|
||||
* Reading data from a NanoVNA -- Compatible devices: NanoVNA, NanoVNA-H,
|
||||
NanoVNA-H4, NanoVNA-F, AVNA via Teensy
|
||||
* Reading data from a TinySA
|
||||
* Splitting a frequency range into multiple segments to increase resolution
|
||||
(tried up to >10k points)
|
||||
* Averaging data for better results particularly at higher frequencies
|
||||
* Displaying data on multiple chart types, such as Smith, LogMag, Phase and
|
||||
VSWR-charts, for both S11 and S21
|
||||
* Displaying markers, and the impedance, VSWR, Q, equivalent
|
||||
capacitance/inductance etc. at these locations
|
||||
* Displaying customizable frequency bands as reference, for example amateur
|
||||
radio bands
|
||||
* Exporting and importing 1-port and 2-port Touchstone files
|
||||
* TDR function (measurement of cable length) - including impedance display
|
||||
* Filter analysis functions for low-pass, high-pass, band-pass and band-stop
|
||||
filters
|
||||
* Display of both an active and a reference trace
|
||||
* Live updates of data from the NanoVNA, including for multi-segment sweeps
|
||||
* In-application calibration, including compensation for non-ideal calibration
|
||||
standards
|
||||
* Customizable display options, including "dark mode"
|
||||
* Exporting images of plotted values
|
||||
|
||||
Screenshot
|
||||
^^^^^^^^^^
|
||||
|
||||
|
||||
.. image:: https://i.imgur.com/ZoFsV2V.png
|
||||
:target: https://i.imgur.com/ZoFsV2V.png
|
||||
:alt: Screenshot of version 0.1.4
|
||||
|
||||
|
||||
Running the application
|
||||
-----------------------
|
||||
|
||||
Main development is currently done on Linux (Mint 21 "Vanessa" Cinnamon)
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Binary releases
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
You can find current binary releases for Windows, Linux and MacOS under
|
||||
https://github.com/NanoVNA-Saver/nanovna-saver/releases/latest
|
||||
|
||||
The 32bit Windows binaries are somewhat smaller and seems to be a
|
||||
little bit more stable.
|
||||
|
||||
`Detailed installation instructions <docs/INSTALLATION.md>`_
|
||||
|
||||
Using the software
|
||||
------------------
|
||||
|
||||
Connect your NanoVNA to a serial port, and enter this serial port in the serial
|
||||
port box. If the NanoVNA is connected before the application starts, it should
|
||||
be automatically detected. Otherwise, click "Rescan". Click "Connect to device"
|
||||
to connect.
|
||||
|
||||
The app can collect multiple segments to get more accurate measurements. Enter
|
||||
the number of segments to be done in the "Segments" box. Each segment is 101
|
||||
data points, and takes about 1.5 seconds to complete.
|
||||
|
||||
Frequencies are entered in Hz, or suffixed with k or M. Scientific notation
|
||||
(6.5e6 for 6.5MHz) also works.
|
||||
|
||||
Markers can be manually entered, or controlled using the mouse. For mouse
|
||||
control, select the active marker using the radio buttons, or hold "shift"
|
||||
while clicking to drag the nearest marker. The marker readout boxes show the
|
||||
actual frequency where values are measured. Marker readouts can be hidden
|
||||
using the "hide data" button when not needed.
|
||||
|
||||
Display settings are available under "Display setup". These allow changing the
|
||||
chart colours, the application font size and which graphs are displayed. The
|
||||
settings are saved between program starts.
|
||||
|
||||
Calibration
|
||||
^^^^^^^^^^^
|
||||
|
||||
*Before using NanoVNA-Saver, please ensure that the device itself is in a
|
||||
reasonable calibration state.*
|
||||
|
||||
A calibration of both ports across the entire frequency span, saved to save
|
||||
slot 0, is sufficient. If the NanoVNA is completely uncalibrated, its readings
|
||||
may be outside the range accepted by the application.
|
||||
|
||||
In-application calibration is available, either assuming ideal standards or
|
||||
with relevant standard correction. To manually calibrate, sweep each standard
|
||||
in turn and press the relevant button in the calibration window.
|
||||
For assisted calibration, press the "Calibration Assistant" button. If desired,
|
||||
enter a note in the provided field describing the conditions under which the
|
||||
calibration was performed.
|
||||
|
||||
Calibration results may be saved and loaded using the provided buttons at the
|
||||
bottom of the window. Notes are saved and loaded along with the calibration
|
||||
data.
|
||||
|
||||
|
||||
.. image:: https://i.imgur.com/p94cxOX.png
|
||||
:target: https://i.imgur.com/p94cxOX.png
|
||||
:alt: Screenshot of Calibration Window
|
||||
|
||||
|
||||
Users of known characterized calibration standard sets can enter the data for
|
||||
these, and save the sets.
|
||||
|
||||
After pressing *Apply*\ , the calibration is immediately applied to the latest
|
||||
sweep data.
|
||||
|
||||
! *Currently, load capacitance is unsupported* !
|
||||
|
||||
TDR
|
||||
^^^
|
||||
|
||||
To get accurate TDR measurements, calibrate the device, and attach the cable to
|
||||
be measured at the calibration plane - i.e. at the same position where the
|
||||
calibration load would be attached. Open the "Time Domain Reflectometry"
|
||||
window, and select the correct cable type, or manually enter a propagation
|
||||
factor.
|
||||
|
||||
Measuring inductor core permeability
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The permeability (mu) of cores can be measured using a one-port measurement.
|
||||
Put one or more windings on a core of known dimensions and use the "S11 mu"
|
||||
plot from the "Display Setup". The core dimensions (cross section area in mm2,
|
||||
effective length in mm) and number of windings can be set in the context menu
|
||||
for the plot (right click on the plot).
|
||||
|
||||
Latest Changes
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
* Using PyQt6
|
||||
* Moved to PyScaffold project structure
|
||||
* Fixed crash in resonance analysis
|
||||
* Added TinySA readout and screenshot
|
||||
|
||||
|
||||
Changes in 0.5.5
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
* Measuring inductor core permeability
|
||||
* Bugfixes for calibration data loading and saving
|
||||
* Let V2 Devices more time for usb-serial setup
|
||||
* Make some windows scrollable
|
||||
|
||||
Changes in 0.5.4
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
* Bugfixes for Python3.11 compatability
|
||||
* Bugfix for Python3.8 compatability
|
||||
* use math instead of table for log step calculation
|
||||
* Support of NanoVNA V2 Plus5 on Windows
|
||||
* New SI prefixes added - Ronna, Quetta
|
||||
* addes a Makefile to build a packages
|
||||
* Simplyfied sweep worker
|
||||
* Fixed calibration data loading
|
||||
* Explicit import of scipy functions - #555
|
||||
* Refactoring of Analysis modules
|
||||
|
||||
Contributing
|
||||
------------
|
||||
|
||||
First off, thanks for taking the time to contribute! Contributions are what
|
||||
make the open-source community such an amazing place to learn, inspire, and
|
||||
create. Any contributions you make will benefit everybody else and are
|
||||
**greatly appreciated**.
|
||||
|
||||
Please read `our contribution guidelines <docs/CONTRIBUTING.md>`_\ , and thank
|
||||
you for being involved!
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
This software is licensed under version 3 of the GNU General Public License. It
|
||||
comes with NO WARRANTY.
|
||||
|
||||
You can use it, commercially as well. You may make changes to the code, but I
|
||||
(and the license) ask that you give these changes back to the community.
|
||||
|
||||
References
|
||||
----------
|
||||
|
||||
|
||||
* Ohan Smit wrote an introduction to using the application:
|
||||
[https://zs1sci.com/blog/nanovnasaver/]
|
||||
* HexAndFlex wrote a 3-part (thus far) series on Getting Started with the
|
||||
NanoVNA:
|
||||
[https://hexandflex.com/2019/08/31/getting-started-with-the-nanovna-part-1/]
|
||||
- Part 3 is dedicated to NanoVNASaver:
|
||||
[https://hexandflex.com/2019/09/15/getting-started-with-the-nanovna-part-3-pc-software/]
|
||||
* Gunthard Kraus did documentation in English and German:
|
||||
[http://www.gunthard-kraus.de/fertig_NanoVNA/English/]
|
||||
[http://www.gunthard-kraus.de/fertig_NanoVNA/Deutsch/]
|
||||
|
||||
Acknowledgements
|
||||
----------------
|
||||
|
||||
Original application by Rune B. Broberg (5Q5R)
|
||||
|
||||
Contributions and changes by Holger Müller (DG5DBH), David Hunt and others.
|
||||
|
||||
TDR inspiration shamelessly stolen from the work of Salil (VU2CWA) at
|
||||
https://nuclearrambo.com/wordpress/accurately-measuring-cable-length-with-nanovna/
|
||||
|
||||
TDR cable types by Larry Goga.
|
||||
|
||||
Bugfixes and Python installation work by Ohan Smit.
|
||||
|
||||
Thanks to everyone who have tested, commented and inspired. Particular thanks
|
||||
go to the alpha testing crew who suffer the early instability of new versions.
|
||||
|
||||
This software is available free of charge. If you read all this way, and you
|
||||
*still* want to support it, you may donate to the developer using the button
|
||||
below:
|
||||
|
||||
|
||||
.. image:: https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif
|
||||
:target: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=T8KTGVDQF5K6E&item_name=NanoVNASaver+Development¤cy_code=EUR&source=url
|
||||
:alt: Paypal
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
# Builds a NanoVNASaver.app on MacOS
|
||||
# ensure you have pyqt >=6.4 installed (brew install pyqt)
|
||||
#
|
||||
export VENV_DIR=macbuildenv
|
||||
|
||||
# setup build venv
|
||||
python3 -m venv ${VENV_DIR}
|
||||
. ./${VENV_DIR}/bin/activate
|
||||
|
||||
# install required dependencies (pyqt libs must be installed on the system)
|
||||
python3 -m pip install pip==23.0.1 setuptools==67.6.0
|
||||
pip install -r requirements.txt
|
||||
pip install PyInstaller==5.9.0
|
||||
|
||||
python3 setup.py -V
|
||||
|
||||
pyinstaller --onedir -p src -n NanoVNASaver nanovna-saver.py --window --clean -y -i icon_48x48.icns
|
||||
tar -C dist -zcf ./dist/NanoVNASaver.app-`uname -m`.tar.gz NanoVNASaver.app
|
||||
|
||||
deactivate
|
||||
rm -rf ${VENV_DIR}
|
3
debug.sh
3
debug.sh
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh
|
||||
export PYTHONPATH="src"
|
||||
exec python -m debugpy --listen 5678 --wait-for-client $@
|
|
@ -1,83 +0,0 @@
|
|||
Contributor Covenant Code of Conduct
|
||||
====================================
|
||||
|
||||
Our Pledge
|
||||
----------
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to make participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age,
|
||||
body size, disability, ethnicity, sex characteristics, gender identity and
|
||||
expression, level of experience, education, socio-economic status, nationality,
|
||||
personal appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
Our Standards
|
||||
-------------
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances Trolling, insulting/derogatory comments, and personal or political
|
||||
attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission Other conduct which could reasonably be
|
||||
considered inappropriate in a professional setting
|
||||
|
||||
Our Responsibilities
|
||||
--------------------
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
Scope
|
||||
-----
|
||||
|
||||
This Code of Conduct applies within all project spaces, and it also applies
|
||||
when an individual is representing the project or its community in public
|
||||
spaces. Examples of representing a project or community include using an
|
||||
official project email address, posting via an official social media account,
|
||||
or acting as an appointed representative at an online or offline event.
|
||||
Representation of a project may be further defined and clarified by project
|
||||
maintainers.
|
||||
|
||||
Enforcement
|
||||
-----------
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project maintainer using any of the [private contact
|
||||
addresses](https://github.com/Nanovna-Saver/nanovna-saver#support). All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an
|
||||
incident. Further details of specific enforcement policies may be posted
|
||||
separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor
|
||||
Covenant](https://www.contributor-covenant.org), version 1.4, available at
|
||||
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
<https://www.contributor-covenant.org/faq>
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
Contributing
|
||||
============
|
||||
|
||||
When contributing to this repository, please first discuss the change you wish
|
||||
to make via issue, email, or any other method with the owners of this
|
||||
repository before making a change.
|
||||
Please note we have a [code of conduct](CODE_OF_CONDUCT.md), please follow it
|
||||
in all your interactions with the project.
|
||||
|
||||
Development environment setup
|
||||
------------------------------
|
||||
|
||||
1. Clone the repo
|
||||
|
||||
```sh
|
||||
git clone https://github.com/NanoVNA-Saver/nanovna-saver
|
||||
```
|
||||
|
||||
2. TODO
|
||||
|
||||
## Issues and feature requests
|
||||
|
||||
You've found a bug in the source code, a mistake in the documentation or maybe
|
||||
you'd like a new feature?Take a look at [GitHub
|
||||
Discussions](https://github.com/NanoVNA-Saver/nanovna-saver/discussions) to see
|
||||
if it's already being discussed. You can help us by [submitting an issue on
|
||||
GitHub](https://github.com/NanoVNA-Saver/nanovna-saver/issues). Before you
|
||||
create an issue, make sure to search the issue archive -- your issue may have
|
||||
already been addressed!
|
||||
|
||||
Please try to create bug reports that are:
|
||||
|
||||
- _Reproducible._ Include steps to reproduce the problem.
|
||||
- _Specific._ Include as much detail as possible: which version, what environment, etc.
|
||||
- _Unique._ Do not duplicate existing opened issues.
|
||||
- _Scoped to a Single Bug._ One bug per report.
|
||||
|
||||
**Even better: Submit a pull request with a fix or new feature!**
|
||||
|
||||
### How to submit a Pull Request
|
||||
|
||||
1. Search our repository for open or closed
|
||||
[Pull Requests](https://github.com/NanoVNA-Saver/nanovna-saver/pulls)
|
||||
that relate to your submission. You don't want to duplicate effort.
|
||||
2. Fork the project
|
||||
3. Create your feature branch (`git checkout -b feat/amazing_feature`)
|
||||
4. Commit your changes (`git commit -m 'feat: add amazing_feature'`)
|
||||
NanoVNA-Saver uses [conventional commits](https://www.conventionalcommits.org),
|
||||
so please follow the specification in your commit messages. 5. Push to the
|
||||
branch (`git push origin feat/amazing_feature`)
|
||||
6. [Open a Pull Request](https://github.com/NanoVNA-Saver/nanovna-saver/compare?expand=1)
|
|
@ -1,129 +0,0 @@
|
|||
# Installation Instructions
|
||||
|
||||
## Installation and Use with pip
|
||||
|
||||
Copy the link of the tgz from latest relaese and install it with pip install. e.g.:
|
||||
|
||||
pip3 install https://github.com/NanoVNA-Saver/nanovna-saver/archive/refs/tags/v0.5.5.tar.gz
|
||||
|
||||
Once completed run with the following command: `NanoVNASaver`
|
||||
|
||||
The instructions omit the easiest way to get the program running under Linux - no installation - just start it in the git directory. This makes it difficult for pure users, e.g. hams, who therefore even try to run the Windows exe version under Wine.
|
||||
|
||||
Proposal - Add these sections below to the top README.md, e.g. between "Detailed installation instructions" and "Using the software" (Please review and add e.g. more necessary debian packages):
|
||||
|
||||
## Running on Linux without installation
|
||||
|
||||
The program simply works from the source directory without having to install it.
|
||||
|
||||
Simple step-by-step instruction, open a terminal window and type:
|
||||
|
||||
sudo apt install git python3-pyqt5 python3-numpy python3-scipy
|
||||
git clone https://github.com/NanoVNA-Saver/nanovna-saver
|
||||
cd nanovna-saver
|
||||
|
||||
Perhaps your system needs a few additional python modules:
|
||||
|
||||
- Run with `python nanovna-saver.py` and look at the response of (e.g. missing modules).
|
||||
- Install the missing modules, preferably via `sudo apt install ...`
|
||||
|
||||
until `nanovna-saver.py` starts up.
|
||||
|
||||
Now the program can be used from the `nanovna-saver` directory.
|
||||
|
||||
## Installing via DEB for Debian (and Ubuntu)
|
||||
|
||||
The installation has the benefit that it allows you to run the program from anywhere, because the
|
||||
main program is found via the regular `$PATH` and the modules are located in the Python module path.
|
||||
|
||||
If you're using a debian based distro you should consider to build your own `*.deb` package.
|
||||
This has the advantage that NanoVNASaver can be installed and uninstalled cleanly in the system.
|
||||
|
||||
For this you need to install `python3-stdeb` - the module for converting Python code and modules into a Debian package:
|
||||
|
||||
apt install python3-stdeb
|
||||
|
||||
Then you can build the package via:
|
||||
|
||||
make deb
|
||||
|
||||
This package can be installed the usual way with
|
||||
|
||||
sudo dpkg -i nanovnasaver....deb
|
||||
or
|
||||
|
||||
sudo apt install ./nanovnasaver....deb
|
||||
|
||||
### Installing via RPM (experimental)
|
||||
|
||||
`make rpm` builds an (untested) rpm package that can be installed on your system the usual way.
|
||||
|
||||
## Ubuntu 20.04 / 22.04
|
||||
|
||||
1. Install python3 and pip
|
||||
|
||||
sudo apt install python3 python3-pip
|
||||
python3 -m venv ~/.venv_nano
|
||||
. ~/.venv_nano/bin/activate
|
||||
pip install -U pip
|
||||
|
||||
2. Clone repo and cd into the directory
|
||||
|
||||
git clone https://github.com/NanoVNA-Saver/nanovna-saver
|
||||
cd nanovna-saver
|
||||
|
||||
3. Update pip and run the pip installation
|
||||
|
||||
python3 -m pip install .
|
||||
|
||||
(You may need to install the additional packages python3-distutils,
|
||||
python3-setuptools and python3-wheel for this command to work on some
|
||||
distributions.)
|
||||
|
||||
4. Once completed run with the following command
|
||||
|
||||
. ~/.venv_nano/bin/activate
|
||||
python3 nanovna-saver.py
|
||||
|
||||
## MacPorts
|
||||
|
||||
Via a MacPorts distribution maintained by @ra1nb0w.
|
||||
|
||||
1. Install MacPorts following the [install guide](https://www.macports.org/install.php)
|
||||
|
||||
2. Install NanoVNASaver :
|
||||
|
||||
sudo port install NanoVNASaver
|
||||
|
||||
3. Now you can run the software from shell `NanoVNASaver` or run as app
|
||||
`/Applications/MacPorts/NanoVNASaver.app`
|
||||
|
||||
## Homebrew
|
||||
|
||||
1. Install Homebrew from <https://brew.sh/> (This will ask for your password)
|
||||
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
|
||||
|
||||
2. Python :
|
||||
|
||||
brew install python
|
||||
|
||||
3. Pip :<br/>
|
||||
Download the get-pip.py file and run it to install pip
|
||||
|
||||
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
|
||||
python3 get-pip.py
|
||||
|
||||
4. NanoVNASaver Installation : <br/>
|
||||
clone the source code to the nanovna-saver folder
|
||||
|
||||
git clone https://github.com/NanoVNA-Saver/nanovna-saver
|
||||
cd nanovna-saver
|
||||
|
||||
5. Install local pip packages
|
||||
|
||||
python3 -m pip install .
|
||||
|
||||
6. Run nanovna-saver in the nanovna-saver folder by:
|
||||
|
||||
python3 nanovna-saver.py
|
|
@ -1,29 +0,0 @@
|
|||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line, and also
|
||||
# from the environment for the first two.
|
||||
SPHINXOPTS ?=
|
||||
SPHINXBUILD ?= sphinx-build
|
||||
SOURCEDIR = .
|
||||
BUILDDIR = _build
|
||||
AUTODOCDIR = api
|
||||
|
||||
# User-friendly check for sphinx-build
|
||||
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $?), 1)
|
||||
$(error "The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from https://sphinx-doc.org/")
|
||||
endif
|
||||
|
||||
.PHONY: help clean Makefile
|
||||
|
||||
# Put it first so that "make" without argument is like "make help".
|
||||
help:
|
||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)/* $(AUTODOCDIR)
|
||||
|
||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@ -1 +0,0 @@
|
|||
# Empty directory
|
|
@ -1,2 +0,0 @@
|
|||
.. _authors:
|
||||
.. include:: ../AUTHORS.rst
|
286
docs/conf.py
286
docs/conf.py
|
@ -1,286 +0,0 @@
|
|||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# This file only contains a selection of the most common options. For a full
|
||||
# list see the documentation:
|
||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
# -- Path setup --------------------------------------------------------------
|
||||
|
||||
__location__ = os.path.dirname(__file__)
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
sys.path.insert(0, os.path.join(__location__, "../src"))
|
||||
|
||||
# -- Run sphinx-apidoc -------------------------------------------------------
|
||||
# This hack is necessary since RTD does not issue `sphinx-apidoc` before running
|
||||
# `sphinx-build -b html . _build/html`. See Issue:
|
||||
# https://github.com/readthedocs/readthedocs.org/issues/1139
|
||||
# DON'T FORGET: Check the box "Install your project inside a virtualenv using
|
||||
# setup.py install" in the RTD Advanced Settings.
|
||||
# Additionally it helps us to avoid running apidoc manually
|
||||
|
||||
try: # for Sphinx >= 1.7
|
||||
from sphinx.ext import apidoc
|
||||
except ImportError:
|
||||
from sphinx import apidoc
|
||||
|
||||
output_dir = os.path.join(__location__, "api")
|
||||
module_dir = os.path.join(__location__, "../src/NanoVNASaver")
|
||||
try:
|
||||
shutil.rmtree(output_dir)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
try:
|
||||
import sphinx
|
||||
|
||||
cmd_line = f"sphinx-apidoc --implicit-namespaces -f -o {output_dir} {module_dir}"
|
||||
|
||||
args = cmd_line.split(" ")
|
||||
if tuple(sphinx.__version__.split(".")) >= ("1", "7"):
|
||||
# This is a rudimentary parse_version to avoid external dependencies
|
||||
args = args[1:]
|
||||
|
||||
apidoc.main(args)
|
||||
except Exception as e:
|
||||
print("Running `sphinx-apidoc` failed!\n{}".format(e))
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = [
|
||||
"sphinx.ext.autodoc",
|
||||
"sphinx.ext.intersphinx",
|
||||
"sphinx.ext.todo",
|
||||
"sphinx.ext.autosummary",
|
||||
"sphinx.ext.viewcode",
|
||||
"sphinx.ext.coverage",
|
||||
"sphinx.ext.doctest",
|
||||
"sphinx.ext.ifconfig",
|
||||
"sphinx.ext.mathjax",
|
||||
"sphinx.ext.napoleon",
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ["_templates"]
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = ".rst"
|
||||
|
||||
# The encoding of source files.
|
||||
# source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = "index"
|
||||
|
||||
# General information about the project.
|
||||
project = "nanovna-saver"
|
||||
copyright = "2023, Holger Mueller"
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# version: The short X.Y version.
|
||||
# release: The full version, including alpha/beta/rc tags.
|
||||
# If you don’t need the separation provided between version and release,
|
||||
# just set them both to the same value.
|
||||
try:
|
||||
from NanoVNASaver import __version__ as version
|
||||
except ImportError:
|
||||
version = ""
|
||||
|
||||
if not version or version.lower() == "unknown":
|
||||
version = os.getenv("READTHEDOCS_VERSION", "unknown") # automatically set by RTD
|
||||
|
||||
release = version
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
# language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
# today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
# today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".venv"]
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
# default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
# add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
# add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
# show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = "sphinx"
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
# modindex_common_prefix = []
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
# keep_warnings = False
|
||||
|
||||
# If this is True, todo emits a warning for each TODO entries. The default is False.
|
||||
todo_emit_warnings = True
|
||||
|
||||
|
||||
# -- Options for HTML output -------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = "alabaster"
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
html_theme_options = {
|
||||
"sidebar_width": "300px",
|
||||
"page_width": "1200px"
|
||||
}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
# html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
# html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
# html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
# html_logo = ""
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
# html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ["_static"]
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
# html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
# html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
# html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
# html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
# html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
# html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
# html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
# html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
# html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
# html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
# html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
# html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = "nanovna-saver-doc"
|
||||
|
||||
|
||||
# -- Options for LaTeX output ------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ("letterpaper" or "a4paper").
|
||||
# "papersize": "letterpaper",
|
||||
# The font size ("10pt", "11pt" or "12pt").
|
||||
# "pointsize": "10pt",
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
# "preamble": "",
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
("index", "user_guide.tex", "nanovna-saver Documentation", "Holger Mueller", "manual")
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
# latex_logo = ""
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
# latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
# latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# latex_domain_indices = True
|
||||
|
||||
# -- External mapping --------------------------------------------------------
|
||||
python_version = ".".join(map(str, sys.version_info[0:2]))
|
||||
intersphinx_mapping = {
|
||||
"sphinx": ("https://www.sphinx-doc.org/en/master", None),
|
||||
"python": ("https://docs.python.org/" + python_version, None),
|
||||
"matplotlib": ("https://matplotlib.org", None),
|
||||
"numpy": ("https://numpy.org/doc/stable", None),
|
||||
"sklearn": ("https://scikit-learn.org/stable", None),
|
||||
"pandas": ("https://pandas.pydata.org/pandas-docs/stable", None),
|
||||
"scipy": ("https://docs.scipy.org/doc/scipy/reference", None),
|
||||
"setuptools": ("https://setuptools.pypa.io/en/stable/", None),
|
||||
"pyscaffold": ("https://pyscaffold.org/en/stable", None),
|
||||
}
|
||||
|
||||
print(f"loading configurations for {project} {version} ...", file=sys.stderr)
|
|
@ -1 +0,0 @@
|
|||
.. include:: ../CONTRIBUTING.rst
|
|
@ -1,60 +0,0 @@
|
|||
=============
|
||||
nanovna-saver
|
||||
=============
|
||||
|
||||
This is the documentation of **nanovna-saver**.
|
||||
|
||||
.. note::
|
||||
|
||||
This is the main page of your project's `Sphinx`_ documentation.
|
||||
It is formatted in `reStructuredText`_. Add additional pages
|
||||
by creating rst-files in ``docs`` and adding them to the `toctree`_ below.
|
||||
Use then `references`_ in order to link them from this page, e.g.
|
||||
:ref:`authors` and :ref:`changes`.
|
||||
|
||||
It is also possible to refer to the documentation of other Python packages
|
||||
with the `Python domain syntax`_. By default you can reference the
|
||||
documentation of `Sphinx`_, `Python`_, `NumPy`_, `SciPy`_, `matplotlib`_,
|
||||
`Pandas`_, `Scikit-Learn`_. You can add more by extending the
|
||||
``intersphinx_mapping`` in your Sphinx's ``conf.py``.
|
||||
|
||||
The pretty useful extension `autodoc`_ is activated by default and lets
|
||||
you include documentation from docstrings. Docstrings can be written in
|
||||
`Google style`_ (recommended!), `NumPy style`_ and `classical style`_.
|
||||
|
||||
|
||||
Contents
|
||||
========
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
Overview <readme>
|
||||
Contributions & Help <contributing>
|
||||
License <license>
|
||||
Authors <authors>
|
||||
Module Reference <api/modules>
|
||||
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
.. _toctree: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html
|
||||
.. _reStructuredText: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
|
||||
.. _references: https://www.sphinx-doc.org/en/stable/markup/inline.html
|
||||
.. _Python domain syntax: https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#the-python-domain
|
||||
.. _Sphinx: https://www.sphinx-doc.org/
|
||||
.. _Python: https://docs.python.org/
|
||||
.. _Numpy: https://numpy.org/doc/stable
|
||||
.. _SciPy: https://docs.scipy.org/doc/scipy/reference/
|
||||
.. _matplotlib: https://matplotlib.org/contents.html#
|
||||
.. _Pandas: https://pandas.pydata.org/pandas-docs/stable
|
||||
.. _Scikit-Learn: https://scikit-learn.org/stable
|
||||
.. _autodoc: https://www.sphinx-doc.org/en/master/ext/autodoc.html
|
||||
.. _Google style: https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings
|
||||
.. _NumPy style: https://numpydoc.readthedocs.io/en/latest/format.html
|
||||
.. _classical style: https://www.sphinx-doc.org/en/master/domains.html#info-field-lists
|
|
@ -1,7 +0,0 @@
|
|||
.. _license:
|
||||
|
||||
=======
|
||||
License
|
||||
=======
|
||||
|
||||
.. include:: ../LICENSE.txt
|
|
@ -1,66 +0,0 @@
|
|||
.\" English manual page for nanovna-saver
|
||||
.\"
|
||||
.\" Copyright (C) 2023-2023 Nicolas Boulenguez <nicolas@debian.org>
|
||||
.\"
|
||||
.\" This program 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 of the
|
||||
.\" License, or (at your option) any later version.
|
||||
.\" This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
.\"
|
||||
.TH NANOVNASAVER 1 "2023-03-19"
|
||||
.\"----------------------------------------------------------------------
|
||||
.SH NAME
|
||||
NANOVNASAVER \- save Touchstone files from the NanoVNA device
|
||||
.\"----------------------------------------------------------------------
|
||||
.SH SYNOPSIS
|
||||
.B NanoVNASaver
|
||||
.RB [\| \-h \|]
|
||||
.RB [\| \-d \|]
|
||||
.RB [\| \-D
|
||||
.IR DEBUG_FILE \|]
|
||||
.RB [\| \-f
|
||||
.IR FILE \|]
|
||||
.RB [\| \-r
|
||||
.IR REF_FILE \|]
|
||||
.RB [\| \-\-version \|]
|
||||
.\"----------------------------------------------------------------------
|
||||
.SH DESCRCIPTION
|
||||
The NanoVNASaver graphical tool saves Touchstone files from the
|
||||
NanoVNA, sweeps frequency spans in segments to gain more data points,
|
||||
and generally displays and analyzes the resulting data.
|
||||
.PP
|
||||
The authors expect most users to use a graphical launcher instead of
|
||||
the command line interface.
|
||||
.\"----------------------------------------------------------------------
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-h\fR, \fB\-\-help\fR
|
||||
Show a summary of options and exit.
|
||||
.TP
|
||||
\fB\-d\fR, \fB\-\-debug\fR
|
||||
Set loglevel to debug.
|
||||
.TP
|
||||
\fB\-D \fIDEBUG_FILE\fR, \fB\-\-debug\-file \fIDEBUG_FILE\fR
|
||||
File to write debug logging output to.
|
||||
.TP
|
||||
\fB\-f \fIFILE\fR, \fB\-\-file \fIFILE\fR
|
||||
Touchstone file to load as sweep for off device usage.
|
||||
.TP
|
||||
\fB\-r \fIREF_FILE\fR, \fB\-\-ref\-file \fIREF_FILE\fR
|
||||
Touchstone file to load as reference for off device usage.
|
||||
.TP
|
||||
\fB\-\-version\fR
|
||||
Show program's version number and exit.
|
||||
.\"----------------------------------------------------------------------
|
||||
.SH SEE ALSO
|
||||
The documentation is installed at
|
||||
.BR /usr/share/doc/nanovna-saver/ .
|
||||
.\"----------------------------------------------------------------------
|
||||
.SH HISTORY
|
||||
This page has been written for Debian but may be reused by others.
|
|
@ -1,2 +0,0 @@
|
|||
.. _readme:
|
||||
.. include:: ../README.rst
|
|
@ -1,5 +0,0 @@
|
|||
# Requirements file for ReadTheDocs, check .readthedocs.yml.
|
||||
# To build the module reference correctly, make sure every external package
|
||||
# under `install_requires` in `setup.cfg` is also listed here!
|
||||
sphinx>=3.2.1
|
||||
# sphinx_rtd_theme
|
|
@ -1,24 +0,0 @@
|
|||
app-id: io.github.zarath.nanovna-saver
|
||||
runtime: org.kde.Platform
|
||||
runtime-version: '6.5'
|
||||
sdk: org.kde.Sdk
|
||||
command: /app/bin/NanoVNASaver
|
||||
build-options:
|
||||
build-args:
|
||||
- --share=network
|
||||
modules:
|
||||
- name: nanonva-saver
|
||||
buildsystem: simple
|
||||
build-commands:
|
||||
- pip3 install --prefix=/app wheel setuptools setuptools-scm
|
||||
- pip3 install --prefix=/app git+https://github.com/NanoVNA-Saver/nanovna-saver.git
|
||||
finish-args:
|
||||
# X11 + XShm access
|
||||
- --share=ipc
|
||||
- --socket=x11
|
||||
# Wayland access
|
||||
- --socket=wayland
|
||||
# Needs access to NanoVNAs
|
||||
- --device=all
|
||||
# Needs to save files locally
|
||||
- --filesystem=xdg-documents
|
BIN
icon_48x48.icns
BIN
icon_48x48.icns
Plik binarny nie jest wyświetlany.
BIN
icon_48x48.ico
BIN
icon_48x48.ico
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 109 KiB |
BIN
icon_48x48.png
BIN
icon_48x48.png
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 17 KiB |
104
setup.cfg
104
setup.cfg
|
@ -1,104 +0,0 @@
|
|||
# This file is used to configure your project.
|
||||
# Read more about the various options under:
|
||||
# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html
|
||||
# https://setuptools.pypa.io/en/latest/references/keywords.html
|
||||
|
||||
[metadata]
|
||||
name = NanoVNASaver
|
||||
author = Rune B. Broberg
|
||||
author_email= NanoVNA-Saver@users.noreply.github.com
|
||||
license = GNU GPL V3
|
||||
license_files = LICENSE,
|
||||
description = GUI for the NanoVNA and derivates
|
||||
long_description = file: README.rst
|
||||
url = https://github.com/NanoVNA-Saver/nanovna-saver
|
||||
version = attr: NanoVNASaver.About.version
|
||||
platforms= all
|
||||
|
||||
[options]
|
||||
zip_safe = False
|
||||
packages = find_namespace:
|
||||
include_package_data = True
|
||||
package_dir =
|
||||
=src
|
||||
|
||||
# Require a min/specific Python version (comma-separated conditions)
|
||||
python_requires = >=3.8, <4
|
||||
|
||||
# Add here dependencies of your project (line-separated), e.g. requests>=2.2,<3.0.
|
||||
# Version specifiers like >=2.2,<3.0 avoid problems due to API changes in
|
||||
# new major versions. This works if the required packages follow Semantic Versioning.
|
||||
# For more information, check out https://semver.org/.
|
||||
install_requires =
|
||||
pyserial>=3.5
|
||||
PyQt6>=5.15.0
|
||||
numpy>=1.21.1
|
||||
scipy>=1.7.1
|
||||
Cython>=0.29.24
|
||||
setuptools-scm
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
||||
exclude =
|
||||
tests
|
||||
|
||||
[options.extras_require]
|
||||
# Add here additional requirements for extra features, to install with:
|
||||
# `pip install nanovna-saver[PDF]` like:
|
||||
# PDF = ReportLab; RXP
|
||||
|
||||
# Add here test requirements (semicolon/line-separated)
|
||||
testing =
|
||||
setuptools
|
||||
pytest
|
||||
pytest-cov
|
||||
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
NanoVNASaver = NanoVNASaver.__main__:main
|
||||
|
||||
[tool:pytest]
|
||||
# Specify command line options as you would do when invoking pytest directly.
|
||||
# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml
|
||||
# in order to write a coverage file that can be read by Jenkins.
|
||||
# CAUTION: --cov flags may prohibit setting breakpoints while debugging.
|
||||
# Comment those flags to avoid this pytest issue.
|
||||
addopts =
|
||||
--cov NanoVNASaver --cov-report term-missing
|
||||
--verbose
|
||||
norecursedirs =
|
||||
dist
|
||||
build
|
||||
.tox
|
||||
testpaths = tests
|
||||
# Use pytest markers to select/deselect specific tests
|
||||
# markers =
|
||||
# slow: mark tests as slow (deselect with '-m "not slow"')
|
||||
# system: mark end-to-end system tests
|
||||
|
||||
[devpi:upload]
|
||||
# Options for the devpi: PyPI server and packaging tool
|
||||
# VCS export must be deactivated since we are using setuptools-scm
|
||||
no_vcs = 1
|
||||
formats = bdist_wheel
|
||||
|
||||
[flake8]
|
||||
# Some sane defaults for the code style checker flake8
|
||||
max_line_length = 88
|
||||
extend_ignore = E203, W503
|
||||
# ^ Black-compatible
|
||||
# E203 and W503 have edge cases handled by black
|
||||
exclude =
|
||||
.tox
|
||||
build
|
||||
dist
|
||||
.eggs
|
||||
docs/conf.py
|
||||
|
||||
[pyscaffold]
|
||||
# PyScaffold's parameters when the project was created.
|
||||
# This will be used when updating. Do not change!
|
||||
version = 4.4
|
||||
package = NanoVNASaver
|
||||
extensions =
|
||||
no_skeleton
|
21
setup.py
21
setup.py
|
@ -1,21 +0,0 @@
|
|||
"""
|
||||
Setup file for nanovna-saver.
|
||||
Use setup.cfg to configure your project.
|
||||
|
||||
This file was generated with PyScaffold 4.4.
|
||||
PyScaffold helps you to put up the scaffold of your new Python project.
|
||||
Learn more under: https://pyscaffold.org/
|
||||
"""
|
||||
from setuptools import setup
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
setup(use_scm_version={"version_scheme": "no-guess-dev"})
|
||||
except: # noqa
|
||||
print(
|
||||
"\n\nAn error occurred while building the project, "
|
||||
"please ensure you have the most updated version of setuptools, "
|
||||
"setuptools_scm and wheel with:\n"
|
||||
" pip install -U setuptools setuptools_scm wheel\n\n"
|
||||
)
|
||||
raise
|
|
@ -18,8 +18,8 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from NanoVNASaver.Hardware.VNA import VNA
|
||||
from Hardware.Serial import Interface
|
||||
from Hardware.VNA import VNA
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -25,19 +25,19 @@ import serial
|
|||
from serial.tools import list_ports
|
||||
from serial.tools.list_ports_common import ListPortInfo
|
||||
|
||||
from NanoVNASaver.Hardware.VNA import VNA
|
||||
from NanoVNASaver.Hardware.AVNA import AVNA
|
||||
from NanoVNASaver.Hardware.NanoVNA import NanoVNA
|
||||
from NanoVNASaver.Hardware.NanoVNA_F import NanoVNA_F
|
||||
from NanoVNASaver.Hardware.NanoVNA_F_V2 import NanoVNA_F_V2
|
||||
from NanoVNASaver.Hardware.NanoVNA_H import NanoVNA_H
|
||||
from NanoVNASaver.Hardware.NanoVNA_H4 import NanoVNA_H4
|
||||
from NanoVNASaver.Hardware.NanoVNA_V2 import NanoVNA_V2
|
||||
from NanoVNASaver.Hardware.TinySA import TinySA, TinySA_Ultra
|
||||
from NanoVNASaver.Hardware.JNCRadio_VNA_3G import JNCRadio_VNA_3G
|
||||
from NanoVNASaver.Hardware.SV4401A import SV4401A
|
||||
from NanoVNASaver.Hardware.SV6301A import SV6301A
|
||||
from NanoVNASaver.Hardware.Serial import drain_serial, Interface
|
||||
from Hardware.VNA import VNA
|
||||
from Hardware.AVNA import AVNA
|
||||
from Hardware.NanoVNA import NanoVNA
|
||||
from Hardware.NanoVNA_F import NanoVNA_F
|
||||
from Hardware.NanoVNA_F_V2 import NanoVNA_F_V2
|
||||
from Hardware.NanoVNA_H import NanoVNA_H
|
||||
from Hardware.NanoVNA_H4 import NanoVNA_H4
|
||||
from Hardware.NanoVNA_V2 import NanoVNA_V2
|
||||
from Hardware.TinySA import TinySA, TinySA_Ultra
|
||||
from Hardware.JNCRadio_VNA_3G import JNCRadio_VNA_3G
|
||||
from Hardware.SV4401A import SV4401A
|
||||
from Hardware.SV6301A import SV6301A
|
||||
from Hardware.Serial import drain_serial, Interface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -21,8 +21,8 @@ import logging
|
|||
import serial
|
||||
from PyQt6.QtGui import QImage, QPixmap
|
||||
|
||||
from NanoVNASaver.Hardware.NanoVNA import NanoVNA
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from Hardware.NanoVNA import NanoVNA
|
||||
from Hardware.Serial import Interface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -23,9 +23,9 @@ import serial
|
|||
import numpy as np
|
||||
from PyQt6.QtGui import QImage, QPixmap
|
||||
|
||||
from NanoVNASaver.Hardware.Serial import drain_serial, Interface
|
||||
from NanoVNASaver.Hardware.VNA import VNA
|
||||
from NanoVNASaver.Version import Version
|
||||
from Hardware.Serial import drain_serial, Interface
|
||||
from Hardware.VNA import VNA
|
||||
from Version import Version
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.Hardware.NanoVNA import NanoVNA
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from Hardware.NanoVNA import NanoVNA
|
||||
from Hardware.Serial import Interface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -21,8 +21,8 @@ import logging
|
|||
import serial
|
||||
from PyQt6.QtGui import QImage, QPixmap
|
||||
|
||||
from NanoVNASaver.Hardware.NanoVNA import NanoVNA
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from Hardware.NanoVNA import NanoVNA
|
||||
from Hardware.Serial import Interface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.Hardware.NanoVNA import NanoVNA
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from Hardware.NanoVNA import NanoVNA
|
||||
from Hardware.Serial import Interface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -17,8 +17,8 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from NanoVNASaver.Hardware.NanoVNA_H import NanoVNA_H
|
||||
from Hardware.Serial import Interface
|
||||
from Hardware.NanoVNA_H import NanoVNA_H
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -21,9 +21,9 @@ import platform
|
|||
from struct import pack, unpack_from
|
||||
from time import sleep
|
||||
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from NanoVNASaver.Hardware.VNA import VNA
|
||||
from NanoVNASaver.Version import Version
|
||||
from Hardware.Serial import Interface
|
||||
from Hardware.VNA import VNA
|
||||
from Version import Version
|
||||
|
||||
if platform.system() != "Windows":
|
||||
import tty
|
|
@ -21,8 +21,8 @@ import logging
|
|||
import serial
|
||||
from PyQt6.QtGui import QImage, QPixmap
|
||||
|
||||
from NanoVNASaver.Hardware.NanoVNA import NanoVNA
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from Hardware.NanoVNA import NanoVNA
|
||||
from Hardware.Serial import Interface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -21,8 +21,8 @@ import logging
|
|||
import serial
|
||||
from PyQt6.QtGui import QImage, QPixmap
|
||||
|
||||
from NanoVNASaver.Hardware.NanoVNA import NanoVNA
|
||||
from NanoVNASaver.Hardware.Serial import Interface
|
||||
from Hardware.NanoVNA import NanoVNA
|
||||
from Hardware.Serial import Interface
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -23,8 +23,8 @@ import serial
|
|||
import numpy as np
|
||||
from PyQt6.QtGui import QImage, QPixmap
|
||||
|
||||
from NanoVNASaver.Hardware.Serial import drain_serial, Interface
|
||||
from NanoVNASaver.Hardware.VNA import VNA
|
||||
from Hardware.Serial import drain_serial, Interface
|
||||
from Hardware.VNA import VNA
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -20,10 +20,8 @@ import logging
|
|||
from time import sleep
|
||||
from typing import Iterator
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.Version import Version
|
||||
from NanoVNASaver.Hardware.Serial import Interface, drain_serial
|
||||
from Version import Version
|
||||
from Hardware.Serial import Interface, drain_serial
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -182,9 +180,6 @@ class VNA:
|
|||
def getCalibration(self) -> str:
|
||||
return " ".join(list(self.exec_command("cal")))
|
||||
|
||||
def getScreenshot(self) -> QtGui.QPixmap:
|
||||
return QtGui.QPixmap()
|
||||
|
||||
def flushSerialBuffers(self):
|
||||
if not self.connected():
|
||||
return
|
|
@ -1,41 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from setuptools_scm import get_version
|
||||
try:
|
||||
version = get_version(root='..', relative_to=__file__)
|
||||
except LookupError:
|
||||
from NanoVNASaver._version import version
|
||||
|
||||
INFO_URL = "https://github.com/NanoVNA-Saver/nanovna-saver"
|
||||
INFO = f"""NanoVNASaver {version}
|
||||
|
||||
Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
|
||||
This program comes with ABSOLUTELY NO WARRANTY
|
||||
This program is licensed under the GNU General Public License version 3
|
||||
|
||||
See {INFO_URL} for further details.
|
||||
"""
|
||||
|
||||
TAGS_URL = "https://github.com/NanoVNA-Saver/nanovna-saver/tags"
|
||||
TAGS_KEY = "/NanoVNA-Saver/nanovna-saver/releases/tag/v"
|
||||
|
||||
LATEST_URL = "https://github.com/NanoVNA-Saver/nanovna-saver/releases/latest"
|
|
@ -1,131 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import logging
|
||||
from time import sleep
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
from NanoVNASaver.Analysis.VSWRAnalysis import VSWRAnalysis
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MagLoopAnalysis(VSWRAnalysis):
|
||||
"""
|
||||
Find min vswr and change sweep to zoom.
|
||||
Useful for tuning magloop.
|
||||
|
||||
"""
|
||||
|
||||
max_dips_shown = 1
|
||||
|
||||
vswr_bandwith_value = 2.56 # -3 dB ?!?
|
||||
bandwith = 25000 # 25 kHz
|
||||
|
||||
def __init__(self, app):
|
||||
# app.sweep_control.get_start() return -1 ?!?
|
||||
# will populate first runAnalysis()
|
||||
self.min_freq = None # app.sweep_control.get_start()
|
||||
self.max_freq = None # app.sweep_control.get_end()
|
||||
self.vswr_limit_value = self.vswr_bandwith_value
|
||||
|
||||
super().__init__(app)
|
||||
|
||||
def runAnalysis(self):
|
||||
super().runAnalysis()
|
||||
new_start = self.app.sweep_control.get_start()
|
||||
new_end = self.app.sweep_control.get_end()
|
||||
if self.min_freq is None:
|
||||
self.min_freq = new_start
|
||||
self.max_freq = new_end
|
||||
logger.debug(
|
||||
"setting hard limits to %s - %s", self.min_freq, self.max_freq
|
||||
)
|
||||
|
||||
if len(self.minimums) > 1:
|
||||
self.layout.addRow(
|
||||
"",
|
||||
QtWidgets.QLabel(
|
||||
"Multiple minimums, not magloop or try to lower VSWR limit"
|
||||
),
|
||||
)
|
||||
return
|
||||
|
||||
if len(self.minimums) == 1:
|
||||
m = self.minimums[0]
|
||||
start, lowest, end = m
|
||||
if start == end:
|
||||
new_start = self.app.data.s11[start].freq - 2 * self.bandwith
|
||||
new_end = self.app.data.s11[end].freq + 2 * self.bandwith
|
||||
logger.debug(" Zoom to %s-%s", new_start, new_end)
|
||||
|
||||
elif self.vswr_limit_value == self.vswr_bandwith_value:
|
||||
Q = self.app.data.s11[lowest].freq / (
|
||||
self.app.data.s11[end].freq - self.app.data.s11[start].freq
|
||||
)
|
||||
self.layout.addRow("Q", QtWidgets.QLabel(f"{int(Q)}"))
|
||||
new_start = self.app.data.s11[start].freq - self.bandwith
|
||||
new_end = self.app.data.s11[end].freq + self.bandwith
|
||||
logger.debug(
|
||||
"Single Spot, new scan on %s-%s", new_start, new_end
|
||||
)
|
||||
|
||||
if self.vswr_limit_value > self.vswr_bandwith_value:
|
||||
self.vswr_limit_value = max(
|
||||
self.vswr_bandwith_value, self.vswr_limit_value - 1
|
||||
)
|
||||
self.input_vswr_limit.setValue(self.vswr_limit_value)
|
||||
logger.debug(
|
||||
"found higher minimum, lowering vswr search to %s",
|
||||
self.vswr_limit_value,
|
||||
)
|
||||
else:
|
||||
new_start = new_start - 5 * self.bandwith
|
||||
new_end = new_end + 5 * self.bandwith
|
||||
if (
|
||||
all((new_start <= self.min_freq, new_end >= self.max_freq))
|
||||
and self.vswr_limit_value < 10
|
||||
):
|
||||
self.vswr_limit_value += 2
|
||||
self.input_vswr_limit.setValue(self.vswr_limit_value)
|
||||
logger.debug(
|
||||
"no minimum found, looking for higher value %s",
|
||||
self.vswr_limit_value,
|
||||
)
|
||||
|
||||
new_start = max(self.min_freq, new_start)
|
||||
new_end = min(self.max_freq, new_end)
|
||||
logger.debug(
|
||||
"next search will be %s - %s for vswr %s",
|
||||
new_start,
|
||||
new_end,
|
||||
self.vswr_limit_value,
|
||||
)
|
||||
|
||||
self.app.sweep_control.set_start(new_start)
|
||||
self.app.sweep_control.set_end(new_end)
|
||||
|
||||
# TODO: get info if sweep is running instead of just sleeping
|
||||
# a guessed time
|
||||
sleep(2.0)
|
||||
if self.app.sweep_control.btn_start.isEnabled():
|
||||
self.app.sweep_start()
|
|
@ -1,219 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
import math
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
import NanoVNASaver.AnalyticTools as at
|
||||
from NanoVNASaver.Analysis.Base import Analysis, CUTOFF_VALS
|
||||
from NanoVNASaver.Formatting import format_frequency
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BandPassAnalysis(Analysis):
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
|
||||
for label in (
|
||||
"octave_l",
|
||||
"octave_r",
|
||||
"decade_l",
|
||||
"decade_r",
|
||||
"freq_center",
|
||||
"span_3.0dB",
|
||||
"span_6.0dB",
|
||||
"q_factor",
|
||||
):
|
||||
self.label[label] = QtWidgets.QLabel()
|
||||
for attn in CUTOFF_VALS:
|
||||
self.label[f"{attn:.1f}dB_l"] = QtWidgets.QLabel()
|
||||
self.label[f"{attn:.1f}dB_r"] = QtWidgets.QLabel()
|
||||
|
||||
layout = self.layout
|
||||
layout.addRow(self.label["titel"])
|
||||
layout.addRow(
|
||||
QtWidgets.QLabel(
|
||||
f"Please place {self.app.markers[0].name}"
|
||||
f" in the filter passband."
|
||||
)
|
||||
)
|
||||
layout.addRow("Result:", self.label["result"])
|
||||
layout.addRow(QtWidgets.QLabel(""))
|
||||
|
||||
layout.addRow("Center frequency:", self.label["freq_center"])
|
||||
layout.addRow("Bandwidth (-3 dB):", self.label["span_3.0dB"])
|
||||
layout.addRow("Quality factor:", self.label["q_factor"])
|
||||
layout.addRow("Bandwidth (-6 dB):", self.label["span_6.0dB"])
|
||||
layout.addRow(QtWidgets.QLabel(""))
|
||||
|
||||
layout.addRow(QtWidgets.QLabel("Lower side:"))
|
||||
layout.addRow("Cutoff frequency:", self.label["3.0dB_l"])
|
||||
layout.addRow("-6 dB point:", self.label["6.0dB_l"])
|
||||
layout.addRow("-60 dB point:", self.label["60.0dB_l"])
|
||||
layout.addRow("Roll-off:", self.label["octave_l"])
|
||||
layout.addRow("Roll-off:", self.label["decade_l"])
|
||||
layout.addRow(QtWidgets.QLabel(""))
|
||||
|
||||
layout.addRow(QtWidgets.QLabel("Upper side:"))
|
||||
layout.addRow("Cutoff frequency:", self.label["3.0dB_r"])
|
||||
layout.addRow("-6 dB point:", self.label["6.0dB_r"])
|
||||
layout.addRow("-60 dB point:", self.label["60.0dB_r"])
|
||||
layout.addRow("Roll-off:", self.label["octave_r"])
|
||||
layout.addRow("Roll-off:", self.label["decade_r"])
|
||||
|
||||
self.set_titel("Band pass filter analysis")
|
||||
|
||||
def runAnalysis(self):
|
||||
if not self.app.data.s21:
|
||||
logger.debug("No data to analyse")
|
||||
self.set_result("No data to analyse.")
|
||||
return
|
||||
|
||||
self.reset()
|
||||
s21 = self.app.data.s21
|
||||
gains = [d.gain for d in s21]
|
||||
|
||||
if (peak := self.find_center(gains)) < 0:
|
||||
return
|
||||
peak_db = gains[peak]
|
||||
logger.debug("Filter center pos: %d(%fdB)", peak, peak_db)
|
||||
|
||||
# find passband bounderies
|
||||
cutoff_pos = self.find_bounderies(gains, peak, peak_db)
|
||||
cutoff_freq = {
|
||||
att: s21[val].freq if val >= 0 else math.nan
|
||||
for att, val in cutoff_pos.items()
|
||||
}
|
||||
cutoff_gain = {
|
||||
att: gains[val] if val >= 0 else math.nan
|
||||
for att, val in cutoff_pos.items()
|
||||
}
|
||||
logger.debug("Cuttoff frequencies: %s", cutoff_freq)
|
||||
logger.debug("Cuttoff gains: %s", cutoff_gain)
|
||||
|
||||
self.derive_60dB(cutoff_pos, cutoff_freq)
|
||||
|
||||
result = {
|
||||
"span_3.0dB": cutoff_freq["3.0dB_r"] - cutoff_freq["3.0dB_l"],
|
||||
"span_6.0dB": cutoff_freq["6.0dB_r"] - cutoff_freq["6.0dB_l"],
|
||||
"freq_center": math.sqrt(
|
||||
cutoff_freq["3.0dB_l"] * cutoff_freq["3.0dB_r"]
|
||||
),
|
||||
}
|
||||
result["q_factor"] = result["freq_center"] / result["span_3.0dB"]
|
||||
|
||||
result["octave_l"], result["decade_l"] = at.calculate_rolloff(
|
||||
s21, cutoff_pos["10.0dB_l"], cutoff_pos["20.0dB_l"]
|
||||
)
|
||||
result["octave_r"], result["decade_r"] = at.calculate_rolloff(
|
||||
s21, cutoff_pos["10.0dB_r"], cutoff_pos["20.0dB_r"]
|
||||
)
|
||||
|
||||
for label, val in cutoff_freq.items():
|
||||
self.label[label].setText(
|
||||
f"{format_frequency(val)}" f" ({cutoff_gain[label]:.1f} dB)"
|
||||
)
|
||||
for label in ("freq_center", "span_3.0dB", "span_6.0dB"):
|
||||
self.label[label].setText(format_frequency(result[label]))
|
||||
self.label["q_factor"].setText(f"{result['q_factor']:.2f}")
|
||||
|
||||
for label in ("octave_l", "decade_l", "octave_r", "decade_r"):
|
||||
self.label[label].setText(f"{result[label]:.3f}dB/{label[:-2]}")
|
||||
|
||||
self.app.markers[0].setFrequency(f"{result['freq_center']}")
|
||||
self.app.markers[1].setFrequency(f"{cutoff_freq['3.0dB_l']}")
|
||||
self.app.markers[2].setFrequency(f"{cutoff_freq['3.0dB_r']}")
|
||||
|
||||
if cutoff_gain["3.0dB_l"] < -4 or cutoff_gain["3.0dB_r"] < -4:
|
||||
logger.warning(
|
||||
"Data points insufficient for true -3 dB points."
|
||||
"Cutoff gains: %fdB, %fdB",
|
||||
cutoff_gain["3.0dB_l"],
|
||||
cutoff_gain["3.0dB_r"],
|
||||
)
|
||||
self.set_result(
|
||||
f"Analysis complete ({len(s21)} points)\n"
|
||||
f"Insufficient data for analysis. Increase segment count."
|
||||
)
|
||||
return
|
||||
self.set_result(f"Analysis complete ({len(s21)} points)")
|
||||
|
||||
def derive_60dB(
|
||||
self, cutoff_pos: dict[str, int], cutoff_freq: dict[str, float]
|
||||
):
|
||||
"""derive 60dB cutoff if needed an possible
|
||||
|
||||
Args:
|
||||
cutoff_pos (dict[str, int])
|
||||
cutoff_freq (dict[str, float])
|
||||
"""
|
||||
if (
|
||||
math.isnan(cutoff_freq["60.0dB_l"])
|
||||
and cutoff_pos["20.0dB_l"] != -1
|
||||
and cutoff_pos["10.0dB_l"] != -1
|
||||
):
|
||||
cutoff_freq["60.0dB_l"] = cutoff_freq["10.0dB_l"] * 10 ** (
|
||||
5
|
||||
* (
|
||||
math.log10(cutoff_pos["20.0dB_l"])
|
||||
- math.log10(cutoff_pos["10.0dB_l"])
|
||||
)
|
||||
)
|
||||
if (
|
||||
math.isnan(cutoff_freq["60.0dB_r"])
|
||||
and cutoff_pos["20.0dB_r"] != -1
|
||||
and cutoff_pos["10.0dB_r"] != -1
|
||||
):
|
||||
cutoff_freq["60.0dB_r"] = cutoff_freq["10.0dB_r"] * 10 ** (
|
||||
5
|
||||
* (
|
||||
math.log10(cutoff_pos["20.0dB_r"])
|
||||
- math.log10(cutoff_pos["10.0dB_r"])
|
||||
)
|
||||
)
|
||||
|
||||
def find_center(self, gains: list[float]) -> int:
|
||||
marker = self.app.markers[0]
|
||||
if marker.location <= 0 or marker.location >= len(gains) - 1:
|
||||
logger.debug(
|
||||
"No valid location for %s (%s)", marker.name, marker.location
|
||||
)
|
||||
self.set_result(f"Please place {marker.name} in the passband.")
|
||||
return -1
|
||||
|
||||
# find center of passband based on marker pos
|
||||
if (peak := at.center_from_idx(gains, marker.location)) < 0:
|
||||
self.set_result("Bandpass center not found")
|
||||
return -1
|
||||
return peak
|
||||
|
||||
def find_bounderies(
|
||||
self, gains: list[float], peak: int, peak_db: float
|
||||
) -> dict[str, int]:
|
||||
cutoff_pos = {}
|
||||
for attn in CUTOFF_VALS:
|
||||
cutoff_pos[f"{attn:.1f}dB_l"] = at.cut_off_left(
|
||||
gains, peak, peak_db, attn
|
||||
)
|
||||
cutoff_pos[f"{attn:.1f}dB_r"] = at.cut_off_right(
|
||||
gains, peak, peak_db, attn
|
||||
)
|
||||
return cutoff_pos
|
|
@ -1,45 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
import NanoVNASaver.AnalyticTools as at
|
||||
from NanoVNASaver.Analysis.Base import CUTOFF_VALS
|
||||
from NanoVNASaver.Analysis.BandPassAnalysis import BandPassAnalysis
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BandStopAnalysis(BandPassAnalysis):
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
self.set_titel("Band stop filter analysis")
|
||||
|
||||
def find_center(self, gains: list[float]) -> int:
|
||||
return max(enumerate(gains), key=lambda i: i[1])[0]
|
||||
|
||||
def find_bounderies(
|
||||
self, gains: list[float], _: int, peak_db: float
|
||||
) -> dict[str, int]:
|
||||
cutoff_pos = {}
|
||||
for attn in CUTOFF_VALS:
|
||||
(
|
||||
cutoff_pos[f"{attn:.1f}dB_l"],
|
||||
cutoff_pos[f"{attn:.1f}dB_r"],
|
||||
) = at.dip_cut_offs(gains, peak_db, attn)
|
||||
return cutoff_pos
|
|
@ -1,58 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CUTOFF_VALS = (3.0, 6.0, 10.0, 20.0, 60.0)
|
||||
|
||||
|
||||
class QHLine(QtWidgets.QFrame):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setFrameShape(QtWidgets.QFrame.Shape.HLine)
|
||||
|
||||
|
||||
class Analysis:
|
||||
def __init__(self, app: QtWidgets.QWidget):
|
||||
self.app = app
|
||||
self.label: dict[str, QtWidgets.QLabel] = {
|
||||
"titel": QtWidgets.QLabel(),
|
||||
"result": QtWidgets.QLabel(),
|
||||
}
|
||||
self.layout = QtWidgets.QFormLayout()
|
||||
self._widget = QtWidgets.QWidget()
|
||||
self._widget.setLayout(self.layout)
|
||||
|
||||
def widget(self) -> QtWidgets.QWidget:
|
||||
return self._widget
|
||||
|
||||
def runAnalysis(self):
|
||||
pass
|
||||
|
||||
def reset(self):
|
||||
for label in self.label.values():
|
||||
label.clear()
|
||||
|
||||
def set_result(self, text):
|
||||
self.label["result"].setText(text)
|
||||
|
||||
def set_titel(self, text):
|
||||
self.label["titel"].setText(text)
|
|
@ -1,177 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import csv
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
import NanoVNASaver.AnalyticTools as at
|
||||
from NanoVNASaver.Analysis.ResonanceAnalysis import (
|
||||
ResonanceAnalysis,
|
||||
format_resistence_neg,
|
||||
)
|
||||
from NanoVNASaver.Formatting import (
|
||||
format_frequency,
|
||||
format_complex_imp,
|
||||
format_frequency_short,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EFHWAnalysis(ResonanceAnalysis):
|
||||
"""
|
||||
find only resonance when HI impedance
|
||||
"""
|
||||
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
self.old_data = []
|
||||
|
||||
def do_resonance_analysis(self):
|
||||
s11 = self.app.data.s11
|
||||
maximums = sorted(
|
||||
at.maxima([d.impedance().real for d in s11], threshold=500)
|
||||
)
|
||||
extended_data = {}
|
||||
logger.info("TO DO: find near data")
|
||||
for lowest in self.crossings:
|
||||
my_data = self._get_data(lowest)
|
||||
if lowest in extended_data:
|
||||
extended_data[lowest].update(my_data)
|
||||
else:
|
||||
extended_data[lowest] = my_data
|
||||
logger.debug("maximumx %s of type %s", maximums, type(maximums))
|
||||
for m in maximums:
|
||||
logger.debug("m %s of type %s", m, type(m))
|
||||
my_data = self._get_data(m)
|
||||
if m in extended_data:
|
||||
extended_data[m].update(my_data)
|
||||
else:
|
||||
extended_data[m] = my_data
|
||||
fields = [
|
||||
("freq", format_frequency_short),
|
||||
("r", format_resistence_neg),
|
||||
("lambda", lambda x: round(x, 2)),
|
||||
]
|
||||
|
||||
if self.old_data:
|
||||
diff = self.compare(self.old_data[-1], extended_data, fields=fields)
|
||||
else:
|
||||
diff = self.compare({}, extended_data, fields=fields)
|
||||
self.old_data.append(extended_data)
|
||||
for i, idx in enumerate(sorted(extended_data.keys())):
|
||||
self.layout.addRow(
|
||||
f"{format_frequency_short(s11[idx].freq)}",
|
||||
QtWidgets.QLabel(
|
||||
f" ({diff[i]['freq']})"
|
||||
f" {format_complex_imp(s11[idx].impedance())}"
|
||||
f" ({diff[i]['r']}) {diff[i]['lambda']} m"
|
||||
),
|
||||
)
|
||||
|
||||
if self.filename and extended_data:
|
||||
with open(
|
||||
self.filename, "w", newline="", encoding="utf-8"
|
||||
) as csvfile:
|
||||
fieldnames = extended_data[
|
||||
sorted(extended_data.keys())[0]
|
||||
].keys()
|
||||
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
for idx in sorted(extended_data.keys()):
|
||||
writer.writerow(extended_data[idx])
|
||||
|
||||
def compare(self, old, new, fields=None):
|
||||
"""
|
||||
Compare data to help changes
|
||||
|
||||
NB
|
||||
must be same sweep
|
||||
( same index must be same frequence )
|
||||
:param old:
|
||||
:param new:
|
||||
"""
|
||||
fields = fields or [
|
||||
("freq", str),
|
||||
]
|
||||
|
||||
def no_compare():
|
||||
return {k: "-" for k, _ in fields}
|
||||
|
||||
old_idx = sorted(old.keys())
|
||||
# 'odict_keys' object is not subscriptable
|
||||
new_idx = sorted(new.keys())
|
||||
diff = {}
|
||||
i_max = min(len(old_idx), len(new_idx))
|
||||
i_tot = max(len(old_idx), len(new_idx))
|
||||
|
||||
if i_max != i_tot:
|
||||
logger.warning(
|
||||
"resonances changed from %s to %s", len(old_idx), len(new_idx)
|
||||
)
|
||||
|
||||
split = 0
|
||||
max_delta_f = 1_000_000
|
||||
for i, k in enumerate(new_idx):
|
||||
if len(old_idx) <= i + split:
|
||||
diff[i] = no_compare()
|
||||
continue
|
||||
|
||||
logger.info("Resonance %s at %s", i, new[k]["freq"])
|
||||
|
||||
delta_f = new[k]["freq"] - old[old_idx[i + split]]["freq"]
|
||||
if abs(delta_f) < max_delta_f:
|
||||
logger.debug("can compare")
|
||||
diff[i] = {
|
||||
desc: fnc(new[k][desc] - old[old_idx[i + split]][desc])
|
||||
for desc, fnc in fields
|
||||
}
|
||||
logger.debug("Deltas %s", diff[i])
|
||||
continue
|
||||
|
||||
logger.debug(
|
||||
"can't compare, %s is too much ", format_frequency(delta_f)
|
||||
)
|
||||
|
||||
if delta_f > 0:
|
||||
logger.debug("possible missing band, ")
|
||||
if len(old_idx) > (i + split + 1):
|
||||
if (
|
||||
abs(
|
||||
new[k]["freq"] - old[old_idx[i + split + 1]]["freq"]
|
||||
)
|
||||
< max_delta_f
|
||||
):
|
||||
logger.debug("new is missing band, compare next ")
|
||||
split += 1
|
||||
# FIXME: manage 2 or more band missing ?!?
|
||||
continue
|
||||
logger.debug("new band, non compare ")
|
||||
diff[i] = no_compare()
|
||||
continue
|
||||
|
||||
logger.debug("new band, non compare ")
|
||||
diff[i] = no_compare()
|
||||
split -= 1
|
||||
|
||||
for i in range(i_max, i_tot):
|
||||
# add missing in old ... if any
|
||||
diff[i] = no_compare()
|
||||
return diff
|
|
@ -1,125 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
import math
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
import NanoVNASaver.AnalyticTools as at
|
||||
from NanoVNASaver.Analysis.Base import Analysis, CUTOFF_VALS
|
||||
from NanoVNASaver.Formatting import format_frequency
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HighPassAnalysis(Analysis):
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
|
||||
self.label["octave"] = QtWidgets.QLabel()
|
||||
self.label["decade"] = QtWidgets.QLabel()
|
||||
for attn in CUTOFF_VALS:
|
||||
self.label[f"{attn:.1f}dB"] = QtWidgets.QLabel()
|
||||
self.label[f"{attn:.1f}dB"] = QtWidgets.QLabel()
|
||||
|
||||
layout = self.layout
|
||||
layout.addRow(self.label["titel"])
|
||||
layout.addRow(
|
||||
QtWidgets.QLabel(
|
||||
f"Please place {self.app.markers[0].name}"
|
||||
f" in the filter passband."
|
||||
)
|
||||
)
|
||||
layout.addRow("Result:", self.label["result"])
|
||||
layout.addRow("Cutoff frequency:", self.label["3.0dB"])
|
||||
layout.addRow("-6 dB point:", self.label["6.0dB"])
|
||||
layout.addRow("-60 dB point:", self.label["60.0dB"])
|
||||
layout.addRow("Roll-off:", self.label["octave"])
|
||||
layout.addRow("Roll-off:", self.label["decade"])
|
||||
|
||||
self.set_titel("Highpass analysis")
|
||||
|
||||
def runAnalysis(self):
|
||||
if not self.app.data.s21:
|
||||
logger.debug("No data to analyse")
|
||||
self.set_result("No data to analyse.")
|
||||
return
|
||||
|
||||
self.reset()
|
||||
s21 = self.app.data.s21
|
||||
gains = [d.gain for d in s21]
|
||||
|
||||
if (peak := self.find_level(gains)) < 0:
|
||||
return
|
||||
peak_db = gains[peak]
|
||||
logger.debug("Passband position: %d(%fdB)", peak, peak_db)
|
||||
|
||||
cutoff_pos = self.find_cutoffs(gains, peak, peak_db)
|
||||
cutoff_freq = {
|
||||
att: s21[val].freq if val >= 0 else math.nan
|
||||
for att, val in cutoff_pos.items()
|
||||
}
|
||||
cutoff_gain = {
|
||||
att: gains[val] if val >= 0 else math.nan
|
||||
for att, val in cutoff_pos.items()
|
||||
}
|
||||
logger.debug("Cuttoff frequencies: %s", cutoff_freq)
|
||||
logger.debug("Cuttoff gains: %s", cutoff_gain)
|
||||
|
||||
octave, decade = at.calculate_rolloff(
|
||||
s21, cutoff_pos["10.0dB"], cutoff_pos["20.0dB"]
|
||||
)
|
||||
|
||||
if cutoff_gain["3.0dB"] < -4:
|
||||
logger.debug(
|
||||
"Cutoff frequency found at %f dB"
|
||||
" - insufficient data points for true -3 dB point.",
|
||||
cutoff_gain,
|
||||
)
|
||||
logger.debug("Found true cutoff frequency at %d", cutoff_freq["3.0dB"])
|
||||
|
||||
for label, val in cutoff_freq.items():
|
||||
self.label[label].setText(
|
||||
f"{format_frequency(val)}" f" ({cutoff_gain[label]:.1f} dB)"
|
||||
)
|
||||
|
||||
self.label["octave"].setText(f"{octave:.3f}dB/octave")
|
||||
self.label["decade"].setText(f"{decade:.3f}dB/decade")
|
||||
|
||||
self.app.markers[0].setFrequency(str(s21[peak].freq))
|
||||
self.app.markers[1].setFrequency(str(cutoff_freq["3.0dB"]))
|
||||
self.app.markers[2].setFrequency(str(cutoff_freq["6.0dB"]))
|
||||
|
||||
self.set_result(f"Analysis complete ({len(s21)}) points)")
|
||||
|
||||
def find_level(self, gains: list[float]) -> int:
|
||||
marker = self.app.markers[0]
|
||||
logger.debug("Pass band location: %d", marker.location)
|
||||
if marker.location < 0:
|
||||
self.set_result(f"Please place {marker.name} in the passband.")
|
||||
return -1
|
||||
return at.center_from_idx(gains, marker.location)
|
||||
|
||||
def find_cutoffs(
|
||||
self, gains: list[float], peak: int, peak_db: float
|
||||
) -> dict[str, int]:
|
||||
return {
|
||||
f"{attn:.1f}dB": at.cut_off_left(gains, peak, peak_db, attn)
|
||||
for attn in CUTOFF_VALS
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
import NanoVNASaver.AnalyticTools as at
|
||||
from NanoVNASaver.Analysis.Base import CUTOFF_VALS
|
||||
from NanoVNASaver.Analysis.HighPassAnalysis import HighPassAnalysis
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LowPassAnalysis(HighPassAnalysis):
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
|
||||
self.set_titel("Lowpass filter analysis")
|
||||
|
||||
def find_cutoffs(
|
||||
self, gains: list[float], peak: int, peak_db: float
|
||||
) -> dict[str, int]:
|
||||
return {
|
||||
f"{attn:.1f}dB": at.cut_off_right(gains, peak, peak_db, attn)
|
||||
for attn in CUTOFF_VALS
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
import numpy as np
|
||||
|
||||
# pylint: disable=import-error, no-name-in-module
|
||||
from scipy.signal import find_peaks, peak_prominences
|
||||
|
||||
from NanoVNASaver.Analysis.Base import QHLine
|
||||
from NanoVNASaver.Analysis.SimplePeakSearchAnalysis import (
|
||||
SimplePeakSearchAnalysis,
|
||||
)
|
||||
|
||||
from NanoVNASaver.Formatting import format_frequency_short
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PeakSearchAnalysis(SimplePeakSearchAnalysis):
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
|
||||
self.peak_cnt = QtWidgets.QSpinBox()
|
||||
self.peak_cnt.setValue(1)
|
||||
self.peak_cnt.setMinimum(1)
|
||||
self.peak_cnt.setMaximum(10)
|
||||
|
||||
self.layout.addRow("Max number of peaks", self.peak_cnt)
|
||||
self.layout.addRow(QHLine())
|
||||
self.layout.addRow(QtWidgets.QLabel("<b>Results</b>"))
|
||||
self.results_header = self.layout.rowCount()
|
||||
|
||||
self.set_titel("Peak search")
|
||||
|
||||
def runAnalysis(self):
|
||||
if not self.app.data.s11:
|
||||
return
|
||||
self.reset()
|
||||
|
||||
s11 = self.app.data.s11
|
||||
data, fmt_fnc = self.data_and_format()
|
||||
|
||||
inverted = False
|
||||
if self.button["peak_l"].isChecked():
|
||||
inverted = True
|
||||
peaks, _ = find_peaks(
|
||||
-np.array(data), width=3, distance=3, prominence=1
|
||||
)
|
||||
else:
|
||||
self.button["peak_h"].setChecked(True)
|
||||
peaks, _ = find_peaks(data, width=3, distance=3, prominence=1)
|
||||
|
||||
# Having found the peaks, get the prominence data
|
||||
for i, p in np.ndenumerate(peaks):
|
||||
logger.debug("Peak %s at %s", i, p)
|
||||
prominences = peak_prominences(data, peaks)[0]
|
||||
logger.debug("%d prominences", len(prominences))
|
||||
|
||||
# Find the peaks with the most extreme values
|
||||
# Alternately, allow the user to select "most prominent"?
|
||||
count = self.peak_cnt.value()
|
||||
if count > len(prominences):
|
||||
count = len(prominences)
|
||||
self.peak_cnt.setValue(count)
|
||||
|
||||
indices = np.argpartition(prominences, -count)[-count:]
|
||||
logger.debug("%d indices", len(indices))
|
||||
for i in indices:
|
||||
pos = peaks[i]
|
||||
self.layout.addRow(
|
||||
f"Freq: {format_frequency_short(s11[pos].freq)}",
|
||||
QtWidgets.QLabel(
|
||||
f" Value: {fmt_fnc(-data[pos] if inverted else data[pos])}"
|
||||
),
|
||||
)
|
||||
|
||||
if self.button["move_marker"].isChecked():
|
||||
if count > len(self.app.markers):
|
||||
logger.warning("More peaks found than there are markers")
|
||||
for i in range(min(count, len(self.app.markers))):
|
||||
self.app.markers[i].setFrequency(
|
||||
str(s11[peaks[indices[i]]].freq)
|
||||
)
|
||||
|
||||
def reset(self):
|
||||
super().reset()
|
||||
logger.debug(
|
||||
"Results start at %d, out of %d",
|
||||
self.results_header,
|
||||
self.layout.rowCount(),
|
||||
)
|
||||
for _ in range(self.results_header, self.layout.rowCount()):
|
||||
logger.debug("deleting %s", self.layout.rowCount())
|
||||
self.layout.removeRow(self.layout.rowCount() - 1)
|
|
@ -1,127 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import os
|
||||
import csv
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
import NanoVNASaver.AnalyticTools as at
|
||||
from NanoVNASaver.Analysis.Base import Analysis, QHLine
|
||||
from NanoVNASaver.Formatting import format_frequency, format_resistance
|
||||
from NanoVNASaver.RFTools import reflection_coefficient
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def format_resistence_neg(x):
|
||||
return format_resistance(x, allow_negative=True)
|
||||
|
||||
|
||||
def vswr_transformed(z, ratio=49) -> float:
|
||||
refl = reflection_coefficient(z / ratio)
|
||||
mag = abs(refl)
|
||||
return 1 if mag == 1 else (1 + mag) / (1 - mag)
|
||||
|
||||
|
||||
class ResonanceAnalysis(Analysis):
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
self.crossings: list[int] = []
|
||||
self.filename = ""
|
||||
self._widget = QtWidgets.QWidget()
|
||||
self.layout = QtWidgets.QFormLayout()
|
||||
self._widget.setLayout(self.layout)
|
||||
self.input_description = QtWidgets.QLineEdit("")
|
||||
self.checkbox_move_marker = QtWidgets.QCheckBox()
|
||||
self.layout.addRow(QtWidgets.QLabel("<b>Settings</b>"))
|
||||
self.layout.addRow("Description", self.input_description)
|
||||
self.layout.addRow(QHLine())
|
||||
|
||||
self.layout.addRow(QHLine())
|
||||
|
||||
self.results_label = QtWidgets.QLabel("<b>Results</b>")
|
||||
self.layout.addRow(self.results_label)
|
||||
|
||||
def _get_data(self, index):
|
||||
s11 = self.app.data.s11
|
||||
my_data = {
|
||||
"freq": s11[index].freq,
|
||||
"s11": s11[index].z,
|
||||
"lambda": s11[index].wavelength,
|
||||
"impedance": s11[index].impedance(),
|
||||
"vswr": s11[index].vswr,
|
||||
}
|
||||
my_data["vswr_49"] = vswr_transformed(my_data["impedance"], 49)
|
||||
my_data["vswr_4"] = vswr_transformed(my_data["impedance"], 4)
|
||||
my_data["r"] = my_data["impedance"].real
|
||||
my_data["x"] = my_data["impedance"].imag
|
||||
|
||||
return my_data
|
||||
|
||||
def runAnalysis(self):
|
||||
self.reset()
|
||||
self.filename = (
|
||||
os.path.join("/tmp/", f"{self.input_description.text()}.csv")
|
||||
if self.input_description.text()
|
||||
else ""
|
||||
)
|
||||
|
||||
results_header = self.layout.indexOf(self.results_label)
|
||||
logger.debug(
|
||||
"Results start at %d, out of %d",
|
||||
results_header,
|
||||
self.layout.rowCount(),
|
||||
)
|
||||
|
||||
for _ in range(results_header, self.layout.rowCount()):
|
||||
self.layout.removeRow(self.layout.rowCount() - 1)
|
||||
|
||||
self.crossings = sorted(
|
||||
set(at.zero_crossings([d.phase for d in self.app.data.s11]))
|
||||
)
|
||||
logger.debug("Found %d sections ", len(self.crossings))
|
||||
if not self.crossings:
|
||||
self.layout.addRow(QtWidgets.QLabel("No resonance found"))
|
||||
return
|
||||
|
||||
self.do_resonance_analysis()
|
||||
|
||||
def do_resonance_analysis(self):
|
||||
extended_data = []
|
||||
for crossing in self.crossings:
|
||||
extended_data.append(self._get_data(crossing))
|
||||
self.layout.addRow(
|
||||
"Resonance",
|
||||
QtWidgets.QLabel(
|
||||
format_frequency(self.app.data.s11[crossing].freq)
|
||||
),
|
||||
)
|
||||
self.layout.addWidget(QHLine())
|
||||
# Remove the final separator line
|
||||
self.layout.removeRow(self.layout.rowCount() - 1)
|
||||
if self.filename and extended_data:
|
||||
with open(
|
||||
self.filename, "w", encoding="utf-8", newline=""
|
||||
) as csvfile:
|
||||
fieldnames = extended_data[0].keys()
|
||||
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
|
||||
writer.writeheader()
|
||||
for row in extended_data:
|
||||
writer.writerow(row)
|
|
@ -1,123 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
from typing import Callable
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
import numpy as np
|
||||
|
||||
from NanoVNASaver.Analysis.Base import Analysis, QHLine
|
||||
from NanoVNASaver.Formatting import (
|
||||
format_frequency,
|
||||
format_gain,
|
||||
format_resistance,
|
||||
format_vswr,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SimplePeakSearchAnalysis(Analysis):
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
|
||||
self.label["peak_freq"] = QtWidgets.QLabel()
|
||||
self.label["peak_db"] = QtWidgets.QLabel()
|
||||
|
||||
self.button = {
|
||||
"vswr": QtWidgets.QRadioButton("VSWR"),
|
||||
"resistance": QtWidgets.QRadioButton("Resistance"),
|
||||
"reactance": QtWidgets.QRadioButton("Reactance"),
|
||||
"gain": QtWidgets.QRadioButton("S21 Gain"),
|
||||
"peak_h": QtWidgets.QRadioButton("Highest value"),
|
||||
"peak_l": QtWidgets.QRadioButton("Lowest value"),
|
||||
"move_marker": QtWidgets.QCheckBox(),
|
||||
}
|
||||
|
||||
self.button["gain"].setChecked(True)
|
||||
self.button["peak_h"].setChecked(True)
|
||||
|
||||
self.btn_group = {
|
||||
"data": QtWidgets.QButtonGroup(),
|
||||
"peak": QtWidgets.QButtonGroup(),
|
||||
}
|
||||
|
||||
for btn in ("vswr", "resistance", "reactance", "gain"):
|
||||
self.btn_group["data"].addButton(self.button[btn])
|
||||
self.btn_group["peak"].addButton(self.button["peak_h"])
|
||||
self.btn_group["peak"].addButton(self.button["peak_l"])
|
||||
|
||||
layout = self.layout
|
||||
layout.addRow(self.label["titel"])
|
||||
layout.addRow(QHLine())
|
||||
layout.addRow(QtWidgets.QLabel("<b>Settings</b>"))
|
||||
layout.addRow("Data source", self.button["vswr"])
|
||||
layout.addRow("", self.button["resistance"])
|
||||
layout.addRow("", self.button["reactance"])
|
||||
layout.addRow("", self.button["gain"])
|
||||
layout.addRow(QHLine())
|
||||
layout.addRow("Peak type", self.button["peak_h"])
|
||||
layout.addRow("", self.button["peak_l"])
|
||||
layout.addRow(QHLine())
|
||||
layout.addRow("Move marker to peak", self.button["move_marker"])
|
||||
layout.addRow(QHLine())
|
||||
layout.addRow(self.label["result"])
|
||||
layout.addRow("Peak frequency:", self.label["peak_freq"])
|
||||
layout.addRow("Peak value:", self.label["peak_db"])
|
||||
|
||||
self.set_titel("Simple peak search")
|
||||
|
||||
def runAnalysis(self):
|
||||
if not self.app.data.s11:
|
||||
return
|
||||
|
||||
s11 = self.app.data.s11
|
||||
data, fmt_fnc = self.data_and_format()
|
||||
|
||||
if self.button["peak_l"].isChecked():
|
||||
idx_peak = np.argmin(data)
|
||||
else:
|
||||
self.button["peak_h"].setChecked(True)
|
||||
idx_peak = np.argmax(data)
|
||||
|
||||
self.label["peak_freq"].setText(format_frequency(s11[idx_peak].freq))
|
||||
self.label["peak_db"].setText(fmt_fnc(data[idx_peak]))
|
||||
|
||||
if self.button["move_marker"].isChecked() and self.app.markers:
|
||||
self.app.markers[0].setFrequency(f"{s11[idx_peak].freq}")
|
||||
|
||||
def data_and_format(self) -> tuple[list[float], Callable]:
|
||||
s11 = self.app.data.s11
|
||||
s21 = self.app.data.s21
|
||||
|
||||
if not s21:
|
||||
self.button["gain"].setEnabled(False)
|
||||
if self.button["gain"].isChecked():
|
||||
self.button["vswr"].setChecked(True)
|
||||
else:
|
||||
self.button["gain"].setEnabled(True)
|
||||
|
||||
if self.button["gain"].isChecked():
|
||||
return ([d.gain for d in s21], format_gain)
|
||||
if self.button["resistance"].isChecked():
|
||||
return ([d.impedance().real for d in s11], format_resistance)
|
||||
if self.button["reactance"].isChecked():
|
||||
return ([d.impedance().imag for d in s11], format_resistance)
|
||||
# default
|
||||
return ([d.vswr for d in s11], format_vswr)
|
|
@ -1,112 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtWidgets
|
||||
|
||||
import NanoVNASaver.AnalyticTools as at
|
||||
from NanoVNASaver.Analysis.Base import Analysis, QHLine
|
||||
from NanoVNASaver.Formatting import format_frequency, format_vswr
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class VSWRAnalysis(Analysis):
|
||||
max_dips_shown = 3
|
||||
vswr_limit_value = 1.5
|
||||
|
||||
def __init__(self, app):
|
||||
super().__init__(app)
|
||||
|
||||
self._widget = QtWidgets.QWidget()
|
||||
self.layout = QtWidgets.QFormLayout()
|
||||
self._widget.setLayout(self.layout)
|
||||
|
||||
self.input_vswr_limit = QtWidgets.QDoubleSpinBox()
|
||||
self.input_vswr_limit.setValue(VSWRAnalysis.vswr_limit_value)
|
||||
self.input_vswr_limit.setSingleStep(0.1)
|
||||
self.input_vswr_limit.setMinimum(1)
|
||||
self.input_vswr_limit.setMaximum(25)
|
||||
self.input_vswr_limit.setDecimals(2)
|
||||
|
||||
self.checkbox_move_marker = QtWidgets.QCheckBox()
|
||||
self.layout.addRow(QtWidgets.QLabel("<b>Settings</b>"))
|
||||
self.layout.addRow("VSWR limit", self.input_vswr_limit)
|
||||
self.layout.addRow(QHLine())
|
||||
|
||||
self.results_label = QtWidgets.QLabel("<b>Results</b>")
|
||||
self.layout.addRow(self.results_label)
|
||||
|
||||
self.minimums: list[int] = []
|
||||
|
||||
def runAnalysis(self):
|
||||
if not self.app.data.s11:
|
||||
return
|
||||
s11 = self.app.data.s11
|
||||
|
||||
data = [d.vswr for d in s11]
|
||||
threshold = self.input_vswr_limit.value()
|
||||
|
||||
minima = sorted(at.minima(data, threshold), key=lambda i: data[i])[
|
||||
: VSWRAnalysis.max_dips_shown
|
||||
]
|
||||
self.minimums = minima
|
||||
|
||||
results_header = self.layout.indexOf(self.results_label)
|
||||
logger.debug(
|
||||
"Results start at %d, out of %d",
|
||||
results_header,
|
||||
self.layout.rowCount(),
|
||||
)
|
||||
for _ in range(results_header, self.layout.rowCount()):
|
||||
self.layout.removeRow(self.layout.rowCount() - 1)
|
||||
|
||||
if not minima:
|
||||
self.layout.addRow(
|
||||
QtWidgets.QLabel(
|
||||
f"No areas found with VSWR below {format_vswr(threshold)}."
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
for idx in minima:
|
||||
rng = at.take_from_idx(data, idx, lambda i: i[1] < threshold)
|
||||
begin, end = rng[0], rng[-1]
|
||||
self.layout.addRow(
|
||||
"Start", QtWidgets.QLabel(format_frequency(s11[begin].freq))
|
||||
)
|
||||
self.layout.addRow(
|
||||
"Minimum",
|
||||
QtWidgets.QLabel(
|
||||
f"{format_frequency(s11[idx].freq)}"
|
||||
f" ({round(s11[idx].vswr, 2)})"
|
||||
),
|
||||
)
|
||||
self.layout.addRow(
|
||||
"End", QtWidgets.QLabel(format_frequency(s11[end].freq))
|
||||
)
|
||||
self.layout.addRow(
|
||||
"Span",
|
||||
QtWidgets.QLabel(
|
||||
format_frequency((s11[end].freq - s11[begin].freq))
|
||||
),
|
||||
)
|
||||
self.layout.addWidget(QHLine())
|
||||
|
||||
self.layout.removeRow(self.layout.rowCount() - 1)
|
|
@ -1,191 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import itertools as it
|
||||
import math
|
||||
from typing import Callable
|
||||
|
||||
import numpy as np
|
||||
|
||||
# pylint: disable=import-error, no-name-in-module
|
||||
from scipy.signal import find_peaks
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
|
||||
|
||||
def zero_crossings(data: list[float]) -> list[int]:
|
||||
"""find zero crossings
|
||||
|
||||
Args:
|
||||
data (list[float]): data list execute
|
||||
|
||||
Returns:
|
||||
list[int]: sorted indices of zero crossing points
|
||||
"""
|
||||
if not data:
|
||||
return []
|
||||
|
||||
np_data = np.array(data)
|
||||
|
||||
# start with real zeros (ignore first and last element)
|
||||
real_zeros = [
|
||||
n for n in np.where(np_data == 0.0)[0] if n not in {0, np_data.size - 1}
|
||||
]
|
||||
# now multipy elements to find change in signess
|
||||
crossings = [
|
||||
n if abs(np_data[n]) < abs(np_data[n + 1]) else n + 1
|
||||
for n in np.where((np_data[:-1] * np_data[1:]) < 0.0)[0]
|
||||
]
|
||||
return sorted(real_zeros + crossings)
|
||||
|
||||
|
||||
def maxima(data: list[float], threshold: float = 0.0) -> list[int]:
|
||||
"""maxima
|
||||
|
||||
Args:
|
||||
data (list[float]): data list to execute
|
||||
|
||||
Returns:
|
||||
list[int]: indices of maxima
|
||||
"""
|
||||
peaks = find_peaks(data, width=2, distance=3, prominence=1)[0].tolist()
|
||||
return [i for i in peaks if data[i] > threshold] if threshold else peaks
|
||||
|
||||
|
||||
def minima(data: list[float], threshold: float = 0.0) -> list[int]:
|
||||
"""minima
|
||||
|
||||
Args:
|
||||
data (list[float]): data list to execute
|
||||
|
||||
Returns:
|
||||
list[int]: indices of minima
|
||||
"""
|
||||
bottoms = find_peaks(-np.array(data), width=2, distance=3, prominence=1)[
|
||||
0
|
||||
].tolist()
|
||||
return [i for i in bottoms if data[i] < threshold] if threshold else bottoms
|
||||
|
||||
|
||||
def take_from_idx(
|
||||
data: list[float], idx: int, predicate: Callable
|
||||
) -> list[int]:
|
||||
"""take_from_center
|
||||
|
||||
Args:
|
||||
data (list[float]): data list to execute
|
||||
idx (int): index of a start position
|
||||
predicate (Callable): predicate on which elements to take
|
||||
from center. (e.g. lambda i: i[1] < threshold)
|
||||
|
||||
Returns:
|
||||
list[int]: indices of element matching predicate left
|
||||
and right from index
|
||||
"""
|
||||
lower = list(
|
||||
reversed(
|
||||
[
|
||||
i
|
||||
for i, _ in it.takewhile(
|
||||
predicate, reversed(list(enumerate(data[:idx])))
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
upper = [i for i, _ in it.takewhile(predicate, enumerate(data[idx:], idx))]
|
||||
return lower + upper
|
||||
|
||||
|
||||
def center_from_idx(gains: list[float], idx: int, delta: float = 3.0) -> int:
|
||||
"""find maximum from index postion of gains in a attn dB gain span
|
||||
|
||||
Args:
|
||||
gains (list[float]): gain values
|
||||
idx (int): start position to search from
|
||||
delta (float, optional): max gain delta from start. Defaults to 3.0.
|
||||
|
||||
Returns:
|
||||
int: position of highest gain from start in range (-1 if no data)
|
||||
"""
|
||||
peak_db = gains[idx]
|
||||
rng = take_from_idx(gains, idx, lambda i: abs(peak_db - i[1]) < delta)
|
||||
return max(rng, key=lambda i: gains[i]) if rng else -1
|
||||
|
||||
|
||||
def cut_off_left(
|
||||
gains: list[float], idx: int, peak_gain: float, attn: float = 3.0
|
||||
) -> int:
|
||||
"""find first position in list where gain in attn lower then peak
|
||||
left from index
|
||||
|
||||
Args:
|
||||
gains (list[float]): gain values
|
||||
idx (int): start position to search from
|
||||
peak_gain (float): reference gain value
|
||||
attn (float, optional): attenuation to search position for.
|
||||
Defaults to 3.0.
|
||||
|
||||
Returns:
|
||||
int: position of attenuation point. (-1 if no data)
|
||||
"""
|
||||
return next(
|
||||
(i for i in range(idx, -1, -1) if (peak_gain - gains[i]) > attn), -1
|
||||
)
|
||||
|
||||
|
||||
def cut_off_right(
|
||||
gains: list[float], idx: int, peak_gain: float, attn: float = 3.0
|
||||
) -> int:
|
||||
"""find first position in list where gain in attn lower then peak
|
||||
right from index
|
||||
|
||||
Args:
|
||||
gains (list[float]): gain values
|
||||
idx (int): start position to search from
|
||||
peak_gain (float): reference gain value
|
||||
attn (float, optional): attenuation to search position for.
|
||||
Defaults to 3.0.
|
||||
|
||||
Returns:
|
||||
int: position of attenuation point. (-1 if no data)
|
||||
"""
|
||||
|
||||
return next(
|
||||
(i for i in range(idx, len(gains)) if (peak_gain - gains[i]) > attn), -1
|
||||
)
|
||||
|
||||
|
||||
def dip_cut_offs(
|
||||
gains: list[float], peak_gain: float, attn: float = 3.0
|
||||
) -> tuple[int, int]:
|
||||
rng = np.where(np.array(gains) < (peak_gain - attn))[0].tolist()
|
||||
return (rng[0], rng[-1]) if rng else (math.nan, math.nan)
|
||||
|
||||
|
||||
def calculate_rolloff(
|
||||
s21: list[Datapoint], idx_1: int, idx_2: int
|
||||
) -> tuple[float, float]:
|
||||
if idx_1 == idx_2:
|
||||
return (math.nan, math.nan)
|
||||
freq_1, freq_2 = s21[idx_1].freq, s21[idx_2].freq
|
||||
gain_1, gain_2 = s21[idx_1].gain, s21[idx_2].gain
|
||||
factor = freq_1 / freq_2 if freq_1 > freq_2 else freq_2 / freq_1
|
||||
attn = abs(gain_1 - gain_2)
|
||||
decade_attn = attn / math.log10(factor)
|
||||
octave_attn = decade_attn * math.log10(2)
|
||||
return (octave_attn, decade_attn)
|
|
@ -1,543 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
import cmath
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
from collections import defaultdict, UserDict
|
||||
from dataclasses import dataclass
|
||||
|
||||
from scipy.interpolate import interp1d
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
|
||||
|
||||
IDEAL_SHORT = complex(-1, 0)
|
||||
IDEAL_OPEN = complex(1, 0)
|
||||
IDEAL_LOAD = complex(0, 0)
|
||||
IDEAL_THROUGH = complex(1, 0)
|
||||
|
||||
RXP_CAL_HEADER = re.compile(
|
||||
r"""
|
||||
^ \# \s+ Hz \s+
|
||||
ShortR \s+ ShortI \s+ OpenR \s+ OpenI \s+
|
||||
LoadR \s+ LoadI
|
||||
(?P<through> \s+ ThroughR \s+ ThroughI)?
|
||||
(?P<thrurefl> \s+ ThrureflR \s+ ThrureflI)?
|
||||
(?P<isolation> \s+ IsolationR \s+ IsolationI)?
|
||||
\s* $
|
||||
""",
|
||||
re.VERBOSE | re.IGNORECASE,
|
||||
)
|
||||
|
||||
RXP_CAL_LINE = re.compile(
|
||||
r"""
|
||||
^ \s*
|
||||
(?P<freq>\d+) \s+
|
||||
(?P<shortr>[-0-9Ee.]+) \s+ (?P<shorti>[-0-9Ee.]+) \s+
|
||||
(?P<openr>[-0-9Ee.]+) \s+ (?P<openi>[-0-9Ee.]+) \s+
|
||||
(?P<loadr>[-0-9Ee.]+) \s+ (?P<loadi>[-0-9Ee.]+)
|
||||
( \s+ (?P<throughr>[-0-9Ee.]+) \s+ (?P<throughi>[-0-9Ee.]+))?
|
||||
( \s+ (?P<thrureflr>[-0-9Ee.]+) \s+ (?P<thrurefli>[-0-9Ee.]+))?
|
||||
( \s+ (?P<isolationr>[-0-9Ee.]+) \s+ (?P<isolationi>[-0-9Ee.]+))?
|
||||
\s* $
|
||||
""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def correct_delay(d: Datapoint, delay: float, reflect: bool = False):
|
||||
mult = 2 if reflect else 1
|
||||
corr_data = d.z * cmath.exp(
|
||||
complex(0, 1) * 2 * math.pi * d.freq * delay * -1 * mult
|
||||
)
|
||||
return Datapoint(d.freq, corr_data.real, corr_data.imag)
|
||||
|
||||
|
||||
@dataclass
|
||||
class CalData:
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
short: complex = complex(0.0, 0.0)
|
||||
open: complex = complex(0.0, 0.0)
|
||||
load: complex = complex(0.0, 0.0)
|
||||
through: complex = complex(0.0, 0.0)
|
||||
thrurefl: complex = complex(0.0, 0.0)
|
||||
isolation: complex = complex(0.0, 0.0)
|
||||
freq: int = 0
|
||||
e00: float = 0.0 # Directivity
|
||||
e11: float = 0.0 # Port1 match
|
||||
delta_e: float = 0.0 # Tracking
|
||||
e10e01: float = 0.0 # Forward Reflection Tracking
|
||||
# 2 port
|
||||
e30: float = 0.0 # Forward isolation
|
||||
e22: float = 0.0 # Port2 match
|
||||
e10e32: float = 0.0 # Forward transmission
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
f"{self.freq}"
|
||||
f" {self.short.real} {self.short.imag}"
|
||||
f" {self.open.real} {self.open.imag}"
|
||||
f" {self.load.real} {self.load.imag}"
|
||||
+ (
|
||||
f" {self.through.real} {self.through.imag}"
|
||||
f" {self.thrurefl.real} {self.thrurefl.imag}"
|
||||
f" {self.isolation.real} {self.isolation.imag}"
|
||||
if self.through
|
||||
else ""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class CalElement:
|
||||
# pylint: disable=too-many-instance-attributes
|
||||
short_is_ideal: bool = True
|
||||
short_l0: float = 5.7e-12
|
||||
short_l1: float = -8.96e-20
|
||||
short_l2: float = -1.1e-29
|
||||
short_l3: float = -4.12e-37
|
||||
short_length: float = -34.2 # ps
|
||||
|
||||
open_is_ideal: bool = True
|
||||
open_c0: float = 2.1e-14
|
||||
open_c1: float = 5.67e-23
|
||||
open_c2: float = -2.39e-31
|
||||
open_c3: float = 2.0e-40
|
||||
open_length: float = 0.0
|
||||
|
||||
load_is_ideal: bool = True
|
||||
load_r: float = 50.0
|
||||
load_l: float = 0.0
|
||||
load_c: float = 0.0
|
||||
load_length: float = 0.0
|
||||
|
||||
through_is_ideal: bool = True
|
||||
through_length: float = 0.0
|
||||
|
||||
|
||||
class CalDataSet(UserDict):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.notes = ""
|
||||
self.data: defaultdict[int, CalData] = defaultdict(CalData)
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
(
|
||||
"# Calibration data for NanoVNA-Saver\n"
|
||||
+ "\n".join([f"! {note}" for note in self.notes.splitlines()])
|
||||
+ "\n"
|
||||
+ "# Hz ShortR ShortI OpenR OpenI LoadR LoadI"
|
||||
+ (
|
||||
" ThroughR ThroughI ThrureflR"
|
||||
" ThrureflI IsolationR IsolationI\n"
|
||||
if self.complete2port()
|
||||
else "\n"
|
||||
)
|
||||
+ "\n".join(
|
||||
[f"{self.data.get(freq)}" for freq in self.frequencies()]
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
if self.complete1port()
|
||||
else ""
|
||||
)
|
||||
|
||||
def _append_match(
|
||||
self, m: re.Match, header: str, line_nr: int, line: str
|
||||
) -> None:
|
||||
cal = m.groupdict()
|
||||
columns = {col[:-1] for col in cal.keys() if cal[col] and col != "freq"}
|
||||
if "through" in columns and header == "sol":
|
||||
logger.warning(
|
||||
"Through data with sol header. %i: %s", line_nr, line
|
||||
)
|
||||
# fix short data (without thrurefl)
|
||||
if "thrurefl" in columns and "isolation" not in columns:
|
||||
cal["isolationr"] = cal["thrureflr"]
|
||||
cal["isolationi"] = cal["thrurefli"]
|
||||
cal["thrureflr"], cal["thrurefli"] = None, None
|
||||
for name in columns:
|
||||
self.insert(
|
||||
name,
|
||||
Datapoint(
|
||||
int(cal["freq"]),
|
||||
float(cal[f"{name}r"]),
|
||||
float(cal[f"{name}i"]),
|
||||
),
|
||||
)
|
||||
|
||||
def from_str(self, text: str) -> "CalDataSet":
|
||||
# reset data
|
||||
self.notes = ""
|
||||
self.data = defaultdict(CalData)
|
||||
header = ""
|
||||
# parse text
|
||||
for i, line in enumerate(text.splitlines(), 1):
|
||||
line = line.strip()
|
||||
|
||||
if line.startswith("!"):
|
||||
self.notes += f"{line[2:]}\n"
|
||||
continue
|
||||
if m := RXP_CAL_HEADER.search(line):
|
||||
if header:
|
||||
logger.warning(
|
||||
"Duplicate header in cal data. %i: %s", i, line
|
||||
)
|
||||
header = "through" if m.group("through") else "sol"
|
||||
continue
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
|
||||
m = RXP_CAL_LINE.search(line)
|
||||
if not m:
|
||||
logger.warning("Illegal caldata. Line %i: %s", i, line)
|
||||
continue
|
||||
if not header:
|
||||
logger.warning(
|
||||
"Caldata without having read header: %i: %s", i, line
|
||||
)
|
||||
self._append_match(m, header, line, i)
|
||||
return self
|
||||
|
||||
def insert(self, name: str, dp: Datapoint):
|
||||
if name not in {
|
||||
"short",
|
||||
"open",
|
||||
"load",
|
||||
"through",
|
||||
"thrurefl",
|
||||
"isolation",
|
||||
}:
|
||||
raise KeyError(name)
|
||||
freq = dp.freq
|
||||
setattr(self.data[freq], name, (dp.z))
|
||||
self.data[freq].freq = freq
|
||||
|
||||
def frequencies(self) -> list[int]:
|
||||
return sorted(self.data.keys())
|
||||
|
||||
def get(self, key: int, default: CalData = None) -> CalData:
|
||||
return self.data.get(key, default)
|
||||
|
||||
def items(self):
|
||||
yield from self.data.items()
|
||||
|
||||
def values(self):
|
||||
for freq in self.frequencies():
|
||||
yield self.get(freq)
|
||||
|
||||
def size_of(self, name: str) -> int:
|
||||
return len([True for val in self.data.values() if getattr(val, name)])
|
||||
|
||||
def complete1port(self) -> bool:
|
||||
for val in self.data.values():
|
||||
if not all((val.short, val.open, val.load)):
|
||||
return False
|
||||
return any(self.data)
|
||||
|
||||
def complete2port(self) -> bool:
|
||||
if not self.complete1port():
|
||||
return False
|
||||
for val in self.data.values():
|
||||
if not all((val.through, val.thrurefl, val.isolation)):
|
||||
return False
|
||||
return any(self.data)
|
||||
|
||||
|
||||
class Calibration:
|
||||
def __init__(self):
|
||||
self.notes = []
|
||||
self.dataset = CalDataSet()
|
||||
self.cal_element = CalElement()
|
||||
self.interp = {}
|
||||
self.isCalculated = False
|
||||
|
||||
self.source = "Manual"
|
||||
|
||||
def insert(self, name: str, data: list[Datapoint]):
|
||||
for dp in data:
|
||||
self.dataset.insert(name, dp)
|
||||
|
||||
def size(self) -> int:
|
||||
return len(self.dataset.frequencies())
|
||||
|
||||
def data_size(self, name) -> int:
|
||||
return self.dataset.size_of(name)
|
||||
|
||||
def isValid1Port(self) -> bool:
|
||||
return self.dataset.complete1port()
|
||||
|
||||
def isValid2Port(self) -> bool:
|
||||
return self.dataset.complete2port()
|
||||
|
||||
def _calc_port_1(self, freq: int, cal: CalData):
|
||||
g1 = self.gamma_short(freq)
|
||||
g2 = self.gamma_open(freq)
|
||||
g3 = self.gamma_load(freq)
|
||||
|
||||
gm1 = cal.short
|
||||
gm2 = cal.open
|
||||
gm3 = cal.load
|
||||
|
||||
denominator = (
|
||||
g1 * (g2 - g3) * gm1
|
||||
+ g2 * g3 * gm2
|
||||
- g2 * g3 * gm3
|
||||
- (g2 * gm2 - g3 * gm3) * g1
|
||||
)
|
||||
cal.e00 = (
|
||||
-(
|
||||
(g2 * gm3 - g3 * gm3) * g1 * gm2
|
||||
- (g2 * g3 * gm2 - g2 * g3 * gm3 - (g3 * gm2 - g2 * gm3) * g1)
|
||||
* gm1
|
||||
)
|
||||
/ denominator
|
||||
)
|
||||
cal.e11 = (
|
||||
(g2 - g3) * gm1 - g1 * (gm2 - gm3) + g3 * gm2 - g2 * gm3
|
||||
) / denominator
|
||||
cal.delta_e = (
|
||||
-(
|
||||
(g1 * (gm2 - gm3) - g2 * gm2 + g3 * gm3) * gm1
|
||||
+ (g2 * gm3 - g3 * gm3) * gm2
|
||||
)
|
||||
/ denominator
|
||||
)
|
||||
|
||||
def _calc_port_2(self, freq: int, cal: CalData):
|
||||
gt = self.gamma_through(freq)
|
||||
|
||||
gm4 = cal.through
|
||||
gm5 = cal.thrurefl
|
||||
gm6 = cal.isolation
|
||||
gm7 = gm5 - cal.e00
|
||||
|
||||
cal.e30 = cal.isolation
|
||||
cal.e10e01 = cal.e00 * cal.e11 - cal.delta_e
|
||||
cal.e22 = gm7 / (gm7 * cal.e11 * gt**2 + cal.e10e01 * gt**2)
|
||||
cal.e10e32 = (gm4 - gm6) * (1 - cal.e11 * cal.e22 * gt**2) / gt
|
||||
|
||||
def calc_corrections(self):
|
||||
if not self.isValid1Port():
|
||||
logger.warning("Tried to calibrate from insufficient data.")
|
||||
raise ValueError(
|
||||
"All of short, open and load calibration steps"
|
||||
"must be completed for calibration to be applied."
|
||||
)
|
||||
logger.debug("Calculating calibration for %d points.", self.size())
|
||||
|
||||
for freq, caldata in self.dataset.items():
|
||||
try:
|
||||
self._calc_port_1(freq, caldata)
|
||||
if self.isValid2Port():
|
||||
self._calc_port_2(freq, caldata)
|
||||
except ZeroDivisionError as exc:
|
||||
self.isCalculated = False
|
||||
logger.error(
|
||||
"Division error - did you use the same measurement"
|
||||
" for two of short, open and load?"
|
||||
)
|
||||
raise ValueError(
|
||||
f"Two of short, open and load returned the same"
|
||||
f" values at frequency {freq}Hz."
|
||||
) from exc
|
||||
|
||||
self.gen_interpolation()
|
||||
self.isCalculated = True
|
||||
logger.debug("Calibration correctly calculated.")
|
||||
|
||||
def gamma_short(self, freq: int) -> complex:
|
||||
if self.cal_element.short_is_ideal:
|
||||
return IDEAL_SHORT
|
||||
logger.debug("Using short calibration set values.")
|
||||
cal_element = self.cal_element
|
||||
Zsp = complex(
|
||||
0.0,
|
||||
2.0
|
||||
* math.pi
|
||||
* freq
|
||||
* (
|
||||
cal_element.short_l0
|
||||
+ cal_element.short_l1 * freq
|
||||
+ cal_element.short_l2 * freq**2
|
||||
+ cal_element.short_l3 * freq**3
|
||||
),
|
||||
)
|
||||
# Referencing https://arxiv.org/pdf/1606.02446.pdf (18) - (21)
|
||||
return (
|
||||
(Zsp / 50.0 - 1.0)
|
||||
/ (Zsp / 50.0 + 1.0)
|
||||
* cmath.exp(
|
||||
complex(0.0, -4.0 * math.pi * freq * cal_element.short_length)
|
||||
)
|
||||
)
|
||||
|
||||
def gamma_open(self, freq: int) -> complex:
|
||||
if self.cal_element.open_is_ideal:
|
||||
return IDEAL_OPEN
|
||||
logger.debug("Using open calibration set values.")
|
||||
cal_element = self.cal_element
|
||||
Zop = complex(
|
||||
0.0,
|
||||
2.0
|
||||
* math.pi
|
||||
* freq
|
||||
* (
|
||||
cal_element.open_c0
|
||||
+ cal_element.open_c1 * freq
|
||||
+ cal_element.open_c2 * freq**2
|
||||
+ cal_element.open_c3 * freq**3
|
||||
),
|
||||
)
|
||||
return ((1.0 - 50.0 * Zop) / (1.0 + 50.0 * Zop)) * cmath.exp(
|
||||
complex(0.0, -4.0 * math.pi * freq * cal_element.open_length)
|
||||
)
|
||||
|
||||
def gamma_load(self, freq: int) -> complex:
|
||||
if self.cal_element.load_is_ideal:
|
||||
return IDEAL_LOAD
|
||||
logger.debug("Using load calibration set values.")
|
||||
cal_element = self.cal_element
|
||||
Zl = complex(cal_element.load_r, 0.0)
|
||||
if cal_element.load_c > 0.0:
|
||||
Zl = cal_element.load_r / complex(
|
||||
1.0,
|
||||
2.0 * cal_element.load_r * math.pi * freq * cal_element.load_c,
|
||||
)
|
||||
if cal_element.load_l > 0.0:
|
||||
Zl = Zl + complex(0.0, 2 * math.pi * freq * cal_element.load_l)
|
||||
return (
|
||||
(Zl / 50.0 - 1.0)
|
||||
/ (Zl / 50.0 + 1.0)
|
||||
* cmath.exp(
|
||||
complex(0.0, -4 * math.pi * freq * cal_element.load_length)
|
||||
)
|
||||
)
|
||||
|
||||
def gamma_through(self, freq: int) -> complex:
|
||||
if self.cal_element.through_is_ideal:
|
||||
return IDEAL_THROUGH
|
||||
logger.debug("Using through calibration set values.")
|
||||
cal_element = self.cal_element
|
||||
return cmath.exp(
|
||||
complex(0.0, -2.0 * math.pi * cal_element.through_length * freq)
|
||||
)
|
||||
|
||||
def gen_interpolation(self):
|
||||
(freq, e00, e11, delta_e, e10e01, e30, e22, e10e32) = zip(
|
||||
*[
|
||||
(
|
||||
c.freq,
|
||||
c.e00,
|
||||
c.e11,
|
||||
c.delta_e,
|
||||
c.e10e01,
|
||||
c.e30,
|
||||
c.e22,
|
||||
c.e10e32,
|
||||
)
|
||||
for c in self.dataset.values()
|
||||
]
|
||||
)
|
||||
|
||||
self.interp = {
|
||||
"e00": interp1d(
|
||||
freq,
|
||||
e00,
|
||||
kind="slinear",
|
||||
bounds_error=False,
|
||||
fill_value=(e00[0], e00[-1]),
|
||||
),
|
||||
"e11": interp1d(
|
||||
freq,
|
||||
e11,
|
||||
kind="slinear",
|
||||
bounds_error=False,
|
||||
fill_value=(e11[0], e11[-1]),
|
||||
),
|
||||
"delta_e": interp1d(
|
||||
freq,
|
||||
delta_e,
|
||||
kind="slinear",
|
||||
bounds_error=False,
|
||||
fill_value=(delta_e[0], delta_e[-1]),
|
||||
),
|
||||
"e10e01": interp1d(
|
||||
freq,
|
||||
e10e01,
|
||||
kind="slinear",
|
||||
bounds_error=False,
|
||||
fill_value=(e10e01[0], e10e01[-1]),
|
||||
),
|
||||
"e30": interp1d(
|
||||
freq,
|
||||
e30,
|
||||
kind="slinear",
|
||||
bounds_error=False,
|
||||
fill_value=(e30[0], e30[-1]),
|
||||
),
|
||||
"e22": interp1d(
|
||||
freq,
|
||||
e22,
|
||||
kind="slinear",
|
||||
bounds_error=False,
|
||||
fill_value=(e22[0], e22[-1]),
|
||||
),
|
||||
"e10e32": interp1d(
|
||||
freq,
|
||||
e10e32,
|
||||
kind="slinear",
|
||||
bounds_error=False,
|
||||
fill_value=(e10e32[0], e10e32[-1]),
|
||||
),
|
||||
}
|
||||
|
||||
def correct11(self, dp: Datapoint):
|
||||
i = self.interp
|
||||
s11 = (dp.z - i["e00"](dp.freq)) / (
|
||||
(dp.z * i["e11"](dp.freq)) - i["delta_e"](dp.freq)
|
||||
)
|
||||
return Datapoint(dp.freq, s11.real, s11.imag)
|
||||
|
||||
def correct21(self, dp: Datapoint, dp11: Datapoint):
|
||||
i = self.interp
|
||||
s21 = (dp.z - i["e30"](dp.freq)) / i["e10e32"](dp.freq)
|
||||
s21 = s21 * (
|
||||
i["e10e01"](dp.freq)
|
||||
/ (i["e11"](dp.freq) * dp11.z - i["delta_e"](dp.freq))
|
||||
)
|
||||
return Datapoint(dp.freq, s21.real, s21.imag)
|
||||
|
||||
def save(self, filename: str):
|
||||
self.dataset.notes = "\n".join(self.notes)
|
||||
if not self.isValid1Port():
|
||||
raise ValueError("Not a valid calibration")
|
||||
with open(filename, mode="w", encoding="utf-8") as calfile:
|
||||
calfile.write(str(self.dataset))
|
||||
|
||||
def load(self, filename):
|
||||
self.source = os.path.basename(filename)
|
||||
with open(filename, encoding="utf-8") as calfile:
|
||||
self.dataset = CalDataSet().from_str(calfile.read())
|
||||
self.notes = self.dataset.notes.splitlines()
|
|
@ -1,194 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.LogMag import LogMagChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CombinedLogMagChart(LogMagChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
|
||||
self.data11: list[Datapoint] = []
|
||||
self.data21: list[Datapoint] = []
|
||||
|
||||
self.reference11: list[Datapoint] = []
|
||||
self.reference21: list[Datapoint] = []
|
||||
|
||||
def setCombinedData(self, data11, data21):
|
||||
self.data11 = data11
|
||||
self.data21 = data21
|
||||
self.update()
|
||||
|
||||
def setCombinedReference(self, data11, data21):
|
||||
self.reference11 = data11
|
||||
self.reference21 = data21
|
||||
self.update()
|
||||
|
||||
def resetReference(self):
|
||||
self.reference11 = []
|
||||
self.reference21 = []
|
||||
self.update()
|
||||
|
||||
def resetDisplayLimits(self):
|
||||
self.reference11 = []
|
||||
self.reference21 = []
|
||||
self.update()
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(
|
||||
int(self.dim.width // 2) - 20, 15, f"{self.name} {self.name_unit}"
|
||||
)
|
||||
qp.drawText(10, 15, "S11")
|
||||
qp.drawText(self.leftMargin + self.dim.width - 8, 15, "S21")
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin,
|
||||
self.topMargin - 5,
|
||||
self.leftMargin,
|
||||
self.topMargin + self.dim.height + 5,
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin + self.dim.height,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin + self.dim.height,
|
||||
)
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if len(self.data11) == 0 and len(self.reference11) == 0:
|
||||
return
|
||||
pen = QtGui.QPen(Chart.color.sweep)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(Chart.color.sweep)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255))
|
||||
highlighter.setWidth(1)
|
||||
if not self.fixedSpan:
|
||||
if len(self.data11) > 0:
|
||||
fstart = self.data11[0].freq
|
||||
fstop = self.data11[len(self.data11) - 1].freq
|
||||
else:
|
||||
fstart = self.reference11[0].freq
|
||||
fstop = self.reference11[len(self.reference11) - 1].freq
|
||||
self.fstart = fstart
|
||||
self.fstop = fstop
|
||||
else:
|
||||
fstart = self.fstart = self.minFrequency
|
||||
fstop = self.fstop = self.maxFrequency
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, fstart, fstop)
|
||||
|
||||
self.calc_scaling()
|
||||
self.draw_grid(qp)
|
||||
|
||||
if self.data11:
|
||||
c = QtGui.QColor(Chart.color.sweep)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(33, 9, 38, 9)
|
||||
c = QtGui.QColor(Chart.color.sweep_secondary)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(
|
||||
self.leftMargin + self.dim.width - 20,
|
||||
9,
|
||||
self.leftMargin + self.dim.width - 15,
|
||||
9,
|
||||
)
|
||||
|
||||
if self.reference11:
|
||||
c = QtGui.QColor(Chart.color.reference)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(33, 14, 38, 14)
|
||||
c = QtGui.QColor(Chart.color.reference_secondary)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(
|
||||
self.leftMargin + self.dim.width - 20,
|
||||
14,
|
||||
self.leftMargin + self.dim.width - 15,
|
||||
14,
|
||||
)
|
||||
|
||||
self.drawData(qp, self.data11, Chart.color.sweep)
|
||||
self.drawData(qp, self.data21, Chart.color.sweep_secondary)
|
||||
self.drawData(qp, self.reference11, Chart.color.reference)
|
||||
self.drawData(qp, self.reference21, Chart.color.reference_secondary)
|
||||
self.drawMarkers(qp, data=self.data11)
|
||||
self.drawMarkers(qp, data=self.data21)
|
||||
|
||||
def calc_scaling(self) -> None:
|
||||
if self.fixedValues:
|
||||
maxValue = self.maxDisplayValue
|
||||
minValue = self.minDisplayValue
|
||||
else:
|
||||
# Find scaling
|
||||
minValue = 100
|
||||
maxValue = -100
|
||||
for d in self.data11 + self.data21:
|
||||
logmag = self.logMag(d)
|
||||
if math.isinf(logmag):
|
||||
continue
|
||||
maxValue = max(maxValue, logmag)
|
||||
minValue = min(minValue, logmag)
|
||||
|
||||
for d in self.reference11 + self.reference21:
|
||||
if d.freq < self.fstart or d.freq > self.fstop:
|
||||
continue
|
||||
logmag = self.logMag(d)
|
||||
if math.isinf(logmag):
|
||||
continue
|
||||
maxValue = max(maxValue, logmag)
|
||||
minValue = min(minValue, logmag)
|
||||
|
||||
minValue = 10 * math.floor(minValue / 10)
|
||||
maxValue = 10 * math.ceil(maxValue / 10)
|
||||
|
||||
self.minValue = minValue
|
||||
self.maxValue = maxValue
|
||||
|
||||
def copy(self):
|
||||
new_chart: LogMagChart = super().copy()
|
||||
new_chart.isInverted = self.isInverted
|
||||
new_chart.span = self.span
|
||||
new_chart.data11 = self.data11
|
||||
new_chart.data21 = self.data21
|
||||
new_chart.reference11 = self.reference11
|
||||
new_chart.reference21 = self.reference21
|
||||
return new_chart
|
|
@ -1,31 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CapacitanceChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
self.minDisplayValue = 0
|
||||
self.maxDisplayValue = 100
|
||||
self.name_unit = "F"
|
||||
self.value_function = lambda x: x.capacitiveEquivalent()
|
|
@ -1,351 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from dataclasses import dataclass, field, replace
|
||||
from typing import ClassVar, Any
|
||||
|
||||
from PyQt6 import QtWidgets, QtGui, QtCore
|
||||
from PyQt6.QtCore import pyqtSignal, Qt
|
||||
from PyQt6.QtGui import QColor, QColorConstants, QAction
|
||||
|
||||
from NanoVNASaver import Defaults
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Marker.Widget import Marker
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ChartColors: # pylint: disable=too-many-instance-attributes
|
||||
background: QColor = field(
|
||||
default_factory=lambda: QColor(QColorConstants.White)
|
||||
)
|
||||
foreground: QColor = field(
|
||||
default_factory=lambda: QColor(QColorConstants.LightGray)
|
||||
)
|
||||
reference: QColor = field(default_factory=lambda: QColor(0, 0, 255, 64))
|
||||
reference_secondary: QColor = field(
|
||||
default_factory=lambda: QColor(0, 0, 192, 48)
|
||||
)
|
||||
sweep: QColor = field(
|
||||
default_factory=lambda: QColor(QColorConstants.DarkYellow)
|
||||
)
|
||||
sweep_secondary: QColor = field(
|
||||
default_factory=lambda: QColor(QColorConstants.DarkMagenta)
|
||||
)
|
||||
swr: QColor = field(default_factory=lambda: QColor(255, 0, 0, 128))
|
||||
text: QColor = field(default_factory=lambda: QColor(QColorConstants.Black))
|
||||
bands: QColor = field(default_factory=lambda: QColor(128, 128, 128, 48))
|
||||
|
||||
|
||||
@dataclass
|
||||
class ChartDimensions:
|
||||
height: int = 200
|
||||
height_min: int = 200
|
||||
width: int = 200
|
||||
width_min: int = 200
|
||||
line: int = 1
|
||||
point: int = 2
|
||||
|
||||
|
||||
@dataclass
|
||||
class ChartDragBox:
|
||||
pos: tuple[int] = (-1, -1)
|
||||
pos_start: tuple[int] = (0, 0)
|
||||
state: bool = False
|
||||
move_x: int = -1
|
||||
move_y: int = -1
|
||||
|
||||
|
||||
@dataclass
|
||||
class ChartFlags:
|
||||
draw_lines: bool = False
|
||||
is_popout: bool = False
|
||||
|
||||
|
||||
class ChartMarker(QtWidgets.QWidget):
|
||||
def __init__(self, qp: QtGui.QPaintDevice):
|
||||
super().__init__()
|
||||
self.qp = qp
|
||||
|
||||
def draw(self, x: int, y: int, color: QtGui.QColor, text: str = ""):
|
||||
offset = int(Defaults.cfg.chart.marker_size // 2)
|
||||
if Defaults.cfg.chart.marker_at_tip:
|
||||
y -= offset
|
||||
pen = QtGui.QPen(color)
|
||||
self.qp.setPen(pen)
|
||||
qpp = QtGui.QPainterPath()
|
||||
qpp.moveTo(x, y + offset)
|
||||
qpp.lineTo(x - offset, y - offset)
|
||||
qpp.lineTo(x + offset, y - offset)
|
||||
qpp.lineTo(x, y + offset)
|
||||
|
||||
if Defaults.cfg.chart.marker_filled:
|
||||
self.qp.fillPath(qpp, color)
|
||||
else:
|
||||
self.qp.drawPath(qpp)
|
||||
|
||||
if text and Defaults.cfg.chart.marker_label:
|
||||
text_width = self.qp.fontMetrics().horizontalAdvance(text)
|
||||
self.qp.drawText(x - int(text_width // 2), y - 3 - offset, text)
|
||||
|
||||
|
||||
class Chart(QtWidgets.QWidget):
|
||||
bands: ClassVar[Any] = None
|
||||
popoutRequested: ClassVar[Any] = pyqtSignal(object)
|
||||
color: ClassVar[ChartColors] = ChartColors()
|
||||
|
||||
def __init__(self, name):
|
||||
super().__init__()
|
||||
self.name = name
|
||||
self.sweepTitle = ""
|
||||
|
||||
self.leftMargin = 30
|
||||
self.rightMargin = 20
|
||||
self.bottomMargin = 20
|
||||
self.topMargin = 30
|
||||
|
||||
self.dim = ChartDimensions()
|
||||
self.dragbox = ChartDragBox()
|
||||
self.flag = ChartFlags()
|
||||
|
||||
self.draggedMarker = None
|
||||
|
||||
self.data: list[Datapoint] = []
|
||||
self.reference: list[Datapoint] = []
|
||||
|
||||
self.markers: list[Marker] = []
|
||||
self.swrMarkers: set[float] = set()
|
||||
|
||||
self.action_popout = QAction("Popout chart")
|
||||
self.action_popout.triggered.connect(
|
||||
lambda: self.popoutRequested.emit(self)
|
||||
)
|
||||
self.addAction(self.action_popout)
|
||||
|
||||
self.action_save_screenshot = QAction("Save image")
|
||||
self.action_save_screenshot.triggered.connect(self.saveScreenshot)
|
||||
self.addAction(self.action_save_screenshot)
|
||||
|
||||
self.setContextMenuPolicy(Qt.ContextMenuPolicy.ActionsContextMenu)
|
||||
|
||||
def setReference(self, data):
|
||||
self.reference = data
|
||||
self.update()
|
||||
|
||||
def resetReference(self):
|
||||
self.reference = []
|
||||
self.update()
|
||||
|
||||
def setData(self, data):
|
||||
self.data = data
|
||||
self.update()
|
||||
|
||||
def setMarkers(self, markers):
|
||||
self.markers = markers
|
||||
|
||||
def setBands(self, bands):
|
||||
self.bands = bands
|
||||
|
||||
def setLineThickness(self, thickness):
|
||||
self.dim.line = thickness
|
||||
self.update()
|
||||
|
||||
def setPointSize(self, size):
|
||||
self.dim.point = size
|
||||
self.update()
|
||||
|
||||
def setMarkerSize(self, size):
|
||||
Defaults.cfg.chart.marker_size = size
|
||||
self.update()
|
||||
|
||||
def setSweepTitle(self, title):
|
||||
self.sweepTitle = title
|
||||
self.update()
|
||||
|
||||
def getActiveMarker(self) -> Marker:
|
||||
if self.draggedMarker is not None:
|
||||
return self.draggedMarker
|
||||
return next(
|
||||
(
|
||||
m
|
||||
for m in self.markers
|
||||
if m.isMouseControlledRadioButton.isChecked()
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
def getNearestMarker(self, x, y) -> Marker | None:
|
||||
if not self.data:
|
||||
return None
|
||||
shortest = 10**6
|
||||
nearest = None
|
||||
for m in self.markers:
|
||||
mx, my = self.getPosition(self.data[m.location])
|
||||
distance = abs(complex(x - mx, y - my))
|
||||
if distance < shortest:
|
||||
shortest = distance
|
||||
nearest = m
|
||||
return nearest
|
||||
|
||||
def getPosition(self, d: Datapoint) -> tuple[int, int]:
|
||||
return self.getXPosition(d), self.getYPosition(d)
|
||||
|
||||
def setDrawLines(self, draw_lines):
|
||||
self.flag.draw_lines = draw_lines
|
||||
self.update()
|
||||
|
||||
def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
|
||||
if event.buttons() == Qt.MouseButton.RightButton:
|
||||
event.ignore()
|
||||
return
|
||||
if event.buttons() == Qt.MouseButton.MiddleButton:
|
||||
# Drag event
|
||||
event.accept()
|
||||
self.dragbox.move_x = event.position().x()
|
||||
self.dragbox.move_y = event.position().y()
|
||||
return
|
||||
if event.modifiers() == Qt.KeyboardModifier.ControlModifier:
|
||||
event.accept()
|
||||
self.dragbox.state = True
|
||||
self.dragbox.pos_start = (
|
||||
event.position().x(),
|
||||
event.position().y(),
|
||||
)
|
||||
return
|
||||
if event.modifiers() == Qt.KeyboardModifier.ShiftModifier:
|
||||
self.draggedMarker = self.getNearestMarker(
|
||||
event.position().x(), event.position().y()
|
||||
)
|
||||
self.mouseMoveEvent(event)
|
||||
|
||||
def mouseReleaseEvent(self, a0: QtGui.QMouseEvent):
|
||||
self.draggedMarker = None
|
||||
if self.dragbox.state:
|
||||
self.zoomTo(
|
||||
self.dragbox.pos_start[0],
|
||||
self.dragbox.pos_start[1],
|
||||
a0.position().x(),
|
||||
a0.position().y(),
|
||||
)
|
||||
self.dragbox.state = False
|
||||
self.dragbox.pos = (-1, -1)
|
||||
self.dragbox.pos_start = (0, 0)
|
||||
self.update()
|
||||
|
||||
def wheelEvent(self, a0: QtGui.QWheelEvent) -> None:
|
||||
delta = a0.angleDelta().y()
|
||||
if not delta or (not self.data and not self.reference):
|
||||
a0.ignore()
|
||||
return
|
||||
modifiers = a0.modifiers()
|
||||
|
||||
zoom_x = modifiers != Qt.KeyboardModifier.ShiftModifier
|
||||
zoom_y = modifiers != Qt.KeyboardModifier.ControlModifier
|
||||
rate = -delta / 120
|
||||
# zooming in 10% increments and 9% complementary
|
||||
divisor = 10 if delta > 0 else 9
|
||||
|
||||
factor_x = rate * self.dim.width / divisor if zoom_x else 0
|
||||
factor_y = rate * self.dim.height / divisor if zoom_y else 0
|
||||
|
||||
abs_x = max(0, a0.position().x() - self.leftMargin)
|
||||
abs_y = max(0, a0.position().y() - self.topMargin)
|
||||
|
||||
ratio_x = abs_x / self.dim.width
|
||||
ratio_y = abs_y / self.dim.height
|
||||
|
||||
self.zoomTo(
|
||||
int(self.leftMargin + ratio_x * factor_x),
|
||||
int(self.topMargin + ratio_y * factor_y),
|
||||
int(self.leftMargin + self.dim.width - (1 - ratio_x) * factor_x),
|
||||
int(self.topMargin + self.dim.height - (1 - ratio_y) * factor_y),
|
||||
)
|
||||
a0.accept()
|
||||
|
||||
def zoomTo(self, x1, y1, x2, y2):
|
||||
raise NotImplementedError()
|
||||
|
||||
def saveScreenshot(self):
|
||||
logger.info("Saving %s to file...", self.name)
|
||||
filename, _ = QtWidgets.QFileDialog.getSaveFileName(
|
||||
parent=self,
|
||||
caption="Save image",
|
||||
filter="PNG (*.png);;All files (*.*)",
|
||||
)
|
||||
|
||||
logger.debug("Filename: %s", filename)
|
||||
if not filename:
|
||||
return
|
||||
if not QtCore.QFileInfo(filename).suffix():
|
||||
filename += ".png"
|
||||
self.grab().save(filename)
|
||||
|
||||
def copy(self):
|
||||
new_chart = self.__class__(self.name)
|
||||
new_chart.data = self.data
|
||||
new_chart.reference = self.reference
|
||||
new_chart.dim = replace(self.dim)
|
||||
new_chart.flag = replace(self.flag)
|
||||
new_chart.markers = self.markers
|
||||
new_chart.swrMarkers = self.swrMarkers
|
||||
new_chart.bands = self.bands
|
||||
|
||||
new_chart.resize(self.width(), self.height())
|
||||
new_chart.setPointSize(self.dim.point)
|
||||
new_chart.setLineThickness(self.dim.line)
|
||||
return new_chart
|
||||
|
||||
def addSWRMarker(self, swr: float):
|
||||
self.swrMarkers.add(swr)
|
||||
self.update()
|
||||
|
||||
def removeSWRMarker(self, swr: float):
|
||||
try:
|
||||
self.swrMarkers.remove(swr)
|
||||
except KeyError:
|
||||
logger.debug("KeyError from %s", self.name)
|
||||
finally:
|
||||
self.update()
|
||||
|
||||
def clearSWRMarkers(self):
|
||||
self.swrMarkers.clear()
|
||||
self.update()
|
||||
|
||||
@staticmethod
|
||||
def drawMarker(
|
||||
x: int, y: int, qp: QtGui.QPainter, color: QtGui.QColor, number: int = 0
|
||||
):
|
||||
cmarker = ChartMarker(qp)
|
||||
cmarker.draw(x, y, color, f"{number}")
|
||||
|
||||
def drawTitle(self, qp: QtGui.QPainter, position: QtCore.QPoint = None):
|
||||
qp.setPen(Chart.color.text)
|
||||
if position is None:
|
||||
qf = QtGui.QFontMetricsF(self.font())
|
||||
width = qf.boundingRect(self.sweepTitle).width()
|
||||
position = QtCore.QPointF(self.width() / 2 - width / 2, 15)
|
||||
qp.drawText(position, self.sweepTitle)
|
||||
|
||||
def update(self):
|
||||
pal = self.palette()
|
||||
pal.setColor(QtGui.QPalette.ColorRole.Window, Chart.color.background)
|
||||
self.setPalette(pal)
|
||||
super().update()
|
|
@ -1,818 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
import numpy as np
|
||||
from PyQt6 import QtWidgets, QtGui, QtCore
|
||||
from PyQt6.QtCore import Qt
|
||||
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Formatting import (
|
||||
parse_frequency,
|
||||
parse_value,
|
||||
format_frequency_chart,
|
||||
format_frequency_chart_2,
|
||||
format_y_axis,
|
||||
)
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.SITools import Format, Value
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FrequencyChart(Chart):
|
||||
def __init__(self, name):
|
||||
super().__init__(name)
|
||||
self.maxFrequency = 100000000
|
||||
self.minFrequency = 1000000
|
||||
self.fixedSpan = False
|
||||
self.fixedValues = False
|
||||
self.logarithmicX = False
|
||||
self.logarithmicY = False
|
||||
|
||||
self.leftMargin = 30
|
||||
self.rightMargin = 20
|
||||
self.bottomMargin = 20
|
||||
self.topMargin = 30
|
||||
|
||||
self.dim.width = 250
|
||||
self.dim.height = 250
|
||||
self.fstart = 0
|
||||
self.fstop = 0
|
||||
|
||||
self.name_unit = ""
|
||||
self.value_function = lambda x: 0.0
|
||||
|
||||
# TODO: use unscaled values instead of unit dependend ones
|
||||
self.minDisplayValue = -1
|
||||
self.maxDisplayValue = 1
|
||||
|
||||
self.minValue = -1
|
||||
self.maxValue = 1
|
||||
self.span = 1
|
||||
|
||||
self.setContextMenuPolicy(Qt.ContextMenuPolicy.DefaultContextMenu)
|
||||
mode_group = QtGui.QActionGroup(self)
|
||||
self.menu = QtWidgets.QMenu()
|
||||
|
||||
self.reset = QtGui.QAction("Reset")
|
||||
self.reset.triggered.connect(self.resetDisplayLimits)
|
||||
self.menu.addAction(self.reset)
|
||||
|
||||
self.x_menu = QtWidgets.QMenu("Frequency axis")
|
||||
self.action_automatic = QtGui.QAction("Automatic")
|
||||
self.action_automatic.setCheckable(True)
|
||||
self.action_automatic.setChecked(True)
|
||||
self.action_automatic.changed.connect(
|
||||
lambda: self.setFixedSpan(self.action_fixed_span.isChecked())
|
||||
)
|
||||
self.action_fixed_span = QtGui.QAction("Fixed span")
|
||||
self.action_fixed_span.setCheckable(True)
|
||||
self.action_fixed_span.changed.connect(
|
||||
lambda: self.setFixedSpan(self.action_fixed_span.isChecked())
|
||||
)
|
||||
mode_group.addAction(self.action_automatic)
|
||||
mode_group.addAction(self.action_fixed_span)
|
||||
self.x_menu.addAction(self.action_automatic)
|
||||
self.x_menu.addAction(self.action_fixed_span)
|
||||
self.x_menu.addSeparator()
|
||||
|
||||
self.action_set_fixed_start = QtGui.QAction(
|
||||
f"Start ({format_frequency_chart(self.minFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_start.triggered.connect(self.setMinimumFrequency)
|
||||
|
||||
self.action_set_fixed_stop = QtGui.QAction(
|
||||
f"Stop ({format_frequency_chart(self.maxFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_stop.triggered.connect(self.setMaximumFrequency)
|
||||
|
||||
self.x_menu.addAction(self.action_set_fixed_start)
|
||||
self.x_menu.addAction(self.action_set_fixed_stop)
|
||||
|
||||
self.x_menu.addSeparator()
|
||||
frequency_mode_group = QtGui.QActionGroup(self.x_menu)
|
||||
self.action_set_linear_x = QtGui.QAction("Linear")
|
||||
self.action_set_linear_x.setCheckable(True)
|
||||
self.action_set_logarithmic_x = QtGui.QAction("Logarithmic")
|
||||
self.action_set_logarithmic_x.setCheckable(True)
|
||||
frequency_mode_group.addAction(self.action_set_linear_x)
|
||||
frequency_mode_group.addAction(self.action_set_logarithmic_x)
|
||||
self.action_set_linear_x.triggered.connect(
|
||||
lambda: self.setLogarithmicX(False)
|
||||
)
|
||||
self.action_set_logarithmic_x.triggered.connect(
|
||||
lambda: self.setLogarithmicX(True)
|
||||
)
|
||||
self.action_set_linear_x.setChecked(True)
|
||||
self.x_menu.addAction(self.action_set_linear_x)
|
||||
self.x_menu.addAction(self.action_set_logarithmic_x)
|
||||
|
||||
self.y_menu = QtWidgets.QMenu("Data axis")
|
||||
self.y_action_automatic = QtGui.QAction("Automatic")
|
||||
self.y_action_automatic.setCheckable(True)
|
||||
self.y_action_automatic.setChecked(True)
|
||||
self.y_action_automatic.changed.connect(
|
||||
lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())
|
||||
)
|
||||
self.y_action_fixed_span = QtGui.QAction("Fixed span")
|
||||
self.y_action_fixed_span.setCheckable(True)
|
||||
self.y_action_fixed_span.changed.connect(
|
||||
lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())
|
||||
)
|
||||
mode_group = QtGui.QActionGroup(self)
|
||||
mode_group.addAction(self.y_action_automatic)
|
||||
mode_group.addAction(self.y_action_fixed_span)
|
||||
self.y_menu.addAction(self.y_action_automatic)
|
||||
self.y_menu.addAction(self.y_action_fixed_span)
|
||||
self.y_menu.addSeparator()
|
||||
|
||||
self.action_set_fixed_minimum = QtGui.QAction(
|
||||
f"Minimum ({self.minDisplayValue})"
|
||||
)
|
||||
self.action_set_fixed_minimum.triggered.connect(self.setMinimumValue)
|
||||
|
||||
self.action_set_fixed_maximum = QtGui.QAction(
|
||||
f"Maximum ({self.maxDisplayValue})"
|
||||
)
|
||||
self.action_set_fixed_maximum.triggered.connect(self.setMaximumValue)
|
||||
|
||||
self.y_menu.addAction(self.action_set_fixed_maximum)
|
||||
self.y_menu.addAction(self.action_set_fixed_minimum)
|
||||
|
||||
if self.logarithmicYAllowed(): # This only works for some plot types
|
||||
self.y_menu.addSeparator()
|
||||
vertical_mode_group = QtGui.QActionGroup(self.y_menu)
|
||||
self.action_set_linear_y = QtGui.QAction("Linear")
|
||||
self.action_set_linear_y.setCheckable(True)
|
||||
self.action_set_logarithmic_y = QtGui.QAction("Logarithmic")
|
||||
self.action_set_logarithmic_y.setCheckable(True)
|
||||
vertical_mode_group.addAction(self.action_set_linear_y)
|
||||
vertical_mode_group.addAction(self.action_set_logarithmic_y)
|
||||
self.action_set_linear_y.triggered.connect(
|
||||
lambda: self.setLogarithmicY(False)
|
||||
)
|
||||
self.action_set_logarithmic_y.triggered.connect(
|
||||
lambda: self.setLogarithmicY(True)
|
||||
)
|
||||
self.action_set_linear_y.setChecked(True)
|
||||
self.y_menu.addAction(self.action_set_linear_y)
|
||||
self.y_menu.addAction(self.action_set_logarithmic_y)
|
||||
|
||||
self.menu.addMenu(self.x_menu)
|
||||
self.menu.addMenu(self.y_menu)
|
||||
self.menu.addSeparator()
|
||||
self.menu.addAction(self.action_save_screenshot)
|
||||
self.action_popout = QtGui.QAction("Popout chart")
|
||||
self.action_popout.triggered.connect(
|
||||
lambda: self.popoutRequested.emit(self)
|
||||
)
|
||||
self.menu.addAction(self.action_popout)
|
||||
self.setFocusPolicy(Qt.FocusPolicy.ClickFocus)
|
||||
|
||||
self.setMinimumSize(
|
||||
self.dim.width + self.rightMargin + self.leftMargin,
|
||||
self.dim.height + self.topMargin + self.bottomMargin,
|
||||
)
|
||||
self.setSizePolicy(
|
||||
QtWidgets.QSizePolicy(
|
||||
QtWidgets.QSizePolicy.Policy.MinimumExpanding,
|
||||
QtWidgets.QSizePolicy.Policy.MinimumExpanding,
|
||||
)
|
||||
)
|
||||
pal = QtGui.QPalette()
|
||||
pal.setColor(QtGui.QPalette.ColorRole.Window, Chart.color.background)
|
||||
self.setPalette(pal)
|
||||
self.setAutoFillBackground(True)
|
||||
|
||||
def _set_start_stop(self):
|
||||
if self.fixedSpan:
|
||||
self.fstart = self.minFrequency
|
||||
self.fstop = self.maxFrequency
|
||||
return
|
||||
if self.data:
|
||||
self.fstart = self.data[0].freq
|
||||
self.fstop = self.data[len(self.data) - 1].freq
|
||||
return
|
||||
self.fstart = self.reference[0].freq
|
||||
self.fstop = self.reference[len(self.reference) - 1].freq
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
self.action_set_fixed_start.setText(
|
||||
f"Start ({format_frequency_chart(self.minFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_stop.setText(
|
||||
f"Stop ({format_frequency_chart(self.maxFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_minimum.setText(
|
||||
f"Minimum ({self.minDisplayValue})"
|
||||
)
|
||||
self.action_set_fixed_maximum.setText(
|
||||
f"Maximum ({self.maxDisplayValue})"
|
||||
)
|
||||
|
||||
if self.fixedSpan:
|
||||
self.action_fixed_span.setChecked(True)
|
||||
else:
|
||||
self.action_automatic.setChecked(True)
|
||||
|
||||
if self.fixedValues:
|
||||
self.y_action_fixed_span.setChecked(True)
|
||||
else:
|
||||
self.y_action_automatic.setChecked(True)
|
||||
|
||||
self.menu.exec(event.globalPos())
|
||||
|
||||
def setFixedSpan(self, fixed_span: bool):
|
||||
self.fixedSpan = fixed_span
|
||||
if fixed_span and self.minFrequency >= self.maxFrequency:
|
||||
self.fixedSpan = False
|
||||
self.action_automatic.setChecked(True)
|
||||
self.action_fixed_span.setChecked(False)
|
||||
self.update()
|
||||
|
||||
def setFixedValues(self, fixed_values: bool):
|
||||
self.fixedValues = fixed_values
|
||||
self.update()
|
||||
|
||||
def setLogarithmicX(self, logarithmic: bool):
|
||||
self.logarithmicX = logarithmic
|
||||
self.update()
|
||||
|
||||
def setLogarithmicY(self, logarithmic: bool):
|
||||
self.logarithmicY = logarithmic and self.logarithmicYAllowed()
|
||||
self.update()
|
||||
|
||||
def logarithmicYAllowed(self) -> bool:
|
||||
return False
|
||||
|
||||
def setMinimumFrequency(self):
|
||||
min_freq_str, selected = QtWidgets.QInputDialog.getText(
|
||||
self,
|
||||
"Start frequency",
|
||||
"Set start frequency",
|
||||
text=str(self.minFrequency),
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
span = abs(self.maxFrequency - self.minFrequency)
|
||||
min_freq = parse_frequency(min_freq_str)
|
||||
if min_freq < 0:
|
||||
return
|
||||
self.minFrequency = min_freq
|
||||
if self.minFrequency >= self.maxFrequency:
|
||||
self.maxFrequency = self.minFrequency + span
|
||||
self.fixedSpan = True
|
||||
self.update()
|
||||
|
||||
def setMaximumFrequency(self):
|
||||
max_freq_str, selected = QtWidgets.QInputDialog.getText(
|
||||
self,
|
||||
"Stop frequency",
|
||||
"Set stop frequency",
|
||||
text=str(self.maxFrequency),
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
span = abs(self.maxFrequency - self.minFrequency)
|
||||
max_freq = parse_frequency(max_freq_str)
|
||||
if max_freq < 0:
|
||||
return
|
||||
self.maxFrequency = max_freq
|
||||
if self.maxFrequency <= self.minFrequency:
|
||||
self.minFrequency = max(self.maxFrequency - span, 0)
|
||||
self.fixedSpan = True
|
||||
self.update()
|
||||
|
||||
def setMinimumValue(self):
|
||||
text, selected = QtWidgets.QInputDialog.getText(
|
||||
self,
|
||||
"Minimum value",
|
||||
"Set minimum value",
|
||||
text=format_y_axis(self.minDisplayValue, self.name_unit),
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
text = text.replace("dB", "")
|
||||
min_val = parse_value(text)
|
||||
yspan = abs(self.maxDisplayValue - self.minDisplayValue)
|
||||
self.minDisplayValue = min_val
|
||||
if self.minDisplayValue >= self.maxDisplayValue:
|
||||
self.maxDisplayValue = self.minDisplayValue + yspan
|
||||
# TODO: negativ logarythmical scale
|
||||
# if self.logarithmicY and min_val <= 0:
|
||||
# self.minDisplayValue = 0.01
|
||||
self.fixedValues = True
|
||||
self.update()
|
||||
|
||||
def setMaximumValue(self):
|
||||
text, selected = QtWidgets.QInputDialog.getText(
|
||||
self,
|
||||
"Maximum value",
|
||||
"Set maximum value",
|
||||
text=format_y_axis(self.maxDisplayValue, self.name_unit),
|
||||
)
|
||||
text = text.replace("dB", "")
|
||||
if not selected:
|
||||
return
|
||||
max_val = parse_value(text)
|
||||
yspan = abs(self.maxDisplayValue - self.minDisplayValue)
|
||||
self.maxDisplayValue = max_val
|
||||
if self.maxDisplayValue <= self.minDisplayValue:
|
||||
self.minDisplayValue = self.maxDisplayValue - yspan
|
||||
self.fixedValues = True
|
||||
self.update()
|
||||
|
||||
def resetDisplayLimits(self):
|
||||
self.fixedValues = False
|
||||
self.y_action_automatic.setChecked(True)
|
||||
self.fixedSpan = False
|
||||
self.action_automatic.setChecked(True)
|
||||
self.logarithmicX = False
|
||||
self.action_set_linear_x.setChecked(True)
|
||||
self.logarithmicY = False
|
||||
if self.logarithmicYAllowed():
|
||||
self.action_set_linear_y.setChecked(True)
|
||||
self.update()
|
||||
|
||||
def getXPosition(self, d: Datapoint) -> int:
|
||||
span = self.fstop - self.fstart
|
||||
if span > 0:
|
||||
if self.logarithmicX:
|
||||
span = math.log(self.fstop) - math.log(self.fstart)
|
||||
return self.leftMargin + round(
|
||||
self.dim.width
|
||||
* (math.log(d.freq) - math.log(self.fstart))
|
||||
/ span
|
||||
)
|
||||
return self.leftMargin + round(
|
||||
self.dim.width * (d.freq - self.fstart) / span
|
||||
)
|
||||
return math.floor(self.width() / 2)
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
try:
|
||||
return self.topMargin + round(
|
||||
(self.maxValue - self.value_function(d))
|
||||
/ self.span
|
||||
* self.dim.height
|
||||
)
|
||||
except ValueError:
|
||||
return self.topMargin
|
||||
|
||||
def frequencyAtPosition(self, x, limit=True) -> int:
|
||||
"""
|
||||
Calculates the frequency at a given X-position
|
||||
:param limit: Determines whether frequencies outside the
|
||||
currently displayed span can be returned.
|
||||
:param x: The X position to calculate for.
|
||||
:return: The frequency at the given position, if one
|
||||
exists or -1 otherwise. If limit is True,
|
||||
and the value is before or after the chart,
|
||||
returns minimum or maximum frequencies.
|
||||
"""
|
||||
if self.fstop - self.fstart <= 0:
|
||||
return -1
|
||||
absx = x - self.leftMargin
|
||||
if limit:
|
||||
if absx < 0:
|
||||
return self.fstart
|
||||
if absx > self.dim.width:
|
||||
return self.fstop
|
||||
if self.logarithmicX:
|
||||
span = math.log(self.fstop) - math.log(self.fstart)
|
||||
step = span / self.dim.width
|
||||
return round(math.exp(math.log(self.fstart) + absx * step))
|
||||
span = self.fstop - self.fstart
|
||||
step = span / self.dim.width
|
||||
return round(self.fstart + absx * step)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
"""
|
||||
Returns the chart-specific value(s) at the specified Y-position
|
||||
:param y: The Y position to calculate for.
|
||||
:return: A list of the values at the Y-position, either
|
||||
containing a single value, or the two values for the
|
||||
chart from left to right Y-axis. If no value can be
|
||||
found, returns the empty list. If the frequency
|
||||
is above or below the chart, returns maximum
|
||||
or minimum values.
|
||||
"""
|
||||
absy = y - self.topMargin
|
||||
val = -1 * ((absy / self.dim.height * self.span) - self.maxValue)
|
||||
return [val * 10e11]
|
||||
|
||||
def zoomTo(self, x1, y1, x2, y2):
|
||||
val1 = self.valueAtPosition(y1)
|
||||
val2 = self.valueAtPosition(y2)
|
||||
|
||||
if len(val1) == len(val2) == 1 and val1[0] != val2[0]:
|
||||
self.minDisplayValue = round(min(val1[0], val2[0]), 3)
|
||||
self.maxDisplayValue = round(max(val1[0], val2[0]), 3)
|
||||
self.setFixedValues(True)
|
||||
|
||||
freq1 = max(1, self.frequencyAtPosition(x1, limit=False))
|
||||
freq2 = max(1, self.frequencyAtPosition(x2, limit=False))
|
||||
|
||||
if freq1 > 0 and freq2 > 0 and freq1 != freq2:
|
||||
self.minFrequency = min(freq1, freq2)
|
||||
self.maxFrequency = max(freq1, freq2)
|
||||
self.setFixedSpan(True)
|
||||
|
||||
self.update()
|
||||
|
||||
def mouseMoveEvent(self, a0: QtGui.QMouseEvent):
|
||||
if a0.buttons() == Qt.MouseButton.RightButton:
|
||||
a0.ignore()
|
||||
return
|
||||
if a0.buttons() == Qt.MouseButton.MiddleButton:
|
||||
# Drag the display
|
||||
a0.accept()
|
||||
if self.dragbox.move_x != -1 and self.dragbox.move_y != -1:
|
||||
dx = self.dragbox.move_x - a0.position().x()
|
||||
dy = self.dragbox.move_y - a0.position().y()
|
||||
self.zoomTo(
|
||||
self.leftMargin + dx,
|
||||
self.topMargin + dy,
|
||||
self.leftMargin + self.dim.width + dx,
|
||||
self.topMargin + self.dim.height + dy,
|
||||
)
|
||||
|
||||
self.dragbox.move_x = a0.position().x()
|
||||
self.dragbox.move_y = a0.position().y()
|
||||
return
|
||||
if a0.modifiers() == Qt.KeyboardModifier.ControlModifier:
|
||||
# Dragging a box
|
||||
if not self.dragbox.state:
|
||||
self.dragbox.pos_start = (a0.position().x(), a0.position().y())
|
||||
self.dragbox.pos = (a0.position().x(), a0.position().y())
|
||||
self.update()
|
||||
a0.accept()
|
||||
return
|
||||
x = a0.position().x()
|
||||
f = self.frequencyAtPosition(x)
|
||||
if x == -1:
|
||||
a0.ignore()
|
||||
return
|
||||
a0.accept()
|
||||
m = self.getActiveMarker()
|
||||
if m is not None:
|
||||
m.setFrequency(str(f))
|
||||
|
||||
def resizeEvent(self, a0: QtGui.QResizeEvent) -> None:
|
||||
self.dim.width = a0.size().width() - self.rightMargin - self.leftMargin
|
||||
self.dim.height = (
|
||||
a0.size().height() - self.bottomMargin - self.topMargin
|
||||
)
|
||||
self.update()
|
||||
|
||||
def paintEvent(self, _: QtGui.QPaintEvent) -> None:
|
||||
qp = QtGui.QPainter(self)
|
||||
self.drawChart(qp)
|
||||
self.drawValues(qp)
|
||||
self._check_frequency_boundaries(qp)
|
||||
if self.dragbox.state and self.dragbox.pos[0] != -1:
|
||||
self.drawDragbog(qp)
|
||||
qp.end()
|
||||
|
||||
def _data_oob(self, data: list[Datapoint]) -> bool:
|
||||
return data[0].freq > self.fstop or self.data[-1].freq < self.fstart
|
||||
|
||||
def _check_frequency_boundaries(self, qp: QtGui.QPainter):
|
||||
if (
|
||||
self.data
|
||||
and self._data_oob(self.data)
|
||||
and (not self.reference or self._data_oob(self.reference))
|
||||
):
|
||||
# Data outside frequency range
|
||||
qp.setBackgroundMode(Qt.BGMode.OpaqueMode)
|
||||
qp.setBackground(Chart.color.background)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(
|
||||
self.leftMargin + int(self.dim.width // 2) - 70,
|
||||
self.topMargin + int(self.dim.height // 2) - 20,
|
||||
"Data outside frequency span",
|
||||
)
|
||||
|
||||
def drawDragbog(self, qp: QtGui.QPainter):
|
||||
dashed_pen = QtGui.QPen(Chart.color.foreground, 1, Qt.PenStyle.DashLine)
|
||||
qp.setPen(dashed_pen)
|
||||
top_left = QtCore.QPoint(
|
||||
self.dragbox.pos_start[0], self.dragbox.pos_start[1]
|
||||
)
|
||||
bottom_right = QtCore.QPoint(self.dragbox.pos[0], self.dragbox.pos[1])
|
||||
rect = QtCore.QRect(top_left, bottom_right)
|
||||
qp.drawRect(rect)
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
headline = self.name
|
||||
if self.name_unit:
|
||||
headline += f" ({self.name_unit})"
|
||||
qp.drawText(3, 15, headline)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin,
|
||||
20,
|
||||
self.leftMargin,
|
||||
self.topMargin + self.dim.height + 5,
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin + self.dim.height,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin + self.dim.height,
|
||||
)
|
||||
self.drawTitle(qp)
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if len(self.data) == 0 and len(self.reference) == 0:
|
||||
return
|
||||
pen = QtGui.QPen(Chart.color.sweep)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(Chart.color.sweep)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255))
|
||||
highlighter.setWidth(1)
|
||||
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
min_value, max_value = self._find_scaling()
|
||||
self.maxValue = max_value
|
||||
self.minValue = min_value
|
||||
span = max_value - min_value
|
||||
if span == 0:
|
||||
logger.info(
|
||||
"Span is zero for %s-Chart, setting to a small value.",
|
||||
self.name,
|
||||
)
|
||||
span = 1e-15
|
||||
self.span = span
|
||||
|
||||
target_ticks = math.floor(self.dim.height / 60)
|
||||
fmt = Format(max_nr_digits=1)
|
||||
for i in range(target_ticks):
|
||||
val = min_value + (i / target_ticks) * span
|
||||
y = self.topMargin + round(
|
||||
(self.maxValue - val) / self.span * self.dim.height
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
if val != min_value:
|
||||
valstr = str(Value(val, fmt=fmt))
|
||||
qp.drawText(3, y + 3, valstr)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
|
||||
)
|
||||
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin,
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(3, self.topMargin + 4, str(Value(max_value, fmt=fmt)))
|
||||
qp.drawText(
|
||||
3, self.dim.height + self.topMargin, str(Value(min_value, fmt=fmt))
|
||||
)
|
||||
self.drawFrequencyTicks(qp)
|
||||
|
||||
self.drawData(qp, self.data, Chart.color.sweep)
|
||||
self.drawData(qp, self.reference, Chart.color.reference)
|
||||
self.drawMarkers(qp)
|
||||
|
||||
def _find_scaling(self) -> tuple[float, float]:
|
||||
min_value = self.minDisplayValue / 10e11
|
||||
max_value = self.maxDisplayValue / 10e11
|
||||
if self.fixedValues:
|
||||
return (min_value, max_value)
|
||||
for d in self.data:
|
||||
val = self.value_function(d)
|
||||
min_value = min(min_value, val)
|
||||
max_value = max(max_value, val)
|
||||
for d in self.reference: # Also check min/max for the reference sweep
|
||||
if d.freq < self.fstart or d.freq > self.fstop:
|
||||
continue
|
||||
val = self.value_function(d)
|
||||
min_value = min(min_value, val)
|
||||
max_value = max(max_value, val)
|
||||
return (min_value, max_value)
|
||||
|
||||
def drawFrequencyTicks(self, qp):
|
||||
fspan = self.fstop - self.fstart
|
||||
qp.setPen(Chart.color.text)
|
||||
# Number of ticks does not include the origin
|
||||
ticks = math.floor(self.dim.width / 100)
|
||||
|
||||
# try to adapt format to span
|
||||
if self.fstart == 0 or int(fspan / ticks / self.fstart * 10000) > 2:
|
||||
my_format_frequency = format_frequency_chart
|
||||
else:
|
||||
my_format_frequency = format_frequency_chart_2
|
||||
|
||||
qp.drawText(
|
||||
self.leftMargin - 20,
|
||||
self.topMargin + self.dim.height + 15,
|
||||
my_format_frequency(self.fstart),
|
||||
)
|
||||
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i + 1) * self.dim.width / ticks)
|
||||
if self.logarithmicX:
|
||||
fspan = math.log(self.fstop) - math.log(self.fstart)
|
||||
freq = round(
|
||||
math.exp(((i + 1) * fspan / ticks) + math.log(self.fstart))
|
||||
)
|
||||
else:
|
||||
freq = round(fspan / ticks * (i + 1) + self.fstart)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
x, self.topMargin, x, self.topMargin + self.dim.height + 5
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(
|
||||
x - 20,
|
||||
self.topMargin + self.dim.height + 15,
|
||||
my_format_frequency(freq),
|
||||
)
|
||||
|
||||
def drawBands(self, qp, fstart, fstop):
|
||||
qp.setBrush(self.bands.color)
|
||||
qp.setPen(QtGui.QColor(128, 128, 128, 0)) # Don't outline the bands
|
||||
for _, start, end in self.bands.bands:
|
||||
try:
|
||||
start = int(start)
|
||||
end = int(end)
|
||||
except ValueError:
|
||||
continue
|
||||
# don't draw if either band not in chart or completely in band
|
||||
if start < fstart < fstop < end or end < fstart or start > fstop:
|
||||
continue
|
||||
x_start = max(
|
||||
self.leftMargin + 1, self.getXPosition(Datapoint(start, 0, 0))
|
||||
)
|
||||
x_stop = min(
|
||||
self.leftMargin + self.dim.width,
|
||||
self.getXPosition(Datapoint(end, 0, 0)),
|
||||
)
|
||||
qp.drawRect(
|
||||
x_start, self.topMargin, x_stop - x_start, self.dim.height
|
||||
)
|
||||
|
||||
def drawData(
|
||||
self,
|
||||
qp: QtGui.QPainter,
|
||||
data: list[Datapoint],
|
||||
color: QtGui.QColor,
|
||||
y_function=None,
|
||||
):
|
||||
if y_function is None:
|
||||
y_function = self.getYPosition
|
||||
pen = QtGui.QPen(color)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(color)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
qp.setPen(pen)
|
||||
for i, d in enumerate(data):
|
||||
x = self.getXPosition(d)
|
||||
y = y_function(d)
|
||||
if y is None:
|
||||
continue
|
||||
if self.isPlotable(x, y):
|
||||
qp.drawPoint(int(x), int(y))
|
||||
if self.flag.draw_lines and i > 0:
|
||||
prevx = self.getXPosition(data[i - 1])
|
||||
prevy = y_function(data[i - 1])
|
||||
if prevy is None:
|
||||
continue
|
||||
qp.setPen(line_pen)
|
||||
if self.isPlotable(x, y):
|
||||
if self.isPlotable(prevx, prevy):
|
||||
qp.drawLine(x, y, prevx, prevy)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(x, y, prevx, prevy)
|
||||
qp.drawLine(x, y, new_x, new_y)
|
||||
elif self.isPlotable(prevx, prevy):
|
||||
new_x, new_y = self.getPlotable(prevx, prevy, x, y)
|
||||
qp.drawLine(prevx, prevy, new_x, new_y)
|
||||
qp.setPen(pen)
|
||||
|
||||
def drawMarkers(self, qp, data=None, y_function=None):
|
||||
if data is None:
|
||||
data = self.data
|
||||
if y_function is None:
|
||||
y_function = self.getYPosition
|
||||
highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255))
|
||||
highlighter.setWidth(1)
|
||||
for m in self.markers:
|
||||
if m.location != -1 and m.location < len(data):
|
||||
x = self.getXPosition(data[m.location])
|
||||
y = y_function(data[m.location])
|
||||
if self.isPlotable(x, y):
|
||||
self.drawMarker(
|
||||
x, y, qp, m.color, self.markers.index(m) + 1
|
||||
)
|
||||
|
||||
def isPlotable(self, x, y):
|
||||
return (
|
||||
y is not None
|
||||
and x is not None
|
||||
and self.leftMargin <= x <= self.leftMargin + self.dim.width
|
||||
and self.topMargin <= y <= self.topMargin + self.dim.height
|
||||
)
|
||||
|
||||
def getPlotable(self, x, y, distantx, distanty):
|
||||
p1 = np.array([x, y])
|
||||
p2 = np.array([distantx, distanty])
|
||||
# First check the top line
|
||||
if distanty < self.topMargin:
|
||||
p3 = np.array([self.leftMargin, self.topMargin])
|
||||
p4 = np.array([self.leftMargin + self.dim.width, self.topMargin])
|
||||
elif distanty > self.topMargin + self.dim.height:
|
||||
p3 = np.array([self.leftMargin, self.topMargin + self.dim.height])
|
||||
p4 = np.array(
|
||||
[
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin + self.dim.height,
|
||||
]
|
||||
)
|
||||
else:
|
||||
return x, y
|
||||
|
||||
da = p2 - p1
|
||||
db = p4 - p3
|
||||
dp = p1 - p3
|
||||
dap = np.array([-da[1], da[0]])
|
||||
denom = np.dot(dap, db)
|
||||
|
||||
if denom:
|
||||
x, y = ((np.dot(dap, dp) / denom.astype(float)) * db + p3)[:2]
|
||||
|
||||
return int(x), int(y)
|
||||
|
||||
def copy(self):
|
||||
new_chart = super().copy()
|
||||
new_chart.fstart = self.fstart
|
||||
new_chart.fstop = self.fstop
|
||||
new_chart.maxFrequency = self.maxFrequency
|
||||
new_chart.minFrequency = self.minFrequency
|
||||
new_chart.span = self.span
|
||||
new_chart.minDisplayValue = self.minDisplayValue
|
||||
new_chart.maxDisplayValue = self.maxDisplayValue
|
||||
new_chart.pointSize = self.dim.point
|
||||
new_chart.lineThickness = self.dim.line
|
||||
|
||||
new_chart.setFixedSpan(self.fixedSpan)
|
||||
new_chart.action_automatic.setChecked(not self.fixedSpan)
|
||||
new_chart.action_fixed_span.setChecked(self.fixedSpan)
|
||||
|
||||
new_chart.setFixedValues(self.fixedValues)
|
||||
new_chart.y_action_automatic.setChecked(not self.fixedValues)
|
||||
new_chart.y_action_fixed_span.setChecked(self.fixedValues)
|
||||
|
||||
new_chart.setLogarithmicX(self.logarithmicX)
|
||||
new_chart.action_set_logarithmic_x.setChecked(self.logarithmicX)
|
||||
new_chart.action_set_linear_x.setChecked(not self.logarithmicX)
|
||||
|
||||
new_chart.setLogarithmicY(self.logarithmicY)
|
||||
if self.logarithmicYAllowed():
|
||||
new_chart.action_set_logarithmic_y.setChecked(self.logarithmicY)
|
||||
new_chart.action_set_linear_y.setChecked(not self.logarithmicY)
|
||||
return new_chart
|
||||
|
||||
def keyPressEvent(self, a0: QtGui.QKeyEvent) -> None:
|
||||
m = self.getActiveMarker()
|
||||
if m is not None and a0.modifiers() == Qt.KeyboardModifier.NoModifier:
|
||||
if a0.key() in [Qt.Key.Key_Down, Qt.Key.Key_Left]:
|
||||
m.frequencyInput.keyPressEvent(
|
||||
QtGui.QKeyEvent(a0.type(), Qt.Key.Key_Down, a0.modifiers())
|
||||
)
|
||||
elif a0.key() in [Qt.Key.Key_Up, Qt.Key.Key_Right]:
|
||||
m.frequencyInput.keyPressEvent(
|
||||
QtGui.QKeyEvent(a0.type(), Qt.Key.Key_Up, a0.modifiers())
|
||||
)
|
||||
else:
|
||||
super().keyPressEvent(a0)
|
|
@ -1,221 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
import numpy as np
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from .Frequency import FrequencyChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GroupDelayChart(FrequencyChart):
|
||||
def __init__(self, name="", reflective=True):
|
||||
super().__init__(name)
|
||||
|
||||
self.name_unit = "ns"
|
||||
|
||||
self.leftMargin = 40
|
||||
self.dim.width = 250
|
||||
self.dim.height = 250
|
||||
self.fstart = 0
|
||||
self.fstop = 0
|
||||
self.minDelay = 0
|
||||
self.maxDelay = 0
|
||||
self.span = 0
|
||||
|
||||
self.reflective = reflective
|
||||
|
||||
self.groupDelay = []
|
||||
self.groupDelayReference = []
|
||||
|
||||
self.minDisplayValue = -180
|
||||
self.maxDisplayValue = 180
|
||||
|
||||
def copy(self):
|
||||
new_chart: GroupDelayChart = super().copy()
|
||||
new_chart.reflective = self.reflective
|
||||
new_chart.groupDelay = self.groupDelay.copy()
|
||||
new_chart.groupDelayReference = self.groupDelay.copy()
|
||||
return new_chart
|
||||
|
||||
def setReference(self, data):
|
||||
self.reference = data
|
||||
self.calculateGroupDelay()
|
||||
|
||||
def setData(self, data):
|
||||
self.data = data
|
||||
self.calculateGroupDelay()
|
||||
|
||||
def calculateGroupDelay(self):
|
||||
self.groupDelay = self.calc_data(self.data)
|
||||
self.groupDelayReference = self.calc_data(self.reference)
|
||||
self.update()
|
||||
|
||||
def calc_data(self, data: list[Datapoint]):
|
||||
data_len = len(data)
|
||||
if data_len <= 1:
|
||||
return []
|
||||
unwrapped = np.degrees(np.unwrap([d.phase for d in data]))
|
||||
delay_data = []
|
||||
for i, d in enumerate(data):
|
||||
# TODO: Replace with call to RFTools.groupDelay
|
||||
if i == 0:
|
||||
phase_change = unwrapped[1] - unwrapped[i]
|
||||
freq_change = data[1].freq - d.freq
|
||||
elif i == data_len - 1:
|
||||
phase_change = unwrapped[-1] - unwrapped[-2]
|
||||
freq_change = d.freq - data[-2].freq
|
||||
else:
|
||||
phase_change = unwrapped[i + 1] - unwrapped[i - 1]
|
||||
freq_change = data[i + 1].freq - data[i - 1].freq
|
||||
delay = (-phase_change / (freq_change * 360)) * 10e8
|
||||
if not self.reflective:
|
||||
delay /= 2
|
||||
delay_data.append(delay)
|
||||
return delay_data
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if len(self.data) == 0 and len(self.reference) == 0:
|
||||
return
|
||||
pen = QtGui.QPen(Chart.color.sweep)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(Chart.color.sweep)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
|
||||
if self.fixedValues:
|
||||
min_delay = self.minDisplayValue
|
||||
max_delay = self.maxDisplayValue
|
||||
elif self.data:
|
||||
min_delay = math.floor(np.min(self.groupDelay))
|
||||
max_delay = math.ceil(np.max(self.groupDelay))
|
||||
elif self.reference:
|
||||
min_delay = math.floor(np.min(self.groupDelayReference))
|
||||
max_delay = math.ceil(np.max(self.groupDelayReference))
|
||||
|
||||
span = max_delay - min_delay
|
||||
if span == 0:
|
||||
span = 0.01
|
||||
self.minDelay = min_delay
|
||||
self.maxDelay = max_delay
|
||||
self.span = span
|
||||
|
||||
tickcount = math.floor(self.dim.height / 60)
|
||||
for i in range(tickcount):
|
||||
delay = min_delay + span * i / tickcount
|
||||
y = self.topMargin + round(
|
||||
(self.maxDelay - delay) / self.span * self.dim.height
|
||||
)
|
||||
if delay not in {min_delay, max_delay}:
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
# TODO use format class
|
||||
digits = (
|
||||
0
|
||||
if delay == 0
|
||||
else max(0, min(2, math.floor(3 - math.log10(abs(delay)))))
|
||||
)
|
||||
delaystr = str(round(delay, digits if digits != 0 else None))
|
||||
qp.drawText(3, y + 3, delaystr)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
|
||||
)
|
||||
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin,
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(3, self.topMargin + 5, str(max_delay))
|
||||
qp.drawText(3, self.dim.height + self.topMargin, str(min_delay))
|
||||
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
self.drawFrequencyTicks(qp)
|
||||
|
||||
self.draw_data(qp, Chart.color.sweep, self.data, self.groupDelay)
|
||||
self.draw_data(
|
||||
qp, Chart.color.reference, self.reference, self.groupDelayReference
|
||||
)
|
||||
|
||||
self.drawMarkers(qp)
|
||||
|
||||
def draw_data(
|
||||
self,
|
||||
qp: QtGui.QPainter,
|
||||
color: QtGui.QColor,
|
||||
data: list[Datapoint],
|
||||
delay: list[Datapoint],
|
||||
):
|
||||
pen = QtGui.QPen(color)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(color)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
qp.setPen(pen)
|
||||
for i, d in enumerate(data):
|
||||
x = self.getXPosition(d)
|
||||
y = self.getYPositionFromDelay(delay[i])
|
||||
if self.isPlotable(x, y):
|
||||
qp.drawPoint(int(x), int(y))
|
||||
if self.flag.draw_lines and i > 0:
|
||||
prevx = self.getXPosition(data[i - 1])
|
||||
prevy = self.getYPositionFromDelay(delay[i - 1])
|
||||
qp.setPen(line_pen)
|
||||
if self.isPlotable(x, y):
|
||||
if self.isPlotable(prevx, prevy):
|
||||
qp.drawLine(x, y, prevx, prevy)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(x, y, prevx, prevy)
|
||||
qp.drawLine(x, y, new_x, new_y)
|
||||
elif self.isPlotable(prevx, prevy):
|
||||
new_x, new_y = self.getPlotable(prevx, prevy, x, y)
|
||||
qp.drawLine(prevx, prevy, new_x, new_y)
|
||||
qp.setPen(pen)
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
# TODO: Find a faster way than these expensive "d in data" lookups
|
||||
try:
|
||||
delay = self.groupDelay[self.data.index(d)]
|
||||
except ValueError:
|
||||
try:
|
||||
delay = self.groupDelayReference[self.reference.index(d)]
|
||||
except ValueError:
|
||||
delay = 0
|
||||
return self.getYPositionFromDelay(delay)
|
||||
|
||||
def getYPositionFromDelay(self, delay: float) -> int:
|
||||
return self.topMargin + int(
|
||||
(self.maxDelay - delay) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
val = -1 * ((absy / self.dim.height * self.span) - self.maxDelay)
|
||||
return [val]
|
|
@ -1,32 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class InductanceChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
self.minDisplayValue = 0
|
||||
self.maxDisplayValue = 100
|
||||
self.name_unit = "H"
|
||||
self.value_function = lambda x: x.inductiveEquivalent()
|
|
@ -1,179 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
from dataclasses import dataclass
|
||||
import math
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.SITools import log_floor_125
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class TickVal:
|
||||
count: int = 0
|
||||
first: float = 0.0
|
||||
step: float = 0.0
|
||||
|
||||
|
||||
def span2ticks(span: float, min_val: float) -> TickVal:
|
||||
span = abs(span)
|
||||
step = log_floor_125(span / 5)
|
||||
count = math.floor(span / step)
|
||||
first = math.ceil(min_val / step) * step
|
||||
if first == min_val:
|
||||
first += step
|
||||
return TickVal(count, first, step)
|
||||
|
||||
|
||||
class LogMagChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
|
||||
self.name_unit = "dB"
|
||||
|
||||
self.minDisplayValue = -80
|
||||
self.maxDisplayValue = 10
|
||||
|
||||
self.minValue = 0.0
|
||||
self.maxValue = 1.0
|
||||
self.span = 1.0
|
||||
|
||||
self.isInverted = False
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter) -> None:
|
||||
if len(self.data) == 0 and len(self.reference) == 0:
|
||||
return
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
self.calc_scaling()
|
||||
self.draw_grid(qp)
|
||||
|
||||
self.drawData(qp, self.data, Chart.color.sweep)
|
||||
self.drawData(qp, self.reference, Chart.color.reference)
|
||||
self.drawMarkers(qp)
|
||||
|
||||
def calc_scaling(self) -> None:
|
||||
if self.fixedValues:
|
||||
maxValue = self.maxDisplayValue
|
||||
minValue = self.minDisplayValue
|
||||
else:
|
||||
# Find scaling
|
||||
minValue = 100
|
||||
maxValue = -100
|
||||
for d in self.data:
|
||||
logmag = self.logMag(d)
|
||||
if math.isinf(logmag):
|
||||
continue
|
||||
maxValue = max(maxValue, logmag)
|
||||
minValue = min(minValue, logmag)
|
||||
|
||||
# Also check min/max for the reference sweep
|
||||
for d in self.reference:
|
||||
if d.freq < self.fstart or d.freq > self.fstop:
|
||||
continue
|
||||
logmag = self.logMag(d)
|
||||
if math.isinf(logmag):
|
||||
continue
|
||||
maxValue = max(maxValue, logmag)
|
||||
minValue = min(minValue, logmag)
|
||||
minValue = 10 * math.floor(minValue / 10)
|
||||
maxValue = 10 * math.ceil(maxValue / 10)
|
||||
|
||||
self.minValue = minValue
|
||||
self.maxValue = maxValue
|
||||
|
||||
def draw_grid(self, qp):
|
||||
self.span = (self.maxValue - self.minValue) or 0.01
|
||||
ticks = span2ticks(self.span, self.minValue)
|
||||
self.draw_db_lines(qp, self.maxValue, self.minValue, ticks)
|
||||
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin,
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(3, self.topMargin + 4, f"{self.maxValue}")
|
||||
qp.drawText(3, self.dim.height + self.topMargin, f"{self.minValue}")
|
||||
self.drawFrequencyTicks(qp)
|
||||
self.draw_swr_markers(qp)
|
||||
|
||||
def draw_db_lines(self, qp, maxValue, minValue, ticks) -> None:
|
||||
for i in range(ticks.count):
|
||||
db = ticks.first + i * ticks.step
|
||||
y = self.topMargin + round(
|
||||
(maxValue - db) / self.span * self.dim.height
|
||||
)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
|
||||
)
|
||||
if db > minValue and db != maxValue:
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(
|
||||
3, y + 4, f"{round(db, 1)}" if ticks.step < 1 else f"{db}"
|
||||
)
|
||||
|
||||
def draw_swr_markers(self, qp) -> None:
|
||||
qp.setPen(Chart.color.swr)
|
||||
for vswr in self.swrMarkers:
|
||||
if vswr <= 1:
|
||||
continue
|
||||
logMag = 20 * math.log10((vswr - 1) / (vswr + 1))
|
||||
if self.isInverted:
|
||||
logMag = logMag * -1
|
||||
y = self.topMargin + round(
|
||||
(self.maxValue - logMag) / self.span * self.dim.height
|
||||
)
|
||||
qp.drawLine(self.leftMargin, y, self.leftMargin + self.dim.width, y)
|
||||
qp.drawText(self.leftMargin + 3, y - 1, f"VSWR: {vswr}")
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
logMag = self.logMag(d)
|
||||
if math.isinf(logMag):
|
||||
return self.topMargin
|
||||
return self.topMargin + int(
|
||||
(self.maxValue - logMag) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
val = -1 * ((absy / self.dim.height * self.span) - self.maxValue)
|
||||
return [val]
|
||||
|
||||
def logMag(self, p: Datapoint) -> float:
|
||||
return -p.gain if self.isInverted else p.gain
|
||||
|
||||
def copy(self):
|
||||
new_chart: LogMagChart = super().copy()
|
||||
new_chart.isInverted = self.isInverted
|
||||
new_chart.span = self.span
|
||||
return new_chart
|
|
@ -1,141 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MagnitudeChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
|
||||
self.minDisplayValue = 0
|
||||
|
||||
self.fixedValues = True
|
||||
self.y_action_fixed_span.setChecked(True)
|
||||
self.y_action_automatic.setChecked(False)
|
||||
|
||||
self.minValue = 0
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if not self.data and not self.reference:
|
||||
return
|
||||
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
if self.fixedValues:
|
||||
max_value = self.maxDisplayValue
|
||||
min_value = self.minDisplayValue
|
||||
else:
|
||||
# Find scaling
|
||||
min_value = 100
|
||||
max_value = 0
|
||||
for d in self.data:
|
||||
mag = self.magnitude(d)
|
||||
max_value = max(max_value, mag)
|
||||
min_value = min(min_value, mag)
|
||||
# Also check min/max for the reference sweep
|
||||
for d in self.reference:
|
||||
if d.freq < self.fstart or d.freq > self.fstop:
|
||||
continue
|
||||
max_value = max(max_value, mag)
|
||||
min_value = min(min_value, mag)
|
||||
min_value = 10 * math.floor(min_value / 10)
|
||||
max_value = 10 * math.ceil(max_value / 10)
|
||||
|
||||
self.maxValue = max_value
|
||||
self.minValue = min_value
|
||||
|
||||
self.span = (max_value - min_value) or 0.01
|
||||
|
||||
target_ticks = int(self.dim.height // 60)
|
||||
for i in range(target_ticks):
|
||||
val = min_value + i / target_ticks * self.span
|
||||
y = self.topMargin + int(
|
||||
(self.maxValue - val) / self.span * self.dim.height
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
if val != min_value:
|
||||
digits = max(0, min(2, math.floor(3 - math.log10(abs(val)))))
|
||||
vswrstr = (
|
||||
str(round(val)) if digits == 0 else str(round(val, digits))
|
||||
)
|
||||
qp.drawText(3, y + 3, vswrstr)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
|
||||
)
|
||||
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin,
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(3, self.topMargin + 4, str(max_value))
|
||||
qp.drawText(3, self.dim.height + self.topMargin, str(min_value))
|
||||
self.drawFrequencyTicks(qp)
|
||||
|
||||
qp.setPen(Chart.color.swr)
|
||||
for vswr in self.swrMarkers:
|
||||
if vswr <= 1:
|
||||
continue
|
||||
mag = (vswr - 1) / (vswr + 1)
|
||||
y = self.topMargin + int(
|
||||
(self.maxValue - mag) / self.span * self.dim.height
|
||||
)
|
||||
qp.drawLine(self.leftMargin, y, self.leftMargin + self.dim.width, y)
|
||||
qp.drawText(self.leftMargin + 3, y - 1, f"VSWR: {vswr}")
|
||||
|
||||
self.drawData(qp, self.data, Chart.color.sweep)
|
||||
self.drawData(qp, self.reference, Chart.color.reference)
|
||||
self.drawMarkers(qp)
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
mag = self.magnitude(d)
|
||||
return self.topMargin + int(
|
||||
(self.maxValue - mag) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
val = -1 * ((absy / self.dim.height * self.span) - self.maxValue)
|
||||
return [val]
|
||||
|
||||
@staticmethod
|
||||
def magnitude(p: Datapoint) -> float:
|
||||
return math.sqrt(p.re**2 + p.im**2)
|
||||
|
||||
def copy(self):
|
||||
new_chart = super().copy()
|
||||
new_chart.span = self.span
|
||||
return new_chart
|
|
@ -1,152 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.SITools import Format, Value, round_ceil, round_floor
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
from NanoVNASaver.Charts.LogMag import LogMagChart
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MagnitudeZChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
|
||||
self.minDisplayValue = 0
|
||||
self.maxDisplayValue = 100
|
||||
|
||||
self.minValue = 0
|
||||
self.maxValue = 1
|
||||
self.span = 1
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if not self.data and not self.reference:
|
||||
return
|
||||
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
if self.fixedValues:
|
||||
self.maxValue = self.maxDisplayValue
|
||||
self.minValue = (
|
||||
max(self.minDisplayValue, 0.01)
|
||||
if self.logarithmicY
|
||||
else self.minDisplayValue
|
||||
)
|
||||
else:
|
||||
# Find scaling
|
||||
self.minValue = 100
|
||||
self.maxValue = 0
|
||||
for d in self.data:
|
||||
mag = self.magnitude(d)
|
||||
if math.isinf(mag): # Avoid infinite scales
|
||||
continue
|
||||
self.maxValue = max(self.maxValue, mag)
|
||||
self.minValue = min(self.minValue, mag)
|
||||
# Also check min/max for the reference sweep
|
||||
for d in self.reference:
|
||||
if d.freq < self.fstart or d.freq > self.fstop:
|
||||
continue
|
||||
mag = self.magnitude(d)
|
||||
if math.isinf(mag): # Avoid infinite scales
|
||||
continue
|
||||
self.maxValue = max(self.maxValue, mag)
|
||||
self.minValue = min(self.minValue, mag)
|
||||
|
||||
self.minValue = round_floor(self.minValue, 2)
|
||||
if self.logarithmicY and self.minValue <= 0:
|
||||
self.minValue = 0.01
|
||||
self.maxValue = round_ceil(self.maxValue, 2)
|
||||
|
||||
self.span = (self.maxValue - self.minValue) or 0.01
|
||||
|
||||
# We want one horizontal tick per 50 pixels, at most
|
||||
horizontal_ticks = int(self.dim.height / 50)
|
||||
fmt = Format(max_nr_digits=4)
|
||||
for i in range(horizontal_ticks):
|
||||
y = self.topMargin + round(i * self.dim.height / horizontal_ticks)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width + 5, y
|
||||
)
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
val = Value(self.valueAtPosition(y)[0], fmt=fmt)
|
||||
qp.drawText(3, y + 4, str(val))
|
||||
|
||||
qp.drawText(
|
||||
3,
|
||||
self.dim.height + self.topMargin,
|
||||
str(Value(self.minValue, fmt=fmt)),
|
||||
)
|
||||
|
||||
self.drawFrequencyTicks(qp)
|
||||
|
||||
self.drawData(qp, self.data, Chart.color.sweep)
|
||||
self.drawData(qp, self.reference, Chart.color.reference)
|
||||
self.drawMarkers(qp)
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
mag = self.magnitude(d)
|
||||
if self.logarithmicY and mag == 0:
|
||||
return self.topMargin - self.dim.height
|
||||
if math.isfinite(mag):
|
||||
if self.logarithmicY:
|
||||
span = math.log(self.maxValue) - math.log(self.minValue)
|
||||
return self.topMargin + int(
|
||||
(math.log(self.maxValue) - math.log(mag))
|
||||
/ span
|
||||
* self.dim.height
|
||||
)
|
||||
return self.topMargin + int(
|
||||
(self.maxValue - mag) / self.span * self.dim.height
|
||||
)
|
||||
return self.topMargin
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
if self.logarithmicY:
|
||||
span = math.log(self.maxValue) - math.log(self.minValue)
|
||||
val = math.exp(
|
||||
math.log(self.maxValue) - absy * span / self.dim.height
|
||||
)
|
||||
else:
|
||||
val = self.maxValue - (absy / self.dim.height * self.span)
|
||||
return [val]
|
||||
|
||||
@staticmethod
|
||||
def magnitude(p: Datapoint) -> float:
|
||||
return abs(p.impedance())
|
||||
|
||||
def logarithmicYAllowed(self) -> bool:
|
||||
return True
|
||||
|
||||
def copy(self):
|
||||
new_chart: LogMagChart = super().copy()
|
||||
new_chart.span = self.span
|
||||
return new_chart
|
|
@ -1,31 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Charts.MagnitudeZ import MagnitudeZChart
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MagnitudeZSeriesChart(MagnitudeZChart):
|
||||
@staticmethod
|
||||
def magnitude(p: Datapoint) -> float:
|
||||
return abs(p.seriesImpedance())
|
|
@ -1,30 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from .MagnitudeZ import MagnitudeZChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MagnitudeZShuntChart(MagnitudeZChart):
|
||||
@staticmethod
|
||||
def magnitude(p: Datapoint) -> float:
|
||||
return abs(p.shuntImpedance())
|
|
@ -1,356 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.Marker.Widget import Marker
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.SITools import Format, Value
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PermeabilityChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
self.leftMargin = 40
|
||||
self.rightMargin = 30
|
||||
self.dim.width = 230
|
||||
self.dim.height = 250
|
||||
self.fstart = 0
|
||||
self.fstop = 0
|
||||
self.span = 0.01
|
||||
self.max = 0
|
||||
|
||||
self.maxDisplayValue = 100
|
||||
self.minDisplayValue = -100
|
||||
|
||||
def logarithmicYAllowed(self) -> bool:
|
||||
return True
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(
|
||||
self.leftMargin + 5,
|
||||
15,
|
||||
self.name + " (\N{MICRO SIGN}\N{OHM SIGN} / Hz)",
|
||||
)
|
||||
qp.drawText(10, 15, "R")
|
||||
qp.drawText(self.leftMargin + self.dim.width + 10, 15, "X")
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin,
|
||||
self.topMargin - 5,
|
||||
self.leftMargin,
|
||||
self.topMargin + self.dim.height + 5,
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin + self.dim.height,
|
||||
self.leftMargin + self.dim.width + 5,
|
||||
self.topMargin + self.dim.height,
|
||||
)
|
||||
self.drawTitle(qp)
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if not self.data and not self.reference:
|
||||
return
|
||||
|
||||
pen = QtGui.QPen(Chart.color.sweep)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(Chart.color.sweep)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
# Find scaling
|
||||
if self.fixedValues:
|
||||
min_val = self.minDisplayValue
|
||||
max_val = self.maxDisplayValue
|
||||
else:
|
||||
min_val = 1000
|
||||
max_val = -1000
|
||||
for d in self.data:
|
||||
imp = d.impedance()
|
||||
re, im = imp.real, imp.imag
|
||||
re = re * 10e6 / d.freq
|
||||
im = im * 10e6 / d.freq
|
||||
max_val = max(max_val, re)
|
||||
max_val = max(max_val, im)
|
||||
min_val = min(min_val, re)
|
||||
min_val = min(min_val, im)
|
||||
# Also check min/max for the reference sweep
|
||||
for d in self.reference:
|
||||
if d.freq < self.fstart or d.freq > self.fstop:
|
||||
continue
|
||||
imp = d.impedance()
|
||||
re, im = imp.real, imp.imag
|
||||
re = re * 10e6 / d.freq
|
||||
im = im * 10e6 / d.freq
|
||||
max_val = max(max_val, re)
|
||||
max_val = max(max_val, im)
|
||||
min_val = min(min_val, re)
|
||||
min_val = min(min_val, im)
|
||||
|
||||
if self.logarithmicY:
|
||||
min_val = max(0.01, min_val)
|
||||
|
||||
self.max = max_val
|
||||
self.span = (max_val - min_val) or 0.01
|
||||
|
||||
# We want one horizontal tick per 50 pixels, at most
|
||||
horizontal_ticks = math.floor(self.dim.height / 50)
|
||||
fmt = Format(max_nr_digits=4)
|
||||
for i in range(horizontal_ticks):
|
||||
y = self.topMargin + round(i * self.dim.height / horizontal_ticks)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width + 5, y
|
||||
)
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
val = Value(self.valueAtPosition(y)[0], fmt=fmt)
|
||||
qp.drawText(3, y + 4, str(val))
|
||||
|
||||
qp.drawText(
|
||||
3, self.dim.height + self.topMargin, str(Value(min_val, fmt=fmt))
|
||||
)
|
||||
|
||||
self.drawFrequencyTicks(qp)
|
||||
|
||||
primary_pen = pen
|
||||
secondary_pen = QtGui.QPen(Chart.color.sweep_secondary)
|
||||
if self.data:
|
||||
c = QtGui.QColor(Chart.color.sweep)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(20, 9, 25, 9)
|
||||
c = QtGui.QColor(Chart.color.sweep_secondary)
|
||||
c.setAlpha(255)
|
||||
pen.setColor(c)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(
|
||||
self.leftMargin + self.dim.width,
|
||||
9,
|
||||
self.leftMargin + self.dim.width + 5,
|
||||
9,
|
||||
)
|
||||
|
||||
primary_pen.setWidth(self.dim.point)
|
||||
secondary_pen.setWidth(self.dim.point)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
|
||||
for i, data in enumerate(self.data):
|
||||
x = self.getXPosition(data)
|
||||
y_re = self.getReYPosition(data)
|
||||
y_im = self.getImYPosition(data)
|
||||
qp.setPen(primary_pen)
|
||||
if self.isPlotable(x, y_re):
|
||||
qp.drawPoint(x, y_re)
|
||||
qp.setPen(secondary_pen)
|
||||
if self.isPlotable(x, y_im):
|
||||
qp.drawPoint(x, y_im)
|
||||
if self.flag.draw_lines and i > 0:
|
||||
prev_x = self.getXPosition(self.data[i - 1])
|
||||
prev_y_re = self.getReYPosition(self.data[i - 1])
|
||||
prev_y_im = self.getImYPosition(self.data[i - 1])
|
||||
|
||||
# Real part first
|
||||
line_pen.setColor(Chart.color.sweep)
|
||||
qp.setPen(line_pen)
|
||||
if self.isPlotable(x, y_re):
|
||||
if self.isPlotable(prev_x, prev_y_re):
|
||||
qp.drawLine(x, y_re, prev_x, prev_y_re)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(
|
||||
x, y_re, prev_x, prev_y_re
|
||||
)
|
||||
qp.drawLine(x, y_re, new_x, new_y)
|
||||
elif self.isPlotable(prev_x, prev_y_re):
|
||||
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
|
||||
qp.drawLine(prev_x, prev_y_re, new_x, new_y)
|
||||
|
||||
# Imag part second
|
||||
line_pen.setColor(Chart.color.sweep_secondary)
|
||||
qp.setPen(line_pen)
|
||||
if self.isPlotable(x, y_im):
|
||||
if self.isPlotable(prev_x, prev_y_im):
|
||||
qp.drawLine(x, y_im, prev_x, prev_y_im)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(
|
||||
x, y_im, prev_x, prev_y_im
|
||||
)
|
||||
qp.drawLine(x, y_im, new_x, new_y)
|
||||
elif self.isPlotable(prev_x, prev_y_im):
|
||||
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
|
||||
qp.drawLine(prev_x, prev_y_im, new_x, new_y)
|
||||
|
||||
primary_pen.setColor(Chart.color.reference)
|
||||
line_pen.setColor(Chart.color.reference)
|
||||
secondary_pen.setColor(Chart.color.reference_secondary)
|
||||
qp.setPen(primary_pen)
|
||||
if self.reference:
|
||||
c = QtGui.QColor(Chart.color.reference)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(20, 14, 25, 14)
|
||||
c = QtGui.QColor(Chart.color.reference_secondary)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(
|
||||
self.leftMargin + self.dim.width,
|
||||
14,
|
||||
self.leftMargin + self.dim.width + 5,
|
||||
14,
|
||||
)
|
||||
|
||||
for i, reference in enumerate(self.reference):
|
||||
if reference.freq < self.fstart or reference.freq > self.fstop:
|
||||
continue
|
||||
x = self.getXPosition(reference)
|
||||
y_re = self.getReYPosition(reference)
|
||||
y_im = self.getImYPosition(reference)
|
||||
qp.setPen(primary_pen)
|
||||
if self.isPlotable(x, y_re):
|
||||
qp.drawPoint(x, y_re)
|
||||
qp.setPen(secondary_pen)
|
||||
if self.isPlotable(x, y_im):
|
||||
qp.drawPoint(x, y_im)
|
||||
if self.flag.draw_lines and i > 0:
|
||||
prev_x = self.getXPosition(self.reference[i - 1])
|
||||
prev_y_re = self.getReYPosition(self.reference[i - 1])
|
||||
prev_y_im = self.getImYPosition(self.reference[i - 1])
|
||||
|
||||
line_pen.setColor(Chart.color.reference)
|
||||
qp.setPen(line_pen)
|
||||
# Real part first
|
||||
if self.isPlotable(x, y_re):
|
||||
if self.isPlotable(prev_x, prev_y_re):
|
||||
qp.drawLine(x, y_re, prev_x, prev_y_re)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(
|
||||
x, y_re, prev_x, prev_y_re
|
||||
)
|
||||
qp.drawLine(x, y_re, new_x, new_y)
|
||||
elif self.isPlotable(prev_x, prev_y_re):
|
||||
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
|
||||
qp.drawLine(prev_x, prev_y_re, new_x, new_y)
|
||||
|
||||
line_pen.setColor(Chart.color.reference_secondary)
|
||||
qp.setPen(line_pen)
|
||||
# Imag part second
|
||||
if self.isPlotable(x, y_im):
|
||||
if self.isPlotable(prev_x, prev_y_im):
|
||||
qp.drawLine(x, y_im, prev_x, prev_y_im)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(
|
||||
x, y_im, prev_x, prev_y_im
|
||||
)
|
||||
qp.drawLine(x, y_im, new_x, new_y)
|
||||
elif self.isPlotable(prev_x, prev_y_im):
|
||||
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
|
||||
qp.drawLine(prev_x, prev_y_im, new_x, new_y)
|
||||
|
||||
# Now draw the markers
|
||||
for m in self.markers:
|
||||
if m.location != -1:
|
||||
x = self.getXPosition(self.data[m.location])
|
||||
y_re = self.getReYPosition(self.data[m.location])
|
||||
y_im = self.getImYPosition(self.data[m.location])
|
||||
|
||||
self.drawMarker(x, y_re, qp, m.color, self.markers.index(m) + 1)
|
||||
self.drawMarker(x, y_im, qp, m.color, self.markers.index(m) + 1)
|
||||
|
||||
def getImYPosition(self, d: Datapoint) -> int:
|
||||
im = d.impedance().imag
|
||||
im = im * 10e6 / d.freq
|
||||
if self.logarithmicY:
|
||||
min_val = self.max - self.span
|
||||
if self.max > 0 and min_val > 0 and im > 0:
|
||||
span = math.log(self.max) - math.log(min_val)
|
||||
else:
|
||||
return -1
|
||||
return int(
|
||||
self.topMargin
|
||||
+ (math.log(self.max) - math.log(im)) / span * self.dim.height
|
||||
)
|
||||
return int(
|
||||
self.topMargin + (self.max - im) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def getReYPosition(self, d: Datapoint) -> int:
|
||||
re = d.impedance().real
|
||||
re = re * 10e6 / d.freq
|
||||
if self.logarithmicY:
|
||||
min_val = self.max - self.span
|
||||
if self.max > 0 and min_val > 0 and re > 0:
|
||||
span = math.log(self.max) - math.log(min_val)
|
||||
else:
|
||||
return -1
|
||||
return int(
|
||||
self.topMargin
|
||||
+ (math.log(self.max) - math.log(re)) / span * self.dim.height
|
||||
)
|
||||
return int(
|
||||
self.topMargin + (self.max - re) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
if self.logarithmicY:
|
||||
min_val = self.max - self.span
|
||||
if self.max > 0 and min_val > 0:
|
||||
span = math.log(self.max) - math.log(min_val)
|
||||
step = span / self.dim.height
|
||||
val = math.exp(math.log(self.max) - absy * step)
|
||||
else:
|
||||
val = -1
|
||||
else:
|
||||
val = -1 * ((absy / self.dim.height * self.span) - self.max)
|
||||
return [val]
|
||||
|
||||
def getNearestMarker(self, x, y) -> Marker:
|
||||
if len(self.data) == 0:
|
||||
return None
|
||||
shortest = 10**6
|
||||
nearest = None
|
||||
for m in self.markers:
|
||||
mx, _ = self.getPosition(self.data[m.location])
|
||||
myr = self.getReYPosition(self.data[m.location])
|
||||
myi = self.getImYPosition(self.data[m.location])
|
||||
dx = abs(x - mx)
|
||||
dy = min(abs(y - myr), abs(y - myi))
|
||||
distance = math.sqrt(dx**2 + dy**2)
|
||||
if distance < shortest:
|
||||
shortest = distance
|
||||
nearest = m
|
||||
return nearest
|
|
@ -1,156 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
import numpy as np
|
||||
|
||||
from PyQt6.QtGui import QAction, QPainter, QPen
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PhaseChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
|
||||
self.minAngle = 0
|
||||
self.maxAngle = 0
|
||||
self.span = 0
|
||||
self.unwrap = False
|
||||
|
||||
self.unwrappedData = []
|
||||
self.unwrappedReference = []
|
||||
|
||||
self.minDisplayValue = -180
|
||||
self.maxDisplayValue = 180
|
||||
|
||||
self.y_menu.addSeparator()
|
||||
self.action_unwrap = QAction("Unwrap")
|
||||
self.action_unwrap.setCheckable(True)
|
||||
self.action_unwrap.triggered.connect(
|
||||
lambda: self.setUnwrap(self.action_unwrap.isChecked())
|
||||
)
|
||||
self.y_menu.addAction(self.action_unwrap)
|
||||
|
||||
def copy(self):
|
||||
new_chart = super().copy()
|
||||
new_chart.setUnwrap(self.unwrap)
|
||||
new_chart.action_unwrap.setChecked(self.unwrap)
|
||||
return new_chart
|
||||
|
||||
def setUnwrap(self, unwrap: bool):
|
||||
self.unwrap = unwrap
|
||||
self.update()
|
||||
|
||||
def drawValues(self, qp: QPainter):
|
||||
if len(self.data) == 0 and len(self.reference) == 0:
|
||||
return
|
||||
|
||||
if self.unwrap:
|
||||
rawData = [d.phase for d in self.data]
|
||||
rawReference = [d.phase for d in self.reference]
|
||||
self.unwrappedData = np.degrees(np.unwrap(rawData))
|
||||
self.unwrappedReference = np.degrees(np.unwrap(rawReference))
|
||||
|
||||
if self.fixedValues:
|
||||
minAngle = self.minDisplayValue
|
||||
maxAngle = self.maxDisplayValue
|
||||
elif self.unwrap and self.data:
|
||||
minAngle = math.floor(np.min(self.unwrappedData))
|
||||
maxAngle = math.ceil(np.max(self.unwrappedData))
|
||||
elif self.unwrap and self.reference:
|
||||
minAngle = math.floor(np.min(self.unwrappedReference))
|
||||
maxAngle = math.ceil(np.max(self.unwrappedReference))
|
||||
else:
|
||||
minAngle = -180
|
||||
maxAngle = 180
|
||||
|
||||
span = maxAngle - minAngle
|
||||
if span == 0:
|
||||
span = 0.01
|
||||
self.minAngle = minAngle
|
||||
self.maxAngle = maxAngle
|
||||
self.span = span
|
||||
|
||||
tickcount = math.floor(self.dim.height / 60)
|
||||
|
||||
for i in range(tickcount):
|
||||
angle = minAngle + span * i / tickcount
|
||||
y = self.topMargin + int(
|
||||
(self.maxAngle - angle) / self.span * self.dim.height
|
||||
)
|
||||
if angle not in [minAngle, maxAngle]:
|
||||
qp.setPen(QPen(Chart.color.text))
|
||||
if angle != 0:
|
||||
digits = max(
|
||||
0, min(2, math.floor(3 - math.log10(abs(angle))))
|
||||
)
|
||||
anglestr = (
|
||||
str(round(angle))
|
||||
if digits == 0
|
||||
else str(round(angle, digits))
|
||||
)
|
||||
else:
|
||||
anglestr = "0"
|
||||
qp.drawText(3, y + 3, f"{anglestr}°")
|
||||
qp.setPen(QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin,
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(3, self.topMargin + 5, f"{maxAngle}°")
|
||||
qp.drawText(3, self.dim.height + self.topMargin, f"{minAngle}°")
|
||||
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
self.drawFrequencyTicks(qp)
|
||||
self.drawData(qp, self.data, Chart.color.sweep)
|
||||
self.drawData(qp, self.reference, Chart.color.reference)
|
||||
self.drawMarkers(qp)
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
if self.unwrap and d in self.data:
|
||||
angle = self.unwrappedData[self.data.index(d)]
|
||||
elif self.unwrap and d in self.reference:
|
||||
angle = self.unwrappedReference[self.reference.index(d)]
|
||||
else:
|
||||
angle = math.degrees(d.phase)
|
||||
return self.topMargin + int(
|
||||
(self.maxAngle - angle) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
val = -1 * ((absy / self.dim.height * self.span) - self.maxAngle)
|
||||
return [val]
|
|
@ -1,63 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
from PyQt6 import QtGui, QtCore
|
||||
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Square import SquareChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PolarChart(SquareChart):
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
center_x = self.width() // 2
|
||||
center_y = self.height() // 2
|
||||
width_2 = self.dim.width // 2
|
||||
height_2 = self.dim.height // 2
|
||||
width_45 = round(self.dim.width * 0.35355)
|
||||
height_45 = round(self.dim.height * 0.35355)
|
||||
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(3, 15, self.name)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
|
||||
qp.drawEllipse(QtCore.QPoint(center_x, center_y), width_2, height_2)
|
||||
qp.drawEllipse(
|
||||
QtCore.QPoint(center_x, center_y), width_2 // 2, height_2 // 2
|
||||
)
|
||||
|
||||
qp.drawLine(center_x - width_2, center_y, center_x + width_2, center_y)
|
||||
qp.drawLine(
|
||||
center_x, center_y - height_2, center_x, center_y + height_2
|
||||
)
|
||||
qp.drawLine(
|
||||
center_x + width_45,
|
||||
center_y + height_45,
|
||||
center_x - width_45,
|
||||
center_y - height_45,
|
||||
)
|
||||
qp.drawLine(
|
||||
center_x + width_45,
|
||||
center_y - height_45,
|
||||
center_x - width_45,
|
||||
center_y + height_45,
|
||||
)
|
||||
|
||||
self.drawTitle(qp)
|
|
@ -1,132 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class QualityFactorChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
self.leftMargin = 35
|
||||
self.dim.width = 250
|
||||
self.dim.height = 250
|
||||
self.fstart = 0
|
||||
self.fstop = 0
|
||||
self.minQ = 0
|
||||
self.maxQ = 0
|
||||
self.span = 0
|
||||
self.minDisplayValue = 0
|
||||
self.maxDisplayValue = 100
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
super().drawChart(qp)
|
||||
|
||||
# Make up some sensible scaling here
|
||||
if self.fixedValues:
|
||||
maxQ = self.maxDisplayValue
|
||||
else:
|
||||
maxQ = 0
|
||||
for d in self.data:
|
||||
Q = d.qFactor()
|
||||
maxQ = max(maxQ, Q)
|
||||
scale = 0
|
||||
if maxQ > 0:
|
||||
scale = max(scale, math.floor(math.log10(maxQ)))
|
||||
maxQ = math.ceil(maxQ / 10**scale) * 10**scale
|
||||
|
||||
self.minQ = self.minDisplayValue
|
||||
self.maxQ = maxQ
|
||||
self.span = self.maxQ - self.minQ
|
||||
if self.span == 0:
|
||||
return # No data to draw the graph from
|
||||
|
||||
tickcount = math.floor(self.dim.height / 60)
|
||||
|
||||
for i in range(tickcount):
|
||||
q = self.minQ + i * self.span / tickcount
|
||||
y = self.topMargin + int(
|
||||
(self.maxQ - q) / self.span * self.dim.height
|
||||
)
|
||||
q = round(q)
|
||||
if q < 10:
|
||||
q = round(q, 2)
|
||||
if q < 20:
|
||||
q = round(q, 1)
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(3, y + 3, str(q))
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin,
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
|
||||
max_q = round(maxQ)
|
||||
if maxQ < 10:
|
||||
max_q = round(maxQ, 2)
|
||||
elif maxQ < 20:
|
||||
max_q = round(maxQ, 1)
|
||||
qp.drawText(3, 35, f"{max_q}")
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if len(self.data) == 0 and len(self.reference) == 0:
|
||||
return
|
||||
if self.span == 0:
|
||||
return
|
||||
pen = QtGui.QPen(Chart.color.sweep)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(Chart.color.sweep)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255))
|
||||
highlighter.setWidth(1)
|
||||
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
self.drawFrequencyTicks(qp)
|
||||
self.drawData(qp, self.data, Chart.color.sweep)
|
||||
self.drawData(qp, self.reference, Chart.color.reference)
|
||||
self.drawMarkers(qp)
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
Q = d.qFactor()
|
||||
return self.topMargin + int(
|
||||
(self.maxQ - Q) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
val = -1 * ((absy / self.dim.height * self.span) - self.maxQ)
|
||||
return [val]
|
|
@ -1,520 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtWidgets, QtGui
|
||||
|
||||
from NanoVNASaver.Formatting import format_frequency_chart
|
||||
from NanoVNASaver.Marker.Widget import Marker
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.SITools import Format, Value
|
||||
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RealImaginaryChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
self.leftMargin = 45
|
||||
self.rightMargin = 45
|
||||
self.dim.width = 230
|
||||
self.dim.height = 250
|
||||
self.fstart = 0
|
||||
self.fstop = 0
|
||||
self.span_real = 0.01
|
||||
self.span_imag = 0.01
|
||||
self.max_real = 0
|
||||
self.max_imag = 0
|
||||
|
||||
self.maxDisplayReal = 100
|
||||
self.maxDisplayImag = 100
|
||||
self.minDisplayReal = 0
|
||||
self.minDisplayImag = -100
|
||||
|
||||
#
|
||||
# Build the context menu
|
||||
#
|
||||
|
||||
self.y_menu.clear()
|
||||
|
||||
self.y_action_automatic = QtGui.QAction("Automatic")
|
||||
self.y_action_automatic.setCheckable(True)
|
||||
self.y_action_automatic.setChecked(True)
|
||||
self.y_action_automatic.changed.connect(
|
||||
lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())
|
||||
)
|
||||
self.y_action_fixed_span = QtGui.QAction("Fixed span")
|
||||
self.y_action_fixed_span.setCheckable(True)
|
||||
self.y_action_fixed_span.changed.connect(
|
||||
lambda: self.setFixedValues(self.y_action_fixed_span.isChecked())
|
||||
)
|
||||
mode_group = QtGui.QActionGroup(self)
|
||||
mode_group.addAction(self.y_action_automatic)
|
||||
mode_group.addAction(self.y_action_fixed_span)
|
||||
self.y_menu.addAction(self.y_action_automatic)
|
||||
self.y_menu.addAction(self.y_action_fixed_span)
|
||||
|
||||
def copy(self):
|
||||
new_chart: RealImaginaryChart = super().copy()
|
||||
|
||||
new_chart.maxDisplayReal = self.maxDisplayReal
|
||||
new_chart.maxDisplayImag = self.maxDisplayImag
|
||||
new_chart.minDisplayReal = self.minDisplayReal
|
||||
new_chart.minDisplayImag = self.minDisplayImag
|
||||
return new_chart
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if not self.data and not self.reference:
|
||||
return
|
||||
|
||||
pen = QtGui.QPen(Chart.color.sweep)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(Chart.color.sweep)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
highlighter = QtGui.QPen(QtGui.QColor(20, 0, 255))
|
||||
highlighter.setWidth(1)
|
||||
|
||||
self._set_start_stop()
|
||||
|
||||
# Draw bands if required
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
|
||||
min_real, max_real, min_imag, max_imag = self.find_scaling()
|
||||
|
||||
self.max_real = max_real
|
||||
self.max_imag = max_imag
|
||||
|
||||
self.span_real = (max_real - min_real) or 0.01
|
||||
self.span_imag = (max_imag - min_imag) or 0.01
|
||||
|
||||
self.drawHorizontalTicks(qp)
|
||||
|
||||
fmt = Format(max_nr_digits=3)
|
||||
qp.drawText(
|
||||
3, self.dim.height + self.topMargin, str(Value(min_real, fmt=fmt))
|
||||
)
|
||||
qp.drawText(
|
||||
self.leftMargin + self.dim.width + 8,
|
||||
self.dim.height + self.topMargin,
|
||||
str(Value(min_imag, fmt=fmt)),
|
||||
)
|
||||
|
||||
self.drawFrequencyTicks(qp)
|
||||
|
||||
primary_pen = pen
|
||||
secondary_pen = QtGui.QPen(Chart.color.sweep_secondary)
|
||||
if self.data:
|
||||
c = QtGui.QColor(Chart.color.sweep)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(20, 9, 25, 9)
|
||||
c = QtGui.QColor(Chart.color.sweep_secondary)
|
||||
c.setAlpha(255)
|
||||
pen.setColor(c)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(
|
||||
self.leftMargin + self.dim.width,
|
||||
9,
|
||||
self.leftMargin + self.dim.width + 5,
|
||||
9,
|
||||
)
|
||||
|
||||
primary_pen.setWidth(self.dim.point)
|
||||
secondary_pen.setWidth(self.dim.point)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
|
||||
for i, data in enumerate(self.data):
|
||||
x = self.getXPosition(data)
|
||||
y_re = self.getReYPosition(data)
|
||||
y_im = self.getImYPosition(data)
|
||||
qp.setPen(primary_pen)
|
||||
if self.isPlotable(x, y_re):
|
||||
qp.drawPoint(x, y_re)
|
||||
qp.setPen(secondary_pen)
|
||||
if self.isPlotable(x, y_im):
|
||||
qp.drawPoint(x, y_im)
|
||||
if self.flag.draw_lines and i > 0:
|
||||
prev_x = self.getXPosition(self.data[i - 1])
|
||||
prev_y_re = self.getReYPosition(self.data[i - 1])
|
||||
prev_y_im = self.getImYPosition(self.data[i - 1])
|
||||
|
||||
# Real part first
|
||||
line_pen.setColor(Chart.color.sweep)
|
||||
qp.setPen(line_pen)
|
||||
if self.isPlotable(x, y_re):
|
||||
if self.isPlotable(prev_x, prev_y_re):
|
||||
qp.drawLine(x, y_re, prev_x, prev_y_re)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(
|
||||
x, y_re, prev_x, prev_y_re
|
||||
)
|
||||
qp.drawLine(x, y_re, new_x, new_y)
|
||||
elif self.isPlotable(prev_x, prev_y_re):
|
||||
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
|
||||
qp.drawLine(prev_x, prev_y_re, new_x, new_y)
|
||||
|
||||
# Imag part second
|
||||
line_pen.setColor(Chart.color.sweep_secondary)
|
||||
qp.setPen(line_pen)
|
||||
if self.isPlotable(x, y_im):
|
||||
if self.isPlotable(prev_x, prev_y_im):
|
||||
qp.drawLine(x, y_im, prev_x, prev_y_im)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(
|
||||
x, y_im, prev_x, prev_y_im
|
||||
)
|
||||
qp.drawLine(x, y_im, new_x, new_y)
|
||||
elif self.isPlotable(prev_x, prev_y_im):
|
||||
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
|
||||
qp.drawLine(prev_x, prev_y_im, new_x, new_y)
|
||||
|
||||
primary_pen.setColor(Chart.color.reference)
|
||||
line_pen.setColor(Chart.color.reference)
|
||||
secondary_pen.setColor(Chart.color.reference_secondary)
|
||||
qp.setPen(primary_pen)
|
||||
if self.reference:
|
||||
c = QtGui.QColor(Chart.color.reference)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(20, 14, 25, 14)
|
||||
c = QtGui.QColor(Chart.color.reference_secondary)
|
||||
c.setAlpha(255)
|
||||
pen = QtGui.QPen(c)
|
||||
pen.setWidth(2)
|
||||
qp.setPen(pen)
|
||||
qp.drawLine(
|
||||
self.leftMargin + self.dim.width,
|
||||
14,
|
||||
self.leftMargin + self.dim.width + 5,
|
||||
14,
|
||||
)
|
||||
|
||||
for i, reference in enumerate(self.reference):
|
||||
if reference.freq < self.fstart or reference.freq > self.fstop:
|
||||
continue
|
||||
x = self.getXPosition(reference)
|
||||
y_re = self.getReYPosition(reference)
|
||||
y_im = self.getImYPosition(reference)
|
||||
qp.setPen(primary_pen)
|
||||
if self.isPlotable(x, y_re):
|
||||
qp.drawPoint(x, y_re)
|
||||
qp.setPen(secondary_pen)
|
||||
if self.isPlotable(x, y_im):
|
||||
qp.drawPoint(x, y_im)
|
||||
if self.flag.draw_lines and i > 0:
|
||||
prev_x = self.getXPosition(self.reference[i - 1])
|
||||
prev_y_re = self.getReYPosition(self.reference[i - 1])
|
||||
prev_y_im = self.getImYPosition(self.reference[i - 1])
|
||||
|
||||
line_pen.setColor(Chart.color.reference)
|
||||
qp.setPen(line_pen)
|
||||
# Real part first
|
||||
if self.isPlotable(x, y_re):
|
||||
if self.isPlotable(prev_x, prev_y_re):
|
||||
qp.drawLine(x, y_re, prev_x, prev_y_re)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(
|
||||
x, y_re, prev_x, prev_y_re
|
||||
)
|
||||
qp.drawLine(x, y_re, new_x, new_y)
|
||||
elif self.isPlotable(prev_x, prev_y_re):
|
||||
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
|
||||
qp.drawLine(prev_x, prev_y_re, new_x, new_y)
|
||||
|
||||
line_pen.setColor(Chart.color.reference_secondary)
|
||||
qp.setPen(line_pen)
|
||||
# Imag part second
|
||||
if self.isPlotable(x, y_im):
|
||||
if self.isPlotable(prev_x, prev_y_im):
|
||||
qp.drawLine(x, y_im, prev_x, prev_y_im)
|
||||
else:
|
||||
new_x, new_y = self.getPlotable(
|
||||
x, y_im, prev_x, prev_y_im
|
||||
)
|
||||
qp.drawLine(x, y_im, new_x, new_y)
|
||||
elif self.isPlotable(prev_x, prev_y_im):
|
||||
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
|
||||
qp.drawLine(prev_x, prev_y_im, new_x, new_y)
|
||||
|
||||
# Now draw the markers
|
||||
for m in self.markers:
|
||||
if m.location != -1:
|
||||
x = self.getXPosition(self.data[m.location])
|
||||
y_re = self.getReYPosition(self.data[m.location])
|
||||
y_im = self.getImYPosition(self.data[m.location])
|
||||
|
||||
self.drawMarker(x, y_re, qp, m.color, self.markers.index(m) + 1)
|
||||
self.drawMarker(x, y_im, qp, m.color, self.markers.index(m) + 1)
|
||||
|
||||
def drawHorizontalTicks(self, qp):
|
||||
# We want one horizontal tick per 50 pixels, at most
|
||||
fmt = Format(max_nr_digits=3)
|
||||
horizontal_ticks = self.dim.height // 50
|
||||
for i in range(horizontal_ticks):
|
||||
y = self.topMargin + i * self.dim.height // horizontal_ticks
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width + 5, y
|
||||
)
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
re = self.max_real - i * self.span_real / horizontal_ticks
|
||||
im = self.max_imag - i * self.span_imag / horizontal_ticks
|
||||
qp.drawText(3, y + 4, f"{Value(re, fmt=fmt)}")
|
||||
qp.drawText(
|
||||
self.leftMargin + self.dim.width + 8,
|
||||
y + 4,
|
||||
f"{Value(im, fmt=fmt)}",
|
||||
)
|
||||
|
||||
def find_scaling(self):
|
||||
# Find scaling
|
||||
if self.fixedValues:
|
||||
min_real = self.minDisplayReal
|
||||
max_real = self.maxDisplayReal
|
||||
min_imag = self.minDisplayImag
|
||||
max_imag = self.maxDisplayImag
|
||||
return min_real, max_real, min_imag, max_imag
|
||||
|
||||
min_real = 1000
|
||||
min_imag = 1000
|
||||
max_real = 0
|
||||
max_imag = -1000
|
||||
for d in self.data:
|
||||
imp = self.value(d)
|
||||
re, im = imp.real, imp.imag
|
||||
if math.isinf(re): # Avoid infinite scales
|
||||
continue
|
||||
max_real = max(max_real, re)
|
||||
min_real = min(min_real, re)
|
||||
max_imag = max(max_imag, im)
|
||||
min_imag = min(min_imag, im)
|
||||
# Also check min/max for the reference sweep
|
||||
for d in self.reference:
|
||||
if d.freq < self.fstart or d.freq > self.fstop:
|
||||
continue
|
||||
imp = self.value(d)
|
||||
re, im = imp.real, imp.imag
|
||||
if math.isinf(re): # Avoid infinite scales
|
||||
continue
|
||||
max_real = max(max_real, re)
|
||||
min_real = min(min_real, re)
|
||||
max_imag = max(max_imag, im)
|
||||
min_imag = min(min_imag, im)
|
||||
# Always have at least 8 numbered horizontal lines
|
||||
max_real = math.ceil(max_real)
|
||||
min_real = math.floor(min_real)
|
||||
max_imag = math.ceil(max_imag)
|
||||
min_imag = math.floor(min_imag)
|
||||
|
||||
min_imag, max_imag = self.imag_scaling_constraints(min_imag, max_imag)
|
||||
return min_real, max_real, min_imag, max_imag
|
||||
|
||||
def imag_scaling_constraints(self, min_imag, max_imag):
|
||||
if max_imag - min_imag < 8:
|
||||
missing = 8 - (max_imag - min_imag)
|
||||
max_imag += math.ceil(missing / 2)
|
||||
min_imag -= math.floor(missing / 2)
|
||||
|
||||
if 0 > max_imag > -2:
|
||||
max_imag = 0
|
||||
if 0 < min_imag < 2:
|
||||
min_imag = 0
|
||||
|
||||
if (max_imag - min_imag) > 8 and min_imag < 0 < max_imag:
|
||||
# We should show a "0" line for the reactive part
|
||||
span = max_imag - min_imag
|
||||
step_size = span / 8
|
||||
if max_imag < step_size:
|
||||
# The 0 line is the first step after the top.
|
||||
# Scale accordingly.
|
||||
max_imag = -min_imag / 7
|
||||
elif -min_imag < step_size:
|
||||
# The 0 line is the last step before the bottom.
|
||||
# Scale accordingly.
|
||||
min_imag = -max_imag / 7
|
||||
else:
|
||||
# Scale max_imag to be a whole factor of min_imag
|
||||
num_min = math.floor(min_imag / step_size * -1)
|
||||
num_max = 8 - num_min
|
||||
max_imag = num_max * (min_imag / num_min) * -1
|
||||
return min_imag, max_imag
|
||||
|
||||
def getImYPosition(self, d: Datapoint) -> int:
|
||||
im = self.value(d).imag
|
||||
return int(
|
||||
self.topMargin
|
||||
+ (self.max_imag - im) / self.span_imag * self.dim.height
|
||||
)
|
||||
|
||||
def getReYPosition(self, d: Datapoint) -> int:
|
||||
re = self.value(d).real
|
||||
return int(
|
||||
self.topMargin
|
||||
+ (self.max_real - re) / self.span_real * self.dim.height
|
||||
if math.isfinite(re)
|
||||
else self.topMargin
|
||||
)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
valRe = -1 * ((absy / self.dim.height * self.span_real) - self.max_real)
|
||||
valIm = -1 * ((absy / self.dim.height * self.span_imag) - self.max_imag)
|
||||
return [valRe, valIm]
|
||||
|
||||
def zoomTo(self, x1, y1, x2, y2):
|
||||
val1 = self.valueAtPosition(y1)
|
||||
val2 = self.valueAtPosition(y2)
|
||||
|
||||
if len(val1) == len(val2) == 2 and val1[0] != val2[0]:
|
||||
self.minDisplayReal = round(min(val1[0], val2[0]), 2)
|
||||
self.maxDisplayReal = round(max(val1[0], val2[0]), 2)
|
||||
self.minDisplayImag = round(min(val1[1], val2[1]), 2)
|
||||
self.maxDisplayImag = round(max(val1[1], val2[1]), 2)
|
||||
self.setFixedValues(True)
|
||||
|
||||
freq1 = max(1, self.frequencyAtPosition(x1, limit=False))
|
||||
freq2 = max(1, self.frequencyAtPosition(x2, limit=False))
|
||||
|
||||
if freq1 > 0 and freq2 > 0 and freq1 != freq2:
|
||||
self.minFrequency = min(freq1, freq2)
|
||||
self.maxFrequency = max(freq1, freq2)
|
||||
self.setFixedSpan(True)
|
||||
|
||||
self.update()
|
||||
|
||||
def getNearestMarker(self, x, y) -> Marker | None:
|
||||
if not self.data:
|
||||
return None
|
||||
shortest = 10e6
|
||||
nearest = None
|
||||
for m in self.markers:
|
||||
mx, _ = self.getPosition(self.data[m.location])
|
||||
myr = self.getReYPosition(self.data[m.location])
|
||||
myi = self.getImYPosition(self.data[m.location])
|
||||
dx = abs(x - mx)
|
||||
dy = min(abs(y - myr), abs(y - myi))
|
||||
distance = math.sqrt(dx**2 + dy**2)
|
||||
if distance < shortest:
|
||||
shortest = distance
|
||||
nearest = m
|
||||
return nearest
|
||||
|
||||
def setMinimumRealValue(self):
|
||||
min_val, selected = QtWidgets.QInputDialog.getDouble(
|
||||
self,
|
||||
"Minimum real value",
|
||||
"Set minimum real value",
|
||||
value=self.minDisplayReal,
|
||||
decimals=2,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and min_val >= self.maxDisplayReal):
|
||||
self.minDisplayReal = min_val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def setMaximumRealValue(self):
|
||||
max_val, selected = QtWidgets.QInputDialog.getDouble(
|
||||
self,
|
||||
"Maximum real value",
|
||||
"Set maximum real value",
|
||||
value=self.maxDisplayReal,
|
||||
decimals=2,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and max_val <= self.minDisplayReal):
|
||||
self.maxDisplayReal = max_val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def setMinimumImagValue(self):
|
||||
min_val, selected = QtWidgets.QInputDialog.getDouble(
|
||||
self,
|
||||
"Minimum imaginary value",
|
||||
"Set minimum imaginary value",
|
||||
value=self.minDisplayImag,
|
||||
decimals=2,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and min_val >= self.maxDisplayImag):
|
||||
self.minDisplayImag = min_val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def setMaximumImagValue(self):
|
||||
max_val, selected = QtWidgets.QInputDialog.getDouble(
|
||||
self,
|
||||
"Maximum imaginary value",
|
||||
"Set maximum imaginary value",
|
||||
value=self.maxDisplayImag,
|
||||
decimals=2,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and max_val <= self.minDisplayImag):
|
||||
self.maxDisplayImag = max_val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def setFixedValues(self, fixed_values: bool):
|
||||
self.fixedValues = fixed_values
|
||||
if fixed_values and (
|
||||
self.minDisplayReal >= self.maxDisplayReal
|
||||
or self.minDisplayImag > self.maxDisplayImag
|
||||
):
|
||||
self.fixedValues = False
|
||||
self.y_action_automatic.setChecked(True)
|
||||
self.y_action_fixed_span.setChecked(False)
|
||||
self.update()
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
self.action_set_fixed_start.setText(
|
||||
f"Start ({format_frequency_chart(self.minFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_stop.setText(
|
||||
f"Stop ({format_frequency_chart(self.maxFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_minimum_real.setText(
|
||||
f"Minimum R ({self.minDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_maximum_real.setText(
|
||||
f"Maximum R ({self.maxDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_minimum_imag.setText(
|
||||
f"Minimum jX ({self.minDisplayImag})"
|
||||
)
|
||||
self.action_set_fixed_maximum_imag.setText(
|
||||
f"Maximum jX ({self.maxDisplayImag})"
|
||||
)
|
||||
self.menu.exec(event.globalPos())
|
||||
|
||||
def value(self, p: Datapoint) -> complex:
|
||||
raise NotImplementedError()
|
|
@ -1,201 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import numpy as np
|
||||
import logging
|
||||
from scipy.constants import mu_0
|
||||
|
||||
from PyQt6 import QtWidgets, QtGui
|
||||
|
||||
from NanoVNASaver.Formatting import format_frequency_chart
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.RI import RealImaginaryChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MU = "\N{GREEK SMALL LETTER MU}"
|
||||
|
||||
|
||||
class RealImaginaryMuChart(RealImaginaryChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
self.y_menu.addSeparator()
|
||||
|
||||
self.action_set_fixed_maximum_real = QtGui.QAction(
|
||||
f"Maximum {MU}' ({self.maxDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_maximum_real.triggered.connect(
|
||||
self.setMaximumRealValue
|
||||
)
|
||||
|
||||
self.action_set_fixed_minimum_real = QtGui.QAction(
|
||||
f"Minimum {MU}' ({self.minDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_minimum_real.triggered.connect(
|
||||
self.setMinimumRealValue
|
||||
)
|
||||
|
||||
self.action_set_fixed_maximum_imag = QtGui.QAction(
|
||||
f"Maximum {MU}'' ({self.maxDisplayImag})"
|
||||
)
|
||||
self.action_set_fixed_maximum_imag.triggered.connect(
|
||||
self.setMaximumImagValue
|
||||
)
|
||||
|
||||
self.action_set_fixed_minimum_imag = QtGui.QAction(
|
||||
f"Minimum {MU}'' ({self.minDisplayImag})"
|
||||
)
|
||||
self.action_set_fixed_minimum_imag.triggered.connect(
|
||||
self.setMinimumImagValue
|
||||
)
|
||||
|
||||
self.y_menu.addAction(self.action_set_fixed_maximum_real)
|
||||
self.y_menu.addAction(self.action_set_fixed_minimum_real)
|
||||
self.y_menu.addSeparator()
|
||||
self.y_menu.addAction(self.action_set_fixed_maximum_imag)
|
||||
self.y_menu.addAction(self.action_set_fixed_minimum_imag)
|
||||
|
||||
# Manage core parameters
|
||||
# TODO pick some sane default values?
|
||||
self.coreLength = 1.0
|
||||
self.coreArea = 1.0
|
||||
self.coreWindings = 1
|
||||
|
||||
self.menu.addSeparator()
|
||||
self.action_set_core_length = QtGui.QAction("Core effective length")
|
||||
self.action_set_core_length.triggered.connect(self.setCoreLength)
|
||||
|
||||
self.action_set_core_area = QtGui.QAction("Core area")
|
||||
self.action_set_core_area.triggered.connect(self.setCoreArea)
|
||||
|
||||
self.action_set_core_windings = QtGui.QAction("Core number of windings")
|
||||
self.action_set_core_windings.triggered.connect(self.setCoreWindings)
|
||||
|
||||
self.menu.addAction(self.action_set_core_length)
|
||||
self.menu.addAction(self.action_set_core_area)
|
||||
self.menu.addAction(self.action_set_core_windings)
|
||||
|
||||
def copy(self):
|
||||
new_chart: RealImaginaryMuChart = super().copy()
|
||||
|
||||
new_chart.coreLength = self.coreLength
|
||||
new_chart.coreArea = self.coreArea
|
||||
new_chart.coreWindings = self.coreWindings
|
||||
|
||||
return new_chart
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(self.leftMargin + 5, 15, f"{self.name}")
|
||||
qp.drawText(5, 15, f"{MU}'")
|
||||
qp.drawText(self.leftMargin + self.dim.width + 10, 15, f"{MU}''")
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin,
|
||||
self.topMargin - 5,
|
||||
self.leftMargin,
|
||||
self.topMargin + self.dim.height + 5,
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin + self.dim.height,
|
||||
self.leftMargin + self.dim.width + 5,
|
||||
self.topMargin + self.dim.height,
|
||||
)
|
||||
self.drawTitle(qp)
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
self.action_set_fixed_start.setText(
|
||||
f"Start ({format_frequency_chart(self.minFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_stop.setText(
|
||||
f"Stop ({format_frequency_chart(self.maxFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_minimum_real.setText(
|
||||
f"Minimum {MU}' ({self.minDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_maximum_real.setText(
|
||||
f"Maximum {MU}' ({self.maxDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_minimum_imag.setText(
|
||||
f"Minimum {MU}'' ({self.minDisplayImag})"
|
||||
)
|
||||
self.action_set_fixed_maximum_imag.setText(
|
||||
f"Maximum {MU}'' ({self.maxDisplayImag})"
|
||||
)
|
||||
self.menu.exec(event.globalPos())
|
||||
|
||||
def setCoreLength(self):
|
||||
val, selected = QtWidgets.QInputDialog.getDouble(
|
||||
self,
|
||||
"Core effective length",
|
||||
"Set core effective length in mm",
|
||||
value=self.coreLength,
|
||||
decimals=2,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and val >= 0):
|
||||
self.coreLength = val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def setCoreArea(self):
|
||||
val, selected = QtWidgets.QInputDialog.getDouble(
|
||||
self,
|
||||
"Core effective area",
|
||||
"Set core cross section area length in mm\N{SUPERSCRIPT TWO}",
|
||||
value=self.coreArea,
|
||||
decimals=2,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and val >= 0):
|
||||
self.coreArea = val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def setCoreWindings(self):
|
||||
val, selected = QtWidgets.QInputDialog.getInt(
|
||||
self,
|
||||
"Core number of windings",
|
||||
"Set core number of windings",
|
||||
value=self.coreWindings,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and val >= 0):
|
||||
self.coreWindings = val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def value(self, p: Datapoint) -> complex:
|
||||
return self.mu_r(p)
|
||||
|
||||
def mu_r(self, p: Datapoint) -> complex:
|
||||
inductance = p.impedance() / (2j * math.pi * p.freq)
|
||||
|
||||
# Core length and core area are in mm and mm2 respectively
|
||||
# note: mu_r = mu' - j * mu ''
|
||||
return np.conj(
|
||||
inductance
|
||||
* (self.coreLength / 1e3)
|
||||
/ (mu_0 * self.coreWindings**2 * (self.coreArea / 1e6))
|
||||
)
|
|
@ -1,116 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.Formatting import format_frequency_chart
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
|
||||
from .RI import RealImaginaryChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RealImaginaryZChart(RealImaginaryChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
self.y_menu.addSeparator()
|
||||
|
||||
self.action_set_fixed_maximum_real = QtGui.QAction(
|
||||
f"Maximum R ({self.maxDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_maximum_real.triggered.connect(
|
||||
self.setMaximumRealValue
|
||||
)
|
||||
|
||||
self.action_set_fixed_minimum_real = QtGui.QAction(
|
||||
f"Minimum R ({self.minDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_minimum_real.triggered.connect(
|
||||
self.setMinimumRealValue
|
||||
)
|
||||
|
||||
self.action_set_fixed_maximum_imag = QtGui.QAction(
|
||||
f"Maximum jX ({self.maxDisplayImag})"
|
||||
)
|
||||
self.action_set_fixed_maximum_imag.triggered.connect(
|
||||
self.setMaximumImagValue
|
||||
)
|
||||
|
||||
self.action_set_fixed_minimum_imag = QtGui.QAction(
|
||||
f"Minimum jX ({self.minDisplayImag})"
|
||||
)
|
||||
self.action_set_fixed_minimum_imag.triggered.connect(
|
||||
self.setMinimumImagValue
|
||||
)
|
||||
|
||||
self.y_menu.addAction(self.action_set_fixed_maximum_real)
|
||||
self.y_menu.addAction(self.action_set_fixed_minimum_real)
|
||||
self.y_menu.addSeparator()
|
||||
self.y_menu.addAction(self.action_set_fixed_maximum_imag)
|
||||
self.y_menu.addAction(self.action_set_fixed_minimum_imag)
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(self.leftMargin + 5, 15, f"{self.name} (\N{OHM SIGN})")
|
||||
qp.drawText(10, 15, "R")
|
||||
qp.drawText(self.leftMargin + self.dim.width + 10, 15, "X")
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin,
|
||||
self.topMargin - 5,
|
||||
self.leftMargin,
|
||||
self.topMargin + self.dim.height + 5,
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin + self.dim.height,
|
||||
self.leftMargin + self.dim.width + 5,
|
||||
self.topMargin + self.dim.height,
|
||||
)
|
||||
self.drawTitle(qp)
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
self.action_set_fixed_start.setText(
|
||||
f"Start ({format_frequency_chart(self.minFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_stop.setText(
|
||||
f"Stop ({format_frequency_chart(self.maxFrequency)})"
|
||||
)
|
||||
self.action_set_fixed_minimum_real.setText(
|
||||
f"Minimum R ({self.minDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_maximum_real.setText(
|
||||
f"Maximum R ({self.maxDisplayReal})"
|
||||
)
|
||||
self.action_set_fixed_minimum_imag.setText(
|
||||
f"Minimum jX ({self.minDisplayImag})"
|
||||
)
|
||||
self.action_set_fixed_maximum_imag.setText(
|
||||
f"Maximum jX ({self.maxDisplayImag})"
|
||||
)
|
||||
self.menu.exec(event.globalPos())
|
||||
|
||||
def value(self, p: Datapoint) -> complex:
|
||||
return self.impedance(p)
|
||||
|
||||
def impedance(self, p: Datapoint) -> complex:
|
||||
return p.impedance()
|
|
@ -1,29 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from .RIZ import RealImaginaryZChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RealImaginaryZSeriesChart(RealImaginaryZChart):
|
||||
def impedance(self, p: Datapoint) -> complex:
|
||||
return p.seriesImpedance()
|
|
@ -1,29 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from .RIZ import RealImaginaryZChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RealImaginaryZShuntChart(RealImaginaryZChart):
|
||||
def impedance(self, p: Datapoint) -> complex:
|
||||
return p.shuntImpedance()
|
|
@ -1,156 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
|
||||
from PyQt6 import QtGui
|
||||
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Frequency import FrequencyChart
|
||||
from NanoVNASaver.Charts.LogMag import LogMagChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SParameterChart(FrequencyChart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
|
||||
self.minDisplayValue = -1
|
||||
self.maxDisplayValue = 1
|
||||
self.fixedValues = True
|
||||
|
||||
self.y_action_automatic.setChecked(False)
|
||||
self.y_action_fixed_span.setChecked(True)
|
||||
|
||||
self.minValue = 0
|
||||
self.maxValue = 1
|
||||
self.span = 1
|
||||
|
||||
self.isInverted = False
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter):
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(self.dim.width // 2 - 20, 15, f"{self.name}")
|
||||
qp.drawText(10, 15, "Real")
|
||||
qp.drawText(self.leftMargin + self.dim.width - 15, 15, "Imag")
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin,
|
||||
self.topMargin - 5,
|
||||
self.leftMargin,
|
||||
self.topMargin + self.dim.height + 5,
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin + self.dim.height,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin + self.dim.height,
|
||||
)
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if len(self.data) == 0 and len(self.reference) == 0:
|
||||
return
|
||||
self._set_start_stop()
|
||||
if self.bands.enabled:
|
||||
self.drawBands(qp, self.fstart, self.fstop)
|
||||
if self.fixedValues:
|
||||
maxValue = self.maxDisplayValue
|
||||
minValue = self.minDisplayValue
|
||||
else:
|
||||
minValue = -1
|
||||
maxValue = 1
|
||||
self.minValue = minValue
|
||||
self.maxValue = maxValue
|
||||
span = maxValue - minValue
|
||||
if span == 0:
|
||||
span = 0.01
|
||||
self.span = span
|
||||
tick_count = self.dim.height // 60
|
||||
tick_step = self.span / tick_count
|
||||
for i in range(tick_count):
|
||||
val = int(minValue + i * tick_step)
|
||||
y = self.topMargin + (maxValue - val) // span * self.dim.height
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5, y, self.leftMargin + self.dim.width, y
|
||||
)
|
||||
if val > minValue and val != maxValue:
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(3, y + 4, str(round(val, 2)))
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.topMargin,
|
||||
self.leftMargin + self.dim.width,
|
||||
self.topMargin,
|
||||
)
|
||||
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(3, self.topMargin + 4, f"{maxValue}")
|
||||
qp.drawText(3, self.dim.height + self.topMargin, f"{minValue}")
|
||||
self.drawFrequencyTicks(qp)
|
||||
self.drawData(qp, self.data, Chart.color.sweep, self.getReYPosition)
|
||||
self.drawData(
|
||||
qp, self.reference, Chart.color.reference, self.getReYPosition
|
||||
)
|
||||
self.drawData(
|
||||
qp, self.data, Chart.color.sweep_secondary, self.getImYPosition
|
||||
)
|
||||
self.drawData(
|
||||
qp,
|
||||
self.reference,
|
||||
Chart.color.reference_secondary,
|
||||
self.getImYPosition,
|
||||
)
|
||||
|
||||
self.drawMarkers(qp, y_function=self.getReYPosition)
|
||||
self.drawMarkers(qp, y_function=self.getImYPosition)
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
return int(
|
||||
self.topMargin
|
||||
+ (self.maxValue - d.re) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def getReYPosition(self, d: Datapoint) -> int:
|
||||
return int(
|
||||
self.topMargin
|
||||
+ (self.maxValue - d.re) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def getImYPosition(self, d: Datapoint) -> int:
|
||||
return int(
|
||||
self.topMargin
|
||||
+ (self.maxValue - d.im) / self.span * self.dim.height
|
||||
)
|
||||
|
||||
def valueAtPosition(self, y) -> list[float]:
|
||||
absy = y - self.topMargin
|
||||
val = -1 * ((absy / self.dim.height * self.span) - self.maxValue)
|
||||
return [val]
|
||||
|
||||
def logMag(self, p: Datapoint) -> float:
|
||||
return -p.gain if self.isInverted else p.gain
|
||||
|
||||
def copy(self):
|
||||
new_chart: LogMagChart = super().copy()
|
||||
new_chart.isInverted = self.isInverted
|
||||
new_chart.span = self.span
|
||||
return new_chart
|
|
@ -1,165 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020ff NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
from PyQt6 import QtGui, QtCore
|
||||
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.Charts.Square import SquareChart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SmithChart(SquareChart):
|
||||
def drawChart(self, qp: QtGui.QPainter) -> None:
|
||||
center_x = self.width() // 2
|
||||
center_y = self.height() // 2
|
||||
width_2 = self.dim.width // 2
|
||||
height_2 = self.dim.height // 2
|
||||
qp.setPen(QtGui.QPen(Chart.color.text))
|
||||
qp.drawText(3, 15, self.name)
|
||||
qp.setPen(QtGui.QPen(Chart.color.foreground))
|
||||
qp.drawEllipse(QtCore.QPoint(center_x, center_y), width_2, height_2)
|
||||
qp.drawLine(center_x - width_2, center_y, center_x + width_2, center_y)
|
||||
|
||||
qp.drawEllipse(
|
||||
QtCore.QPoint(center_x + int(self.dim.width / 4), center_y),
|
||||
self.dim.width // 4,
|
||||
self.dim.height // 4,
|
||||
) # Re(Z) = 1
|
||||
qp.drawEllipse(
|
||||
QtCore.QPoint(center_x + self.dim.width // 3, center_y),
|
||||
self.dim.width // 6,
|
||||
self.dim.height // 6,
|
||||
) # Re(Z) = 2
|
||||
qp.drawEllipse(
|
||||
QtCore.QPoint(center_x + 3 * self.dim.width // 8, center_y),
|
||||
self.dim.width // 8,
|
||||
self.dim.height // 8,
|
||||
) # Re(Z) = 3
|
||||
qp.drawEllipse(
|
||||
QtCore.QPoint(center_x + 5 * self.dim.width // 12, center_y),
|
||||
self.dim.width // 12,
|
||||
self.dim.height // 12,
|
||||
) # Re(Z) = 5
|
||||
qp.drawEllipse(
|
||||
QtCore.QPoint(center_x + self.dim.width // 6, center_y),
|
||||
self.dim.width // 3,
|
||||
self.dim.height // 3,
|
||||
) # Re(Z) = 0.5
|
||||
qp.drawEllipse(
|
||||
QtCore.QPoint(center_x + self.dim.width // 12, center_y),
|
||||
5 * self.dim.width // 12,
|
||||
5 * self.dim.height // 12,
|
||||
) # Re(Z) = 0.2
|
||||
|
||||
qp.drawArc(
|
||||
center_x + 3 * self.dim.width // 8,
|
||||
center_y,
|
||||
self.dim.width // 4,
|
||||
self.dim.width // 4,
|
||||
90 * 16,
|
||||
152 * 16,
|
||||
) # Im(Z) = -5
|
||||
qp.drawArc(
|
||||
center_x + 3 * self.dim.width // 8,
|
||||
center_y,
|
||||
self.dim.width // 4,
|
||||
-self.dim.width // 4,
|
||||
-90 * 16,
|
||||
-152 * 16,
|
||||
) # Im(Z) = 5
|
||||
qp.drawArc(
|
||||
center_x + self.dim.width // 4,
|
||||
center_y,
|
||||
width_2,
|
||||
height_2,
|
||||
90 * 16,
|
||||
127 * 16,
|
||||
) # Im(Z) = -2
|
||||
qp.drawArc(
|
||||
center_x + self.dim.width // 4,
|
||||
center_y,
|
||||
width_2,
|
||||
-height_2,
|
||||
-90 * 16,
|
||||
-127 * 16,
|
||||
) # Im(Z) = 2
|
||||
qp.drawArc(
|
||||
center_x,
|
||||
center_y,
|
||||
self.dim.width,
|
||||
self.dim.height,
|
||||
90 * 16,
|
||||
90 * 16,
|
||||
) # Im(Z) = -1
|
||||
qp.drawArc(
|
||||
center_x,
|
||||
center_y,
|
||||
self.dim.width,
|
||||
-self.dim.height,
|
||||
-90 * 16,
|
||||
-90 * 16,
|
||||
) # Im(Z) = 1
|
||||
qp.drawArc(
|
||||
center_x - width_2,
|
||||
center_y,
|
||||
self.dim.width * 2,
|
||||
self.dim.height * 2,
|
||||
int(99.5 * 16),
|
||||
int(43.5 * 16),
|
||||
) # Im(Z) = -0.5
|
||||
qp.drawArc(
|
||||
center_x - width_2,
|
||||
center_y,
|
||||
self.dim.width * 2,
|
||||
-self.dim.height * 2,
|
||||
int(-99.5 * 16),
|
||||
int(-43.5 * 16),
|
||||
) # Im(Z) = 0.5
|
||||
qp.drawArc(
|
||||
center_x - self.dim.width * 2,
|
||||
center_y,
|
||||
self.dim.width * 5,
|
||||
self.dim.height * 5,
|
||||
int(93.85 * 16),
|
||||
int(18.85 * 16),
|
||||
) # Im(Z) = -0.2
|
||||
qp.drawArc(
|
||||
center_x - self.dim.width * 2,
|
||||
center_y,
|
||||
self.dim.width * 5,
|
||||
-self.dim.height * 5,
|
||||
int(-93.85 * 16),
|
||||
int(-18.85 * 16),
|
||||
) # Im(Z) = 0.2
|
||||
|
||||
self.drawTitle(qp)
|
||||
|
||||
qp.setPen(Chart.color.swr)
|
||||
for swr in self.swrMarkers:
|
||||
if swr <= 1:
|
||||
continue
|
||||
gamma = (swr - 1) / (swr + 1)
|
||||
r = int(gamma * self.dim.width / 2)
|
||||
qp.drawEllipse(QtCore.QPoint(center_x, center_y), r, r)
|
||||
qp.drawText(
|
||||
QtCore.QRect(center_x - 50, center_y - 4 + r, 100, 20),
|
||||
QtCore.Qt.AlignmentFlag.AlignCenter,
|
||||
f"{swr}",
|
||||
)
|
|
@ -1,161 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import logging
|
||||
import math
|
||||
|
||||
from PyQt6 import QtGui, QtCore, QtWidgets
|
||||
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
from NanoVNASaver.RFTools import Datapoint
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class SquareChart(Chart):
|
||||
def __init__(self, name=""):
|
||||
super().__init__(name)
|
||||
sizepolicy = QtWidgets.QSizePolicy(
|
||||
QtWidgets.QSizePolicy.Policy.Fixed,
|
||||
QtWidgets.QSizePolicy.Policy.MinimumExpanding,
|
||||
)
|
||||
self.setSizePolicy(sizepolicy)
|
||||
self.dim.width = 250
|
||||
self.dim.height = 250
|
||||
self.setMinimumSize(self.dim.width + 40, self.dim.height + 40)
|
||||
|
||||
pal = QtGui.QPalette()
|
||||
pal.setColor(QtGui.QPalette.ColorRole.Window, Chart.color.background)
|
||||
self.setPalette(pal)
|
||||
self.setAutoFillBackground(True)
|
||||
|
||||
def paintEvent(self, _: QtGui.QPaintEvent) -> None:
|
||||
qp = QtGui.QPainter(self)
|
||||
self.drawChart(qp)
|
||||
self.drawValues(qp)
|
||||
qp.end()
|
||||
|
||||
def drawChart(self, qp: QtGui.QPainter) -> None:
|
||||
raise NotImplementedError()
|
||||
|
||||
def draw_data(
|
||||
self,
|
||||
qp: QtGui.QPainter,
|
||||
color: QtGui.QColor,
|
||||
data: list[Datapoint],
|
||||
fstart: int = 0,
|
||||
fstop: int = 0,
|
||||
):
|
||||
if not data:
|
||||
return
|
||||
fstop = fstop or data[-1].freq
|
||||
pen = QtGui.QPen(color)
|
||||
pen.setWidth(self.dim.point)
|
||||
line_pen = QtGui.QPen(color)
|
||||
line_pen.setWidth(self.dim.line)
|
||||
|
||||
qp.setPen(pen)
|
||||
prev_x = self.getXPosition(data[0])
|
||||
prev_y = int(self.height() / 2 + data[0].im * -1 * self.dim.height / 2)
|
||||
for i, d in enumerate(data):
|
||||
x = self.getXPosition(d)
|
||||
y = int(self.height() / 2 + d.im * -1 * self.dim.height / 2)
|
||||
if d.freq > fstart and d.freq < fstop:
|
||||
qp.drawPoint(x, y)
|
||||
if self.flag.draw_lines and i > 0:
|
||||
qp.setPen(line_pen)
|
||||
qp.drawLine(x, y, prev_x, prev_y)
|
||||
qp.setPen(pen)
|
||||
prev_x, prev_y = x, y
|
||||
|
||||
def drawValues(self, qp: QtGui.QPainter):
|
||||
if not (self.data or self.reference):
|
||||
return
|
||||
self.draw_data(qp, Chart.color.sweep, self.data)
|
||||
|
||||
fstart = self.data[0].freq if self.data else 0
|
||||
fstop = self.data[-1].freq if self.data else 0
|
||||
self.draw_data(qp, Chart.color.reference, self.reference, fstart, fstop)
|
||||
|
||||
for m in self.markers:
|
||||
if m.location != -1 and m.location < len(self.data):
|
||||
x = self.getXPosition(self.data[m.location])
|
||||
y = int(
|
||||
self.height() // 2
|
||||
- self.data[m.location].im * self.dim.height // 2
|
||||
)
|
||||
self.drawMarker(x, y, qp, m.color, self.markers.index(m) + 1)
|
||||
|
||||
def resizeEvent(self, a0: QtGui.QResizeEvent) -> None:
|
||||
if not self.flag.is_popout:
|
||||
self.setFixedWidth(a0.size().height())
|
||||
self.dim.width = a0.size().height() - 40
|
||||
self.dim.height = a0.size().height() - 40
|
||||
else:
|
||||
min_dimension = min(a0.size().height(), a0.size().width())
|
||||
self.dim.width = self.dim.height = min_dimension - 40
|
||||
self.update()
|
||||
|
||||
def mouseMoveEvent(self, a0: QtGui.QMouseEvent):
|
||||
if a0.buttons() == QtCore.Qt.MouseButton.RightButton:
|
||||
a0.ignore()
|
||||
return
|
||||
|
||||
x = a0.position().x()
|
||||
y = a0.position().y()
|
||||
absx = x - (self.width() - self.dim.width) / 2
|
||||
absy = y - (self.height() - self.dim.height) / 2
|
||||
if (
|
||||
absx < 0
|
||||
or absx > self.dim.width
|
||||
or absy < 0
|
||||
or absy > self.dim.height
|
||||
or (not self.data and not self.reference)
|
||||
):
|
||||
a0.ignore()
|
||||
return
|
||||
a0.accept()
|
||||
|
||||
target = self.data or self.reference
|
||||
positions = []
|
||||
|
||||
dim_x_2 = self.dim.width / 2
|
||||
dim_y_2 = self.dim.height / 2
|
||||
width_2 = self.width() / 2
|
||||
height_2 = self.height() / 2
|
||||
|
||||
positions = [
|
||||
math.sqrt(
|
||||
(x - (width_2 + d.re * dim_x_2)) ** 2
|
||||
+ (y - (height_2 - d.im * dim_y_2)) ** 2
|
||||
)
|
||||
for d in target
|
||||
]
|
||||
|
||||
minimum_position = positions.index(min(positions))
|
||||
if m := self.getActiveMarker():
|
||||
m.setFrequency(str(round(target[minimum_position].freq)))
|
||||
|
||||
def getXPosition(self, d: Datapoint) -> int:
|
||||
return int(self.width() / 2 + d.re * self.dim.width / 2)
|
||||
|
||||
def getYPosition(self, d: Datapoint) -> int:
|
||||
return int(self.height() / 2 + d.im * -1 * self.dim.height / 2)
|
||||
|
||||
def zoomTo(self, x1, y1, x2, y2):
|
||||
pass
|
|
@ -1,560 +0,0 @@
|
|||
# NanoVNASaver
|
||||
#
|
||||
# A python program to view and export Touchstone data from a NanoVNA
|
||||
# Copyright (C) 2019, 2020 Rune B. Broberg
|
||||
# Copyright (C) 2020,2021 NanoVNA-Saver Authors
|
||||
#
|
||||
# This program 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 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
import math
|
||||
import logging
|
||||
|
||||
import numpy as np
|
||||
from PyQt6.QtCore import QPoint, QRect, Qt
|
||||
from PyQt6.QtGui import (
|
||||
QAction,
|
||||
QActionGroup,
|
||||
QMouseEvent,
|
||||
QPalette,
|
||||
QPainter,
|
||||
QPaintEvent,
|
||||
QPen,
|
||||
QResizeEvent,
|
||||
)
|
||||
from PyQt6.QtWidgets import QInputDialog, QMenu, QSizePolicy
|
||||
|
||||
from NanoVNASaver.Charts.Chart import Chart
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TDRChart(Chart):
|
||||
maxDisplayLength = 50
|
||||
minDisplayLength = 0
|
||||
fixedSpan = False
|
||||
|
||||
minImpedance = 0
|
||||
maxImpedance = 1000
|
||||
fixedValues = False
|
||||
|
||||
markerLocation = -1
|
||||
|
||||
def __init__(self, name):
|
||||
super().__init__(name)
|
||||
self.tdrWindow = None
|
||||
|
||||
self.bottomMargin = 25
|
||||
self.topMargin = 20
|
||||
|
||||
self.setMinimumSize(300, 300)
|
||||
self.setSizePolicy(
|
||||
QSizePolicy(
|
||||
QSizePolicy.Policy.MinimumExpanding,
|
||||
QSizePolicy.Policy.MinimumExpanding,
|
||||
)
|
||||
)
|
||||
pal = QPalette()
|
||||
pal.setColor(QPalette.ColorRole.Window, Chart.color.background)
|
||||
self.setPalette(pal)
|
||||
self.setAutoFillBackground(True)
|
||||
|
||||
self.setContextMenuPolicy(Qt.ContextMenuPolicy.DefaultContextMenu)
|
||||
self.menu = QMenu()
|
||||
|
||||
self.reset = QAction("Reset")
|
||||
self.reset.triggered.connect(self.resetDisplayLimits)
|
||||
self.menu.addAction(self.reset)
|
||||
|
||||
self.x_menu = QMenu("Length axis")
|
||||
self.mode_group = QActionGroup(self.x_menu)
|
||||
self.action_automatic = QAction("Automatic")
|
||||
self.action_automatic.setCheckable(True)
|
||||
self.action_automatic.setChecked(True)
|
||||
self.action_automatic.changed.connect(
|
||||
lambda: self.setFixedSpan(self.action_fixed_span.isChecked())
|
||||
)
|
||||
self.action_fixed_span = QAction("Fixed span")
|
||||
self.action_fixed_span.setCheckable(True)
|
||||
self.action_fixed_span.changed.connect(
|
||||
lambda: self.setFixedSpan(self.action_fixed_span.isChecked())
|
||||
)
|
||||
self.mode_group.addAction(self.action_automatic)
|
||||
self.mode_group.addAction(self.action_fixed_span)
|
||||
self.x_menu.addAction(self.action_automatic)
|
||||
self.x_menu.addAction(self.action_fixed_span)
|
||||
self.x_menu.addSeparator()
|
||||
|
||||
self.action_set_fixed_start = QAction(
|
||||
f"Start ({self.minDisplayLength})"
|
||||
)
|
||||
self.action_set_fixed_start.triggered.connect(self.setMinimumLength)
|
||||
|
||||
self.action_set_fixed_stop = QAction(f"Stop ({self.maxDisplayLength})")
|
||||
self.action_set_fixed_stop.triggered.connect(self.setMaximumLength)
|
||||
|
||||
self.x_menu.addAction(self.action_set_fixed_start)
|
||||
self.x_menu.addAction(self.action_set_fixed_stop)
|
||||
|
||||
self.y_menu = QMenu("Impedance axis")
|
||||
self.y_mode_group = QActionGroup(self.y_menu)
|
||||
self.y_action_automatic = QAction("Automatic")
|
||||
self.y_action_automatic.setCheckable(True)
|
||||
self.y_action_automatic.setChecked(True)
|
||||
self.y_action_automatic.changed.connect(
|
||||
lambda: self.setFixedValues(self.y_action_fixed.isChecked())
|
||||
)
|
||||
self.y_action_fixed = QAction("Fixed")
|
||||
self.y_action_fixed.setCheckable(True)
|
||||
self.y_action_fixed.changed.connect(
|
||||
lambda: self.setFixedValues(self.y_action_fixed.isChecked())
|
||||
)
|
||||
self.y_mode_group.addAction(self.y_action_automatic)
|
||||
self.y_mode_group.addAction(self.y_action_fixed)
|
||||
self.y_menu.addAction(self.y_action_automatic)
|
||||
self.y_menu.addAction(self.y_action_fixed)
|
||||
self.y_menu.addSeparator()
|
||||
|
||||
self.y_action_set_fixed_maximum = QAction(
|
||||
f"Maximum ({self.maxImpedance})"
|
||||
)
|
||||
self.y_action_set_fixed_maximum.triggered.connect(
|
||||
self.setMaximumImpedance
|
||||
)
|
||||
|
||||
self.y_action_set_fixed_minimum = QAction(
|
||||
f"Minimum ({self.minImpedance})"
|
||||
)
|
||||
self.y_action_set_fixed_minimum.triggered.connect(
|
||||
self.setMinimumImpedance
|
||||
)
|
||||
|
||||
self.y_menu.addAction(self.y_action_set_fixed_maximum)
|
||||
self.y_menu.addAction(self.y_action_set_fixed_minimum)
|
||||
|
||||
self.menu.addMenu(self.x_menu)
|
||||
self.menu.addMenu(self.y_menu)
|
||||
self.menu.addSeparator()
|
||||
self.menu.addAction(self.action_save_screenshot)
|
||||
self.action_popout = QAction("Popout chart")
|
||||
self.action_popout.triggered.connect(
|
||||
lambda: self.popoutRequested.emit(self)
|
||||
)
|
||||
self.menu.addAction(self.action_popout)
|
||||
|
||||
self.dim.width = self.width() - self.leftMargin - self.rightMargin
|
||||
self.dim.height = self.height() - self.bottomMargin - self.topMargin
|
||||
|
||||
def contextMenuEvent(self, event):
|
||||
self.action_set_fixed_start.setText(f"Start ({self.minDisplayLength})")
|
||||
self.action_set_fixed_stop.setText(f"Stop ({self.maxDisplayLength})")
|
||||
self.y_action_set_fixed_minimum.setText(
|
||||
f"Minimum ({self.minImpedance})"
|
||||
)
|
||||
self.y_action_set_fixed_maximum.setText(
|
||||
f"Maximum ({self.maxImpedance})"
|
||||
)
|
||||
self.menu.exec(event.globalPos())
|
||||
|
||||
def isPlotable(self, x, y):
|
||||
return (
|
||||
self.leftMargin <= x <= self.width() - self.rightMargin
|
||||
and self.topMargin <= y <= self.height() - self.bottomMargin
|
||||
)
|
||||
|
||||
def resetDisplayLimits(self):
|
||||
self.fixedSpan = False
|
||||
self.minDisplayLength = 0
|
||||
self.maxDisplayLength = 100
|
||||
self.fixedValues = False
|
||||
self.minImpedance = 0
|
||||
self.maxImpedance = 1000
|
||||
self.update()
|
||||
|
||||
def setFixedSpan(self, fixed_span):
|
||||
self.fixedSpan = fixed_span
|
||||
self.update()
|
||||
|
||||
def setMinimumLength(self):
|
||||
min_val, selected = QInputDialog.getDouble(
|
||||
self,
|
||||
"Start length (m)",
|
||||
"Set start length (m)",
|
||||
value=self.minDisplayLength,
|
||||
min=0,
|
||||
decimals=1,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedSpan and min_val >= self.maxDisplayLength):
|
||||
self.minDisplayLength = min_val
|
||||
if self.fixedSpan:
|
||||
self.update()
|
||||
|
||||
def setMaximumLength(self):
|
||||
max_val, selected = QInputDialog.getDouble(
|
||||
self,
|
||||
"Stop length (m)",
|
||||
"Set stop length (m)",
|
||||
value=self.minDisplayLength,
|
||||
min=0.1,
|
||||
decimals=1,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedSpan and max_val <= self.minDisplayLength):
|
||||
self.maxDisplayLength = max_val
|
||||
if self.fixedSpan:
|
||||
self.update()
|
||||
|
||||
def setFixedValues(self, fixed_values):
|
||||
self.fixedValues = fixed_values
|
||||
self.update()
|
||||
|
||||
def setMinimumImpedance(self):
|
||||
min_val, selected = QInputDialog.getDouble(
|
||||
self,
|
||||
"Minimum impedance (\N{OHM SIGN})",
|
||||
"Set minimum impedance (\N{OHM SIGN})",
|
||||
value=self.minDisplayLength,
|
||||
min=0,
|
||||
decimals=1,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and min_val >= self.maxImpedance):
|
||||
self.minImpedance = min_val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def setMaximumImpedance(self):
|
||||
max_val, selected = QInputDialog.getDouble(
|
||||
self,
|
||||
"Maximum impedance (\N{OHM SIGN})",
|
||||
"Set maximum impedance (\N{OHM SIGN})",
|
||||
value=self.minDisplayLength,
|
||||
min=0.1,
|
||||
decimals=1,
|
||||
)
|
||||
if not selected:
|
||||
return
|
||||
if not (self.fixedValues and max_val <= self.minImpedance):
|
||||
self.maxImpedance = max_val
|
||||
if self.fixedValues:
|
||||
self.update()
|
||||
|
||||
def copy(self):
|
||||
new_chart: TDRChart = super().copy()
|
||||
new_chart.tdrWindow = self.tdrWindow
|
||||
new_chart.minDisplayLength = self.minDisplayLength
|
||||
new_chart.maxDisplayLength = self.maxDisplayLength
|
||||
new_chart.fixedSpan = self.fixedSpan
|
||||
new_chart.minImpedance = self.minImpedance
|
||||
new_chart.maxImpedance = self.maxImpedance
|
||||
new_chart.fixedValues = self.fixedValues
|
||||
self.tdrWindow.updated.connect(new_chart.update)
|
||||
return new_chart
|
||||
|
||||
def mouseMoveEvent(self, a0: QMouseEvent) -> None:
|
||||
if a0.buttons() == Qt.MouseButton.RightButton:
|
||||
a0.ignore()
|
||||
return
|
||||
if a0.buttons() == Qt.MouseButton.MiddleButton:
|
||||
# Drag the display
|
||||
a0.accept()
|
||||
if self.dragbox.move_x != -1 and self.dragbox.move_y != -1:
|
||||
dx = self.dragbox.move_x - a0.position().x()
|
||||
dy = self.dragbox.move_y - a0.position().y()
|
||||
self.zoomTo(
|
||||
self.leftMargin + dx,
|
||||
self.topMargin + dy,
|
||||
self.leftMargin + self.dim.width + dx,
|
||||
self.topMargin + self.dim.height + dy,
|
||||
)
|
||||
self.dragbox.move_x = a0.position().x()
|
||||
self.dragbox.move_y = a0.position().y()
|
||||
return
|
||||
if a0.modifiers() == Qt.KeyboardModifier.ControlModifier:
|
||||
# Dragging a box
|
||||
if not self.dragbox.state:
|
||||
self.dragbox.pos_start = (a0.position().x(), a0.position().y())
|
||||
self.dragbox.pos = (a0.position().x(), a0.position().y())
|
||||
self.update()
|
||||
a0.accept()
|
||||
return
|
||||
|
||||
x = a0.position().x()
|
||||
absx = x - self.leftMargin
|
||||
if absx < 0 or absx > self.width() - self.rightMargin:
|
||||
a0.ignore()
|
||||
return
|
||||
a0.accept()
|
||||
width = self.width() - self.leftMargin - self.rightMargin
|
||||
if self.tdrWindow.td:
|
||||
if self.fixedSpan:
|
||||
max_index = np.searchsorted(
|
||||
self.tdrWindow.distance_axis, self.maxDisplayLength * 2
|
||||
)
|
||||
min_index = np.searchsorted(
|
||||
self.tdrWindow.distance_axis, self.minDisplayLength * 2
|
||||
)
|
||||
x_step = (max_index - min_index) / width
|
||||
else:
|
||||
max_index = math.ceil(len(self.tdrWindow.distance_axis) / 2)
|
||||
x_step = max_index / width
|
||||
|
||||
self.markerLocation = int(round(absx * x_step))
|
||||
self.update()
|
||||
return
|
||||
|
||||
def _draw_ticks(self, height, width, x_step, min_index):
|
||||
ticks = (self.width() - self.leftMargin) // 100
|
||||
qp = QPainter(self)
|
||||
for i in range(ticks):
|
||||
x = self.leftMargin + round((i + 1) * width / ticks)
|
||||
qp.setPen(QPen(Chart.color.foreground))
|
||||
qp.drawLine(x, self.topMargin, x, self.topMargin + height)
|
||||
qp.setPen(QPen(Chart.color.text))
|
||||
distance = (
|
||||
self.tdrWindow.distance_axis[
|
||||
min_index + int((x - self.leftMargin) * x_step) - 1
|
||||
]
|
||||
/ 2
|
||||
)
|
||||
qp.drawText(
|
||||
x - 15, self.topMargin + height + 15, f"{round(distance, 1)}m"
|
||||
)
|
||||
qp.setPen(QPen(Chart.color.text))
|
||||
qp.drawText(
|
||||
self.leftMargin - 10,
|
||||
self.topMargin + height + 15,
|
||||
f"{str(round(self.tdrWindow.distance_axis[min_index] / 2, 1))}m",
|
||||
)
|
||||
|
||||
def _draw_y_ticks(self, height, width, min_impedance, max_impedance):
|
||||
qp = QPainter(self)
|
||||
y_step = (max_impedance - min_impedance) / height
|
||||
y_ticks = math.floor(height / 60)
|
||||
y_tick_step = height / y_ticks
|
||||
for i in range(y_ticks):
|
||||
y = self.bottomMargin + int(i * y_tick_step)
|
||||
qp.setPen(Chart.color.foreground)
|
||||
qp.drawLine(self.leftMargin, y, self.leftMargin + width, y)
|
||||
y_val = max_impedance - y_step * i * y_tick_step
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(3, y + 3, str(round(y_val, 1)))
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(
|
||||
3, self.topMargin + height + 3, f"{round(min_impedance, 1)}"
|
||||
)
|
||||
|
||||
def _draw_max_point(self, height, x_step, y_step, min_index):
|
||||
qp = QPainter(self)
|
||||
id_max = np.argmax(self.tdrWindow.td)
|
||||
|
||||
max_point = QPoint(
|
||||
self.leftMargin + int((id_max - min_index) / x_step),
|
||||
(self.topMargin + height) - int(self.tdrWindow.td[id_max] / y_step),
|
||||
)
|
||||
|
||||
qp.setPen(self.markers[0].color)
|
||||
qp.drawEllipse(max_point, 2, 2)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawText(
|
||||
max_point.x() - 10,
|
||||
max_point.y() - 5,
|
||||
f"{round(self.tdrWindow.distance_axis[id_max] / 2, 2)}m",
|
||||
)
|
||||
|
||||
def _draw_marker(self, height, x_step, y_step, min_index):
|
||||
qp = QPainter(self)
|
||||
marker_point = QPoint(
|
||||
self.leftMargin + int((self.markerLocation - min_index) / x_step),
|
||||
(self.topMargin + height)
|
||||
- int(self.tdrWindow.td[self.markerLocation] / y_step),
|
||||
)
|
||||
qp.setPen(Chart.color.text)
|
||||
qp.drawEllipse(marker_point, 2, 2)
|
||||
qp.drawText(
|
||||
marker_point.x() - 10,
|
||||
marker_point.y() - 5,
|
||||
f"""{round(
|
||||
self.tdrWindow.distance_axis[self.markerLocation] / 2,
|
||||
2)}m""",
|
||||
)
|
||||
|
||||
def _draw_graph(self, height, width):
|
||||
min_index = 0
|
||||
max_index = math.ceil(len(self.tdrWindow.distance_axis) / 2)
|
||||
|
||||
if self.fixedSpan:
|
||||
max_length = max(0.1, self.maxDisplayLength)
|
||||
max_index = np.searchsorted(
|
||||
self.tdrWindow.distance_axis, max_length * 2
|
||||
)
|
||||
min_index = np.searchsorted(
|
||||
self.tdrWindow.distance_axis, self.minDisplayLength * 2
|
||||
)
|
||||
if max_index == min_index:
|
||||
if max_index < len(self.tdrWindow.distance_axis) - 1:
|
||||
max_index += 1
|
||||
else:
|
||||
min_index -= 1
|
||||
x_step = (max_index - min_index) / width
|
||||
|
||||
# TODO: Limit the search to the selected span?
|
||||
min_impedance = max(0, np.min(self.tdrWindow.step_response_Z) / 1.05)
|
||||
max_impedance = min(1000, np.max(self.tdrWindow.step_response_Z) * 1.05)
|
||||
if self.fixedValues:
|
||||
min_impedance = max(0, self.minImpedance)
|
||||
max_impedance = max(0.1, self.maxImpedance)
|
||||
|
||||
y_step = max(self.tdrWindow.td) * 1.1 / height or 1.0e-30
|
||||
|
||||
self._draw_ticks(height, width, x_step, min_index)
|
||||
self._draw_y_ticks(height, width, min_impedance, max_impedance)
|
||||
|
||||
qp = QPainter(self)
|
||||
pen = QPen(Chart.color.sweep)
|
||||
pen.setWidth(self.dim.point)
|
||||
qp.setPen(pen)
|
||||
|
||||
y_step = (max_impedance - min_impedance) / height
|
||||
for i in range(min_index, max_index):
|
||||
x = self.leftMargin + int((i - min_index) / x_step)
|
||||
y = (self.topMargin + height) - int(self.tdrWindow.td[i] / y_step)
|
||||
if self.isPlotable(x, y):
|
||||
pen.setColor(Chart.color.sweep)
|
||||
qp.setPen(pen)
|
||||
qp.drawPoint(x, y)
|
||||
|
||||
x = self.leftMargin + int((i - min_index) / x_step)
|
||||
y = (self.topMargin + height) - int(
|
||||
(self.tdrWindow.step_response_Z[i] - min_impedance) / y_step
|
||||
)
|
||||
if self.isPlotable(x, y):
|
||||
pen.setColor(Chart.color.sweep_secondary)
|
||||
qp.setPen(pen)
|
||||
qp.drawPoint(x, y)
|
||||
|
||||
self._draw_max_point(height, x_step, y_step, min_index)
|
||||
|
||||
if self.markerLocation != -1:
|
||||
self._draw_marker(height, x_step, y_step, min_index)
|
||||
|
||||
def paintEvent(self, _: QPaintEvent) -> None:
|
||||
qp = QPainter(self)
|
||||
qp.setPen(QPen(Chart.color.text))
|
||||
qp.drawText(3, 15, self.name)
|
||||
|
||||
width = self.width() - self.leftMargin - self.rightMargin
|
||||
height = self.height() - self.bottomMargin - self.topMargin
|
||||
|
||||
qp.setPen(QPen(Chart.color.foreground))
|
||||
qp.drawLine(
|
||||
self.leftMargin - 5,
|
||||
self.height() - self.bottomMargin,
|
||||
self.width() - self.rightMargin,
|
||||
self.height() - self.bottomMargin,
|
||||
)
|
||||
qp.drawLine(
|
||||
self.leftMargin,
|
||||
self.topMargin - 5,
|
||||
self.leftMargin,
|
||||
self.height() - self.bottomMargin + 5,
|
||||
)
|
||||
# Number of ticks does not include the origin
|
||||
self.drawTitle(qp)
|
||||
|
||||
if self.tdrWindow.td:
|
||||
self._draw_graph(height, width)
|
||||
|
||||
if self.dragbox.state and self.dragbox.pos[0] != -1:
|
||||
dashed_pen = QPen(Chart.color.foreground, 1, Qt.PenStyle.DashLine)
|
||||
qp.setPen(dashed_pen)
|
||||
qp.drawRect(
|
||||
QRect(
|
||||
QPoint(*self.dragbox.pos_start),
|
||||
QPoint(*self.dragbox.pos),
|
||||
)
|
||||
)
|
||||
|
||||
qp.end()
|
||||
|
||||
def valueAtPosition(self, y):
|
||||
if self.tdrWindow.td:
|
||||
height = self.height() - self.topMargin - self.bottomMargin
|
||||
absy = (self.height() - y) - self.bottomMargin
|
||||
if self.fixedValues:
|
||||
min_impedance = self.minImpedance
|
||||
max_impedance = self.maxImpedance
|
||||
else:
|
||||
min_impedance = max(
|
||||
0, np.min(self.tdrWindow.step_response_Z) / 1.05
|
||||
)
|
||||
max_impedance = min(
|
||||
1000, np.max(self.tdrWindow.step_response_Z) * 1.05
|
||||
)
|
||||
y_step = (max_impedance - min_impedance) / height
|
||||
return y_step * absy + min_impedance
|
||||
return 0
|
||||
|
||||
def lengthAtPosition(self, x, limit=True):
|
||||
if not self.tdrWindow.td:
|
||||
return 0
|
||||
width = self.width() - self.leftMargin - self.rightMargin
|
||||
absx = x - self.leftMargin
|
||||
min_length = self.minDisplayLength if self.fixedSpan else 0
|
||||
max_length = (
|
||||
self.maxDisplayLength
|
||||
if self.fixedSpan
|
||||
else (
|
||||
self.tdrWindow.distance_axis[
|
||||
math.ceil(len(self.tdrWindow.distance_axis) / 2)
|
||||
]
|
||||
/ 2
|
||||
)
|
||||
)
|
||||
|
||||
x_step = (max_length - min_length) / width
|
||||
if limit and absx < 0:
|
||||
return min_length
|
||||
return (
|
||||
max_length if limit and absx > width else absx * x_step + min_length
|
||||
)
|
||||
|
||||
def zoomTo(self, x1, y1, x2, y2):
|
||||
logger.debug(
|
||||
"Zoom to (x,y) by (x,y): (%d, %d) by (%d, %d)", x1, y1, x2, y2
|
||||
)
|
||||
val1 = self.valueAtPosition(y1)
|
||||
val2 = self.valueAtPosition(y2)
|
||||
|
||||
if val1 != val2:
|
||||
self.minImpedance = round(min(val1, val2), 3)
|
||||
self.maxImpedance = round(max(val1, val2), 3)
|
||||
self.setFixedValues(True)
|
||||
|
||||
len1 = max(0, self.lengthAtPosition(x1, limit=False))
|
||||
len2 = max(0, self.lengthAtPosition(x2, limit=False))
|
||||
|
||||
if len1 >= 0 and len2 >= 0 and len1 != len2:
|
||||
self.minDisplayLength = min(len1, len2)
|
||||
self.maxDisplayLength = max(len1, len2)
|
||||
self.setFixedSpan(True)
|
||||
|
||||
self.update()
|
||||
|
||||
def resizeEvent(self, a0: QResizeEvent) -> None:
|
||||
super().resizeEvent(a0)
|
||||
self.dim.width = self.width() - self.leftMargin - self.rightMargin
|
||||
self.dim.height = self.height() - self.bottomMargin - self.topMargin
|
Some files were not shown because too many files have changed in this diff Show More
Ładowanie…
Reference in New Issue