Skip to content

Commit

Permalink
Merge pull request NeuroML#386 from NeuroML/feat/coverage
Browse files Browse the repository at this point in the history
Feat/coverage
  • Loading branch information
sanjayankur31 authored Jun 6, 2024
2 parents 357ec2c + 57f609b commit d993521
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 53 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,3 @@ jobs:
pynml -h
./test-ghactions.sh -neuron
- name: Lint with ruff
run: |
pip install ruff
ruff . --exit-zero --show-source
16 changes: 16 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Ruff
on:
pull_request:
branches:
- master
- development
- experimental
- 'test*'
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
with:
changed-files: 'true'
12 changes: 5 additions & 7 deletions pyneuroml/channelml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
Copyright 2023 NeuroML contributors
"""


import argparse
import logging
import typing
import pathlib
from lxml.etree import parse, XSLT, tostring
import typing
from typing import Optional

from lxml.etree import XSLT, parse, tostring

from pyneuroml.utils.cli import build_namespace
from typing import Optional


logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -53,7 +51,7 @@ def channelml2nml(
"""
try:
dom = parse(channelmlfile)
except:
except Exception:
logger.error(f"Cannot parse channelml file: {channelmlfile}")
return None
if not xsltfile:
Expand All @@ -62,7 +60,7 @@ def channelml2nml(

try:
xslt = parse(xsltfile)
except:
except Exception:
logger.error(f"Cannot parse XSL: {xsltfile}")
return None

Expand Down
19 changes: 9 additions & 10 deletions pyneuroml/lems/LEMSSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
Helper class for generating LEMS xml files for simulations
"""

import os.path
import logging
import typing
import random
import os
import os.path
import random
import typing
from typing import Optional

import airspeed
from pyneuroml import __version__ as pynml_ver
from neuroml import __version__ as libnml_ver
from pyneuroml.pynml import read_neuroml2_file
from pyneuroml.pynml import read_lems_file

from pyneuroml import __version__ as pynml_ver
from pyneuroml.pynml import read_lems_file, read_neuroml2_file
from pyneuroml.utils.plot import get_next_hex_color
from pyneuroml.utils.units import convert_to_units
from typing import Optional

logger = logging.getLogger(__name__)


class LEMSSimulation:

"""
Helper class for creating LEMS Simulations for running NeuroML2 models.
"""
Expand Down Expand Up @@ -88,7 +87,7 @@ def __init__(
:type meta: dict
"""

if type(duration) is str:
if isinstance(duration, str):
# is this just the magnitude in the string?
try:
duration_mag_ms = float(duration)
Expand All @@ -97,7 +96,7 @@ def __init__(
else:
duration_mag_ms = float(duration)

if type(dt) is str:
if isinstance(dt, str):
# is this just the magnitude in the string?
try:
dt_mag_ms = float(dt)
Expand Down
5 changes: 0 additions & 5 deletions pyneuroml/neuron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
import airspeed
import yaml

try:
from yaml import CDumper as Dumper
except ImportError:
from yaml import Dumper

from pyneuroml.pynml import validate_neuroml1, validate_neuroml2

pp = pprint.PrettyPrinter(depth=4)
Expand Down
9 changes: 5 additions & 4 deletions pyneuroml/plot/PlotTimeSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import typing

import numpy
import pyneuroml.lems as pynmll
import pyneuroml.plot.Plot as pynmlplt
from matplotlib import pyplot as plt
from matplotlib_scalebar.scalebar import ScaleBar

import pyneuroml.lems as pynmll
import pyneuroml.plot.Plot as pynmlplt
from pyneuroml.utils.cli import build_namespace

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -77,7 +78,7 @@ def plot_time_series(
:raises ValueError: if a 't' (time) key is not found in the traces data
"""
if type(trace_data) is dict:
if isinstance(trace_data, dict):
trace_data = [trace_data]

num_traces = 0
Expand Down Expand Up @@ -217,7 +218,7 @@ def plot_time_series_from_data_files(
"""
all_traces = []
if type(data_file_names) is str:
if isinstance(data_file_names, str):
data_file_names = [data_file_names]

for f in data_file_names:
Expand Down
16 changes: 9 additions & 7 deletions pyneuroml/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Copyright 2024 NeuroML contributors
"""


import inspect
import logging
import math
Expand Down Expand Up @@ -107,9 +106,12 @@ def run_lems_with_jneuroml(
return False

if load_saved_data:
if verbose: logger.info(
"Reloading data generated by: {}, plotting: {}".format(lems_file_name, plot)
)
if verbose:
logger.info(
"Reloading data generated by: {}, plotting: {}".format(
lems_file_name, plot
)
)
return reload_saved_data(
lems_file_name,
base_dir=exec_in_dir,
Expand Down Expand Up @@ -676,15 +678,15 @@ def _gui_string(nogui: bool) -> str:


def _include_string(
paths_to_include: typing.Union[str, typing.Tuple[str], typing.List[str]]
paths_to_include: typing.Union[str, typing.Tuple[str], typing.List[str]],
) -> str:
"""Convert a path or list of paths into an include string to be used by jnml.
:param paths_to_include: path or list or tuple of paths to be included
:type paths_to_include: str or list(str) or tuple(str)
:returns: include string to be used with jnml.
"""
if paths_to_include:
if type(paths_to_include) is str:
if isinstance(paths_to_include, str):
paths_to_include = [paths_to_include]
if type(paths_to_include) in (tuple, list):
result = " -I '%s'" % ":".join(paths_to_include)
Expand Down Expand Up @@ -847,7 +849,7 @@ def run_jneuroml_with_realtime_output(

except KeyboardInterrupt as e:
raise e
except:
except Exception:
logger.error("*** Execution of jnml has failed! ***")
logger.error("*** Command: %s ***" % command)
if exit_on_fail:
Expand Down
6 changes: 3 additions & 3 deletions pyneuroml/tellurium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
run a model using the tellurium engine
"""

import os
import logging
from pyneuroml.sedml import validate_sedml_files
import os

from pyneuroml.sedml import validate_sedml_files

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -51,7 +51,7 @@ def run_from_sedml_file(input_files, args):
if "-outputdir" in args:
try:
outputdir = args[args.index("-outputdir") + 1]
except:
except Exception:
raise ValueError("Incorrectly specified outputdir")

if outputdir == "none":
Expand Down
2 changes: 1 addition & 1 deletion pyneuroml/tune/NeuroMLTuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def _run_optimisation(a: argparse.Namespace) -> typing.Optional[dict]:
added = []
# print("Plotting saved data from %s which are relevant for targets: %s"%(best_candidate_v.keys(), a.target_data.keys()))

fig = plt.figure()
plt.figure()
plt.get_current_fig_manager().set_window_title(
"Simulation of fittest individual from run: %s" % ref
)
Expand Down
6 changes: 3 additions & 3 deletions pyneuroml/utils/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from matplotlib.lines import Line2D
from matplotlib.patches import Rectangle
from matplotlib_scalebar.scalebar import ScaleBar
from neuroml import Cell, NeuroMLDocument
from neuroml import Cell, NeuroMLDocument, Segment
from neuroml.loaders import read_neuroml2_file

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -317,9 +317,9 @@ def get_cell_bound_box(cell: Cell):
:returns: tuple (min view, max view)
"""
seg0 = cell.morphology.segments[0] # type: Segment
seg0: Segment = cell.morphology.segments[0]
ex1 = numpy.array([seg0.distal.x, seg0.distal.y, seg0.distal.z])
seg1 = cell.morphology.segments[-1] # type: Segment
seg1: Segment = cell.morphology.segments[-1]
ex2 = numpy.array([seg1.distal.x, seg1.distal.y, seg1.distal.z])
center = (ex1 + ex2) / 2
diff = numpy.linalg.norm(ex2 - ex1)
Expand Down
1 change: 0 additions & 1 deletion pyneuroml/xppaut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import argparse
import logging
import os
import sys
import typing
from pprint import pprint

Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ build-backend = "setuptools.build_meta"

[tool.ruff.lint]
ignore = ["F403", "F405"]

[tool.pytest.ini_options]
addopts = "--cov=pyneuroml"
markers = [
"localonly", # test to not be run on GH actions: they segfault.
]
3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

8 changes: 4 additions & 4 deletions tests/plot/test_PlotSpikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_plot_spikes_from_data_single(self):
pyplts.plot_spikes(
title=f"spikes from data - {data['name']}",
spike_data=[data],
show_plots_already=True,
show_plots_already=False,
save_spike_plot_to=f"spike-plot-test-{data['name']}.png",
)
self.assertIsFile(f"spike-plot-test-{data['name']}.png")
Expand All @@ -62,7 +62,7 @@ def test_plot_spikes_from_data_multi(self):
pyplts.plot_spikes(
title="spikes from data",
spike_data=self.spike_data,
show_plots_already=True,
show_plots_already=False,
save_spike_plot_to="spike-plot-test-multi.png",
)
self.assertIsFile("spike-plot-test-multi.png")
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_plot_spikes_from_files(self, max_spikes_per_population=100):
filelist,
format_="id_t",
title="spikes from data files",
show_plots_already=True,
show_plots_already=False,
save_spike_plot_to="spike-plot-from-file-test.png",
)

Expand Down Expand Up @@ -199,7 +199,7 @@ def test_plot_spikes_from_lems_file(self):
pyplts.plot_spikes_from_lems_file(
lems_file_name=lems_file.name,
base_dir=".",
show_plots_already=True,
show_plots_already=False,
save_spike_plot_to="spikes-test-from-lems-file.png",
rates=False,
# rate_window=50,
Expand Down

0 comments on commit d993521

Please sign in to comment.