Thanks to visit codestin.com
Credit goes to github.com

Skip to content
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
.DS_Store
.idea
*__pycache__*
*.edd-info*
*.egg-info*
*.asv
59 changes: 59 additions & 0 deletions python/commons/lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import sys
import os
import numpy as np

import datajoint as dj

schema = dj.schema('common_lab', locals())

@schema
class Paths(dj.Lookup):
definition = ...

def get_local_path(self, path, local_os=None):

# determine local os
if local_os is None:
local_os = sys.platform
local_os = local_os[:(min(3, len(local_os)))]
if local_os.lower() == 'glo':
local = 0
home = '~'

elif local_os.lower() == 'lin':
local = 1
home = os.environ['HOME']

elif local_os.lower() == 'win':
local = 2
home = os.environ['HOME']

elif local_os.lower() == 'dar':
local = 3
home = '~'

else:
raise NameError('unknown OS')

path = path.replace(os.path.sep, '/')
path = path.replace('~', home)

mapping = np.asarray(self.fetch['global', 'linux', 'windows', 'mac'])
size = mapping.shape
for i in range(size[1]):
for j in range(size[0]):
n = len(mapping[j, i])
if j != local and path[:n] == mapping[j, i][:n]:
path = os.path.join(mapping[local, i], path[n+1:])
break

if os.path.sep == '\\' and local_os.lower() != 'glo':
path = path.replacec('/', '\\')

else:
path = path.replace('\\', '/')

return path



Empty file added python/tests/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions python/tests/test_lab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from nose.tools import assert_raises, assert_equal, \
assert_false, assert_true, assert_list_equal, \
assert_tuple_equal, assert_dict_equal, raises

import os
import random
from commons import lab
from pipeline import experiment


def test_paths():
rel = experiment.Session() * experiment.Scan.EyeVideo() * experiment.Scan.BehaviorFile().proj(
hdf_file='filename')

path_info = random.choice(rel.fetch.as_dict())

tmp = path_info['hdf_file'].split('.')
if '%d' in tmp[0]:
# new version
path_info['hdf_file'] = tmp[0][:-2] + '0.' + tmp[-1]
else:
path_info['hdf_file'] = tmp[0][:-1] + '0.' + tmp[-1]

hdf_path = lab.Paths().get_local_path('{behavior_path}/{hdf_file}'.format(**path_info))
avi_path = lab.Paths().get_local_path('{behavior_path}/{filename}'.format(**path_info))

assert_true(os.path.isfile(avi_path) and os.path.isfile(hdf_path))