Question

I read a *.sav file saved by IDL with 'readsav' (from scipy.io.idl import readsav). The original *.sav file is a structure (size 170 Mb).

from scipy.io.idl import readsav
sorce = readsav('sorce.sav')

In [60]: sorce
Out[60]:
{'sorce': rec.array([ (20030225.5, 2452696.0, 0.0, 1.0, 57, 10, 7.812899639247917e-06,  0.07400000095367432, 0.527999997138977),
    (20030225.5, 2452696.0, 1.0, 2.0, 57, 10, 0.00011726999946404248, 0.07400000095367432, 0.527999997138977),
    (20030225.5, 2452696.0, 2.0, 3.0, 57, 10, 4.074300159118138e-05, 0.07400000095367432, 0.527999997138977),
    ...,
    (20110511.5, 2455693.0, 37.0, 38.0, 57, 10, 8.608300049672835e-06, 0.02227799966931343, 0.19189999997615814),
    (20110511.5, 2455693.0, 38.0, 39.0, 57, 10, 7.07949993739021e-06, 0.02227799966931343, 0.19189999997615814),
    (20110511.5, 2455693.0, 39.0, 40.0, 57, 10, 5.316100214258768e-06, 0.02227799966931343, 0.19189999997615814)],
   dtype=[(('nominal_date_yyyymmdd', 'NOMINAL_DATE_YYYYMMDD'), '>f8'), (('nominal_date_jdn', 'NOMINAL_DATE_JDN'), '>f8'), (('min_wavelength', 'MIN_WAVELENGTH'), '>f4'), (('max_wavelength', 'MAX_WAVELENGTH'), '>f4'), (('instrument_mode_id', 'INSTRUMENT_MODE_ID'), '>i2'), (('data_version', 'DATA_VERSION'), '>i2'), (('irradiance', 'IRRADIANCE'), '>f4'), (('irradiance_uncertainty', 'IRRADIANCE_UNCERTAINTY'), '>f4'), (('quality', 'QUALITY'), '>f4')])}

How can I access data in 'sorce'?

I found some descriptions here http://docs.scipy.org/doc/numpy/reference/generated/numpy.recarray.html

But the 'dtype' in the examples is like:

dtype=[('x', '<i4'), ...]

while in my case is like:

dtype=[('x', 'X', '<i4'), ...]

I can't access data by

sorce.x  (x -> 'nominal_date_yyyymmdd', etc)

or

sorce.X

I have searched for a while, but still can't figure it out.

Was it helpful?

Solution

Your sorce variable is referencing a dict, not a recarray. From the above example you should use:

from scipy.io.idl import readsav
sorce = readsav('sorce.sav')

sorce_rec = sorce["sorce"]

Now you can access your data as a normal recarray.

Note also that you suggest that your dtype is:

dtype=[('x', 'X', '<i4'), ...]

when it is actually:

dtype=[(('x', 'X'), '<i4'), ...]

In the second case 'x' and 'X' are synonyms and both can be used to access the data in the 'x' column (i.e. sorce_rec['x'] == sorce_rec['X'] is true).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top