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

[MRG] Add name parameter to tonic bias and add tonic biases to different sections #922

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7e43655
tonic bias options
katduecker Jul 9, 2024
8471d4d
update defaults
katduecker Sep 17, 2024
82756c9
describe new parameters
katduecker Oct 27, 2024
52c00fe
stop tracking arm64
katduecker Oct 27, 2024
29a9a24
flake8
katduecker Oct 27, 2024
0c54729
unit tests
katduecker Oct 29, 2024
bebfaba
change sect_name to section for consistency
katduecker Oct 29, 2024
2d3154f
change sect_name to section for consistency test_gui
katduecker Oct 29, 2024
161c402
workaround backwards compatibility
katduecker Oct 29, 2024
fe03432
change CSD back
katduecker Oct 29, 2024
b8e1530
add deprecation warning
katduecker Oct 29, 2024
8215226
fix typos
katduecker Oct 29, 2024
1fc36a3
unit tests
katduecker Oct 29, 2024
fd44180
clean up section warning
katduecker Oct 29, 2024
73cc766
refactor: changed the default value from None to 'soma'
gtdang Nov 4, 2024
2303f0b
chore: updated test asset with section attributes in external_biases
gtdang Nov 4, 2024
0e2fbf8
chore: removed 'section' from ignore_keys in test_gui.check_equal_net…
gtdang Nov 4, 2024
a411607
Merge pull request #1 from brown-ccv/tonic_bias_sections
katduecker Nov 4, 2024
c62eb8d
fix test
katduecker Nov 4, 2024
75164d8
add bias_name test
katduecker Nov 4, 2024
e1f5c66
update value error
katduecker Nov 4, 2024
321f589
fix regex test
katduecker Nov 5, 2024
22722ad
Update hnn_core/tests/test_network.py
katduecker Nov 7, 2024
7ebe6b3
Update hnn_core/tests/test_network.py
katduecker Nov 7, 2024
0d015c8
Update hnn_core/tests/test_network.py
katduecker Nov 7, 2024
957f3bd
Update hnn_core/network.py
katduecker Nov 7, 2024
d9ea104
Update hnn_core/network.py
katduecker Nov 7, 2024
403339b
update whats_new and fix flake8
katduecker Nov 7, 2024
0e0edf7
update whats_new
katduecker Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions hnn_core/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,9 @@ def _insert_dipole(self, sec_name_apical):
dpp.ztan = seg_lens_z[-1]
self.dipole = h.Vector().record(self.dpl_ref)

def create_tonic_bias(self, amplitude, t0, tstop, loc=0.5):
"""Create tonic bias at the soma.
def create_tonic_bias(self, amplitude, t0, tstop, section='soma',
loc=0.5):
katduecker marked this conversation as resolved.
Show resolved Hide resolved
"""Create tonic bias at defined section.

Parameters
----------
Expand All @@ -739,10 +740,13 @@ def create_tonic_bias(self, amplitude, t0, tstop, loc=0.5):
The start time of tonic input (in ms).
tstop : float
The end time of tonic input (in ms).
section : str
Section tonic input is applied to.
loc : float (0 to 1)
The location of the input in the soma section.
The location of the input in the section.
"""
stim = h.IClamp(self._nrn_sections['soma'](loc))

stim = h.IClamp(self._nrn_sections[section](loc))
stim.delay = t0
stim.dur = tstop - t0
stim.amp = amplitude
Expand Down
1 change: 1 addition & 0 deletions hnn_core/cells_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def pyramidal_ca(cell_name, pos, override_params=None, gid=None):
override_params['L5Pyr_dend_gbar_ca'] = gbar_ca
override_params['L5Pyr_dend_gnabar_hh2'] = gbar_na
override_params['L5Pyr_dend_gkbar_hh2'] = gbar_k
override_params['L5Pyr_soma_gbar_ca'] = 10.
katduecker marked this conversation as resolved.
Show resolved Hide resolved

cell = pyramidal(cell_name, pos, override_params=override_params,
gid=gid)
Expand Down
39 changes: 32 additions & 7 deletions hnn_core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,8 @@ def _instantiate_drives(self, tstop, n_trials=1):
self.external_drives[
drive['name']]['events'].append(event_times)

def add_tonic_bias(self, *, cell_type=None, amplitude, t0=0, tstop=None):
def add_tonic_bias(self, *, cell_type=None, section=None,
bias_name='tonic', amplitude, t0=0, tstop=None):
katduecker marked this conversation as resolved.
Show resolved Hide resolved
"""Attaches parameters of tonic bias input for given cell types

Parameters
Expand All @@ -1142,6 +1143,10 @@ def add_tonic_bias(self, *, cell_type=None, amplitude, t0=0, tstop=None):
The name of the cell type to add a tonic input. When supplied,
a float value must be provided with the `amplitude` keyword.
Valid inputs are those listed in `net.cell_types`.
section : str | None
section the bias should be applied to.
katduecker marked this conversation as resolved.
Show resolved Hide resolved
bias_name : str | 'tonic'
katduecker marked this conversation as resolved.
Show resolved Hide resolved
The name of the bias.
amplitude: dict | float
A dictionary of cell type keys (str) to amplitude values (float).
Valid inputs for cell types are those listed in `net.cell_types`.
Expand Down Expand Up @@ -1169,6 +1174,7 @@ def add_tonic_bias(self, *, cell_type=None, amplitude, t0=0, tstop=None):
_validate_type(amplitude, (float, int), 'amplitude')

_add_cell_type_bias(network=self, cell_type=cell_type,
section=section, bias_name=bias_name,
amplitude=float(amplitude),
t_0=t0, t_stop=tstop)
else:
Expand All @@ -1180,6 +1186,7 @@ def add_tonic_bias(self, *, cell_type=None, amplitude, t0=0, tstop=None):

for _cell_type, _amplitude in amplitude.items():
_add_cell_type_bias(network=self, cell_type=_cell_type,
section=section, bias_name=bias_name,
amplitude=_amplitude,
t_0=t0, t_stop=tstop)

Expand Down Expand Up @@ -1648,7 +1655,7 @@ def __repr__(self):


def _add_cell_type_bias(network: Network, amplitude: Union[float, dict],
cell_type=None,
cell_type=None, section=None, bias_name='tonic',
t_0=0, t_stop=None):

if network is None:
Expand All @@ -1665,15 +1672,33 @@ def _add_cell_type_bias(network: Network, amplitude: Union[float, dict],
f'{list(network.cell_types.keys())}. '
f'Got {cell_type}')

if 'tonic' not in network.external_biases:
network.external_biases['tonic'] = dict()
if bias_name not in network.external_biases:
network.external_biases[bias_name] = dict()

if cell_type in network.external_biases['tonic']:
raise ValueError(f'Tonic bias already defined for {cell_type}')
if cell_type in network.external_biases[bias_name]:
raise ValueError(f'Bias named {bias_name} already defined '
f'for {cell_type}')
katduecker marked this conversation as resolved.
Show resolved Hide resolved

cell_type_bias = {
'amplitude': amplitude,
't0': t_0,
'tstop': t_stop
}
network.external_biases['tonic'][cell_type] = cell_type_bias

sections = list(network.cell_types[cell_type].sections.keys())

# Ensures backwards compatibility with existing json
# files (see test_read_configuration_json in test_io.py)
if section is None:
warnings.warn("Section for tonic bias is not defined."
"Defaulting to 'soma'.",
DeprecationWarning, stacklevel=1)
katduecker marked this conversation as resolved.
Show resolved Hide resolved
# error when section is defined that doesn't exist.
elif section not in sections:
raise ValueError(f'section must be an existing '
f'section of the current cell or None. '
f'Got {section}.')
else:
cell_type_bias['section'] = section
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is it defaulting to soma?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I realize now that it just doesn't add 'section' to the cell_type_bias dictionary and the Cell.create_tonic_bias will eventually use 'soma' as a default. I feel like that behavior is obtuse. Is it possible to bring the defaults higher-level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See above, it's because of test_read_configuration_json

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Resolved in developer meeting. We ended up regenerating the jones2009_3x3_drives.json file so that it contains section. The user will not be affected by this change if they don't define a section.


network.external_biases[bias_name][cell_type] = cell_type_bias
8 changes: 4 additions & 4 deletions hnn_core/network_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ def _create_cells_and_drives(self, threshold, record_vsec=False,
else:
cell.build()
# add tonic biases
if ('tonic' in self.net.external_biases and
src_type in self.net.external_biases['tonic']):
cell.create_tonic_bias(**self.net.external_biases
['tonic'][src_type])
for bias in self.net.external_biases:
if src_type in self.net.external_biases[bias]:
cell.create_tonic_bias(**self.net.external_biases
[bias][src_type])
cell.record(record_vsec, record_isec, record_ca)

# this call could belong in init of a _Cell (with threshold)?
Expand Down
3 changes: 2 additions & 1 deletion hnn_core/tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def check_drive(drive1, drive2, keys):
for cell_type, bias_params in bias_dict.items():
check_items(bias_params,
net2.external_biases[bias_name][cell_type],
ignore_keys=['tstop'],
# OK to ignore section here?
ignore_keys=['tstop', 'section'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll have to update the GUI for this tonic bias API change. I think what would make the most sense is creating a side branch for "multiple_tonics". We'll merge this PR into that branch and then add a second PR with the GUI changes. Once both are combined and working, we can merge it into main. Thoughts @asoplata @jasmainak @ntolley @dylansdaniels ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

is the multiple tonic feature required in the GUI? In any case, I think it could be a follow-up PR ... wouldn't make side branches, it makes for more complicated workflows

Copy link
Collaborator

Choose a reason for hiding this comment

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

If someone tired to load a network configuration file with multiple tonics it wouldn't work. I'm not exactly sure what would happen but I think there are checks to make sure that only one tonic is allowed and it must be named a certain way.

message=f'{bias_name}>{cell_type}>')

# Check all other attributes
Expand Down
19 changes: 18 additions & 1 deletion hnn_core/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ def test_add_cell_type():


def test_tonic_biases():

katduecker marked this conversation as resolved.
Show resolved Hide resolved
"""Test tonic biases."""
hnn_core_root = op.dirname(hnn_core.__file__)

Expand Down Expand Up @@ -855,9 +856,25 @@ def test_tonic_biases():
assert 'tonic' in net.external_biases
assert 'L5_pyramidal' not in net.external_biases['tonic']
assert net.external_biases['tonic']['L2_pyramidal']['t0'] == 0
with pytest.raises(ValueError, match=r'Tonic bias already defined for.*$'):
with pytest.raises(ValueError, match=r'Bias named tonic already defined '
r'for.*$'):
net.add_tonic_bias(amplitude=tonic_bias_2)

# non-existent section
net.external_biases = dict()

with pytest.raises(ValueError, match=r'section must be an existing '
katduecker marked this conversation as resolved.
Show resolved Hide resolved
r'section of the current cell or None. '
r'Got apical_4.'):
net.add_tonic_bias(amplitude={'L2_pyramidal': .5}, section='apical_4')
katduecker marked this conversation as resolved.
Show resolved Hide resolved

# deprecation warning when section not defined
net.external_biases = dict()
with pytest.warns(DeprecationWarning,
match=r"Section for tonic bias is not defined."
r"Defaulting to 'soma'."):
net.add_tonic_bias(amplitude={'L2_pyramidal': .5})


def test_network_mesh():
"""Test mesh for defining cell positions biases."""
Expand Down
Loading