Beispiel #1
0
 def make_path(self):
     now = time.strftime('%Y-%m-%dT%H-%M-%S', time.localtime())
     self.path = Path(self.basedir, now)
     try:
         os.makedirs(self.path.str)
     except Exception as e:
         raise Exception('Failed creating a base directory: ' + str(e))
Beispiel #2
0
def get_sessionmaker(dbpath, echo=True, autocommit=True, **kw):
    from sqlalchemy import create_engine
    from sqlalchemy.orm import sessionmaker
    path = Path(dbpath)
    engine = create_engine('sqlite:///{}'.format(dbpath),
        echo=echo, **kw) if path.is_file() else recreate('', echo=echo)
    return sessionmaker(engine, autocommit=autocommit)
Beispiel #3
0
 def __init__(self, path, n_focal_pane=1, c_focal_pane=0):
     self.n_focal_pane = n_focal_pane
     self.c_focal_pane = c_focal_pane
     self.path = Path(path).ensure_suffix('.chan')
     self.channel = int(self.path.stem)
     self.maxppath = self.path.join_suffixes('.maxp.npy')
     self.mmappath = self.path.join_suffixes('.mmap.npy')
     self.statpath = self.path.join_suffixes('.stat.npy')
     self.metapath = self.path.join_suffixes('.meta.json')
     self.cmap = colormaps['Jet']
     self.min_val = 0
     self.max_val = 255
Beispiel #4
0
def ephemeral(profile):
    from pacu.util import identity
    from pacu.core.model import fixture
    l = manager.instance('log')
    resource = identity.formattempfile('%s-db-engine-ephemeral.db')
    engine = _create_sqlite_engine(profile.uri + resource, profile.echo.bool)
    engine.__pacu_protect__ = profile.PROTECT.bool
    s = get_scoped(engine)
    if not Path(resource).is_file():
        fixture.base.setup(s)
        l.info('Tables of ephemeral db has initialized.')
    return s
Beispiel #5
0
def upgrade_sqlite(path):
    """
    for io in ScanboxIO.iter_every_io():
    print io.db_path
    upgrade_sqlite(io.db_path)
    """
    import shutil
    path = Path(path)
    Session = open_sqlite(path.str)
    meta = schema.SQLite3Base.metadata
    bind = Session.kw.get('bind')
    shutil.copy2(path.str, path.with_suffix('.backup.sqlite3').str)
    schema.fix_incremental(meta, bind)
    return Session
Beispiel #6
0
def import_ephys(filepath):
    """
    filepath = '/Volumes/Users/ht/dev/current/pacu/tmp/Jack/jzg1/day1/day1_000_007.txt'
    risings = import_ephys(filepath)
    """
    path = Path(filepath)
    if not path.is_file():
        raise NoRawDataError('Can not find raw data {!r}'.format(path.name))
    try:
        raw = np.genfromtxt(path.str,
                            delimiter=' ',
                            names=['TTL', 'ON'],
                            dtype='b')
        first_frame = find_nth_rising(raw['TTL'])
        data = raw[first_frame:]
        data['ON'][data['ON'] == 60] = 1
        edges = np.diff(data['TTL']) > 0
        ed_indices = np.where(edges)[0] + 1
        on_chunks = np.split(data['ON'], ed_indices)
        return np.array([chunk.any() for chunk in on_chunks])
    except Exception as e:
        raise RawDataParseError(e)
Beispiel #7
0
 def __init__(self, path):
     self.path = Path(path).merge_or_join_suffix('.imported', on='.tif')
Beispiel #8
0
def TrajectoryIOFetcher(recording, trial, session):
    root = manager.instance('opt').trajectory_root
    path = Path(root).joinpath(recording, trial)
    return TrajectoryIO(path).set_session(session)
Beispiel #9
0
def ScanboxIOFetcher(mouse, day, io_name, workspace_id):
    root = manager.instance('opt').scanbox_root
    path = Path(root).joinpath(mouse, day, io_name)
    return ScanboxIO(path).set_workspace(workspace_id).set_channel(0)
Beispiel #10
0
from pacu.util.path import Path

class Session(object):
    def __init__(self, id, path):
        self.id = id
        self.path = path
    @property
    def hasimported(self):
        return len(self.path.ls('*.imported')) == self.number_of_trials
    @property
    def number_of_trials(self):
        return len(self.path.ls('*.tif'))
    @property
    def as_json(self):
        return dict(
            type='tr-session',
            id=self.id,
            attributes=dict(
                name=self.path.name,
                numberoftrials=self.number_of_trials,
                hasimported=self.hasimported,
        ))

# test = Path('/Volumes/Gandhi Lab - HT/Soyun/2016-02-04T14-27-00')
test = Path('/Volumes/Gandhi Lab - HT/Soyun/2016-02-11T09-56-35')
t = Session(0, test)
Beispiel #11
0
 def from_metadata_filename(cls, filename, meta):
     sbxpath = Path(filename).with_suffix('.sbx')
     if sbxpath.is_file():
         return cls(sbxpath.str, meta)
Beispiel #12
0
 def __init__(self, path):
     # wself.path = Path(str(path) + '.imported')
     if '.imported' in str(path):
         self.path = Path(path)
     else:
         self.path = Path(str(path) + '.imported')
Beispiel #13
0
 def populate(cls, path=None):
     path = Path(path) if path else path_manager.instance().scanbox_root
     paths = path.rglob('*.mat')
     data_set = [(path.name, cls(path.str)) for path in paths]
     return [(name, vars(self))
             for name, self in data_set if self.is_available]
Beispiel #14
0
        raise Exception('Communication error: ' + str(e))
    data = json.get('data')
    error = json.get('error')
    if error:
        raise Exception(str(error))
    return data


def make_datapath(member, now):
    filedir = '{d.month}.{d.day}.{y}'.format(d=now, y=str(now.year)[2:])
    filename = ('{d.year}{d.month:02}{d.day:02}T'
                '{d.hour:02}{d.minute:02}{d.second:02}').format(d=now)
    return '/'.join((member, filedir, filename))


ip1_condpath = Path('D:', 'DropBox', 'Data', 'Conditions', 'Intrinsic')


def make_condpath(now):
    filedir = now.strftime('%d-%b-%Y')
    filename = ('{d.year}{d.month:02}{d.day:02}T'
                '{d.hour:02}{d.minute:02}{d.second:02}').format(d=now)
    filepath = ip1_condpath.joinpath(filedir)
    if not filepath.is_dir():
        os.makedirs(filepath.str)
    return filepath.joinpath(filename)


def savemat(path, params):
    io.savemat(path, params)
Beispiel #15
0
 def unfold(self):
     yield Path(self.data)
Beispiel #16
0

# print FSGraph(sbxpath).render().to_json()
# qwe = FSGraph(sbxpath.joinpath('JZ5', 'JZ5_000_003.mat')).render().to_json()
# print qwe.render().to_json()
# print qwe.catch()
# print qwe
# qwe = FSGraph(sbxpath.joinpath('fake-error-data.mat')).render().to_json()
# jz5 = '/Volumes/Users/ht/tmp/pysbx-data/JZ5/JZ5_000_003'
# f = FileGroup(jz5)

from pacu.profile import manager

sbxroot = manager.instance('opt').scanbox_root

sbxpath = Path(sbxroot)
# sbxpath = Path('/Volumes/Users/ht/tmp/pysbx-data')
# sbxpath = Path('/Volumes/Recordings/scanbox-jack/my4r_1_3')


def get(req, anchor, *hops, **kwargs):
    action = kwargs.get('action')
    # dest = path.cwd.joinpath(*hops)
    dest = sbxpath.joinpath(*hops)
    try:
        graph = FSGraph(dest)
        return graph.action(action) if action else graph.render().to_json()
    except Exception as e:
        print e
        raise e
Beispiel #17
0
 def __init__(self, path):
     self.path = Path(path)
     self.dcmap = DistortedColormap('jet', xmid=0.5, ymid=0.5)
Beispiel #18
0
 def __init__(self, compatible_path):
     self.tiff_path = Path(compatible_path).with_suffix('.tif')
     self.package_path = Path(compatible_path).with_suffix('.imported')
     self.mouse, self.date, self.user = self.tiff_path.parts[::-1][1:4]
Beispiel #19
0
def ScanimageIOFetcher(year, month, day, mouse, image, session):
    root = manager.instance('opt').scanimage_root
    date = '{}.{:2}.{:2}'.format(year, month, day)
    path = Path(root).joinpath(date, mouse, image)
    return ScanimageIO(path).set_session(session)
Beispiel #20
0
 def __init__(self, path):
     self.path = Path(path).ensure_suffix('.mat')
     self.bound_sbx_path = self.path.with_suffix('.sbx')
     array = io.loadmat(self.path.str, squeeze_me=True).get('info')
     super(ScanboxMatView, self).__init__(array)
Beispiel #21
0
 def __init__(self, path):
     self.path = Path(path).with_suffix('.session')
     self.roi = HybridNamespace.from_path(self.path.joinpath('roi'))
     self.opt = HybridNamespace.from_path(self.path.joinpath('opt'))
Beispiel #22
0
 def __init__(self, path, glob='*', delta=timedelta(180)):
     self.path = Path(path).resolve()
     self.glob = glob
     self.delta = delta
     self.now = datetime.now()
Beispiel #23
0
import re
import os

import time
from tifffile import TiffWriter

from pacu.util.path import Path
from pacu.core.svc.andor.handler.base import BaseHandler
from pacu.util.compat import str

re_filename = re.compile(r'^\w+$')
users_desktop = Path(os.path.expanduser('~'), 'Desktop')
ip1_datapath = Path('D:', 'data')


class WriterHandler(BaseHandler):
    def sync_name(self, member, filedir, filename):
        path = ip1_datapath.joinpath(member, filedir)
        if not path.is_dir():
            os.makedirs(path.str)
        self.tifpath = path.joinpath(filename).with_suffix('.tif')
        self.csvpath = path.joinpath(filename).with_suffix('.csv')
        return True  # self.ready()

    def check(self, filename):
        pass

    def ready(self):
        if self.tifpath.is_file() or self.csvpath.is_file():
            raise Exception(
                'Filename already exists. Please provide new one...')
Beispiel #24
0
 def __init__(self, io, path):
     self.io = io
     self.path = Path(path).with_suffix('.txt')
     self.npy = self.path.with_suffix('.io').joinpath('ephys.npy')
Beispiel #25
0
from pacu.util.path import Path
from pacu.core.scanbox import adapter

localpath = Path('/Volumes/Users/ht/tmp/pysbx-data')
localsbx = []

for path in localpath.rglob('*.mat'):
    try:
        localsbx.append(adapter.get_meta(path.str))
    except Exception as e:
        print 'Unable to read {}'.format(path.str)
    else:
        print 'Data loaded: {}'.format(path.str)


def get(req):
    data = [
        dict(uid=index, text=Path(sbx.raw.filename).stem)
        for index, sbx in enumerate(localsbx)
    ]
    return dict(data=data)
Beispiel #26
0
 def __init__(self, path):
     self.path = Path(path).ensure_suffix('.io')
     self.session = SessionBoundNamespace(self.db_session_factory(),
                                          db.Workspace, db.ROI, db.Datatag,
                                          db.Condition, db.Trial)
Beispiel #27
0
 def __init__(self, path):
     self.path = Path(path)  # without_suffixes '.mat', '.sbx'
Beispiel #28
0
 def __init__(self, path):
     self.path = Path(path)
Beispiel #29
0
def get(req):
    data = [
        dict(uid=index, text=Path(sbx.raw.filename).stem)
        for index, sbx in enumerate(localsbx)
    ]
    return dict(data=data)
Beispiel #30
0
 def __init__(self, path):
     self.path = Path(path).with_suffix('.session')
     self.package, self.mouse, self.date, self.user = self.path.parts[::-1][
         1:5]
     self.roi = HybridNamespace.from_path(self.path.joinpath('roi'))
     self.opt = HybridNamespace.from_path(self.path.joinpath('opt'))