In [1]:
from iuvs import io
import pandas as pd
l1bfiles = io.l1b_filenames()

In [2]:
from IPython.parallel import Client
rc = Client()

In [3]:
dview = rc.direct_view()
lview = rc.load_balanced_view()

In [34]:
def get_header_df(header, drop_comment=True):
    import pandas as pd
    df = pd.DataFrame(header.values(),
                      index=header.keys())
    return df.drop('COMMENT KERNEL'.split()) if drop_comment else df

def save_to_hdf(df, basename):
    import os
    HOME = os.environ['HOME']
    newfname = os.path.splitext(basename)[0] + '.h5'
    path = os.path.join(HOME, 'output', newfname)
    print(path)
    df.to_hdf(path, 'df', format='t')
    
def process_img_headers(fname):
    from iuvs import io
    import os
    from astropy.io import fits
    iuvsfname = io.Filename(fname)
    l1b = io.L1BReader(fname)
    hdu = l1b.hdulist[0]
    hdu.verify('fix')
    df = get_header_df(hdu.header).T.convert_objects()
    basename = os.path.basename(fname)
    df['filename'] = basename
    save_to_hdf(df, basename)
    return

In [31]:
dview.push({'get_header_df':get_header_df,
            'save_to_hdf': save_to_hdf})


Out[31]:
<AsyncResult: finished>

In [35]:
results = lview.map_async(process_img_headers, l1bfiles)

In [40]:
import time
while not results.ready():
    print("{:.1f} %".format(100*results.progress/len(l1bfiles)))
    time.sleep(30)


2.1 %
2.3 %
2.7 %
2.9 %
3.3 %
3.7 %
4.0 %
4.4 %
4.7 %
5.1 %
5.5 %
5.8 %
6.2 %
6.6 %
7.0 %
7.3 %
7.6 %
7.9 %
8.3 %
8.6 %
9.0 %
9.4 %
9.8 %
10.2 %
10.6 %
10.9 %
11.3 %
11.6 %
12.0 %
12.4 %
12.8 %
13.1 %
13.4 %
13.7 %
14.0 %
14.3 %
14.6 %
15.0 %
15.3 %
15.6 %
15.9 %
16.2 %
16.5 %
16.9 %
17.1 %
17.4 %
17.7 %
18.1 %
18.5 %
18.8 %
19.2 %
19.5 %
19.9 %
20.3 %
20.6 %
21.0 %
21.4 %
21.7 %
22.1 %
22.5 %
23.0 %
23.3 %
23.6 %
24.0 %
24.4 %
24.6 %
25.0 %
25.2 %
25.6 %
25.9 %
26.4 %
26.7 %
27.1 %
27.5 %
27.8 %
28.2 %
28.6 %
29.0 %
29.3 %
29.6 %
29.9 %
30.3 %
30.6 %
31.0 %
31.4 %
31.8 %
32.2 %
32.5 %
32.7 %
33.1 %
33.4 %
33.7 %
34.1 %
34.4 %
34.8 %
35.2 %
35.5 %
35.9 %
36.2 %
36.5 %
36.9 %
37.2 %
37.5 %
37.8 %
38.2 %
38.6 %
38.8 %
39.2 %
39.6 %
39.9 %
40.3 %
40.6 %
41.0 %
41.3 %
41.7 %
42.0 %
42.3 %
42.6 %
42.9 %
43.4 %
43.7 %
44.0 %
44.3 %
44.7 %
45.0 %
45.3 %
45.8 %
46.0 %
46.4 %
46.8 %
47.0 %
47.4 %
47.8 %
48.1 %
48.4 %
48.7 %
48.9 %
49.3 %
49.7 %
50.0 %
50.4 %
50.7 %
51.1 %
51.6 %
51.9 %
52.3 %
52.8 %
53.2 %
53.5 %
53.9 %
54.3 %
54.7 %
55.0 %
55.2 %
55.6 %
56.0 %
56.4 %
56.7 %
57.1 %
57.5 %
57.9 %
58.3 %
58.6 %
59.0 %
59.4 %
59.7 %
60.1 %
60.5 %
60.8 %
61.1 %
61.5 %
61.9 %
62.3 %
62.7 %
63.1 %
63.4 %
63.8 %
64.2 %
64.7 %
65.0 %
65.4 %
65.7 %
66.1 %
66.4 %
66.7 %
67.1 %
67.5 %
67.9 %
68.3 %
68.6 %
68.9 %
69.3 %
69.7 %
70.1 %
70.5 %
70.9 %
71.3 %
71.7 %
72.1 %
72.6 %
72.9 %
73.4 %
73.7 %
74.1 %
74.4 %
74.8 %
75.2 %
75.6 %
76.0 %
76.3 %
76.7 %
77.1 %
77.4 %
77.7 %
78.1 %
78.4 %
78.9 %
79.2 %
79.7 %
80.1 %
80.4 %
80.8 %
81.2 %
81.6 %
81.9 %
82.2 %
82.7 %
83.0 %
83.4 %
83.7 %
84.1 %
84.5 %
84.9 %
85.2 %
85.7 %
86.1 %
86.5 %
86.7 %
87.1 %
87.5 %
87.9 %
88.3 %
88.6 %
89.0 %
89.4 %
89.7 %
90.1 %
90.6 %
90.9 %
91.1 %
91.6 %
92.0 %
92.4 %
92.8 %
93.1 %
93.5 %
93.8 %
94.2 %
94.5 %
94.9 %
95.2 %
95.6 %
95.9 %
96.2 %
96.7 %
97.2 %
97.5 %
98.0 %
98.4 %
98.9 %
99.2 %
99.5 %
99.9 %

In [23]:
l1b = process_img_headers(l1bfiles[0])

In [24]:
hdu = l1b.hdulist[0]
hdu.verify('silentfix')

In [25]:
hdu.header


Out[25]:
SIMPLE  =                    T /Primary Header created by MWRFITS v1.11         
BITPIX  =                  -32 /                                                
NAXIS   =                    2 /                                                
NAXIS1  =                  512 /                                                
NAXIS2  =                  512 /                                                
EXTEND  =                    T /Extensions may be present                       
COMMENT MAVEN IUVS Level 1B Data Product                                        
COMMENT IUVS Principal Investigator N. Schneider                                
COMMENT Laboratory for Atmospheric and Space Physics                            
COMMENT University of Colorado Boulder                                          
COMMENT 1234 Innovation Drive, Boulder CO 80303                                 
COMMENT MAVEN Mission scientific and model results are open to all.             
COMMENT Users should contact the PI or designated IUVS team member early in an  
COMMENT analysis project to discuss appropriate use of instrument data results. 
COMMENT Appropriate acknowledgement to institutions, personnel, and funding     
COMMENT agencies should be given. Version numbers should also be specified.     
COMMENT Floating point Not-a-Number (NaN) used for fill data                    
FILENAME= 'mvn_iuv_l1b_IPH2-cycle00044-mode031-fuv_20140503T082457_v01_r01.fits'
CAPTURE = '2014/123 May 03 08:24:57.71271UTC' /Start of integration SCET        
PROCESS = '2015/021 Jan 21 02:09:30.00000UTC' /File processing time             
SW_VER  = '-1' /SVN revision of processing code                                 
XUV     = 'FUV'                                                                 
OBS_ID  =                   31                                                  
MIR_DN  =                29322 //MIRROR_DN                                      
MIR_DEG =        4.4997253E+01 / /MIRROR_DEG                                    
FOV_DEG =        8.9994507E+01                                                  
LYA_CENT=                65535 //LYA_CENTROID                                   
INT_TIME=   60.000 /Integration time in seconds                                 
MCP_VOLT=  846.558 /MCP voltage in volts                                        
MIR_DEG =   45.000 /Mirror position in deg                                      
N_FILL  =        59419 //Number of absent bins in observation                   
BIN_TBL = 'LINEAR 8,8 RidealongIPH2'                                            
SPA_OFS =        0 //Spatial linear bin offset                                  
SPA_SIZE=        2 //Number of pixels per spatial bin                           
SPE_OFS =        0 //Spectral linear bin offset                                 
SPE_SIZE=        2 //Number of pixels per spectral bin                          
KERNEL  = 'naif0010.tls'                                                        
KERNEL  = 'maven_v05_draft4.tf'                                                 
KERNEL  = 'maven_iuvs_v01.ti'                                                   
KERNEL  = 'mvn_app_stow_131118_141009_v01.bc'                                   
KERNEL  = 'trj_c_od015a_140215-141012_moiprelim_v1.bsp'                         
KERNEL  = 'mvn_sc_rel_140428_140504_v01.bc'                                     
KERNEL  = 'mvn_iuv_all_l0_20140503_v002.bc'                                     
KERNEL  = 'MVN_SCLKSCET.00014.tsc'                                              
BUNIT   = 'kR/nm'                                                               
COMMENT Calibrated data for this observation (units: kR/nm)                     

In [ ]: