Ska.Table

Functions

Ska.Table._make_record_array(array, headerrow, datastart, headertype, colnames)
Ska.Table._parse_ascii_lines(lines, dialect)

Attempt to parse the supplied table lines given the csv dialect values. Problems result in a ParseLinesError exception. If successful, the number of warnings and the lines (parsed into columns) is returned.

Ska.Table._parse_ascii_table(lines, delimiters=['|', '&', ',', '\t', ' '], comment=' *#', quotechars=['"', "'"], cleanspaces=True, headertype='names', loud=None, colnames=None)
Ska.Table._parse_vots_header(lines, **opt)

Parse VOTS header fields from ‘lines’, which should be an iterable that returns lines of the VOTS table. Returns an dict of header fields where all but ‘description’ are in turn a numpy recarray table.

Ska.Table.read_ascii_table(indata, headerrow=1, datastart=None, **opt)

Read the given ASCII data table (supplied as a list of strings or a file object). Try each of the delimiters and quotechars in order and stop for the first case gives a sensible result. Returns a numpy record array object of the data table.

Allowed values of the headertype parameter are:

name first row consists of column names
rdb first row consists of column names, second row gets ignored
none column names auto-generated as col1, col2, ...
Parameters:
  • indata – File name or iterable file-like or list object
  • delimiters – List of single character delimiters (no RE because csv can’t do this)
  • comment – RE for comment line if matched at beginning (can be a compiled re)
  • quotechars – List of possible quote characters
  • cleanspaces – Clean leading/trailing space chars from input lines and output data fields
  • headerrow – Row number of header (default=1, None => column names auto-generated)
  • datastart – Row number of data start (default=None => headerrow+1)
  • headertype – Deprecated, use headerrow and datastart instead.
  • colnames – Explicitly set column names from list
  • loud – Print debug info
Ska.Table.read_fits_table(infile, hdunum=1, pyfits=False)

Use pyfits to read the first HDU of the FITS table file ‘infile’. Returns a record array object which can be accessed either by row or column, e.g. data[2] or data.field(‘col1’).

Parameters:
  • hdunum – HDU number for desired table (default=1)
  • pyfits – Return as a pyfits.NP_pyfits.FITS_rec instead of numpy.rec.recarray.
Return type:

Table object

Ska.Table.read_table(file_or_data, **opt)

All-purpose function to guess the format of a data table and read via the format-specific parsers. First tries FITS then ASCII.

Parameters:
  • file_or_data – Name of a file or some iterable object with the data
  • opt – Other options specific to the format (see read_ascii_table and read_fits_table)
Return type:

Table object

Ska.Table.read_vots_table(indata, delimiters=[' '], quotechars=["'"], cleanspaces=True, loud=False)

Read the given VOTS (VOTable Simple) data table (supplied as a list of strings or a file object). Try each of the delimiters and quotechars in order and stop for the first case gives a sensible result.

Parameters:
  • indata – File name or iterable file-like or list object
  • delimiters – List of single character delimiters (no RE because csv can’t do this)
  • quotechars – List of possible quote characters
  • cleanspaces – Clean leading/trailing space chars from input lines and output data fields
  • loud – Print debug info
Return type:

(header, data)

header: dict containing VOTS header elements data: numpy record array object of the data table.

Ska.Table.write_fits_table(outfile, recarray, header={}, clobber=True, units={}, nulls={}, bscales={}, bzeros={}, disps={})

Write recarray to a FITS binary table file.

NOTES:
  • Set the binary table extension name with header['extname']
  • Vector column elements should work. Column elements with 2 or more dimensions have not been tested and may have row-ordering issues.
Parameters:
  • outfile – output file name
  • recarray – input data (numpy record array)
  • header – dict of header keyword values
  • clobber – overwrite existing file (default True)
  • units – dict specifying column unit values
  • nulls – dict specifying column null values
  • bscales – dict specifying column bscale values
  • bzeros – dict specifying column bzero values
  • disps – dict specifying column disp values
Return type:

None

Classes

class Ska.Table._NullFile
close()
flush()
write(data)
writelines(lines)
class Ska.Table._ParseDialect

Bases: object

Exceptions

class Ska.Table.ParseLinesError

Bases: exceptions.ValueError

args
message
class Ska.Table.ParseTableError

Bases: exceptions.ValueError

args
message

Table Of Contents

Previous topic

Ska.Sun

Next topic

Ska.TelemArchive.fetch