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

kymo: make single line scan return a valid line_time_seconds #576

Merged
merged 3 commits into from
Oct 31, 2023

Conversation

JoepVanlier
Copy link
Member

@JoepVanlier JoepVanlier commented Sep 26, 2023

Why this PR?
Prior to this change, Kymos consisting of a single or partial scan line provide no line_time_seconds which prevents plotting and other functionality. Now they provide the line time of what is actually shown in the plot (e.g. a full line, without deadtime if the line time is smaller or equal than a single line).

The second issue is that for a few Bluelake versions, Bluelake put some kymographs that were taken with a fixed line count in the Scan field. The last commit contains a fallback method so that they will not be loaded as corrupted Scan items, but end up in the kymos field.

@JoepVanlier JoepVanlier changed the title Single line scan kymo: make single line scan return a valid line_time_seconds Sep 26, 2023
@rpauszek rpauszek force-pushed the rework_confocal_tests branch 2 times, most recently from 66a2d99 to d774ff7 Compare September 27, 2023 09:41
Base automatically changed from rework_confocal_tests to main September 27, 2023 10:54
@JoepVanlier JoepVanlier force-pushed the single_line_scan branch 2 times, most recently from 679b129 to 83818ad Compare October 24, 2023 14:13
@JoepVanlier JoepVanlier marked this pull request as ready for review October 24, 2023 15:25
@JoepVanlier JoepVanlier requested review from a team as code owners October 24, 2023 15:25
@JoepVanlier JoepVanlier force-pushed the single_line_scan branch 2 times, most recently from a9c3ff4 to 6652798 Compare October 27, 2023 14:11
Copy link
Contributor

@rpauszek rpauszek left a comment

Choose a reason for hiding this comment

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

good stuff, it's nice to handle our mistakes graciously 😅 just a left a couple minor comments for clarity

changelog.md Outdated
@@ -7,6 +7,12 @@
* Added more options for plotting color channels for images:
* Shortcuts `"r"`, `"g"`, and `"b"` can now be used for plotting single color channels in addition to `"red"`, `"green"`, and `"blue"`.
* Two-channel visualizations can be plotted using `"rg"`, `"gb"`, or `"rb"`.
* Handle kymographs that were accidentally stored in the `Scan` field.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Handle kymographs that were accidentally stored in the `Scan` field.
* Handle kymographs that were erroneously stored in the `Scan` field.

Is this fixed in BL and if so do we know in which version? Also, I think this would be more appropriate under Bug Fixes or Improvements

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call on adding the version number!

And yeah that's fair, it's an improvement. I feel it's not necessarily a bugfix on pylake's part.

changelog.md Outdated

#### Improvements

* Kymographs that only consist of a single line no longer raise, but report a `line_time_seconds`. This also allows you to now call `Kymo.plot()` on these.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Kymographs that only consist of a single line no longer raise, but report a `line_time_seconds`. This also allows you to now call `Kymo.plot()` on these.
* Kymographs consisting of a single scan line now return a valid `line_time_seconds`. This allows certain downstream functionality, such as `Kymo.plot()`.

)
pixel_boundary = np.argmax(infowave == InfowaveCode.pixel_boundary)
if infowave[pixel_boundary] != InfowaveCode.pixel_boundary:
raise RuntimeError("No completed pixel found in Scan")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
raise RuntimeError("No completed pixel found in Scan")
raise RuntimeError("No completed pixel found in image")

maybe don't use "Scan" so as not to confuse with the class

Comment on lines 38 to 43

# Special case for no dead time. Is it really no deadtime, or a single line?
if dead_time == 0 and not np.any(beyond_first_line):
raise RuntimeError(single_line_error)
return scan_time * infowave._src.dt * ns_to_sec

except ValueError: # ValueError occurs when beyond_first_line is empty
raise RuntimeError(single_line_error)
return scan_time * infowave._src.dt * ns_to_sec
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't suggest on the whole block, but it seems that the try ... except was there mostly to re-throw a more descriptive error. Since we don't need to do that now, we could move the early out up and save some indentation

Personally, I find it cleaner, for lines 35-44:

beyond_first_line = infowave.data[start + scan_time :] != InfowaveCode.discard
if not np.any(beyond_first_line):
    return scan_time * infowave._src.dt * ns_to_sec

# Special case for no dead time. Is it really no deadtime, or a single line?
if (dead_time := np.argmax(beyond_first_line)) == 0:
    return scan_time * infowave._src.dt * ns_to_sec

I tried it and all of the tests pass

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's fair. I'd rather check for len(beyond_first_line) than using np.any, since that's the only case we need to be covering (to prevent argmax from getting an empty array).

Comment on lines +738 to +742
if len(coordinate) <= 4:
raise RuntimeError(
"You need at least 5 time points to estimate the number of points to include in "
"the fit."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we have this check already somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do have a similar check elsewhere, but you don't even get to that check if you run diffusion estimation on an empty track. Instead you are greeted by a TypeError: expected non-empty vector for x which is not helpful.

prior to this change, kymographs with a single line could not be plotted since `line_time_seconds` is unavailable
@JoepVanlier JoepVanlier merged commit 5588392 into main Oct 31, 2023
8 checks passed
@JoepVanlier JoepVanlier deleted the single_line_scan branch October 31, 2023 16:48
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.

2 participants