Skip to content

Adds corrected intensities to Corfunc output#3907

Merged
jellybean2004 merged 12 commits intomainfrom
cfunc_save_ex
Apr 10, 2026
Merged

Adds corrected intensities to Corfunc output#3907
jellybean2004 merged 12 commits intomainfrom
cfunc_save_ex

Conversation

@jellybean2004
Copy link
Copy Markdown
Member

Description

The Export Extrapolation button in Corfunc would save a CSV file with q and I. As suggested by @smk78, I have updated this button to save two files: uncorrected with q and I (same as before) and corrected with q and I minus background.

Fixes #2138

How Has This Been Tested?

Added and ran a unit test and manually tested in the build.

Review Checklist:

Documentation

  • There is nothing that needs documenting
  • Documentation changes are in this PR
  • There is an issue open for the documentation (link?)

Installers

  • There is a chance this will affect the installers, if so
    • Windows installer (GH artifact) has been tested (installed and worked)
    • MacOSX installer (GH artifact) has been tested (installed and worked)
    • Wheels installer (GH artifact) has been tested (installed and worked)

Licensing

  • The introduced changes comply with SasView license (BSD 3-Clause)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates Corfunc’s “Export Extrapolated” workflow to export both raw extrapolated intensities and background-corrected intensities for downstream use.

Changes:

  • Export now writes two CSVs: *_uncorrected.csv and *_corrected.csv (background-subtracted).
  • CorfuncPerspective passes the calculator background into the export dialog.
  • Adds a unit test for the two-file export behavior and updates Corfunc documentation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/sas/qtgui/Perspectives/Corfunc/media/corfunc-how-to.rst Documents the updated extrapolated export behavior (two CSV outputs).
src/sas/qtgui/Perspectives/Corfunc/UnitTesting/SaveExtrapolatedPopupTest.py Adds a unit test asserting both uncorrected and corrected files are created with expected contents.
src/sas/qtgui/Perspectives/Corfunc/SaveExtrapolatedPopup.py Implements two-file export and background subtraction in the corrected output.
src/sas/qtgui/Perspectives/Corfunc/CorfuncPerspective.py Wires the calculator background through to the export popup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jellybean2004
Copy link
Copy Markdown
Member Author

Hi @smk78! If you have some time, would you mind reviewing this PR, please?

Copy link
Copy Markdown
Contributor

@smk78 smk78 left a comment

Choose a reason for hiding this comment

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

Installed and tested CI Build #5766 on W11/x64.
Performed Corfunc analysis on example data ISIS_98929.txt using automatic settings and Guinier End: 0.01469087, Porod Start: 0.1658318 and Porod End: 0.2364554. Then used Export Extrapolated setting Lowest Q: 0.001 and Highest Q: 0.3 (input data ranged 0.007 - 0.285).
SasView computed a Background=0.30151 and generated two extrapolation files (_uncorrected and _corrected) which were read back into SasView and then compared with the input data:

Image

Further comparing the data values in all three files showed that the extrapolations were performed and integrated as expected (ie, 0.001 - Guinier End and Porod Start - 0.3) and that the intensities in the _corrected file are those in the _uncorrected file minus the computed Background to 4 decimal places. This is probably sufficient for most use cases, but if anyone performs their own subtractions manually using the Background value quoted (to 5 d.p.) in the GUI they will get very slightly different output.
Otherwise this improved functionality seems to perform exactly as described.
The corfunc-how-to Help file has also been updated to mention that Export Extrapolated now generates two files.
I also reviewed the correlation_function_analysis_in_sasview_v6 Tutorial. Whilst this mentions the Export Extrapolated functionality, it is written in such a way that I do not see a need to make any changes to the Tutorial.
I am happy to approve this.

@smk78
Copy link
Copy Markdown
Contributor

smk78 commented Mar 25, 2026

NB: I did not perform a code review!

@DrPaulSharp
Copy link
Copy Markdown
Contributor

NB: I did not perform a code review!

Sounds like that might be a job for me then!

Copy link
Copy Markdown
Contributor

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

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

This looks good, but I came to the same conclusion as copilot - you need to check for the existence of [filename]_corrected.csv and [filename]_uncorrected.csv. Currently, you warn about overwriting [filename].csv despite the fact that you do not do this.

I recommend passing the QFileDialog.Option.DontConfirmOverwrite to the save dialog, and launching dialogs immediately after obtaining the filename that check for whether the files exist and acting accordingly.

@jellybean2004
Copy link
Copy Markdown
Member Author

Hey @DrPaulSharp! I have pushed new commits adding the following functionality:

  • Added file dialog option DontConfirmOverwrite to suppress Qt’s base-path overwrite prompt.
  • If either output file already exists, show a custom overwrite confirmation dialog.
  • If the user says no, create files with numeric suffixes.

Copy link
Copy Markdown
Contributor

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

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

A couple more things to consider.

if not uncorrected_path.exists() and not corrected_path.exists():
return uncorrected_path, corrected_path

suffix_index += 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The iteration for suffix_index = 0 requires an additional if statement for every iteration of this loop (suffix = "" if suffix_index == 0 else f"_{suffix_index}") and it's already been established prior to calling this routine that either of base_path.parent / f"{base_path.name}_uncorrected.csv or base_path.parent / f"{base_path.name}_corrected.csv exists. Could you simplify this routine by starting from suffix_index = 1 instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What happens if there are an extremely large number of numerical files here? Should there be an escape after a certain number of attempts?

@jellybean2004
Copy link
Copy Markdown
Member Author

Hey @DrPaulSharp! Just pushed some commits implementing the suggested changes.

I have also added a cap for the suffix, set to 1000. Let me know what you think.


from .UI.SaveExtrapolated import Ui_SaveExtrapolatedPanel

MAX_SUFFIX_ATTEMPTS = 10000
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think a default of 1000, as stated in your text, would be a better value here.

Copy link
Copy Markdown
Contributor

@DrPaulSharp DrPaulSharp left a comment

Choose a reason for hiding this comment

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

All looks good! Merge when ready.

@jellybean2004 jellybean2004 merged commit c898718 into main Apr 10, 2026
36 checks passed
@jellybean2004 jellybean2004 deleted the cfunc_save_ex branch April 10, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add corrected intensities to Save Extrapolation output in Corfunc

4 participants