LumAPI 1.1.4__tar.gz → 1.1.6__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.
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI/__init__.py +2 -2
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI/lumapi.py +136 -2
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI/lumapi.pyi +2 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI/lumgenstubs.py +2 -0
- {lumapi-1.1.4 → lumapi-1.1.6/LumAPI.egg-info}/PKG-INFO +3 -3
- {lumapi-1.1.4/LumAPI.egg-info → lumapi-1.1.6}/PKG-INFO +3 -3
- {lumapi-1.1.4 → lumapi-1.1.6}/README.md +2 -2
- {lumapi-1.1.4 → lumapi-1.1.6}/pyproject.toml +1 -1
- lumapi-1.1.6/test/test.py +22 -0
- lumapi-1.1.4/test/test.py +0 -18
- {lumapi-1.1.4 → lumapi-1.1.6}/LICENSE +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI/cli.py +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI/config.json +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI/gui.py +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI.egg-info/SOURCES.txt +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI.egg-info/dependency_links.txt +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI.egg-info/entry_points.txt +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI.egg-info/requires.txt +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/LumAPI.egg-info/top_level.txt +0 -0
- {lumapi-1.1.4 → lumapi-1.1.6}/setup.cfg +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
from .lumapi import (
|
|
5
5
|
lumapi, lumerical, LumFuncBase,
|
|
6
6
|
FDTD, MODE, DEVICE, INTERCONNECT,
|
|
7
|
-
savemat, loadmat,
|
|
7
|
+
savemat, loadmat, save_h5, load_h5,
|
|
8
8
|
create_cmap, set_colorbar_range,
|
|
9
9
|
Estimate_focal, Kirchhoff,
|
|
10
10
|
RayleighSommerfeld_Scalar, RayleighSommerfeld_Vector, AngularSpectrum_Vector
|
|
@@ -14,7 +14,7 @@ from .lumapi import (
|
|
|
14
14
|
__all__ = [
|
|
15
15
|
'lumapi', 'lumerical', 'LumFuncBase',
|
|
16
16
|
'FDTD', 'MODE', 'DEVICE', 'INTERCONNECT',
|
|
17
|
-
'savemat', 'loadmat',
|
|
17
|
+
'savemat', 'loadmat', 'save_h5', 'load_h5',
|
|
18
18
|
'create_cmap', 'set_colorbar_range',
|
|
19
19
|
'Estimate_focal', 'Kirchhoff',
|
|
20
20
|
'RayleighSommerfeld_Scalar', 'RayleighSommerfeld_Vector', 'AngularSpectrum_Vector'
|
|
@@ -9,7 +9,7 @@ import re, platform
|
|
|
9
9
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
10
10
|
CONFIG_PATH = os.path.join(current_dir, 'config.json')
|
|
11
11
|
|
|
12
|
-
#
|
|
12
|
+
# ******************数据处理函数******************
|
|
13
13
|
def savemat(filename, data_dict, version='v7.3', auto_transpose=True):
|
|
14
14
|
"""
|
|
15
15
|
将字典数据写入 MATLAB .mat 文件。
|
|
@@ -49,7 +49,8 @@ def savemat(filename, data_dict, version='v7.3', auto_transpose=True):
|
|
|
49
49
|
|
|
50
50
|
if version == 'v7.3':
|
|
51
51
|
import h5py
|
|
52
|
-
|
|
52
|
+
# 预留 512 字节的 userblock 空间给 MATLAB 特征头
|
|
53
|
+
with h5py.File(filename, 'w', userblock_size=512) as f:
|
|
53
54
|
for key, data_array in processed_dict.items():
|
|
54
55
|
|
|
55
56
|
# 自动转置处理
|
|
@@ -67,6 +68,22 @@ def savemat(filename, data_dict, version='v7.3', auto_transpose=True):
|
|
|
67
68
|
f.create_dataset(key, data=mat_complex)
|
|
68
69
|
else:
|
|
69
70
|
f.create_dataset(key, data=data_array)
|
|
71
|
+
|
|
72
|
+
# 受限于底层 HDF5 C 语言库的运行机制,wb模式会清空文件,追加a模式会报错,只能先h5py保存后with open打开写入文件头
|
|
73
|
+
# HDF5 文件写入完成后,以读写模式打开并注入 MATLAB 文件头
|
|
74
|
+
with open(filename, 'r+b') as f:
|
|
75
|
+
# 前 116 字节为文本描述,不足部分用空格补齐
|
|
76
|
+
header_str = 'MATLAB 7.3 MAT-file, created by LumAPI custom script'
|
|
77
|
+
header_bytes = header_str.encode('ascii').ljust(116, b' ')
|
|
78
|
+
|
|
79
|
+
# 接下来的 8 字节为子系统数据偏移量(全 0 即可)
|
|
80
|
+
subsys_offset = b'\x00' * 8
|
|
81
|
+
|
|
82
|
+
# 最后 4 字节为版本号和字节序:0x0200 表示 v7.3,'IM' 表示小端序 (Little Endian)
|
|
83
|
+
version_and_endian = b'\x02\x00IM'
|
|
84
|
+
|
|
85
|
+
f.seek(0)
|
|
86
|
+
f.write(header_bytes + subsys_offset + version_and_endian)
|
|
70
87
|
|
|
71
88
|
elif version == 'v7':
|
|
72
89
|
import scipy.io
|
|
@@ -157,6 +174,123 @@ def loadmat(filename, auto_transpose=True, squeeze_me=True):
|
|
|
157
174
|
|
|
158
175
|
return data_dict
|
|
159
176
|
|
|
177
|
+
def save_h5(filename, data_dict, compression=True):
|
|
178
|
+
"""
|
|
179
|
+
将字典数据写入标准 HDF5 文件,支持复数处理和压缩。
|
|
180
|
+
|
|
181
|
+
参数 (Parameters):
|
|
182
|
+
------------------
|
|
183
|
+
filename : str
|
|
184
|
+
输出的 .h5 文件路径和名称。
|
|
185
|
+
data_dict : dict
|
|
186
|
+
需要写入的数据字典。
|
|
187
|
+
compression : bool, 可选 (默认: True)
|
|
188
|
+
是否进行数据压缩,使文件更小
|
|
189
|
+
|
|
190
|
+
返回 (Returns):
|
|
191
|
+
---------------
|
|
192
|
+
bool
|
|
193
|
+
写入成功返回 True。
|
|
194
|
+
"""
|
|
195
|
+
import h5py
|
|
196
|
+
# 自动补全后缀
|
|
197
|
+
if not filename.endswith('.h5') and not filename.endswith('.hdf5'):
|
|
198
|
+
filename += '.h5'
|
|
199
|
+
|
|
200
|
+
with h5py.File(filename, 'w') as f:
|
|
201
|
+
for key, val in data_dict.items():
|
|
202
|
+
data = np.asarray(val)
|
|
203
|
+
|
|
204
|
+
# 将所有数据(包括标量)强制提升为至少2维来兼容matlab和origin的读取。
|
|
205
|
+
data = np.atleast_2d(data)
|
|
206
|
+
|
|
207
|
+
# 处理数据类型:将整型转为双精度浮点
|
|
208
|
+
if np.issubdtype(data.dtype, np.integer):
|
|
209
|
+
data = data.astype(np.float64)
|
|
210
|
+
|
|
211
|
+
# 压缩设置:对于大数据非常有帮助
|
|
212
|
+
dataset_args = {}
|
|
213
|
+
# 仅在数据量超过一定大小时启用压缩
|
|
214
|
+
if compression and data.ndim > 1024:
|
|
215
|
+
dataset_args = {"compression": "gzip", "compression_opts": 4}
|
|
216
|
+
|
|
217
|
+
if np.iscomplexobj(data):
|
|
218
|
+
# 采用复合类型存储复数
|
|
219
|
+
complex_dt = np.dtype([('real', data.real.dtype), ('imag', data.imag.dtype)])
|
|
220
|
+
mat_complex = np.empty(data.shape, dtype=complex_dt)
|
|
221
|
+
|
|
222
|
+
# 兼容 0D 标量复数和多维复数数组的赋值
|
|
223
|
+
if data.ndim == 0:
|
|
224
|
+
mat_complex['real'] = data.real
|
|
225
|
+
mat_complex['imag'] = data.imag
|
|
226
|
+
else:
|
|
227
|
+
mat_complex['real'] = data.real
|
|
228
|
+
mat_complex['imag'] = data.imag
|
|
229
|
+
|
|
230
|
+
dset = f.create_dataset(key, data=mat_complex, **dataset_args)
|
|
231
|
+
dset.attrs['is_complex'] = 1
|
|
232
|
+
else:
|
|
233
|
+
f.create_dataset(key, data=data, **dataset_args)
|
|
234
|
+
|
|
235
|
+
# print(f"[成功] 数据已保存至标准 HDF5: {filename}")
|
|
236
|
+
return True
|
|
237
|
+
|
|
238
|
+
def load_h5(filename, squeeze_me=True):
|
|
239
|
+
"""
|
|
240
|
+
从标准 HDF5 文件读取数据,并自动恢复复数结构。
|
|
241
|
+
|
|
242
|
+
参数 (Parameters):
|
|
243
|
+
------------------
|
|
244
|
+
filename : str
|
|
245
|
+
读取的 .h5 文件路径和名称。
|
|
246
|
+
squeeze_me : bool, 可选 (默认: True)
|
|
247
|
+
是否开启数组压缩功能。
|
|
248
|
+
如果开启,会自动将 1xN 或 Nx1 数组降维为真正的 1D NumPy 数组 (N,)。
|
|
249
|
+
同时会将 1x1 的矩阵提取为单纯的标量。
|
|
250
|
+
|
|
251
|
+
返回 (Returns):
|
|
252
|
+
---------------
|
|
253
|
+
dict
|
|
254
|
+
读取的数据字典。
|
|
255
|
+
"""
|
|
256
|
+
import h5py
|
|
257
|
+
if not os.path.exists(filename):
|
|
258
|
+
raise FileNotFoundError(f"找不到文件: {filename}")
|
|
259
|
+
|
|
260
|
+
data_dict = {}
|
|
261
|
+
try:
|
|
262
|
+
with h5py.File(filename, 'r') as f:
|
|
263
|
+
for key in f.keys():
|
|
264
|
+
data = np.array(f[key])
|
|
265
|
+
|
|
266
|
+
# 自动检测并恢复复数
|
|
267
|
+
# 检查是否存在属性标记,或检查复合类型字段
|
|
268
|
+
is_complex = f[key].attrs.get('is_complex', 0)
|
|
269
|
+
has_fields = data.dtype.names is not None and 'real' in data.dtype.names
|
|
270
|
+
|
|
271
|
+
if is_complex or has_fields:
|
|
272
|
+
data = data['real'] + 1j * data['imag']
|
|
273
|
+
|
|
274
|
+
# 维度压缩处理
|
|
275
|
+
if isinstance(data, np.ndarray):
|
|
276
|
+
# 维度压缩
|
|
277
|
+
if squeeze_me:
|
|
278
|
+
# np.squeeze 会自动剥离所有大小为 1 的维度
|
|
279
|
+
data = np.squeeze(data)
|
|
280
|
+
|
|
281
|
+
# 提取标量处理
|
|
282
|
+
if data.ndim == 0:
|
|
283
|
+
# 提取 0维 数组为真正的标量值
|
|
284
|
+
data = data[()]
|
|
285
|
+
elif not squeeze_me and data.shape == (1, 1):
|
|
286
|
+
# 如果用户关闭了压缩,兜底提取 1x1 矩阵为标量
|
|
287
|
+
data = data[0, 0]
|
|
288
|
+
|
|
289
|
+
data_dict[key] = data
|
|
290
|
+
return data_dict
|
|
291
|
+
except Exception as e:
|
|
292
|
+
print(f"错误:读取 H5 文件失败 - {str(e)}")
|
|
293
|
+
return None
|
|
160
294
|
|
|
161
295
|
# *****************绘图增强函数******************
|
|
162
296
|
def create_cmap(color_list, cmap_name="custom_cmap"):
|
|
@@ -4,6 +4,8 @@ import numpy as np
|
|
|
4
4
|
# ================= 自定义功能函数 =================
|
|
5
5
|
def savemat(filename: str, data_dict: Dict[str, Any], version: str = 'v7.3', auto_transpose: bool = True) -> bool: ...
|
|
6
6
|
def loadmat(filename: str, auto_transpose: bool = True, squeeze_me: bool = True) -> Dict[str, Any]: ...
|
|
7
|
+
def save_h5(filename, data_dict, compression=True) -> bool: ...
|
|
8
|
+
def load_h5(filename) -> Dict[str, Any]: ...
|
|
7
9
|
|
|
8
10
|
def create_cmap(color_list: list, cmap_name: str = "custom_cmap") -> Any: ...
|
|
9
11
|
def set_colorbar_range(mappable: Any, vmin: float, vmax: float) -> None: ...
|
|
@@ -58,6 +58,8 @@ import numpy as np
|
|
|
58
58
|
# ================= mat保存读取函数 =================
|
|
59
59
|
def savemat(filename: str, data_dict: Dict[str, Any], version: str = 'v7.3', auto_transpose: bool = True) -> bool: ...
|
|
60
60
|
def loadmat(filename: str, auto_transpose: bool = True, squeeze_me: bool = True) -> Dict[str, Any]: ...
|
|
61
|
+
def save_h5(filename, data_dict, compression=True) -> bool: ...
|
|
62
|
+
def load_h5(filename) -> Dict[str, Any]: ...
|
|
61
63
|
|
|
62
64
|
# ==================== 绘图函数 ====================
|
|
63
65
|
def create_cmap(color_list: list, cmap_name: str = "custom_cmap") -> Any: ...
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: LumAPI
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.6
|
|
4
4
|
Summary: Lumerical Python API 自动化配置工具
|
|
5
5
|
Author-email: JaniQuiz <janiquiz@163.com>
|
|
6
6
|
Maintainer-email: JaniQuiz <janiquiz@163.com>
|
|
@@ -22,7 +22,7 @@ Requires-Dist: h5py
|
|
|
22
22
|
Requires-Dist: tqdm
|
|
23
23
|
Dynamic: license-file
|
|
24
24
|
|
|
25
|
-
# Lumerical
|
|
25
|
+
# LumAPI:Lumerical Python接口的轻量级封装与增强库
|
|
26
26
|
|
|
27
27
|
本项目旨在简化 Lumerical FDTD 软件与 Python 环境的交互流程,提供自动化的路径配置工具,并封装了matlab数据文件.mat的读取和写入,以及常用的光学仿真后处理算法(如近场至远场变换)。
|
|
28
28
|
|
|
@@ -55,7 +55,7 @@ Dynamic: license-file
|
|
|
55
55
|
- [矢量角谱(Angular Spectrum)矢量衍射积分函数验证](docs/AngularSpectrum_Vector.md)
|
|
56
56
|
|
|
57
57
|
## 📜 许可证
|
|
58
|
-
|
|
58
|
+
本仓库遵循[GPL-3.0](https://www.gnu.org/licenses/gpl-3.0.html)开源许可证
|
|
59
59
|
|
|
60
60
|
## 📧 联系作者
|
|
61
61
|
- **作者**: [JaniQuiz](https://github.com/JaniQuiz)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: LumAPI
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.6
|
|
4
4
|
Summary: Lumerical Python API 自动化配置工具
|
|
5
5
|
Author-email: JaniQuiz <janiquiz@163.com>
|
|
6
6
|
Maintainer-email: JaniQuiz <janiquiz@163.com>
|
|
@@ -22,7 +22,7 @@ Requires-Dist: h5py
|
|
|
22
22
|
Requires-Dist: tqdm
|
|
23
23
|
Dynamic: license-file
|
|
24
24
|
|
|
25
|
-
# Lumerical
|
|
25
|
+
# LumAPI:Lumerical Python接口的轻量级封装与增强库
|
|
26
26
|
|
|
27
27
|
本项目旨在简化 Lumerical FDTD 软件与 Python 环境的交互流程,提供自动化的路径配置工具,并封装了matlab数据文件.mat的读取和写入,以及常用的光学仿真后处理算法(如近场至远场变换)。
|
|
28
28
|
|
|
@@ -55,7 +55,7 @@ Dynamic: license-file
|
|
|
55
55
|
- [矢量角谱(Angular Spectrum)矢量衍射积分函数验证](docs/AngularSpectrum_Vector.md)
|
|
56
56
|
|
|
57
57
|
## 📜 许可证
|
|
58
|
-
|
|
58
|
+
本仓库遵循[GPL-3.0](https://www.gnu.org/licenses/gpl-3.0.html)开源许可证
|
|
59
59
|
|
|
60
60
|
## 📧 联系作者
|
|
61
61
|
- **作者**: [JaniQuiz](https://github.com/JaniQuiz)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Lumerical
|
|
1
|
+
# LumAPI:Lumerical Python接口的轻量级封装与增强库
|
|
2
2
|
|
|
3
3
|
本项目旨在简化 Lumerical FDTD 软件与 Python 环境的交互流程,提供自动化的路径配置工具,并封装了matlab数据文件.mat的读取和写入,以及常用的光学仿真后处理算法(如近场至远场变换)。
|
|
4
4
|
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
- [矢量角谱(Angular Spectrum)矢量衍射积分函数验证](docs/AngularSpectrum_Vector.md)
|
|
32
32
|
|
|
33
33
|
## 📜 许可证
|
|
34
|
-
|
|
34
|
+
本仓库遵循[GPL-3.0](https://www.gnu.org/licenses/gpl-3.0.html)开源许可证
|
|
35
35
|
|
|
36
36
|
## 📧 联系作者
|
|
37
37
|
- **作者**: [JaniQuiz](https://github.com/JaniQuiz)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from LumAPI import *
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
# x = np.linspace(0, 1, 100)
|
|
5
|
+
# y = np.linspace(0, 1, 100)
|
|
6
|
+
# X, Y = np.meshgrid(x, y)
|
|
7
|
+
# E = np.ones_like(X)
|
|
8
|
+
|
|
9
|
+
# data = {
|
|
10
|
+
# 'x': x,
|
|
11
|
+
# 'y': y,
|
|
12
|
+
# 'E': E
|
|
13
|
+
# }
|
|
14
|
+
# savemat('test.mat', data)
|
|
15
|
+
|
|
16
|
+
fdtd = lumapi.FDTD()
|
|
17
|
+
fdtd.addrect()
|
|
18
|
+
|
|
19
|
+
fdtd.close()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
lumapi-1.1.4/test/test.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|