pypeit.find_objects module

Main driver class for object finding, global skysubtraction and skymask construction

class pypeit.find_objects.EchelleFindObjects(sciImg, slits, spectrograph, par, objtype, **kwargs)[source]

Bases: FindObjects

Child of Reduce for Echelle reductions

See parent doc string for Args and Attributes

find_objects_pypeline(image, ivar, std_trace=None, show=False, show_peaks=False, show_fits=False, show_trace=False, save_objfindQA=False, neg=False, debug=False, manual_extract_dict=None)[source]

Pipeline specific find objects routine

Parameters:
  • image (numpy.ndarray) – Image to search for objects from. This floating-point image has shape (nspec, nspat) where the first dimension (nspec) is spectral, and second dimension (nspat) is spatial.

  • std_trace (numpy.ndarray, optional) – This is a one dimensional float array with shape = (nspec,) containing the standard star trace which is used as a crutch for tracing. If the no standard star is provided the code uses the the slit boundaries as the crutch.

  • manual_extract_dict (dict, optional) – Dict guiding the manual extraction

  • show_peaks (bool, optional) – Generate QA showing peaks identified by object finding

  • show_fits (bool, optional) – Generate QA showing fits to traces

  • show_trace (bool, optional) – Generate QA showing traces identified. Requires an open ginga RC modules window

  • save_objfindQA (bool, optional) – Save to disk (png file) QA showing the object profile

  • neg (bool, optional) – Is this a negative image?

  • show (bool, optional) –

  • debug (bool, optional) –

Returns:

  • specobjs (SpecObjs) – Container holding Specobj objects

  • nobj (int) – Number of objects identified

get_platescale(slitord_id=None)[source]

Return the platescale in binned pixels for the current detector/echelle order

Parameters:

slitord_id (int, optional) – slit spat_id (MultiSlit, SlicerIFU) or ech_order (Echelle) value

Returns:

plate scale in binned pixels

Return type:

float

class pypeit.find_objects.FindObjects(sciImg, slits, spectrograph, par, objtype, wv_calib=None, waveTilts=None, tilts=None, initial_skymask=None, bkg_redux=False, find_negative=False, std_redux=False, show=False, clear_ginga=True, basename=None, manual=None)[source]

Bases: object

Base class used to find objects and perform global sky subtraction for science or standard-star exposures.

Parameters:
  • sciImg (PypeItImage) – Image to reduce.

  • slits (SlitTraceSet) – Object providing slit traces for the image to reduce.

  • spectrograph (Spectrograph) – PypeIt Spectrograph class

  • par (PypeItPar) – Reduction parameters class

  • objtype (str) – Specifies object being reduced. Should be ‘science’, ‘standard’, or ‘science_coadd2d’.

  • wv_calib (WaveCalib, optional) – This is only used for the SlicerIFUFindObjects child when a joint sky subtraction is requested.

  • waveTilts (WaveTilts, optional) – Calibration frame with arc/sky line tracing of the wavelength tilt. Only waveTilts or tilts is needed (not both).

  • tilts (numpy.ndarray, optional) – Tilts frame produced by fit2tiltimg() for given a spatial flexure. Only waveTilts or tilts is needed (not both).

  • initial_skymask (numpy.ndarray, optional) – Boolean array that selects (array elements are True) image pixels in sky regions. If provided, the 2nd pass on the global sky subtraction is omitted.

  • bkg_redux (bool, optional) – If True, the sciImg has been subtracted by a background image (e.g. standard treatment in the IR)

  • find_negative (bool, optional) – If True, the negative objects are found

  • std_redux (bool, optional) – If True, the object being extracted is a standard star, so that the reduction parameters can be adjusted accordingly.

  • show (bool, optional) – Show plots along the way?

  • clear_ginga (bool, optional) – Clear the ginga window before showing the object finding results.

  • basename (str, optional) – Base name for output files

  • manual (ManualExtractionObj, optional) – Object containing manual extraction instructions/parameters.

ivarmodel

Model of inverse variance

Type:

numpy.ndarray

objimage

Model of object

Type:

numpy.ndarray

skyimage

Final model of sky

Type:

numpy.ndarray

initial_sky

Initial sky model after first pass with global_skysub()

Type:

numpy.ndarray

global_sky

Fit to global sky

Type:

numpy.ndarray

skymask

Mask of the sky fit

Type:

numpy.ndarray

outmask

Final output mask

Type:

numpy.ndarray

extractmask

Extraction mask

Type:

numpy.ndarray

slits
Type:

SlitTraceSet

sobjs_obj

Objects found

Type:

pypeit.specobjs.SpecObjs

spat_flexure_shift
Type:

float

tilts

WaveTilts images generated on-the-spot

Type:

numpy.ndarray

waveimg

WaveImage image generated on-the-spot

Type:

numpy.ndarray

slitshift

Global spectral flexure correction for each slit (in pixels)

Type:

numpy.ndarray

vel_corr

Relativistic reference frame velocity correction (e.g. heliocentyric/barycentric/topocentric)

Type:

float

create_skymask(sobjs_obj)[source]

Creates a skymask from a SpecObjs object

Parameters:

sobjs_obj (pypeit.specobjs.SpecObjs) – Objects for which you would like to create the mask

Returns:

Boolean image with shape \((N_{\rm spec}, N_{\rm spat})\) indicating which pixels are usable for global sky subtraction. True = usable for sky subtraction, False = should be masked when sky subtracting.

Return type:

numpy.ndarray

find_objects(image, ivar, std_trace=None, show_peaks=False, show_fits=False, show_trace=False, show=False, save_objfindQA=True, manual_extract_dict=None, debug=False)[source]

Single pass at finding objects in the input image

If self.find_negative is True, do a search for negative objects too

Parameters:
  • image (numpy.ndarray) – Image to search for objects from. This floating-point image has shape (nspec, nspat) where the first dimension (nspec) is spectral, and second dimension (nspat) is spatial.

  • std_trace (numpy.ndarray, optional) – This is a one dimensional float array with shape = (nspec,) containing the standard star trace which is used as a crutch for tracing. If the no standard star is provided the code uses the the slit boundaries as the crutch.

  • show_peaks (bool, optional) – Generate QA showing peaks identified by object finding

  • show_fits (bool, optional) – Generate QA showing fits to traces

  • show_trace (bool, optional) – Generate QA showing traces identified. Requires an open ginga RC modules window

  • show (bool, optional) – Show all the QA

  • save_objfindQA (bool, optional) – Save to disk (png file) QA showing the object profile

  • manual_extract_dict (dict, optional) – This is only used by 2D coadd

  • debug (bool, optional) – Show debugging plots?

Returns:

  • sobjs_obj_single (SpecObjs) – Objects found

  • nobj_single (int) – Number of objects found

find_objects_pypeline(image, ivar, std_trace=None, show_peaks=False, show_fits=False, show_trace=False, show=False, save_objfindQA=False, neg=False, debug=False, manual_extract_dict=None)[source]

Dummy method for object finding. Overloaded by class specific object finding.

Returns:

classmethod get_instance(sciImg, slits, spectrograph, par, objtype, wv_calib=None, waveTilts=None, tilts=None, initial_skymask=None, bkg_redux=False, find_negative=False, std_redux=False, show=False, clear_ginga=True, basename=None, manual=None)[source]

Instantiate and return the FindObjects subclass appropriate for the provided spectrograph.

For argument descriptions, see FindObjects.

get_platescale(slitord_id=None)[source]

Return the platescale in binned pixels for the current detector/echelle order

Over-loaded by the children

Parameters:

slitord_id (int, optional) – slit spat_id (MultiSlitFindObjects, SlicerIFUFindObjects) or ech_order (EchelleFindObjects) value.

Returns:

plate scale in binned pixels

Return type:

float

global_skysub(skymask=None, update_crmask=True, previous_sky=None, show_fit=False, show=False, show_objs=False, objs_not_masked=False, reinit_bpm: bool = True)[source]

Perform global sky subtraction, slit by slit

Wrapper to skysub.global_skysub

Parameters:
  • skymask (numpy.ndarray, optional) – A 2D image indicating sky regions (1=sky)

  • update_crmask (bool, optional) – Update the crmask in the science image

  • show_fit (bool, optional) – Show the sky fits?

  • show (bool, optional) – Show the sky image generated?

  • show_objs (bool, optional) – If show=True, show the objects on the sky image?

  • previous_sky (numpy.ndarray, optional) – Sky model estimate from a previous run of global_sky Used to generate an improved estimated of the variance

  • objs_not_masked (bool, optional) – Set this to be True if there are objects on the slit/order that are not being masked by the skymask. This is typically the case for the first pass sky-subtraction before object finding, since a skymask has not yet been created.

  • reinit_bpm (bool, optional) – If True (default), the bpm is reinitialized to the initial bpm Should be False on the final run in case there was a failure upstream and no sources were found in the slit/order

Returns:

image of the the global sky model

Return type:

numpy.ndarray

initialize_slits(slits, initial=False)[source]

Gather all the SlitTraceSet attributes that we’ll use here in FindObjects

Parameters:
  • slits (SlitTraceSet) – SlitTraceSet object containing the slit boundaries that will be initialized.

  • initial (bool, optional) – Use the initial definition of the slits. If False, tweaked slits are used.

run(std_trace=None, show_peaks=False, show_skysub_fit=False)[source]

Primary code flow for object finding in PypeIt reductions

Parameters:
  • std_trace (numpy.ndarray, optional) – Trace of the standard star

  • show_peaks (bool, optional) – Show peaks in find_objects methods

  • show_skysub_fit (bool, optional) – Show the fits for the global sky subtraction

Returns:

  • initial_sky (numpy.ndarray) – Initial global sky model

  • sobjs_obj (SpecObjs) – List of objects found

show(attr, image=None, global_sky=None, showmask=False, sobjs=None, chname=None, slits=False, clear=False)[source]

Show one of the internal images

Todo

  • This docstring is incomplete!

Parameters:
  • attr (str) –

    String specifying the image to show. Options are:
    • global – Sky model (global)

    • sci – Processed science image

    • rawvar – Raw variance image

    • modelvar – Model variance image

    • crmasked – Science image with CRs set to 0

    • skysub – Science image with global sky subtracted

    • image – Input image

  • image (ndarray, optional) – User supplied image to display

class pypeit.find_objects.MultiSlitFindObjects(sciImg, slits, spectrograph, par, objtype, **kwargs)[source]

Bases: FindObjects

Child of Reduce for Multislit and Longslit reductions

See parent doc string for Args and Attributes

find_objects_pypeline(image, ivar, std_trace=None, manual_extract_dict=None, show_peaks=False, show_fits=False, show_trace=False, show=False, save_objfindQA=False, neg=False, debug=False)[source]

Pipeline specific find objects routine

Parameters:
  • image (numpy.ndarray) – Image to search for objects from. This floating-point image has shape (nspec, nspat) where the first dimension (nspec) is spectral, and second dimension (nspat) is spatial.

  • std_trace (numpy.ndarray, optional) – This is a one dimensional float array with shape = (nspec,) containing the standard star trace which is used as a crutch for tracing. If the no standard star is provided the code uses the the slit boundaries as the crutch.

  • manual_extract_dict (dict, optional) – Dict guiding the manual extraction

  • show_peaks (bool, optional) – Generate QA showing peaks identified by object finding

  • show_fits (bool, optional) – Generate QA showing fits to traces

  • show_trace (bool, optional) – Generate QA showing traces identified. Requires an open ginga RC modules window

  • show (bool, optional) – Show all the QA

  • save_objfindQA (bool, optional) – Save to disk (png file) QA showing the object profile

  • neg (bool, optional) – Is this a negative image?

  • debug (bool, optional) – Show debugging plots?

Returns:

  • specobjs (SpecObjs) – Container holding Specobj objects

  • nobj (int) – Number of objects identified

get_platescale(slitord_id=None)[source]

Return the platescale in binned pixels for the current detector/echelle order

Parameters:

slitord_id (int, optional) – slit spat_id (MultiSlit, SlicerIFU) or ech_order (Echelle) value

Returns:

plate scale in binned pixels

Return type:

float

class pypeit.find_objects.SlicerIFUFindObjects(sciImg, slits, spectrograph, par, objtype, **kwargs)[source]

Bases: MultiSlitFindObjects

Child of Reduce for SlicerIFU reductions

See parent doc string for Args and Attributes

apply_relative_scale(scaleImg)[source]

Apply a relative scale to the science frame (and correct the varframe, too)

Parameters:

scaleImg (numpy.ndarray) – scale image to divide the science frame by

calculate_flexure(global_sky)[source]

Convenience function to calculate the flexure of an IFU. The flexure is calculated by cross-correlating the sky model of a reference slit with an archival sky spectrum. This gives an “absolute” flexure correction for the reference slit in pixels. Then, the flexure for all other slits is calculated by cross-correlating the sky model of each slit with the sky model of the reference slit. This gives a “relative” flexure correction for each slit in pixels. The relative flexure is then added to the absolute flexure to give the total flexure correction for each slit in pixels.

Parameters:

global_sky (ndarray) – Sky model

Returns:

new_slitshift – The flexure in pixels

Return type:

ndarray

global_skysub(skymask=None, update_crmask=True, previous_sky=None, show_fit=False, show=False, show_objs=False, objs_not_masked=False, reinit_bpm: bool = True)[source]

Perform global sky subtraction. This SlicerIFU-specific routine ensures that the edges of the slits are not trimmed, and performs a spatial and spectral correction using the sky spectrum, if requested. See Reduce.global_skysub() for parameter definitions.

See base class method for description of parameters.

Parameters:

reinit_bpm (bool, optional) – If True (default), the bpm is reinitialized to the initial bpm Should be False on the final run in case there was a failure upstream and no sources were found in the slit/order

initialize_slits(slits, initial=True)[source]

Gather all the SlitTraceSet attributes that we’ll use here in FindObjects. Identical to the parent but the slits are not trimmed.

Parameters:
  • slits (SlitTraceSet) – SlitTraceSet object containing the slit boundaries that will be initialized.

  • initial (bool, optional) – Use the initial definition of the slits. If False, tweaked slits are used.

joint_skysub(skymask=None, update_crmask=True, trim_edg=(0, 0), show_fit=False, show=False, show_objs=False, adderr=0.01, objs_not_masked=False)[source]

Perform a joint sky model fit to the data. See Reduce.global_skysub() for parameter definitions.