coordinate-transformer 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coordinate_transformer-0.2.3/.circleci/config.yml +41 -0
- coordinate_transformer-0.2.3/.github/workflows/publish_pypi.yml +76 -0
- coordinate_transformer-0.2.3/.gitignore +209 -0
- coordinate_transformer-0.2.3/LICENSE +21 -0
- coordinate_transformer-0.2.3/PKG-INFO +17 -0
- coordinate_transformer-0.2.3/README.md +296 -0
- coordinate_transformer-0.2.3/coordinate_transform_example.ipynb +337 -0
- coordinate_transformer-0.2.3/example_nmd.ipynb +1050 -0
- coordinate_transformer-0.2.3/images/AIMD_holder_mk1_white_sample.png +0 -0
- coordinate_transformer-0.2.3/instrument_coordinate_transforms.yaml +38 -0
- coordinate_transformer-0.2.3/nmdchecks/12.NMD +0 -0
- coordinate_transformer-0.2.3/nmdchecks/TEST11_000000000000000000000011_0_758.NMPROJ +17 -0
- coordinate_transformer-0.2.3/nmdchecks/example_nmd.ipynb +935 -0
- coordinate_transformer-0.2.3/pyproject.toml +48 -0
- coordinate_transformer-0.2.3/sample_holder_visualization.ipynb +690 -0
- coordinate_transformer-0.2.3/setup.cfg +4 -0
- coordinate_transformer-0.2.3/src/coordinate_transformer/__init__.py +258 -0
- coordinate_transformer-0.2.3/src/coordinate_transformer/__main__.py +3 -0
- coordinate_transformer-0.2.3/src/coordinate_transformer.egg-info/PKG-INFO +17 -0
- coordinate_transformer-0.2.3/src/coordinate_transformer.egg-info/SOURCES.txt +24 -0
- coordinate_transformer-0.2.3/src/coordinate_transformer.egg-info/dependency_links.txt +1 -0
- coordinate_transformer-0.2.3/src/coordinate_transformer.egg-info/entry_points.txt +2 -0
- coordinate_transformer-0.2.3/src/coordinate_transformer.egg-info/requires.txt +11 -0
- coordinate_transformer-0.2.3/src/coordinate_transformer.egg-info/top_level.txt +1 -0
- coordinate_transformer-0.2.3/tests/__init__.py +0 -0
- coordinate_transformer-0.2.3/tests/test_coordinate_transformer.py +382 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
|
|
3
|
+
jobs:
|
|
4
|
+
test:
|
|
5
|
+
docker:
|
|
6
|
+
- image: cimg/python:3.12
|
|
7
|
+
steps:
|
|
8
|
+
- checkout
|
|
9
|
+
- run:
|
|
10
|
+
name: Install dependencies
|
|
11
|
+
command: |
|
|
12
|
+
python -m pip install --upgrade pip
|
|
13
|
+
python -m pip install -e ".[test]"
|
|
14
|
+
- run:
|
|
15
|
+
name: Run linter
|
|
16
|
+
command: ruff check .
|
|
17
|
+
- run:
|
|
18
|
+
name: Run tests
|
|
19
|
+
command: pytest --junitxml=test-results/results.xml --cov=coordinate_transformer --cov-report=term-missing
|
|
20
|
+
- store_test_results:
|
|
21
|
+
path: test-results
|
|
22
|
+
|
|
23
|
+
test-min-python:
|
|
24
|
+
docker:
|
|
25
|
+
- image: cimg/python:3.10
|
|
26
|
+
steps:
|
|
27
|
+
- checkout
|
|
28
|
+
- run:
|
|
29
|
+
name: Install dependencies
|
|
30
|
+
command: |
|
|
31
|
+
python -m pip install --upgrade pip
|
|
32
|
+
python -m pip install -e ".[test]"
|
|
33
|
+
- run:
|
|
34
|
+
name: Run tests
|
|
35
|
+
command: pytest
|
|
36
|
+
|
|
37
|
+
workflows:
|
|
38
|
+
ci:
|
|
39
|
+
jobs:
|
|
40
|
+
- test
|
|
41
|
+
- test-min-python
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.10", "3.12"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- name: Install dependencies
|
|
20
|
+
run: |
|
|
21
|
+
python -m pip install --upgrade pip
|
|
22
|
+
python -m pip install -e ".[test]"
|
|
23
|
+
- name: Lint
|
|
24
|
+
if: matrix.python-version == '3.12'
|
|
25
|
+
run: ruff check .
|
|
26
|
+
- name: Run tests
|
|
27
|
+
run: pytest --tb=short
|
|
28
|
+
|
|
29
|
+
build:
|
|
30
|
+
needs: test
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v4
|
|
34
|
+
with:
|
|
35
|
+
fetch-depth: 0 # full history needed for setuptools-scm
|
|
36
|
+
- uses: actions/setup-python@v5
|
|
37
|
+
with:
|
|
38
|
+
python-version: "3.12"
|
|
39
|
+
- name: Install build tools
|
|
40
|
+
run: python -m pip install --upgrade pip build setuptools-scm
|
|
41
|
+
- name: Verify version from tag
|
|
42
|
+
run: python -m setuptools_scm
|
|
43
|
+
- name: Build sdist and wheel
|
|
44
|
+
run: python -m build
|
|
45
|
+
- name: Check dist contents
|
|
46
|
+
run: ls -la dist/
|
|
47
|
+
- uses: actions/upload-artifact@v4
|
|
48
|
+
with:
|
|
49
|
+
name: dist
|
|
50
|
+
path: dist/
|
|
51
|
+
|
|
52
|
+
publish:
|
|
53
|
+
needs: build
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
environment: pypi
|
|
56
|
+
permissions:
|
|
57
|
+
id-token: write # required for trusted publishing via OIDC
|
|
58
|
+
steps:
|
|
59
|
+
- uses: actions/download-artifact@v4
|
|
60
|
+
with:
|
|
61
|
+
name: dist
|
|
62
|
+
path: dist/
|
|
63
|
+
- name: Publish to PyPI
|
|
64
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
65
|
+
|
|
66
|
+
github-release:
|
|
67
|
+
needs: publish
|
|
68
|
+
runs-on: ubuntu-latest
|
|
69
|
+
permissions:
|
|
70
|
+
contents: write
|
|
71
|
+
steps:
|
|
72
|
+
- uses: actions/checkout@v4
|
|
73
|
+
- name: Create GitHub Release
|
|
74
|
+
env:
|
|
75
|
+
GH_TOKEN: ${{ github.token }}
|
|
76
|
+
run: gh release create "${{ github.ref_name }}" --generate-notes
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
.DS_Store
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
*.NMD
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 High-Throughput Materials Discovery for Extreme Conditions (HTMDEC)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: coordinate-transformer
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: Config-driven affine coordinate transforms for lab instruments
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: numpy>=1.26
|
|
9
|
+
Requires-Dist: PyYAML>=6.0
|
|
10
|
+
Provides-Extra: notebook
|
|
11
|
+
Requires-Dist: jupyter>=1.0; extra == "notebook"
|
|
12
|
+
Requires-Dist: ipykernel>=6.29; extra == "notebook"
|
|
13
|
+
Provides-Extra: test
|
|
14
|
+
Requires-Dist: pytest>=8.0; extra == "test"
|
|
15
|
+
Requires-Dist: pytest-cov>=5.0; extra == "test"
|
|
16
|
+
Requires-Dist: ruff>=0.4; extra == "test"
|
|
17
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# Coordinate Transformer
|
|
2
|
+
|
|
3
|
+
Config-driven affine coordinate transforms for lab instruments. (updated to v0.2.1 for PyPI)
|
|
4
|
+
|
|
5
|
+
This repository provides a small Python module that reads instrument calibration data from `instrument_coordinate_transforms.yaml`, fits a 2D affine transform for each instrument, and converts `(x, y)` points between an instrument coordinate system and a canonical sample coordinate system.
|
|
6
|
+
|
|
7
|
+
The current configuration includes these instruments:
|
|
8
|
+
|
|
9
|
+
- `MAXIMA`
|
|
10
|
+
- `HELIX`
|
|
11
|
+
- `SPHINX`
|
|
12
|
+
|
|
13
|
+
## Repository contents
|
|
14
|
+
|
|
15
|
+
- `src/coordinate_transformer/` is the package with the `CoordinateTransformer` class and a small CLI
|
|
16
|
+
- `instrument_coordinate_transforms.yaml` is the calibration data config based on the canonical sample coordinate system
|
|
17
|
+
- `coordinate_transform_example.ipynb` is a simple example notebook showing the transformer in action
|
|
18
|
+
- `tests/` is the test suite (40 tests covering transforms, validation, batch operations, and the CLI)
|
|
19
|
+
- `pyproject.toml` has project metadata, build configuration, and dependency groups
|
|
20
|
+
- `.circleci/` contains the CircleCI pipeline configuration for continuous integration
|
|
21
|
+
- `.github/workflows/` contains the GitHub Actions workflow for publishing to PyPI on tagged releases
|
|
22
|
+
- `LICENSE` is the MIT license
|
|
23
|
+
|
|
24
|
+
## How it works
|
|
25
|
+
|
|
26
|
+
For each instrument, the YAML file contains three calibration point pairs:
|
|
27
|
+
|
|
28
|
+
- `instrument: [x_inst, y_inst]`
|
|
29
|
+
- `sample: [x_sample, y_sample]`
|
|
30
|
+
|
|
31
|
+
The module fits a 2D affine transform from instrument coordinates to sample coordinates. With three non-collinear calibration pairs, the transform is determined exactly. If you later provide more than three calibration pairs, the code will fit the transform by least squares.
|
|
32
|
+
|
|
33
|
+
## Requirements
|
|
34
|
+
|
|
35
|
+
- Python 3.9+
|
|
36
|
+
|
|
37
|
+
Core dependencies (installed automatically):
|
|
38
|
+
|
|
39
|
+
- `numpy`
|
|
40
|
+
- `PyYAML`
|
|
41
|
+
|
|
42
|
+
Optional extras:
|
|
43
|
+
|
|
44
|
+
- `pip install coordinate-transformer[notebook]` adds `jupyter` and `ipykernel` for running the example notebook
|
|
45
|
+
- `pip install coordinate-transformer[test]` adds `pytest`, `pytest-cov`, and `ruff` for testing and linting
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
### From PyPI
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pip install coordinate-transformer
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Development installation
|
|
56
|
+
|
|
57
|
+
Clone the repository, create a virtual environment, and install in editable mode with test dependencies:
|
|
58
|
+
|
|
59
|
+
#### macOS / Linux
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
python -m venv .venv
|
|
63
|
+
source .venv/bin/activate
|
|
64
|
+
python -m pip install --upgrade pip
|
|
65
|
+
pip install -e ".[test]"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Windows PowerShell
|
|
69
|
+
|
|
70
|
+
```powershell
|
|
71
|
+
python -m venv .venv
|
|
72
|
+
.venv\Scripts\Activate.ps1
|
|
73
|
+
python -m pip install --upgrade pip
|
|
74
|
+
pip install -e ".[test]"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Running tests
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install -e ".[test]"
|
|
81
|
+
pytest
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Linting is available via:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
ruff check .
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
CI runs automatically on CircleCI (for every push) and GitHub Actions (for tagged releases).
|
|
91
|
+
|
|
92
|
+
## YAML configuration
|
|
93
|
+
|
|
94
|
+
The transformer is driven by `instrument_coordinate_transforms.yaml`.
|
|
95
|
+
|
|
96
|
+
The top-level structure is:
|
|
97
|
+
|
|
98
|
+
```yaml
|
|
99
|
+
canonical_system:
|
|
100
|
+
origin: bottom-left
|
|
101
|
+
x_positive: right
|
|
102
|
+
y_positive: up
|
|
103
|
+
units: mm
|
|
104
|
+
sample_width: 40.0
|
|
105
|
+
sample_height: 40.0
|
|
106
|
+
|
|
107
|
+
instruments:
|
|
108
|
+
- name: MAXIMA
|
|
109
|
+
units: mm
|
|
110
|
+
calibration_points:
|
|
111
|
+
- instrument: [x1, y1]
|
|
112
|
+
sample: [x1s, y1s]
|
|
113
|
+
- instrument: [x2, y2]
|
|
114
|
+
sample: [x2s, y2s]
|
|
115
|
+
- instrument: [x3, y3]
|
|
116
|
+
sample: [x3s, y3s]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
To update an instrument, edit its calibration points in the YAML. To add another instrument, add another entry under `instruments` with at least three non-collinear calibration pairs.
|
|
120
|
+
|
|
121
|
+
## Using the class
|
|
122
|
+
|
|
123
|
+
Import the class and load the YAML file:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from coordinate_transformer import CoordinateTransformer
|
|
127
|
+
|
|
128
|
+
transformer = CoordinateTransformer.from_yaml("instrument_coordinate_transforms.yaml")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### List available instruments
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
transformer.instruments()
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Transform one point into sample coordinates
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
x_sample, y_sample = transformer.transform("MAXIMA", -14.0, -20.0)
|
|
141
|
+
print(x_sample, y_sample)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Inverse transform from sample coordinates back to an instrument frame
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
x_inst, y_inst = transformer.inverse_transform("SPHINX", 40.0, 40.0)
|
|
148
|
+
print(x_inst, y_inst)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Transform a batch of points
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
import numpy as np
|
|
155
|
+
|
|
156
|
+
points = np.array([
|
|
157
|
+
[125.319, 148.213],
|
|
158
|
+
[124.924, 107.753],
|
|
159
|
+
[165.189, 107.350],
|
|
160
|
+
])
|
|
161
|
+
|
|
162
|
+
sample_points = transformer.transform_points("SPHINX", points)
|
|
163
|
+
print(sample_points)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Inspect the affine matrix for one instrument
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
matrix = transformer.get_transform("HELIX").matrix
|
|
170
|
+
print(matrix)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Validate calibration fit
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
errors = transformer.validate()
|
|
177
|
+
print(errors)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
This returns the maximum calibration-point residual for each instrument.
|
|
181
|
+
|
|
182
|
+
## API summary
|
|
183
|
+
|
|
184
|
+
### `CoordinateTransformer`
|
|
185
|
+
|
|
186
|
+
Main methods:
|
|
187
|
+
|
|
188
|
+
- `CoordinateTransformer.from_yaml(path)`
|
|
189
|
+
- `instruments()`
|
|
190
|
+
- `get_transform(instrument_name)`
|
|
191
|
+
- `transform(instrument_name, x, y)`
|
|
192
|
+
- `inverse_transform(instrument_name, x, y)`
|
|
193
|
+
- `transform_points(instrument_name, points)`
|
|
194
|
+
- `inverse_transform_points(instrument_name, points)`
|
|
195
|
+
- `validate()`
|
|
196
|
+
- `summary()`
|
|
197
|
+
|
|
198
|
+
### `InstrumentTransform`
|
|
199
|
+
|
|
200
|
+
Returned by `get_transform(...)`. Useful attributes and methods:
|
|
201
|
+
|
|
202
|
+
- `name`
|
|
203
|
+
- `units`
|
|
204
|
+
- `matrix`
|
|
205
|
+
- `inverse_matrix`
|
|
206
|
+
- `transform_point(x, y)`
|
|
207
|
+
- `inverse_transform_point(x, y)`
|
|
208
|
+
- `transform_points(points)`
|
|
209
|
+
- `inverse_transform_points(points)`
|
|
210
|
+
- `calibration_residuals()`
|
|
211
|
+
- `max_calibration_error()`
|
|
212
|
+
|
|
213
|
+
## Command-line usage
|
|
214
|
+
|
|
215
|
+
The module also includes a small CLI.
|
|
216
|
+
|
|
217
|
+
### Transform an instrument point into sample coordinates
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
python -m coordinate_transformer instrument_coordinate_transforms.yaml MAXIMA -14 -20
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Inverse transform from sample coordinates into instrument coordinates
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
python -m coordinate_transformer instrument_coordinate_transforms.yaml SPHINX 40 40 --inverse
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Show the fitted affine matrix
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
python -m coordinate_transformer instrument_coordinate_transforms.yaml HELIX 8 8 --show-matrix
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Using the console script
|
|
236
|
+
|
|
237
|
+
After installation, `coordinate-transformer` is also available as a standalone command:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
coordinate-transformer instrument_coordinate_transforms.yaml MAXIMA -14 -20
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Running the example notebook
|
|
244
|
+
|
|
245
|
+
After installing the environment:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
jupyter notebook coordinate_transform_example.ipynb
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
The notebook demonstrates how to:
|
|
252
|
+
|
|
253
|
+
- load the YAML configuration
|
|
254
|
+
- inspect the canonical coordinate system
|
|
255
|
+
- list instruments
|
|
256
|
+
- validate calibration errors
|
|
257
|
+
- transform a single point
|
|
258
|
+
- transform a batch of points
|
|
259
|
+
- perform an inverse transform
|
|
260
|
+
- inspect a fitted affine matrix
|
|
261
|
+
|
|
262
|
+
If you want to use the notebook with a dedicated kernel, you can register the environment explicitly:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
python -m ipykernel install --user --name coordinate-transformer --display-name "Python (coordinate-transformer)"
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Then choose that kernel in Jupyter.
|
|
269
|
+
|
|
270
|
+
## Versioning and releases
|
|
271
|
+
|
|
272
|
+
The version is derived automatically from git tags using [setuptools-scm](https://github.com/pypa/setuptools-scm). To release a new version:
|
|
273
|
+
|
|
274
|
+
1. Tag the commit with a `v` prefix (e.g., `git tag v0.2.0`)
|
|
275
|
+
2. Push the tag: `git push origin --tags`
|
|
276
|
+
3. The GitHub Actions workflow will publish to PyPI automatically
|
|
277
|
+
|
|
278
|
+
## Notes
|
|
279
|
+
|
|
280
|
+
- At least three non-collinear calibration points are required per instrument.
|
|
281
|
+
- If the calibration points are degenerate, the code raises an error.
|
|
282
|
+
- Units are recorded per instrument, but the transform assumes your calibration pairs already define the correct mapping into the canonical sample units.
|
|
283
|
+
- The current implementation uses a full affine model, so it can represent translation, rotation, reflection, scaling, shear, or combinations of those.
|
|
284
|
+
|
|
285
|
+
## Typical update workflow
|
|
286
|
+
|
|
287
|
+
1. Edit `instrument_coordinate_transforms.yaml`
|
|
288
|
+
2. Replace or add calibration points for the relevant instrument
|
|
289
|
+
3. Reload the transformer:
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
transformer = CoordinateTransformer.from_yaml("instrument_coordinate_transforms.yaml")
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
4. Re-run `transformer.validate()`
|
|
296
|
+
5. Re-run the example notebook if needed
|