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


Groups > comp.lang.python > #76933

Challenge to convert a simple IDL code into Python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cleo21drakos@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '480': 0.05; 'subject:Python': 0.06; 'binary': 0.07; 'subject:code': 0.07; 'correct,': 0.09; 'fname': 0.09; 'subject:into': 0.09; 'python': 0.11; "'rb')": 0.16; 'code?': 0.16; 'skip:n 90': 0.16; 'subject:simple': 0.16; 'url:gz': 0.16; 'url:nasa': 0.16; 'url:gov': 0.24; 'code:': 0.26; 'skip:" 20': 0.27; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'file': 0.32; 'skip:& 30': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'wrong': 0.37; 'two': 0.37; 'same.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'here:': 0.62; 'here': 0.66; 'results': 0.69; 'pro': 0.69; 'contents,': 0.84; 'obtained': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=stS/9T9aiUU48Dx4OhYjE9Dr3OCkvPKnoPBWCe7HcIs=; b=qi3npaEMOe+LTzynnAz2rQ0NmuizEAtptnCEkJ+Wz5QHFKJQQWBgT6uyn2EaFamN6K +I+9KoU6KPhQruXws7whlTIWnLb9E3IwjhgfXETNeqa7DejeGhSAlCo1qWZ4suEhce2q HpRB/CJY0LKq0EVv5sJsAmVulmtIpn9U6ukCueXH5LnEaefrFipptFZMQzHzMJETr0GJ dKLxptEEj+pw/UeUyaSGMQPjGm+sjAxGkao5O2nJOrk58a9+W0EXO+WS3XszzCsEXjXc xVfNtqcFXUVrRa+IEq05aPIwMv0FSxUEVuiTiDPJciXUYxZ7pwyt5J0LALTkLRFglhno 5NdQ==
X-Received by 10.182.44.135 with SMTP id e7mr16590825obm.18.1408894738892; Sun, 24 Aug 2014 08:38:58 -0700 (PDT)
MIME-Version 1.0
From Cleo Drakos <cleo21drakos@gmail.com>
Date Mon, 25 Aug 2014 00:38:18 +0900
Subject Challenge to convert a simple IDL code into Python
To python-list@python.org
Content-Type multipart/alternative; boundary=001a11c3075c700ce9050161de93
X-Mailman-Approved-At Sun, 24 Aug 2014 19:05:59 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13377.1408899960.18130.python-list@python.org> (permalink)
Lines 383
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408899960 news.xs4all.nl 2892 [2001:888:2000:d::a6]:54580
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76933

Show key headers only | View raw


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

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?

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


cleo

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


Thread

Challenge to convert a simple IDL code into Python Cleo Drakos <cleo21drakos@gmail.com> - 2014-08-25 00:38 +0900

csiph-web