Skip to content

Commit

Permalink
Merge pull request NeuroML#383 from NeuroML/feat/ruff-fixes
Browse files Browse the repository at this point in the history
chore: linter fixes
  • Loading branch information
sanjayankur31 authored Jun 5, 2024
2 parents aaaff3d + 5679ca4 commit 357ec2c
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 303 deletions.
4 changes: 2 additions & 2 deletions pyneuroml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def print_v(msg):
except KeyError:
java_max_memory = "400M"

DEFAULTS = {
DEFAULTS: typing.Dict[str, typing.Any] = {
"v": False,
"default_java_max_memory": java_max_memory,
"nogui": False,
} # type: dict[str, typing.Any]
}
15 changes: 8 additions & 7 deletions pyneuroml/analysis/ChannelDensityPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# ion channel densities in NeuroML2 cells
#

import argparse
import logging
import math
import os
Expand All @@ -12,9 +13,9 @@
from collections import OrderedDict

import matplotlib
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.pyplot as plt
import numpy
from matplotlib.colors import LinearSegmentedColormap
from neuroml import (
Cell,
Cell2CaPools,
Expand All @@ -29,13 +30,13 @@
ChannelDensityVShift,
VariableParameter,
)
from sympy import sympify

from pyneuroml.plot.Plot import generate_plot
from pyneuroml.plot.PlotMorphology import plot_2D_cell_morphology
from pyneuroml.pynml import get_value_in_si, read_neuroml2_file
from pyneuroml.utils import get_ion_color
from pyneuroml.utils.cli import build_namespace
from sympy import sympify
import argparse

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -495,7 +496,7 @@ def get_conductance_density_for_segments(

# filter to seg_ids
if seg_ids is not None:
if type(seg_ids) == str:
if isinstance(seg_ids, str):
segments = [seg_ids]
else:
segments = list(set(seg_ids) & set(segments))
Expand All @@ -510,7 +511,7 @@ def get_conductance_density_for_segments(
data[seg.id] = value
else:
# get the inhomogeneous param/value from the channel density
param = channel_density.variable_parameters[0] # type: VariableParameter
param: VariableParameter = channel_density.variable_parameters[0]
inhom_val = param.inhomogeneous_value.value
# H(x) -> Heaviside(x, 0)
if "H" in inhom_val:
Expand Down Expand Up @@ -631,7 +632,7 @@ def plot_channel_densities(
}

if channel_density_ids is not None:
if type(channel_density_ids) == str:
if isinstance(channel_density_ids, str):
channel_density_ids_list = []
channel_density_ids_list.append(channel_density_ids)
channel_density_ids = channel_density_ids_list
Expand Down Expand Up @@ -725,7 +726,7 @@ def plot_channel_densities(
plt.close()

elif ion_channels is not None:
if type(ion_channels) == str:
if isinstance(ion_channels, str):
ion_channel_list = []
ion_channel_list.append(ion_channels)
ion_channels = ion_channel_list
Expand Down
10 changes: 5 additions & 5 deletions pyneuroml/analysis/NML2ChannelAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def plot_channel(channel, a, results, iv_data=None, grid=True):


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


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

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


def make_iv_curve_fig(a, grid=True):
fig = plt.figure()
plt.figure()
plt.get_current_fig_manager().set_window_title(
"Currents vs. holding potentials at erev = %s V" % a.erev
)
Expand All @@ -794,7 +794,7 @@ def plot_iv_curve(a, hold_v, i, *plt_args, **plt_kwargs):
plt_kwargs["label"] = "Current"
if not same_fig:
make_iv_curve_fig(a, grid=grid)
if type(i) is dict:
if isinstance(i, dict):
i = [i[v] for v in hold_v]
plt.plot(
[v * 1e3 for v in hold_v], [ii * 1e12 for ii in i], *plt_args, **plt_kwargs
Expand Down
2 changes: 1 addition & 1 deletion pyneuroml/biosimulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_simulator_versions(
:returns: json response from API
:rtype: str
"""
if type(simulators) is str:
if isinstance(simulators, str):
simulators = [simulators]
all_siminfo = {} # type: typing.Dict[str, typing.List[str]]
for sim in simulators:
Expand Down
19 changes: 10 additions & 9 deletions pyneuroml/neuron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"""

import os
import logging
import warnings
import typing
import pathlib
import json
import logging
import math
import os
import pathlib
import pprint
import typing
import warnings

import airspeed
import yaml

Expand All @@ -22,15 +23,15 @@
except ImportError:
from yaml import Dumper

from pyneuroml.pynml import validate_neuroml1
from pyneuroml.pynml import validate_neuroml2
from pyneuroml.pynml import validate_neuroml1, validate_neuroml2

pp = pprint.PrettyPrinter(depth=4)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

try:
from neuron import h

from pyneuroml.neuron.nrn_export_utils import set_erev_for_mechanism
except ImportError:
logger.warning("Please install optional dependencies to use NEURON features:")
Expand Down Expand Up @@ -468,8 +469,8 @@ def getinfo(seclist: list, doprint: str = "", listall: bool = False):
ms.name(pname, j)
totParamVal[j] += ms.get(pname)
if (
not replace_brackets(str(sec))
in paramsectiondict[rm_NML_str(pname[0])].keys()
replace_brackets(str(sec))
not in paramsectiondict[rm_NML_str(pname[0])].keys()
):
paramsectiondict[rm_NML_str(pname[0])][
replace_brackets(str(sec))
Expand Down
6 changes: 3 additions & 3 deletions pyneuroml/plot/PlotMorphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
Copyright 2023 NeuroML contributors
"""


import argparse
import logging
import os
import random
import sys
import typing
from typing import Optional

import matplotlib
import numpy
from matplotlib import pyplot as plt
from neuroml import Cell, NeuroMLDocument, Segment, SegmentGroup
from neuroml import Cell, NeuroMLDocument, SegmentGroup
from neuroml.neuro_lex_ids import neuro_lex_ids

from pyneuroml.pynml import read_neuroml2_file
from pyneuroml.utils import extract_position_info
from pyneuroml.utils.cli import build_namespace
Expand All @@ -34,7 +35,6 @@
get_next_hex_color,
load_minimal_morphplottable__model,
)
from typing import Optional

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down
7 changes: 4 additions & 3 deletions pyneuroml/plot/PlotMorphologyVispy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
import math
import random
import typing
from typing import Optional

import numpy
import progressbar
from neuroml import Cell, NeuroMLDocument, SegmentGroup, Segment
from neuroml import Cell, NeuroMLDocument, SegmentGroup
from neuroml.neuro_lex_ids import neuro_lex_ids
from scipy.spatial.transform import Rotation

from pyneuroml.pynml import read_neuroml2_file
from pyneuroml.utils import extract_position_info
from pyneuroml.utils.plot import (
Expand All @@ -26,8 +29,6 @@
get_next_hex_color,
load_minimal_morphplottable__model,
)
from scipy.spatial.transform import Rotation
from typing import Optional

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down
11 changes: 5 additions & 6 deletions pyneuroml/povray/NeuroML2ToPOVRay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
This work has been funded by the Medical Research Council and Wellcome Trust
"""


import typing
import random
import argparse
import logging
import random

import neuroml

from pyneuroml import pynml

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -478,9 +477,9 @@ def generate_povray(
else:
parent = int(segment.parent.segments)
proximalpoint = distpoints[parent]
cell_id_vs_seg_id_vs_proximal[cell.id][
id
] = cell_id_vs_seg_id_vs_distal[cell.id][parent]
cell_id_vs_seg_id_vs_proximal[cell.id][id] = (
cell_id_vs_seg_id_vs_distal[cell.id][parent]
)

proxpoints[id] = proximalpoint

Expand Down
21 changes: 10 additions & 11 deletions pyneuroml/tune/NeuroMLTuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,30 @@
Please see the output of `pynml-tune -h` for more information on `pynml-tune`.
"""

from __future__ import unicode_literals
from __future__ import annotations
import os
import os.path
import time
import re
from collections import OrderedDict
from __future__ import annotations, unicode_literals

import argparse
import logging
import os
import os.path
import pprint
import time
import typing
from collections import OrderedDict

from matplotlib import pyplot as plt
from pyneuroml.utils.cli import build_namespace

from pyneuroml import print_v
from pyneuroml.utils.cli import build_namespace

pp = pprint.PrettyPrinter(indent=4)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


try:
from neurotune import optimizers
from neurotune import evaluators
from neurotune import utils
from neurotune import evaluators, optimizers, utils

from pyneuroml.tune.NeuroMLController import NeuroMLController
except ImportError:
logger.warning("Please install optional dependencies to use neurotune features:")
Expand Down
2 changes: 1 addition & 1 deletion 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, Segment
from neuroml import Cell, NeuroMLDocument
from neuroml.loaders import read_neuroml2_file

logger = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit 357ec2c

Please sign in to comment.