Reading doubles from binary file in Python

26 görüntüleme
İlk okunmamış mesaja atla

Stephen Hill

okunmadı,
3 Şub 2018 10:52:033.02.2018
alıcı NumFOCUS
Hi everyone. I am new to this group, so please accept my apologies if I have asked an inappropriate/off topic question. Also, please let me know if you require further information.

I am writing a module in Python to read some archive chromatography files written by TotalChrom. I have a file structure document, which has provided me with the basic data structures in the file, and it has worked well except for all values it says are stored as doubles. The values are read are completely different from what I expected - please see below:

methane 3.6368230562528605e-307
ethane -8.243249632731949e+306
propane 1.839329701286865e-60
2-methylpropane -2.55127317345224e-306
butane 3.737451552798833e+59

... And this table shows, what the values should be:
methane 97.25
ethane 426.50
propane 2755.60
2-methylpropane 3390.25
butane 10906.60

Does anyone have any ideas regarding how double values may be stored differently to how I expect, or whether I am using the wrong methods etc. I have included the following files to help:

.rst & .raw files - these are files from where I want to get the data.
.tx0 - a file created by Perkin Elmer from the above files with the data I expect to get.
.py - the Python file I have am trying to use to analyse the data.

Many thanks in advance for your help.

Stephen
nap ex 3-1 0800 8-9-07_004-20180125-101438.TX0
nap ex 3-1 0800 8-9-17_004.raw
nap ex 3-1 0800 8-9-17_004.rst
readtcfiles.py

Stephen Hill

okunmadı,
3 Şub 2018 11:58:303.02.2018
alıcı NumFOCUS
I should add - that the information I am looking at specifically is in the Peak Descriptors part, but I think any solution will sort out the problem for all the double values.

Eric Firing

okunmadı,
3 Şub 2018 12:33:513.02.2018
alıcı numf...@googlegroups.com
Stephen,

This is indeed not a suitable list for programming assistance; it is a
low-traffic list related to organization of python projects under the
Numfocus umbrella. I don't know what would be most appropriate, but
stackoverflow and numpy-discussion would at least be closer to the mark.
Someone else might have better suggestions.

Nevertheless, based on a quick look, I think that at least part of your
problem will be fixed if you change all of your

struct.unpack('d', file.read(8))[0]

expressions to

struct.unpack('>d', file.read(8))[0]

so that doubles will be byte-swapped as needed. See
https://docs.python.org/3/library/struct.html.

Eric
> --
> You received this message because you are subscribed to the Google
> Groups "NumFOCUS" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to numfocus+u...@googlegroups.com
> <mailto:numfocus+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Stephen Hill

okunmadı,
4 Şub 2018 10:22:524.02.2018
alıcı numf...@googlegroups.com
Hi Eric,

Thank you for your message - unfortunately i was not able to find help on this topic on Stackoverflow. I have tried using the “>” character in the format string, and it does not seem to work as desired - the values are still unexpected, and some of the values created are NaN’s.

Thank you anyway.

Kind regards,

Stephen
> You received this message because you are subscribed to a topic in the Google Groups "NumFOCUS" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/numfocus/CfFgP5ONOOk/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to numfocus+u...@googlegroups.com.
Tümünü yanıtla
Yazarı yanıtla
Yönlendir
0 yeni ileti