echemdata / galvani

Read proprietary file formats from electrochemical test stations
GNU General Public License v3.0
47 stars 30 forks source link

Add support for data module version 3 #35

Closed SomePythonUser closed 5 years ago

SomePythonUser commented 5 years ago

Hi!

I'm doing my Masters and will probably continue with my PhD working with EC-Lab quite a bit and I've just about had it with the .mpr file format which requires me to export the data manually every single time.

I stumbled upon this seemingly amazing module and I've been trying to import data using the BioLogic.MPRfile function, but I can't seem to get it to work as I get "ValueError: Unrecognised version for data module: 3" when I run BioLogic.MPRfile("some_file.mpr")

I have some experience with python but mainly as a tool for data analysis, so my troubles may be a result of my very limited Python knowledge.

I was hoping that you might have an idea as to how I could get this module to work so that I may import .mpr files directly into Python.

(I wasn't really sure how to reach out for help here so I opened an issue as I could find no other way of doing so. I'm sorry if this was an inappropriate way of going about it)

bcolsen commented 5 years ago

I'm doing my Masters and will probably continue with my PhD working with EC-Lab quite a bit and I've just about had it with the .mpr file format which requires me to export the data manually every single time.

I completely agree!!!

I can't seem to get it to work as I get "ValueError: Unrecognised version for data module: 3" when I run BioLogic.MPRfile("some_file.mpr")

Yup this is a bug. Well actually it's not implemented yet. It looks like they made a new version of their undocumented proprietary data format again. So it needs to be reverse engineered again.

@SomePythonUser Since I don't have that version yet. It would be a great help if you could attach a zip file to this issue containing the .mpr and the exported .mpt file so I can see what needs to be changed.

SomePythonUser commented 5 years ago

Thanks for your reply.

I'm using EC-Lab V11.30.

I've attached a zip file with a random .mpt file and the corresponding .mpr file below.

sample_files.zip

bcolsen commented 5 years ago

@SomePythonUser I think I have fixed the problem. It would be great if you could test it as I don't have the new software version.

To test:

It would also be great if you could attach a zip file here with a .mpr and .mpt like before only this time for a very short run so the data file would be short enough to include with galvani for testing.

SomePythonUser commented 5 years ago

It works really well now. I've tried quite a few different files and I have no issues at all.

I've attached the smallest file, I could find below. small_sample_files.zip

So, now I just have to stick with this version of EC-Lab, I guess.

Thank you for all your help, and thanks for sharing your work!

bcolsen commented 5 years ago

It works really well now. I've tried quite a few different files and I have no issues at all.

That's great, if you use pandas here's some code that you might find usefull. It cleans up the column names so they can be used with the df.column_name access:

def sanitize_labels(label):
    return label.split('/')[0].lower().lstrip('-').translate(dict.fromkeys(map(ord, " ,|()-"),'_')).rstrip('_')

mpr = BioLogic.MPRfile("file_name.mpr")
df = pd.DataFrame(mpr.data)
df.columns = [sanitize_labels(label) for label in df.columns]
df['redox'] = mpr.get_flag('ox/red')

I've attached the smallest file, I could find below.

Looks great, thanks!

So, now I just have to stick with this version of EC-Lab, I guess.

They don't really seem to change the version of the data files that often, so upgrading shouldn't be problem again for a while.