diff --git a/news/muD2.rst b/news/muD2.rst new file mode 100644 index 0000000..617eb2b --- /dev/null +++ b/news/muD2.rst @@ -0,0 +1,23 @@ +**Added:** + +* no news added - rename variables in `mud_calculator.py` and edit tests + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/labpdfproc/mud_calculator.py b/src/diffpy/labpdfproc/mud_calculator.py index 20bc88f..604d167 100644 --- a/src/diffpy/labpdfproc/mud_calculator.py +++ b/src/diffpy/labpdfproc/mud_calculator.py @@ -15,19 +15,19 @@ def _top_hat(z, half_slit_width): def _model_function(z, diameter, z0, I0, mud, slope): """ Compute the model function with the following steps: - 1. Recenter z to x by subtracting z0 (so that the circle is centered at 0 and it is easier to compute length l) + 1. Let dz = z-z0, so that dz is centered at 0 2. Compute length l that is the effective length for computing intensity I = I0 * e^{-mu * l}: - - For x within the diameter range, l is the chord length of the circle at position x - - For x outside this range, l = 0 + - For dz within the capillary diameter, l is the chord length of the circle at position dz + - For dz outside this range, l = 0 3. Apply a linear adjustment to I0 by taking I0 as I0 - slope * z """ min_radius = -diameter / 2 max_radius = diameter / 2 - x = z - z0 + dz = z - z0 length = np.piecewise( - x, - [x < min_radius, (min_radius <= x) & (x <= max_radius), x > max_radius], - [0, lambda x: 2 * np.sqrt((diameter / 2) ** 2 - x**2), 0], + dz, + [dz < min_radius, (min_radius <= dz) & (dz <= max_radius), dz > max_radius], + [0, lambda dz: 2 * np.sqrt((diameter / 2) ** 2 - dz**2), 0], ) return (I0 - slope * z) * np.exp(-mud / diameter * length) diff --git a/tests/test_mud_calculator.py b/tests/test_mud_calculator.py index b74585e..551adb5 100644 --- a/tests/test_mud_calculator.py +++ b/tests/test_mud_calculator.py @@ -19,4 +19,4 @@ def test_compute_mud(tmp_path): expected_mud = 3 actual_mud = compute_mud(file) - assert actual_mud == pytest.approx(expected_mud, rel=0.01, abs=0.1) + assert actual_mud == pytest.approx(expected_mud, rel=1e-4, abs=1e-3)