Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99592

Re: read 4D binary data

From Laura Creighton <lac@openend.se>
Newsgroups comp.lang.python
Subject Re: read 4D binary data
Date 2015-11-26 19:00 +0100
Message-ID <mailman.150.1448560867.20593.python-list@python.org> (permalink)
References <4d15f12abb4c4781168ce05d3b450f63@cptec.inpe.br>

Show all headers | View raw


In a message of Thu, 26 Nov 2015 15:15:43 -0200, jorge.conrado@cptec.inpe.br wr
ites:
>Hi,
>
>
>I'm startig in Python and I have a 4D binary data. The dimension of my 
>data is:
>
>67 ----> longitude points
>41 ----> latitude points
>10 ----> pressure levels points
>33 ----> time points
>
>
>How can I read this data and what can I do to get a 2D array 
>(longitude,latitude) for a specific pressure  and time dimension.
>
>
>Conrado

If your binary data is all of the same type -- these are all floats,
or all ints -- you can use the python array module to read it.
https://docs.python.org/3/library/array.html

If they are heterogenous then you cannot use array, but can use struct
https://docs.python.org/3.5/library/struct.html

If I were you, I would want to get my data into pandas, which is
the best tool for data analysis
http://pandas.pydata.org/

And I would do this pretty much exactly as 
Albert Jan outlines in this stackoverflow question.
http://stackoverflow.com/questions/16573089/reading-binary-data-into-pandas
though, as I said, if your data is homogeneous you can use the array
module instead of using the struct one.  But struct will work on
homogenous data as well -- it is just slower.  You may not care.

Note that Albert Jan's answer is the one on the bottom, i.e. not the
one that got the checkmark from the original poster.

Laura

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: read 4D binary data Laura Creighton <lac@openend.se> - 2015-11-26 19:00 +0100

csiph-web