0

I am trying to read from all of these data tables separately for some data crunching and I can't seem to manage to do it.

The data is available here: http://cdsweb.u-strasbg.fr/topbase/tables/AGS05.OP17

There are 126 tables and it gives me empty arrays for the first 100 tables and then gradually fills them up. What am I doing wrong?

Code:

import numpy as np
from matplotlib import pyplot as plt

for x in np.arange(0,126):
    table = np.genfromtxt('AGS05.OP17',skip_header=(245+(x*71)),skip_footer=(9500-(x*71)))
    print x
    print table

Also, if I try to get only the first one

In [38]: np.genfromtxt('AGS05.OP17',skip_header=245, skip_footer=9500)
Out[38]: array([], dtype=float64)
Gabriel Ilharco
  • 1,649
  • 1
  • 21
  • 34

1 Answers1

0

This reads 126 tables in a list:

tables = []
diff_header = 76
diff_footer = 73
with open('AGS05.OP17', 'rb') as fobj:
    for x in np.arange(126):
        header_skip = 245 + x * diff_header
        footer_skip = 9125 - x * diff_footer
        tables.append(np.genfromtxt(fobj, skip_header=header_skip,
                                    skip_footer=footer_skip))
        fobj.seek(0)

>>> len(tables)
126
>>> len(tables[0])
70
>>> len(tables[-1])
>>> tables[-1]
array([[ 3.75 , -0.433, -0.838, ...,  0.162,  0.592,  0.986],
       [ 3.8  ,  9.999, -0.476, ...,  0.372,  0.797,  1.227],
       [ 3.85 ,  9.999, -0.388, ...,  0.765,  1.094,  1.467],
       ..., 
       [ 8.3  ,  9.999,  9.999, ...,  9.999,  9.999,  9.999],
       [ 8.5  ,  9.999,  9.999, ...,  9.999,  9.999,  9.999],
       [ 8.7  ,  9.999,  9.999, ...,  9.999,  9.999,  9.999]])
70
Mike Müller
  • 82,630
  • 20
  • 166
  • 161