scubes.utilities

scubes.utilities.args module

scubes.utilities.args.create_parser(args_dict, program_description=None)

Create the parser for the arguments keys on args_dict to s-cubes entry-points console scripts.

It uses readFileArgumentParser to include the option to read the arguments from a file using the prefix @ before the filename:

entrypoint @file.args
Parameters:
  • args_dict (dict) – Dictionary to with the long options as keys and a list containing the short option char at the first position and the kwargs for the argument configuration.

  • program_description (str, optional) – Program description. Default is None.

Returns:

parser – The arguments parser.

Return type:

argparse.ArgumentParser

See also

argparse.ArgumentParser.add_argument()

class scubes.utilities.args.readFileArgumentParser(*args, **kwargs)

Bases: ArgumentParser

A class that extends argparse.ArgumentParser to read arguments from file.

convert_arg_line_to_args: yeld's arguments reading a file.
convert_arg_line_to_args(line)

scubes.utilities.daofinder module

scubes.utilities.io module

scubes.utilities.io.check_units(ra, dec)

Check and add units to the input coordinates if units are missing.

Parameters:
  • ra (str or numeric) – Right ascension coordinate.

  • dec (str or numeric) – Declination coordinate.

Returns:

Tuple containing the checked and possibly modified right ascension and declination.

Return type:

tuple

scubes.utilities.io.convert_coord_to_degrees(ra, dec, frame='icrs')

Convert the input celestial coordinates to degrees.

Parameters:
  • ra (str or numeric) – Right ascension coordinate.

  • dec (str or numeric) – Declination coordinate.

  • frame (str, optional) – Reference frame for the coordinates. Defaults to ‘icrs’.

Returns:

Tuple containing the right ascension and declination converted to degrees.

Return type:

tuple

scubes.utilities.io.print_level(msg, level=0, verbose=0)

Print a message with a specified verbosity level.

Parameters:
  • msg (str) – The message to be printed.

  • level (int, optional) – The verbosity level of the message. Defaults to 0.

  • verbose (int, optional) – The overall verbosity level. Messages with verbosity levels less than or equal to this value will be printed. Defaults to 0.

scubes.utilities.io.read_first_line(filename)

Return the first non-commented record of the given filename.

Parameters:

filename (str) – The name of the file for which to get the first record.

Returns:

The first non-commented record found in the given filename.

Return type:

str

scubes.utilities.plots module

scubes.utilities.plots.crop3D(filename, hfrac_crop=None, wfrac_crop=None, output_filename=None)

Crops a 3D image by specified height and width fractions.

Parameters:
  • filename (str) – Path to the image file to be cropped.

  • hfrac_crop (list of float, optional) – List containing two values that define the fractional crop limits for height, where 0 is the start and 1 is the end (default is [0, 1] which means no cropping in height).

  • wfrac_crop (list of float, optional) – List containing two values that define the fractional crop limits for width, where 0 is the start and 1 is the end (default is [0, 1] which means no cropping in width).

  • output_filename (str, optional) – Path to save the cropped image. If None, the image is not saved (default is None).

Returns:

The cropped image array.

Return type:

np.ndarray

Notes

  • The function reads the image, crops it according to the fractional limits specified for height and width, and returns the cropped image. If output_filename is provided, the cropped image is saved to that file.

  • Fractional cropping values should be between 0 and 1, where 0 represents the beginning and 1 the full length.

scubes.utilities.plots.fmagr(x, w, p)
scubes.utilities.plots.plot_extra_sources(xsource, filename=None)
scubes.utilities.plots.plot_mask(detection_image, lupton_rgb, masked_ddata, resulting_mask, sewregions, daoregions=None, save_fig=False, prefix_filename=None, fig=None)

Plot a mosaic showing various images and regions related to source detection and masking.

Parameters:
  • detection_image (str) – The path to the FITS file containing the detection image.

  • lupton_rgb (array-like) – The RGB image array used for plotting.

  • masked_ddata (array-like) – The masked detection image data.

  • resulting_mask (array-like) – The resulting mask array.

  • sewregions (list of CirclePixelRegion) – List of regions around sources detected by SExtractor.

  • daoregions (list of CirclePixelRegion, optional) – List of regions around sources detected by DAOStarFinder. Defaults to None.

  • save_fig (bool, optional) – If True, save the figure as an image file. Defaults to False.

  • prefix_filename (str, optional) – The prefix for the saved figure filename. Defaults to ‘OBJECT’.

  • fig (matplotlib.figure.Figure, optional) – The existing figure to use. If None, a new figure will be created. Defaults to None.

Returns:

The generated figure if save_fig is False, otherwise None.

Return type:

matplotlib.figure.Figure or None

scubes.utilities.plots.plot_masks_final_plot(scube, masks_builder)
scubes.utilities.plots.plot_masks_psf(RGB__yxc, apertures, mask_Ha, mask_star__yx, fig=None)
scubes.utilities.plots.plot_psf(psf__bsxy, filename=None)
scubes.utilities.plots.plot_scube_RGB_mask_sky(scube, masks_builder)
scubes.utilities.plots.plot_violin_reescaled_error_spectrum(scube, masks_builder)
class scubes.utilities.plots.scube_plots(filename, block=False)

Bases: object

Class for creating various plots from SCUBE data (spectral cubes).

This class provides methods to generate different types of plots, including images of flux, magnitude, signal-to-noise ratios, sky flux, and integrated spectra. It also supports 3D flux visualization, LRGB image creation, and contour plotting.

Parameters:
  • filename (str) – The path to the FITS file containing the SCUBE data.

  • block (bool, optional) – If True, blocks the execution of plots until they are closed (default is False).

scube_filename

Path to the SCUBE file being processed.

Type:

str

scube

Instance of the read_scube class, containing the data from the FITS file.

Type:

read_scube

block

Whether plots are blocked or not.

Type:

bool

filter_colors

Array of colors corresponding to each filter in the SCUBE.

Type:

np.ndarray

aur

The golden ratio (used for figure aspect ratios).

Type:

float

readscube(filename)

Reads the SCUBE data from the specified FITS file.

images_plot(img_lyx, mask_yx=None, suptitle=None, output_filename=None, cmap='Spectral_r', vminmax=None)

Plots a set of images for each filter in the data cube.

images_mag_plot(output_filename=None, cmap='Spectral')

Plots magnitude images for each filter in the data cube.

images_emag_plot(output_filename=None, cmap='Spectral')

Plots error magnitude images for each filter in the data cube.

images_flux_plot(output_filename=None, cmap='Spectral_r')

Plots flux images for each filter in the data cube in log scale.

images_eflux_plot(output_filename=None, cmap='Spectral_r')

Plots flux error images for each filter in the data cube in log scale.

images_SN_plot(output_filename=None, cmap='Spectral_r')

Plots signal-to-noise (S/N) images for each filter in the data cube.

images_skyflux_plot(sky, output_filename=None, cmap='Spectral_r')

Plots sky flux images based on the provided sky data.

images_3D_plot(output_filename=None, FOV=140)

Creates a 3D scatter plot of the flux data cube with respect to wavelength.

LRGB_plot(output_filename=None, \*\*kw_rgb)

Creates an LRGB image from the data cube.

LRGB_spec_plot(output_filename=None, i_x0=None, i_y0=None)

Plots a spectrum with an associated LRGB image at a given pixel position.

LRGB_centspec_plot(output_filename=None)

Plots a spectrum with an associated LRGB image at the central pixel.

SN_filters_plot(output_filename=None, SN_range=None, valid_mask__yx=None, bins=50)

Plots histograms of the signal-to-noise ratio (S/N) for each filter.

sky_spec_plot(sky, output_filename=None)

Plots the sky spectrum based on the provided sky data.

rings_spec_plot(output_filename=None, pa=0, ba=1, theta=None, rad_scale=1, mode='mean', sky_mask=None, rad_mask=None)

Plots the spectrum of concentric rings from the center of the object.

contour_plot(output_filename=None, contour_levels=None)

Plots contour levels over the r-band magnitude image.

int_area_spec_plot(output_filename=None, pa_deg=0, ba=1, R_pix=50)

Plots the integrated area spectrum for a specified elliptical region.

LRGB_centspec_plot(output_filename=None)

Plots a spectrum with an associated LRGB image at the central pixel.

Parameters:

output_filename (str, optional) – Path to save the output figure (default is None).

LRGB_plot(output_filename=None, **kw_rgb)

Creates an LRGB image from the data cube.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • **kw_rgb (dict, optional) – Additional keyword arguments for controlling the LRGB image creation. See scubes.utilities.readscube.read_scubes.lRGB_image for help on the arguments.

LRGB_spec_plot(output_filename=None, i_x0=None, i_y0=None)

Plots a spectrum with an associated LRGB image at a given pixel position.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • i_x0 (int, optional) – x-coordinate of the pixel (default is None).

  • i_y0 (int, optional) – y-coordinate of the pixel (default is None).

SN_filters_plot(output_filename=None, SN_range=None, valid_mask__yx=None, bins=50)

Plots histograms of the signal-to-noise ratio (S/N) for each filter.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • SN_range (list, optional) – Range of S/N values to display (default is [0, 10]).

  • valid_mask__yx (np.ndarray, optional) – Mask indicating valid pixels (default is None).

  • bins (int, optional) – Number of bins to use for the histogram (default is 50).

contour_plot(output_filename=None, contour_levels=None)

Plots contour levels over the r-band magnitude image.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • contour_levels (list, optional) – List of contour levels to plot (default is [21, 23, 24]).

images_3D_plot(output_filename=None, FOV=140)

Creates a 3D scatter plot of the flux data cube with respect to wavelength.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • FOV (float, optional) – Field of view (FOV) for the 3D projection (default is 140 degrees).

images_SN_plot(output_filename=None, cmap='Spectral_r')

Plots signal-to-noise (S/N) images for each filter in the data cube.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • cmap (str, optional) – Colormap to use for the images (default is ‘Spectral_r’).

images_eflux_plot(output_filename=None, cmap='Spectral_r')

Plots flux error images for each filter in the data cube in log scale.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • cmap (str, optional) – Colormap to use for the images (default is ‘Spectral_r’).

images_emag_plot(output_filename=None, cmap='Spectral')

Plots error magnitude images for each filter in the data cube.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • cmap (str, optional) – Colormap to use for the images (default is ‘Spectral’).

images_flux_plot(output_filename=None, cmap='Spectral_r')

Plots flux images for each filter in the data cube in log scale.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • cmap (str, optional) – Colormap to use for the images (default is ‘Spectral_r’).

images_mag_plot(output_filename=None, cmap='Spectral')

Plots magnitude images for each filter in the data cube.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • cmap (str, optional) – Colormap to use for the images (default is ‘Spectral’).

images_plot(img__lyx, mask__yx=None, suptitle=None, output_filename=None, cmap='Spectral_r', vminmax=None)

Plots a set of images for each filter in the data cube.

Parameters:
  • img__lyx (np.ndarray) – 3D array with image data for each filter.

  • mask__yx (np.ndarray, optional) – 2D mask to apply to the images (default is None).

  • suptitle (str, optional) – Title to display above the figure (default is None).

  • output_filename (str, optional) – Path to save the output figure (default is None).

  • cmap (str, optional) – Colormap to use for the images (default is ‘Spectral_r’).

  • vminmax (list of float, optional) – Minimum and maximum values for the colormap (default is None).

images_skyflux_plot(sky, output_filename=None, cmap='Spectral_r')

Plots sky flux images based on the provided sky data.

Parameters:
  • sky (dict) – Sky data dictionary returned from a sky estimation function.

  • output_filename (str, optional) – Path to save the output figure (default is None).

  • cmap (str, optional) – Colormap to use for the images (default is ‘Spectral_r’).

int_area_spec_plot(output_filename=None, pa_deg=0, ba=1, R_pix=50)

Plots the integrated area spectrum for a specified elliptical region.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • pa_deg (float, optional) – Position angle in degrees (default is 0).

  • ba (float, optional) – Axis ratio (default is 1).

  • R_pix (int, optional) – Radius in pixels for the integration area (default is 50).

readscube(filename)

Reads the SCUBE data from the specified FITS file.

Parameters:

filename (str) – Path to the FITS file to read.

rings_spec_plot(output_filename=None, pa=0, ba=1, theta=None, object_HLR=10, rad_scale=1, mode='mean', sky_mask=None, rad_mask=None)

Plots the spectrum of concentric rings from the center of the object.

Parameters:
  • output_filename (str, optional) – Path to save the output figure (default is None).

  • pa (float, optional) – Position angle in radians (default is 0).

  • ba (float, optional) – Axis ratio (default is 1).

  • theta (float, optional) – Ellipse rotation angle in degrees (default is None).

  • object_HLR (float, optional) – Determines the object size to create the radial bins. The function will create 10 pixels bins up to 5*object_HLR. (default is 10)

  • rad_scale (float, optional) – Scaling factor for radial distances (default is 1).

  • mode (str, optional) – Mode for calculating the profile (‘mean’ or ‘median’, default is ‘mean’).

  • sky_mask (np.ndarray, optional) – Mask for the sky pixels (default is None).

  • rad_mask (np.ndarray, optional) – Radial mask (default is None).

sky_spec_plot(sky, output_filename=None)

Plots the sky spectrum based on the provided sky data.

Parameters:
  • sky (dict) – Sky data dictionary returned from a sky estimation function.

  • output_filename (str, optional) – Path to save the output figure (default is None).

scubes.utilities.readscube module

scubes.utilities.readscube.get_distance(x, y, x0, y0, pa=0.0, ba=1.0)

Return an image (numpy.ndarray) of the distance from the center (x0, y0) in pixels, assuming a projected disk.

Parameters:
  • x (array) – X coordinates to get the pixel distances.

  • y (array) – y coordinates to get the pixel distances.

  • x0 (float) – X coordinate of the origin.

  • y0 (float) – Y coordinate of the origin.

  • pa (float, optional) – Position angle in radians, counter-clockwise relative to the positive X axis.

  • ba (float, optional) – Ellipticity, defined as the ratio between the semiminor axis and the semimajor axis (\(b/a\)).

Returns:

pixel_distance – Pixel distances.

Return type:

array

scubes.utilities.readscube.get_image_distance(shape, x0, y0, pa=0.0, ba=1.0)

Return an image (numpy.ndarray) of the distance from the center (x0, y0) in pixels, assuming a projected disk.

Parameters:
  • shape ((float, float)) – Shape of the image to get the pixel distances.

  • x0 (float) – X coordinate of the origin.

  • y0 (float) – Y coordinate of the origin.

  • pa (float, optional) – Position angle in radians, counter-clockwise relative to the positive X axis. Defaults to 0.0.

  • ba (float, optional) – Ellipticity, defined as the ratio between the semiminor axis and the semimajor axis (\(b/a\)). Defaults to 1.0.

Returns:

pixel_distance – Image containing the distances.

Return type:

2-D array

See also

get_distance()

scubes.utilities.readscube.make_RGB_tom(flux__lyx, rgb=(7, 5, 9), rgb_f=(1, 1, 1), pminmax=(5, 95), im_max=255, minimum=(0, 0, 0), Q=0, stretch=10)
scubes.utilities.readscube.radial_profile(prop, bin_r, x0, y0, pa=0.0, ba=1.0, rad_scale=1.0, mask=None, mode='mean', return_npts=False)

Calculate the radial profile of an N-D image.

Parameters:
  • prop (array) – Image of property to calculate the radial profile.

  • bin_r (array) – Semimajor axis bin boundaries in units of rad_scale.

  • x0 (float) – X coordinate of the origin.

  • y0 (float) – Y coordinate of the origin.

  • pa (float, optional) – Position angle in radians, counter-clockwise relative to the positive X axis.

  • ba (float, optional) – Ellipticity, defined as the ratio between the semiminor axis and the semimajor axis (\(b/a\)).

  • rad_scale (float, optional) – Scale of the bins, in pixels. Defaults to 1.0.

  • mask (array, optional) – Mask containing the pixels to use in the radial profile. Must be bidimensional and have the same shape as the last two dimensions of prop. Default: no mask.

  • mode (string, optional) –

    One of:
    • 'mean': Compute the mean inside the radial bins (default).

    • 'median': Compute the median inside the radial bins.

    • 'sum': Compute the sum inside the radial bins.

    • 'var': Compute the variance inside the radial bins.

    • 'std': Compute the standard deviation inside the radial bins.

  • return_npts (bool, optional) – If set to True, also return the number of points inside each bin. Defaults to False.

Returns:

  • radProf ([masked] array) – Array containing the radial profile as the last dimension. Note that radProf.shape[-1] == (len(bin_r) - 1) If prop is a masked aray, this and npts will be a masked array as well.

  • npts ([masked] array, optional) – The number of points inside each bin, only if return_npts is set to True.

class scubes.utilities.readscube.read_scube(filename)

Bases: object

Class for reading and processing data from an astronomical data cube (SCUBE).

Parameters:

filename (str) – The path to the FITS file to be read and processed.

filename

The path to the FITS file.

Type:

str

_hdulist

The list of HDU (Header Data Units) from the FITS file.

Type:

astropy.io.fits.HDUList

wcs

The World Coordinate System (WCS) for the data.

Type:

astropy.wcs.WCS

cent_coord

The central sky coordinates of the object.

Type:

astropy.coordinates.SkyCoord

x0, y0

Pixel coordinates of the central sky position.

Type:

float

i_x0, i_y0

Integer pixel coordinates of the central sky position.

Type:

int

mag_arcsec2__lyx

The magnitude per square arcsecond for each layer in the data cube.

Type:

np.ndarray

emag_arcsec2__lyx

The error in the magnitude per square arcsecond.

Type:

np.ndarray

pa, ba

Position angle (pa) and axis ratio (ba) for pixel distance calculations.

Type:

float

pixel_distance__yx

Pixel distance array from the central coordinate, adjusted by pa and ba.

Type:

np.ndarray

mask_stars_filename

Filename for the star mask generated in source_extractor().

Type:

str

detection_image_filename

Filename for the detection image used in source_extractor().

Type:

str

mask_stars_hdul

The HDUList containing the star mask data.

Type:

astropy.io.fits.HDUList

detection_image_hdul

The HDUList containing the detection image data.

Type:

astropy.io.fits.HDUList

_read()

Reads the FITS file and loads the data.

_init_wcs()

Initializes the WCS (World Coordinate System) for the data.

_init_centre()

Calculates the central coordinates of the object in pixel space.

_mag_values()

Computes magnitude values and their errors for each layer in the data cube.

_init()

Initializes WCS, central coordinates, and magnitude values.

lRGB_image(rgb, rgb_f, pminmax, im_max, minimum, Q, stretch)

Creates an RGB image from the data cube using specified filters.

source_extractor(sextractor, username, password, class_star, satur_level, back_size, detect_thresh, estimate_fwhm, force, verbose)

Runs source extraction using SExtractor on the data cube.

get_iso_sky(isophotal_limit, isophotal_medsize, stars_mask, n_sigma, n_iter, clip_neg)

Estimates the sky flux from the data cube using isophotal limits.

mask_optimal()

Generates a mask for optimal data handling based on flux and error values.

property SN__lyx
property central_wave
property data_header
property dec
property eflux__lyx
property emag__lyx
property filters
property flux__lyx
property galaxy
generate_masked_cube(mask_stars_bands=7, mask_stars_threshold=20, xsource_std_f=2, mask_isophotal_medsize=30, mask_isophotal_limit=24, sky_isophotal_medsize=30, sky_isophotal_limit=25, star_size_calc='sky', star_fwhm_individual_calc=False, extra_pix=5, sky_n_sigma=3, sky_n_iter=5, sky_clip_neg=False, no_interact=False)
get_filter_i(filt)
get_iso_sky(ref_mag_filt='rSDSS', isophotal_limit=25, isophotal_medsize=10, stars_mask=None, n_sigma=3, n_iter=5, clip_neg=False)

Estimates the sky flux using isophotal limits and clipping outliers in the flux data.

Parameters:
  • ref_mag_filt (str or int, optional) – Filter name or index number for the reference magnitude for the isophotal limits evaluation.

  • isophotal_limit (float, optional) – Threshold value for selecting sky pixels (default is 25).

  • isophotal_medsize (int, optional) – Size of the median filter for smoothing the mask (default is 10).

  • stars_mask (np.ndarray, optional) – Mask indicating the positions of stars (default is None).

  • n_sigma (float, optional) – Sigma clipping threshold (default is 3).

  • n_iter (int, optional) – Number of iterations for sigma clipping (default is 5).

  • clip_neg (bool, optional) – If True, clip negative and positive outliers (default is False).

Returns:

Dictionary containing the sky flux information and masks.

Return type:

dict

lRGB_image(rgb=('rSDSS', 'gSDSS', 'iSDSS'), rgb_f=(1, 1, 1), pminmax=(5, 95), im_max=255, minimum=(0, 0, 0), Q=0, stretch=10)

Creates an RGB image from the data cube using specified filters.

Parameters:
  • rgb (tuple of str or tuple of int, optional) – Tuple specifying the filters to use for the red, green, and blue channels (default is (‘rSDSS’, ‘gSDSS’, ‘iSDSS’)).

  • rgb_f (tuple of float, optional) – Scaling factors for the red, green, and blue channels (default is (1, 1, 1)).

  • pminmax (tuple of int, optional) – Percentiles for scaling the RGB intensities (default is (5, 95)).

  • im_max (int, optional) – Maximum intensity value for the RGB image (default is 255).

  • minimum (tuple of float, optional) – Minimum values for scaling the RGB channels (default is (0, 0, 0)).

  • Q (float, optional) – Parameter for controlling the contrast in the Lupton RGB scaling (default is 0).

  • stretch (float, optional) – Stretch factor for enhancing the RGB intensities (default is 10).

Returns:

3D array representing the RGB image with shape (height, width, 3).

Return type:

np.ndarray

property mag__lyx
mask_optimal()

Creates an optimal mask for the data cube based on flux, error, and weight information.

The mask is generated by checking the following conditions: - The weight image (weimask__lyx) is greater than zero. - The flux values are non-negative. - The error values are finite.

Returns:

A boolean array where True indicates valid pixels (not masked) and False indicates masked pixels.

Return type:

np.ndarray

property metadata
property n_filters
property n_x
property n_y
property pivot_wave
property pixscale
property primary_header
property psf_fwhm
property ra
property size
source_extractor(sextractor, username, password, class_star=0.25, satur_level=1600, back_size=64, detect_thresh=1.1, estimate_fwhm=False, force=False, verbose=0)

Runs source extraction on the data cube using SExtractor.

Parameters:
  • sextractor (str) – Path to the SExtractor executable.

  • username (str) – Username for accessing cloud services or external databases.

  • password (str) – Password for accessing cloud services or external databases.

  • class_star (float, optional) – Threshold for classifying objects as stars (default is 0.25).

  • satur_level (float, optional) – Saturation level for the image (default is 1600).

  • back_size (int, optional) – Background size parameter for SExtractor (default is 64).

  • detect_thresh (float, optional) – Detection threshold for SExtractor (default is 1.1).

  • estimate_fwhm (bool, optional) – If True, estimate the full width at half maximum (FWHM) of sources (default is False).

  • force (bool, optional) – If True, force re-running source extraction (default is False).

  • verbose (int, optional) – Verbosity level of the source extraction process (default is 0).

property tile
property weimask__lyx
property weimask__yx
property x0tile
property y0tile
class scubes.utilities.readscube.tupperware_none

Bases: Namespace

scubes.utilities.sextractor module

scubes.utilities.sextractor.SEWregions(sewcat, shape, class_star, verbose=0)

Generate circular regions based on SExtractor output.

Parameters:
  • sewcat (sewpy.output.SExtractor) – SExtractor catalog result.

  • shape (tuple) – Shape of the image (height, width).

  • class_star (float) – CLASS_STAR threshold for star/galaxy separation.

  • verbose (int, optional) – Verbosity level. Defaults to 0.

Returns:

List of circular regions.

Return type:

list of regions.CirclePixelRegion

scubes.utilities.sextractor.run_sex(sex_path, detection_fits, input_config, output_params, work_dir=None, output_file=None, overwrite=True, verbose=0)

Run SExtractor on the given FITS file.

Parameters:
  • sex_path (str) – Path to the SExtractor executable.

  • detection_fits (str) – Path to the input FITS file for detection.

  • input_config (str) – Path to the SExtractor configuration file.

  • output_params (list) – List of output parameters for SExtractor.

  • work_dir (str, optional) – Working directory for SExtractor. Defaults to None (current directory).

  • output_file (str, optional) – Path to the output catalog FITS file. Defaults to None.

  • overwrite (bool, optional) – Whether to overwrite the output file if it already exists. Defaults to True.

  • verbose (int, optional) – Verbosity level. Defaults to 0.

Returns:

SExtractor catalog result.

Return type:

sewpy.output.SExtractor

scubes.utilities.sextractor.unmask_sewregions(data, sewregions, size, unmask_stars=None, verbose=0)

Unmask circular regions in the given data.

Parameters:
  • data (numpy.ndarray) – Input image data.

  • sewregions (list of regions.CirclePixelRegion) – List of circular regions.

  • size (int) – Size of the image.

  • unmask_stars (list, optional) – List of indices to exclude from unmasking. Defaults to None.

  • verbose (int, optional) – Verbosity level. Defaults to 0.

Returns:

Tuple containing masked data (numpy.ndarray) and resulting mask (numpy.ndarray).

Return type:

tuple

scubes.utilities.sky module

scubes.utilities.sky.get_iso_sky(refmag__yx, flux__lyx, isophotal_limit=25, isophotal_medsize=10, stars_mask=None, n_sigma=3, n_iter=5, clip_neg=False)

Estimate the sky flux by masking stars and clipping outliers in the flux data.

Parameters:
  • refmag__yx (np.ndarray) – 2D array of reference magnitudes used for creating the isophotal mask.

  • flux__lyx (np.ndarray) – 3D array of flux values, where the first axis corresponds to different layers (e.g., different filters or exposures) and the last two axes correspond to spatial dimensions (y, x).

  • isophotal_limit (float, optional) – The threshold value for the reference magnitude used to mask sky pixels (default is 25).

  • isophotal_medsize (int, optional) – Size of the window used for the median filter when smoothing the mask (default is 10).

  • stars_mask (np.ndarray, optional) – 2D boolean array where 1 indicates a star, and 0 means no star (default is None).

  • n_sigma (float, optional) – The threshold number of standard deviations to use for clipping outliers in sky flux values (default is 3).

  • n_iter (int, optional) – The number of iterations to perform for sigma clipping to remove outliers (default is 5).

  • clip_neg (bool, optional) – If True, clip both negative and positive outliers. If False, only clip positive outliers (default is False).

Returns:

sky – Dictionary containing the following fields:

  • ’isophotal_limit’float

    The isophotal limit used for the sky mask.

  • ’isophotal_medsize’int

    The median filter window size used to smooth the sky mask.

  • ’flux__lyx’np.ma.MaskedArray

    The 3D array of sky flux values with outliers masked.

  • ’mask__yx’np.ndarray

    2D boolean array where True indicates sky pixels, False indicates non-sky pixels.

  • ’mean__l’np.ndarray

    1D array of mean sky flux values for each layer.

  • ’median__l’np.ndarray

    1D array of median sky flux values for each layer.

  • ’std__l’np.ndarray

    1D array of standard deviation of sky flux values for each layer.

Return type:

dict

Notes

The sky mask is created by masking pixels where the reference magnitude is below a certain threshold and applying a median filter to smooth the mask. The function then iteratively clips outliers in the flux data using sigma clipping. Sky flux values for each layer (e.g., different filters or exposures) are stored in a masked array to exclude outliers.

scubes.utilities.splusdata module

scubes.utilities.splusdata.connect_splus_cloud(username=None, password=None)

Connect to the S-PLUS Cloud service.

Parameters:
  • username (str, optional) – The username for S-PLUS Cloud authentication.

  • password (str, optional) – The password for S-PLUS Cloud authentication.

Returns:

An instance of the S-PLUS Cloud connection (splusdata.Core) or None if the authentication fails after three attempts.

Return type:

splusdata.Core or None

scubes.utilities.splusdata.detection_image_hdul(conn, wcs=False, **kwargs)

Retrieve the detection image from the S-PLUS Cloud service.

Parameters:
  • conn (splusdata.Core) – An instance of the S-PLUS Cloud connection.

  • wcs (bool, optional) – If True, update the header with World Coordinate System (WCS) information. Default is False.

  • **kwargs (dict) – Additional keyword arguments to be passed to conn.stamp_detection().

Returns:

An HDUList containing a PrimaryHDU and an ImageHDU representing the detection image. If wcs is True, the header of the ImageHDU is updated with WCS information.

Return type:

astropy.io.fits.HDUList

scubes.utilities.splusdata.get_lupton_rgb(conn, transpose=False, save_img=False, filename=None, **kwargs)

Retrieve an RGB image using the Lupton algorithm from the S-PLUS Cloud service.

Parameters:
  • conn (splusdata.Core) – An instance of the S-PLUS Cloud connection.

  • transpose (bool, optional) – If True, transpose the RGB image. Default is False.

  • save_img (bool, optional) – If True, save the RGB image to a file. Default is False.

  • filename (str, optional) – The filename to save the RGB image if save_img is True. If None, the default filename is ‘OBJECT.png’.

  • **kwargs (dict) – Additional keyword arguments to be passed to conn.lupton_rgb().

Returns:

An RGB image represented as a PIL Image object.

Return type:

PIL.Image.Image

scubes.utilities.stats module

scubes.utilities.stats.robustStat(arr, sigma=3, iters=5, med=False)

Computes various robust statistics for an input array.

Parameters:
  • arr (numpy array) – The input array.

  • sigma (float, optional) – The number of standard deviations allowed for data to be considered as an outlier. Defaults to 3.

  • iters (int, optional) – The number of iterations to perform the outlier rejection process. Defaults to 5.

  • med (bool, optional) – If True, use the median absolute deviation (MAD) instead of the standard deviation for outlier rejection. Defaults to False.

Returns:

A dictionary containing the maximum, minimum, mean, median, standard deviation, fraction of rejected data points, robust standard deviation (nmad), and robust standard deviation (rms) of the input array.

Return type:

dict

scubes.utilities.utils module

scubes.utilities.utils.get_lupton_RGB()

Entry-point function for downloading S-PLUS RGB images.

Return type:

None

scubes.utilities.utils.get_lupton_RGB_argsparse(args)

A particular parser of the command-line arguments for get_lupton_RGB entry-point script.

Parameters:

args (argparse.Namespace) – Command-line arguments parsed by argparse.ArgumentParser.parse_args()

Returns:

Command-line arguments parsed.

Return type:

argparse.Namespace

scubes.utilities.utils.ml2header()

Entry-point function to add the masterlist information to the primary header of a S-CUBES original cube.

Raises:

SystemExit – If some input paths are not existent or present some problem or if the primary header of the cube FITS miss some needed information, like the S-CUBES name information.

Return type:

None

scubes.utilities.utils.ml2header_argparse(args)

A particular parser of the command-line arguments for ml2header entry-point script.

Parameters:

args (argparse.Namespace) – Command-line arguments parsed by argparse.ArgumentParser.parse_args()

Returns:

Command-line arguments parsed.

Return type:

argparse.Namespace

scubes.utilities.utils.ml2header_updheader(cube_filename, ml_table, force=False)

Updates a S-CUBES raw cube primary header with the masterlist information.

Parameters:
  • cube_filename (str) – Path to S-CUBES raw cube.

  • ml_table (astropy.table.table.Table) – Masterlist read using astropy.io.ascii.read()

  • force (bool, optional) – Force the update the key value is the key is existent at the S-CUBES header.

scubes.utilities.utils.scube_mask()
scubes.utilities.utils.scube_sex_mask_stars()

Uses S-PLUS detection image and SExtractor to identify stars on the FOV. This entry-point script uses a S-Cube as input to gather the needed information to the retrieve the correct detection image stamp.

Raises:

SystemExit – If the detection file exists.

Return type:

None

scubes.utilities.utils.scube_sex_mask_stars_argsparse(args)

A particular parser of the command-line arguments for scube_sex_mask_stars_cube entry-point script.

Parameters:

args (argparse.Namespace) – Command-line arguments parsed by argparse.ArgumentParser.parse_args()

Returns:

Command-line arguments parsed.

Return type:

argparse.Namespace

scubes.utilities.utils.sky_or_int(arg)
scubes.utilities.utils.splots()

Entry-point function to generate plots from a SCUBE.

Return type:

None