Skip to content

Commit fb7a955

Browse files
committed
Start local import for neo.rawio
1 parent 070eb47 commit fb7a955

File tree

6 files changed

+9
-45
lines changed

6 files changed

+9
-45
lines changed

neo/rawio/baserawio.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@
7575

7676
from neo import logging_handler
7777

78-
try:
79-
import joblib
80-
81-
HAVE_JOBLIB = True
82-
except ImportError:
83-
HAVE_JOBLIB = False
8478

8579
possible_raw_modes = ['one-file', 'multi-file', 'one-dir', ] # 'multi-dir', 'url', 'other'
8680

@@ -162,7 +156,7 @@ def __init__(self, use_cache=False, cache_path='same_as_resource', **kargs):
162156

163157
self.use_cache = use_cache
164158
if use_cache:
165-
assert HAVE_JOBLIB, 'You need to install joblib for cache'
159+
import joblib
166160
self.setup_cache(cache_path)
167161
else:
168162
self._cache = None
@@ -703,6 +697,8 @@ def rescale_epoch_duration(self, raw_duration, dtype='float64',
703697
return self._rescale_epoch_duration(raw_duration, dtype, event_channel_index)
704698

705699
def setup_cache(self, cache_path, **init_kargs):
700+
import joblib
701+
706702
if self.rawmode in ('one-file', 'multi-file'):
707703
resource_name = self.filename
708704
elif self.rawmode == 'one-dir':

neo/rawio/biocamrawio.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212

1313
import numpy as np
1414

15-
try:
16-
import h5py
17-
HAVE_H5PY = True
18-
except ImportError:
19-
HAVE_H5PY = False
2015

2116

2217
class BiocamRawIO(BaseRawIO):
@@ -45,7 +40,6 @@ def _source_name(self):
4540
return self.filename
4641

4742
def _parse_header(self):
48-
assert HAVE_H5PY, 'h5py is not installed'
4943
self._header_dict = open_biocam_file_header(self.filename)
5044
self._num_channels = self._header_dict["num_channels"]
5145
self._num_frames = self._header_dict["num_frames"]
@@ -121,7 +115,7 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop,
121115
def open_biocam_file_header(filename):
122116
"""Open a Biocam hdf5 file, read and return the recording info, pick the correct method to access raw data,
123117
and return this to the caller."""
124-
assert HAVE_H5PY, 'h5py is not installed'
118+
import h5py
125119

126120
rf = h5py.File(filename, 'r')
127121
# Read recording variables

neo/rawio/cedrawio.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
import numpy as np
2727
from copy import deepcopy
2828

29-
try:
30-
import sonpy
31-
HAVE_SONPY = True
32-
except ImportError:
33-
HAVE_SONPY = False
3429

3530

3631
class CedRawIO(BaseRawIO):
@@ -53,7 +48,7 @@ def _source_name(self):
5348
return self.filename
5449

5550
def _parse_header(self):
56-
assert HAVE_SONPY, 'sonpy must be installed'
51+
import sonpy
5752

5853
self.smrx_file = sonpy.lib.SonFile(sName=str(self.filename), bReadOnly=True)
5954
smrx = self.smrx_file

neo/rawio/maxwellrawio.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727

2828
import numpy as np
2929

30-
try:
31-
import h5py
32-
HAVE_H5 = True
33-
except ImportError:
34-
HAVE_H5 = False
35-
3630

3731
class MaxwellRawIO(BaseRawIO):
3832
"""
@@ -50,12 +44,7 @@ def _source_name(self):
5044
return self.filename
5145

5246
def _parse_header(self):
53-
try:
54-
import MEArec as mr
55-
HAVE_MEAREC = True
56-
except ImportError:
57-
HAVE_MEAREC = False
58-
assert HAVE_H5, 'h5py is not installed'
47+
import h5py
5948

6049
h5 = h5py.File(self.filename, mode='r')
6150
self.h5_file = h5

neo/rawio/mearecrawio.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ def _source_name(self):
4444
return self.filename
4545

4646
def _parse_header(self):
47-
try:
48-
import MEArec as mr
49-
HAVE_MEAREC = True
50-
except ImportError:
51-
HAVE_MEAREC = False
52-
assert HAVE_MEAREC, 'MEArec is not installed'
47+
import MEArec as mr
5348
self._recgen = mr.load_recordings(recordings=self.filename, return_h5_objects=True,
5449
check_suffix=False,
5550
load=['recordings', 'spiketrains', 'channel_positions'],

neo/rawio/nixrawio.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
_spike_channel_dtype, _event_channel_dtype)
1616
from ..io.nixio import check_nix_version
1717

18-
try:
19-
import nixio as nix
20-
21-
HAVE_NIX = True
22-
except ImportError:
23-
HAVE_NIX = False
24-
nix = None
2518

2619

2720
# When reading metadata properties, the following keys are ignored since they
@@ -50,6 +43,8 @@ def _source_name(self):
5043
return self.filename
5144

5245
def _parse_header(self):
46+
import nixio as nix
47+
5348
self.file = nix.File.open(self.filename, nix.FileMode.ReadOnly)
5449
signal_channels = []
5550
anasig_ids = {0: []} # ids of analogsignals by segment

0 commit comments

Comments
 (0)