Skip to content

allow reading of certain IDL 8.0 .sav files - #5801

Merged
pv merged 2 commits into
scipy:masterfrom
meresmclr:master
Feb 13, 2016
Merged

pv merged 2 commits into
scipy:masterfrom
meresmclr:master

Conversation

@meresmclr

Copy link
Copy Markdown

Some IDL anonymous structures throw an exception needlessly in readsav, the structures read fine when the Exception is turned into a warning. Registration case to verify this patch follows

"""
scipy.io.readsav registration test
illustrates IDL 8.0 .sav file bug workaround
Michael Hirsch
https://scivision.co

This test fails with SciPy 0.16.1 and the latest Git, but will pass
after patching either version with the one line patch below.

In git rev 9e86073, line 283 of scipy.io.readsav, change to
warnings.warn("Error occurred while reading byte array")

"""
from six.moves import urllib
from scipy.io import readsav
from numpy import isclose

def reg_readsav(fn):
    dat = readsav(fn)
    assert isclose(dat['skymap']['full_azimuth'][0][128,128],235.79643)

if __name__ =='__main__':
    url='http://data.phys.ucalgary.ca/sort_by_project/THEMIS/asi/skymaps/new_style/mcgr_20110305/themis_skymap_mcgr_20110305-+_vXX.sav'
    fn = url.rsplit('/',1)[-1]
    try:
        reg_readsav(fn)
    except IOError:
        urllib.request.urlretrieve(url,fn)
        reg_readsav(fn)

registration case follows

#/usr/bin/env python3
"""
scipy.io.readsav registration test
illustrates IDL 8.0 .sav file bug workaround
Michael Hirsch
https://scivision.co

This test fails with SciPy 0.16.1 and the latest Git, but will pass
after patching either version with the one line patch below.

In git rev 9e86073, line 283 of scipy.io.readsav, change to
warnings.warn("Error occurred while reading byte array")

"""
from six.moves import urllib
from scipy.io import readsav
from numpy import isclose

def reg_readsav(fn):
    dat = readsav(fn)
    assert isclose(dat['skymap']['full_azimuth'][0][128,128],235.79643)

if __name__ =='__main__':
    url='http://data.phys.ucalgary.ca/sort_by_project/THEMIS/asi/skymaps/new_style/mcgr_20110305/themis_skymap_mcgr_20110305-+_vXX.sav'
    fn = url.rsplit('/',1)[-1]
    try:
        reg_readsav(fn)
    except IOError:
        urllib.request.urlretrieve(url,fn)
        reg_readsav(fn)
@codecov-io

Copy link
Copy Markdown
@@            master   #5801   diff @@
======================================
  Files          235     235       
  Stmts        43348   43347     -1
  Branches      8165    8165       
  Methods          0       0       
======================================
+ Hit          33723   33725     +2
  Partial       2594    2594       
+ Missed        7031    7028     -3

Review entire Coverage Diff as of e1e60e8

Powered by Codecov. Updated on successful CI builds.

@rgommers rgommers added scipy.io maintenance Items related to regular maintenance tasks labels Feb 4, 2016
@rgommers

rgommers commented Feb 4, 2016

Copy link
Copy Markdown
Member

@scienceopen thanks for the fix. Could you please turn the example above into a self-contained regression test (in scipy/io/tests/test_idl.py)? Then we know that this stays fixed.

@meresmclr

Copy link
Copy Markdown
Author

@rgommers added IDL 8.0 style struct byte array file and regression test that trips error in existing code (but not in my patched version of readsav).

Does that suffice? Thanks for your help.

pv added a commit that referenced this pull request Feb 13, 2016
ENH: io: allow reading of certain IDL 8.0 .sav files
@pv
pv merged commit 9590192 into scipy:master Feb 13, 2016
@pv

pv commented Feb 13, 2016

Copy link
Copy Markdown
Member

Thanks, looks good to me. Merged.

@rgommers rgommers added this to the 0.18.0 milestone Feb 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Items related to regular maintenance tasks scipy.io

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants