BaseEnhancedTable#

class stellarphot.BaseEnhancedTable(*args, input_data=None, table_description=None, colname_map=None, **kwargs)[source]#

Bases: QTable

A class to validate an astropy.table.QTable table of astronomical data during creation and store metadata as attributes.

This is based on the astropy.timeseries.QTable class. We extend this to allow for checking of the units for the columns to match the table_description, but what this returns is just an astropy.table.QTable.

Parameters:
input_data: `astropy.table.QTable` (Default: None)

A table containing astronomical data of interest. This table will be checked to make sure all columns listed in table_description exist and have the right units. Additional columns that may be present in data but are not listed in table_description will NOT be removed. This data is copied, so any changes made during validation will not only affect the data attribute of the instance, the original input data is left unchanged.

table_description: dict or dict-like (Default: None)

This is a dictionary where each key is a required table column name and the value corresponding to each key is the required dtype (can be None). This is used to check the format of the input data table. Columns will be output in the order of the keys in the dictionary with any additional columns tacked on the end.

colname_map: dict, optional (Default: None)

A dictionary containing old column names as keys and new column names as values. This is used to automatically update the column names to the desired names BEFORE the validation is performed.

Notes

This class is based on the astropy.timeseries.QTable class. If no table_description and no input_data is provided, then an empty QTable is returned. If table_description and input_data are provided, then validation of the inputs is performed and the resulting table is returned.

Methods Summary

clean([remove_rows_with_mask])

Return a catalog with only the rows that meet the criteria specified.

read(*args, **kwargs)

Read a table from a file and return it as an instance of this class.

write(*args, **kwargs)

Write the table to a file.

Methods Documentation

clean(remove_rows_with_mask=False, **other_restrictions)[source]#

Return a catalog with only the rows that meet the criteria specified.

Parameters:
catalogastropy.table.Table

Table of catalog information. There are no restrictions on the columns.

remove_rows_with_maskbool, optional

If True, remove rows in which one or more of the values is masked.

other_restrictions: dict, optional

Key/value pairs in which the key is the name of a column in the catalog and the value is the criteria that values in that column must satisfy to be kept in the cleaned catalog. The criteria must be simple, beginning with a comparison operator and including a value. See Examples below.

Returns:
same type as object whose method was called

Table with filtered data

Examples

>>> from astropy.table import Table
>>> from stellarphot import BaseEnhancedTable  # Any subclasses will work too
>>> t = Table([[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]], names=('a', 'b'), masked=True)
>>> bet = BaseEnhancedTable(t)
>>> bet['a'].mask = [True, False, False]
>>> bet['b'].mask = [False, False, True]
>>> bet.clean(remove_rows_with_mask=True)
<BaseEnhancedTable length=1>
   a       b
float64 float64
------- -------
  2.0     2.0
>>> bet.clean(a='>2')
<BaseEnhancedTable length=1>
   a       b
float64 float64
------- -------
    3.0    --
classmethod read(*args, **kwargs)[source]#

Read a table from a file and return it as an instance of this class.

Parameters:
filenamestr

The name of the file to read.

**kwargsdict

Additional keyword arguments to pass to the astropy.table.Table.read method.

write(*args, **kwargs)[source]#

Write the table to a file.

Parameters:
filenamestr

The name of the file to write.

**kwargsdict

Additional keyword arguments to pass to the astropy.table.Table.write method.