Base Data Model
Data models for KPF data
- class kpfpipe.models.base_model.KPFDataModel[source]
The base class for all KPF data models.
Warning
This class (KPFDataModel) should not be used directly. Based on the data level of your .fits file, used the appropriate level specific data model.
This is the base model for all KPF data models. Level specific data inherit from this class, so any attribute and method listed here applies to all data models.
- header
a dictionary of headers of each extension (HDU)
Header stores all header information from the FITS file. Since Each file is organized into extensions (HDUs), and Astropy parses each extension’s header cards into a dictionary, this attribute is structured as a dictionary of Astropy header objects. The first layer is the name of the header, and the second layer is the name of the key.
Note
For KPF, FITS extensions are identified by their name
- Examples
>>> from kpfpipe.models.level0 import KPF0 # Assume we have an NEID level 0 file called "level0.fits" >>> level0 = KPF0.from_fits('level0.fits', 'NEID') # Accessing key 'OBS_TIME' from the 'PRIMARY' HDU >>> obs_time = level0.header['PRIMARY']['OBS_TIME']
- Type:
- receipt
a table that records the history of this data
The receipt keeps track of the data process history, so that the information stored by this instance can be reproduced from the original data. It is structured as a pandas.DataFrame table, with each row as an entry
Primitives that modifies the content of a data product are expected to also write to the receipt. Three string inputs from the primitive are required: name, any relevant parameters, and a status. The receipt will also automatically fill in additional information, such as the time of execution, code release version, current branch, ect.
Note
It is not recommended to modify the Dataframe directly. Use the provided methods to make any adjustments.
Examples
>>> from kpfpipe.models.level0 import KPF0 >>> data = KPF0() # Add an entry into the receipt # Three args are required: name_of_primitive, param, status >>> data.receipt_add_entry('primitive1', 'param1', 'PASS') >>> data.receipt Time ... Module_Param Status 0 2020-06-22T15:42:18.360409 ... input1 PASS
- Type:
pandas.DataFrame
- extensions
a dictionary of extensions.
This attribute stores any additional information that any primitive may wish to record to FITS. Creating an extension creates an empty extension of the given type and one may modify it directly. Creating an extension will also create a new key-value pair in header, so that one can write header keywords to the extension. When writing to FITS extensions are stored in the FITS data type as specified in kpfpipe.models.metadata.KPF_definitions.FITS_TYPE_MAP (image or binary table). Whitespace or any symbols that may be interpreted by Python as an operator (e.g. -) are not allowed in extension names.
Examples
>>> from kpfpipe.models.level0 import KPF0 >>> data = KPF0() # Add an extension # A unique name is required >>> data.create_extension('extension1', pd.DataFrame) # Access the extension by using its name as an attribute # Add a column called 'col1' to the Dataframe >>> data.extension1['col1'] = [1, 2, 3] >>> data.extension1['extension1'] col1 0 1 1 2 2 3 # add a key-value pair to the header >>> data.header['extension1']['key'] = 'value' # delete the extension we just made >>> data.del_extension['extension1']
- Type:
- config
two-column dataframe that stores each line of the input configuration file
- Type:
DataFrame
- create_extension(ext_name, ext_type=<class 'pandas.core.frame.DataFrame'>)[source]
Create a new empty extension to be saved to FITS. Will not overwrite an existing extensions
- del_extension(ext_name)[source]
Delete an existing auxiliary extension
- Parameters:
ext_name (str) – extension name
- classmethod from_fits(fn, data_type='KPF')[source]
Create a data instance from a file
This method emplys the
readmethod for reading the file. Refer to it for more detail.
- read(fn, data_type, overwrite=False)[source]
Read the content of a .fits file and populate this data structure.
- Parameters:
- Raises:
IOError – when a invalid file is presented
Note
This is not a @classmethod so initialization is required before calling this function
- receipt_add_entry(module, mod_path, param, status, chip='all', comment=' ')[source]
Add an entry to the receipt