Skip to content

Commit d4ef07e

Browse files
committed
Remove module attribute and use hidden class property
1 parent f6d85db commit d4ef07e

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

neo/rawio/alphaomegarawio.py

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@
5555
Not a lot of memory optimization effort was put into this module. You should
5656
expect a big memory usage when loading data with this module
5757
58-
:attribute __FOLLOW_SPEC: the AlphaOmega specifiction describe some field that
59-
seems to be different in the recorded data. If True it
60-
will follow the look-alike buggy spec implementation.
61-
Default to False. Be aware that this affects only when
62-
the module is loaded so changing this attribute will
63-
have no effect once it's loaded. You should change it
64-
in the source code.
65-
:type __FOLLOW_SPEC: bool
66-
:attribute __IGNORE_UNKNOWN_BLOCK__: if True (the default) will not read the
67-
unknown block types. This should be faster if there are a lot of them.
68-
:type __IGNORE_UNKNOWN_BLOCK__: bool
69-
7058
.. todo::
7159
1. First search TODO in this file.
7260
2. add IO class with :py:class:`neo.io.basefromrawio.BaseFromRaw`
@@ -99,10 +87,6 @@
9987
)
10088

10189

102-
__FOLLOW_SPEC = False
103-
__IGNORE_UNKNOWN_BLOCK__ = True
104-
105-
10690
class AlphaOmegaRawIO(BaseRawIO):
10791
"""
10892
Handles several blocks and segments.
@@ -148,6 +132,7 @@ def __init__(self, dirname, prune_channels=True):
148132
self.logger.error(f"{self.dirname} is not a folder")
149133
self._prune_channels = prune_channels
150134
self._opened_files = {}
135+
self._ignore_unknown_blocks = True # internal debug property
151136

152137
def _explore_folder(self):
153138
"""
@@ -553,7 +538,7 @@ def _read_file_blocks(self, filename, prune_channels=True):
553538
}
554539
)
555540
else:
556-
if not __IGNORE_UNKNOWN_BLOCK__:
541+
if not self._ignore_unknown_blocks:
557542
try:
558543
bt = block_type.decode()
559544
self.logger.debug(
@@ -1258,19 +1243,18 @@ def get_name(f, name_length):
12581243
- sample_number (ulong): the sample number of the event
12591244
- value (short): value of the event
12601245
"""
1261-
if __FOLLOW_SPEC:
1262-
SDataChannelPort = struct.Struct("<Lh")
1263-
else:
1264-
SDataChannelPort = struct.Struct("<HL")
1265-
"""
1266-
Then for digital ports:
1267-
- value (ushort)
1268-
- sample_number (ulong)
1269-
1270-
.. warning::
1271-
The specification says that for port channels it should be the same as for
1272-
digital channels but the data says otherwise
1273-
"""
1246+
SDataChannelPort = struct.Struct("<HL")
1247+
"""
1248+
Then for digital ports:
1249+
- value (ushort)
1250+
- sample_number (ulong)
1251+
1252+
.. warning::
1253+
The specification says that for port channels it should be the same as for
1254+
digital channels but the data (and AO engineers) says otherwise. According
1255+
to AlphaOmega engineer, this could change in a future logging software
1256+
release and could break this reader.
1257+
"""
12741258

12751259
SAOEvent = struct.Struct("<cL")
12761260
"""Type E: stream data block:

neo/test/rawiotest/test_alphaomegarawio.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class and a full test will be done to test if the new coded IO
2727

2828
from pathlib import Path
2929

30-
from neo.rawio.alphaomegarawio import AlphaOmegaRawIO, __IGNORE_UNKNOWN_BLOCK__
30+
from neo.rawio.alphaomegarawio import AlphaOmegaRawIO
3131

3232
from neo.test.rawiotest.common_rawio_test import BaseTestRawIO
3333

@@ -145,12 +145,15 @@ def test_read_file_blocks(self):
145145

146146
self.assertIsInstance(events, list)
147147

148-
# unknown_blocks is empty by default unless you set modules's attribute
149-
# __IGNORE_UNKNOWN_BLOCK__ to False (which is True by default)
150-
if __IGNORE_UNKNOWN_BLOCK__:
151-
self.assertFalse(unknown_blocks)
152-
else:
153-
self.assertTrue(unknown_blocks) # should not be empty
148+
self.assertFalse(unknown_blocks) # unknown blocks are ignored by default
149+
150+
def test_read_unknown_blocks(self):
151+
path = Path(self.get_local_path("alphaomega/mpx_map_version4"))
152+
reader = AlphaOmegaRawIO(dirname=path)
153+
reader._ignore_unknown_blocks = False
154+
first_mpx = list(path.glob("*.mpx"))[0]
155+
*_, unknown_blocks = reader._read_file_blocks(first_mpx, prune_channels=False)
156+
self.assertTrue(unknown_blocks)
154157

155158
def test_read_file_blocks_prune(self):
156159
"""Check that pruning keep only channels with recorded data"""

0 commit comments

Comments
 (0)