def wvcal_spectrum(sp, fxpeaks, poly_degree_wfit, wv_master,
                   wv_ini_search=None, wv_end_search=None,
                   wvmin_useful=None, wvmax_useful=None,
                   geometry=None, debugplot=0):
    """Execute wavelength calibration of a spectrum using fixed line peaks.

    Parameters
    ----------
    sp : 1d numpy array
        Spectrum to be wavelength calibrated.
    fxpeaks : 1d numpy array
        Refined location of peaks in array index scale, i.e, from 0
        to naxis1 - 1. The wavelength calibration is performed using
        these line locations.
    poly_degree_wfit : int
        Degree for wavelength calibration polynomial.
    wv_master : 1d numpy array
        Array with arc line wavelengths.
    wv_ini_search : float or None
        Minimum expected wavelength in spectrum.
    wv_end_search : float or None
        Maximum expected wavelength in spectrum.
    wvmin_useful : float or None
        If not None, this value is used to clip detected lines below it.
    wvmax_useful : float or None
        If not None, this value is used to clip detected lines above it.
    geometry : tuple (4 integers) or None
        x, y, dx, dy values employed to set the Qt backend geometry.
    debugplot : int
        Determines whether intermediate computations and/or plots
        are displayed. The valid codes are defined in
        numina.array.display.pause_debugplot.

    Returns
    -------
    solution_wv : instance of SolutionArcCalibration
        Wavelength calibration solution.

    """

    # check there are enough lines for fit
    if len(fxpeaks) <= poly_degree_wfit:
        print(">>> Warning: not enough lines to fit spectrum")
        return None

    # spectrum dimension
    naxis1 = sp.shape[0]

    wv_master_range = wv_master[-1] - wv_master[0]
    delta_wv_master_range = 0.20 * wv_master_range
    if wv_ini_search is None:
        wv_ini_search = wv_master[0] - delta_wv_master_range
    if wv_end_search is None:
        wv_end_search = wv_master[-1] + delta_wv_master_range

    # use channels (pixels from 1 to naxis1)
    xchannel = fxpeaks + 1.0

    # wavelength calibration
    list_of_wvfeatures = arccalibration(
        wv_master=wv_master,
        xpos_arc=xchannel,
        naxis1_arc=naxis1,
        crpix1=1.0,
        wv_ini_search=wv_ini_search,
        wv_end_search=wv_end_search,
        wvmin_useful=wvmin_useful,
        wvmax_useful=wvmax_useful,
        error_xpos_arc=3,
        times_sigma_r=3.0,
        frac_triplets_for_sum=0.50,
        times_sigma_theil_sen=10.0,
        poly_degree_wfit=poly_degree_wfit,
        times_sigma_polfilt=10.0,
        times_sigma_cook=10.0,
        times_sigma_inclusion=10.0,
        geometry=geometry,
        debugplot=debugplot
    )

    title = "Wavelength calibration"
    solution_wv = fit_list_of_wvfeatures(
        list_of_wvfeatures=list_of_wvfeatures,
        naxis1_arc=naxis1,
        crpix1=1.0,
        poly_degree_wfit=poly_degree_wfit,
        weighted=False,
        plot_title=title,
        geometry=geometry,
        debugplot=debugplot
    )

    if abs(debugplot) % 10 != 0:
        # final plot with identified lines
        xplot = np.arange(1, naxis1 + 1, dtype=float)
        ax = ximplotxy(xplot, sp, title=title, show=False,
                       xlabel='pixel (from 1 to NAXIS1)',
                       ylabel='number of counts',
                       geometry=geometry)
        ymin = sp.min()
        ymax = sp.max()
        dy = ymax-ymin
        ymin -= dy/20.
        ymax += dy/20.
        ax.set_ylim([ymin, ymax])
        # plot wavelength of each identified line
        for feature in solution_wv.features:
            xpos = feature.xpos
            reference = feature.reference
            ax.text(xpos, sp[int(xpos+0.5)-1],
                    str(reference), fontsize=8,
                    horizontalalignment='center')
        # show plot
        print('Plot with identified lines')
        pause_debugplot(12, pltshow=True)

    # return the wavelength calibration solution
    return solution_wv
def wvcal_spectrum ( sp , fxpeaks , poly_degree_wfit , wv_master , wv_ini_search = None , wv_end_search = None , wvmin_useful = None , wvmax_useful = None , geometry = None , debugplot = 0 ) : if len ( fxpeaks ) <= poly_degree_wfit : print ( ">>> Warning: not enough lines to fit spectrum" ) return None naxis1 = sp . shape [ 0 ] wv_master_range = wv_master [ - 1 ] - wv_master [ 0 ] delta_wv_master_range = 0.20 * wv_master_range if wv_ini_search is None : wv_ini_search = wv_master [ 0 ] - delta_wv_master_range if wv_end_search is None : wv_end_search = wv_master [ - 1 ] + delta_wv_master_range xchannel = fxpeaks + 1.0 list_of_wvfeatures = arccalibration ( wv_master = wv_master , xpos_arc = xchannel , naxis1_arc = naxis1 , crpix1 = 1.0 , wv_ini_search = wv_ini_search , wv_end_search = wv_end_search , wvmin_useful = wvmin_useful , wvmax_useful = wvmax_useful , error_xpos_arc = 3 , times_sigma_r = 3.0 , frac_triplets_for_sum = 0.50 , times_sigma_theil_sen = 10.0 , poly_degree_wfit = poly_degree_wfit , times_sigma_polfilt = 10.0 , times_sigma_cook = 10.0 , times_sigma_inclusion = 10.0 , geometry = geometry , debugplot = debugplot ) title = "Wavelength calibration" solution_wv = fit_list_of_wvfeatures ( list_of_wvfeatures = list_of_wvfeatures , naxis1_arc = naxis1 , crpix1 = 1.0 , poly_degree_wfit = poly_degree_wfit , weighted = False , plot_title = title , geometry = geometry , debugplot = debugplot ) if abs ( debugplot ) % 10 != 0 : xplot = np . arange ( 1 , naxis1 + 1 , dtype = float ) ax = ximplotxy ( xplot , sp , title = title , show = False , xlabel = 'pixel (from 1 to NAXIS1)' , ylabel = 'number of counts' , geometry = geometry ) ymin = sp . min ( ) ymax = sp . max ( ) dy = ymax - ymin ymin -= dy / 20. ymax += dy / 20. ax . set_ylim ( [ ymin , ymax ] ) for feature in solution_wv . features : xpos = feature . xpos reference = feature . reference ax . text ( xpos , sp [ int ( xpos + 0.5 ) - 1 ] , str ( reference ) , fontsize = 8 , horizontalalignment = 'center' ) print ( 'Plot with identified lines' ) pause_debugplot ( 12 , pltshow = True ) return solution_wv
Execute wavelength calibration of a spectrum using fixed line peaks.

    Parameters
    ----------
    sp : 1d numpy array
        Spectrum to be wavelength calibrated.
    fxpeaks : 1d numpy array
        Refined location of peaks in array index scale, i.e, from 0
        to naxis1 - 1. The wavelength calibration is performed using
        these line locations.
    poly_degree_wfit : int
        Degree for wavelength calibration polynomial.
    wv_master : 1d numpy array
        Array with arc line wavelengths.
    wv_ini_search : float or None
        Minimum expected wavelength in spectrum.
    wv_end_search : float or None
        Maximum expected wavelength in spectrum.
    wvmin_useful : float or None
        If not None, this value is used to clip detected lines below it.
    wvmax_useful : float or None
        If not None, this value is used to clip detected lines above it.
    geometry : tuple (4 integers) or None
        x, y, dx, dy values employed to set the Qt backend geometry.
    debugplot : int
        Determines whether intermediate computations and/or plots
        are displayed. The valid codes are defined in
        numina.array.display.pause_debugplot.

    Returns
    -------
    solution_wv : instance of SolutionArcCalibration
        Wavelength calibration solution.