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

Add CI configuration #12

Merged
merged 5 commits into from
Mar 18, 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
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
push:
branches:
- master
- 'v[0-9]*'
tags:
- 'v[0-9]*'
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
tests:
strategy:
matrix:
python_version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-14]
exclude:
- os: macos-14
python_version: "3.9"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Choose Python version ${{ matrix.python_version }}
uses: actions/setup-python@v5
with:
python-version: '${{ matrix.python_version }}'
- name: install the package
run: python3 -m pip install .[test]
- name: run pytest
run: pytest --cov=microscope_calibration --cov-report=xml --cov-report=term tests/
- name: submit code coverage
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

numba_coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 'Choose Python version 3.12'
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: install the package
run: python3 -m pip install .[test]
- name: run pytest
run: NUMBA_DISABLE_JIT=1 pytest --cov=microscope_calibration --cov-report=xml --cov-report=term tests/
- name: submit code coverage
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
hooks:
- id: pyupgrade
args: ["--py39-plus"]
1 change: 0 additions & 1 deletion packaging/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Microscope-Calibration

2 changes: 1 addition & 1 deletion packaging/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ mkdir packaging/Microscope-Calibration; \
git archive --format=tar HEAD | tar xvf - -C packaging/Microscope-Calibration \
)

apptainer build --force overfocus.sif overfocus.def
apptainer build --force overfocus.sif overfocus.def
apptainer overlay create --size 1024 overfocus.sif
1 change: 0 additions & 1 deletion packaging/run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/sh
apptainer run --writable overfocus.sif

1 change: 0 additions & 1 deletion packaging/update-requirements.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/sh
uv pip compile --python-version=3.11 requirements.in ../pyproject.toml > requirements.txt

9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,23 @@ name = "microscope-calibration"
description = "Tools to calibrate a microscope"
license = {file = "LICENSE"}
keywords = ["microscopy", "LiberTEM", "TEM", "STEM"]
requires-python = ">=3.7"
requires-python = ">=3.9"
dynamic = ["version", "readme"]
dependencies = [
"numpy",
"libertem",
"typing-extensions",
"temgymbasic@git+https://github.com/TemGym/TemGym",
"temgymbasic@git+https://github.com/TemGym/TemGym@03062b098a50ea72f0ae9a2438b861d7a62691ee",
"numba",
"scikit-image",
"scipy",
]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Development Status :: 3 - Alpha",
]
authors = [
Expand All @@ -35,7 +34,7 @@ authors = [
repository = "https://github.com/LiberTEM/Microscope-Calibration"

[project.optional-dependencies]
test = ["pytest"]
test = ["pytest", "pytest-cov"]

[tool.setuptools.dynamic]
version = {attr = "microscope_calibration.__version__"}
Expand Down
3 changes: 2 additions & 1 deletion src/microscope_calibration/util/optimize.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
from scipy. optimize import shgo
from skimage.measure import blur_effect
from typing import TYPE_CHECKING, Iterable, Callable, Optional
from typing import TYPE_CHECKING, Callable, Optional
from collections.abc import Iterable

from microscope_calibration.common.stem_overfocus import OverfocusParams

Expand Down
4 changes: 2 additions & 2 deletions src/microscope_calibration/util/stem_overfocus_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def smiley(size):
y, x = np.ogrid[-size//2:size//2, -size//2:size//2]

outline = (((y*1.2)**2 + x**2) > (110/256*size)**2) & \
((((y*1.2)**2 + x**2) < (120/256*size)**2))
(((y*1.2)**2 + x**2) < (120/256*size)**2)
obj[outline] = 0.0

left_eye = ((y + 40/256*size)**2 + (x + 40/256*size)**2) < (20/256*size)**2
Expand All @@ -35,7 +35,7 @@ def smiley(size):
obj[nose] = (0.05j * x + 0.05j * y)[nose]

mouth = (((y*1)**2 + x**2) > (50/256*size)**2) & \
((((y*1)**2 + x**2) < (70/256*size)**2)) & \
(((y*1)**2 + x**2) < (70/256*size)**2) & \
(y > 20/256*size)

obj[mouth] = 0
Expand Down
11 changes: 7 additions & 4 deletions tests/test_overfocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from microscope_calibration.common.stem_overfocus import (
OverfocusParams, make_model, get_translation_matrix
)
from microscope_calibration.util.optimize import make_overfocus_loss_function, minimize
from microscope_calibration.util.optimize import make_overfocus_loss_function, optimize

from microscope_calibration.udf.stem_overfocus import OverfocusUDF
from libertem.api import Context
Expand Down Expand Up @@ -441,14 +441,14 @@ def test_optimize():
dataset=ds,
overfocus_udf=ref_udf,
)
res = minimize(loss=loss)
res = optimize(loss=loss)
res_params = make_new_params(res.x)
assert_allclose(res_params['scan_rotation'], params['scan_rotation'], atol=0.1)
assert_allclose(res_params['overfocus'], params['overfocus'], rtol=0.1)

valdict = {'val': False}

def callback(args, new_params, udf_results):
def callback(args, new_params, udf_results, current_loss):
if valdict['val']:
pass
else:
Expand All @@ -467,7 +467,10 @@ def callback(args, new_params, udf_results):
extra_udfs=(OverfocusUDF(params), ),
plots=(),
)
res = minimize(loss=loss, method='SLSQP', bounds=[(-10, 10), (-10, 10)])
res = optimize(
loss=loss, minimizer_kwargs={'method': 'SLSQP'},
bounds=[(-10, 10), (-10, 10)],
)
res_params = make_new_params(res.x)
assert_allclose(res_params['scan_rotation'], params['scan_rotation'], atol=0.1)
assert_allclose(res_params['overfocus'], params['overfocus'], rtol=0.1)
Loading