c2ImageD11 0.2.1__py3-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 +167 -0
- c2ImageD11/_cImageD11_AMD64.pyd +0 -0
- c2imaged11-0.2.1.dist-info/DELVEWHEEL +2 -0
- c2imaged11-0.2.1.dist-info/METADATA +64 -0
- c2imaged11-0.2.1.dist-info/RECORD +10 -0
- c2imaged11-0.2.1.dist-info/WHEEL +5 -0
- c2imaged11-0.2.1.dist-info/top_level.txt +1 -0
- c2imaged11.libs/.load-order-c2imaged11-0.2.1 +2 -0
- c2imaged11.libs/vcomp140-f96f3a14d88d8846f31f3ab38a490304.dll +0 -0
- c2imaged11.libs/vcruntime140-052ad6a20d375957e82aa6a3c441ea54.dll +0 -0
c2ImageD11/__init__.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
|
|
14
|
+
# start delvewheel patch
|
|
15
|
+
def _delvewheel_patch_1_13_0():
|
|
16
|
+
import ctypes
|
|
17
|
+
import os
|
|
18
|
+
import platform
|
|
19
|
+
import sys
|
|
20
|
+
libs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'c2imaged11.libs'))
|
|
21
|
+
is_conda_cpython = platform.python_implementation() == 'CPython' and (hasattr(ctypes.pythonapi, 'Anaconda_GetVersion') or 'packaged by conda-forge' in sys.version)
|
|
22
|
+
if sys.version_info[:2] >= (3, 8) and not is_conda_cpython or sys.version_info[:2] >= (3, 10):
|
|
23
|
+
if os.path.isdir(libs_dir):
|
|
24
|
+
os.add_dll_directory(libs_dir)
|
|
25
|
+
else:
|
|
26
|
+
load_order_filepath = os.path.join(libs_dir, '.load-order-c2imaged11-0.2.1')
|
|
27
|
+
if os.path.isfile(load_order_filepath):
|
|
28
|
+
import ctypes.wintypes
|
|
29
|
+
with open(os.path.join(libs_dir, '.load-order-c2imaged11-0.2.1')) as file:
|
|
30
|
+
load_order = file.read().split()
|
|
31
|
+
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
|
|
32
|
+
kernel32.LoadLibraryExW.restype = ctypes.wintypes.HMODULE
|
|
33
|
+
kernel32.LoadLibraryExW.argtypes = ctypes.wintypes.LPCWSTR, ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD
|
|
34
|
+
for lib in load_order:
|
|
35
|
+
lib_path = os.path.join(os.path.join(libs_dir, lib))
|
|
36
|
+
if os.path.isfile(lib_path) and not kernel32.LoadLibraryExW(lib_path, None, 8):
|
|
37
|
+
raise OSError('Error loading {}; {}'.format(lib, ctypes.FormatError(ctypes.get_last_error())))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
_delvewheel_patch_1_13_0()
|
|
41
|
+
del _delvewheel_patch_1_13_0
|
|
42
|
+
# end delvewheel patch
|
|
43
|
+
|
|
44
|
+
__version__ = "0.2.1"
|
|
45
|
+
|
|
46
|
+
import os
|
|
47
|
+
import platform
|
|
48
|
+
import sys
|
|
49
|
+
import warnings
|
|
50
|
+
|
|
51
|
+
# ---------------------------------------------------------------------------
|
|
52
|
+
# Arch-aware .so loader
|
|
53
|
+
#
|
|
54
|
+
# The .so files in this directory follow the naming convention:
|
|
55
|
+
# _cImageD11_{arch}.so (Linux)
|
|
56
|
+
# _cImageD11_{arch}.pyd (Windows)
|
|
57
|
+
#
|
|
58
|
+
# Where {arch} matches platform.machine() output:
|
|
59
|
+
# x86_64, aarch64, ppc64le, AMD64 (Windows), arm64 (Windows)
|
|
60
|
+
#
|
|
61
|
+
# The same binary works across Python 2.7-3.14 because c2py23 emits both
|
|
62
|
+
# init_cImageD11 (Py2) and PyInit__cImageD11 (Py3) entry points.
|
|
63
|
+
# ---------------------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
_here = os.path.dirname(__file__)
|
|
66
|
+
_arch = platform.machine()
|
|
67
|
+
_ext = ".pyd" if sys.platform == "win32" else ".so"
|
|
68
|
+
_lib_name = "_cImageD11_{}{}".format(_arch, _ext)
|
|
69
|
+
_lib_path = os.path.join(_here, _lib_name)
|
|
70
|
+
|
|
71
|
+
# Fallback: plain name _cImageD11.so (no arch suffix)
|
|
72
|
+
if not os.path.exists(_lib_path):
|
|
73
|
+
_lib_path = os.path.join(_here, "_cImageD11" + _ext)
|
|
74
|
+
|
|
75
|
+
if not os.path.exists(_lib_path):
|
|
76
|
+
# .so not built yet (e.g. during setuptools metadata reading).
|
|
77
|
+
# __version__ is still available; C functions will not be.
|
|
78
|
+
_mod = None
|
|
79
|
+
else:
|
|
80
|
+
if sys.version_info[0] >= 3:
|
|
81
|
+
import importlib.util
|
|
82
|
+
_spec = importlib.util.spec_from_file_location(
|
|
83
|
+
"c2ImageD11._cImageD11", _lib_path)
|
|
84
|
+
_mod = importlib.util.module_from_spec(_spec)
|
|
85
|
+
sys.modules["c2ImageD11._cImageD11"] = _mod
|
|
86
|
+
_spec.loader.exec_module(_mod)
|
|
87
|
+
else:
|
|
88
|
+
import imp
|
|
89
|
+
_mod = imp.load_dynamic("c2ImageD11._cImageD11", _lib_path)
|
|
90
|
+
|
|
91
|
+
if _mod is not None:
|
|
92
|
+
# Make _cImageD11 importable as c2ImageD11._cImageD11
|
|
93
|
+
sys.modules[__name__]._cImageD11 = _mod
|
|
94
|
+
|
|
95
|
+
# Re-export all non-private names from the loaded module
|
|
96
|
+
for _k in dir(_mod):
|
|
97
|
+
if not _k.startswith("_"):
|
|
98
|
+
globals()[_k] = getattr(_mod, _k)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
_blobproperties_c = _mod.blobproperties # save raw C function
|
|
102
|
+
|
|
103
|
+
def blobproperties(data, labels, npk, omega=0.0, verbose=0):
|
|
104
|
+
"""Allocate results and call C blobproperties, matching f2py convention."""
|
|
105
|
+
import numpy as np
|
|
106
|
+
results = np.zeros((npk, 36), dtype=np.float64)
|
|
107
|
+
_blobproperties_c(data, labels, npk, results, omega, verbose)
|
|
108
|
+
return results
|
|
109
|
+
|
|
110
|
+
_sparse_blob2Dproperties_c = _mod.sparse_blob2Dproperties
|
|
111
|
+
|
|
112
|
+
def sparse_blob2Dproperties(v, i, j, labels, npk):
|
|
113
|
+
"""Allocate results and call C sparse_blob2Dproperties, matching f2py convention."""
|
|
114
|
+
import numpy as np
|
|
115
|
+
results = np.zeros((npk, 11), dtype=np.float64)
|
|
116
|
+
_sparse_blob2Dproperties_c(v, i, j, labels, npk, results)
|
|
117
|
+
return results
|
|
118
|
+
|
|
119
|
+
# Replace raw C functions on submodule with allocation wrappers
|
|
120
|
+
_mod.blobproperties = blobproperties
|
|
121
|
+
_mod.sparse_blob2Dproperties = sparse_blob2Dproperties
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# -----------------------------------------------------------------------
|
|
125
|
+
# OpenMP safety
|
|
126
|
+
# -----------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
def _check_multiprocessing(patch=False):
|
|
129
|
+
"""Warn about fork+threads interaction with OpenMP.
|
|
130
|
+
|
|
131
|
+
You cannot safely use os.fork together with threads.
|
|
132
|
+
But the cImageD11 codes uses threads via openmp, and you are importing them.
|
|
133
|
+
So please use forkserver or spawn for multiprocessing.
|
|
134
|
+
"""
|
|
135
|
+
if not hasattr(os, "fork"):
|
|
136
|
+
return
|
|
137
|
+
import multiprocessing
|
|
138
|
+
if not hasattr(multiprocessing, "get_start_method"):
|
|
139
|
+
warnings.warn(
|
|
140
|
+
"python2.7 with c2ImageD11: for multiprocessing use spawn\n"
|
|
141
|
+
)
|
|
142
|
+
return
|
|
143
|
+
method = multiprocessing.get_start_method(allow_none=True)
|
|
144
|
+
if method == "fork":
|
|
145
|
+
warnings.warn(_check_multiprocessing.__doc__)
|
|
146
|
+
parent = None
|
|
147
|
+
if hasattr(multiprocessing, "parent_process"):
|
|
148
|
+
parent = multiprocessing.parent_process()
|
|
149
|
+
if parent is not None:
|
|
150
|
+
if "OMP_NUM_THREADS" not in os.environ:
|
|
151
|
+
cimaged11_omp_set_num_threads(1)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
check_multiprocessing = _check_multiprocessing # public alias (f2py compat)
|
|
155
|
+
|
|
156
|
+
if cimaged11_omp_get_max_threads() == 0:
|
|
157
|
+
OPENMP = False
|
|
158
|
+
else:
|
|
159
|
+
OPENMP = True
|
|
160
|
+
_check_multiprocessing()
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
# -----------------------------------------------------------------------
|
|
164
|
+
# Sanity check
|
|
165
|
+
# -----------------------------------------------------------------------
|
|
166
|
+
|
|
167
|
+
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,10 @@
|
|
|
1
|
+
c2ImageD11/_cImageD11_AMD64.pyd,sha256=et6P7swpbeNwAZDNwuuQe5-vmp6oKGPgc8ef4jEYpdU,519680
|
|
2
|
+
c2ImageD11/__init__.py,sha256=r8FdrFlu2XFV0phwoCy3591z-5EX2OwEIj3qBU6sMyo,6601
|
|
3
|
+
c2imaged11-0.2.1.dist-info/DELVEWHEEL,sha256=-lVgGiiZ4hyUpVETfAQxTD3zBpZfysq47Urv_PqQ8ic,225
|
|
4
|
+
c2imaged11-0.2.1.dist-info/METADATA,sha256=afrGQ40CwudLhQNGHcg9HalikchC0Ic4NkOR-nZUdBo,2080
|
|
5
|
+
c2imaged11-0.2.1.dist-info/RECORD,,
|
|
6
|
+
c2imaged11-0.2.1.dist-info/top_level.txt,sha256=Zisg4zXBajKHAbtdPf0ik4OXFXJvGCq7GfSjomZw478,11
|
|
7
|
+
c2imaged11-0.2.1.dist-info/WHEEL,sha256=GjDPPQwEcripVP6P2r3RxLa-h5Lb9ifGB7FYYtbLDT0,98
|
|
8
|
+
c2imaged11.libs/.load-order-c2imaged11-0.2.1,sha256=itUAVgurK8BVFTvlvrNUGCnz1DP3lfluDCnSXl1U_mY,96
|
|
9
|
+
c2imaged11.libs/vcomp140-f96f3a14d88d8846f31f3ab38a490304.dll,sha256=-W86FNiNiEbzHzqzikkDBM59bk9w-uQwTGPlnHrqLTA,213072
|
|
10
|
+
c2imaged11.libs/vcruntime140-052ad6a20d375957e82aa6a3c441ea54.dll,sha256=BSrWog03WVfoKqajxEHqVI2JvgmBUWyn6zBuBj1QJ_Q,120400
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c2ImageD11
|
|
Binary file
|
|
Binary file
|