pypeit.core.gui.identify module

class pypeit.core.gui.identify.Identify(canvas, axes, spec, specres, detns, line_lists, par, lflag_color, slit=0, spatid='0', wv_calib=None, pxtoler=None, specname='', y_log=True, rescale_resid=False)[source]

Bases: object

GUI to interactively identify arc lines. The GUI can be run within PypeIt during data reduction, or as a standalone script outside of PypeIt. To initialise the GUI, call the initialise() function in this file.

add_new_detection()[source]

Perform a local Gaussian fit to the pixels near the mouse cursor. If the fit is accetable, a new line will be added to the detections provided that the line is not too close to another line already in the detections list.

auto_id()[source]

Automatically assign lines based on a few lines identified by the user

Using the current line IDs and approximate wavelength solution, automatically assign a wavelength to all line detections.

button_press_callback(event)[source]

What to do when the mouse button is pressed

Parameters:

event (matplotlib.backend_bases.Event) – Matplotlib event instance containing information about the event

button_release_callback(event)[source]

What to do when the mouse button is released

Parameters:

event (matplotlib.backend_bases.Event) – Matplotlib event instance containing information about the event

delete_line_id()[source]

Remove an incorrect line ID

draw_callback(event)[source]

Draw the lines and annotate with their IDs

Parameters:

event (matplotlib.backend_bases.Event) – A matplotlib event instance

draw_fitregions(trans)[source]

Refresh the fit regions

Parameters:

trans (AxisTransform) – A matplotlib axis transform from data to axes coordinates

draw_ghost()[source]

Draw tick marks at the location of the ghost

draw_lines()[source]

Draw the lines and annotate with their IDs

draw_residuals()[source]

Update the subplots that show the residuals

fitsol_deriv(xfit=None, idx=None)[source]

Calculate the dispersion as a function of wavelength

Parameters:
  • xfit (numpy.ndarray, float) – Pixel values that the user wishes to evaluate the wavelength

  • idx (int) – Index of the arc line detections that the user wishes to evaluate the wavelength

Returns:

The dispersion (Angstroms/pixel) as a function of wavelength

Return type:

ndarray, float

fitsol_fit()[source]

Perform a fit to the line identifications

fitsol_value(xfit=None, idx=None)[source]

Calculate the wavelength at a pixel

Parameters:
  • xfit (numpy.ndarray, float) – Pixel values that the user wishes to evaluate the wavelength

  • idx (numpy.ndarray, int) – Index of the arc line detections that the user wishes to evaluate the wavelength

Returns:

disp – The wavelength (Angstroms) of the requested pixels

Return type:

numpy.ndarray, float

get_ann_ypos(scale=1.02)[source]

Calculate the y locations of the annotated IDs

Parameters:

scale (float) – Scale the location relative to the maximum value of the spectrum

Returns:

y locations of the annotations

Return type:

numpy.ndarray

get_axisID(event)[source]

Get the ID of the axis where an event has occurred

Parameters:

event (matplotlib.backend_bases.Event) – Matplotlib event instance containing information about the event

Returns:

Axis where the event has occurred

Return type:

int

get_detns()[source]

Get the index of the detection closest to the cursor

get_ind_under_point(event)[source]

Get the index of the line closest to the cursor

Parameters:

event (matplotlib.backend_bases.Event) – Matplotlib event instance containing information about the event

Returns:

Index of the spectrum where the event occurred

Return type:

int

get_results()[source]

Perform the final wavelength calibration

Using the line IDs perform the final fit according to the wavelength calibration parameters set by the user. This routine must be called after the user has manually identified all lines.

Returns:

Dict of wavelength calibration solutions

Return type:

dict

classmethod initialise(arccen, lamps, slits, slit=0, par=None, wv_calib_all=None, wavelim=None, nonlinear_counts=None, test=False, pxtoler=0.1, fwhm=4.0, specname='', y_log=True, sigdetect=None, rescale_resid=False)[source]

Initialise the ‘Identify’ window for real-time wavelength calibration

Todo

  • Implement multislit functionality

Parameters:
  • arccen (numpy.ndarray) – Arc spectrum

  • lamps (list) – List of arc lamps to be used for wavelength calibration. E.g., [‘ArI’,’NeI’,’KrI’,’XeI’]

  • slits (SlitTraceSet) – Data container with slit trace information

  • slit (int, optional) – The slit to be used for wavelength calibration

  • par (int, optional) – The slit to be used for wavelength calibration

  • wv_calib_all (dict, None, optional) – If a best-fitting solution exists, and you wish to load it, provide the wv_calib dictionary.

  • wavelim (list, None, optional) – A two element list containing the desired minimum and maximum wavelength of the linelist

  • test (bool, optional) – If True, do not show the plots

  • nonlinear_counts (float, optional) – Counts where the arc is presumed to go non-linear Passed to arc_lines_from_spec() Defaults to 1e10 if None is input

  • fwhm (float, optional) – FWHM of arc lines in pixels for detection

  • sigdetect (float, optional) – sigma detection limit for arc lines; defaults to par[‘sigdetect’]

  • pxtoler (float, optional) – Tolerance in pixels for adding lines with the auto option

  • specname (str, optional) – The name of the spectrograph

  • y_log (bool, optional) – Scale the Y-axis logarithmically instead of linearly? (Default: True)

  • rescale_resid (bool, optional) – Rescale the residuals plot to include all points? (Default: False)

Returns:

object – Returns an instance of the Identify class, which contains the results of the fit

Return type:

Identify

key_press_callback(event)[source]

What to do when a key is pressed

Parameters:

event (matplotlib.backend_bases.Event) – Matplotlib event instance containing information about the event

linelist_init()[source]

Initialise the linelist Slider (used to assign a line to a detection)

linelist_select(event)[source]

Assign a wavelength to a detection

Note, only the LMB works.

Parameters:

event (matplotlib.backend_bases.Event) – A matplotlib event instance

linelist_update(val)[source]

For a given detection, set the linelist value to be the best guess based on the wavelength solution

When a user selects a detection, reset the current value of the linelist to reflect the best candidate wavelength for that detection (given the current wavelength solution)

Parameters:

val (int) – The index corresponding to the closest match

load_IDs(wv_calib=None, fname='waveid.ascii')[source]

Load line IDs

motion_notify_event(event)[source]
operations(key, axisID, event)[source]

Canvas operations

Parameters:
  • key (str) – Which key has been pressed

  • axisID (int) – The index of the axis where the key has been pressed (see get_axisID)

print_help()[source]

Print the keys and descriptions that can be used for Identification

replot()[source]

Redraw the entire canvas

save_IDs(fname='waveid.ascii')[source]

Save the current IDs

store_solution(final_fit, binspec, rmstol=0.15, force_save=False, wvcalib=None, multi=False, fits_dicts=None, specdata_multi=None, slits=None, lines_pix_arr=None, lines_wav_arr=None, lines_fit_ord=None, custom_wav=None, custom_wav_ind=None)[source]

Check if the user wants to store this solution in the reid arxiv, when doing the wavelength solution for multiple traces

Parameters:
  • final_fit (dict) – Dict of wavelength calibration solutions (see self.get_results())

  • binspec (int) – Spectral binning

  • rmstol (float, optional) – RMS tolerance allowed for the wavelength solution to be stored in the archive

  • force_save (bool, optional) – Force save

  • multi (bool, optional) – Flag if the template has multiple slits/traces.

  • fits_dict (list, optional) – List of dictionaries containing the _fitdict of previous calls, if multi-trace data

  • specdata_multi (array, optional) – Numpy array containing the flux information from all the traces, if multiple traces are being fit.

  • wvcalib (pypeit.wavecalib.WaveCalib, optional) – Wavelength solution

  • lines_pix_arr (array, optional) – Numpy array containing the pixel locations of all ID’d lines

  • lines_wav_arr (array, optional) – Numpy array containing wavelengths of all the ID’d lines

Returns:

wvarxiv_name – The name of the wvarxiv file if saved. “None” if not saved

Return type:

str

toggle_wavepix(toggled=False)[source]
toggle_yscale()[source]
update_ghosts()[source]

Update the ghosts

update_infobox(message="Press '?' to list the available options", yesno=True, default=False)[source]

Send a new message to the information window at the top of the canvas

Parameters:

message (str) – Message to be displayed

update_line_id()[source]

Find the nearest wavelength in the linelist

update_regions()[source]

Update the regions used to fit Gaussian