From 94a062adc55308b9ae87366fc9dbdd375c6b9c19 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:07:39 -0400 Subject: [PATCH 01/11] tests: update tests for read and write configurations --- hnn_core/tests/test_io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hnn_core/tests/test_io.py b/hnn_core/tests/test_io.py index 7a894c67e..2bf208025 100644 --- a/hnn_core/tests/test_io.py +++ b/hnn_core/tests/test_io.py @@ -215,7 +215,7 @@ def test_cell_response_to_dict(jones_2009_network): result2 = _cell_response_to_dict(net, write_output=True) assert bool(result2) and isinstance(result2, dict) - # Check for None if kw supplied + # Check for empty dict if kw supplied result3 = _cell_response_to_dict(net, write_output=False) assert result3 == dict() From 4effcc7ed6ffd57ac4498a29485d3a52093237ee Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Wed, 1 May 2024 14:22:33 -0400 Subject: [PATCH 02/11] feat!: changed convert_to_hdf5 to convert_to_json --- hnn_core/__init__.py | 4 ++-- hnn_core/params.py | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/hnn_core/__init__.py b/hnn_core/__init__.py index f560eaa4e..876d9d2df 100644 --- a/hnn_core/__init__.py +++ b/hnn_core/__init__.py @@ -1,5 +1,5 @@ -from .dipole import simulate_dipole, read_dipole, average_dipoles, Dipole -from .params import Params, read_params, convert_to_hdf5 +from .dipole import simulate_dipole, read_dipole, average_dipoles, Dipole,_read_dipole_txt +from .params import Params, read_params, convert_to_json from .network import Network, pick_connection from .network_models import jones_2009_model, law_2021_model, calcium_model from .cell import Cell diff --git a/hnn_core/params.py b/hnn_core/params.py index 6f26fe2cb..d28385aae 100644 --- a/hnn_core/params.py +++ b/hnn_core/params.py @@ -662,9 +662,9 @@ def compare_dictionaries(d1, d2): return d1 -def convert_to_hdf5(params_fname, out_fname, include_drives=True, - overwrite=True, write_output=False): - """Converts json or param format to hdf5 +def convert_to_json(params_fname, out_fname, include_drives=True, + overwrite=True): + """Converts legacy json or param format to hierarchical json format Parameters ---------- @@ -676,8 +676,6 @@ def convert_to_hdf5(params_fname, out_fname, include_drives=True, Include drives from params file overwrite: bool, default=True Overwrite file - write_output: bool, default=False - Write out simulations Returns ------- None @@ -692,17 +690,16 @@ def convert_to_hdf5(params_fname, out_fname, include_drives=True, params_suffix = params_fname.suffix.lower().split('.')[-1] # Add suffix if not supplied - if out_fname.suffix != '.hdf5': - out_fname = out_fname.with_suffix('.hdf5') + if out_fname.suffix != '.json': + out_fname = out_fname.with_suffix('.json') net = Network(params=read_params(params_fname), add_drives_from_params=include_drives, legacy_mode=True if params_suffix == 'param' else False, ) - net.write(fname=out_fname, - overwrite=overwrite, - write_output=write_output, - ) + net.write_configuration(fname=out_fname, + overwrite=overwrite, + ) return From f91b6994d600d3522cbad7b754cba52e6010bd15 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Wed, 1 May 2024 14:23:24 -0400 Subject: [PATCH 03/11] feat: update convert_params.py to use convert_to_json --- dev_scripts/convert_params.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/dev_scripts/convert_params.py b/dev_scripts/convert_params.py index 979146dce..9f52d0331 100644 --- a/dev_scripts/convert_params.py +++ b/dev_scripts/convert_params.py @@ -10,7 +10,9 @@ from pathlib import Path from requests.exceptions import HTTPError -from hnn_core import convert_to_hdf5 +from hnn_core import convert_to_json + +root_path = Path(__file__).parents[1] def download_folder_contents(owner, repo, path): @@ -49,7 +51,7 @@ def download_folder_contents(owner, repo, path): return temp_dir -def convert_param_files_from_repo(owner, repo, path): +def convert_param_files_from_repo(owner, repo, repo_path, local_path): """Converts param and json parameter files to a hdf5 file. Parameters @@ -66,17 +68,19 @@ def convert_param_files_from_repo(owner, repo, path): None """ # Download param files - temp_dir = download_folder_contents(owner, repo, path) + temp_dir = download_folder_contents(owner, repo, repo_path) # Get list of json and param files file_list = [Path(temp_dir, f) for f in os.listdir(temp_dir) if f.endswith('.param') or f.endswith('.json')] # Assign output location and names - output_dir = Path(__file__).parents[1] / 'hnn_core' / 'param' + output_dir = Path(local_path) + if not os.path.exists(output_dir): + os.makedirs(output_dir) output_filenames = [Path(output_dir, f.name.split('.')[0]) for f in file_list] - [convert_to_hdf5(file, outfile) + [convert_to_json(file, outfile) for (file, outfile) in zip(file_list, output_filenames)] # Delete downloads @@ -88,8 +92,14 @@ def convert_param_files_from_repo(owner, repo, path): # hnn param files convert_param_files_from_repo(owner='jonescompneurolab', repo='hnn', - path='param') + repo_path='param', + local_path=(root_path / + 'network_configuration'), + ) # hnn-core json files convert_param_files_from_repo(owner='jonescompneurolab', repo='hnn-core', - path='hnn_core/param') + repo_path='hnn_core/param', + local_path=(root_path / + 'network_configuration'), + ) From 945b879e1834048bcb7c09e58a99f5fd54ad7a6f Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Wed, 1 May 2024 14:24:47 -0400 Subject: [PATCH 04/11] tests: update tests for convert_to_json --- hnn_core/tests/test_params.py | 66 +++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/hnn_core/tests/test_params.py b/hnn_core/tests/test_params.py index 8b767ebff..bc272cde0 100644 --- a/hnn_core/tests/test_params.py +++ b/hnn_core/tests/test_params.py @@ -8,7 +8,10 @@ import pytest -from hnn_core import read_params, Params, jones_2009_model, convert_to_hdf5 +from hnn_core import (read_params, Params, jones_2009_model, convert_to_json, + Network) +from hnn_core.hnn_io import read_network_configuration + hnn_core_root = Path(__file__).parents[1] @@ -74,8 +77,59 @@ def test_base_params(): assert params == params_base -def test_convert_to_hdf5_bad_type(): - """Tests type validation in convert_to_hdf5 function""" +def test_convert_to_json(tmp_path): + """Tests conversion of a flat json file to hierarchical json""" + # Download params + param_url = ('https://raw.githubusercontent.com/hnn-core/' + 'hnn_core/param/default.json') + params_base_fname = Path(hnn_core_root, 'param', 'default.json') + if not op.exists(params_base_fname): + urlretrieve(param_url, params_base_fname) + net_params = Network(read_params(params_base_fname), + add_drives_from_params=True, + ) + + # Write hdf5 and check if constructed network is equal + outpath = Path(tmp_path, 'default.json') + convert_to_json(params_base_fname, outpath) + net_hjson = read_network_configuration(outpath) + assert net_hjson == net_params + + # Write hdf5 without drives + outpath_no_drives = Path(tmp_path, 'default_no_drives.json') + convert_to_json(params_base_fname, outpath_no_drives, include_drives=False) + net_hjson_no_drives = read_network_configuration(outpath_no_drives) + assert net_hjson_no_drives != net_hjson + assert bool(net_hjson_no_drives.external_drives) is False + + # Check that writing with no extension will add one + outpath_no_ext = Path(tmp_path, 'default_no_ext') + convert_to_json(params_base_fname, outpath_no_ext) + assert outpath_no_ext.with_suffix('.json').exists() + + +def test_convert_to_hdf5_legacy(tmp_path): + """Tests conversion of a param legacy file to hdf5""" + # Download params + param_url = ('https://raw.githubusercontent.com/hnnsolver/' + 'hnn-core/test_data/default.param') + params_base_fname = Path(hnn_core_root, 'param', 'default.param') + if not op.exists(params_base_fname): + urlretrieve(param_url, params_base_fname) + net_params = Network(read_params(params_base_fname), + add_drives_from_params=True, + legacy_mode=True + ) + + # Write hdf5 and check if constructed network is equal + outpath = Path(tmp_path, 'default.json') + convert_to_json(params_base_fname, outpath) + net_hdf5 = read_network_configuration(outpath) + assert net_hdf5 == net_params + + +def test_convert_to_json_bad_type(): + """Tests type validation in convert_to_json function""" good_path = hnn_core_root path_str = str(good_path) bad_path = 5 @@ -85,18 +139,18 @@ def test_convert_to_hdf5_bad_type(): ValueError, match="Unrecognized extension, expected one of" ): - convert_to_hdf5(good_path, path_str) + convert_to_json(good_path, path_str) # Bad params_fname with pytest.raises( TypeError, match="params_fname must be an instance of str or Path" ): - convert_to_hdf5(bad_path, good_path) + convert_to_json(bad_path, good_path) # Bad out_fname with pytest.raises( TypeError, match="out_fname must be an instance of str or Path" ): - convert_to_hdf5(good_path, bad_path) + convert_to_json(good_path, bad_path) From 4231bcaa8fed8892d7202eed65ad5425f512c272 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Thu, 16 May 2024 17:52:02 -0400 Subject: [PATCH 05/11] feat: Added network_connectivity argument to convert_to_json to add pre-defined network connectivity models in the conversion. --- hnn_core/params.py | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/hnn_core/params.py b/hnn_core/params.py index d28385aae..8082a243a 100644 --- a/hnn_core/params.py +++ b/hnn_core/params.py @@ -662,7 +662,10 @@ def compare_dictionaries(d1, d2): return d1 -def convert_to_json(params_fname, out_fname, include_drives=True, +def convert_to_json(params_fname, + out_fname, + network_connectivity='jones_2009_model', + include_drives=True, overwrite=True): """Converts legacy json or param format to hierarchical json format @@ -672,6 +675,11 @@ def convert_to_json(params_fname, out_fname, include_drives=True, Path to file out_fname: str Path to output + network_connectivity: str or None, default:' jones_2009_model' + Options: ['jones_2009_model', 'law_2021_model', 'calcium_model', None] + Neocortical network model to use. Models are defined in network_models. + If None, the base Network object with no defined network connectivity + will be used. include_drives: bool, default=True Include drives from params file overwrite: bool, default=True @@ -681,6 +689,23 @@ def convert_to_json(params_fname, out_fname, include_drives=True, None """ from .network import Network + from .network_models import jones_2009_model, law_2021_model, calcium_model + + # Assign network model callables + model_functions = {'jones_2009_model': jones_2009_model, + 'law_2021_model': law_2021_model, + 'calcium_model': calcium_model + } + if network_connectivity: + try: + network_model = model_functions[network_connectivity] + except KeyError: + raise KeyError(f'Invalid network connectivity: ' + f'"{network_connectivity}"; ' + f'Valid options: {list(model_functions.keys())}') + else: + network_model = Network + # Validate inputs _validate_type(params_fname, (str, Path), 'params_fname') _validate_type(out_fname, (str, Path), 'out_fname') @@ -693,10 +718,12 @@ def convert_to_json(params_fname, out_fname, include_drives=True, if out_fname.suffix != '.json': out_fname = out_fname.with_suffix('.json') - net = Network(params=read_params(params_fname), - add_drives_from_params=include_drives, - legacy_mode=True if params_suffix == 'param' else False, - ) + net = network_model(params=read_params(params_fname), + add_drives_from_params=include_drives, + legacy_mode=(True if params_suffix == 'param' + else False), + ) + net.write_configuration(fname=out_fname, overwrite=overwrite, ) From 65c7ce0d59d8eb11d4e4ab6715efee51ff31e95b Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Thu, 16 May 2024 17:52:41 -0400 Subject: [PATCH 06/11] test: Updated and refactored convert_to_json tests. --- hnn_core/tests/test_params.py | 218 ++++++++++++++++++++++------------ 1 file changed, 140 insertions(+), 78 deletions(-) diff --git a/hnn_core/tests/test_params.py b/hnn_core/tests/test_params.py index bc272cde0..5923cb379 100644 --- a/hnn_core/tests/test_params.py +++ b/hnn_core/tests/test_params.py @@ -8,9 +8,11 @@ import pytest -from hnn_core import (read_params, Params, jones_2009_model, convert_to_json, +from hnn_core import (read_params, Params, convert_to_json, Network) from hnn_core.hnn_io import read_network_configuration +from hnn_core.network_models import (jones_2009_model, law_2021_model, + calcium_model) hnn_core_root = Path(__file__).parents[1] @@ -77,80 +79,140 @@ def test_base_params(): assert params == params_base -def test_convert_to_json(tmp_path): - """Tests conversion of a flat json file to hierarchical json""" - # Download params - param_url = ('https://raw.githubusercontent.com/hnn-core/' - 'hnn_core/param/default.json') - params_base_fname = Path(hnn_core_root, 'param', 'default.json') - if not op.exists(params_base_fname): - urlretrieve(param_url, params_base_fname) - net_params = Network(read_params(params_base_fname), - add_drives_from_params=True, - ) - - # Write hdf5 and check if constructed network is equal - outpath = Path(tmp_path, 'default.json') - convert_to_json(params_base_fname, outpath) - net_hjson = read_network_configuration(outpath) - assert net_hjson == net_params - - # Write hdf5 without drives - outpath_no_drives = Path(tmp_path, 'default_no_drives.json') - convert_to_json(params_base_fname, outpath_no_drives, include_drives=False) - net_hjson_no_drives = read_network_configuration(outpath_no_drives) - assert net_hjson_no_drives != net_hjson - assert bool(net_hjson_no_drives.external_drives) is False - - # Check that writing with no extension will add one - outpath_no_ext = Path(tmp_path, 'default_no_ext') - convert_to_json(params_base_fname, outpath_no_ext) - assert outpath_no_ext.with_suffix('.json').exists() - - -def test_convert_to_hdf5_legacy(tmp_path): - """Tests conversion of a param legacy file to hdf5""" - # Download params - param_url = ('https://raw.githubusercontent.com/hnnsolver/' - 'hnn-core/test_data/default.param') - params_base_fname = Path(hnn_core_root, 'param', 'default.param') - if not op.exists(params_base_fname): - urlretrieve(param_url, params_base_fname) - net_params = Network(read_params(params_base_fname), - add_drives_from_params=True, - legacy_mode=True - ) - - # Write hdf5 and check if constructed network is equal - outpath = Path(tmp_path, 'default.json') - convert_to_json(params_base_fname, outpath) - net_hdf5 = read_network_configuration(outpath) - assert net_hdf5 == net_params - - -def test_convert_to_json_bad_type(): - """Tests type validation in convert_to_json function""" - good_path = hnn_core_root - path_str = str(good_path) - bad_path = 5 - - # Valid path and string, but not actual files - with pytest.raises( - ValueError, - match="Unrecognized extension, expected one of" - ): - convert_to_json(good_path, path_str) - - # Bad params_fname - with pytest.raises( - TypeError, - match="params_fname must be an instance of str or Path" - ): - convert_to_json(bad_path, good_path) - - # Bad out_fname - with pytest.raises( - TypeError, - match="out_fname must be an instance of str or Path" - ): - convert_to_json(good_path, bad_path) +class TestConvertToJson: + """Tests convert_to_json function""" + + path_default = Path(hnn_core_root, 'param', 'default.json') + + def test_default_network_connectivity(self, tmp_path): + """Tests conversion with default parameters""" + + net_params = jones_2009_model(params=read_params(self.path_default), + add_drives_from_params=True) + + # Write json and check if constructed network is equal + outpath = Path(tmp_path, 'default.json') + convert_to_json(self.path_default, + outpath + ) + net_json = read_network_configuration(outpath) + assert net_json == net_params + + # Write json without drives + outpath_no_drives = Path(tmp_path, 'default_no_drives.json') + convert_to_json(self.path_default, + outpath_no_drives, + include_drives=False + ) + net_json_no_drives = read_network_configuration(outpath_no_drives) + assert net_json_no_drives != net_json + assert bool(net_json_no_drives.external_drives) is False + + # Check that writing with no extension will add one + outpath_no_ext = Path(tmp_path, 'default_no_ext') + convert_to_json(self.path_default, + outpath_no_ext + ) + assert outpath_no_ext.with_suffix('.json').exists() + + def test_law_network_connectivity(self, tmp_path): + """Tests conversion with Law 2021 network connectivity model""" + + net_params = law_2021_model(read_params(self.path_default), + add_drives_from_params=True, + ) + + # Write json and check if constructed network is equal + outpath = Path(tmp_path, 'default.json') + convert_to_json(self.path_default, + outpath, + network_connectivity='law_2021_model') + net_json = read_network_configuration(outpath) + assert net_json == net_params + + def test_calcium_network_connectivity(self, tmp_path): + """Tests conversion with calcium network connectivity model""" + + net_params = calcium_model(read_params(self.path_default), + add_drives_from_params=True, + ) + + # Write json and check if constructed network is equal + outpath = Path(tmp_path, 'default.json') + convert_to_json(self.path_default, + outpath, + network_connectivity='calcium_model') + net_json = read_network_configuration(outpath) + assert net_json == net_params + + def test_no_network_connectivity(self, tmp_path): + """Tests conversion with no network connectivity model""" + + net_params = Network(read_params(self.path_default), + add_drives_from_params=True, + ) + + # Write json and check if constructed network is equal + outpath = Path(tmp_path, 'default.json') + convert_to_json(self.path_default, + outpath, + network_connectivity=None) + net_json = read_network_configuration(outpath) + assert net_json == net_params + + def test_convert_to_json_legacy(self, tmp_path): + """Tests conversion of a param legacy file to json""" + + # Download params + param_url = ('https://raw.githubusercontent.com/hnnsolver/' + 'hnn-core/test_data/default.param') + params_base_fname = Path(hnn_core_root, 'param', 'default.param') + if not op.exists(params_base_fname): + urlretrieve(param_url, params_base_fname) + net_params = jones_2009_model(read_params(params_base_fname), + add_drives_from_params=True, + legacy_mode=True + ) + + # Write json and check if constructed network is equal + outpath = Path(tmp_path, 'default.json') + convert_to_json(params_base_fname, outpath) + net_json = read_network_configuration(outpath) + assert net_json == net_params + + def test_convert_to_json_bad_type(self): + """Tests type validation in convert_to_json function""" + + good_path = hnn_core_root + path_str = str(good_path) + bad_path = 5 + bad_network_conn = 'bad_model' + + # Valid path and string, but not actual files + with pytest.raises( + ValueError, + match="Unrecognized extension, expected one of" + ): + convert_to_json(good_path, path_str) + + # Bad params_fname + with pytest.raises( + TypeError, + match="params_fname must be an instance of str or Path" + ): + convert_to_json(bad_path, good_path) + + # Bad out_fname + with pytest.raises( + TypeError, + match="out_fname must be an instance of str or Path" + ): + convert_to_json(good_path, bad_path) + + # Bad network_connectivity + with pytest.raises( + KeyError, + match="Invalid network connectivity:" + ): + convert_to_json(good_path, good_path, + network_connectivity=bad_network_conn) From ba1a96f3ca3a702ac7a99d900174e43da50a8058 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Thu, 16 May 2024 17:58:20 -0400 Subject: [PATCH 07/11] docs: Updated whats_new.rst --- doc/whats_new.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 2b86badcb..9cb40926e 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -29,9 +29,6 @@ Changelog - Add ability to specify number of cells in :class:`~hnn_core.Network`, by `Nick Tolley`_ in :gh:`705` - -- Add feature to convert param and json files to HDF5 format, by `George Dang`_ - in :gh:`723` - Fixed figure annotation overlap in multiple sub-plots, by `Camilo Diaz`_ in :gh:`741` @@ -61,13 +58,16 @@ Changelog - Added :class:`~hnn_core/viz/NetworkPlotter` to visualize and animate network simulations, by `Nick Tolley`_ in :gh:`649`. -- Added GUI feature to include Tonic input drives in simulations, +- Added GUI feature to include Tonic input drives in simulations, by `Camilo Diaz` :gh:`773` -- :func:`~plot_laminar_lfp`, :func:`~plot_dipole`, :func:`~plot_spikes_hist`, +- :func:`~plot_laminar_lfp`, :func:`~plot_dipole`, :func:`~plot_spikes_hist`, and :func:`~plot_spikes_raster` now plotted from 0 to tstop. Inputs tmin and tmax are deprecated, by `Katharina Duecker`_ in :gh:`769` +- Add feature to convert legacy param and json files to new json format, + by `George Dang`_ in :gh:`772` + Bug ~~~ - Fix inconsistent connection mapping from drive gids to cell gids, by From 0bf246c99fb049836f78fc4608037909fbd601ec Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Thu, 16 May 2024 18:03:40 -0400 Subject: [PATCH 08/11] docs: Reformated docstring. --- hnn_core/params.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hnn_core/params.py b/hnn_core/params.py index 8082a243a..22f8f3583 100644 --- a/hnn_core/params.py +++ b/hnn_core/params.py @@ -677,9 +677,9 @@ def convert_to_json(params_fname, Path to output network_connectivity: str or None, default:' jones_2009_model' Options: ['jones_2009_model', 'law_2021_model', 'calcium_model', None] - Neocortical network model to use. Models are defined in network_models. - If None, the base Network object with no defined network connectivity - will be used. + Neocortical network model to use. Models are defined in + network_models. If None, the base Network object with no defined + network connectivity will be used. include_drives: bool, default=True Include drives from params file overwrite: bool, default=True From b4d565d5294846eecee32ddf1312d901551f5158 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Mon, 20 May 2024 15:03:03 -0400 Subject: [PATCH 09/11] docs: Updated whats_new.rst with function link. --- doc/whats_new.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 9cb40926e..efe2486c5 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -65,8 +65,8 @@ Changelog and :func:`~plot_spikes_raster` now plotted from 0 to tstop. Inputs tmin and tmax are deprecated, by `Katharina Duecker`_ in :gh:`769` -- Add feature to convert legacy param and json files to new json format, - by `George Dang`_ in :gh:`772` +- Add function :func:`~hnn_core/params/convert_to_json` to convert legacy param + and json files to new json format, by `George Dang`_ in :gh:`772` Bug ~~~ From 16689fb20e65d0b3af2757b578d7192e55b976c6 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:18:10 -0400 Subject: [PATCH 10/11] refactor: update argument name from "network_connectivity" to "model_template" --- hnn_core/params.py | 10 +++++----- hnn_core/tests/test_params.py | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hnn_core/params.py b/hnn_core/params.py index 22f8f3583..b8bb5a600 100644 --- a/hnn_core/params.py +++ b/hnn_core/params.py @@ -664,7 +664,7 @@ def compare_dictionaries(d1, d2): def convert_to_json(params_fname, out_fname, - network_connectivity='jones_2009_model', + model_template='jones_2009_model', include_drives=True, overwrite=True): """Converts legacy json or param format to hierarchical json format @@ -675,7 +675,7 @@ def convert_to_json(params_fname, Path to file out_fname: str Path to output - network_connectivity: str or None, default:' jones_2009_model' + model_template: str or None, default:' jones_2009_model' Options: ['jones_2009_model', 'law_2021_model', 'calcium_model', None] Neocortical network model to use. Models are defined in network_models. If None, the base Network object with no defined @@ -696,12 +696,12 @@ def convert_to_json(params_fname, 'law_2021_model': law_2021_model, 'calcium_model': calcium_model } - if network_connectivity: + if model_template: try: - network_model = model_functions[network_connectivity] + network_model = model_functions[model_template] except KeyError: raise KeyError(f'Invalid network connectivity: ' - f'"{network_connectivity}"; ' + f'"{model_template}"; ' f'Valid options: {list(model_functions.keys())}') else: network_model = Network diff --git a/hnn_core/tests/test_params.py b/hnn_core/tests/test_params.py index 5923cb379..fcb53f1ec 100644 --- a/hnn_core/tests/test_params.py +++ b/hnn_core/tests/test_params.py @@ -126,7 +126,7 @@ def test_law_network_connectivity(self, tmp_path): outpath = Path(tmp_path, 'default.json') convert_to_json(self.path_default, outpath, - network_connectivity='law_2021_model') + model_template='law_2021_model') net_json = read_network_configuration(outpath) assert net_json == net_params @@ -141,7 +141,7 @@ def test_calcium_network_connectivity(self, tmp_path): outpath = Path(tmp_path, 'default.json') convert_to_json(self.path_default, outpath, - network_connectivity='calcium_model') + model_template='calcium_model') net_json = read_network_configuration(outpath) assert net_json == net_params @@ -156,7 +156,7 @@ def test_no_network_connectivity(self, tmp_path): outpath = Path(tmp_path, 'default.json') convert_to_json(self.path_default, outpath, - network_connectivity=None) + model_template=None) net_json = read_network_configuration(outpath) assert net_json == net_params @@ -186,7 +186,7 @@ def test_convert_to_json_bad_type(self): good_path = hnn_core_root path_str = str(good_path) bad_path = 5 - bad_network_conn = 'bad_model' + bad_model = 'bad_model' # Valid path and string, but not actual files with pytest.raises( @@ -209,10 +209,10 @@ def test_convert_to_json_bad_type(self): ): convert_to_json(good_path, bad_path) - # Bad network_connectivity + # Bad model_template with pytest.raises( KeyError, match="Invalid network connectivity:" ): convert_to_json(good_path, good_path, - network_connectivity=bad_network_conn) + model_template=bad_model) From 9509178a300d283cead3c0b8dcbb96b0ac6c7338 Mon Sep 17 00:00:00 2001 From: George Dang <53052793+gtdang@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:26:16 -0400 Subject: [PATCH 11/11] tests: Added connectivity length check --- hnn_core/tests/test_params.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hnn_core/tests/test_params.py b/hnn_core/tests/test_params.py index fcb53f1ec..e532bd009 100644 --- a/hnn_core/tests/test_params.py +++ b/hnn_core/tests/test_params.py @@ -159,6 +159,8 @@ def test_no_network_connectivity(self, tmp_path): model_template=None) net_json = read_network_configuration(outpath) assert net_json == net_params + # Should only have external drive connections defined, n=22 + assert len(net_json.connectivity) == len(net_params.connectivity) == 22 def test_convert_to_json_legacy(self, tmp_path): """Tests conversion of a param legacy file to json"""