Skip to content

Commit

Permalink
create_many_to_one_relationship() is now just create_relationship()
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed May 2, 2023
1 parent 1f84881 commit 006c97b
Show file tree
Hide file tree
Showing 27 changed files with 49 additions and 97 deletions.
2 changes: 1 addition & 1 deletion examples/generated_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def generate_block(n_segments=3, n_channels=4, n_units=3,
seg.spiketrains.append(train)
u.spiketrains.append(train)

block.create_many_to_one_relationship()
block.create_relationship()
return block


Expand Down
67 changes: 10 additions & 57 deletions neo/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,9 @@ class Container(BaseNeo):
object recursively that are of a
particular class.
:create_many_to_one_relationship(**args): For each child of the current
object that can only have a
single parent, set its parent
to be the current object.
:create_relationship(**args): Same as :create_many_to_one_relationship:
:create_relationship(**args): For each child of the current
object, set its parent
to be the current object.
:merge(**args): Annotations are merged based on the rules of
:merge_annotations:. Child objects with the same name
Expand Down Expand Up @@ -209,7 +206,7 @@ def __init__(self, name=None, description=None, file_origin=None,
file_origin=file_origin, **annotations)

@property
def _single_child_objects(self):
def _child_objects(self):
"""
Child objects that have a single parent.
"""
Expand All @@ -233,34 +230,20 @@ def _data_child_containers(self):
self._data_child_objects])

@property
def _single_child_containers(self):
def _child_containers(self):
"""
Containers for child objects with a single parent.
"""
return tuple([_container_name(child) for child in
self._single_child_objects])

@property
def _child_objects(self):
"""
All types for child objects.
"""
return self._single_child_objects

@property
def _child_containers(self):
"""
All containers for child objects.
"""
return self._single_child_containers
self._child_objects])

@property
def _single_children(self):
"""
All child objects that can only have single parents.
"""
childs = [list(getattr(self, attr)) for attr in
self._single_child_containers]
self._child_containers]
return tuple(sum(childs, []))

@property
Expand Down Expand Up @@ -405,18 +388,11 @@ def list_children_by_class(self, cls):
objs.extend(getattr(child, container_name, []))
return objs

def create_many_to_one_relationship(self, force=False, recursive=True):
def create_relationship(self, force=False, recursive=True):
"""
For each child of the current object that can only have a single
parent, set its parent to be the current object.
Usage:
>>> a_block.create_many_to_one_relationship()
>>> a_block.create_many_to_one_relationship(force=True)
If the current object is a :class:`Block`, you want to run
populate_RecordingChannel first, because this will create new objects
that this method will link up.
For children of the current object, put the current object in the parent list.
If force is True overwrite any existing relationships
If recursive is True descend into child objects and create
Expand All @@ -429,30 +405,7 @@ def create_many_to_one_relationship(self, force=False, recursive=True):
setattr(child, parent_name, self)
if recursive:
for child in self.container_children:
child.create_many_to_one_relationship(force=force,
recursive=True)

def create_relationship(self, force=False, append=True, recursive=True):
"""
For each child of the current object that can only have a single
parent, set its parent to be the current object.
For children of the current object that can have more than one parent
of this type, put the current object in the parent list.
If the current object is a :class:`Block`, you want to run
populate_RecordingChannel first, because this will create new objects
that this method will link up.
If force is True overwrite any existing relationships
If append is True add it to the list, otherwise overwrite the list.
If recursive is True descend into child objects and create
relationships there
"""
self.create_many_to_one_relationship(force=force, recursive=False)
if recursive:
for child in self.container_children:
child.create_relationship(force=force, append=append,
recursive=True)
child.create_relationship(force=force, recursive=True)

def __deepcopy__(self, memo):
"""
Expand Down
2 changes: 1 addition & 1 deletion neo/io/asciisignalio.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def read_segment(self, lazy=False):
name='Column %d' % i)
seg.analogsignals.append(ana_sig)

seg.create_many_to_one_relationship()
seg.create_relationship()
return seg

def read_metadata(self):
Expand Down
2 changes: 1 addition & 1 deletion neo/io/asciispiketrainio.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def read_segment(self,
sptr.annotate(channel_index=i)
seg.spiketrains.append(sptr)

seg.create_many_to_one_relationship()
seg.create_relationship()
return seg

def write_segment(self, segment,
Expand Down
4 changes: 2 additions & 2 deletions neo/io/basefromrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def read_block(self, block_index=0, lazy=False,
for c, sptr in enumerate(seg.spiketrains):
st_groups[c].add(sptr)

bl.create_many_to_one_relationship()
bl.create_relationship()

return bl

Expand Down Expand Up @@ -278,7 +278,7 @@ def read_segment(self, block_index=0, seg_index=0, lazy=False,
e.segment = seg
seg.epochs.append(e)

seg.create_many_to_one_relationship()
seg.create_relationship()
return seg

def get_sub_signal_streams(self, signal_group_mode='group-by-same-units'):
Expand Down
2 changes: 1 addition & 1 deletion neo/io/baseio.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def read(self, lazy=False, **kargs):
bl = Block(name='One segment only')
seg = self.read_segment(lazy=lazy, **kargs)
bl.segments.append(seg)
bl.create_many_to_one_relationship()
bl.create_relationship()
return [bl]
else:
raise NotImplementedError
Expand Down
4 changes: 2 additions & 2 deletions neo/io/brainwaredamio.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def read_block(self, lazy=False, **kargs):

# create the objects to store other objects
gr = Group(file_origin=self._filename)

# load objects into their containers
block.groups.append(gr)

Expand All @@ -149,7 +149,7 @@ def read_block(self, lazy=False, **kargs):
# remove the file object
self._fsrc = None

block.create_many_to_one_relationship()
block.create_relationship()
return block

# -------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion neo/io/brainwaref32io.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def read_block(self, lazy=False, **kargs):
while res:
res = self.__read_id()

block.create_many_to_one_relationship()
block.create_relationship()

# cleanup attributes
self._fsrc = None
Expand Down
2 changes: 1 addition & 1 deletion neo/io/brainwaresrcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def read_next_block(self, **kargs):
raise

# since we read at a Block level we always do this
self._blk.create_many_to_one_relationship()
self._blk.create_relationship()

# put the Block in a local object so it can be gargabe collected
blockobj = self._blk
Expand Down
2 changes: 1 addition & 1 deletion neo/io/klustakwikio.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def read_block(self, lazy=False):
u.add(st)
seg.spiketrains.append(st)

block.create_many_to_one_relationship()
block.create_relationship()
return block

# Helper hidden functions for reading
Expand Down
2 changes: 1 addition & 1 deletion neo/io/kwikio.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def read_block(self,

seg.duration = model.duration * pq.s

blk.create_many_to_one_relationship()
blk.create_relationship()
return blk

def read_analogsignal(self, model, units='uV', lazy=False):
Expand Down
2 changes: 1 addition & 1 deletion neo/io/neomatlabio.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def read_block(self, lazy=False):
bl_struct = d['block']
bl = self.create_ob_from_struct(
bl_struct, 'Block')
bl.create_many_to_one_relationship()
bl.create_relationship()
return bl

def write_block(self, bl, **kargs):
Expand Down
2 changes: 1 addition & 1 deletion neo/io/neuroshareapiio.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def read_segment(self,
# add the spike object to segment
seg.spiketrains += [sptr]

seg.create_many_to_one_relationship()
seg.create_relationship()

return seg

Expand Down
2 changes: 1 addition & 1 deletion neo/io/neurosharectypesio.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def read_segment(self, import_neuroshare_segment=True,
# close
neuroshare.ns_CloseFile(hFile)

seg.create_many_to_one_relationship()
seg.create_relationship()
return seg


Expand Down
2 changes: 1 addition & 1 deletion neo/io/stimfitio.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ def read_block(self, lazy=False):
bl.segments.append(seg)
t_start = t_start + length * dt

bl.create_many_to_one_relationship()
bl.create_relationship()

return bl
2 changes: 1 addition & 1 deletion neo/test/coretest/test_analogsignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test__children(self):

segment = Segment(name='seg1')
segment.analogsignals = [signal]
segment.create_many_to_one_relationship()
segment.create_relationship()

self.assertEqual(signal._parent_objects, ('Segment',))

Expand Down
6 changes: 3 additions & 3 deletions neo/test/coretest/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def test__children(self):

self.assertEqual(container._repr_pretty_containers, ())

self.assertEqual(container._single_child_objects, ())
self.assertEqual(container._child_objects, ())

self.assertEqual(container._container_child_containers, ())
self.assertEqual(container._data_child_containers, ())
self.assertEqual(container._single_child_containers, ())
self.assertEqual(container._child_containers, ())

self.assertEqual(container._child_objects, ())
self.assertEqual(container._child_containers, ())
Expand All @@ -91,7 +91,7 @@ def test__children(self):

self.assertEqual(container.size, {})

container.create_many_to_one_relationship()
container.create_relationship()
container.create_relationship()

def test_filter(self):
Expand Down
2 changes: 1 addition & 1 deletion neo/test/coretest/test_epoch.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test__children(self):

segment = Segment(name='seg1')
segment.epochs = [epc]
segment.create_many_to_one_relationship()
segment.create_relationship()

self.assertEqual(epc._parent_objects, ('Segment',))

Expand Down
2 changes: 1 addition & 1 deletion neo/test/coretest/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def test__children(self):

segment = Segment(name='seg1')
segment.events = [evt]
segment.create_many_to_one_relationship()
segment.create_relationship()

self.assertEqual(evt._parent_objects, ('Segment',))

Expand Down
8 changes: 4 additions & 4 deletions neo/test/coretest/test_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def test__time_slice(self):

block = Block()
block.segments = [seg]
block.create_many_to_one_relationship()
block.create_relationship()

# test without resetting the time
sliced = seg.time_slice(time_slice[0], time_slice[1])
Expand Down Expand Up @@ -499,7 +499,7 @@ def test__time_slice(self):

block = Block()
block.segments = [seg]
block.create_many_to_one_relationship()
block.create_relationship()

# test with resetting the time
sliced = seg.time_slice(time_slice[0], time_slice[1], reset_time=True)
Expand Down Expand Up @@ -561,7 +561,7 @@ def test__time_slice(self):

block = Block()
block.segments = [seg]
block.create_many_to_one_relationship()
block.create_relationship()

# test with proxy objects
sliced = seg.time_slice(time_slice[0], time_slice[1])
Expand Down Expand Up @@ -607,7 +607,7 @@ def test_time_slice_None(self):

block = Block()
block.segments = [seg]
block.create_many_to_one_relationship()
block.create_relationship()

# test without resetting the time
for t_start, t_stop in time_slices:
Expand Down
2 changes: 1 addition & 1 deletion neo/test/coretest/test_spiketrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ def test__times(self):
def test__children(self):
segment = Segment(name='seg1')
segment.spiketrains = [self.train1]
segment.create_many_to_one_relationship()
segment.create_relationship()

self.assertEqual(self.train1._parent_objects, ('Segment',))

Expand Down
7 changes: 3 additions & 4 deletions neo/test/generate_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def generate_one_simple_block(block_name='block_0', nb_segment=3, supported_obje
# if RecordingChannel in objects:
# populate_RecordingChannel(bl)

bl.create_many_to_one_relationship()
bl.create_relationship()
return bl


Expand Down Expand Up @@ -373,12 +373,11 @@ def generate_one_simple_segment(seg_name='segment 0', supported_objects=[], nb_a

# TODO : Spike, Event

seg.create_many_to_one_relationship()
seg.create_relationship()
return seg


def generate_from_supported_objects(supported_objects):
# ~ create_many_to_one_relationship
if not supported_objects:
raise ValueError('No objects specified')
objects = supported_objects
Expand All @@ -390,5 +389,5 @@ def generate_from_supported_objects(supported_objects):
# TODO
return None

higher.create_many_to_one_relationship()
higher.create_relationship()
return higher
2 changes: 1 addition & 1 deletion neo/test/iotest/test_brainwaredamio.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def proc_dam(filename):
gr.analogsignals.append(sig)
sig.group = gr

block.create_many_to_one_relationship()
block.create_relationship()

return block

Expand Down
Loading

0 comments on commit 006c97b

Please sign in to comment.