Example #1
0
def source_to_unknowns(source, write=False, verbose=True, min_ampl=0.):
    """
    Parameters
    ----------
    source
    write
    min_ampl : float (optional)
      Minimum amplitude for a new UNKNOWN

    Returns
    -------

    """

    # Load
    src_dict = load_source.load(source)
    U_lines = src_dict['U_lines']

    # Cut on amplitude
    print("Cutting UNKNOWNs on min_ampl")
    U_lines = U_lines[U_lines['amplitude'] > min_ampl]
    src_dict['U_lines'] = U_lines

    # UNKNWN lines
    if U_lines is None:
        return

    # Unique ions
    uions = arcl_utils.unique_ions(source, src_dict=src_dict)

    # Check against 'complete' NIST and our line lists
    mask, _ = arcl_utils.vette_unkwn_against_lists(U_lines,
                                                   uions,
                                                   verbose=verbose)
    if np.sum(mask) == 0:
        return

    if not os.path.isfile(unk_file):  # Generate?
        if write:
            print("Generating line list:\n   {:s}".format(unk_file))
            unknwn_list = create_line_list(U_lines[mask > 0],
                                           source['File'],
                                           source['Instr'],
                                           unknown=True,
                                           ions=uions)
            arcl_io.write_line_list(unknwn_list, unk_file)
    else:  # Update
        unknwn_list, updated = update_uline_list(U_lines[mask > 0],
                                                 source['File'],
                                                 source['Instr'], uions)
        if write and updated:
            arcl_io.write_line_list(unknwn_list, unk_file)
    # Return
    return unknwn_list
Example #2
0
def source_to_line_lists(source, write=False, llist_dict=None):
    """
    Parameters
    ----------
    source
    write
    scratch : bool, optional
      Build from scratch -- EXPERTS ONLY

    Returns
    -------

    """
    if llist_dict is None:  # For building without writing
        llist_dict = {}
    # Parse
    src_dict = load_source.load(source)
    # Check
    if src_dict['ID_lines'] is None:
        print("No IDs in source: {:s}".format(source['File']))
        return llist_dict

    # Unique ions
    uions = arcl_utils.unique_ions(source, src_dict=src_dict)

    # Loop on ID ions
    for ion in uions:
        ion_file = llist_path + '{:s}_lines.dat'.format(ion)
        # Parse
        idx = src_dict['ID_lines']['ion'] == ion
        sub_tbl = src_dict['ID_lines'][idx]
        # Generate?
        if (not os.path.isfile(ion_file)) and (ion not in llist_dict.keys()):
            # New
            llist_dict[ion] = create_line_list(sub_tbl, source['File'],
                                               source['Instr'])
            if not write:
                print("Would generate line list:\n   {:s}".format(ion_file))
            else:
                print("Generating line list:\n   {:s}".format(ion_file))
                arcl_io.write_line_list(llist_dict[ion], ion_file)
        else:
            if ion not in llist_dict.keys():
                raise KeyError(
                    "You are trying to build from scratch but didn't remove {:s}"
                    .format(ion_file))
            llist_dict[ion], updated = update_line_list(
                llist_dict[ion], sub_tbl, source['File'], source['Instr'])
            # Write
            if write and updated:
                arcl_io.write_line_list(llist_dict[ion], ion_file)
    # Return
    return llist_dict
Example #3
0
def by_hand(llist_dict, write=False):
    """
    Returns
    -------

    """
    # By-hand
    print("=============================================================")
    print("Adding lines by hand!")
    print("=============================================================")
    handIDs = arcl_io.load_by_hand()
    uhions = np.unique(handIDs['ion'].data)
    # Loop on ID ions
    for ion in uhions:
        # Parse
        idx = handIDs['ion'] == ion
        sub_tbl = handIDs[idx]
        # Update only
        llist_dict[ion], updated = update_line_list(llist_dict[ion], sub_tbl, None, None)
        if write and updated:
            ion_file = llist_path+'{:s}_lines.dat'.format(ion)
            arcl_io.write_line_list(llist_dict[ion], ion_file)
Example #4
0
def purge_unknowns(line_list, write=False, tol_llist=2., verbose=True):

    line_dict = defs.lines()
    # Load
    unknwns = arcl_io.load_unknown_list([], all=True)
    mask = np.array([True] * len(unknwns))
    updated = False
    # Loop
    for ss, row in enumerate(unknwns):
        dwv = np.abs(line_list['wave'] - row['wave'])
        imin = np.argmin(np.abs(dwv))
        # Match?
        if dwv[imin] < tol_llist:
            line_flag = line_dict[line_list['ion'][imin]]
            if row['line_flag'] % (2 * line_flag) >= line_flag:
                mask[ss] = False
                updated = True
                if verbose:
                    print("Will purge UNKNOWN line \n {}".format(row))
                    print("Matched to \n {}".format(line_list[imin]))
    # Write?
    if write and updated:
        arcl_io.write_line_list(unknwns[mask], unk_file)