pypeit.pypeitsetup module

Class for organizing PypeIt setup

class pypeit.pypeitsetup.PypeItSetup(file_list, frametype=None, usrdata=None, setups=None, cfg_lines=None, spectrograph_name=None, pypeit_file=None)[source]

Bases: object

Prepare for a pypeit run.

The main deliverables are the set of parameters used for PypeIt’s algorithms (par), a table with metadata pulled from the files to be reduced (fitstbl), and a class used to perform instrument-specific operations (spectrograph).

Parameters:
  • file_list (list) – A list of strings with the full path to each file to be reduced.

  • frametype (dict, optional) – A dictionary that associates the name of the file (just the fits file name without the full path) to a specific frame type (e.g., arc, bias, etc.). The file name and type are expected to be the key and value of the dictionary, respectively. If None, this is determined by the get_frame_types() method.

  • usrdata (astropy.table.Table, optional) – A user provided set of data used to supplement or overwrite metadata read from the file headers. The table must have a filename column that is used to match to the metadata table generated within PypeIt.

  • setups (list, optional) – A list of setups that each file can be associated with. If None, all files are expected to be for a single setup.

  • cfg_lines (list, optional) –

    A list of strings that provide a set of user-defined parameters for executing pypeit. These are the lines of a configuration file. See the documentation for the configobj package. One of the user-level inputs should be the spectrograph that provided the data to be reduced. One can get the list of spectrographs currently served by running:

    from pypeit.spectrographs.util import valid_spectrographs
    print(valid_spectrographs())
    

    To use all the default parameters when reducing data from a given spectrograph, you can set cfg_lines = None, but you then must provide the spectrograph_name.

  • spectrograph_name (str, optional) – If not providing a list of configuration lines (cfg_lines), this sets the spectrograph. The spectrograph defined in cfg_lines takes precedent over anything provided by this argument.

  • pypeit_file (str, optional) –

    The name of the pypeit file used to instantiate the reduction. This can be None, and will lead to default names for output files (TODO: Give list). Setting PypeIt Reduction File here only sets the name of the file. To instantiate a PypeItSetup object directly from a pypeit file (i.e. by reading the file), use the from_pypeit_file() method; i.e.:

    setup = PypeItSetup.from_pypeit_file('myfile.pypeit')
    

file_list

See description of class argument.

Type:

list

frametype

See description of class argument.

Type:

dict

setups

See description of class argument.

Type:

list

pypeit_file

See description of class argument.

Type:

str

spectrograph

An instance of the Spectrograph class used throughout the reduction procedures.

Type:

pypeit.spectrographs.spectrograph.Spectrograph

par

An instance of the PypeitPar class that provides the parameters to all the algorthms that pypeit uses to reduce the data.

Type:

pypeit.par.pypeitpar.PypeItPar

fitstbl

A Table that provides the salient metadata for the fits files to be reduced.

Type:

pypeit.metadata.PypeItMetaData

build_fitstbl(strict=True)[source]

Construct the table with metadata for the frames to reduce.

Largely a wrapper for PypeItMetaData.

Parameters:

strict (bool, optional) – Function will fault if astropy.io.fits.getheader fails to read the headers of any of the files in file_list. Set to False to only report a warning and continue.

Returns:

Table with the metadata for each fits file to reduce. Note this is different from fitstbl, which is a PypeItMetaData object.

Return type:

astropy.table.Table

classmethod from_file_root(root, spectrograph, extension='.fits')[source]

Instantiate the PypeItSetup object by providing a file root.

Parameters:
  • root (str) – String used to find the raw files; see files_from_extension().

  • spectrograph (str) – The PypeIt name of the spectrograph used to take the observations. This should be one of the available options in available_spectrographs.

  • extension (str, optional) – The extension common to all the fits files to reduce; see files_from_extension().

Returns:

The instance of the class.

Return type:

PypeitSetup

classmethod from_pypeit_file(filename)[source]

Instantiate the PypeitSetup object using a pypeit file.

Parameters:

filename (str) – Name of the pypeit file to read. PypeIt files have a specific set of valid formats. A description can be found PypeIt Reduction File.

Returns:

The instance of the class.

Return type:

PypeitSetup

classmethod from_rawfiles(data_files: list, spectrograph: str, frametype=None)[source]

Instantiate the PypeItSetup object by providing a list of raw files.

Parameters:
  • data_files (list) – List of raw files to be reduced.

  • spectrograph (str) – The PypeIt name of the spectrograph used

  • frametype (dict, optional) – A dictionary that associates the name of the file (just the fits file name without the full path) to a specific frame type (e.g., arc, bias, etc.). The file name and type are expected to be the key and value of the dictionary, respectively. If None, this is determined by the get_frame_types() method.

Returns:

The instance of the class.

Return type:

PypeItSetup

generate_ql_calib_pypeit_files(output_path: str, det: str = None, configs: str = 'all', bkg_redux: bool = False, overwrite: bool = False)[source]

Generate the PypeIt files for the calibrations for quicklook purposes.

Parameters:
  • output_path (str) – Output path for the PypeIt files

  • det (str, optional) – Detector/mosaic.

  • configs (str, optional) – Which configurations to generate.

  • bkg_redux (bool, optional) – Setup for A-B subtraction.

  • overwrite (bool, optional) – Overwrite existing files.

Returns:

List of calib PypeIt files

Return type:

list

get_frame_types(flag_unknown=False)[source]

Include the frame types in the metadata table.

This is mainly a wrapper for get_frame_types().

Warning

Because this merges the frame types with the existing fitstbl this should only be run once.

Parameters:

flag_unknown (bool, optional) – Allow for frames to have unknown types instead of crashing. This should be True for initial setup and False otherwise. Passed to get_frame_types().

property nfiles

The number of files to reduce.

remove_table_rows(rows, regroup=False)[source]

Remove rows from fitstbl.

This is a wrapper for remove_rows() that propagates the files removed from the fits table to the other attributes of the class: file_list, frametype, and usrdata.

This directly modifies the attributes of the instance.

Parameters:
  • rows (int, array-like) – One or more rows that should be removed from the datatable. This is passed directly to astropy.table.Table.remove_rows; see astropy documentation to confirm allowed types.

  • regroup (bool, optional) – If True, reset the setup/configuration, calibration, and combination groups.

run(setup_only=False, clean_config=True, groupings=True)[source]

Perform the main setup operations.

The code flow is as follows::
  • Build the metadata table from an input file_list (if it hasn’t been already)

  • Remove frames (if requested using clean_config) that cannot be associated with a configuration because of incomplete metadata or a configuration that PypeIt cannot reduce

  • Type the files (bias, arc, etc.)

  • Match calibration files to the science files (if groupings is True)

It is expected that a user will run this twice if they’re being careful. Once with setup_only=True to confirm the images are properly typed and grouped together for calibration. A second time to do the actual setup that groups frames by instrument configuration, preparing the user to proceed with the reductions using the run_pypeit script.

Parameters:
  • setup_only (bool, optional) – Only this setup will be performed. PypeIt is expected to execute in a way that ends after this class is fully instantiated such that the user can inspect the results before proceeding. This has the effect of providing more output describing the success of the setup and how to proceed, and provides warnings (instead of errors) for issues that may cause the reduction itself to fail. If True, this also allows for bad headers.

  • clean_config (bool, optional) – Remove files with metadata that indicate an instrument configuration that PypeIt cannot reduce. See valid_configuration_values().

  • groupings (bool, optional) – Group frames into instrument configurations and calibration sets, and add the default combination-group columns.

Returns:

Returns, respectively, the PypeItPar object with the reduction parameters, the Spectrograph object with the spectrograph instance, and the PypeItMetaData() object with the an file metadata.

Return type:

tuple