Skip to content

docs: fix the example of using DiffractionObject.get_array_index in the documentation #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions docs/source/examples/diffraction_objects_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ For example, attempting to add a diffraction object and a string will raise an e

.. code-block:: python

tth_ninety_index = diff_object1.get_array_index(90, xtype="tth")
tth_ninety_index = diff_object1.get_array_index(xvalue=90, xtype="tth")
Copy link
Contributor

Choose a reason for hiding this comment

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

This will have to be fixed later when we finalize the signature. Let's just remember to do it....

intensity_at_ninety = diff_object1.on_tth()[1][tth_ninety_index]

If you do not specify an ``xtype``, it will default to the ``xtype`` used when creating the ``DiffractionObject``.
Expand All @@ -190,8 +190,8 @@ you can find its closest index for ``q=0.25`` by typing either of the following:
.. code-block:: python

print(do._input_xtype) # remind ourselves which array was input. prints "q" in this case.
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
index = do.get_array_index(xvalue=0.25) # no xtype passed, defaults to do._input_xtype, or in this example, q
Copy link
Contributor

Choose a reason for hiding this comment

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

same here.

index = do.get_array_index(xvalue=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
(widely used chi format used, for example, by Fit2D and diffpy. These files can be read by ``LoadData()``
Expand Down
3 changes: 1 addition & 2 deletions docs/source/examples/parsers_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ Now we can extract specific data table columns from the dictionary.

parsed_file_data = serialize_data('<PATH to data.txt>', hdata, data_table, serial_file='<PATH to serialfile.json>')

The returned value, ``parsed_file_data``, is the dictionary we just added to ``serialfile.json``.
To extract the data from the serial file, we use ``deserialize_data``.
The returned value, ``parsed_file_data``, is the dictionary we just added to ``serialfile.json``. To extract the data from the serial file, we use ``deserialize_data``.

.. code-block:: python

Expand Down
12 changes: 0 additions & 12 deletions docs/source/examples/resample_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ given enough datapoints.
Each data table has two columns: first is the grid and second is the function value.
To extract the columns, we can utilize the serialize function ...

.. code-block:: python

from diffpy.utils.parsers.serialization import serialize_data
nickel_data = serialize_data('Nickel.gr', {}, nickel_datatable, dt_colnames=['grid', 'func'])
nickel_grid = nickel_data['Nickel.gr']['grid']
nickel_func = nickel_data['Nickel.gr']['func']
target_data = serialize_data('NiTarget.gr', {}, nitarget_datatable, dt_colnames=['grid', 'function'])
target_grid = nickel_data['Nickel.gr']['grid']
target_func = nickel_data['Nickel.gr']['func']

To extract the columns, we can utilize the serialize function ...

.. code-block:: python

from diffpy.utils.parsers.serialization import serialize_data
Expand Down
23 changes: 23 additions & 0 deletions news/fix-docs-example.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news added: Fix some examples in the documentation.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
Loading