Skip to content

Conversation

@bparks13
Copy link
Member

@bparks13 bparks13 commented Oct 20, 2025

This PR was initially a part of #493; it has been split out into this PR as well so that we can review the underlying infrastructural changes independently of the addition of the single-shank Neuropixels 2.0 probes. This is prompted by #522, which would benefit from some of these changes but we do not need the single-shank probes for #522 to be implemented.

Below are the major highlights of this PR:

  • Add Neuropixels V2 probe info interfaces and implementations
  • Moved all probe-specific logic from the dialog to the info class in the Design library
  • Update all methods/classes to handle the abstract class, with easy scalability to add single-shank probes in the future
  • Add clone method for NeuropixelsV2eProbeGroup to ensure that dialogs can be exited without affecting settings
  • Update how the ChannelMap is accessed and utilized

@bparks13 bparks13 added this to the 0.7.0 milestone Oct 20, 2025
@bparks13 bparks13 requested a review from jonnew October 20, 2025 18:45
@bparks13 bparks13 self-assigned this Oct 20, 2025
@bparks13 bparks13 requested review from aacuevas and removed request for jonnew October 30, 2025 19:46
Copy link
Collaborator

@aacuevas aacuevas left a comment

Choose a reason for hiding this comment

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

I left a couple of comments, but there are other parts where these same comments are still true.
In short, while it is in general a good abstraction effort, there are some places where separation of responsibilities is broken and the general classes include switches of the specifics, which is not a good pattern.

@bparks13 bparks13 requested a review from aacuevas November 4, 2025 19:50
@bparks13
Copy link
Member Author

bparks13 commented Nov 4, 2025

@aacuevas I have updated the implementation as we discussed, and tested it out. There is no difference in behavior, but this is definitely a cleaner separation between responsibilities, and should translate well when I add in the single-shank probe. Let me know if this looks good, and I can rebase the other branch to make use of these changes.

- Add Neuropixels V2 probe info interfaces and implementations
- Moved all probe-specific logic from the dialog to the info class in the Design library
- Update all methods/classes to handle the abstract class, with easy scalability to add single-shank probes in the future
- Add clone method for NeuropixelsV2eProbeGroup to ensure that dialogs can be exited without affecting settings
- Update how the ChannelMap is accessed and utilized
@bparks13 bparks13 force-pushed the refactor-npx2-config branch from d37589c to 5db06c3 Compare November 7, 2025 21:58
Copy link
Collaborator

@aacuevas aacuevas left a comment

Choose a reason for hiding this comment

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

I made some comments of some things I believe should be either addressed or justified.

1 => offset + 40.0f,
_ => throw new ArgumentException("Invalid index given.")
};
return Activator.CreateInstance(typeof(T), Specification, Version, Probes.Select(probe => new Probe(probe)).ToArray()) as T ?? throw new NullReferenceException($"Issue creating new probe group of type {nameof(NeuropixelsV2eProbeGroup)}.");
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 I understand what you're trying to do here, but this might be a case of excessive complication.
It might be easier, and way more readable, to just create a virtual (or abstract) base Clone() and have every derived override with a Clone() { return new WhateverIAm() }

Maybe I am wrong, but I don't see the advantage of using reflection here. Reflection is a powerful tool, but should not be overused.

if (base.OpenFile<NeuropixelsV2eProbeGroup>())
{
ProbeConfiguration = new((NeuropixelsV2eProbeGroup)ProbeGroup, ProbeConfiguration.Reference, ProbeConfiguration.Probe);
MethodInfo method = GetType().GetMethod(
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are several things about this method that I believe warrant some justification:

  • It is a bool OpenFile<T>(). Why is it generic if the T is not used anywhere?

  • What makes this fundamentally different from the base dialog openfile? Either is generic or not, but this seems a weird combination

  • Why all the reflection stuff?

    • is 100% needed that the call to OpenAndParseConfigurationFile is done with the parent type
    • Even if it is, it is easier to just do
    dynamic probeGroupObj = ProbeGroup; //probeGroupObj  will be of the derived type
    OpenAndParseConfigurationFile(probeGroupObj); 
    

    In any case, I tried to go down the rabbit hole of this method, and I believe it starts to get too complex with generics at some point.
    I believe the objective of all this chain of generic is to be able to call

    var obj = JsonConvert.DeserializeObject<T>(jsonString, serializerSettings);

    But, would it not be easier to at some point call the methods with a Type argument, use the object? JsonConvert.DeserializeObject(string value, Type? type, JsonSerializerSettings? settings) overload and then cast to whatever you need?

    So at some point you can break the generic chain and just do something like OpenAndParseConfigurationFile(T.GetType()) in some places and OpenAndParseConfigurationFile(GetType()) here for example

[Browsable(false)]
[Externalizable(false)]
[XmlElement(nameof(ProbeGroup))]
public override string ProbeGroupString
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this not collide with the other PR to get json out of the xml?
I suppose it's an interim solution...

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