Skip to content

Adds corrected intensities to Corfunc output#3907

Open
jellybean2004 wants to merge 4 commits intomainfrom
cfunc_save_ex
Open

Adds corrected intensities to Corfunc output#3907
jellybean2004 wants to merge 4 commits intomainfrom
cfunc_save_ex

Conversation

@jellybean2004
Copy link
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

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.

Comment on lines +108 to +124
selected_path = Path(filename)
base_path = selected_path.with_suffix("")
uncorrected_path = base_path.parent / f"{base_path.name}_uncorrected.csv"
corrected_path = base_path.parent / f"{base_path.name}_corrected.csv"

with open(filename, "w") as outfile:
outfile.write("Q, I(q)\n")
background = 0.0 if self.background is None else self.background
background_subtracted_intensity = intensity - background

with open(uncorrected_path, "w") as uncorrected_file:
uncorrected_file.write("Q, I(q)\n")
for q_value, i_value in zip(q, intensity):
outfile.write("%.6g, %.6g\n"%(q_value, i_value))
uncorrected_file.write("%.6g, %.6g\n" % (q_value, i_value))

with open(corrected_path, "w") as corrected_file:
corrected_file.write("Q, I(q)-Background\n")
for q_value, i_subtracted in zip(q, background_subtracted_intensity):
corrected_file.write("%.6g, %.6g\n" % (q_value, i_subtracted))
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

Because the two output filenames are derived from the selected base name, the Qt “overwrite existing file” confirmation (if any) only applies to the user-selected path, not necessarily to *_uncorrected.csv / *_corrected.csv. This can silently overwrite existing exports when the base file doesn’t exist but one/both derived files do. Consider explicitly checking uncorrected_path.exists() / corrected_path.exists() and prompting the user before overwriting.

Copilot uses AI. Check for mistakes.
jellybean2004 and others added 4 commits March 24, 2026 12:22
@jellybean2004
Copy link
Member Author

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

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

2 participants