pyneuroml.io module#

Methods related to IO.

File: pyneuroml/io.py

Copyright 2024 NeuroML contributors

pyneuroml.io.confirm_file_exists(filename: str) None#

Check if a file exists, exit if it does not.

Parameters:

filename (str) – the filename to check

pyneuroml.io.confirm_lems_file(filename: str) None#

Confirm that file exists and is a LEMS file before proceeding with processing.

Parameters:

filename (list of strings) – Names of files to check

pyneuroml.io.confirm_neuroml_file(filename: str) None#

Confirm that file exists and is a NeuroML file before proceeding with processing.

Parameters:

filename (str) – Names of files to check

pyneuroml.io.read_lems_file(lems_file_name: str, include_includes: bool = False, fail_on_missing_includes: bool = False, debug: bool = False) Model#

Read LEMS file using PyLEMS. See WARNING below.

WARNING: this is a general function that uses PyLEMS to read any files that are valid LEMS even if they are not valid NeuroML. Therefore, this function is not aware of the standard NeuroML LEMS definitions.

To validate NeuroML LEMS files which need to be aware of the NeuroML standard LEMS definitions, please use the validate_neuroml2_lems_file function instead.

pyneuroml.io.read_neuroml2_file(nml2_file_name: str, include_includes: bool = False, verbose: bool = False, already_included: list | None = None, optimized: bool = False, check_validity_pre_include: bool = False) NeuroMLDocument#

Read a NeuroML2 file into a nml.NeuroMLDocument

Parameters:
  • nml2_file_name (str) – file of NeuroML 2 file to read

  • include_includes (bool) – toggle whether files included in NML file should also be included/read

  • verbose (bool) – toggle verbosity

  • already_included (list) – list of files already included

  • optimized (bool) – toggle whether the HDF5 loader should optimise the document

  • check_validity_pre_include (bool) – check each file for validity before including

Returns:

nml.NeuroMLDocument object containing the read NeuroML file(s)

pyneuroml.io.write_lems_file(lems_model: Model, lems_file_name: str, validate: bool = False) None#

Write a lems_model.Model to file using pyLEMS.

Parameters:
  • lems_model (lems_model.Model) – LEMS model to write to file

  • lems_file_name (str) – name of file to write to

  • validate (bool) – toggle whether written file should be validated

pyneuroml.io.write_neuroml2_file(nml2_doc: NeuroMLDocument, nml2_file_name: str, validate: bool = True, verbose_validate: bool = False, hdf5: bool = False) bool | Tuple[bool, str] | None#

Write a NeuroMLDocument object to a file using libNeuroML.

Parameters:
  • nml2_doc (NeuroMLDocument) – NeuroMLDocument object to write to file

  • nml2_file_name (str) – name of file to write to

  • validate (bool) – toggle whether the written file should be validated

  • verbose_validate (bool) – toggle whether the validation should be verbose

  • hdf5 (bool) – write to HDF5 file