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

Add parents in HTML representation and always print class name #3700

Merged
merged 5 commits into from
Feb 18, 2025

Conversation

alejoe91
Copy link
Member

I'm always finding myself searching through the kwargs to check the preprocessing chain...
@chrishalcrow you're gonna like this :)

Added the Parent section in the HTML repr (and also appended the class name to the self.name). Here's how it looks:

image

@alejoe91 alejoe91 added the core Changes to core module label Feb 17, 2025
Copy link
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

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

Nice.
I like having both the user assigned name and the class name together but why are you not displaying name for the parent classes?

@alejoe91
Copy link
Member Author

Nice. I like having both the user assigned name and the class name together but why are you not displaying name for the parent classes?

because the name is copied over to child classes, so I think it's redundant!

Copy link
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

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

What if you have a class with name "A", then you filter it and set the name to "B"? Is that allowed? Would the preprocessing chain have a different name in that case?

I have a slight leaning to keep the representation as it is even if it is a bit redundant to simplify the code and not care about edge cases. That said, I think this is good as it is:

LGTM

Feel free to merge.

@h-mayorquin
Copy link
Collaborator

Oh yes, JFYI you can paste html code to github so if you copy the output of a the notebook cell you can just paste it here with an HTML tag and we would be able to click on it!

@alejoe91
Copy link
Member Author

Maybe we can propagate the name and only display if different?

@chrishalcrow
Copy link
Collaborator

Very fun! Yeah, looks good.

I wonder if we should display the kwargs too? Maybe for another PR... There's some code for grabbing our the preprocessing kwargs in the #3438

Screenshot 2025-02-18 at 09 45 54

@alejoe91 alejoe91 added this to the 0.102.1 milestone Feb 18, 2025
@h-mayorquin
Copy link
Collaborator

Maybe we can propagate the name and only display if different?

If you feel that the complication is worth it to have a cleaner display I am OK with it. I am also OK with the things as they are here as what I mentioned is probably an edge case.

@alejoe91
Copy link
Member Author

@chrishalcrow let's extend to kwargs later.

@h-mayorquin I added some logic to only display names if different from parent. Here's how it looks:

Recording

Preprocessed (WhitenRecording): 4 channels - 25.0kHz - 1 segments - 250,000 samples - 10.00s - float32 dtype - 3.81 MiB
Channel IDs
    ['0' '1' '2' '3']
Annotations
  • is_filtered : True
  • probe_0_planar_contour : [[ -25. 45.]\n [ -25. -25.]\n [ 10. -125.]\n [ 45. -25.]\n [ 45. 45.]]
  • probes_info : [{}]
  • name : Preprocessed
Channel Properties
    contact_vector [(0, 0., 0., 'circle', 6., '', '0', 0, 'um', 1., 0., 0., 1.)\n (0, 0., 20., 'circle', 6., '', '1', 1, 'um', 1., 0., 0., 1.)\n (0, 20., 0., 'circle', 6., '', '2', 2, 'um', 1., 0., 0., 1.)\n (0, 20., 20., 'circle', 6., '', '3', 3, 'um', 1., 0., 0., 1.)]
    location [[ 0. 0.]\n [ 0. 20.]\n [20. 0.]\n [20. 20.]]
    group [0 0 0 0]
    gain_to_uV [1. 1. 1. 1.]
    offset_to_uV [0 0 0 0]
Parent
    CommonReferenceRecording: 4 channels - 25.0kHz - 1 segments - 250,000 samples - 10.00s - float32 dtype - 3.81 MiB
    Channel IDs
      ['0' '1' '2' '3']
    Annotations
    • is_filtered : True
    • probe_0_planar_contour : [[ -25. 45.]\n [ -25. -25.]\n [ 10. -125.]\n [ 45. -25.]\n [ 45. 45.]]
    • probes_info : [{}]
    • name : Preprocessed
    Channel Properties
      contact_vector [(0, 0., 0., 'circle', 6., '', '0', 0, 'um', 1., 0., 0., 1.)\n (0, 0., 20., 'circle', 6., '', '1', 1, 'um', 1., 0., 0., 1.)\n (0, 20., 0., 'circle', 6., '', '2', 2, 'um', 1., 0., 0., 1.)\n (0, 20., 20., 'circle', 6., '', '3', 3, 'um', 1., 0., 0., 1.)]
      location [[ 0. 0.]\n [ 0. 20.]\n [20. 0.]\n [20. 20.]]
      group [0 0 0 0]
      gain_to_uV [1. 1. 1. 1.]
      offset_to_uV [0 0 0 0]
    Parent
      HighpassFilterRecording: 4 channels - 25.0kHz - 1 segments - 250,000 samples - 10.00s - float32 dtype - 3.81 MiB
      Channel IDs
        ['0' '1' '2' '3']
      Annotations
      • is_filtered : True
      • probe_0_planar_contour : [[ -25. 45.]\n [ -25. -25.]\n [ 10. -125.]\n [ 45. -25.]\n [ 45. 45.]]
      • probes_info : [{}]
      • name : Preprocessed
      Channel Properties
        contact_vector [(0, 0., 0., 'circle', 6., '', '0', 0, 'um', 1., 0., 0., 1.)\n (0, 0., 20., 'circle', 6., '', '1', 1, 'um', 1., 0., 0., 1.)\n (0, 20., 0., 'circle', 6., '', '2', 2, 'um', 1., 0., 0., 1.)\n (0, 20., 20., 'circle', 6., '', '3', 3, 'um', 1., 0., 0., 1.)]
        location [[ 0. 0.]\n [ 0. 20.]\n [20. 0.]\n [20. 20.]]
        group [0 0 0 0]
        gain_to_uV [1. 1. 1. 1.]
        offset_to_uV [0 0 0 0]
      Parent
        GroundTruthRecording (InjectTemplatesRecording): 4 channels - 25.0kHz - 1 segments - 250,000 samples - 10.00s - float32 dtype - 3.81 MiB
        Channel IDs
          ['0' '1' '2' '3']
        Annotations
        • is_filtered : True
        • probe_0_planar_contour : [[ -25. 45.]\n [ -25. -25.]\n [ 10. -125.]\n [ 45. -25.]\n [ 45. 45.]]
        • probes_info : [{}]
        • name : GroundTruthRecording
        Channel Properties
          contact_vector [(0, 0., 0., 'circle', 6., '', '0', 0, 'um', 1., 0., 0., 1.)\n (0, 0., 20., 'circle', 6., '', '1', 1, 'um', 1., 0., 0., 1.)\n (0, 20., 0., 'circle', 6., '', '2', 2, 'um', 1., 0., 0., 1.)\n (0, 20., 20., 'circle', 6., '', '3', 3, 'um', 1., 0., 0., 1.)]
          location [[ 0. 0.]\n [ 0. 20.]\n [20. 0.]\n [20. 20.]]
          group [0 0 0 0]
          gain_to_uV [1. 1. 1. 1.]
          offset_to_uV [0. 0. 0. 0.]

Sorting

Another name (UnitsSelectionSorting): 5 units - 1 segments - 25.0kHz
Unit IDs
    ['0' '1' '2' '3' '4']
Annotations
  • name : Another name
Unit Properties
    gt_unit_locations[[11.9931 26.779676 45.756153 ]\n [ 4.539259 -4.575459 32.77219 ]\n [-6.4170756 29.897282 36.195335 ]\n [-7.765987 7.734192 14.736742 ]\n [-5.590045 12.970678 48.677856 ]]
Parent
    GroundTruthSorting (NumpySorting): 10 units - 1 segments - 25.0kHz
    Unit IDs
      ['0' '1' '2' '3' '4' '5' '6' '7' '8' '9']
    Annotations
    • name : GroundTruthSorting
    Unit Properties
      gt_unit_locations[[11.9931 26.779676 45.756153 ]\n [ 4.539259 -4.575459 32.77219 ]\n [-6.4170756 29.897282 36.195335 ]\n [-7.765987 7.734192 14.736742 ]\n [-5.590045 12.970678 48.677856 ]\n [26.28562 15.958191 13.609822 ]\n [25.525425 4.8619213 45.831062 ]\n [-8.12456 28.146242 16.332659 ]\n [21.863459 -7.436342 15.753815 ]\n [10.559567 14.730136 38.61602 ]]

@@ -30,19 +30,26 @@ def __init__(self, sampling_frequency: float, unit_ids: List):
self._cached_spike_trains = {}

def __repr__(self):
return self._repr_header()

def _repr_header(self, parent_name=None):
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I like this design. would be better to have an explicit display_name=True/False

Copy link
Member Author

Choose a reason for hiding this comment

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

and then have the logic in the _repr_html_()? Ok for me

@samuelgarcia
Copy link
Member

excelent.

@alejoe91 alejoe91 merged commit 48581eb into SpikeInterface:main Feb 18, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Changes to core module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants