From e91661df5764bae3a0bb0a6d81e29daab8f8b793 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sat, 28 Dec 2024 23:02:00 -0500 Subject: [PATCH 01/10] add news --- news/scaleto-max.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/scaleto-max.rst diff --git a/news/scaleto-max.rst b/news/scaleto-max.rst new file mode 100644 index 00000000..0037f533 --- /dev/null +++ b/news/scaleto-max.rst @@ -0,0 +1,23 @@ +**Added:** + +* new feature in `scale_to()` to run without specifying an x-value + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* From 4a87d00a4ed1f093b177b546bc7dcd8febd92196 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sat, 28 Dec 2024 23:02:33 -0500 Subject: [PATCH 02/10] add example --- doc/source/examples/diffraction_objects_example.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/source/examples/diffraction_objects_example.rst b/doc/source/examples/diffraction_objects_example.rst index 8621f50f..aa4de157 100644 --- a/doc/source/examples/diffraction_objects_example.rst +++ b/doc/source/examples/diffraction_objects_example.rst @@ -117,6 +117,13 @@ For convenience, you can also apply an offset to the scaled new diffraction obje scaled_and_offset_measured = measured.scale_to(calculated, q=5.5, offset=0.5) +You can call `scale_to()` without specifying a value for `q`, `tth`, or `d`. +In this case, the scaling will be done based on the maximal x-array value of both diffraction objects: + +.. code-block:: python + + scaled_measured = measured.scale_to(calculated) + DiffractionObject convenience functions --------------------------------------- From 2c8335cd1dda1762e60f5c4a6501c4c0364b49f5 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sat, 28 Dec 2024 23:07:19 -0500 Subject: [PATCH 03/10] add feature so that user can run scale_to without xvalue --- src/diffpy/utils/diffraction_objects.py | 15 ++++++--- tests/test_diffraction_objects.py | 41 +++++++++++++------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/diffpy/utils/diffraction_objects.py b/src/diffpy/utils/diffraction_objects.py index 25e3e28c..413d9eac 100644 --- a/src/diffpy/utils/diffraction_objects.py +++ b/src/diffpy/utils/diffraction_objects.py @@ -402,14 +402,16 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=0): The y-value in the target at the closest specified x-value will be used as the factor to scale to. The entire array is scaled by this factor so that one object places on top of the other at that point. - If multiple values of `q`, `tth`, or `d` are provided, or none are provided, an error will be raised. + If none of `q`, `tth`, or `d` are provided, + the scaling will be based on the maximal x-array value from both objects. + If multiple values of `q`, `tth`, or `d` are provided, an error will be raised. Parameters ---------- target_diff_object: DiffractionObject the diffraction object you want to scale the current one onto - q, tth, d : float, optional, must specify exactly one of them + q, tth, d : float, optional, default is q with the maximal x-array value of the current object The value of the x-array where you want the curves to line up vertically. Specify a value on one of the allowed grids, q, tth, or d), e.g., q=10. @@ -422,11 +424,16 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=0): """ scaled = self.copy() count = sum([q is not None, tth is not None, d is not None]) - if count != 1: + if count > 1: raise ValueError( - "You must specify exactly one of 'q', 'tth', or 'd'. Please rerun specifying only one." + "You must specify none or exactly one of 'q', 'tth', or 'd'. " + "Please provide either none or one value." ) + if count == 0: + scaled._all_arrays[:, 0] *= max(target_diff_object.on_q()[1]) / max(self.on_q()[1]) + return scaled + xtype = "q" if q is not None else "tth" if tth is not None else "d" data = self.on_xtype(xtype) target = target_diff_object.on_xtype(xtype) diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index c6355882..789a5e77 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -284,23 +284,7 @@ def test_init_invalid_xtype(): }, {"xtype": "tth", "yarray": np.array([4.1, 5.1, 6.1, 7.1, 8.1, 9.1])}, ), - ], -) -def test_scale_to(org_do_args, target_do_args, scale_inputs, expected): - original_do = DiffractionObject(**org_do_args) - target_do = DiffractionObject(**target_do_args) - scaled_do = original_do.scale_to( - target_do, q=scale_inputs["q"], tth=scale_inputs["tth"], d=scale_inputs["d"], offset=scale_inputs["offset"] - ) - # Check the intensity data is the same as expected - assert np.allclose(scaled_do.on_xtype(expected["xtype"])[1], expected["yarray"]) - - -@pytest.mark.parametrize( - "org_do_args, target_do_args, scale_inputs", - [ - # Test expected errors produced from scale_to() with invalid inputs - ( # C1: none of q, tth, d, provided, expect ValueError + ( # C5: none of q, tth, d, provided, expect to scale on the maximal x-arrays { "xarray": np.array([0.1, 0.2, 0.3]), "yarray": np.array([1, 2, 3]), @@ -319,8 +303,25 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected): "d": None, "offset": 0, }, + {"xtype": "q", "yarray": np.array([10, 20, 30])}, ), - ( # C2: tth and d both provided, expect ValueErrort + ], +) +def test_scale_to(org_do_args, target_do_args, scale_inputs, expected): + original_do = DiffractionObject(**org_do_args) + target_do = DiffractionObject(**target_do_args) + scaled_do = original_do.scale_to( + target_do, q=scale_inputs["q"], tth=scale_inputs["tth"], d=scale_inputs["d"], offset=scale_inputs["offset"] + ) + # Check the intensity data is the same as expected + assert np.allclose(scaled_do.on_xtype(expected["xtype"])[1], expected["yarray"]) + + +@pytest.mark.parametrize( + "org_do_args, target_do_args, scale_inputs", + [ + # Test expected errors produced from scale_to() with invalid inputs + ( # C2: tth and d both provided, expect ValueError { "xarray": np.array([10, 25, 30.1, 40.2, 61, 120, 140]), "yarray": np.array([10, 20, 30, 40, 50, 60, 100]), @@ -346,7 +347,9 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs): original_do = DiffractionObject(**org_do_args) target_do = DiffractionObject(**target_do_args) with pytest.raises( - ValueError, match="You must specify exactly one of 'q', 'tth', or 'd'. Please rerun specifying only one." + ValueError, + match="You must specify none or exactly one of 'q', 'tth', or 'd'. " + "Please provide either none or one value.", ): original_do.scale_to( target_do, From 630011a6210663b3428e81784a921efab5d3624f Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sun, 29 Dec 2024 16:28:47 -0500 Subject: [PATCH 04/10] refactor: reorder docstring and tests, change offset default to None, update tests for flexible inputs --- src/diffpy/utils/diffraction_objects.py | 13 ++-- tests/test_diffraction_objects.py | 87 ++++++++----------------- 2 files changed, 34 insertions(+), 66 deletions(-) diff --git a/src/diffpy/utils/diffraction_objects.py b/src/diffpy/utils/diffraction_objects.py index 413d9eac..36386ce1 100644 --- a/src/diffpy/utils/diffraction_objects.py +++ b/src/diffpy/utils/diffraction_objects.py @@ -396,14 +396,14 @@ def on_tth(self): def on_d(self): return [self.all_arrays[:, 3], self.all_arrays[:, 0]] - def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=0): + def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None): """Returns a new diffraction object which is the current object but rescaled in y to the target. + By default, if none of `q`, `tth`, or `d` are provided, + the scaling is based on the maximal x-array value from both objects. The y-value in the target at the closest specified x-value will be used as the factor to scale to. The entire array is scaled by this factor so that one object places on top of the other at that point. - If none of `q`, `tth`, or `d` are provided, - the scaling will be based on the maximal x-array value from both objects. If multiple values of `q`, `tth`, or `d` are provided, an error will be raised. Parameters @@ -411,17 +411,20 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=0): target_diff_object: DiffractionObject the diffraction object you want to scale the current one onto - q, tth, d : float, optional, default is q with the maximal x-array value of the current object + q, tth, d : float, optional, default is q with the maximal x-array value from each object The value of the x-array where you want the curves to line up vertically. Specify a value on one of the allowed grids, q, tth, or d), e.g., q=10. - offset : float, optional, default is 0 + offset : float, optional, default is None an offset to add to the scaled y-values Returns ------- the rescaled DiffractionObject as a new object """ + if offset is None: + offset = 0 + scaled = self.copy() count = sum([q is not None, tth is not None, d is not None]) if count > 1: diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 789a5e77..6499bdd7 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -191,7 +191,23 @@ def test_init_invalid_xtype(): "org_do_args, target_do_args, scale_inputs, expected", [ # Test whether the original y-array is scaled as expected - ( # C1: Same x-arrays + ( # C1: none of q, tth, d, provided, expect to scale on the maximal x-arrays + { + "xarray": np.array([0.1, 0.2, 0.3]), + "yarray": np.array([1, 2, 3]), + "xtype": "q", + "wavelength": 2 * np.pi, + }, + { + "xarray": np.array([0.05, 0.1, 0.2, 0.3]), + "yarray": np.array([5, 10, 20, 30]), + "xtype": "q", + "wavelength": 2 * np.pi, + }, + {}, + {"xtype": "q", "yarray": np.array([10, 20, 30])}, + ), + ( # C2: Same x-arrays # x-value has exact matches at tth=60 (y=60) and tth=60 (y=6), # for original and target diffraction objects, # expect original y-array to multiply by 6/60=1/10 @@ -207,15 +223,10 @@ def test_init_invalid_xtype(): "xtype": "tth", "wavelength": 2 * np.pi, }, - { - "q": None, - "tth": 60, - "d": None, - "offset": 0, - }, + {"tth": 60}, {"xtype": "tth", "yarray": np.array([1, 2, 2.5, 3, 6, 10])}, ), - ( # C2: Different x-arrays with same length, + ( # C3: Different x-arrays with same length, # x-value has closest match at q=0.12 (y=10) and q=0.14 (y=1) # for original and target diffraction objects, # expect original y-array to multiply by 1/10 @@ -231,15 +242,10 @@ def test_init_invalid_xtype(): "xtype": "q", "wavelength": 2 * np.pi, }, - { - "q": 0.1, - "tth": None, - "d": None, - "offset": 0, - }, + {"q": 0.1}, {"xtype": "q", "yarray": np.array([1, 2, 4, 6])}, ), - ( # C3: Different x-array lengths + ( # C4: Different x-array lengths # x-value has closest matches at tth=61 (y=50) and tth=62 (y=5), # for original and target diffraction objects, # expect original y-array to multiply by 5/50=1/10 @@ -255,15 +261,10 @@ def test_init_invalid_xtype(): "xtype": "tth", "wavelength": 2 * np.pi, }, - { - "q": None, - "tth": 60, - "d": None, - "offset": 0, - }, + {"tth": 60}, {"xtype": "tth", "yarray": np.array([1, 2, 3, 4, 5, 6, 10])}, ), - ( # C4: Same x-array and y-array with 2.1 offset, expect y-array to shift up by 2.1 + ( # C5: Same x-array and y-array with 2.1 offset, expect y-array to shift up by 2.1 { "xarray": np.array([10, 15, 25, 30, 60, 140]), "yarray": np.array([2, 3, 4, 5, 6, 7]), @@ -276,43 +277,15 @@ def test_init_invalid_xtype(): "xtype": "tth", "wavelength": 2 * np.pi, }, - { - "q": None, - "tth": 60, - "d": None, - "offset": 2.1, - }, + {"tth": 60, "offset": 2.1}, {"xtype": "tth", "yarray": np.array([4.1, 5.1, 6.1, 7.1, 8.1, 9.1])}, ), - ( # C5: none of q, tth, d, provided, expect to scale on the maximal x-arrays - { - "xarray": np.array([0.1, 0.2, 0.3]), - "yarray": np.array([1, 2, 3]), - "xtype": "q", - "wavelength": 2 * np.pi, - }, - { - "xarray": np.array([0.05, 0.1, 0.2, 0.3]), - "yarray": np.array([5, 10, 20, 30]), - "xtype": "q", - "wavelength": 2 * np.pi, - }, - { - "q": None, - "tth": None, - "d": None, - "offset": 0, - }, - {"xtype": "q", "yarray": np.array([10, 20, 30])}, - ), ], ) def test_scale_to(org_do_args, target_do_args, scale_inputs, expected): original_do = DiffractionObject(**org_do_args) target_do = DiffractionObject(**target_do_args) - scaled_do = original_do.scale_to( - target_do, q=scale_inputs["q"], tth=scale_inputs["tth"], d=scale_inputs["d"], offset=scale_inputs["offset"] - ) + scaled_do = original_do.scale_to(target_do, **scale_inputs) # Check the intensity data is the same as expected assert np.allclose(scaled_do.on_xtype(expected["xtype"])[1], expected["yarray"]) @@ -335,10 +308,8 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected): "wavelength": 2 * np.pi, }, { - "q": None, "tth": 60, "d": 10, - "offset": 0, }, ), ], @@ -351,13 +322,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs): match="You must specify none or exactly one of 'q', 'tth', or 'd'. " "Please provide either none or one value.", ): - original_do.scale_to( - target_do, - q=scale_inputs["q"], - tth=scale_inputs["tth"], - d=scale_inputs["d"], - offset=scale_inputs["offset"], - ) + original_do.scale_to(target_do, **scale_inputs) @pytest.mark.parametrize( From 66c67c6a169ce38f1dd3256f24bb03e4c94972b2 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sun, 29 Dec 2024 16:50:45 -0500 Subject: [PATCH 05/10] docs: clarify docstring and news --- news/scaleto-max.rst | 2 +- src/diffpy/utils/diffraction_objects.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/news/scaleto-max.rst b/news/scaleto-max.rst index 0037f533..d70e9d7f 100644 --- a/news/scaleto-max.rst +++ b/news/scaleto-max.rst @@ -1,6 +1,6 @@ **Added:** -* new feature in `scale_to()` to run without specifying an x-value +* new feature in `scale_to()`: default scaling is based on the max q-value in each diffraction object. **Changed:** diff --git a/src/diffpy/utils/diffraction_objects.py b/src/diffpy/utils/diffraction_objects.py index 36386ce1..80202cd3 100644 --- a/src/diffpy/utils/diffraction_objects.py +++ b/src/diffpy/utils/diffraction_objects.py @@ -400,9 +400,8 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None): """Returns a new diffraction object which is the current object but rescaled in y to the target. - By default, if none of `q`, `tth`, or `d` are provided, - the scaling is based on the maximal x-array value from both objects. - The y-value in the target at the closest specified x-value will be used as the factor to scale to. + By default, if `q`, `tth`, or `d` are not provided, scaling is based on the max q-value from each object. + Otherwise, y-value in the target at the closest specified x-value will be used as the factor to scale to. The entire array is scaled by this factor so that one object places on top of the other at that point. If multiple values of `q`, `tth`, or `d` are provided, an error will be raised. @@ -411,7 +410,7 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None): target_diff_object: DiffractionObject the diffraction object you want to scale the current one onto - q, tth, d : float, optional, default is q with the maximal x-array value from each object + q, tth, d : float, optional, default is the max q-value from each object The value of the x-array where you want the curves to line up vertically. Specify a value on one of the allowed grids, q, tth, or d), e.g., q=10. From 0a155aaf231c3dc237e7f6ddeefde23e64d5a4c9 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sun, 29 Dec 2024 17:01:33 -0500 Subject: [PATCH 06/10] docs: edit example file --- .../examples/diffraction_objects_example.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/source/examples/diffraction_objects_example.rst b/doc/source/examples/diffraction_objects_example.rst index aa4de157..f956081c 100644 --- a/doc/source/examples/diffraction_objects_example.rst +++ b/doc/source/examples/diffraction_objects_example.rst @@ -106,23 +106,26 @@ we would replace the code above with The ``scale_to()`` method returns a new ``DiffractionObject`` which we can assign to a new variable and make use of, +The default behavior is to align the objects based on the maximal q-value of each diffraction object, +so they will align at the intensity at these indices. + .. code-block:: python - scaled_measured = measured.scale_to(calculated, q=5.5) + scaled_measured = measured.scale_to(calculated) -For convenience, you can also apply an offset to the scaled new diffraction object with the optional -``offset`` argument, for example, +If this doesn't give the desirable results, you can specify an ``xtype=value`` to scale +based on the closest x-value in both objects. For example: .. code-block:: python - scaled_and_offset_measured = measured.scale_to(calculated, q=5.5, offset=0.5) + scaled_measured = measured.scale_to(calculated, q=5.5) -You can call `scale_to()` without specifying a value for `q`, `tth`, or `d`. -In this case, the scaling will be done based on the maximal x-array value of both diffraction objects: +For convenience, you can also apply an offset to the scaled new diffraction object with the optional +``offset`` argument, for example, .. code-block:: python - scaled_measured = measured.scale_to(calculated) + scaled_and_offset_measured = measured.scale_to(calculated, q=5.5, offset=0.5) DiffractionObject convenience functions --------------------------------------- From 13f227dfb03bfc7b7e20b4fbc3d31891d615e689 Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sun, 29 Dec 2024 21:04:49 -0500 Subject: [PATCH 07/10] docs: improve docstring --- src/diffpy/utils/diffraction_objects.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/diffpy/utils/diffraction_objects.py b/src/diffpy/utils/diffraction_objects.py index 80202cd3..3ce01346 100644 --- a/src/diffpy/utils/diffraction_objects.py +++ b/src/diffpy/utils/diffraction_objects.py @@ -408,22 +408,22 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None): Parameters ---------- target_diff_object: DiffractionObject - the diffraction object you want to scale the current one onto + The diffraction object you want to scale the current one onto. - q, tth, d : float, optional, default is the max q-value from each object + q, tth, d : float, optional, default is None The value of the x-array where you want the curves to line up vertically. Specify a value on one of the allowed grids, q, tth, or d), e.g., q=10. offset : float, optional, default is None - an offset to add to the scaled y-values + The offset to add to the scaled y-values. Returns ------- - the rescaled DiffractionObject as a new object + scaled : DiffractionObject + The rescaled DiffractionObject as a new object. """ if offset is None: offset = 0 - scaled = self.copy() count = sum([q is not None, tth is not None, d is not None]) if count > 1: From cdf4b49e45ce7f32023633fce6dcf397385e3280 Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Sun, 29 Dec 2024 21:33:19 -0500 Subject: [PATCH 08/10] doc: small tweak to description of scale_to --- doc/source/examples/diffraction_objects_example.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/source/examples/diffraction_objects_example.rst b/doc/source/examples/diffraction_objects_example.rst index f956081c..4494fcfc 100644 --- a/doc/source/examples/diffraction_objects_example.rst +++ b/doc/source/examples/diffraction_objects_example.rst @@ -104,10 +104,9 @@ we would replace the code above with plt.show() The ``scale_to()`` method returns a new ``DiffractionObject`` which we can assign to a new -variable and make use of, +variable and make use of. -The default behavior is to align the objects based on the maximal q-value of each diffraction object, -so they will align at the intensity at these indices. +The default behavior is to align the objects based on the maximal value of each diffraction object. .. code-block:: python From 27da4ded721f3d0978745ca9f7bcc4d567b88aca Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sun, 29 Dec 2024 22:19:06 -0500 Subject: [PATCH 09/10] feat: add offset to default behavior and test case --- src/diffpy/utils/diffraction_objects.py | 4 +++- tests/test_diffraction_objects.py | 31 +++++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/diffpy/utils/diffraction_objects.py b/src/diffpy/utils/diffraction_objects.py index 3ce01346..a404b155 100644 --- a/src/diffpy/utils/diffraction_objects.py +++ b/src/diffpy/utils/diffraction_objects.py @@ -433,7 +433,9 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None): ) if count == 0: - scaled._all_arrays[:, 0] *= max(target_diff_object.on_q()[1]) / max(self.on_q()[1]) + q_target_max = max(target_diff_object.on_q()[1]) + q_self_max = max(self.on_q()[1]) + scaled._all_arrays[:, 0] = scaled._all_arrays[:, 0] * q_target_max / q_self_max + offset return scaled xtype = "q" if q is not None else "tth" if tth is not None else "d" diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 6499bdd7..455dc41c 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -264,21 +264,38 @@ def test_init_invalid_xtype(): {"tth": 60}, {"xtype": "tth", "yarray": np.array([1, 2, 3, 4, 5, 6, 10])}, ), - ( # C5: Same x-array and y-array with 2.1 offset, expect y-array to shift up by 2.1 + ( # C5.1: Reuse test case from C1, none of q, tth, d, provided, but include an offset, + # expect scaled y-array in C1 to shift up by 2 { - "xarray": np.array([10, 15, 25, 30, 60, 140]), - "yarray": np.array([2, 3, 4, 5, 6, 7]), + "xarray": np.array([0.1, 0.2, 0.3]), + "yarray": np.array([1, 2, 3]), + "xtype": "q", + "wavelength": 2 * np.pi, + }, + { + "xarray": np.array([0.05, 0.1, 0.2, 0.3]), + "yarray": np.array([5, 10, 20, 30]), + "xtype": "q", + "wavelength": 2 * np.pi, + }, + {"offset": 2}, + {"xtype": "q", "yarray": np.array([12, 22, 32])}, + ), + ( # C5.2: Reuse test case from C4, but include an offset, expect scaled y-array in C4 to shift up by 2 + { + "xarray": np.array([10, 25, 30.1, 40.2, 61, 120, 140]), + "yarray": np.array([10, 20, 30, 40, 50, 60, 100]), "xtype": "tth", "wavelength": 2 * np.pi, }, { - "xarray": np.array([10, 15, 25, 30, 60, 140]), - "yarray": np.array([2, 3, 4, 5, 6, 7]), + "xarray": np.array([20, 25.5, 32, 45, 50, 62, 100, 125, 140]), + "yarray": np.array([1.1, 2, 3, 3.5, 4, 5, 10, 12, 13]), "xtype": "tth", "wavelength": 2 * np.pi, }, - {"tth": 60, "offset": 2.1}, - {"xtype": "tth", "yarray": np.array([4.1, 5.1, 6.1, 7.1, 8.1, 9.1])}, + {"tth": 60, "offset": 2}, + {"xtype": "tth", "yarray": np.array([3, 4, 5, 6, 7, 8, 12])}, ), ], ) From 0691e545f1680b45461e357277de5556d079a8da Mon Sep 17 00:00:00 2001 From: yucongalicechen Date: Sun, 29 Dec 2024 22:23:19 -0500 Subject: [PATCH 10/10] docs: improve docstring and test comment --- src/diffpy/utils/diffraction_objects.py | 2 +- tests/test_diffraction_objects.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diffpy/utils/diffraction_objects.py b/src/diffpy/utils/diffraction_objects.py index a404b155..1b32e1d7 100644 --- a/src/diffpy/utils/diffraction_objects.py +++ b/src/diffpy/utils/diffraction_objects.py @@ -400,7 +400,7 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=None): """Returns a new diffraction object which is the current object but rescaled in y to the target. - By default, if `q`, `tth`, or `d` are not provided, scaling is based on the max q-value from each object. + By default, if `q`, `tth`, or `d` are not provided, scaling is based on the max intensity from each object. Otherwise, y-value in the target at the closest specified x-value will be used as the factor to scale to. The entire array is scaled by this factor so that one object places on top of the other at that point. If multiple values of `q`, `tth`, or `d` are provided, an error will be raised. diff --git a/tests/test_diffraction_objects.py b/tests/test_diffraction_objects.py index 455dc41c..9f0d9a0d 100644 --- a/tests/test_diffraction_objects.py +++ b/tests/test_diffraction_objects.py @@ -191,7 +191,7 @@ def test_init_invalid_xtype(): "org_do_args, target_do_args, scale_inputs, expected", [ # Test whether the original y-array is scaled as expected - ( # C1: none of q, tth, d, provided, expect to scale on the maximal x-arrays + ( # C1: none of q, tth, d, provided, expect to scale on the maximal intensity from each object { "xarray": np.array([0.1, 0.2, 0.3]), "yarray": np.array([1, 2, 3]),