-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract information from temporary files for unfinished experiments #102
base: master
Are you sure you want to change the base?
Conversation
Add support for EC-Lab v11.50 Rebased from echemdata#95 by @JhonFlash3008
…p_index and timestamp from the temporary _LOOP.txt and .mpl files during MPRfile initialization Added unitary tests but cannot upload test files due to LFS quota exceeded
from 498 to 502, had to replace other column ids. This is dangerous, as it also modifies dtype from f8 to f4
- supports files without setting module --> extracted loops and cycles - handles conflict between colIDs for the "stack mode" (VMP3 hardware) - supports old files with a timestamp with variable byte index - added lots of new colIDs - supports data_module version 1 - MPRfile attributes startdate, enddate, timestamp are initialized with None value because it is weird if all MPRfile objects don't have the same attributes
…ules, but only if the given argument of MPRfile is a path. This avoids keeping a file busy if an error occurred during class initialization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather see os.path.foo
than path.foo
.
@@ -9,7 +9,7 @@ | |||
|
|||
import re | |||
import csv | |||
from os import SEEK_SET | |||
from os import SEEK_SET, path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from os import SEEK_SET, path | |
from os import SEEK_SET | |
import os.path |
@@ -614,49 +828,39 @@ def __init__(self, file_or_path): | |||
raise ValueError( | |||
"Unrecognised version for data module: %d" % data_module["version"] | |||
) | |||
else: | |||
if path.isfile(loop_file): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if path.isfile(loop_file): | |
if os.path.isfile(loop_file): |
raise ValueError( | ||
"Date mismatch:\n" | ||
+ " Start date: %s\n" % self.startdate | ||
+ " End date: %s\n" % self.enddate | ||
+ " Timestamp: %s\n" % self.timestamp | ||
) | ||
else: | ||
if path.isfile(log_file): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if path.isfile(log_file): | |
if os.path.isfile(log_file): |
for key, value in stack_mode_colID_dtype_map.items(): | ||
dtype_map[key] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for key, value in stack_mode_colID_dtype_map.items(): | |
dtype_map[key] = value | |
dtype_map.update(stack_mode_colID_dtype_map) |
"Column ID {cid} after column {prev} " | ||
"is unknown".format(cid=colID, prev=type_list[-1][0]) | ||
) | ||
if type_list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if type_list: | |
if len(type_list) > 0: |
Better to make it explicit what you are checking than relying on implicit boolean conversion.
if isinstance(file_or_path, str): | ||
fileobj.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be done with a contextmanager but the if ...: close()
is better than nothing.
@@ -522,7 +645,83 @@ def read_VMP_modules(fileobj, read_module_data=True): | |||
yield hdr_dict | |||
fileobj.seek(hdr_dict["offset"] + hdr_dict["length"], SEEK_SET) | |||
|
|||
def loop_from_file(file: str, encoding: str ="latin1"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this is the code that matches the description of the pull request.
It would be nicer if you kept this change and then moved the other changes to separate pull requests with their own descriptions.
|
||
if maybe_log_module: | ||
(log_module,) = maybe_log_module | ||
self.enddate = parse_BioLogic_date(log_module["date"]) | ||
|
||
# There is a timestamp at either 465 or 469 bytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs to be updated rather than just removed completely.
index_inf_100k = np.where(mpr.data["freq/Hz"] < 100000)[0] | ||
assert_allclose( | ||
mpr.data[index_inf_100k][fieldname], | ||
mpt[index_inf_100k][fieldname].astype(mpr.data[fieldname].dtype), | ||
) | ||
if len(mpr.data) == 1: | ||
if mpt["THD Ewe/%"] != -1: | ||
assert_allclose( | ||
mpr.data[fieldname], | ||
mpt[fieldname].astype(mpr.data[fieldname].dtype), | ||
) | ||
else: | ||
indexes = np.where(mpt["THD Ewe/%"] != -1)[0] | ||
|
||
assert_allclose( | ||
mpr.data[indexes][fieldname], | ||
mpt[indexes][fieldname].astype(mpr.data[fieldname].dtype), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what you are changing here and why.
if mpr.loop_index is None: | ||
raise AssertionError("No loop_index found") | ||
elif not len(mpr.loop_index) == 4: | ||
raise AssertionError("loop_index is not the right size") | ||
elif not (mpr.loop_index == [0, 4, 8, 11]).all(): | ||
raise AssertionError("loop_index values are wrong") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a way to assert all of this in one statement using the pytest numpy integrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if mpr.loop_index is None: | |
raise AssertionError("No loop_index found") | |
elif not len(mpr.loop_index) == 4: | |
raise AssertionError("loop_index is not the right size") | |
elif not (mpr.loop_index == [0, 4, 8, 11]).all(): | |
raise AssertionError("loop_index values are wrong") | |
assert mpr.loop_index is not None | |
assert_array_equal(mpr.loop_index, [0, 4, 8, 11]) |
mpr = MPRfile(os.path.join(testdata_dir, "running", "running_OCV.mpr")) | ||
if not hasattr(mpr, "timestamp"): | ||
raise AssertionError("No timestamp found") | ||
elif not mpr.timestamp.timestamp() == 1707299985.908: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With floating point numbers you need to use assert_close()
or similar, because they will not always be exactly equal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You changed the exec bit on this file which will stop it working as a command line script. Undo that change.
if not hasattr(mpr, "timestamp"): | ||
raise AssertionError("No timestamp found") | ||
elif not mpr.timestamp.timestamp() == 1707299985.908: | ||
raise AssertionError("timestamp value is wrong") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not hasattr(mpr, "timestamp"): | |
raise AssertionError("No timestamp found") | |
elif not mpr.timestamp.timestamp() == 1707299985.908: | |
raise AssertionError("timestamp value is wrong") | |
assert mpr.timestamp.timestamp() == pytest.approx(1707299985.908) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might still break if you have effects depending on the system timezone. I need to check this myself locally.
When acquisition is still running, the
mpr
file does not contain the log or loop modules. Instead, these data are stored in ampl
and_LOOP.txt
file, respectively and are adeed to thempr
files only when the experiment stops (and the temporary files are deleted).I added 2 functions to extract the loop_index and the timestamp from these temp files during the MPRfile initialization. They are not called if a loop_module and/or a log_module is already found
I wrote the tests but unfortunately I cannot upload the test files, I receive an error saying I exceeded the LFS quota