Skip to content

Conversation

@Chetank99
Copy link
Contributor

Hey @asoplata

a very rough draft right now, will add docstrings, and ofcourse tests(!) later

this is in ref: #1128
for the "Cartesian product" of the elements
i set the sources as drives + cell types and for the targets, cell types only, as drives can't receive current? mentioned it as a temp comment in the code too

Added two new viz funcs for analyzing synaptic current dynamics in networks, sprinkled in the use of metadata here

  • plot_current_exchange(): matrix view of currents between all source-target pairs (drives + cells → cells)
  • plot_layer_comparison(): aggregates layer-wise current flow (L2/L5 + drives → L2/L5)

added a few helper functions for this

  • _aggregate_connection_currents(): aggregates synaptic currents by (src_type, target_type) pairs

  • _get_layer_groups(): extracts layer groups from metadata {maybe it need not be a seperate function, i can use it directly as code chunk in plot_layer_comparison too, used it as a style of helper functions like __lighten_color, __decimate_plot_data, etc, if there is scope for reuse in future funcs}

i followed the viz's function style to have Normalize option (0-1 scale or absolute), inspired from the existing plot_drive_strength function

I validated on Jones 2009 model with 3 drives (evdist1, evprox1, evprox2)

import matplotlib.pyplot as plt
from hnn_core import jones_2009_model, simulate_dipole
from hnn_core.viz import plot_current_exchange, plot_layer_comparison

net = jones_2009_model()

net.add_evoked_drive(
    "evdist1",
    mu=63.0,
    sigma=3.85,
    numspikes=1,
    location="distal",
    weights_ampa={"L2_pyramidal": 5.4e-5, "L5_pyramidal": 5.4e-4},
    synaptic_delays=0.1,
)

net.add_evoked_drive(
    "evprox1",
    mu=26.0,
    sigma=2.5,
    numspikes=1,
    location="proximal",
    weights_ampa={
        "L2_basket": 1.4e-4,
        "L2_pyramidal": 4.8e-5,
        "L5_basket": 1.9e-4,
        "L5_pyramidal": 7.9e-5,
    },
    synaptic_delays=0.1,
)

net.add_evoked_drive(
    "evprox2",
    mu=135.0,
    sigma=8.0,
    numspikes=1,
    location="proximal",
    weights_ampa={
        "L2_basket": 3.0e-6,
        "L2_pyramidal": 1.4,
        "L5_basket": 9.0e-3,
        "L5_pyramidal": 0.68,
    },
    synaptic_delays=0.1,
)

dpl = simulate_dipole(net, tstop=200.0, dt=0.5, record_isec="all", n_trials=1)

print("full current exchange matrix plot")
fig1 = plot_current_exchange(net, trial_idx=0, normalize=True, decim=5)

# absolute current
print(" layer comparison")
fig2 = plot_layer_comparison(net, trial_idx=0, normalize=False, decim=5)

# layer comparison as percentage
print("Creating percentage-based layer comparison...")
fig3 = plot_layer_comparison(net, trial_idx=0, normalize=True, decim=5)

plt.show()
image image image

@ntolley
Copy link
Collaborator

ntolley commented Dec 3, 2025

@Chetank99 this is super cool!! Really great visualization

i set the sources as drives + cell types and for the targets, cell types only, as drives can't receive current?

Yes that's correct, the drive "cells" are more or less a glorified list of event times

Something that is a little surprising to me from the plots shown, the evprox1 drive has a mean mu=26 ms, but in the plot it seems that all of the currents are increasing at 175 ms. Could either 1) indicate a bug, or 2) my intuition about when currents are increasing is flawed.

One thing that could potentially explain this, the current flow is actually dependent on the membrane potential. Current will only flow if the membrane potential is far from the nernst potential of the channel and the channel is open (i.e. increased conductance g). It could just be that the NMDA channels opened at 25 ms stay open for a really long time, but the swings in membrane potential produce a lot more current flow...

I'll check out the code and think about what would be a simple/intuitive simulation that would help illustrate this is working as intended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants