triplespec_focus package#

Subpackages#

Submodules#

triplespec_focus.entrypoints module#

triplespec_focus.entrypoints.run_triplespec_focus(args=None)#

triplespec_focus.triplespec_focus module#

class triplespec_focus.triplespec_focus.TripleSpecFocus(debug: bool = False, date_key: str = 'DATE', date_time_key: str = 'DATE-OBS', focus_key: str = 'TELFOCUS', filename_key: str = 'FILENAME', file_pattern: str = '*.fits', n_brightest: int = 5, saturation: float = 40000, plot_results: bool = False, debug_plots: bool = False)#

Bases: object

Focus Calculator for the TripleSpec’s Slit Viewer Camera

Parameters:
  • debug (bool) – If set to True will set the logger to debug level.

  • date_key (str) – FITS keyword name for obtaining the date from the FITS file. Default DATE.

  • date_time_key (str) – FITS keyword name for obtaining the date and time from the FITS file. Default DATE-OBS.

  • focus_key (str) – FITS keyword name for obtaining the focus value from the FITS file. Default TELFOCUS.

  • filename_key (str) – FITS keyword name for obtaining the file name from the FITS file. Default FILENAME.

  • file_pattern (str) – Pattern for searching files in the provided data path. Default *.fits.

  • n_brightest (int) – Number of the brightest sources to use for measuring source statistics. Default 5.

  • saturation (float) – Data value at which the detector saturates. Default 40000.

  • plot_results (bool) – If set to True will display information plots at the end. Default False.

  • debug_plots (bool) – If set to True will display several plots useful for debugging or viewing the process. Default False.

detect_sources(ccd: CCDData, debug_plots: bool = False) QTable#

Detects sources in the sharpest image

Using DAOStarFinder will detect the stellar sources in it.

Parameters:
  • ccd (CCDData) – An image with point sources.

  • debug_plots (bool) – If set to True will display the image with the sources. Default False.

Returns:

An Astropy’s QTable containing ids, centroids, focus value and image name.

get_best_focus(df: DataFrame, x_axis_size: int = 2000) List[ndarray]#

Obtains the best focus for a single source

Parameters:
  • df (DataFrame) – Pandas DataFrame containing at least a ‘focus’ and a ‘fwhm’ column. The data should belong to a single source.

  • x_axis_size (int) – Size of the x-axis used to sample the fitted model. Is not an interpolation size.

Returns:

A list with the x-axis and the sampled data using the fitted model, None if it is not possible to find the

focus.

triplespec_focus.utils module#

triplespec_focus.utils.circular_aperture_statistics(ccd: CCDData, positions: ndarray, aperture_radius: float = 10, filename_key: str = 'FILENAME', focus_key: str = 'TELFOCUS', plot: bool = False) DataFrame#

Obtain aperture statistics from a FITS file with point sources

Uses CircularAperture from photutils to obtain several data but the most important is the FWHM

Parameters:
  • ccd (CCDData) – An image with point sources.

  • positions (numpy.ndarray) – Coordinates of the sources to be measured.

  • aperture_radius (float) – Aperture size for obtaining measurements. Default 10.

  • filename_key (str) – FITS keyword name for obtaining the file name from the FITS file. Default FILENAME.

  • focus_key (str) – FITS keyword name for obtaining the focus value from the FITS file. Default TELFOCUS.

  • plot (bool) – If set to True will display a plot of the image and the measured sources.

Returns:

id, mean, fwhm, max, xcentroid, ycentroid and filename.

Return type:

A DataFrame containing the following columns

triplespec_focus.utils.get_args(arguments: List | None = None) Namespace#

Helper function to get the console arguments using argparse.

Parameters:

arguments (List, None) – Optional list of arguments. Default None.

Returns:

An instance of arparse’s Namespace.

triplespec_focus.utils.get_best_image_by_peak(file_list: List, saturation_level: float = 40000.0, focus_key: str = 'TELFOCUS') List#

Select the best image by its peak value

The best peak must be the highest below the saturation level, therefore the data is first masked and then sorted by the peak.

Parameters:
  • file_list (List) – The list of images to be used.

  • saturation_level (float) – Data level at which the image saturates. Default 40000.

  • focus_key (str) – FITS keyword name for obtaining the focus value from the FITS file. Default TELFOCUS.

Returns:

A list wit the best image according to the criteria described above.

triplespec_focus.utils.plot_sources_and_masked_data(ccd: CCDData, positions: ndarray, title: str = '', aperture_radius: int = 10)#

Helper function to plot data and sources

Parameters:
  • ccd (CCDData) – The image to be shown.

  • positions (numpy.ndarray) – Array of source positions to be plotted over the image.

  • title (str) – Title to put to the plot. Default ‘’ (empty string).

  • aperture_radius (int) – Radius size in pixels for the drawing of the sources. Default 10.

triplespec_focus.utils.setup_logging(debug: bool = False, enable_astropy_logger: bool = False) Logger#

Helper function to setup the logger.

Parameters:
  • debug (bool) – If set to True will create a logger in debug level. Default False.

  • enable_astropy_logger (bool) – If set to True will allow the astropy logger to remain active. Default False.

Returns:

A Logger instance from python’s logging.

Module contents#