Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binary file (Labview .DAT file) conversion using Python

I work in a lab where we acquire electrophysiological recordings (across 4 recording channels) using custom Labview VIs, which save the acquired data as a .DAT (binary) file. The analysis of these files can then be continued in more Labview VIs, however I would like to analyse all my recordings in Python. First, I need walk through all of my files and convert them out of binary!

I have tried numpy.fromfile (filename), but the numbers I get out make no sense to me:

array([ 3.44316221e-282, 1.58456331e+029, 1.73060724e-077, ..., 4.15038967e+262, -1.56447362e-090, 1.80454329e+070])

To try and get further I looked up the .DAT header format to understand how to grab the bytes and translate them - how many bytes the data is saved in etc: http://zone.ni.com/reference/en-XX/help/370859J-01/header/header/headerallghd_allgemein/

But I can't work out what to do. When I type "head filename" into terminal, below is what I see.

e.g. >> head 2014_04_10c1slice2_rest.DAT

DTL? 0???? @@???? empty array PF?c ƀ????l?N?"1'.+?K13:13:27;0.00010000-08??t?޾??DY ??N?t?x???D? ?uv?tgD?~I?? ??N?t?x>?n?? ????t?x>?n?? ????t?޾??D? ????t?x???D? ????t?x?~I?? ????tgD>?n?? ??N?tgD???D? ??N?t?x???D? ????t????DY ??N?t?x>?n?? ??N?t????DY ?Kn$?t?????DY ??N?t??>?n?? ??N?tgD>?n?? ????t?x?~I?? ????tgD>?n?? ??N?tgD>?n?? ??N?tgD???DY ????t?x???D? ????t???~I?? ??N?tgD???DY ??N?tgD???D? ??N?t?޿~I?? ??N?t?x???DY ??N?tF>?n?? ??N?t?x??%Y

Any help or suggestions on what to do next would be really appreciated.

Thanks.

P.s. There is an old (broken) matlab file that seems to have been intended to convert these files. I think this could probably be helpful, but having spent a couple of days trying to understand it I am still stuck. http://www.mathworks.co.uk/matlabcentral/fileexchange/27195-load-labview-binary-data

like image 785
Cornspierre Avatar asked Aug 05 '26 16:08

Cornspierre


1 Answers

Based on this link it looks like the following should do the trick:

binaryFile = open('Measurement_4.bin', mode='rb')
(data.offset,) = struct.unpack('>d', binaryFile.read(8))

Note that mode is set to 'rb' for binary.

With numpy you can directly do this as

data = numpy.fromfile('Measurement_4.bin', dtype='>d')

Please note that if you are just using Python as an intermediate and want to go back to LabVIEW with the data, you should instead use the function Read from Binary file.vi to read the binary file using native LabVIEW.

like image 147
Cory Kramer Avatar answered Aug 08 '26 12:08

Cory Kramer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!