Skip to content

Commit

Permalink
move away from poetry, doc improvements, gui fixes
Browse files Browse the repository at this point in the history
* bokeh 3 fix and bug fix

* bumping version requirements

* moving load of data and added get_edge

* fixes to data

* adding tests

* added custom material example

* added example that show edges

* moved api to generated dir and added clean command to make

* bug fixes and improvements to gui

* Update .gitignore

* fixes to docs

* update to tests for edges

* update to bokeh version pin

* expanded get_element_symbol ability and solved issue #52

* removed poetry

* Update codestyle.yml

* fixes tests and linting

* Update testing.yml

* Update .pre-commit-config.yaml

* added pre-commit checks

* Update pyproject.toml

* moved precommit to its own workflow

* fixed missing doc dependency

* pre-commit fixes

* not needed because get_atomic_number issue error already

* fix for new version of black req

* Update README.rst

* update to black version req and black fix

* fixed license file reference

* fixed dynamic version number and cleanup
  • Loading branch information
ehsteve committed Mar 12, 2024
1 parent d66fbad commit 3f3d2c7
Show file tree
Hide file tree
Showing 170 changed files with 2,532 additions and 2,270 deletions.
66 changes: 29 additions & 37 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will install Python dependencies, run tests, run linting, and test building docs
# This workflow will install Python dependencies and check code style and linting
name: Codestyle and Linting

on:
Expand All @@ -8,42 +8,34 @@ on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
platform: ["ubuntu-latest"]
python-version: ["3.10"]
defaults:
run:
shell: bash
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-pip-wheels
uses: actions/cache@v2
with:
path: ~/.cache
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: poetry install --no-interaction --no-root --with dev

- name: Install library
run: poetry install --no-interaction

- name: Lint with Black
run: |
poetry run black --check --diff roentgen
- name: flake8
run: |
poetry run flake8 --count roentgen
- name: isort
run: |
poetry run isort roentgen -c
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install pip setuptools wheel --upgrade
python -m pip install -e '.[style]'
- name: Lint with Black
run: |
black --check --diff roentgen
- name: flake8
run: |
flake8 --count roentgen
- name: isort
run: |
isort roentgen -c
53 changes: 22 additions & 31 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,28 @@ on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
platform: ["ubuntu-latest"]
python-version: ["3.10"]
defaults:
run:
shell: bash
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-pip-wheels
uses: actions/cache@v2
with:
path: ~/.cache
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: poetry install --no-interaction --no-root --with docs

- name: Install library
run: poetry install --no-interaction

- name: Build docs
run: |
source $VENV
sphinx-build docs docs/_build/html -b html
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install pip setuptools wheel --upgrade
python -m pip install -e '.[docs]'
- name: Build docs
run: |
sphinx-build docs docs/_build/html -b html
26 changes: 26 additions & 0 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This workflow will install Python dependencies and run a few (not all) pre-commit checks
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
with:
extra_args: check-ast --all-files
- uses: pre-commit/action@v3.0.0
with:
extra_args: trailing-whitespace --all-files
- uses: pre-commit/action@v3.0.0
with:
extra_args: mixed-line-ending --all-files
- uses: pre-commit/action@v3.0.0
with:
extra_args: debug-statements --all-files
58 changes: 19 additions & 39 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,32 @@ on:
pull_request:
branches:
- main

jobs:
build:
strategy:
fail-fast: false
matrix:
platform: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: [3.9]
python-version: ["3.10", "3.11"]
defaults:
run:
shell: bash
runs-on: ${{ matrix.platform }}
steps:
- name: Check out repository
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-pip-wheels
uses: actions/cache@v2
with:
path: ~/.cache
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: poetry install --no-interaction --no-root --with dev

- name: Install library
run: poetry install --no-interaction

- name: Run tests
run: |
poetry run pytest --cov=./ --cov-report=xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
fail_ci_if_error: true
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install pip setuptools wheel --upgrade
python -m pip install -e '.[tests]'
- name: Run tests
run: |
pytest --cov=./ --cov-report=xml
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
fail_ci_if_error: true
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ pip-wheel-metadata/**
*.c

# Other generated files
*/version.py
*/_version.py
*/cython_version.py
htmlcov
.coverage
MANIFEST
.ipynb_checkpoints

# Sphinx
docs/api
docs/generated
docs/_build

# Eclipse editor project files
Expand Down
15 changes: 8 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,29 @@ repos:
# E902 - IOError
# F822: undefined name in __all__
# F823: local variable name referenced before assignment
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
args: ['--count', '--select', 'E101,W191,W291,W292,W293,W391,E111,E112,E113,E303,E304,E306,E502,E722,E901,E902,F822,F823']
args: ['--count', '--select', 'E501, E203']

- repo: https://github.com/psf/black
rev: 21.6b0
rev: 24.2.0
hooks:
- id: black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v4.5.0
hooks:
- id: check-ast
- id: check-case-conflict
- id: trailing-whitespace
exclude: ".*(.fits|.fts|.fit|.txt)$"
- id: check-yaml
- id: check-toml
- id: detect-private-key
- id: debug-statements
- id: check-added-large-files
# - id: end-of-file-fixer uncommenting this will break the testing of the cookiecutter template
# exclude: ".*(.fits|.fts|.fit|.txt|tca.*)$"
- id: mixed-line-ending
exclude: ".*(.fits|.fts|.fit|.txt|tca.*)$"
exclude: ".*(.fits|.fts|.fit|.txt|tca.*)$"
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ It is based on `bokeh <https://docs.bokeh.org/en/stable/>`_. To run it locally u

bokeh serve --show <roengten_directory>/gui

An online version of this tool usually working at `https://roentgen-069cf7954bb2.herokuapp.com/gui <https://roentgen-069cf7954bb2.herokuapp.com/gui>`_.

Data Sources
============
Expand Down
7 changes: 6 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ help:

.PHONY: help Makefile

clean:
rm -rf $(BUILDDIR)
rm -rf ./generated

# 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)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

15 changes: 9 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
# documents. Set to the "smart" one.
default_role = "obj"

# Set automodapi to generate files inside the generated directory
automodapi_toctreedirnm = "generated/api"

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
Expand Down Expand Up @@ -99,10 +102,10 @@
graphviz_output_format = "svg"

graphviz_dot_args = [
'-Nfontsize=10',
'-Nfontname=Helvetica Neue, Helvetica, Arial, sans-serif',
'-Efontsize=10',
'-Efontname=Helvetica Neue, Helvetica, Arial, sans-serif',
'-Gfontsize=10',
'-Gfontname=Helvetica Neue, Helvetica, Arial, sans-serif'
"-Nfontsize=10",
"-Nfontname=Helvetica Neue, Helvetica, Arial, sans-serif",
"-Efontsize=10",
"-Efontname=Helvetica Neue, Helvetica, Arial, sans-serif",
"-Gfontsize=10",
"-Gfontname=Helvetica Neue, Helvetica, Arial, sans-serif",
]
29 changes: 29 additions & 0 deletions docs/examples/tutorial9.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Defining your own custom material
=================================
Though the compounds list provided in this package is extensive it may not provide the exact material that you are interested in.
It easily possible to define your own material if you know it's chemical composition.
The following example, we investigate the absorption of a Gallium Arsenide (GaAs) detector in the same configuration as that in `G. Lioliou & A.M. Barnett (2016) <https://doi.org/10.1016/j.nima.2016.08.047>`__.
Compare our plot with their `Figure 1 <https://www.sciencedirect.com/science/article/pii/S016890021630866X#f0005>`__.

.. plot::
:include-source:

import astropy.units as u
import numpy as np

from matplotlib import pyplot as plt
from roentgen.absorption import Material

gaas_deadlayer = Material({'Ga': 0.518, 'As': 0.482},
density=5.32*u.g/u.cm**3, thickness=500*u.nm)

gaas_detector = Material({'Ga': 0.518, 'As': 0.482},
density=5.32*u.g/u.cm**3, thickness=10000*u.nm)
e = np.linspace(1, 30, 1000)*u.keV

plt.plot(e, gaas_detector.absorption(e) * gaas_deadlayer.transmission(e))
plt.xlabel(f'Energy [{e.unit}]')
plt.ylabel('Quantum Efficiency')
plt.ylim(0.001, 1)
plt.yscale('log')
plt.show()
24 changes: 24 additions & 0 deletions docs/examples/tutorial_10.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
X-ray Transmission through air at STP
======================================

.. plot::
:include-source:

import numpy as np
from matplotlib import pyplot as plt
from astropy import constants as const
import astropy.units as u

from roentgen.absorption import Material
from roentgen.util import density_ideal_gas

air_density = density_ideal_gas(1 * const.atm, 20 * u.Celsius)
air = Material('air', 1 * u.m, density=air_density)

e = np.linspace(1, 30, 1000)*u.keV

plt.plot(e, air.transmission(e))
plt.xlabel(f'Energy [{e.unit}]')
plt.ylabel('X-ray Transmission through 1 m of air at STP')
plt.ylim(0, 1)
plt.show()

0 comments on commit 3f3d2c7

Please sign in to comment.