Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions doc/source/examples/diffraction_objects_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ For convenience, you can also apply an offset to the scaled new diffraction obje
DiffractionObject convenience functions
---------------------------------------

1) create a copy of a diffraction object using the ``copy`` method
1. create a copy of a diffraction object using the ``copy`` method
when you want to preserve the original data while working with a modified version.

.. code-block:: python

copy_of_calculated = calculated.copy()

2) test the equality of two diffraction objects. For example,
2. test the equality of two diffraction objects. For example,

.. code-block:: python

Expand All @@ -145,15 +145,38 @@ DiffractionObject convenience functions

will return ``True``.

3) make arithmetic operations on the intensities of diffraction objects. e.g.,
3. make arithmetic operations on the intensities of diffraction objects.
For example, you can do scalar operations on a single diffraction object,
which will modify the intensity values (``yarrays``) without affecting other properties:

.. code-block:: python

doubled_object = 2 * diff_object1 # Double the intensities
sum_object = diff_object1 + diff_object2 # Sum the intensities
subtract_scaled = diff_object1 - 5 * diff_object2 # subtract 5 * obj2 from obj 1
increased_intensity = diff_object1 + 5 # Increases the intensities by 5
decreased_intensity = diff_object1 - 1 # Decreases the intensities by 1
doubled_object = 2 * diff_object1 # Double the intensities
reduced_intensity = diff_object1 / 2 # Halves the intensities

4) get the value of the DiffractionObject at a given point in one of the xarrays
You can also do binary operations between two diffraction objects, as long as their yarrays have the same length.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the condition "same length xarray" or "on the same q/tth/d-array"? I think it should be the latter or we are adding things incorrectly. Please can you check the code. If the code is doing it right, change the doc. If hte doc is right, we probably should revisit hte tests and code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think the code only checks for the length of yarrays. I can edit the test on this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I wanna talk to @bobleesj first before making any changes. His test cases seem to be carefully chosen.. Made this into a new issue #298. @sbillinge I changed the docs and it's ready for review

The operation will apply to the intensity values, while other properties
(such as ``xarrays``, ``xtype``, and ``metadata``) will be inherited
from the left-hand side diffraction object (``diff_object1``).
For example:

.. code-block:: python

sum_object = diff_object1 + diff_object2 # Sum the intensities
subtract_scaled = diff_object1 - 5 * diff_object2 # Subtract 5 * obj2 from obj 1
multiplied_object = diff_object1 * diff_object2 # Multiply the intensities
divided_object = diff_object1 / diff_object2 # Divide the intensities

You cannot perform operations between diffraction objects and incompatible types.
For example, attempting to add a diffraction object and a string will raise an error:

.. code-block:: python

diff_object1 + "string_value" # This will raise an error

4. get the value of the DiffractionObject at a given point in one of the xarrays

.. code-block:: python

Expand All @@ -170,7 +193,7 @@ you can find its closest index for ``q=0.25`` by typing either of the following:
index = do.get_array_index(0.25) # no xtype passed, defaults to do._input_xtype, or in this example, q
index = do.get_array_index(0.25, xtype="q") # explicitly choose an xtype to specify a value

5) The ``dump`` function saves the diffraction data and relevant information to an xy format file with headers
5. The ``dump`` function saves the diffraction data and relevant information to an xy format file with headers
(widely used chi format used, for example, by Fit2D and diffpy. These files can be read by ``LoadData()``
in ``diffpy.utils.parsers``).

Expand Down
23 changes: 23 additions & 0 deletions news/docs-do.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* no news added: adding documentation for diffraction object operation examples

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
Loading