c2ImageD11 0.2.1__py2-none-win_amd64.whl

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.
c2ImageD11/__init__.py ADDED
@@ -0,0 +1,136 @@
1
+ """
2
+ c2ImageD11 - compiled C extensions for ImageD11, built with c2py23.
3
+
4
+ Provides:
5
+ - All C functions re-exported from the arch-named .so
6
+ - Blob property constants (s_1, s_I, NPROPERTY, etc.)
7
+ - Allocation wrappers for f2py-compatible tuple returns
8
+ - __version__
9
+ """
10
+
11
+ from __future__ import absolute_import, division, print_function, unicode_literals
12
+
13
+ __version__ = "0.2.1"
14
+
15
+ import os
16
+ import platform
17
+ import sys
18
+ import warnings
19
+
20
+ # ---------------------------------------------------------------------------
21
+ # Arch-aware .so loader
22
+ #
23
+ # The .so files in this directory follow the naming convention:
24
+ # _cImageD11_{arch}.so (Linux)
25
+ # _cImageD11_{arch}.pyd (Windows)
26
+ #
27
+ # Where {arch} matches platform.machine() output:
28
+ # x86_64, aarch64, ppc64le, AMD64 (Windows), arm64 (Windows)
29
+ #
30
+ # The same binary works across Python 2.7-3.14 because c2py23 emits both
31
+ # init_cImageD11 (Py2) and PyInit__cImageD11 (Py3) entry points.
32
+ # ---------------------------------------------------------------------------
33
+
34
+ _here = os.path.dirname(__file__)
35
+ _arch = platform.machine()
36
+ _ext = ".pyd" if sys.platform == "win32" else ".so"
37
+ _lib_name = "_cImageD11_{}{}".format(_arch, _ext)
38
+ _lib_path = os.path.join(_here, _lib_name)
39
+
40
+ # Fallback: plain name _cImageD11.so (no arch suffix)
41
+ if not os.path.exists(_lib_path):
42
+ _lib_path = os.path.join(_here, "_cImageD11" + _ext)
43
+
44
+ if not os.path.exists(_lib_path):
45
+ # .so not built yet (e.g. during setuptools metadata reading).
46
+ # __version__ is still available; C functions will not be.
47
+ _mod = None
48
+ else:
49
+ if sys.version_info[0] >= 3:
50
+ import importlib.util
51
+ _spec = importlib.util.spec_from_file_location(
52
+ "c2ImageD11._cImageD11", _lib_path)
53
+ _mod = importlib.util.module_from_spec(_spec)
54
+ sys.modules["c2ImageD11._cImageD11"] = _mod
55
+ _spec.loader.exec_module(_mod)
56
+ else:
57
+ import imp
58
+ _mod = imp.load_dynamic("c2ImageD11._cImageD11", _lib_path)
59
+
60
+ if _mod is not None:
61
+ # Make _cImageD11 importable as c2ImageD11._cImageD11
62
+ sys.modules[__name__]._cImageD11 = _mod
63
+
64
+ # Re-export all non-private names from the loaded module
65
+ for _k in dir(_mod):
66
+ if not _k.startswith("_"):
67
+ globals()[_k] = getattr(_mod, _k)
68
+
69
+
70
+ _blobproperties_c = _mod.blobproperties # save raw C function
71
+
72
+ def blobproperties(data, labels, npk, omega=0.0, verbose=0):
73
+ """Allocate results and call C blobproperties, matching f2py convention."""
74
+ import numpy as np
75
+ results = np.zeros((npk, 36), dtype=np.float64)
76
+ _blobproperties_c(data, labels, npk, results, omega, verbose)
77
+ return results
78
+
79
+ _sparse_blob2Dproperties_c = _mod.sparse_blob2Dproperties
80
+
81
+ def sparse_blob2Dproperties(v, i, j, labels, npk):
82
+ """Allocate results and call C sparse_blob2Dproperties, matching f2py convention."""
83
+ import numpy as np
84
+ results = np.zeros((npk, 11), dtype=np.float64)
85
+ _sparse_blob2Dproperties_c(v, i, j, labels, npk, results)
86
+ return results
87
+
88
+ # Replace raw C functions on submodule with allocation wrappers
89
+ _mod.blobproperties = blobproperties
90
+ _mod.sparse_blob2Dproperties = sparse_blob2Dproperties
91
+
92
+
93
+ # -----------------------------------------------------------------------
94
+ # OpenMP safety
95
+ # -----------------------------------------------------------------------
96
+
97
+ def _check_multiprocessing(patch=False):
98
+ """Warn about fork+threads interaction with OpenMP.
99
+
100
+ You cannot safely use os.fork together with threads.
101
+ But the cImageD11 codes uses threads via openmp, and you are importing them.
102
+ So please use forkserver or spawn for multiprocessing.
103
+ """
104
+ if not hasattr(os, "fork"):
105
+ return
106
+ import multiprocessing
107
+ if not hasattr(multiprocessing, "get_start_method"):
108
+ warnings.warn(
109
+ "python2.7 with c2ImageD11: for multiprocessing use spawn\n"
110
+ )
111
+ return
112
+ method = multiprocessing.get_start_method(allow_none=True)
113
+ if method == "fork":
114
+ warnings.warn(_check_multiprocessing.__doc__)
115
+ parent = None
116
+ if hasattr(multiprocessing, "parent_process"):
117
+ parent = multiprocessing.parent_process()
118
+ if parent is not None:
119
+ if "OMP_NUM_THREADS" not in os.environ:
120
+ cimaged11_omp_set_num_threads(1)
121
+
122
+
123
+ check_multiprocessing = _check_multiprocessing # public alias (f2py compat)
124
+
125
+ if cimaged11_omp_get_max_threads() == 0:
126
+ OPENMP = False
127
+ else:
128
+ OPENMP = True
129
+ _check_multiprocessing()
130
+
131
+
132
+ # -----------------------------------------------------------------------
133
+ # Sanity check
134
+ # -----------------------------------------------------------------------
135
+
136
+ assert verify_rounding(20) == 0, "Problem with cImageD11 fast rounding code"
Binary file
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: c2ImageD11
3
+ Version: 0.2.1
4
+ Summary: C extensions for ImageD11 (c2py23 binding)
5
+ Author-email: Jon Wright <wright@esrf.fr>
6
+ Project-URL: Homepage, https://github.com/jonwright/c2ImageD11
7
+ Project-URL: Source, https://github.com/jonwright/c2ImageD11
8
+ Project-URL: Bug tracker, https://github.com/jonwright/c2ImageD11/issues
9
+ Keywords: imageD11,diffraction,xray,crystallography
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
13
+ Classifier: Programming Language :: Python :: 2.7
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: C
16
+ Classifier: Topic :: Scientific/Engineering :: Physics
17
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
18
+ Requires-Python: >=2.7
19
+ Description-Content-Type: text/markdown
20
+ Requires-Dist: numpy
21
+
22
+ # c2ImageD11
23
+
24
+ > All code in this repository was generated by [DeepSeek V4](https://deepseek.com)
25
+ > and other large language models, in collaboration with jonwright.
26
+
27
+ Standalone C extensions for ImageD11, ported from f2py to **c2py23**.
28
+ C functions are exposed by a generated CPython extension wrapper.
29
+ Two functions (`blobproperties`, `sparse_blob2Dproperties`) have thin
30
+ Python allocation wrappers in `__init__.py` to match f2py's convention
31
+ of auto-allocating output arrays.
32
+
33
+ ## Build
34
+
35
+ A normal build needs only meson + ninja + a C compiler. The generated
36
+ files in `lib/interface/` are checked into git, so c2py23 is **not**
37
+ required.
38
+
39
+ ```bash
40
+ mkdir -p build/libc2ImageD11
41
+ cd build/libc2ImageD11
42
+ meson setup ../../lib
43
+ ninja
44
+ cp _cImageD11.so ../../c2ImageD11/
45
+ ```
46
+
47
+ ## Regenerate `lib/interface/`
48
+
49
+ Run this when C2PY_BLOCKs change or c2py23 is updated (requires c2py23):
50
+
51
+ ```bash
52
+ python3 tools/harvester.py --output-dir lib/interface
53
+ ```
54
+
55
+ ## Test
56
+
57
+ ```bash
58
+ python3 -m pytest tests/
59
+ ```
60
+
61
+ ## Distributing
62
+
63
+ Copy `_cImageD11.so` into `c2ImageD11/` and the package is ready --
64
+ same pattern as a ctypes library.
@@ -0,0 +1,6 @@
1
+ c2ImageD11/__init__.py,sha256=ybxdyUGoxXdo_USrawgibdoSSqTRTtCVcT3RItedyc0,5028
2
+ c2ImageD11/_cImageD11_AMD64.pyd,sha256=kODIkD6BnHYjNuzuPFf3JjuxUf2ElHKdFVSqoukO_cI,535552
3
+ c2imaged11-0.2.1.dist-info/METADATA,sha256=afrGQ40CwudLhQNGHcg9HalikchC0Ic4NkOR-nZUdBo,2080
4
+ c2imaged11-0.2.1.dist-info/WHEEL,sha256=E7_2keCVFfKMIq0kiQu-iEup9Yz5uqe35RtC3nD1cQg,98
5
+ c2imaged11-0.2.1.dist-info/top_level.txt,sha256=Zisg4zXBajKHAbtdPf0ik4OXFXJvGCq7GfSjomZw478,11
6
+ c2imaged11-0.2.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: false
4
+ Tag: py2-none-win_amd64
5
+
@@ -0,0 +1 @@
1
+ c2ImageD11