Skip to content

Commit

Permalink
c2s.load_data can bow be used without being installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Theis committed Jul 14, 2016
1 parent f2c94b9 commit 952cc2e
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions c2s/c2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@
from scipy.interpolate import interp1d
from scipy.optimize import minimize
from scipy.io import loadmat
from cmt.models import MCGSM, STM, Poisson
from cmt.nonlinear import ExponentialFunction, BlobNonlinearity
from cmt.tools import generate_data_from_image, extract_windows
from cmt.transforms import PCATransform
from cmt.utils import random_select
try:
from cmt.models import MCGSM, STM, Poisson
from cmt.nonlinear import ExponentialFunction, BlobNonlinearity
from cmt.tools import generate_data_from_image, extract_windows
from cmt.transforms import PCATransform
from cmt.utils import random_select
except ImportError:
warn('Install conditional modeling toolkit (https://github.com/lucastheis/cmt) for full functionality.')
from .experiment import Experiment

try:
Expand Down Expand Up @@ -151,8 +154,13 @@ def load_data(filepath):
return data
return []

with open(filepath) as handle:
return load(handle)
try:
with open(filepath) as handle:
return load(handle)
except UnicodeDecodeError:
# Open files saved with Python 2 in Python 3
with open(filepath, 'rb') as handle:
return load(handle, encoding='latin1')


def preprocess(data, fps=100., filter=None, verbosity=0, fps_threshold=.1):
Expand Down Expand Up @@ -205,8 +213,7 @@ def preprocess(data, fps=100., filter=None, verbosity=0, fps_threshold=.1):
data[k]['calcium'] = data[k]['calcium'] - (a * x + b)
else:
data[k]['calcium'] = data[k]['calcium'] - \
percentile_filter(data[k]['calcium'], window_length=int(data[k]['fps'] * filter),
perc=5)
percentile_filter(data[k]['calcium'], window_length=int(data[k]['fps'] * filter), perc=5)

# normalize dispersion
calcium05 = percentile(data[k]['calcium'], 5)
Expand Down

0 comments on commit 952cc2e

Please sign in to comment.