mertisreader v0.0.5
  • Home
  • Tutorials
  • API

    On this page

    • MERTISDataPackReader
      • Methods
        • data_assembler
        • data_collector
        • detect_processing_level
        • filetypes2dict
        • get_fits_files
        • get_frames
        • get_input_path_dict
        • get_metadata
        • get_original_frames
        • get_tis_product
        • get_wavelengths
        • listfiletypes
        • save_plot
        • set_logger
        • set_output_dir
        • show_files
    • Report an issue

    MERTISDataPackReader

    MERTISDataPackReader(input_dir, output_dir='', log_level='', lazy=False)

    Class to read and process MERTIS data.

    Attributes: input_dir (pathlib.Path): Input directory. output_dir (pathlib.Path): Output directory. log_level (str): Log level. fits_files (list): List of FITS files. input_path_dict (dict): Dictionary of input paths. collect_data (dict): Dictionary of collected data.

    Methods

    Name Description
    data_assembler Assembles the collected data into convenient data structures.
    data_collector Collect data from the input files and store it in the collect_data attribute.
    detect_processing_level Detects the processing level (RAW, CAL, PAR) from the files in the input directory.
    filetypes2dict Convert the input files into a dictionary, where the keys are the file types and the values are lists of file paths.
    get_fits_files Get the list of FITS files.
    get_frames Get science frames dictionary with lazy-loaded arrays.
    get_input_path_dict Get the dictionary of input paths.
    get_metadata Get metadata (HK data) from collected files.
    get_original_frames Return the original frames dictionary after assembly.
    get_tis_product Get a TIS product with lazy-loaded science data and metadata.
    get_wavelengths Get wavelength data for TIS products.
    listfiletypes Print the list of file types and the number of files for each file type.
    save_plot Save a plot to the output directory.
    set_logger Set the logger.
    set_output_dir Set the output directory.
    show_files Print statistics about the files in the input directory.

    data_assembler

    MERTISDataPackReader.data_assembler(verbose=False)

    Assembles the collected data into convenient data structures.

    This function processes the collected data and stores it in convenient data structures. The processed data includes: - geom_ls: a dictionary of dictionaries, where each dictionary contains the data for a specific file, and each inner dictionary contains the data for a specific parameter. - frames: a dictionary of numpy arrays, where each array contains the data for a specific file. - wavelengths: a dictionary of numpy arrays, where each array contains the wavelength data for a specific file. - mertis_tis_metadata: a dictionary of pandas DataFrames, where each DataFrame contains the metadata for a specific file. - space_index: a pandas Index object containing the indices of the space measurements. - bb7_index: a pandas Index object containing the indices of the BB7 measurements. - bb3_index: a pandas Index object containing the indices of the BB3 measurements. - planet_index: a pandas Index object containing the indices of the planet measurements.

    data_collector

    MERTISDataPackReader.data_collector()

    Collect data from the input files and store it in the collect_data attribute.

    This function iterates over the input_path_dict dictionary, which contains the file paths for each file type. For each file type, it checks if there are files available and reads the data from the files. The collected data is stored in the collect_data attribute.

    In lazy mode (self.lazy=True), FITS data is wrapped in LazyArray and HK data in LazyCSVLoader to defer I/O until data is actually accessed.

    Returns: None

    detect_processing_level

    MERTISDataPackReader.detect_processing_level()

    Detects the processing level (RAW, CAL, PAR) from the files in the input directory. Ensures all files have the same level.

    filetypes2dict

    MERTISDataPackReader.filetypes2dict()

    Convert the input files into a dictionary, where the keys are the file types and the values are lists of file paths.

    Returns: dict: A dictionary where the keys are the file types and the values are lists of file paths.

    get_fits_files

    MERTISDataPackReader.get_fits_files()

    Get the list of FITS files.

    Returns: list: List of FITS files.

    get_frames

    MERTISDataPackReader.get_frames(file_key=None)

    Get science frames dictionary with lazy-loaded arrays.

    Args: file_key (str, optional): Specific file key. If None, returns all files.

    Returns: dict or LazyArray: If file_key provided, returns LazyArray for that file. Otherwise returns dict {file_key: LazyArray}.

    Raises: RuntimeError: If data_collector() has not been called.

    get_input_path_dict

    MERTISDataPackReader.get_input_path_dict()

    Get the dictionary of input paths.

    Returns: dict: Dictionary of input paths.

    get_metadata

    MERTISDataPackReader.get_metadata(file_type='hk_default', file_key=None)

    Get metadata (HK data) from collected files.

    Args: file_type (str): Type of HK data (‘hk_default’ or ‘hk_extended’). file_key (str, optional): Specific file key. If None, returns dict of all files.

    Returns: dict or LazyCSVLoader or pd.DataFrame: Metadata as LazyCSVLoader in lazy mode, or DataFrame in eager mode.

    get_original_frames

    MERTISDataPackReader.get_original_frames()

    Return the original frames dictionary after assembly.

    Per ADR-004: This method is cached - returns the same object on subsequent calls.

    Returns: dict: The frames dictionary with keys as file stems and values as 3D numpy arrays.

    Raises: RuntimeError: If data_assembler() has not been called yet.

    get_tis_product

    MERTISDataPackReader.get_tis_product(file_key=None)

    Get a TIS product with lazy-loaded science data and metadata.

    Convenience helper for accessing TIS data without manually navigating collect_data and re-opening FITS files. Per ADR-006, returns LazyArray wrappers that defer I/O until data is accessed.

    Args: file_key (str, optional): File stem/key to retrieve. If None, returns the first available TIS file.

    Returns: dict: Dictionary with keys: - ‘fits’: astropy.io.fits.HDUList (memmap) - ‘frames’: LazyArray for science data - ‘wavelengths’: LazyArray or None - ‘metadata’: LazyCSVLoader or None (for HK files) - ‘path’: pathlib.Path to the FITS file

    Raises: RuntimeError: If data_collector() has not been called. ValueError: If no TIS files are available or file_key not found.

    Example: >>> reader = MERTISDataPackReader(dir, lazy=True) >>> reader.data_collector() >>> product = reader.get_tis_product() # first file >>> frames = product[‘frames’] # LazyArray, no I/O yet >>> print(frames.shape) # Still no I/O >>> data = frames.materialize() # Now I/O happens

    get_wavelengths

    MERTISDataPackReader.get_wavelengths(file_key=None)

    Get wavelength data for TIS products.

    Args: file_key (str, optional): Specific file key. If None, returns dict of all files.

    Returns: dict or LazyArray or None: Wavelength data as LazyArray (lazy-loaded). Returns None if wavelengths not available (e.g., RAW level).

    Raises: RuntimeError: If data_collector() has not been called.

    listfiletypes

    MERTISDataPackReader.listfiletypes()

    Print the list of file types and the number of files for each file type.

    This function iterates over the input_path_dict dictionary and prints the file types and the number of files for each file type. The file types and the number of files are printed using the rich.print function.

    Returns: None

    save_plot

    MERTISDataPackReader.save_plot(out_file, dpi=150, out_format='jpg')

    Save a plot to the output directory.

    Args: out_file (str): The name of the output file. dpi (int): The resolution of the saved image in dots per inch. Default is 150. out_format (str): The format of the saved image. Default is ‘jpg’.

    Returns: None

    set_logger

    MERTISDataPackReader.set_logger()

    Set the logger.

    set_output_dir

    MERTISDataPackReader.set_output_dir(output_dir)

    Set the output directory.

    Args: output_dir (str or pathlib.Path): Output directory.

    Returns: pathlib.Path: Output directory.

    show_files

    MERTISDataPackReader.show_files()

    Print statistics about the files in the input directory.

    Prints the number of files in the input directory and the number of files in the input directory that match the old pattern ’’ and the new pattern ’mer_cal_sc_tis_YYYYMMDD--___.fits’.

    • Report an issue