midas-transforms 0.1.0__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.
Files changed (35) hide show
  1. midas_transforms-0.1.0/PKG-INFO +137 -0
  2. midas_transforms-0.1.0/README.md +111 -0
  3. midas_transforms-0.1.0/midas_transforms/__init__.py +46 -0
  4. midas_transforms-0.1.0/midas_transforms/__main__.py +6 -0
  5. midas_transforms-0.1.0/midas_transforms/bin_data/__init__.py +10 -0
  6. midas_transforms-0.1.0/midas_transforms/bin_data/core.py +448 -0
  7. midas_transforms-0.1.0/midas_transforms/cli.py +175 -0
  8. midas_transforms-0.1.0/midas_transforms/device.py +65 -0
  9. midas_transforms-0.1.0/midas_transforms/fit_setup/__init__.py +10 -0
  10. midas_transforms-0.1.0/midas_transforms/fit_setup/core.py +422 -0
  11. midas_transforms-0.1.0/midas_transforms/fit_setup/refine.py +121 -0
  12. midas_transforms-0.1.0/midas_transforms/fit_setup/transform.py +244 -0
  13. midas_transforms-0.1.0/midas_transforms/io/__init__.py +4 -0
  14. midas_transforms-0.1.0/midas_transforms/io/binary.py +59 -0
  15. midas_transforms-0.1.0/midas_transforms/io/csv.py +138 -0
  16. midas_transforms-0.1.0/midas_transforms/io/zarr_io.py +87 -0
  17. midas_transforms-0.1.0/midas_transforms/merge/__init__.py +10 -0
  18. midas_transforms-0.1.0/midas_transforms/merge/core.py +525 -0
  19. midas_transforms-0.1.0/midas_transforms/params.py +493 -0
  20. midas_transforms-0.1.0/midas_transforms/pipeline.py +197 -0
  21. midas_transforms-0.1.0/midas_transforms/radius/__init__.py +10 -0
  22. midas_transforms-0.1.0/midas_transforms/radius/core.py +350 -0
  23. midas_transforms-0.1.0/midas_transforms.egg-info/PKG-INFO +137 -0
  24. midas_transforms-0.1.0/midas_transforms.egg-info/SOURCES.txt +33 -0
  25. midas_transforms-0.1.0/midas_transforms.egg-info/dependency_links.txt +1 -0
  26. midas_transforms-0.1.0/midas_transforms.egg-info/entry_points.txt +6 -0
  27. midas_transforms-0.1.0/midas_transforms.egg-info/requires.txt +10 -0
  28. midas_transforms-0.1.0/midas_transforms.egg-info/top_level.txt +1 -0
  29. midas_transforms-0.1.0/pyproject.toml +58 -0
  30. midas_transforms-0.1.0/setup.cfg +4 -0
  31. midas_transforms-0.1.0/tests/test_bin_data.py +111 -0
  32. midas_transforms-0.1.0/tests/test_io.py +80 -0
  33. midas_transforms-0.1.0/tests/test_regression_vs_c.py +273 -0
  34. midas_transforms-0.1.0/tests/test_smoke.py +61 -0
  35. midas_transforms-0.1.0/tests/test_transform.py +110 -0
@@ -0,0 +1,137 @@
1
+ Metadata-Version: 2.4
2
+ Name: midas-transforms
3
+ Version: 0.1.0
4
+ Summary: Pure-Python/PyTorch FF-HEDM transforms (drop-in for MergeOverlappingPeaksAllZarr / CalcRadiusAllZarr / FitSetupZarr / SaveBinData)
5
+ Author-email: Hemant Sharma <hsharma@anl.gov>
6
+ License-Expression: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/marinerhemant/MIDAS
8
+ Project-URL: Documentation, https://github.com/marinerhemant/MIDAS/tree/master/packages/midas_transforms
9
+ Project-URL: Issues, https://github.com/marinerhemant/MIDAS/issues
10
+ Keywords: MIDAS,HEDM,differentiable,PyTorch,far-field,diffraction,crystallography,polycrystal,grain,geometry-correction
11
+ Classifier: Development Status :: 2 - Pre-Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Scientific/Engineering :: Physics
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: numpy>=1.22
18
+ Requires-Dist: torch>=2.0
19
+ Requires-Dist: zarr<3.0,>=2.18
20
+ Requires-Dist: numcodecs>=0.12
21
+ Requires-Dist: midas-calibrate>=0.2.1
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.0; extra == "dev"
24
+ Requires-Dist: pytest-cov; extra == "dev"
25
+ Requires-Dist: pytest-benchmark; extra == "dev"
26
+
27
+ # midas-transforms
28
+
29
+ Pure-Python / PyTorch FF-HEDM intermediate transforms — the four stages
30
+ between peak-fitting and indexing in the MIDAS workflow.
31
+
32
+ Drop-in replacement for these C binaries:
33
+
34
+ | C binary | Python entry point |
35
+ |-----------------------------------|----------------------------|
36
+ | `MergeOverlappingPeaksAllZarr` | `midas-merge-peaks` |
37
+ | `CalcRadiusAllZarr` | `midas-calc-radius` |
38
+ | `FitSetupZarr` | `midas-fit-setup` |
39
+ | `SaveBinData` | `midas-bin-data` |
40
+
41
+ Plus an end-to-end `midas-transforms pipeline <zarr>` that runs all four on
42
+ GPU with no CSV / binary disk round-trips between stages.
43
+
44
+ ## Why
45
+
46
+ - **Speed.** Vectorised PyTorch kernels target ≥ 1× C on CPU and 5–50× on
47
+ GPU at production scale. Binning and merge are the workflow's longest
48
+ tails; both are now broadcast + scatter operations.
49
+ - **Bit-matching with C.** Every deterministic stage targets byte-exact
50
+ output at float64. The geometry refine (`DoFit==1`) targets
51
+ physics-meaningful tolerance via `midas-calibrate.refine_geometry`
52
+ (LM with ADAM fallback — no NLopt, no Nelder-Mead).
53
+ - **Differentiable.** All geometry parameters that flow through detector
54
+ projection (`Lsd`, `BC_y`, `BC_z`, `tx/ty/tz`, `p0..p14`, `wedge`,
55
+ `dLsd`, `dP2`, residual-correction map values) carry full autograd
56
+ through `apply_tilt_distortion` — useful for joint calibration with
57
+ downstream grain mapping.
58
+ - **CPU/GPU portable.** Single `device=` switch (cpu / cuda / mps). No
59
+ separate `.cu` codebase. No C extensions, no `cibuildwheel`.
60
+
61
+ ## Install
62
+
63
+ ```bash
64
+ pip install -e packages/midas_transforms
65
+ ```
66
+
67
+ (Until uploaded to PyPI; once released, `pip install midas-transforms`.)
68
+
69
+ ## Quick start
70
+
71
+ ### Per-stage CLI (drop-in for the C binaries)
72
+
73
+ ```bash
74
+ midas-merge-peaks scan.zip
75
+ midas-calc-radius scan.zip
76
+ midas-fit-setup scan.zip
77
+ midas-bin-data --result-folder .
78
+ ```
79
+
80
+ ### End-to-end Pipeline (intermediates stay on GPU)
81
+
82
+ ```bash
83
+ midas-transforms pipeline scan.zip --device cuda --out-dir /scratch/run42
84
+ ```
85
+
86
+ ### Library
87
+
88
+ ```python
89
+ from midas_transforms import Pipeline
90
+
91
+ pipe = Pipeline.from_zarr("scan.zip", device="cuda")
92
+ result = pipe.run()
93
+ result.merge # (N, 17) on GPU
94
+ result.radius # (N, 24) on GPU
95
+ result.fit_setup # InputAll/Extra tensors on GPU
96
+ result.bins # Spots/ExtraInfo/Data/nData tensors on GPU
97
+ pipe.dump("/scratch/run42")
98
+ ```
99
+
100
+ Or use stages individually:
101
+
102
+ ```python
103
+ from midas_transforms import merge_overlapping_peaks, calc_radius, fit_setup, bin_data
104
+
105
+ merge_overlapping_peaks(zarr_path="scan.zip", device="cuda")
106
+ calc_radius(result_folder=".", zarr_params=..., device="cuda")
107
+ fit_setup(result_folder=".", zarr_params=..., device="cuda")
108
+ bin_data(result_folder=".", device="cuda")
109
+ ```
110
+
111
+ ## Wiring into `ff_MIDAS.py`
112
+
113
+ `ff_MIDAS.py` accepts a `--useTorchTransforms 1` flag (mirrors the
114
+ existing `--useTorchIndexer` / `--peakFitGPU` flags). When set, the
115
+ workflow's `merge_overlaps`, `calc_radius`, `data_transform`, and
116
+ `binning` stages dispatch to the Python entry points instead of the C
117
+ binaries. Outputs are byte-compatible (or numerically equivalent for
118
+ the `DoFit` geometry refine).
119
+
120
+ ## Limits in v0.1.0.dev0
121
+
122
+ - **Pixel-overlap merge mode** (`UsePixelOverlap=1`) is not yet supported
123
+ — use the C `MergeOverlappingPeaksAllZarr` for that path.
124
+ - **Scanning workflows** (`SaveBinDataScanning`, `MergeMultipleScans`) are
125
+ out of scope here; they belong with the broader scanning pipeline.
126
+ - **Byte-level regression vs C** is in progress. Unit tests cover kernel
127
+ correctness; full end-to-end byte-equality against C goldens lands in
128
+ v0.1.0 proper.
129
+
130
+ ## See also
131
+
132
+ - `dev/implementation_plan.md` — full design, scope, and risk register.
133
+ - `midas-peakfit` — upstream peak-fitting (writes the consolidated HDF5).
134
+ - `midas-index` — downstream indexer (consumes `Spots.bin`/`Data.bin`).
135
+ - `midas-calibrate` — provides `geometry_torch.pixel_to_REta_torch` and
136
+ `refine_geometry` (LM solver) used by `fit_setup`.
137
+ - `midas-hkls` — upstream `hkls.csv` generation.
@@ -0,0 +1,111 @@
1
+ # midas-transforms
2
+
3
+ Pure-Python / PyTorch FF-HEDM intermediate transforms — the four stages
4
+ between peak-fitting and indexing in the MIDAS workflow.
5
+
6
+ Drop-in replacement for these C binaries:
7
+
8
+ | C binary | Python entry point |
9
+ |-----------------------------------|----------------------------|
10
+ | `MergeOverlappingPeaksAllZarr` | `midas-merge-peaks` |
11
+ | `CalcRadiusAllZarr` | `midas-calc-radius` |
12
+ | `FitSetupZarr` | `midas-fit-setup` |
13
+ | `SaveBinData` | `midas-bin-data` |
14
+
15
+ Plus an end-to-end `midas-transforms pipeline <zarr>` that runs all four on
16
+ GPU with no CSV / binary disk round-trips between stages.
17
+
18
+ ## Why
19
+
20
+ - **Speed.** Vectorised PyTorch kernels target ≥ 1× C on CPU and 5–50× on
21
+ GPU at production scale. Binning and merge are the workflow's longest
22
+ tails; both are now broadcast + scatter operations.
23
+ - **Bit-matching with C.** Every deterministic stage targets byte-exact
24
+ output at float64. The geometry refine (`DoFit==1`) targets
25
+ physics-meaningful tolerance via `midas-calibrate.refine_geometry`
26
+ (LM with ADAM fallback — no NLopt, no Nelder-Mead).
27
+ - **Differentiable.** All geometry parameters that flow through detector
28
+ projection (`Lsd`, `BC_y`, `BC_z`, `tx/ty/tz`, `p0..p14`, `wedge`,
29
+ `dLsd`, `dP2`, residual-correction map values) carry full autograd
30
+ through `apply_tilt_distortion` — useful for joint calibration with
31
+ downstream grain mapping.
32
+ - **CPU/GPU portable.** Single `device=` switch (cpu / cuda / mps). No
33
+ separate `.cu` codebase. No C extensions, no `cibuildwheel`.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install -e packages/midas_transforms
39
+ ```
40
+
41
+ (Until uploaded to PyPI; once released, `pip install midas-transforms`.)
42
+
43
+ ## Quick start
44
+
45
+ ### Per-stage CLI (drop-in for the C binaries)
46
+
47
+ ```bash
48
+ midas-merge-peaks scan.zip
49
+ midas-calc-radius scan.zip
50
+ midas-fit-setup scan.zip
51
+ midas-bin-data --result-folder .
52
+ ```
53
+
54
+ ### End-to-end Pipeline (intermediates stay on GPU)
55
+
56
+ ```bash
57
+ midas-transforms pipeline scan.zip --device cuda --out-dir /scratch/run42
58
+ ```
59
+
60
+ ### Library
61
+
62
+ ```python
63
+ from midas_transforms import Pipeline
64
+
65
+ pipe = Pipeline.from_zarr("scan.zip", device="cuda")
66
+ result = pipe.run()
67
+ result.merge # (N, 17) on GPU
68
+ result.radius # (N, 24) on GPU
69
+ result.fit_setup # InputAll/Extra tensors on GPU
70
+ result.bins # Spots/ExtraInfo/Data/nData tensors on GPU
71
+ pipe.dump("/scratch/run42")
72
+ ```
73
+
74
+ Or use stages individually:
75
+
76
+ ```python
77
+ from midas_transforms import merge_overlapping_peaks, calc_radius, fit_setup, bin_data
78
+
79
+ merge_overlapping_peaks(zarr_path="scan.zip", device="cuda")
80
+ calc_radius(result_folder=".", zarr_params=..., device="cuda")
81
+ fit_setup(result_folder=".", zarr_params=..., device="cuda")
82
+ bin_data(result_folder=".", device="cuda")
83
+ ```
84
+
85
+ ## Wiring into `ff_MIDAS.py`
86
+
87
+ `ff_MIDAS.py` accepts a `--useTorchTransforms 1` flag (mirrors the
88
+ existing `--useTorchIndexer` / `--peakFitGPU` flags). When set, the
89
+ workflow's `merge_overlaps`, `calc_radius`, `data_transform`, and
90
+ `binning` stages dispatch to the Python entry points instead of the C
91
+ binaries. Outputs are byte-compatible (or numerically equivalent for
92
+ the `DoFit` geometry refine).
93
+
94
+ ## Limits in v0.1.0.dev0
95
+
96
+ - **Pixel-overlap merge mode** (`UsePixelOverlap=1`) is not yet supported
97
+ — use the C `MergeOverlappingPeaksAllZarr` for that path.
98
+ - **Scanning workflows** (`SaveBinDataScanning`, `MergeMultipleScans`) are
99
+ out of scope here; they belong with the broader scanning pipeline.
100
+ - **Byte-level regression vs C** is in progress. Unit tests cover kernel
101
+ correctness; full end-to-end byte-equality against C goldens lands in
102
+ v0.1.0 proper.
103
+
104
+ ## See also
105
+
106
+ - `dev/implementation_plan.md` — full design, scope, and risk register.
107
+ - `midas-peakfit` — upstream peak-fitting (writes the consolidated HDF5).
108
+ - `midas-index` — downstream indexer (consumes `Spots.bin`/`Data.bin`).
109
+ - `midas-calibrate` — provides `geometry_torch.pixel_to_REta_torch` and
110
+ `refine_geometry` (LM solver) used by `fit_setup`.
111
+ - `midas-hkls` — upstream `hkls.csv` generation.
@@ -0,0 +1,46 @@
1
+ """midas-transforms: Pure-Python/PyTorch FF-HEDM transforms.
2
+
3
+ Drop-in replacement for the four C binaries that sit between peak-fitting
4
+ (``midas-peakfit``) and indexing (``midas-index``):
5
+
6
+ - ``MergeOverlappingPeaksAllZarr`` -> ``midas_transforms.merge_overlapping_peaks``
7
+ - ``CalcRadiusAllZarr`` -> ``midas_transforms.calc_radius``
8
+ - ``FitSetupZarr`` -> ``midas_transforms.fit_setup``
9
+ - ``SaveBinData`` -> ``midas_transforms.bin_data``
10
+
11
+ Two equally-supported usage modes:
12
+
13
+ **Mode 1 - per-stage (round-trips through disk, like the C binaries):**
14
+
15
+ from midas_transforms import merge_overlapping_peaks, calc_radius, fit_setup, bin_data
16
+ merge_overlapping_peaks(zarr_path="...", result_folder="...", device="cuda")
17
+ calc_radius(result_folder="...", device="cuda")
18
+ fit_setup(result_folder="...", device="cuda")
19
+ bin_data(result_folder="...", device="cuda")
20
+
21
+ **Mode 2 - chained Pipeline (intermediates stay on GPU, only final outputs written):**
22
+
23
+ from midas_transforms import Pipeline
24
+ pipe = Pipeline.from_zarr(zarr_path, device="cuda")
25
+ result = pipe.run()
26
+ pipe.dump(out_dir)
27
+
28
+ See ``dev/implementation_plan.md`` for design and roadmap.
29
+ """
30
+
31
+ __version__ = "0.1.0"
32
+
33
+ from .merge import merge_overlapping_peaks
34
+ from .radius import calc_radius
35
+ from .fit_setup import fit_setup
36
+ from .bin_data import bin_data
37
+ from .pipeline import Pipeline
38
+
39
+ __all__ = [
40
+ "merge_overlapping_peaks",
41
+ "calc_radius",
42
+ "fit_setup",
43
+ "bin_data",
44
+ "Pipeline",
45
+ "__version__",
46
+ ]
@@ -0,0 +1,6 @@
1
+ """Allow ``python -m midas_transforms <stage> [args]``."""
2
+
3
+ from .cli import main
4
+
5
+ if __name__ == "__main__":
6
+ raise SystemExit(main())
@@ -0,0 +1,10 @@
1
+ """bin_data — replaces the C ``SaveBinData`` binary.
2
+
3
+ Reads ``InputAll.csv``, ``InputAllExtraInfoFittingAll.csv``, ``paramstest.txt``;
4
+ writes ``Spots.bin``, ``ExtraInfo.bin``, and (unless ``NoSaveAll==1``)
5
+ ``Data.bin`` + ``nData.bin``.
6
+ """
7
+
8
+ from .core import bin_data, BinDataResult
9
+
10
+ __all__ = ["bin_data", "BinDataResult"]