Skip to content

docs: some parts in documentation are incorrect. #352

Description

@ycexiao

Problems

  • Failed example for DiffractionObject.get_array_index
  • Duplicate code block
  • Failed example for diffpy.utils.transform.d_to_tth
  • Markup not rendered correctlly

failed example for DiffractionObject.get_array_index

In Diffraction Objects Example documentation step 4

tth_ninety_index = diff_object1.get_array_index(90, xtype="tth")

will raise

TypeError: DiffractionObject.get_array_index() got multiple values for argument 'xtype'

Because the signature is

def get_array_index(self, xtype, value):
    ...

failed example for diffpy.utils.transform.d_to_tth

In https://www.diffpy.org/diffpy.utils/examples/transforms_example.html#id1, step 3

from diffpy.utils.transforms import d_to_tth

wavelength = 0.71
d = np.array([1.0, 0.8, 0.6, 0.4, 0.2])
tth = d_to_tth(d, wavelength)

will raise

ValueError: The supplied input array and wavelength will result in an impossible two-theta. Please check these values and re-instantiate the DiffractionObject with correct values. 

duplicate code block

In https://www.diffpy.org/diffpy.utils/examples/resample_example.html#resampling-example, step 1. The same code block and words appear twice. This might be a typo.


markup not rendered correctly

In https://www.diffpy.org/diffpy.utils/examples/parsers_example.html#id1, step 5. A sentence is included in a code block.

Proposed solution

Activity

  1. ycexiao commented on Jul 24, 2025

    @ycexiao
    ContributorAuthor

    The function DiffractionObject.get_array_index

        def get_array_index(self, xtype, xvalue):
            """Return the index of the closest value in the array associated with
            the specified xtype and the value provided.
            ...
            xtype = self._input_xtype
            xarray = self.on_xtype(xtype)[0]
            if len(xarray) == 0:
                raise ValueError(
                    f"The '{xtype}' array is empty. "
                    "Please ensure it is initialized."
                )
            index = (np.abs(xarray - xvalue)).argmin()
            return index
            """
    

    So the input parameterxtype doesn't have an effect at all. Thus, the following code

    x = np.linspace(0, 90, 1000)
    y = np.random.rand(1000)
    tmp = DiffractionObject(
         xarray=x,
         yarray=y,
         xtype="angle",
         wavelength=1.54,
    )
    index_angle = tmp.get_array_index(xvalue=0.24, xtype="angle")
    index_q_from_function = tmp.get_array_index(xvalue=0.24, xtype="q")
    real_index_q =  np.argmin(np.abs(tmp.on_xtype("q")[0] - 0.24))
    print(index_angle == index_q_from_function)
    print(index_q_from_function == real_index_q)
    

    returns True and False.

    @sbillinge, is it a bug we want to fix?

  2. changed the title [-]docs: example of using `get_array_index` failed[/-] [+]docs: Some parts in documentation are incorrect.[/+] on Jul 24, 2025
  3. changed the title [-]docs: Some parts in documentation are incorrect.[/-] [+]docs: some parts in documentation are incorrect.[/+] on Jul 24, 2025
  4. sbillinge commented on Jul 25, 2025

    @sbillinge
    Contributor

    @sbillinge, is it a bug we want to fix?

    yes, this looks like a bug. The intent is that the user wants the index of, for example, Q=23.4 a-1, or tth=45 deg. so inside we want to use the relevant xarray, be it Q or tth or whatever.

    Let's write some tests for this then fix the code.

    Please check everywhere in the code where this is used, and also the docs so everything agrees. Maybe do all that work on separate PR clsing a separate issue.

    Please also fix all the other documentation issues that you found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions