Skip to content
Snippets Groups Projects
Commit 84088172 authored by Alexandre  BLANC's avatar Alexandre BLANC
Browse files

Change trx syntax in repository, fix larva indexing

parent 850c0947
No related branches found
No related tags found
No related merge requests found
from pathlib import Path from pathlib import Path
from typing import Dict, List from typing import Dict, List
import functools
from .trx import TRX from .trx import TRX
class DateTime: class DateTime:
...@@ -10,7 +11,7 @@ class DateTime: ...@@ -10,7 +11,7 @@ class DateTime:
@property @property
def trx(self)->TRX: def trx(self)->TRX:
return TRX(self.path/'trx.mat') return functools.partial(TRX, self.path/'trx.mat')
class Protocol: class Protocol:
def __init__(self, name:str, root:Path): def __init__(self, name:str, root:Path):
...@@ -34,7 +35,7 @@ class Line: ...@@ -34,7 +35,7 @@ class Line:
self.name = name self.name = name
self.root = root self.root = root
assert(str(root.name) == name) assert(str(root.name) == name)
self._protocols:Dict[str, Protocol] = {p.name:Protocol(p.name, p) for p in self.root.glob('p_*') if p.is_dir()} self._protocols:Dict[str, Protocol] = {p.name:Protocol(p.name, p) for p in self.root.iterdir() if p.is_dir() and (p.name.startswith('p_') or p.name.startswith('ch_'))}
def __getitem__(self, protocol:str)->Protocol: def __getitem__(self, protocol:str)->Protocol:
return self._protocols[protocol] return self._protocols[protocol]
...@@ -82,8 +83,8 @@ class Tracker: ...@@ -82,8 +83,8 @@ class Tracker:
class Repository: class Repository:
def __init__(self, root:Path, trackers:List[str]): def __init__(self, root, trackers:List[str]):
self.root = root self.root = Path(root)
self._trackers:Dict[str, Tracker] = {t:Tracker(t, self.root/t) for t in trackers if (self.root/t in self.root.iterdir()) and (self.root/t).is_dir()} self._trackers:Dict[str, Tracker] = {t:Tracker(t, self.root/t) for t in trackers if (self.root/t in self.root.iterdir()) and (self.root/t).is_dir()}
def __getitem__(self, tracker:str)->Tracker: def __getitem__(self, tracker:str)->Tracker:
......
...@@ -52,5 +52,6 @@ def test_repository(root): ...@@ -52,5 +52,6 @@ def test_repository(root):
print(dt) print(dt)
for trx in repo.trx(): for trx in repo.trx():
print(trx) print(trx)
print(trx())
print(repo['t1']['a@a']['p_0']['00000000_000000'].trx) print(repo['t1']['a@a']['p_0']['00000000_000000'].trx)
...@@ -65,11 +65,19 @@ def test_get_string_asarray_false(trx: TRX): ...@@ -65,11 +65,19 @@ def test_get_string_asarray_false(trx: TRX):
s = trx.get_string(['neuron', 'protocol'], asarray=False) s = trx.get_string(['neuron', 'protocol'], asarray=False)
print(s) print(s)
def test_larva_filtering(trx: TRX):
larvae = trx.get_as_array('numero_larva_num')
larva = larvae[0].item()
x = trx.get_as_array(['t', 'x_head'], l=[larva])[0]
print(x)
if __name__ == '__main__': if __name__ == '__main__':
trx = TRX('trx.mat') trx = TRX('tests/trx.mat')
test_get_scalar_list_larvae(trx) test_get_scalar_list_larvae(trx)
test_get_ts_list_larvae(trx) test_get_ts_list_larvae(trx)
test_get_ts_and_scalar(trx) test_get_ts_and_scalar(trx)
test_get_bunched_scalar(trx) test_get_bunched_scalar(trx)
test_get_string(trx) test_get_string(trx)
test_get_string_asarray_false(trx) test_get_string_asarray_false(trx)
\ No newline at end of file test_larva_filtering(trx)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment