Skip to content

Commit a9fbbe5

Browse files
authored
Merge pull request #147 from yucongalicechen/mudcalc
rename x to dz in `mud_calculator.py` and decrease error tolerance for tests
2 parents e8572fa + 11d2ccd commit a9fbbe5

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

news/muD2.rst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* no news added - rename variables in `mud_calculator.py` and edit tests
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

src/diffpy/labpdfproc/mud_calculator.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ def _top_hat(z, half_slit_width):
1515
def _model_function(z, diameter, z0, I0, mud, slope):
1616
"""
1717
Compute the model function with the following steps:
18-
1. Recenter z to x by subtracting z0 (so that the circle is centered at 0 and it is easier to compute length l)
18+
1. Let dz = z-z0, so that dz is centered at 0
1919
2. Compute length l that is the effective length for computing intensity I = I0 * e^{-mu * l}:
20-
- For x within the diameter range, l is the chord length of the circle at position x
21-
- For x outside this range, l = 0
20+
- For dz within the capillary diameter, l is the chord length of the circle at position dz
21+
- For dz outside this range, l = 0
2222
3. Apply a linear adjustment to I0 by taking I0 as I0 - slope * z
2323
"""
2424
min_radius = -diameter / 2
2525
max_radius = diameter / 2
26-
x = z - z0
26+
dz = z - z0
2727
length = np.piecewise(
28-
x,
29-
[x < min_radius, (min_radius <= x) & (x <= max_radius), x > max_radius],
30-
[0, lambda x: 2 * np.sqrt((diameter / 2) ** 2 - x**2), 0],
28+
dz,
29+
[dz < min_radius, (min_radius <= dz) & (dz <= max_radius), dz > max_radius],
30+
[0, lambda dz: 2 * np.sqrt((diameter / 2) ** 2 - dz**2), 0],
3131
)
3232
return (I0 - slope * z) * np.exp(-mud / diameter * length)
3333

tests/test_mud_calculator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def test_compute_mud(tmp_path):
1919

2020
expected_mud = 3
2121
actual_mud = compute_mud(file)
22-
assert actual_mud == pytest.approx(expected_mud, rel=0.01, abs=0.1)
22+
assert actual_mud == pytest.approx(expected_mud, rel=1e-4, abs=1e-3)

0 commit comments

Comments
 (0)