Source code for pyspex.ascdump

#!/usr/bin/env python

from . import pyspex_f2py
import numpy
from astropy.table import QTable, Column
import astropy.units as u


[docs]class Ascdump: """Generic ascdump interface to retreive ascdump output tables and return an Astropy table. :ivar table: Output table. :vartype table: astropy.table.QTable """ def __init__(self): self.table = QTable()
[docs] def get(self, isect, icomp, atype): """Run and get the ascdump output for a certain ascdump type (atype) for a model component defined by its sector number (isect) and component number (icomp). :param isect: Sector number of the component. :type isect: int :param icomp: Component number. :type icomp: int :param atype: Ascdump type (see :ref:`sec:ascdump` for more information). :type atype: str """ ier = pyspex_f2py.api_ascdump.asc_run(isect, icomp, atype) if ier == 0: nrows = pyspex_f2py.api_ascdump.asc_nuse for i in numpy.arange(pyspex_f2py.api_ascdump.asc_nv): ier = pyspex_f2py.api_ascdump.asc_get_col(i+1) datatype = int(pyspex_f2py.api_ascdump.asc_type) name = str(pyspex_f2py.api_ascdump.asc_name.astype('U32')).strip() acro = str(pyspex_f2py.api_ascdump.asc_acro.astype('U4')).strip() unit = str(pyspex_f2py.api_ascdump.asc_units.astype('U16')).strip() form = int(pyspex_f2py.api_ascdump.asc_na.astype(int)) format = '' if datatype == 1: data = pyspex_f2py.api_ascdump.asc_la.astype(bool) elif datatype == 3: data = pyspex_f2py.api_ascdump.asc_ia.astype(int) elif datatype == 4: data = pyspex_f2py.api_ascdump.asc_ra.astype(float) format = '0.0'+str(form)+'E' elif datatype == 8: data = pyspex_f2py.api_ascdump.asc_da.astype(float) format = '0.0'+str(form)+'E' elif datatype == 9: data = numpy.zeros(nrows, dtype=object) for j in numpy.arange(nrows): bytestring = pyspex_f2py.api_ascdump.asc_get_char(i+1, j+1) data[j] = str(bytestring.decode('utf-8')).strip() else: print('Error: Data type of column unknown.') ier = 1 return ier if unit != '': col = Column(data, name=acro, description=name, unit=unit, format=format) else: col = Column(data, name=acro, description=name, format=format) self.table.add_column(col) pyspex_f2py.api_ascdump.asc_final() return ier