mirror of
https://github.com/cdtools-developers/cdtools.git
synced 2026-09-10 05:22:41 +02:00
Fix an inconsistency in the incoherent sum measurement and update the test
This commit is contained in:
@@ -47,22 +47,22 @@ def incoherent_sum(wavefields, detector_slice=None, epsilon=1e-7, saturation=Non
|
||||
the wavefields. If a detector slice is given, the returned array
|
||||
will only include that slice from the simulated wavefronts.
|
||||
|
||||
The first index is the index of the diffraction pattern to measure,
|
||||
the second index is the set of incoherently adding patterns, and
|
||||
the next two indices index the wavefield. The final index is the complex
|
||||
The first index is the set of incoherently adding patterns, and
|
||||
the second index is the index of the diffraction pattern to measure.
|
||||
The next two indices index the wavefield. The final index is the complex
|
||||
index.
|
||||
|
||||
Args:
|
||||
wavefields (torch.Tensor) : A JxLxMxNx2 stack of complex wavefields
|
||||
wavefields (torch.Tensor) : An LxJxMxNx2 stack of complex wavefields
|
||||
detector_slice (slice) : Optional, a slice or tuple of slices defining a section of the simulation to return
|
||||
saturation (float) : Optional, a maximum saturation value to clamp the resulting intensities to
|
||||
|
||||
Returns:
|
||||
torch.Tensor : A real MxN array storing the incoherently summed intensities
|
||||
torch.Tensor : A real JXMxN array storing the incoherently summed intensities
|
||||
"""
|
||||
# This syntax just adds an axis to the slice to preserve the J direction
|
||||
if detector_slice is None:
|
||||
output = t.sum(cmath.cabssq(wavefields),dim=-3) + epsilon
|
||||
output = t.sum(cmath.cabssq(wavefields),dim=0) + epsilon
|
||||
else:
|
||||
if wavefields.dim() == 4:
|
||||
output = t.sum(cmath.cabssq(wavefields[(np.s_[:],)+detector_slice]),dim=0) + epsilon
|
||||
|
||||
@@ -31,11 +31,11 @@ def test_intensity():
|
||||
def test_incoherent_sum():
|
||||
wavefields = t.rand((5,4,10,10,2))
|
||||
epsilon=1e-6
|
||||
np_result = np.sum(np.abs(cmath.torch_to_complex(wavefields))**2,axis=1) + epsilon
|
||||
np_result = np.sum(np.abs(cmath.torch_to_complex(wavefields))**2,axis=0) + epsilon
|
||||
assert t.allclose(measurements.incoherent_sum(wavefields,epsilon=epsilon),
|
||||
t.tensor(np_result))
|
||||
# Test single field case
|
||||
assert t.allclose(measurements.incoherent_sum(wavefields[0],epsilon=epsilon),
|
||||
assert t.allclose(measurements.incoherent_sum(wavefields[:,0],epsilon=epsilon),
|
||||
t.tensor(np_result[0]))
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ def test_incoherent_sum():
|
||||
assert t.allclose(measurements.incoherent_sum(wavefields,det_slice,epsilon=epsilon),
|
||||
t.tensor(np_result[(np.s_[:],)+det_slice]))
|
||||
# Test single field case
|
||||
assert t.allclose(measurements.incoherent_sum(wavefields[0],det_slice,epsilon=epsilon),
|
||||
assert t.allclose(measurements.incoherent_sum(wavefields[:,0],det_slice,epsilon=epsilon),
|
||||
t.tensor(np_result[0][det_slice]))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user