Skip to content
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

Fix for ROI Addition After Exporting CSV #2458

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ashleymeigh2
Copy link
Collaborator

Issue

Closes #2422

Description

This PR resolves an issue in the Spectrum Viewer where adding new ROIs fails after exporting a CSV file. The problem was caused by tof_data becoming unavailable post-export.

Acceptance Criteria

Open a dataset (without the spectra file), open the spectum viewer
Click "Add" to add an ROI
Click "Export Spectrum" and choose name to save an CSV file
Click "Add" to add an ROI
A new ROI should be successfully added and displayed in the Spectrum Viewer

Documentation

All changes should be noted in the appropriate file in docs/release_notes

Copy link
Collaborator

@JackEAllen JackEAllen left a comment

Choose a reason for hiding this comment

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

Changes look good! I have ran unit tests locally and manually tested by loading in a spectrum dataset, adding some ROIs, exporting data, then adding more ROIs.
Just a few small suggestions and happy to merge 🙂

Comment on lines +442 to +443
spectrum_values = [v for v in self.spectrum_widget.spectrum_data_dict.values() if v is not None]
tof_data = np.arange(len(spectrum_values[0]) if spectrum_values else 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we give V a more descriptive name please

Comment on lines +442 to +443
spectrum_values = [v for v in self.spectrum_widget.spectrum_data_dict.values() if v is not None]
tof_data = np.arange(len(spectrum_values[0]) if spectrum_values else 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we are okay to use .size here as spectrum_values should always be an np.ndarray.

tof_data = np.arange(spectrum_values[0].size if spectrum_values else 0)

@@ -437,9 +437,14 @@ def set_roi_visibility_flags(self, roi_name: str, visible: bool) -> None:
self.show_visible_spectrums()

def show_visible_spectrums(self) -> None:
Copy link
Collaborator

@JackEAllen JackEAllen Jan 20, 2025

Choose a reason for hiding this comment

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

As this method does a few things now, can we add a docstring to explain what the method does.

@@ -0,0 +1 @@
2422: Spectrum viewer: cant add an ROI after exporting CSV
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we re-word this slightly to say what the proposed change is resolving, maybe something like:

"Spectrum viewer: Resolves a bug preventing a new ROI from being added after exporting to a CSV file,"

Copy link
Collaborator

@samtygier-stfc samtygier-stfc left a comment

Choose a reason for hiding this comment

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

I think would be good to understand why model.tof_data is None here after doing a CSV export.

It looks like it is set in model.set_stack() and also in model.save_csv(). Does it get set to None by one of those?

@ashleymeigh2 ashleymeigh2 self-assigned this Jan 21, 2025
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.

Spectrum viewer: cant add an ROI after exporting CSV
4 participants