@@ -129,14 +129,14 @@ For convenience, you can also apply an offset to the scaled new diffraction obje
129
129
DiffractionObject convenience functions
130
130
---------------------------------------
131
131
132
- 1) create a copy of a diffraction object using the ``copy `` method
132
+ 1. create a copy of a diffraction object using the ``copy `` method
133
133
when you want to preserve the original data while working with a modified version.
134
134
135
135
.. code-block :: python
136
136
137
137
copy_of_calculated = calculated.copy()
138
138
139
- 2) test the equality of two diffraction objects. For example,
139
+ 2. test the equality of two diffraction objects. For example,
140
140
141
141
.. code-block :: python
142
142
@@ -145,15 +145,38 @@ DiffractionObject convenience functions
145
145
146
146
will return ``True ``.
147
147
148
- 3) make arithmetic operations on the intensities of diffraction objects. e.g.,
148
+ 3. make arithmetic operations on the intensities of diffraction objects.
149
+ For example, you can do scalar operations on a single diffraction object,
150
+ which will modify the intensity values (``yarrays ``) without affecting other properties:
149
151
150
152
.. code-block :: python
151
153
152
- doubled_object = 2 * diff_object1 # Double the intensities
153
- sum_object = diff_object1 + diff_object2 # Sum the intensities
154
- subtract_scaled = diff_object1 - 5 * diff_object2 # subtract 5 * obj2 from obj 1
154
+ increased_intensity = diff_object1 + 5 # Increases the intensities by 5
155
+ decreased_intensity = diff_object1 - 1 # Decreases the intensities by 1
156
+ doubled_object = 2 * diff_object1 # Double the intensities
157
+ reduced_intensity = diff_object1 / 2 # Halves the intensities
155
158
156
- 4) get the value of the DiffractionObject at a given point in one of the xarrays
159
+ You can also do binary operations between two diffraction objects, as long as they are on the same ``q/tth/d-array ``.
160
+ The operation will apply to the intensity values, while other properties
161
+ (such as ``xarrays ``, ``xtype ``, and ``metadata ``) will be inherited
162
+ from the left-hand side diffraction object (``diff_object1 ``).
163
+ For example:
164
+
165
+ .. code-block :: python
166
+
167
+ sum_object = diff_object1 + diff_object2 # Sum the intensities
168
+ subtract_scaled = diff_object1 - 5 * diff_object2 # Subtract 5 * obj2 from obj 1
169
+ multiplied_object = diff_object1 * diff_object2 # Multiply the intensities
170
+ divided_object = diff_object1 / diff_object2 # Divide the intensities
171
+
172
+ You cannot perform operations between diffraction objects and incompatible types.
173
+ For example, attempting to add a diffraction object and a string will raise an error:
174
+
175
+ .. code-block :: python
176
+
177
+ diff_object1 + " string_value" # This will raise an error
178
+
179
+ 4. get the value of the DiffractionObject at a given point in one of the xarrays
157
180
158
181
.. code-block :: python
159
182
@@ -170,7 +193,7 @@ you can find its closest index for ``q=0.25`` by typing either of the following:
170
193
index = do.get_array_index(0.25 ) # no xtype passed, defaults to do._input_xtype, or in this example, q
171
194
index = do.get_array_index(0.25 , xtype = " q" ) # explicitly choose an xtype to specify a value
172
195
173
- 5) The ``dump `` function saves the diffraction data and relevant information to an xy format file with headers
196
+ 5. The ``dump `` function saves the diffraction data and relevant information to an xy format file with headers
174
197
(widely used chi format used, for example, by Fit2D and diffpy. These files can be read by ``LoadData() ``
175
198
in ``diffpy.utils.parsers ``).
176
199
0 commit comments