py/prospect/utilities.py
def match_rrdetails_to_spectra(redrockfile, spectra, Nfit=None):
    """ Creates a Table from a detailed Redrock output fit, matching a list of DESI spectra.

    Parameters
    ----------
    redrockfile : :class:`str`, filename for the detailed Redrock output file (.h5 file)
    spectra : :class:`~desispec.spectra.Spectra`
    Nfit : :class:`int`, optional
        Number of best-fits to store in output Table. By default, store all fits available in the detailed Redrock file

    Returns
    -------
    :class:`~astropy.table.Table`
        Table with the following columns: TARGETID, CHI2, DELTACHI2, COEFF, Z, ZERR, ZWARN, SPECTYPE, SUBTYPE.
        The rows are matched to spectra's TARGETIDs

    Raises
    ------
    RuntimeError
        If a set of Nfit rows in redrockfile is not found matching each of spectra's TARGETIDs
    """

    dummy, rr_table = redrock.results.read_zscan(redrockfile)
    rr_targets = rr_table['targetid']
    if Nfit is None:
        ww, = np.where( (rr_targets == rr_targets[0]) )
        Nfit = len(ww)
    matched_redrock_cat = Table(
        dtype=[('TARGETID', '<i8'), ('CHI2', '<f8', (Nfit,)),
               ('DELTACHI2', '<f8', (Nfit,)), ('COEFF', '<f8', (Nfit,10,)),
               ('Z', '<f8', (Nfit,)), ('ZERR', '<f8', (Nfit,)),
               ('ZWARN', '<i8', (Nfit,)), ('SPECTYPE', '<U6', (Nfit,)), ('SUBTYPE', '<U2', (Nfit,))])

    for i_spec in range(spectra.num_spectra()):
        ww, = np.where((rr_targets == spectra.fibermap['TARGETID'][i_spec]))
        if len(ww)<Nfit :
            raise RuntimeError("Redrock table cannot match spectra with "+str(Nfit)+" best fits")
        ind = np.argsort(rr_table[ww]['chi2'])[0:Nfit] # Sort fit results by chi2 (independently of spectype)
        sub_table = rr_table[ww][ind]
        the_entry = [ spectra.fibermap['TARGETID'][i_spec] ]
        for redrock_key in ['chi2', 'deltachi2', 'coeff', 'z', 'zerr', 'zwarn', 'spectype', 'subtype']:
            the_entry.append(sub_table[redrock_key])
        matched_redrock_cat.add_row(the_entry)

    return matched_redrock_cat
 Creates a Table from a detailed Redrock output fit, matching a list of DESI spectra.

    Parameters
    ----------
    redrockfile : :class:`str`, filename for the detailed Redrock output file (.h5 file)
    spectra : :class:`~desispec.spectra.Spectra`
    Nfit : :class:`int`, optional
        Number of best-fits to store in output Table. By default, store all fits available in the detailed Redrock file

    Returns
    -------
    :class:`~astropy.table.Table`
        Table with the following columns: TARGETID, CHI2, DELTACHI2, COEFF, Z, ZERR, ZWARN, SPECTYPE, SUBTYPE.
        The rows are matched to spectra's TARGETIDs

    Raises
    ------
    RuntimeError
        If a set of Nfit rows in redrockfile is not found matching each of spectra's TARGETIDs
    
Creates a Table from a detailed Redrock output fit, matching a list of DESI spectra.
Parameters



Returns
Creates a Table from a detailed Redrock output fit matching a list of DESI spectra . Parameters Returns
def match_rrdetails_to_spectra(redrockfile, spectra, Nfit=None):
    dummy, rr_table = redrock.results.read_zscan(redrockfile)
    rr_targets = rr_table['targetid']
    if Nfit is None:
        ww, = np.where( (rr_targets == rr_targets[0]) )
        Nfit = len(ww)
    matched_redrock_cat = Table(
        dtype=[('TARGETID', '<i8'), ('CHI2', '<f8', (Nfit,)),
               ('DELTACHI2', '<f8', (Nfit,)), ('COEFF', '<f8', (Nfit,10,)),
               ('Z', '<f8', (Nfit,)), ('ZERR', '<f8', (Nfit,)),
               ('ZWARN', '<i8', (Nfit,)), ('SPECTYPE', '<U6', (Nfit,)), ('SUBTYPE', '<U2', (Nfit,))])
    for i_spec in range(spectra.num_spectra()):
        ww, = np.where((rr_targets == spectra.fibermap['TARGETID'][i_spec]))
        if len(ww)<Nfit :
            raise RuntimeError("Redrock table cannot match spectra with "+str(Nfit)+" best fits")
        ind = np.argsort(rr_table[ww]['chi2'])[0:Nfit] 
        sub_table = rr_table[ww][ind]
        the_entry = [ spectra.fibermap['TARGETID'][i_spec] ]
        for redrock_key in ['chi2', 'deltachi2', 'coeff', 'z', 'zerr', 'zwarn', 'spectype', 'subtype']:
            the_entry.append(sub_table[redrock_key])
        matched_redrock_cat.add_row(the_entry)
    return matched_redrock_cat
def match_rrdetails_to_spectra ( redrockfile , spectra , Nfit = None ) : dummy , rr_table = redrock . results . read_zscan ( redrockfile ) rr_targets = rr_table [ 'targetid' ] if Nfit is None : ww , = np . where ( ( rr_targets == rr_targets [ 0 ] ) ) Nfit = len ( ww ) matched_redrock_cat = Table ( dtype = [ ( 'TARGETID' , '<i8' ) , ( 'CHI2' , '<f8' , ( Nfit , ) ) , ( 'DELTACHI2' , '<f8' , ( Nfit , ) ) , ( 'COEFF' , '<f8' , ( Nfit , 10 , ) ) , ( 'Z' , '<f8' , ( Nfit , ) ) , ( 'ZERR' , '<f8' , ( Nfit , ) ) , ( 'ZWARN' , '<i8' , ( Nfit , ) ) , ( 'SPECTYPE' , '<U6' , ( Nfit , ) ) , ( 'SUBTYPE' , '<U2' , ( Nfit , ) ) ] ) for i_spec in range ( spectra . num_spectra ( ) ) : ww , = np . where ( ( rr_targets == spectra . fibermap [ 'TARGETID' ] [ i_spec ] ) ) if len ( ww ) < Nfit : raise RuntimeError ( "Redrock table cannot match spectra with " + str ( Nfit ) + " best fits" ) ind = np . argsort ( rr_table [ ww ] [ 'chi2' ] ) [ 0 : Nfit ] sub_table = rr_table [ ww ] [ ind ] the_entry = [ spectra . fibermap [ 'TARGETID' ] [ i_spec ] ] for redrock_key in [ 'chi2' , 'deltachi2' , 'coeff' , 'z' , 'zerr' , 'zwarn' , 'spectype' , 'subtype' ] : the_entry . append ( sub_table [ redrock_key ] ) matched_redrock_cat . add_row ( the_entry ) return matched_redrock_cat
Creates a Table from a detailed Redrock output fit, matching a list of DESI spectra.
Creates a Table from a detailed Redrock output fit matching a list of DESI spectra .
""" Creates a Table from a detailed Redrock output fit, matching a list of DESI spectra.

    Parameters
    ----------
    redrockfile : :class:`str`, filename for the detailed Redrock output file (.h5 file)
    spectra : :class:`~desispec.spectra.Spectra`
    Nfit : :class:`int`, optional
        Number of best-fits to store in output Table. By default, store all fits available in the detailed Redrock file

    Returns
    -------
    :class:`~astropy.table.Table`
        Table with the following columns: TARGETID, CHI2, DELTACHI2, COEFF, Z, ZERR, ZWARN, SPECTYPE, SUBTYPE.
        The rows are matched to spectra's TARGETIDs

    Raises
    ------
    RuntimeError
        If a set of Nfit rows in redrockfile is not found matching each of spectra's TARGETIDs
    """ # Sort fit results by chi2 (independently of spectype)
redrockfile
spectra
Nfit
class


Raises

RuntimeError
If a set of Nfit rows in redrockfile is not found matching each of spectra's TARGETIDs
Raises RuntimeError If a set of Nfit rows in redrockfile is not found matching each of spectra ' s TARGETIDs