3

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

Cornspierre
  • 322
  • 1
  • 5
  • 14

2 Answers2

1

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.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
1

DAT is a pretty generic suffix, not necessarily something pointing to a specific format. If I'm understanding correctly, that help section is for DIAdem, which may be completely unrelated to how your data is saved from LV.

What you want is this help section, which tells you how LV flattens data to be stored on disk - http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/flattened_data/

You will need to look at the LV code to see exactly what kind of data you're saving and how the write file function is configured (byte order, size prepending, etc.) and then use that document to translate it to the actual representation.

Yair
  • 2,266
  • 12
  • 12