Skip to content

Commit

Permalink
Merge branch 'master' into black-formatting-action
Browse files Browse the repository at this point in the history
  • Loading branch information
alejoe91 authored Jan 26, 2024
2 parents 33e8bfb + e8f0b12 commit d4b83a6
Show file tree
Hide file tree
Showing 25 changed files with 410 additions and 230 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/publish-to-pypi-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ jobs:
python -m pip install --upgrade pip
pip install setuptools wheel twine build
pip install .
- name: Get the tag version
id: get-version
run: |
echo ${GITHUB_REF#refs/tags/}
echo "TAG::${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Test version/tag correspondence
id: version-check
run: |
neo_version=$(python -c "import neo; print(neo.__version__)")
tag_version=${{ steps.get-version.outputs.TAG }}
echo $neo_version
TAG=${{ github.event.release.tag_name }}
echo $TAG
if [[ $TAG == $neo_version ]]; then
echo $tag_version
if [[ $tag_version == $neo_version ]]; then
echo "VERSION_TAG_MATCH=true" >> $GITHUB_OUTPUT
echo "Version matches tag, proceeding with release to Test PyPI"
else
Expand Down
6 changes: 5 additions & 1 deletion neo/core/baseneo.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ def _container_name(class_name):
referenced by `block.segments`. The attribute name `segments` is
obtained by calling `_container_name_plural("Segment")`.
"""
return _reference_name(class_name) + 's'
if "RegionOfInterest" in class_name:
# this is a hack, pending a more principled way to handle this
return "regionsofinterest"
else:
return _reference_name(class_name) + 's'


class BaseNeo:
Expand Down
8 changes: 0 additions & 8 deletions neo/core/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from neo.core.container import Container, unique_objs
from neo.core.group import Group
from neo.core.objectlist import ObjectList
from neo.core.regionofinterest import RegionOfInterest
from neo.core.segment import Segment


Expand Down Expand Up @@ -91,7 +90,6 @@ def __init__(self, name=None, description=None, file_origin=None,
self.index = index
self._segments = ObjectList(Segment, parent=self)
self._groups = ObjectList(Group, parent=self)
self._regionsofinterest = ObjectList(RegionOfInterest, parent=self)

segments = property(
fget=lambda self: self._get_object_list("_segments"),
Expand All @@ -105,12 +103,6 @@ def __init__(self, name=None, description=None, file_origin=None,
doc="list of Groups contained in this block"
)

regionsofinterest = property(
fget=lambda self: self._get_object_list("_regionsofinterest"),
fset=lambda self, value: self._set_object_list("_regionsofinterest", value),
doc="list of RegionOfInterest objects contained in this block"
)

@property
def data_children_recur(self):
'''
Expand Down
11 changes: 10 additions & 1 deletion neo/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from neo.core.segment import Segment
from neo.core.spiketrainlist import SpikeTrainList
from neo.core.view import ChannelView
from neo.core.regionofinterest import RegionOfInterest


class Group(Container):
Expand Down Expand Up @@ -49,7 +50,8 @@ class Group(Container):
"""
_data_child_objects = (
'AnalogSignal', 'IrregularlySampledSignal', 'SpikeTrain',
'Event', 'Epoch', 'ChannelView', 'ImageSequence'
'Event', 'Epoch', 'ChannelView', 'ImageSequence', 'CircularRegionOfInterest',
'RectangularRegionOfInterest', 'PolygonRegionOfInterest'
)
_container_child_objects = ('Group',)
_parent_objects = ('Block',)
Expand All @@ -69,6 +71,7 @@ def __init__(self, objects=None, name=None, description=None, file_origin=None,
self._epochs = ObjectList(Epoch)
self._channelviews = ObjectList(ChannelView)
self._imagesequences = ObjectList(ImageSequence)
self._regionsofinterest = ObjectList(RegionOfInterest)
self._segments = ObjectList(Segment) # to remove?
self._groups = ObjectList(Group)

Expand Down Expand Up @@ -119,6 +122,12 @@ def __init__(self, objects=None, name=None, description=None, file_origin=None,
doc="list of ImageSequences contained in this group"
)

regionsofinterest = property(
fget=lambda self: self._get_object_list("_regionsofinterest"),
fset=lambda self, value: self._set_object_list("_regionsofinterest", value),
doc="list of RegionOfInterest objects contained in this group"
)

spiketrains = property(
fget=lambda self: self._get_object_list("_spiketrains"),
fset=lambda self, value: self._set_object_list("_spiketrains", value),
Expand Down
6 changes: 3 additions & 3 deletions neo/core/imagesequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ImageSequence(BaseSignal):
)
_recommended_attrs = BaseNeo._recommended_attrs

def __new__(cls, image_data, units=None, dtype=None, copy=True, t_start=0 * pq.s,
def __new__(cls, image_data, units=pq.dimensionless, dtype=None, copy=True, t_start=0 * pq.s,
spatial_scale=None, frame_duration=None,
sampling_rate=None, name=None, description=None, file_origin=None,
**annotations):
Expand Down Expand Up @@ -127,7 +127,7 @@ def __new__(cls, image_data, units=None, dtype=None, copy=True, t_start=0 * pq.s

return obj

def __init__(self, image_data, units=None, dtype=None, copy=True, t_start=0 * pq.s,
def __init__(self, image_data, units=pq.dimensionless, dtype=None, copy=True, t_start=0 * pq.s,
spatial_scale=None, frame_duration=None,
sampling_rate=None, name=None, description=None, file_origin=None,
**annotations):
Expand All @@ -142,7 +142,7 @@ def __array_finalize__spec(self, obj):

self.sampling_rate = getattr(obj, "sampling_rate", None)
self.spatial_scale = getattr(obj, "spatial_scale", None)
self.units = getattr(obj, "units", None)
self.units = getattr(obj, "units", pq.dimensionless)
self._t_start = getattr(obj, "_t_start", 0 * pq.s)

return obj
Expand Down
36 changes: 31 additions & 5 deletions neo/core/regionofinterest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
from math import floor, ceil

from neo.core.baseneo import BaseNeo
from neo.core.imagesequence import ImageSequence


class RegionOfInterest(BaseNeo):
"""Abstract base class"""
pass

_parent_objects = ('Group',)
_parent_attrs = ('group',)
_necessary_attrs = (
('obj', ('ImageSequence', ), 1),
)

def __init__(self, image_sequence, name=None, description=None, file_origin=None, **annotations):
super().__init__(name=name, description=description,
file_origin=file_origin, **annotations)

if not (isinstance(image_sequence, ImageSequence) or (
hasattr(image_sequence, "proxy_for") and issubclass(image_sequence.proxy_for, ImageSequence))):
raise ValueError("Can only take a RegionOfInterest of an ImageSequence")
self.image_sequence = image_sequence

def resolve(self):
"""
Return a signal from within this region of the underlying ImageSequence.
"""
return self.image_sequence.signal_from_region(self)


class CircularRegionOfInterest(RegionOfInterest):
Expand All @@ -23,8 +44,9 @@ class CircularRegionOfInterest(RegionOfInterest):
Radius of the ROI in pixels
"""

def __init__(self, x, y, radius):

def __init__(self, image_sequence, x, y, radius, name=None, description=None,
file_origin=None, **annotations):
super().__init__(image_sequence, name, description, file_origin, **annotations)
self.y = y
self.x = x
self.radius = radius
Expand Down Expand Up @@ -72,7 +94,9 @@ class RectangularRegionOfInterest(RegionOfInterest):
Height (y-direction) of the ROI in pixels
"""

def __init__(self, x, y, width, height):
def __init__(self, image_sequence, x, y, width, height, name=None, description=None,
file_origin=None, **annotations):
super().__init__(image_sequence, name, description, file_origin, **annotations)
self.x = x
self.y = y
self.width = width
Expand Down Expand Up @@ -115,7 +139,9 @@ class PolygonRegionOfInterest(RegionOfInterest):
of the vertices of the polygon
"""

def __init__(self, *vertices):
def __init__(self, image_sequence, *vertices, name=None, description=None,
file_origin=None, **annotations):
super().__init__(image_sequence, name, description, file_origin, **annotations)
self.vertices = vertices

def polygon_ray_casting(self, bounding_points, bounding_box_positions):
Expand Down
6 changes: 4 additions & 2 deletions neo/io/baseio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
If you want a model for developing a new IO start from exampleIO.
"""
from __future__ import annotations
from pathlib import Path

try:
from collections.abc import Sequence
Expand Down Expand Up @@ -96,7 +98,7 @@ class BaseIO:

mode = 'file' # or 'fake' or 'dir' or 'database'

def __init__(self, filename=None, **kargs):
def __init__(self, filename: str | Path = None, **kargs):
self.filename = str(filename)
# create a logger for the IO class
fullname = self.__class__.__module__ + '.' + self.__class__.__name__
Expand All @@ -111,7 +113,7 @@ def __init__(self, filename=None, **kargs):
corelogger.addHandler(logging_handler)

######## General read/write methods #######################
def read(self, lazy=False, **kargs):
def read(self, lazy: bool = False, **kargs):
"""
Return all data from the file as a list of Blocks
"""
Expand Down
Loading

0 comments on commit d4b83a6

Please sign in to comment.