spectuner.cube

spectuner.cube.fit_pixel_by_pixel(config: Config, fname_cube: str, save_name: str, sl_db: SpectralLineDB | None = None)[source]

Fit the spectra of a cube.

Parameters:
  • configConfig instance.

  • fname_cube – Path to the cube data.

  • save_name – Path to save the output file.

  • sl_db – Spectral line database. If this is provided, the code will use this database instead of the one defined in the config.

class spectuner.cube.CubePipeline(maxiters: int = 1000, n_estimate: int = 10000, atol_factor: float = 0.0001, window_size: int = 31, rel_height: float = 0.25, noise_factor_global: float = 4.0, noise_factor_local: float = 6.0, number_cut: int = 3, f_pla_cut: float = 0.75, v_LSR: float = 0.0)[source]

Convert cube data into format that can be used by the model.

For each segment, the pipline does the following steps:
  1. Set any inf and nan values in the spectrum to the continuum.

  2. Estimate the global RMS noise of the spectrum by randomly selecting several pixels and using sigma clipping.

  3. Set any outiler values (> 1e4*noise) to the continuum.

  4. Estimate the number of peaks in each spectrum.

Secondly, the pipline removes bad fixels:
  1. Estimate the local RMS noise using the spectrum of one pixel.

  2. Count the number of peaks, and remove the pixel if the total number of peaks of all segments is below a threshold.

  3. Estimate the plateau fraction using by smoothing spectrum, and remove the pixel if the plateau fraction is above a threshold.

maxiters

Maximum number of iterations used in sigma_clipped_stats.

Type:

int

n_estimate

Number of pixels to estimate the RMS noise.

Type:

int

atol_factor

Absolute tolerance factor to remove plateau.

Type:

float

window_size

Window size to smooth the spectrum when removing plateau.

Type:

int

f_pla_cut

Plateau fraction below which a pixel is removed.

Type:

float

noise_factor_global

Global RMS noise multipler to identify peaks.

Type:

float

noise_factor_local

Local RMS noise multipler to identify peaks.

Type:

float

number_cut

Number of peak below which a pixel is removed.

Type:

int

run(file_list: list[CubeItem], save_name: str, fname_mask=None, header_lookup: dict | None = None)[source]

Run the pipeline.

Parameters:
  • file_list

    A list of CubeItem instances to specify the information of each spectral window. The following arguments can be specified:

    • line: Path to the line cube file.

    • continuum: Path to the continuum cube file. If not given, the continuum will be set to zero. Defaults to None.

    • window: A list of (start, end) pairs to specify the frequency range of sub-windows in MHz. Defaults to None.

    • mask: A list of (start, end) pairs to specify the frequency range to be masked in MHz. Defaults to None.

    • header: A dict to specify the header attributes.

    For example:

    files_list = [
        CubeItem(
            continuum="PATH_TO_CONTIUUM_FILE_1",
            line="PATH_TO_LINE_FILE_1",
            window=[(200000., 200500.)]
        ),
        CubeItem(
            continuum="PATH_TO_CONTIUUM_FILE_2",
            line="PATH_TO_LINE_FILE_2",
        ),
    ]
    

  • save_name – Saving name of the output HDF file.

  • fname_mask – Path to a mask file. The file should have a 2D array. The masked pixels should be set to NaN.

  • header_lookup

    A dictionary to specify the aliases of some header attributes. Below is the default header lookup:

    {
        "freq_start": "CRVAL3",
        "dfreq": "CDELT3",
        "n_freq": "NAXIS3",
        "i_freq": "CRPIX3",
        "BMAJ": "BMAJ",
        "BMIN": "BMIN",
    }
    

    Change any attributes if necessary.

load_freqs(header)[source]

Load frequency data from a FITS header.

Parameters:

header (object) – FITS header.

Returns:

Frequency data in MHz.

class spectuner.cube.HDFCubeManager(fname: str)[source]

Interface to access HDF cube files.

Parameters:

fname – Path to the HDF cube file of the observations, which is obtained using CubePipline.

load_count_map() ndarray[source]

Load the map which shows the number of peaks in each pixel.

Returns:

The map of number counts.

load_config(fname: str) Config[source]

Load the config from a fitting result.

Parameters:

fname – Path to the fitting result.

Returns:

Loaded Config instance.

load_pred_data(fname: str, target: str) ndarray[source]

Load a map in the fitting result.

Parameters:
  • fname – Path to the fitting result.

  • target – Dataset Name. May be an absolute or relative path. Use h5ls or spectuner.print_h5_structure to check avilable data.

Returns

The target map.

obs_data_to_fits(save_dir: str, add_T_bg: bool = False, overwrite: bool = False)[source]

Save the observation data to FITS files.

Parameters:
  • save_dir – Directory to save the FITS files.

  • add_T_bg – Whether to add the background temperature to the observed spectrum.

  • overwrite – Whether to overwrite the existing files.

pred_data_to_fits(fname: str, save_dir: str, add_v_LSR: bool = True, add_T_bg: bool = False, overwrite=False)[source]

Save a fitting result to FITS files.

Parameters:
  • fname – Path to the fitting result.

  • save_dir – Directory to save the FITS files.

  • add_v_LSR – Whether to add the LSR velocity to the predicted spectra to match the observation.

  • add_T_bg – Whether to add the background temperature to the observed spectrum.

  • overwrite – Whether to overwrite the existing files.