Skip to content

Conversation

rozyczko
Copy link
Member

This adds the PDF functionality to the new EDL.
Unfortunately, the built-in charts don't work with the PDF data so I had to reimplement bokeh plotting for the included example.

@rozyczko rozyczko requested a review from AndrewSazonov April 14, 2025 09:07
added a way to set additional attributes on a Component.
Modified the PDF instrument param class accordingly
@rozyczko rozyczko added the [scope] enhancement Adds/improves features (major.MINOR.patch) label Apr 15, 2025
@rozyczko rozyczko moved this to In Review in New EasyDiffractionLib Apr 15, 2025
@rozyczko rozyczko self-assigned this Apr 15, 2025
@AndrewSazonov
Copy link
Member

Tried installing diffpy.pdffit2==0.0.2 from https://easyscience.github.io/pypi, but ran into runtime errors when using it in a Python 3.12 virtual environment on macOS 14 (Apple Silicon):

python -c "import diffpy.pdffit2"

Gives:

ImportError: dlopen(.../pdffit2.cpython-312-darwin.so, 0x0002): 
symbol not found in flat namespace '_gsl_fft_complex_radix2_forward'

This suggests the GSL shared library isn’t found at runtime, or it’s not properly linked during packaging.

I installed GSL with brew install gsl and reinstalled the package, but the error persisted.

Checked the dynamic libraries with:

otool -L .../pdffit2.cpython-312-darwin.so

Output:

(architecture x86_64):
  /usr/lib/libc++.1.dylib
  /usr/lib/libSystem.B.dylib
(architecture arm64):
  /usr/lib/libc++.1.dylib
  /usr/lib/libSystem.B.dylib

No GSL dependency listed here — looks like it wasn’t linked into the ‘.so’. So it’s likely a packaging/build issue with diffpy.pdffit2==0.0.2.

I then uninstalled that version and accidentally let pip install the default one (diffpy.pdffit2==1.5.1 from PyPI). Surprisingly, it worked - I was able to run the example and see both measured and calculated patterns (see screenshot) 😁🤔

Just to confirm: is this the expected plot?

bokeh_plot

re-enable fitting in the pdf example
@rozyczko
Copy link
Member Author

Holy cow! Indeed! PDFFIT2 is now available as binary distribution on pypi, as of Feb 7, 2025.
The only reason we were building this module was that the pypi distro was source only and getting GSL installed and usable for linking was a nightmare (on windows at least).
This is great! We no longer have to rely on our own builds.
I modified the setup

@AndrewSazonov
Copy link
Member

I’ve made some updates to the code - mainly extending the plotting functionality and doing a bit of intermediate refactoring to improve clarity. I also replaced the existing PDF analysis example with two others that provide a better quality of fit.

That said, some PDF-specific parameters are currently defined in the Instrument class but should eventually be moved to the Peak class. Before making that change, though, we need a broader set of PDF examples using Diffpy. In particular, we’re still missing examples for constant-wavelength and time-of-flight neutron diffraction. So far, we only have an X-ray-based case. Getting at least one example for each type will help us understand what additional parameters or adjustments might be needed - especially for DREAM.

@rozyczko
Copy link
Member Author

Functional tests now fail with

AttributeError: 'Analysis' object has no attribute 'show_meas_vs_calc_chart'

@rozyczko rozyczko merged commit 8a813c1 into develop Apr 30, 2025
@github-project-automation github-project-automation bot moved this from In Review to Done in New EasyDiffractionLib Apr 30, 2025
@rozyczko rozyczko deleted the pdf branch May 2, 2025 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[scope] enhancement Adds/improves features (major.MINOR.patch)
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants