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


Groups > comp.lang.python > #76934 > unrolled thread

Re: Challenge to convert a simple IDL code into Python

Started byGary Herron <gary.herron@islandtraining.com>
First post2014-08-24 10:40 -0700
Last post2014-08-24 10:40 -0700
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.


Contents

  Re: Challenge to convert a simple IDL code into Python Gary Herron <gary.herron@islandtraining.com> - 2014-08-24 10:40 -0700

#76934 — Re: Challenge to convert a simple IDL code into Python

FromGary Herron <gary.herron@islandtraining.com>
Date2014-08-24 10:40 -0700
SubjectRe: Challenge to convert a simple IDL code into Python
Message-ID<mailman.13378.1408902408.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On 08/24/2014 08:38 AM, Cleo Drakos wrote:
>
> Here is IDL code:
>
> |pro read_binary_file
>
> file=  "3B42RT.2014010318.7.bin"
>
> num_lon=  1440
> num_lat=  480
>
> data=  {header:  bytarr(num_lon*2),  precip:  intarr(num_lon,num_lat),  precip_error:  intarr(num_lon,num_lat),  $
>        source_of_estimate:  bytarr(num_lon,num_lat),  precip_uncal:  intarr(num_lon,num_lat)}
>
> close,  1
> openr,  1,  file
> readu,  1,  data
> close,  1     
> precip=  swap_endian(data.precip)
>
> print,  precip
> end|
>
> My attempt in Python is here:
>
> |fname=  '3B42RT.2014010318.7.bin'
>
> num_lon=  1440
> num_lat=  480
>
> with  open(fname,  'rb')  as  fi:
>      contents=  fi.read()
>      precip=  struct.unpack_from('>'+str(num_lon*num_lat)+'I',  contents,  offset=  num_lon*2)
>
>      precip=  np.array(data,dtype=int)
>      precip data|
>
> But, the results obtained from two codes above are not same. The IDL 
> code is correct, but what is wrong with my python code?
>

You are not giving us much to go on here.

First that's not legal Python .  The |last line was probably meant to be 
a print|||, but if you expect us to examine your code, you absolutely 
*must* give us the actual code.  Please cut and paste.

Second, saying it doesn't work us useless.  Please tell us what the code 
is supposed to do, and what it actually does, what you expected...  If 
there is output, cut and paste it.  If there is an error traceback, cut 
and paste it.

While you are at it, tell us what the IDL code does and cut and paste 
it's output.

Gary Herron


> Here is binary file I was working 
> with:ftp://trmmopen.gsfc.nasa.gov/pub/merged/3B42RT/3B42RT.2014010318.7.bin.gz
>
>
> cleo
>
>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web