Data objects

Cutout containers (CutoutData, MultiBandCutout) and the HDF5 (de)serialisation helpers used by the pipeline.

exception sphot.data.DebugException(message, debug_var)[source]

Bases: Exception

exception sphot.data.DegenerateCutoutError[source]

Bases: ValueError

Raised when a CutoutData step cannot proceed because the cutout is too degenerate (e.g. mostly-NaN data, insufficient finite isophote samples, or a required intermediate attribute hasn’t been produced yet). Subclass of ValueError so existing except ValueError: handlers keep working; SLURM array tasks can catch this specifically to skip + record the cutout instead of aborting.

sphot.data.calc_mag(counts_Mjy_per_Sr, errors_Mjy_per_Sr=None, pixel_scale=0.03)[source]
class sphot.data.CutoutData(data=None, psf=None, psf_oversample=None, filtername=None, **kwargs)[source]

Bases: object

fix_psf()[source]

make sure the sum of PSF is 1

calc_psf_sigma()[source]

estimate Gaussian sigma-equivalent size of the PSF

blur_psf(psf_blurring=None)[source]

blur the PSF

determine_psf_blurring()[source]

determine the best PSF blurring value based on the number of stars detected

plot()[source]
init_size_guess(sigma_guess=10, center_slack=0.2, plot=False, sigma_kernel=5, clip_lower_counts_percentile=10, **kwargs)[source]

roughly estimate the effective radius using Gaussian profile.

Parameters:
  • sigma_guess (float) – initial guess for the standard deviation of the Gaussian profile (in pixels)

  • center_slack (float) – the fraction of the image size (from center) within which the center of the galaxy is expected. Default is 5%

Returns:

float – rough estimate of the effective radius (in pixels)

remove_bkg(bkg_level)[source]
perform_bkg_stats(plot=False)[source]
remove_sky(fit_to='residual_masked', remove_from='psf_sub_data', **kwargs)[source]
fit_sky(fit_to='residual_masked', poly_deg=1, radius_in=7, width=7, plot=False, **kwargs)[source]
class sphot.data.MultiBandCutout(name=None, **kwargs)[source]

Bases: object

a container for CutoutData. Includes some useful methods for handling multiple bands of the same object.

add_image(filtername, data)[source]
property images
property image_list
plot(attr='data', title='', show=True, **kwargs)[source]
set_size(size)[source]
crop_in(x0, y0, size)[source]

crop-in and re-generate the MultiBandCutout object.

Parameters:
  • multiband_obj (MultiBandCutout) – the object to crop in

  • x0,y0 (float) – the center of the new image

  • size (int) – the size of the new image (in pixels)

Returns:

galaxy_crop (MultiBandCutout) – the cropped object

save(filepath)[source]

save the MultiBandCutout object to a h5 file

fill_nans(isophot_base_filter, fit_isophot_to='data', isophot_frac_min=0.05, isophot_frac_max=0.95, apply_to='residual', fill_max_nan_frac=0.5, fill_replace_with='sersic_modelimg')[source]

fill NaNs in all bands using isophotal apertures from a base filter.

sphot.data.read(filepath, **kwargs)[source]

a convenient wrapper for loading h5 files. It can load both sphot h5 files and raw data h5 files.

sphot.data.load_h5data(filepath, name='', filters=[], psffile=None, psf_oversample=4)[source]

load raw data h5 file and turn it into a MultiBandCutout object.

sphot.data.get_data_annulus(data, aper_r, plot=True, flatten=True)[source]

extract flattened data outside the annulus

sphot.data.str_to_json(s)[source]

encode string to json-readable format. This is a helper function for saving h5 files.

sphot.data.decode_if_bytestring(val)[source]

reverse of str_to_json

sphot.data.load_sphotfile(filepath)[source]

alias to read_sphot_h5

sphot.data.read_sphot_h5(filepath)[source]

load sphot h5 file and turn it into an sphot object