reflectorch 1.2.0__py3-none-any.whl → 1.2.1__py3-none-any.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.
Potentially problematic release.
This version of reflectorch might be problematic. Click here for more details.
- reflectorch/data_generation/reflectivity/__init__.py +3 -3
- reflectorch/data_generation/reflectivity/abeles.py +31 -16
- reflectorch/data_generation/reflectivity/kinematical.py +1 -1
- reflectorch/data_generation/reflectivity/memory_eff.py +1 -1
- reflectorch/inference/inference_model.py +4 -2
- {reflectorch-1.2.0.dist-info → reflectorch-1.2.1.dist-info}/METADATA +1 -1
- {reflectorch-1.2.0.dist-info → reflectorch-1.2.1.dist-info}/RECORD +10 -10
- {reflectorch-1.2.0.dist-info → reflectorch-1.2.1.dist-info}/LICENSE.txt +0 -0
- {reflectorch-1.2.0.dist-info → reflectorch-1.2.1.dist-info}/WHEEL +0 -0
- {reflectorch-1.2.0.dist-info → reflectorch-1.2.1.dist-info}/top_level.txt +0 -0
|
@@ -31,15 +31,15 @@ def reflectivity(
|
|
|
31
31
|
q (Tensor): tensor of momentum transfer (q) values with shape [batch_size, n_points] or [n_points]
|
|
32
32
|
thickness (Tensor): tensor containing the layer thicknesses (ordered from top to bottom) with shape [batch_size, n_layers]
|
|
33
33
|
roughness (Tensor): tensor containing the interlayer roughnesses (ordered from top to bottom) with shape [batch_size, n_layers + 1]
|
|
34
|
-
sld (Tensor):
|
|
35
|
-
|
|
34
|
+
sld (Tensor): tensor containing the layer SLDs (real or complex; ordered from top to bottom) with shape
|
|
35
|
+
[batch_size, n_layers + 1] (excluding ambient SLD which is assumed to be 0) or [batch_size, n_layers + 2] (including ambient SLD; only for the default ``abeles_func='abeles'``)
|
|
36
36
|
dq (Tensor, optional): tensor of resolutions used for curve smearing with shape [batch_size, 1].
|
|
37
37
|
Either dq if ``constant_dq`` is ``True`` or dq/q if ``constant_dq`` is ``False``. Defaults to None.
|
|
38
38
|
gauss_num (int, optional): the number of gaussians for curve smearing. Defaults to 51.
|
|
39
39
|
constant_dq (bool, optional): if ``True`` the smearing is constant (constant dq at each point in the curve)
|
|
40
40
|
otherwise the smearing is linear (constant dq/q at each point in the curve). Defaults to True.
|
|
41
41
|
log (bool, optional): if True the base 10 logarithm of the reflectivity curves is returned. Defaults to False.
|
|
42
|
-
abeles_func (Callable, optional): a function implementing the simulation of the reflectivity curves, if different than the default Abeles matrix implementation. Defaults to None.
|
|
42
|
+
abeles_func (Callable, optional): a function implementing the simulation of the reflectivity curves, if different than the default Abeles matrix implementation ('abeles'). Defaults to None.
|
|
43
43
|
|
|
44
44
|
Returns:
|
|
45
45
|
Tensor: tensor containing the simulated reflectivity curves with shape [batch_size, n_points]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import math
|
|
3
|
+
from functools import reduce
|
|
3
4
|
|
|
4
5
|
import torch
|
|
5
6
|
from torch import Tensor
|
|
@@ -17,8 +18,9 @@ def abeles(
|
|
|
17
18
|
q (Tensor): tensor of momentum transfer (q) values with shape [batch_size, n_points] or [n_points]
|
|
18
19
|
thickness (Tensor): tensor containing the layer thicknesses (ordered from top to bottom) with shape [batch_size, n_layers]
|
|
19
20
|
roughness (Tensor): tensor containing the interlayer roughnesses (ordered from top to bottom) with shape [batch_size, n_layers + 1]
|
|
20
|
-
sld (Tensor):
|
|
21
|
-
|
|
21
|
+
sld (Tensor): tensor containing the layer SLDs (real or complex; ordered from top to bottom). The tensor shape should be one of the following:
|
|
22
|
+
- [batch_size, n_layers + 1]: in this case, the ambient SLD is not included but assumed to be 0
|
|
23
|
+
- [batch_size, n_layers + 2]: this shape includes the ambient SLD as the first element in the tensor
|
|
22
24
|
|
|
23
25
|
Returns:
|
|
24
26
|
Tensor: tensor containing the simulated reflectivity curves with shape [batch_size, n_points]
|
|
@@ -27,11 +29,24 @@ def abeles(
|
|
|
27
29
|
|
|
28
30
|
batch_size, num_layers = thickness.shape
|
|
29
31
|
|
|
30
|
-
sld
|
|
31
|
-
|
|
32
|
+
if sld.shape[-1] == num_layers + 1:
|
|
33
|
+
# add zero ambient sld
|
|
34
|
+
sld = torch.cat([torch.zeros(batch_size, 1).to(sld), sld], -1)
|
|
35
|
+
if sld.shape[-1] != num_layers + 2:
|
|
36
|
+
raise ValueError(
|
|
37
|
+
"Number of SLD values does not equal to num_layers + 2 (substrate + ambient)."
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
sld = sld[:, None]
|
|
41
|
+
|
|
42
|
+
# add zero thickness for ambient layer:
|
|
43
|
+
thickness = torch.cat([torch.zeros(batch_size, 1).to(thickness), thickness], -1)[
|
|
44
|
+
:, None
|
|
45
|
+
]
|
|
46
|
+
|
|
32
47
|
roughness = roughness[:, None] ** 2
|
|
33
48
|
|
|
34
|
-
sld = sld * 1e-6 + 1e-
|
|
49
|
+
sld = (sld - sld[..., :1]) * 1e-6 + 1e-36j
|
|
35
50
|
|
|
36
51
|
k_z0 = (q / 2).to(c_dtype)
|
|
37
52
|
|
|
@@ -41,7 +56,7 @@ def abeles(
|
|
|
41
56
|
if k_z0.dim() == 2:
|
|
42
57
|
k_z0.unsqueeze_(-1)
|
|
43
58
|
|
|
44
|
-
k_n = torch.sqrt(k_z0
|
|
59
|
+
k_n = torch.sqrt(k_z0**2 - 4 * math.pi * sld)
|
|
45
60
|
|
|
46
61
|
# k_n.shape - (batch, q, layers)
|
|
47
62
|
|
|
@@ -52,22 +67,22 @@ def abeles(
|
|
|
52
67
|
exp_beta = torch.exp(beta)
|
|
53
68
|
exp_m_beta = torch.exp(-beta)
|
|
54
69
|
|
|
55
|
-
rn = (k_n - k_np1) / (k_n + k_np1) * torch.exp(-
|
|
70
|
+
rn = (k_n - k_np1) / (k_n + k_np1) * torch.exp(-2 * k_n * k_np1 * roughness)
|
|
56
71
|
|
|
57
|
-
c_matrices = torch.stack(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
c_matrices = torch.stack(
|
|
73
|
+
[
|
|
74
|
+
torch.stack([exp_beta, rn * exp_m_beta], -1),
|
|
75
|
+
torch.stack([rn * exp_beta, exp_m_beta], -1),
|
|
76
|
+
],
|
|
77
|
+
-1,
|
|
78
|
+
)
|
|
61
79
|
|
|
62
80
|
c_matrices = [c.squeeze(-3) for c in c_matrices.split(1, -3)]
|
|
63
81
|
|
|
64
|
-
m
|
|
65
|
-
|
|
66
|
-
for c in c_matrices:
|
|
67
|
-
m = m @ c
|
|
82
|
+
m = reduce(torch.matmul, c_matrices)
|
|
68
83
|
|
|
69
84
|
r = (m[..., 1, 0] / m[..., 0, 0]).abs() ** 2
|
|
70
|
-
r = torch.clamp_max_(r, 1.)
|
|
85
|
+
r = torch.clamp_max_(r, 1.0)
|
|
71
86
|
|
|
72
87
|
return r
|
|
73
88
|
|
|
@@ -19,7 +19,7 @@ def kinematical_approximation(
|
|
|
19
19
|
q (Tensor): tensor of momentum transfer (q) values with shape [batch_size, n_points] or [n_points]
|
|
20
20
|
thickness (Tensor): tensor containing the layer thicknesses (ordered from top to bottom) with shape [batch_size, n_layers]
|
|
21
21
|
roughness (Tensor): tensor containing the interlayer roughnesses (ordered from top to bottom) with shape [batch_size, n_layers + 1]
|
|
22
|
-
sld (Tensor):
|
|
22
|
+
sld (Tensor): tensor containing the layer SLDs (real or complex; ordered from top to bottom) with shape [batch_size, n_layers + 1].
|
|
23
23
|
It includes the substrate but excludes the ambient medium which is assumed to have an SLD of 0.
|
|
24
24
|
apply_fresnel (bool, optional): whether to use the Fresnel coefficient in the computation. Defaults to ``True``.
|
|
25
25
|
log (bool, optional): if True the base 10 logarithm of the reflectivity curves is returned. Defaults to ``False``.
|
|
@@ -19,7 +19,7 @@ def abeles_memory_eff(
|
|
|
19
19
|
q (Tensor): tensor of momentum transfer (q) values with shape [batch_size, n_points] or [n_points]
|
|
20
20
|
thickness (Tensor): tensor containing the layer thicknesses (ordered from top to bottom) with shape [batch_size, n_layers]
|
|
21
21
|
roughness (Tensor): tensor containing the interlayer roughnesses (ordered from top to bottom) with shape [batch_size, n_layers + 1]
|
|
22
|
-
sld (Tensor):
|
|
22
|
+
sld (Tensor): tensor containing the layer SLDs (real or complex; ordered from top to bottom) with shape [batch_size, n_layers + 1].
|
|
23
23
|
It includes the substrate but excludes the ambient medium which is assumed to have an SLD of 0.
|
|
24
24
|
|
|
25
25
|
Returns:
|
|
@@ -354,7 +354,8 @@ class EasyInferenceModel(object):
|
|
|
354
354
|
torch.from_numpy(polished_params_arr[:-1][None]),
|
|
355
355
|
torch.from_numpy(priors.T[0][None]),
|
|
356
356
|
torch.from_numpy(priors.T[1][None]),
|
|
357
|
-
|
|
357
|
+
self.trainer.loader.prior_sampler.max_num_layers,
|
|
358
|
+
self.trainer.loader.prior_sampler.param_model
|
|
358
359
|
)
|
|
359
360
|
else:
|
|
360
361
|
polished_params_arr, curve_polished = standard_refl_fit(
|
|
@@ -366,7 +367,8 @@ class EasyInferenceModel(object):
|
|
|
366
367
|
torch.from_numpy(polished_params_arr[None]),
|
|
367
368
|
torch.from_numpy(priors.T[0][None]),
|
|
368
369
|
torch.from_numpy(priors.T[1][None]),
|
|
369
|
-
|
|
370
|
+
self.trainer.loader.prior_sampler.max_num_layers,
|
|
371
|
+
self.trainer.loader.prior_sampler.param_model
|
|
370
372
|
)
|
|
371
373
|
except Exception as err:
|
|
372
374
|
polished_params = predicted_params
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: reflectorch
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.1
|
|
4
4
|
Summary: A Pytorch-based package for the analysis of reflectometry data
|
|
5
5
|
Author-email: Vladimir Starostin <vladimir.starostin@uni-tuebingen.de>, Valentin Munteanu <valentin.munteanu@uni-tuebingen.de>
|
|
6
6
|
Maintainer-email: Valentin Munteanu <valentin.munteanu@uni-tuebingen.de>, Vladimir Starostin <vladimir.starostin@uni-tuebingen.de>, Alexander Hinderhofer <alexander.hinderhofer@uni-tuebingen.de>
|
|
@@ -27,10 +27,10 @@ reflectorch/data_generation/priors/sampler_strategies.py,sha256=U-v5dXpFLJq939aQ
|
|
|
27
27
|
reflectorch/data_generation/priors/scaler_mixin.py,sha256=gI64v2KOZugSJWaLKASR34fn6qVFl-aoeVA1BR5yXNg,2648
|
|
28
28
|
reflectorch/data_generation/priors/subprior_sampler.py,sha256=TE8DOQhxVr69VmWSjwHyElpgVjOhZKBIPChFWNVYzRc,14769
|
|
29
29
|
reflectorch/data_generation/priors/utils.py,sha256=bmIZYHq95gG68kETfNH6ygR39oitUEJ0eCO_Fb8maH0,3836
|
|
30
|
-
reflectorch/data_generation/reflectivity/__init__.py,sha256=
|
|
31
|
-
reflectorch/data_generation/reflectivity/abeles.py,sha256=
|
|
32
|
-
reflectorch/data_generation/reflectivity/kinematical.py,sha256=
|
|
33
|
-
reflectorch/data_generation/reflectivity/memory_eff.py,sha256=
|
|
30
|
+
reflectorch/data_generation/reflectivity/__init__.py,sha256=MxVtNqO52iORdual2TtmSRN41TC9VmVSFH5ov-wuAJc,3202
|
|
31
|
+
reflectorch/data_generation/reflectivity/abeles.py,sha256=Pcov-m0HImw1DOR57t0OsBOLZs3MA6fk7RePf_VCEZU,3097
|
|
32
|
+
reflectorch/data_generation/reflectivity/kinematical.py,sha256=78E128l3DQif_vz2Ae6hjRg-69kRz7cbN0Ak5dOc5PM,2625
|
|
33
|
+
reflectorch/data_generation/reflectivity/memory_eff.py,sha256=pbsXkcGwDorey6qVx2SlBK6IlzNJY1FeeF84cEJB_hY,4023
|
|
34
34
|
reflectorch/data_generation/reflectivity/numpy_implementations.py,sha256=QBzn4yVnOdlkHeeR-ZFPS115GnLdO9lMTGO2d3YhG9I,3177
|
|
35
35
|
reflectorch/data_generation/reflectivity/smearing.py,sha256=pc95Lig9NIWtHDCKnKbLp7G_kmL7_3YB6ZpDphgC2D8,4001
|
|
36
36
|
reflectorch/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -39,7 +39,7 @@ reflectorch/extensions/jupyter/callbacks.py,sha256=K4Z8Mlm_Pa80YDsNOdMZLIJZyVrg0
|
|
|
39
39
|
reflectorch/extensions/matplotlib/__init__.py,sha256=ARmc228xbZUj4fWNq5fVxZ8PN444fjDNxNP4ytVCyfo,104
|
|
40
40
|
reflectorch/extensions/matplotlib/losses.py,sha256=H2vrjNqzmQ0BP4377uN4uhlH88aS5OAfA7pwRM2WHqA,686
|
|
41
41
|
reflectorch/inference/__init__.py,sha256=i0KNn83XN33mLrV7bpHdLd0SXxuGCKfbQcIoa247Uts,834
|
|
42
|
-
reflectorch/inference/inference_model.py,sha256=
|
|
42
|
+
reflectorch/inference/inference_model.py,sha256=uxzdL2S01CN6lN737B4x5L_NIFnaCkHrNUQKwh4xNW0,36739
|
|
43
43
|
reflectorch/inference/multilayer_fitter.py,sha256=0CxDpLOEp1terR4N39yFlxhvA8qAbHf_01NbmvYadck,5510
|
|
44
44
|
reflectorch/inference/multilayer_inference_model.py,sha256=hH_-dJGdMOox8GHXdM_nODXDlNgh_v449xW5FmklRdo,7575
|
|
45
45
|
reflectorch/inference/query_matcher.py,sha256=Dk49dW0XreeCjufzYBTKchfTdVbG6759ryV6I-wQL60,3387
|
|
@@ -76,8 +76,8 @@ reflectorch/runs/config.py,sha256=8YtUOXr_DvNvgpu59CNAr3KrQijx1AGDE95gYrsuwsM,80
|
|
|
76
76
|
reflectorch/runs/slurm_utils.py,sha256=Zyj4_K5YpiWNJhgpFLWYHsSaaI-mgVEWsN15Gd_BhI0,2600
|
|
77
77
|
reflectorch/runs/train.py,sha256=e-Jj0fwYlUB2NLDxCzy0cLsSrJbNqd5pN5T1L7-Eiig,2560
|
|
78
78
|
reflectorch/runs/utils.py,sha256=bp3Nwd6pfX5yFlTVX28zDtSTo2gg2JZh9HCpZpvnJWk,12637
|
|
79
|
-
reflectorch-1.2.
|
|
80
|
-
reflectorch-1.2.
|
|
81
|
-
reflectorch-1.2.
|
|
82
|
-
reflectorch-1.2.
|
|
83
|
-
reflectorch-1.2.
|
|
79
|
+
reflectorch-1.2.1.dist-info/LICENSE.txt,sha256=2kX9kLKiIRiQRqUXwk3J-Ba3fqmztNu8ORskLBlAuKM,1098
|
|
80
|
+
reflectorch-1.2.1.dist-info/METADATA,sha256=ANjKriMGr9vTl5pvhgqpsCL40aZxh1ryKrfy66Eh_wU,7805
|
|
81
|
+
reflectorch-1.2.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
|
82
|
+
reflectorch-1.2.1.dist-info/top_level.txt,sha256=2EyIWrt4SeZ3hNadLXvEVpPFhyoZ4An7YflP4y_E3Fc,12
|
|
83
|
+
reflectorch-1.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|