Image Reduction API

class aspired.image_reduction.ImageReduction(verbose=True, logger_name='ImageReduction', log_level='INFO', log_file_folder='default', log_file_name=None)[source]

This class is not intented for quality data reduction, it exists for completeness such that users can produce a minimal pipeline with a single pacakge. Users should preprocess calibration frames, for example, we cannot properly combine arc frames taken with long and short exposures for wavelength calibration with both bright and faint lines; fringing correction with flat frames; light frames with various exposure times.

The initialisation only sets up the logger.

Parameters:
  • verbose (boolean (Default: True)) – Set to False to suppress all verbose warnings, except for critical failure.
  • logger_name (str (Default: ImageReduction)) – This will set the name of the logger, if the name is used already, it will reference to the existing logger. This will be the first part of the default log file name unless log_file_name is provided.
  • log_level (str (Default: 'INFO')) – Four levels of logging are available, in decreasing order of information and increasing order of severity: (1) DEBUG, (2) INFO, (3) WARNING, (4) ERROR and (5) CRITICAL. WARNING means that there is suboptimal operations in some parts of that step. ERROR means that the requested operation cannot be performed, but the software can handle it by either using the default setting or skipping the operation. CRITICAL means that the requested operation cannot be resolved without human interaction, this is most usually coming from missing data.
  • log_file_folder (None or str (Default: "default")) – Folder in which the file is save, set to default to save to the current path.
  • log_file_name (None or str (Default: None)) – File name of the log, set to None to print to screen only.
add_arc(arc, header)[source]

Add the arc frame.

Parameters:
  • arc (2-d array or CCDData object) – The arc image
  • header (astropy header object) – The FITS header
add_bias(bias, header)[source]

Add the bias frame.

Parameters:
  • bias (2-d array or CCDData object) – The bias image
  • header (astropy header object) – The FITS header
add_dark(dark, header, exposure_time)[source]

Add the dark frame.

Parameters:
  • dark (2-d array or CCDData object) – The dark image
  • header (astropy header object) – The FITS header
  • exposure_time (float) – The exposure time of the frame.
add_filelist(filelist, ftype='csv', delimiter=None)[source]

If a field-flattened 2D spectrum is already avaialble, it can be the only listed item. Set it as a ‘light’ frame.

Parameters:
  • filelist (str) – File location, does not support URL
  • ftype (str (Default: "csv")) – One of csv, tsv and ascii. Default is csv.
  • delimiter (str (Default: None)) – Set the delimiter. This overrides ftype.
add_flat(flat, header, exposure_time)[source]

Add the flat frame.

Parameters:
  • flat (2-d array or CCDData object) – The flat image
  • header (astropy header object) – The FITS header
  • exposure_time (float) – The exposure time of the frame.
add_light(light, header, exposure_time)[source]

Add the light frame.

Parameters:
  • light (2-d array or CCDData object) – The light image (i.e. science/target frame)
  • header (astropy header object) – The FITS header
  • exposure_time (float) – The exposure time of the frame.
combine_arc(combinetype_arc=None, sigma_clipping_arc=None, clip_low_arc=None, clip_high_arc=None)[source]

Combine the arc frames. The parameters provide here OVERRIDE those set previously. Use with caution.

combine_bias(combinetype_bias=None, sigma_clipping_bias=None, clip_low_bias=None, clip_high_bias=None)[source]

Combine the bias frames. The parameters provide here OVERRIDE those set previously. Use with caution.

combine_dark(combinetype_dark=None, sigma_clipping_dark=None, clip_low_dark=None, clip_high_dark=None)[source]

Combine the dark frames. The parameters provide here OVERRIDE those set previously. Use with caution.

combine_flat(combinetype_flat=None, sigma_clipping_flat=None, clip_low_flat=None, clip_high_flat=None)[source]

Combine the flat frames. The parameters provide here OVERRIDE those set previously. Use with caution.

combine_light(combinetype_light=None, sigma_clipping_light=None, clip_low_light=None, clip_high_light=None)[source]

Combine the light frames. The parameters provide here OVERRIDE those set previously. Use with caution.

create_bad_mask()[source]

Create mask for bad pixels, and saturated pixels.

create_bad_pixel_mask(grow=False, iterations=1, diagonal=False, create_bad_mask=True)[source]

Heal the bad pixels by taking the average of their n-nearest good neighboring pixels. See more at util.bfixpix(). If you wish to have fine control of the the bad mask creation, please use the util.create_cutoff_mask() and util.create_bad_mask() manually; or supply your own the bad masks.

Parameters:
  • grow (bool (Default: False)) – Set to True to grow the mask, see grow_mask()
  • iterations (int (Default: 1)) – The number of pixel growth along the Cartesian axes directions.
  • diagonal (bool (Default: False)) – Set to True to grow in the diagonal directions.
  • create_bad_mask (bool (Deafult: True)) – If set to True, combine the the bad_pixel_mask and saturation_mask
heal_bad_pixels(bad_mask=None, n=4)[source]

Heal the bad pixels by taking the average of their n-nearest good neighboring pixels. See more at util.bfixpix(). By default, this is not used, becase any automatic tampering of data is not a good idea.

Parameters:
  • bad_mask (numpy.ndarray) – The bad pixel mask for healing. If it is not provided, it will be computed from the reduced data.
  • n (int) – Number of nearest, good pixels to average over.
inspect(log=True, display=True, renderer='default', width=1280, height=720, return_jsonstring=False, save_fig=False, fig_type='iframe+png', filename=None, open_iframe=False)[source]

Display the reduced image with a supported plotly renderer or export as json strings.

Parameters:
  • log (bool) – Log the ADU count per second in the display. Default is True.
  • display (bool) – Set to True to display disgnostic plot.
  • renderer (str) – plotly renderer options.
  • width (int/float) – Number of pixels in the horizontal direction of the outputs
  • height (int/float) – Number of pixels in the vertical direction of the outputs
  • return_jsonstring (bool (Default: False)) – set to True to return json string that can be rendered by Plotly in any support language.
  • save_fig (bool (default: False)) – Save an image if set to True. Plotly uses the pio.write_html() or pio.write_image(). The support format types should be provided in fig_type.
  • fig_type (string (default: 'iframe+png')) – Image type to be saved, choose from: jpg, png, svg, pdf and iframe. Delimiter is ‘+’.
  • filename (str (Default: None)) – Filename for the output, all of them will share the same name but will have different extension.
  • open_iframe (bool (Default: False)) – Open the save_iframe in the default browser if set to True.
Returns:

Return type:

JSON strings if return_jsonstring is set to True.

list_files()[source]

Print the file input list.

load_data()[source]

Load the data listed in the filelist and apply the property setting as provided by the various set properties commands.

reduce()[source]

Perform data reduction using the frames provided.

save_fits(filename='reduced_image', extension='fits', overwrite=False)[source]

Save the reduced image to disk.

Parameters:
  • filename (str) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • extension (str) – File extension without the dot.
  • overwrite (bool) – Default is False.
save_masks(filename='reduced_image_mask', extension='fits', overwrite=False)[source]

Save the reduced image to disk.

Parameters:
  • filename (str) – Disk location to be written to. Default is at where the process/subprocess is execuated.
  • extension (str) – File extension without the dot.
  • overwrite (bool) – Default is False.
set_arc_properties(combinetype_arc=-1, sigma_clipping_arc=-1, clip_low_arc=-1, clip_high_arc=-1)[source]

Set the properties of the arc frame. -1 means stay the same, None means use the default value, and any other valid input for the respective argument. See set_properties() for the argument description.

set_bias_properties(combinetype_bias=-1, sigma_clipping_bias=-1, clip_low_bias=-1, clip_high_bias=-1)[source]

Set the properties of the bias frame. -1 means stay the same, None means use the default value, and any other valid input for the respective argument. See set_properties() for the argument description.

set_cosmic_properties(cosmicray=-1, fsmode=-1, psfmodel=-1, kwargs=-1)[source]

Set the properties for the cosmic ray rejection with AstroScrappy. See set_properties() for the argument description.

set_dark_properties(combinetype_dark=-1, sigma_clipping_dark=-1, clip_low_dark=-1, clip_high_dark=-1, exptime_dark=-1, exptime_dark_keyword=-1)[source]

Set the properties of the dark frame. -1 means stay the same, None means use the default value, and any other valid input for the respective argument. See set_properties() for the argument description.

set_detector_properties(gain=-1, readnoise=-1, heal_pixels=-1, cutoff=-1, grow=-1, iterations=-1, diagonal=-1)[source]

Set the properties for the detector. See set_properties() for the argument description.

set_flat_properties(combinetype_flat=-1, sigma_clipping_flat=-1, clip_low_flat=-1, clip_high_flat=-1, exptime_flat=-1, exptime_flat_keyword=-1)[source]

Set the properties of the flat frame. -1 means stay the same, None means use the default value, and any other valid input for the respective argument. See set_properties() for the argument description.

set_light_properties(combinetype_light=-1, sigma_clipping_light=-1, clip_low_light=-1, clip_high_light=-1, exptime_light=-1, exptime_light_keyword=-1)[source]

Set the properties of the light frame. -1 means stay the same, None means use the default value, and any other valid input for the respective argument. See set_properties() for the argument description.

set_properties(saxis=-1, combinetype_light=-1, sigma_clipping_light=-1, clip_low_light=-1, clip_high_light=-1, exptime_light=-1, exptime_light_keyword=-1, combinetype_arc=-1, sigma_clipping_arc=-1, clip_low_arc=-1, clip_high_arc=-1, combinetype_dark=-1, sigma_clipping_dark=-1, clip_low_dark=-1, clip_high_dark=-1, exptime_dark=-1, exptime_dark_keyword=-1, combinetype_bias=-1, sigma_clipping_bias=-1, clip_low_bias=-1, clip_high_bias=-1, combinetype_flat=-1, sigma_clipping_flat=-1, clip_low_flat=-1, clip_high_flat=-1, exptime_flat=-1, exptime_flat_keyword=-1, cosmicray=-1, gain=-1, readnoise=-1, fsmode=-1, psfmodel=-1, heal_pixels=-1, cutoff=-1, grow=-1, iterations=-1, diagonal=-1, **kwargs)[source]
Parameters:
  • sxais (int, 0 or 1 (Default: None)) – OVERRIDE the SAXIS value in the FITS header, or to provide the SAXIS if it does not exist
  • combinetype_light (str (Default: 'median')) – ‘average’ or ‘median’ for CCDproc.Combiner.average_combine() and CCDproc.Combiner.median_combine(). All the frame types follow the same combinetype.
  • sigma_clipping_light (bool (Default: True)) – Perform sigma clipping if set to True. sigma is computed with the numpy.ma.std method
  • clip_low_light (float (Default: 5)) – Set the lower threshold of the sigma clipping
  • clip_high_light (float (Default: 5)) – Set the upper threshold of the sigma clipping
  • exptime_light (float (Default: None)) – OVERRIDE the exposure time value in the FITS header, or to provide one if the keyword does not exist
  • exptime_light_keyword (str (Default: None)) – HDU keyword for the exposure time of the light frame
  • combinetype_dark (str (Default: 'median')) – ‘average’ or ‘median’ for CCDproc.Combiner.average_combine() and CCDproc.Combiner.median_combine(). All the frame types follow the same combinetype.
  • sigma_clipping_dark (bool (Default: True)) – Perform sigma clipping if set to True. sigma is computed with the numpy.ma.std method
  • clip_low_dark (float (Default: 5)) – Set the lower threshold of the sigma clipping
  • clip_high_dark (float (Default: 5)) – Set the upper threshold of the sigma clipping
  • exptime_dark (float (Default: None)) – OVERRIDE the exposure time value in the FITS header, or to provide one if the keyword does not exist
  • exptime_dark_keyword (str (Default: None)) – HDU keyword for the exposure time of the dark frame
  • combinetype_bias (str (Default: 'median')) – ‘average’ or ‘median’ for CCDproc.Combiner.average_combine() and CCDproc.Combiner.median_combine(). All the frame types follow the same combinetype.
  • sigma_clipping_bias (bool (Default: False)) – Perform sigma clipping if set to True. sigma is computed with the numpy.ma.std method
  • clip_low_bias (float (Default: 5)) – Set the lower threshold of the sigma clipping
  • clip_high_bias (float (Default: 5)) – Set the upper threshold of the sigma clipping
  • combinetype_flat (str (Default: 'median')) – ‘average’ or ‘median’ for CCDproc.Combiner.average_combine() and CCDproc.Combiner.median_combine(). All the frame types follow the same combinetype.
  • sigma_clipping_flat (bool (Default: True)) – Perform sigma clipping if set to True. sigma is computed with the numpy.ma.std method
  • clip_low_flat (float (Default: 5)) – Set the lower threshold of the sigma clipping
  • clip_high_flat (float (Default: 5)) – Set the upper threshold of the sigma clipping
  • exptime_flat (float (Default: None)) – OVERRIDE the exposure time value in the FITS header, or to provide one if the keyword does not exist
  • exptime_flat_keyword (str (Default: None)) – HDU keyword for the exposure time of the flat frame
  • cosmicray (bool (Default: False)) – Set to True to remove cosmic rays, this directly alter the reduced image data. We only explicitly include the 4 most important parameters in this function: gain, readnoise, fsmode, and psfmodel, the rest can be configured with kwargs.
  • gain (float (Default: 1.0)) – Gain of the image (electrons / ADU). We always need to work in electrons for cosmic ray detection.
  • readnoise (float (Default: 0.0)) – Read noise of the image (electrons). Used to generate the noise model of the image.
  • fsmode (str (Default: 'convolve')) – Method to build the fine structure image: median: Use the median filter in the standard LA Cosmic algorithm. convolve: Convolve the image with the psf kernel to calculate the fine structure image.
  • psfmodel (str (Default: 'gaussy')) – Model to use to generate the psf kernel if fsmode is convolve and psfk is None. The current choices are Gaussian and Moffat profiles. gauss and ‘moffat’ produce circular PSF kernels. The gaussx and gaussy produce Gaussian kernels in the x and y directions respectively. gaussxy and gaussyx apply the Gaussian kernels in the x then the y direction, and first y then x direction, respectively.
  • heal_pixels (bool (Deafult: False)) – Set to True to attempt to heal bad pixels by taking the median value of neighbouring pixels.
  • cutoff (float (Default: 60000.)) – This sets the (lower and) upper limit of electron count.
  • grow (bool (Default: False)) – Set to True to grow the mask, see grow_mask()
  • iterations (int (Default: 1)) – The number of pixel growth along the Cartesian axes directions.
  • diagonal (bool (Default: False)) – Set to True to grow in the diagonal directions.
  • **kwargs

    Extra keyword arguments for the astroscrappy.detect_cosmics: https://astroscrappy.readthedocs.io/en/latest/api/ astroscrappy.detect_cosmics.html The default setting is:

    astroscrappy.detect_cosmics(indat, inmask=None, bkg=None,
        var=None, sigclip=4.5, sigfrac=0.3, objlim=5.0, gain=1.0,
        readnoise=6.5, satlevel=65536.0, niter=4, sepmed=True,
        cleantype='meanmask', fsmode='median', psfmodel='gauss',
        psffwhm=2.5, psfsize=7, psfk=None, psfbeta=4.765,
        verbose=False)
    
set_saxis(saxis=None)[source]

Set the orientation of the image.

Parameters:saxis (0, 1 or None) – 0 for a spectrum going horizontally, 1 for vertically.