Skip to content

Commit 357ec2c

Browse files
Merge pull request #383 from NeuroML/feat/ruff-fixes
chore: linter fixes
2 parents aaaff3d + 5679ca4 commit 357ec2c

File tree

11 files changed

+366
-303
lines changed

11 files changed

+366
-303
lines changed

pyneuroml/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def print_v(msg):
3939
except KeyError:
4040
java_max_memory = "400M"
4141

42-
DEFAULTS = {
42+
DEFAULTS: typing.Dict[str, typing.Any] = {
4343
"v": False,
4444
"default_java_max_memory": java_max_memory,
4545
"nogui": False,
46-
} # type: dict[str, typing.Any]
46+
}

pyneuroml/analysis/ChannelDensityPlot.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# ion channel densities in NeuroML2 cells
55
#
66

7+
import argparse
78
import logging
89
import math
910
import os
@@ -12,9 +13,9 @@
1213
from collections import OrderedDict
1314

1415
import matplotlib
15-
from matplotlib.colors import LinearSegmentedColormap
1616
import matplotlib.pyplot as plt
1717
import numpy
18+
from matplotlib.colors import LinearSegmentedColormap
1819
from neuroml import (
1920
Cell,
2021
Cell2CaPools,
@@ -29,13 +30,13 @@
2930
ChannelDensityVShift,
3031
VariableParameter,
3132
)
33+
from sympy import sympify
34+
3235
from pyneuroml.plot.Plot import generate_plot
3336
from pyneuroml.plot.PlotMorphology import plot_2D_cell_morphology
3437
from pyneuroml.pynml import get_value_in_si, read_neuroml2_file
3538
from pyneuroml.utils import get_ion_color
3639
from pyneuroml.utils.cli import build_namespace
37-
from sympy import sympify
38-
import argparse
3940

4041
logger = logging.getLogger(__name__)
4142
logger.setLevel(logging.INFO)
@@ -495,7 +496,7 @@ def get_conductance_density_for_segments(
495496

496497
# filter to seg_ids
497498
if seg_ids is not None:
498-
if type(seg_ids) == str:
499+
if isinstance(seg_ids, str):
499500
segments = [seg_ids]
500501
else:
501502
segments = list(set(seg_ids) & set(segments))
@@ -510,7 +511,7 @@ def get_conductance_density_for_segments(
510511
data[seg.id] = value
511512
else:
512513
# get the inhomogeneous param/value from the channel density
513-
param = channel_density.variable_parameters[0] # type: VariableParameter
514+
param: VariableParameter = channel_density.variable_parameters[0]
514515
inhom_val = param.inhomogeneous_value.value
515516
# H(x) -> Heaviside(x, 0)
516517
if "H" in inhom_val:
@@ -631,7 +632,7 @@ def plot_channel_densities(
631632
}
632633

633634
if channel_density_ids is not None:
634-
if type(channel_density_ids) == str:
635+
if isinstance(channel_density_ids, str):
635636
channel_density_ids_list = []
636637
channel_density_ids_list.append(channel_density_ids)
637638
channel_density_ids = channel_density_ids_list
@@ -725,7 +726,7 @@ def plot_channel_densities(
725726
plt.close()
726727

727728
elif ion_channels is not None:
728-
if type(ion_channels) == str:
729+
if isinstance(ion_channels, str):
729730
ion_channel_list = []
730731
ion_channel_list.append(ion_channels)
731732
ion_channels = ion_channel_list

pyneuroml/analysis/NML2ChannelAnalysis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def plot_channel(channel, a, results, iv_data=None, grid=True):
584584

585585

586586
def plot_kinetics(channel, a, results, grid=True):
587-
fig = plt.figure()
587+
plt.figure()
588588
plt.get_current_fig_manager().set_window_title(
589589
("Time course(s) of activation variables of " "%s from %s at %s degC")
590590
% (channel.id, channel.file, a.temperature)
@@ -627,7 +627,7 @@ def plot_kinetics(channel, a, results, grid=True):
627627

628628

629629
def plot_steady_state(channel, a, results, grid=True):
630-
fig = plt.figure()
630+
plt.figure()
631631
plt.get_current_fig_manager().set_window_title(
632632
("Steady state(s) of activation variables of " "%s from %s at %s degC")
633633
% (channel.id, channel.file, a.temperature)
@@ -748,7 +748,7 @@ def plot_iv_curves(channel, a, iv_data, grid=True):
748748

749749
def plot_iv_curve_vm(channel, a, hold_v, times, currents, grid=True):
750750
# Holding potentials
751-
fig = plt.figure()
751+
plt.figure()
752752
ax = plt.subplot(111)
753753
plt.get_current_fig_manager().set_window_title(
754754
("Currents through voltage clamp for %s " "from %s at %s degC, erev: %s V")
@@ -775,7 +775,7 @@ def plot_iv_curve_vm(channel, a, hold_v, times, currents, grid=True):
775775

776776

777777
def make_iv_curve_fig(a, grid=True):
778-
fig = plt.figure()
778+
plt.figure()
779779
plt.get_current_fig_manager().set_window_title(
780780
"Currents vs. holding potentials at erev = %s V" % a.erev
781781
)
@@ -794,7 +794,7 @@ def plot_iv_curve(a, hold_v, i, *plt_args, **plt_kwargs):
794794
plt_kwargs["label"] = "Current"
795795
if not same_fig:
796796
make_iv_curve_fig(a, grid=grid)
797-
if type(i) is dict:
797+
if isinstance(i, dict):
798798
i = [i[v] for v in hold_v]
799799
plt.plot(
800800
[v * 1e3 for v in hold_v], [ii * 1e12 for ii in i], *plt_args, **plt_kwargs

pyneuroml/biosimulations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_simulator_versions(
7777
:returns: json response from API
7878
:rtype: str
7979
"""
80-
if type(simulators) is str:
80+
if isinstance(simulators, str):
8181
simulators = [simulators]
8282
all_siminfo = {} # type: typing.Dict[str, typing.List[str]]
8383
for sim in simulators:

pyneuroml/neuron/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
77
"""
88

9-
import os
10-
import logging
11-
import warnings
12-
import typing
13-
import pathlib
149
import json
10+
import logging
1511
import math
12+
import os
13+
import pathlib
1614
import pprint
15+
import typing
16+
import warnings
17+
1718
import airspeed
1819
import yaml
1920

@@ -22,15 +23,15 @@
2223
except ImportError:
2324
from yaml import Dumper
2425

25-
from pyneuroml.pynml import validate_neuroml1
26-
from pyneuroml.pynml import validate_neuroml2
26+
from pyneuroml.pynml import validate_neuroml1, validate_neuroml2
2727

2828
pp = pprint.PrettyPrinter(depth=4)
2929
logger = logging.getLogger(__name__)
3030
logger.setLevel(logging.INFO)
3131

3232
try:
3333
from neuron import h
34+
3435
from pyneuroml.neuron.nrn_export_utils import set_erev_for_mechanism
3536
except ImportError:
3637
logger.warning("Please install optional dependencies to use NEURON features:")
@@ -468,8 +469,8 @@ def getinfo(seclist: list, doprint: str = "", listall: bool = False):
468469
ms.name(pname, j)
469470
totParamVal[j] += ms.get(pname)
470471
if (
471-
not replace_brackets(str(sec))
472-
in paramsectiondict[rm_NML_str(pname[0])].keys()
472+
replace_brackets(str(sec))
473+
not in paramsectiondict[rm_NML_str(pname[0])].keys()
473474
):
474475
paramsectiondict[rm_NML_str(pname[0])][
475476
replace_brackets(str(sec))

pyneuroml/plot/PlotMorphology.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
Copyright 2023 NeuroML contributors
88
"""
99

10-
1110
import argparse
1211
import logging
1312
import os
1413
import random
1514
import sys
1615
import typing
16+
from typing import Optional
1717

1818
import matplotlib
1919
import numpy
2020
from matplotlib import pyplot as plt
21-
from neuroml import Cell, NeuroMLDocument, Segment, SegmentGroup
21+
from neuroml import Cell, NeuroMLDocument, SegmentGroup
2222
from neuroml.neuro_lex_ids import neuro_lex_ids
23+
2324
from pyneuroml.pynml import read_neuroml2_file
2425
from pyneuroml.utils import extract_position_info
2526
from pyneuroml.utils.cli import build_namespace
@@ -34,7 +35,6 @@
3435
get_next_hex_color,
3536
load_minimal_morphplottable__model,
3637
)
37-
from typing import Optional
3838

3939
logger = logging.getLogger(__name__)
4040
logger.setLevel(logging.INFO)

pyneuroml/plot/PlotMorphologyVispy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
import math
1414
import random
1515
import typing
16+
from typing import Optional
1617

1718
import numpy
1819
import progressbar
19-
from neuroml import Cell, NeuroMLDocument, SegmentGroup, Segment
20+
from neuroml import Cell, NeuroMLDocument, SegmentGroup
2021
from neuroml.neuro_lex_ids import neuro_lex_ids
22+
from scipy.spatial.transform import Rotation
23+
2124
from pyneuroml.pynml import read_neuroml2_file
2225
from pyneuroml.utils import extract_position_info
2326
from pyneuroml.utils.plot import (
@@ -26,8 +29,6 @@
2629
get_next_hex_color,
2730
load_minimal_morphplottable__model,
2831
)
29-
from scipy.spatial.transform import Rotation
30-
from typing import Optional
3132

3233
logger = logging.getLogger(__name__)
3334
logger.setLevel(logging.INFO)

pyneuroml/povray/NeuroML2ToPOVRay.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
This work has been funded by the Medical Research Council and Wellcome Trust
99
"""
1010

11-
12-
import typing
13-
import random
1411
import argparse
1512
import logging
13+
import random
1614

1715
import neuroml
16+
1817
from pyneuroml import pynml
1918

2019
logger = logging.getLogger(__name__)
@@ -478,9 +477,9 @@ def generate_povray(
478477
else:
479478
parent = int(segment.parent.segments)
480479
proximalpoint = distpoints[parent]
481-
cell_id_vs_seg_id_vs_proximal[cell.id][
482-
id
483-
] = cell_id_vs_seg_id_vs_distal[cell.id][parent]
480+
cell_id_vs_seg_id_vs_proximal[cell.id][id] = (
481+
cell_id_vs_seg_id_vs_distal[cell.id][parent]
482+
)
484483

485484
proxpoints[id] = proximalpoint
486485

pyneuroml/tune/NeuroMLTuner.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,30 @@
1515
Please see the output of `pynml-tune -h` for more information on `pynml-tune`.
1616
"""
1717

18-
from __future__ import unicode_literals
19-
from __future__ import annotations
20-
import os
21-
import os.path
22-
import time
23-
import re
24-
from collections import OrderedDict
18+
from __future__ import annotations, unicode_literals
19+
2520
import argparse
2621
import logging
22+
import os
23+
import os.path
2724
import pprint
25+
import time
2826
import typing
27+
from collections import OrderedDict
2928

3029
from matplotlib import pyplot as plt
31-
from pyneuroml.utils.cli import build_namespace
30+
3231
from pyneuroml import print_v
32+
from pyneuroml.utils.cli import build_namespace
3333

3434
pp = pprint.PrettyPrinter(indent=4)
3535
logger = logging.getLogger(__name__)
3636
logger.setLevel(logging.INFO)
3737

3838

3939
try:
40-
from neurotune import optimizers
41-
from neurotune import evaluators
42-
from neurotune import utils
40+
from neurotune import evaluators, optimizers, utils
41+
4342
from pyneuroml.tune.NeuroMLController import NeuroMLController
4443
except ImportError:
4544
logger.warning("Please install optional dependencies to use neurotune features:")

pyneuroml/utils/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from matplotlib.lines import Line2D
1919
from matplotlib.patches import Rectangle
2020
from matplotlib_scalebar.scalebar import ScaleBar
21-
from neuroml import Cell, NeuroMLDocument, Segment
21+
from neuroml import Cell, NeuroMLDocument
2222
from neuroml.loaders import read_neuroml2_file
2323

2424
logger = logging.getLogger(__name__)

0 commit comments

Comments
 (0)