Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99592 > unrolled thread
| Started by | Laura Creighton <lac@openend.se> |
|---|---|
| First post | 2015-11-26 19:00 +0100 |
| Last post | 2015-11-26 19:00 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: read 4D binary data Laura Creighton <lac@openend.se> - 2015-11-26 19:00 +0100
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Date | 2015-11-26 19:00 +0100 |
| Subject | Re: read 4D binary data |
| Message-ID | <mailman.150.1448560867.20593.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web