comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Reading binary files made by Python
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Reading binary files made by Python [message #49264] Tue, 11 July 2006 00:14
Maarten[1] is currently offline  Maarten[1]
Messages: 176
Registered: November 2005
Senior Member
Rick Towler wrote:
> FWIW, I would consider XDR if you can do that from the Python side. It
> is *much* easier to use than HDF, CDF, etc. and sounds like it is
> exactly what you are looking for. The only potential issue is that I
> don't think MATLAB reads it so if that is a requirement I would go back
> to your original approach.

Yes, that is probably even better, and part of the standard python
library:
http://docs.python.org/lib/module-xdrlib.html

I usually work with hierarchical data sets, or data that is best stored
in that way, hence my suggestion to use HDF.

Maarten
Re: Reading binary files made by Python [message #49266 is a reply to message #49264] Mon, 10 July 2006 13:22 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
kuyper@wizard.net wrote:
> Rick Towler wrote:
> ...
>> FWIW, I would consider XDR if you can do that from the Python side. It
>> is *much* easier to use than HDF, CDF, etc. and sounds like it is
>> exactly what you are looking for. The only potential issue is that I
>> don't think MATLAB reads it so if that is a requirement I would go back
>> to your original approach.
>
> Keep in mind that HDF and CDF use XDR internally.
>

I'm trying to K-I-S-S. Set the XDR keyword on OPENR/OPENW and you just
read/write the data... Easier than storing data in HDF/CDF and it seems
to fit the limited needs of the OP.

-Rick
Re: Reading binary files made by Python [message #49267 is a reply to message #49266] Mon, 10 July 2006 11:51 Go to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Rick Towler wrote:
...
> FWIW, I would consider XDR if you can do that from the Python side. It
> is *much* easier to use than HDF, CDF, etc. and sounds like it is
> exactly what you are looking for. The only potential issue is that I
> don't think MATLAB reads it so if that is a requirement I would go back
> to your original approach.

Keep in mind that HDF and CDF use XDR internally.
Re: Reading binary files made by Python [message #49276 is a reply to message #49267] Mon, 10 July 2006 08:55 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
Sheldon wrote:
> Maarten wrote:
>> Sheldon wrote:
>>
>>> I have created som binary files using python and tried to read them
>>> with IDL. I used the binary_template as well but IDL completely
>>> misinterprets the data and returns wrong values and values that were
>>> never written in the file.
>>
>> I would recommend to write out the data in a portable file format, like
>> HDF (pytables is an easy way to do that). You can then use the idl HDF
>> routines to ingest the data, avoiding the larger part of the headaches.
>>
>> Maarten
>>
>> pytables: http://www.pytables.org/
>
> This is a very good idea. I think that I will do just that. The data
> was written and read on the same machine. Silly me, I thought that
> binary is just a binary but I guess not. Will try the HDF format.

Binary is just binary :) Try to keep it simple and just use OPENR/READU
and your knowledge of the file. Do it interactively a few bytes at a
time. You'll at least know exactly when things go wrong...

FWIW, I would consider XDR if you can do that from the Python side. It
is *much* easier to use than HDF, CDF, etc. and sounds like it is
exactly what you are looking for. The only potential issue is that I
don't think MATLAB reads it so if that is a requirement I would go back
to your original approach.

-Rick
Re: Reading binary files made by Python [message #49277 is a reply to message #49276] Mon, 10 July 2006 06:41 Go to previous message
Liberum is currently offline  Liberum
Messages: 48
Registered: September 2005
Member
Maarten wrote:
> Sheldon wrote:
>
>> I have created som binary files using python and tried to read them
>> with IDL. I used the binary_template as well but IDL completely
>> misinterprets the data and returns wrong values and values that were
>> never written in the file. Now Matlab is able to read these files
>> without problem. My question is why is IDL failing to do this? I know
>> that the binaries are Float32 and the dimensions are correct. I am
>> doing something wrong?
>
> Without actually seeing the code you used to write the files, it seems
> a bit hard to answer this question. One obvious issue is the endianess
> of the data, I don't know what python, IDL or matlab assume about that
> (I guess you use the same machine to write and read the data).
>
> I would recommend to write out the data in a portable file format, like
> HDF (pytables is an easy way to do that). You can then use the idl HDF
> routines to ingest the data, avoiding the larger part of the headaches.
>
> Maarten
>
> pytables: http://www.pytables.org/

This is a very good idea. I think that I will do just that. The data
was written and read on the same machine. Silly me, I thought that
binary is just a binary but I guess not. Will try the HDF format.

Thanks,
/Sheldon
Re: Reading binary files made by Python [message #49278 is a reply to message #49277] Mon, 10 July 2006 06:29 Go to previous message
Maarten[1] is currently offline  Maarten[1]
Messages: 176
Registered: November 2005
Senior Member
Sheldon wrote:

> I have created som binary files using python and tried to read them
> with IDL. I used the binary_template as well but IDL completely
> misinterprets the data and returns wrong values and values that were
> never written in the file. Now Matlab is able to read these files
> without problem. My question is why is IDL failing to do this? I know
> that the binaries are Float32 and the dimensions are correct. I am
> doing something wrong?

Without actually seeing the code you used to write the files, it seems
a bit hard to answer this question. One obvious issue is the endianess
of the data, I don't know what python, IDL or matlab assume about that
(I guess you use the same machine to write and read the data).

I would recommend to write out the data in a portable file format, like
HDF (pytables is an easy way to do that). You can then use the idl HDF
routines to ingest the data, avoiding the larger part of the headaches.

Maarten

pytables: http://www.pytables.org/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: format codes
Next Topic: Reading Binary

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:03:54 PDT 2025

Total time taken to generate the page: 0.00657 seconds