Ejemplo n.º 1
0
def MakeFLlinesDictionary(sample_size, sample_size_l, element_name,
                          fl_lines_xdb, fl_lines, probe_energy, an_lib,
                          det_energy_u, n_det_energy_bins):
    voxel_size = sample_size_l / sample_size
    FL_dic = {'element': element_name}
    fl_cs_ls = xlib_np.CS_FluorLine_Kissel_Cascade(
        np.array([an_lib[element_name]]), fl_lines, probe_energy)
    i = 0
    detected_fl_unit_concentration = np.zeros((n_det_energy_bins * 2))
    det_energy_list_full = np.linspace(
        -det_energy_u + det_energy_u / n_det_energy_bins, det_energy_u,
        n_det_energy_bins * 2)
    for name, line in xdb.xray_lines(element_name).items():
        if name in set(fl_lines_xdb):
            idx_nearest, value_nearest = find_nearest(det_energy_list_full,
                                                      line[0])
            detected_fl_unit_concentration[idx_nearest] += fl_cs_ls[0, i][0]
            i += 1
    FL_dic['detected_fl_unit'] = detected_fl_unit_concentration * voxel_size
    return FL_dic
Ejemplo n.º 2
0
def MakeFLlinesDictionary(this_aN_dic,
                          probe_energy,
                          sample_size_n,
                          sample_size_cm,
                          fl_line_groups=np.array(["K", "L", "M"]),
                          fl_K=fl_K,
                          fl_L=fl_L,
                          fl_M=fl_M,
                          group_lines=True):
    """   

        Parameters
    ----------
    this_aN_dic: dictionary
        a dictionary of items with key = element symbol (string), and value = atomic number
        e.g. this_aN_dic = {"C":6, "O": 8}

    probe_energy : ndarray
        This array is an array with only 1 element. The element is the keV energy of the incident beam.

    sample_size_n: int scalar
        sample size in number of pixles on the side along the probe propagation axis

    sample_size_cm: scalar
        sample size in cm on the side along the probe propagation axis

    fl_line_groups : ndarray of string, optional
        representing XRF line group. The default is np.array(["K", "L", "M"]).

    fl_K : ndarray, optional
        The default is fl_K, an array of sub-lines of K line with the required format by xraylib.

    fl_L : ndarray, optional
        The default is fl_L, an array of sub-lines of L line with the required format by xraylib.

    fl_M : ndarray, optional
        The default is fl_M, an array of sub-lines of M line with the required format by xraylib.

    group_lines : boolean, optional
        Whether treating all K (or L, M) sub-lines as a single line. The default is True.

    Returns
    -------
    FL_all_elements_dic : dictionary
        The dictionary has 3 items. 
        1st item 
        key: "(element_name, Line)"
        value: an ndarray of ndarrays of 2 elements(type: string), [element symbol, line group]
        e.g. [['C', 'K'], ['O', 'K'], ['Si', 'K'], ['Si', 'L']]

        2nd item
        key: "fl_energy"
        value: float, Fluorescence energy in keV for each line of all element

        3rd item: 
        key: "detected_fl_unit_concentration"
        value: a 1D array of the fluorescence ratio generated assuming unit concentration [1 g/cm^3 ] for all element in this_aN_dic
        
        4th item: 
        key: "n_line_group_each_element"
        value: an array indicating the number of fluorescence line groups for each element specified in this_aN_dictionary
        
        5th item:
        key: "n_lines"
        total number of fluorescence lines (grouped) in this system
    """

    element_ls = np.array(list(this_aN_dic.keys()))
    aN_ls = np.array(list(this_aN_dic.values()))

    n_line_group = len(fl_line_groups)
    FL_all_elements_dic = {
        "element_Line": [],
        "fl_energy": np.array([]),
        "detected_fl_unit_concentration": np.array([])
    }
    voxel_size = sample_size_cm / sample_size_n

    fl_cs_K = xlib_np.CS_FluorLine_Kissel_Cascade(aN_ls, fl_K, probe_energy)
    fl_cs_L = xlib_np.CS_FluorLine_Kissel_Cascade(aN_ls, fl_L, probe_energy)
    fl_cs_M = xlib_np.CS_FluorLine_Kissel_Cascade(aN_ls, fl_M, probe_energy)

    # Remove the extra dimension with only 1 element
    fl_cs_K = np.reshape(fl_cs_K, (fl_cs_K.shape[:-1]))
    fl_cs_L = np.reshape(fl_cs_L, (fl_cs_L.shape[:-1]))
    fl_cs_M = np.reshape(fl_cs_M, (fl_cs_M.shape[:-1]))

    fl_energy_K = xlib_np.LineEnergy(aN_ls, fl_K)
    fl_energy_L = xlib_np.LineEnergy(aN_ls, fl_L)
    fl_energy_M = xlib_np.LineEnergy(aN_ls, fl_M)

    FL_all_elements_dic = {
        "(element_name, Line)": [],
        "fl_energy": np.array([]),
        "detected_fl_unit_concentration": np.array([]),
        "n_line_group_each_element": np.array([]),
        "n_lines": None
    }
    if group_lines == True:
        fl_energy_group = np.zeros((len(element_ls), n_line_group))
        fl_cs_group = np.zeros((len(element_ls), n_line_group))

        for i, element_name in enumerate(element_ls):

            if np.sum(fl_cs_K[i] != 0):
                fl_energy_group[i, 0] = np.average(fl_energy_K[i],
                                                   weights=fl_cs_K[i])
                fl_cs_group[i, 0] = np.sum(fl_cs_K[i])
            else:
                fl_energy_group[i, 0] = 0
                fl_cs_group[i, 0] = 0

            if np.sum(fl_cs_L[i] != 0):
                fl_energy_group[i, 1] = np.average(fl_energy_L[i],
                                                   weights=fl_cs_L[i])
                fl_cs_group[i, 1] = np.sum(fl_cs_L[i])
            else:
                fl_energy_group[i, 1] = 0
                fl_cs_group[i, 1] = 0

            if np.sum(fl_cs_M[i] != 0):
                fl_energy_group[i, 2] = np.average(fl_energy_M[i],
                                                   weights=fl_cs_M[i])
                fl_cs_group[i, 2] = np.sum(fl_cs_M[i])
            else:
                fl_energy_group[i, 2] = 0
                fl_cs_group[i, 2] = 0

            element_Line = fl_line_groups[fl_energy_group[i] != 0]
            element_Line = [[element_name, element_Line[j]]
                            for j in range(len(element_Line))]
            for k in range(len(element_Line)):
                FL_all_elements_dic["(element_name, Line)"].append(
                    element_Line[k])

            Line_energy = fl_energy_group[i][fl_energy_group[i] != 0]
            FL_all_elements_dic["fl_energy"] = np.append(
                FL_all_elements_dic["fl_energy"], Line_energy)
            fl_unit_con = fl_cs_group[i][fl_energy_group[i] != 0] * voxel_size
            FL_all_elements_dic["detected_fl_unit_concentration"] = np.append(
                FL_all_elements_dic["detected_fl_unit_concentration"],
                fl_unit_con)
            FL_all_elements_dic["n_line_group_each_element"] = np.append(
                FL_all_elements_dic["n_line_group_each_element"],
                len(fl_unit_con))

        FL_all_elements_dic["(element_name, Line)"] = np.array(
            FL_all_elements_dic["(element_name, Line)"])

    FL_all_elements_dic["n_lines"] = len(
        FL_all_elements_dic["(element_name, Line)"])
    return FL_all_elements_dic