-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
line_time_seconds
66a2d99
to
d774ff7
Compare
cd02fcc
to
8868688
Compare
679b129
to
83818ad
Compare
a9c3ff4
to
6652798
Compare
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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()`. |
lumicks/pylake/detail/image.py
Outdated
) | ||
pixel_boundary = np.argmax(infowave == InfowaveCode.pixel_boundary) | ||
if infowave[pixel_boundary] != InfowaveCode.pixel_boundary: | ||
raise RuntimeError("No completed pixel found in Scan") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
lumicks/pylake/kymo.py
Outdated
|
||
# 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
if len(coordinate) <= 4: | ||
raise RuntimeError( | ||
"You need at least 5 time points to estimate the number of points to include in " | ||
"the fit." | ||
) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
6652798
to
319d50a
Compare
Why this PR?
Prior to this change,
Kymo
s consisting of a single or partial scan line provide noline_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 corruptedScan
items, but end up in thekymos
field.