8000 adding function for plotting specific interval lists side by side by gshvarts · Pull Request #1330 · LorenFrankLab/spyglass · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

adding function for plotting specific interval lists side by side #1330

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

gshvarts
Copy link

Description

Adding the function plot_specific_interval_lists() to common_interval.py.
I added this function to my repo locally a while ago and use it all the time so figured it might be helpful for other people too. It's similar to the IntervalList.plot_intervals() function except takes in a specific list of interval_list_name values to display and does some nice formatting. I've used it often as a helpful tool when double checking that my interval lists span the times that I expect them to and when developing new custom interval lists to add.

Example usage:

from spyglass.utils.nwb_helper_fn import get_nwb_copy_filename
from spyglass.common.common_interval import plot_specific_interval_lists

subj = 'chip'
date = 20220104

nwb_file_name = f"{subj}{date}.nwb"
nwb_copy_file_name = get_nwb_copy_filename(nwb_file_name)

plot_specific_interval_lists(nwb_copy_file_name, ['raw data valid times', 'pos 1 valid times', 'pos 1 mobile times', 'pos 3 valid times'])

Outputs:
plot_specific_interval_lists_example

Checklist:

  • This PR should be accompanied by a release: no
  • N/A. If release, I have updated the CITATION.cff
  • This PR makes edits to table definitions: no
  • N/A. If table edits, I have included an alter snippet for release notes.
  • N/A. If this PR makes changes to position, I ran the relevant tests locally.
  • N/A. I have updated the CHANGELOG.md with PR number and description.
  • N/A. I have added/edited docs/notebooks to reflect the changes

Copy link
Member
@CBroz1 CBroz1 left a comment

Choose a reason for hiding this comment

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

Thanks @gshvarts ! This looks good! There are two things I might add, and they can either happen in this PR if you want to take them on, or I can open an issue and migrate later.

  1. Testing - as you might have seen in other functions, the return_fig arg is used to our test suite can grab and inspect the content. This could be as simple as testing that all intervals were captured like this
  2. Class Method - I'd like to open up the use of this function by invoking a method from the main class. Meaning something like ....
(IntervalList & my_restriction).plot_lists(start_time=0)

This requires some familiarity with object-oriented programing, fetching the list names from self, but it would better align with the feedback I've seen from users requesting the ability to restrict a table before invoking a method

Lmk what you think. Like I said, you can either take a stab at the above or we can either review/merge as is

"nwb_file_name": nwb_copy_file_name,
"interval_list_name": interval_list_name,
}
).fetch1("valid_times")
Copy link
Member

Choose a reason for hiding this comment

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

This fetch loop will really slow down for greater numbers of intervals. I think you could optimize by running a single fetch of the name and times, and then running your convert function separately

@edeno edeno requested a review from Copilot June 15, 2025 17:50
Copy link
Contributor
@Copilot 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

This PR introduces a new helper function that plots specific interval lists side by side for visual validation and debugging.

  • Added the function plot_specific_interval_lists() to generate a timeline plot using matplotlib.
  • Introduced a new import for matplotlib as mpl and a helper function to convert interval endpoints to plot ranges.
Comments suppressed due to low confidence (2)

src/spyglass/common/common_interval.py:1157

  • The comment and conversion here indicate a scaling by 60, which converts seconds to minutes, but the x-axis label states seconds. Consider updating the conversion factor, comment, and/or axis label to maintain consistency in units.
int_min = (interval[0] - start_time) / 60  # and convert to seconds

src/spyglass/common/common_interval.py:1129

  • The docstring omits a description for the 'return_fig' parameter. Adding a brief explanation for 'return_fig' would improve clarity.
def plot_specific_interval_lists(nwb_copy_file_name, interval_list_names, start_time=0, return_fig=False):

Copy link
codecov bot commented Jun 17, 2025

Codecov Report

Attention: Patch coverage is 91.30435% with 2 lines in your changes missing coverage. Please review.

Project coverage is 67.46%. Comparing base (11cb77c) to head (69d3db9).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/spyglass/common/common_interval.py 91.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1330      +/-   ##
==========================================
+ Coverage   67.21%   67.46%   +0.24%     
==========================================
  Files          98       98              
  Lines       12272    12300      +28     
==========================================
+ Hits         8249     8298      +49     
+ Misses       4023     4002      -21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gshvarts
Copy link
Author

@CBroz1 I updated the existing plot_intervals class function with my newer version and also updated the existing test_plot_intervals function to check both the plotted interval list names and the times.

One thing I couldn't quite figure out is that the times had some weird rounding issues after being plotted. I'm guessing that has something to do with the interval times getting converted into seconds for plotting and then maybe not being as precise to enough decimal points. I ended up just rounded the times arrays to the 4th decimal place before checking if they're equal to each other. I figured getting to that resolution for this plotting function isn't very important but let me know if it's something I should keep looking into.

@edeno edeno requested a review from CBroz1 June 18, 2025 01:28
@gshvarts
Copy link
Author

Added an error if there's more than one nwb_file_name in the IntervalList and a warning if there's >100 entries. Let me know if there's anything else I should add!

@CBroz1
Copy link
Member
CBroz1 commented Jun 22, 2025

Let me know if there's anything else I should add!

Thanks @gshvarts - I'll test it out myself on Monday as a final check. The only other minor thing to correct is the lint check. This can be fixed by running...

pip install black
black /path/to/this_file.py

It may ask you to split up the longer strings like this:

raise ValueError(
f"Found {len(need_update)} rows with existing names, but "
+ f"different times:{need_update}"
)

to prevent any one line from going past the 80 char limit. If you use VSCode, you can look at mentions of black here for how to do this automatically - or at least get warnings.

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.

3 participants
0