Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodocs #36

Merged
merged 10 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/build_documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: documentation

on: [push, pull_request, workflow_dispatch]

permissions:
contents: write

jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install dependencies
run: |
pip install sphinx sphinx_rtd_theme myst_parser sphinx-autoapi
- name: Sphinx build
run: |
sphinx-build doc/sphinx _build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
if: ${{ github.event_name == 'push' }}
with:
publish_branch: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: _build/
force_orphan: true
10 changes: 5 additions & 5 deletions .github/workflows/check-code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
env:
CLANG_FORMAT: clang-format-15
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends $CLANG_FORMAT && $CLANG_FORMAT --version
- name: Run clang-format
Expand All @@ -29,8 +29,8 @@ jobs:
cmake-formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install cmake-format
Expand All @@ -53,8 +53,8 @@ jobs:
python-formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install ruff
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand All @@ -43,7 +43,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# 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@v1
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v3
4 changes: 2 additions & 2 deletions .github/workflows/compile-without-helpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
name: Compile without helpers
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
miniconda-version: "latest"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
miniconda-version: "latest"
Expand All @@ -39,5 +39,5 @@ jobs:
run: pytest -v --color=yes --cov=hdtv --cov-report=xml tests

- name: Post Coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
if: matrix.python-version == '3.12' && matrix.root-version == '6.32.2'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.spyproject/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -56,7 +57,7 @@ junit.xml
*.log

# Sphinx documentation
docs/_build/
doc/sphinx/_build/

# PyBuilder
target/
Expand Down
70 changes: 70 additions & 0 deletions doc/guide/hdtv-tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,31 @@ To write all existing calibrations into a calibration list file, use

hdtv> calibration position list write <filename>

Alternatively, the calibration can be done with some known calibration
sources automatically:

.. code-block::

hdtv> calibration position nuclide Eu-152 -d IAEA -a

To calibrate the efficiency also the built-in calibration sources can
be used.
.. code-block::

hdtv> calibration efficiency fit -d IAEA 0,152Eu

NORMALIZE SPECTRA
=================
Spectra can be normalized with a coefficient with

.. code-block::

hdtv> spectrum normalize <specID> <coefficient>

Afterwards, go to the spectrum and press ``shift``+``1`` to apply the normalization.
Press the key combination again to unapply it.


WORKING WITH MULTIPLE SPECTRA
=============================

Expand Down Expand Up @@ -348,6 +373,51 @@ a <specID>
The currently visible spectra and their corresponding colors are shown in
the top left corner of the GUI spectra window.

Spectra can be also deleted, or copied:

.. code-block::

hdtv> spectrum copy <specID>
hdtv> spectrum delete <specID>

Add several spectra by first specifying the specID of the resulting summed
spectrum:

.. code-block::

hdtv> spectrum add <specID_sum> <specID1> <specID2> ...


OPEN ROOT FILES
===============

To open a ROOT histogram:

.. code-block::

hdtv> root get path/to/rootfile.root/histogram

To open an asymmetric ROOT matrix:

.. code-block::

hdtv> root matrix get asym path/to/rootfile.root/matrix

For symmetric matrices use ``sym`` instead of ``asym``.
Opening a matrix gives two spectra 0.0 and 0.1 which are the X and Y projections.

PEAK SEARCH
===========
Find peaks automatically between start and end bin:

.. code-block::

hdtv> fit peakfind startbin endbin [-a] [-r] [-s] [-t]

The option [-a] automatically fits the found peaks. [-r] rejects peaks.
With [-s] sigma and with [-t] the threshold for the search can be specified.


SEE ALSO
========

Expand Down
16 changes: 16 additions & 0 deletions doc/sphinx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Minimal 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 = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# 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)
6 changes: 6 additions & 0 deletions doc/sphinx/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Build the autoapi documentation with
sphinx-build -b html . _build
inside this directory.
Dependencies for this documentation:
sphinx-autoapi
sphinx-rtd-theme
29 changes: 29 additions & 0 deletions doc/sphinx/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Configuration file for the Sphinx documentation builder.

For the full list of built-in configuration values, see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "hdtv"
project_copyright = "2024, IKP"
author = "IKP"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ["autoapi.extension"]
autoapi_dirs = ["../../hdtv"]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
1 change: 1 addition & 0 deletions doc/sphinx/include_guide.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../guide/hdtv.rst
1 change: 1 addition & 0 deletions doc/sphinx/include_tutorial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../guide/hdtv-tutorial.rst
22 changes: 22 additions & 0 deletions doc/sphinx/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. hdtv documentation master file, created by
sphinx-quickstart on Thu Apr 11 16:12:11 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to hdtv's documentation!
================================

.. toctree::
:maxdepth: 3
:caption: Contents:

Documentation <include_guide.rst>
Tutorial <include_tutorial.rst>


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions doc/sphinx/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
5 changes: 4 additions & 1 deletion hdtv/hsluv.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ def lch_to_hpluv(_hx_tuple):


def rgb_to_hex(_hx_tuple):
return f"#{int(_math.floor(_hx_tuple[0] * 255 + 0.5)):02x}{int(_math.floor(_hx_tuple[1] * 255 + 0.5)):02x}{int(_math.floor(_hx_tuple[2] * 255 + 0.5)):02x}"
r = int(_math.floor(_hx_tuple[0] * 255 + 0.5))
g = int(_math.floor(_hx_tuple[1] * 255 + 0.5))
b = int(_math.floor(_hx_tuple[2] * 255 + 0.5))
return f"#{r:02x}{g:02x}{b:02x}"


def hex_to_rgb(_hex):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lint.ignore = [
"RUF012", # enforces type annotations on a codebase that lacks type annotations
"B904",
"ISC001",
"UP031",
"UP031", # Use format specifiers instead of percent format
]
lint.select = [
"E",
Expand Down
Loading