예제 #1
0
def compton(energy, compound):
    '''
    Compton scaterring crossection for a given compound in cm2g. Energy is given in KeV
    '''

    # xraylib might complain about types:
    energy = numpy.double(energy)

    if numpy.size(energy) == 1:
        return xraylib.CS_Compt_CP(compound, energy)
    else:
        return numpy.array([xraylib.CS_Compt_CP(compound, e) for e in energy])
예제 #2
0
def mu(material='H2C'):
    energy_range = np.arange(5., 800., 0.1, dtype=np.double)
    density = GetDensity(material)
    #print(f'density {material} = {density}')
    mu_rho = [xrl.CS_Total_CP(material, E) * density for E in energy_range]
    mu_rho_Photo = [
        xrl.CS_Photo_CP(material, E) * density for E in energy_range
    ]
    mu_rho_Compt = [
        xrl.CS_Compt_CP(material, E) * density for E in energy_range
    ]
    mu_rho_Rayl = [xrl.CS_Rayl_CP(material, E) * density for E in energy_range]
    plt.close(1)
    fig = plt.figure(num=1, dpi=150, clear=True)
    mpl.rcParams.update({'font.size': 6})
    axMW = plt.subplot(111)
    axMW.plot(energy_range,
              mu_rho,
              color="black",
              linewidth=2.,
              linestyle="-",
              label='Total')
    axMW.plot(energy_range,
              mu_rho_Photo,
              color="red",
              linewidth=2.,
              linestyle="-",
              label='Photoelectric')
    axMW.plot(energy_range,
              mu_rho_Compt,
              color="blue",
              linewidth=2.,
              linestyle="-",
              label='Compton')
    axMW.plot(energy_range,
              mu_rho_Rayl,
              color="green",
              linewidth=2.,
              linestyle="-",
              label='Rayleigh')
    axMW.set_xscale('log')
    axMW.set_yscale('log')
    axMW.set_xlim(np.min(energy_range), np.max(energy_range))
    axMW.set_ylim(1e-2, 1e4)
    plt.legend(loc='center right', frameon=True)
    plt.xlabel('Énergie (keV)')
    plt.ylabel("Coefficient d'atténuation linéique (cm$^{-1}$)")
    axMW.grid(which='major',
              axis='x',
              linewidth=0.5,
              linestyle='-',
              color='0.75')
    axMW.grid(which='minor',
              axis='x',
              linewidth=0.3,
              linestyle='-',
              color='0.75')
    axMW.grid(which='major',
              axis='y',
              linewidth=0.5,
              linestyle='-',
              color='0.75')
    axMW.grid(which='minor',
              axis='y',
              linewidth=0.3,
              linestyle='-',
              color='0.75')
    axMW.xaxis.set_major_formatter(mpl.ticker.FormatStrFormatter("%d"))
    #axMW.xaxis.set_minor_formatter(mpl.ticker.FormatStrFormatter("%d"))
    axMW.grid(True)
    #symbol=xrl.AtomicNumberToSymbol(material)
    axMW.set_title("%s" % material, va='bottom')
    #plt.savefig('mu_over_rho_W.pdf', format='PDF')
    text = axMW.text(np.min(energy_range), 1e4, "", va="top", ha="left")

    def onclick(event):
        energy = np.round(event.xdata * 10) * 0.1
        energyidx = int(
            np.where(
                np.min(np.abs(energy_range - energy)) == np.abs(energy_range -
                                                                energy))[0])
        tx = 'Le coefficient d\'atténuation linéique de ' + material + ' à %.1f keV est %1.4e cm$^{-1}$\n(Rayleigh %1.4e cm$^{-1}$, Photoelectric %1.4e cm$^{-1}$, Compton %1.4e cm$^{-1}$)' % (
            energy, mu_rho[energyidx], mu_rho_Rayl[energyidx],
            mu_rho_Photo[energyidx], mu_rho_Compt[energyidx])
        text.set_text(tx)
        text.set_x(axMW.get_xlim()[0])
        text.set_y(axMW.get_ylim()[1])

    cid = fig.canvas.mpl_connect('button_press_event', onclick)
    plt.show()
예제 #3
0
    def get_xray_categories(self,
                            xray_beam,
                            measurement,
                            output,
                            return_aux=False):

        energy = xray_beam.energy

        # Abbe criterion applied
        wavelen = xray_beam.wavelength
        num_aperture = measurement.get_numerical_aperture(xray_beam)
        (eta_el_f,
         eta_inel_f) = scat_efficiencies(energy, self.sample.feature_mw,
                                         self.sample.feature_elements,
                                         self.sample.feature_stoic)
        (eta_el_b, eta_inel_b) = scat_efficiencies(energy,
                                                   self.sample.matrix_mw,
                                                   self.sample.matrix_elements,
                                                   self.sample.matrix_stoic)

        # frac1 is the fraction in forward scattered (detectable) photons that finally enter the aperture
        frac1 = inna_frac(wavelen, num_aperture)

        # frac2 is the fraction of forward scattered inelastic scattered or plural scattered photons that enter the
        # aperture and contribute to PCI background
        frac2 = num_aperture**2 / 2

        cs_inel_b = xraylib.CS_Compt_CP(self.sample.matrix, energy)
        cs_el_b = xraylib.CS_Rayl_CP(self.sample.matrix, energy)
        cs_pi_b = xraylib.CS_Photo_CP(self.sample.matrix, energy)
        cs_tot_b = xraylib.CS_Total_CP(self.sample.matrix, energy)

        cs_inel_f = xraylib.CS_Compt_CP(self.sample.feature, energy)
        cs_el_f = xraylib.CS_Rayl_CP(self.sample.feature, energy)
        cs_pi_f = xraylib.CS_Photo_CP(self.sample.feature, energy)
        cs_tot_f = xraylib.CS_Total_CP(self.sample.feature, energy)

        # probability per length in um-1
        k_el_b = cs_el_b * self.sample.matrix_den * 1e-4
        k_inel_b = cs_inel_b * self.sample.matrix_den * 1e-4
        k_elin_b = cs_el_b * (1 - eta_el_b) * self.sample.matrix_den * 1e-4
        k_inelin_b = cs_inel_b * (1 -
                                  eta_inel_b) * self.sample.matrix_den * 1e-4
        k_out_b = (cs_el_b * eta_el_b * self.sample.matrix_den +
                   cs_inel_b * eta_inel_b * self.sample.matrix_den) * 1e-4
        k_pi_b = cs_pi_b * self.sample.matrix_den * 1e-4
        k_tot_b = k_inel_b + k_el_b + k_pi_b

        # probability per length in um-1
        k_el_f = cs_el_f * self.sample.feature_den * 1e-4
        k_inel_f = cs_inel_f * self.sample.feature_den * 1e-4
        k_elin_f = cs_el_f * (1 - eta_el_f) * self.sample.feature_den * 1e-4
        k_inelin_f = cs_inel_f * (1 -
                                  eta_inel_f) * self.sample.feature_den * 1e-4
        k_out_f = (cs_el_f * eta_el_f * self.sample.feature_den +
                   cs_inel_f * eta_inel_f * self.sample.feature_den) * 1e-4
        k_pi_f = cs_pi_f * self.sample.feature_den * 1e-4
        k_tot_f = k_inel_f + k_el_f + k_pi_f

        t_b = output.t_b
        t_f = output.t_f
        t = output.t

        # intensity fractions for matrix relative to primary beam
        i_noscat_b_func = lambda t: np.exp(-k_tot_b * t)
        i_1el_b_func = lambda t: k_elin_b * t * i_noscat_b_func(t)
        i_1elpc_b_func = lambda t: frac1 * i_1el_b_func(t)
        i_pc_b_func = lambda t: i_noscat_b_func(t) + i_1elpc_b_func(t)
        i_innoinel_b_func = lambda t: np.exp(-(k_inelin_b + k_out_b + k_pi_b) *
                                             t)
        i_elpl_b_func = lambda t: i_innoinel_b_func(t) - i_noscat_b_func(
            t) - i_1el_b_func(t)
        i_elplpc_b_func = lambda t: i_elpl_b_func(t) * frac2
        i_out_b_func = lambda t: (k_out_b / (k_out_b + k_pi_b)) * (1 - np.exp(
            -(k_out_b + k_pi_b) * t))
        i_pi_b_func = lambda t: (k_pi_b / (k_out_b + k_pi_b)) * (1 - np.exp(-(
            k_out_b + k_pi_b) * t))
        i_inel_b_func = lambda t: np.exp(-(k_out_b + k_pi_b) * t_b
                                         ) - i_innoinel_b_func(t)
        i_inelpc_b_func = lambda t: i_inel_b_func(t) * frac2

        i_noscat_b = np.exp(-k_tot_b * t)
        i_1el_b = k_elin_b * t * i_noscat_b
        i_1elpc_b = frac1 * i_1el_b
        i_pc_b = i_noscat_b + i_1elpc_b
        i_innoinel_b = np.exp(-(k_inelin_b + k_out_b + k_pi_b) * t)
        i_elpl_b = i_innoinel_b - i_noscat_b - i_1el_b
        i_elplpc_b = i_elpl_b * frac2
        i_out_b = (k_out_b /
                   (k_out_b + k_pi_b)) * (1 - np.exp(-(k_out_b + k_pi_b) * t))
        i_pi_b = (k_pi_b /
                  (k_out_b + k_pi_b)) * (1 - np.exp(-(k_out_b + k_pi_b) * t))
        i_inel_b = np.exp(-(k_out_b + k_pi_b) * t_b) - i_innoinel_b
        i_inelpc_b = i_inel_b * frac2

        i_noscat_ftf = np.exp(-k_tot_f * t_f)
        i_1el_ftf = k_elin_f * t_f * i_noscat_ftf
        i_1elpc_ftf = frac1 * i_1el_ftf
        i_pc_ftf = i_noscat_ftf + i_1elpc_ftf
        i_innoinel_ftf = np.exp(-(k_inelin_f + k_out_f + k_pi_f) * t_f)
        i_elpl_ftf = i_innoinel_ftf - i_noscat_ftf - i_1el_ftf
        i_elplpc_ftf = i_elpl_ftf * frac2
        i_out_ftf = (k_out_f /
                     (k_out_f + k_pi_f)) * (1 -
                                            np.exp(-(k_out_f + k_pi_f) * t_f))
        i_pi_ftf = (k_pi_f /
                    (k_out_f + k_pi_f)) * (1 -
                                           np.exp(-(k_out_f + k_pi_f) * t_f))
        i_inel_ftf = np.exp(-(k_out_f + k_pi_f) * t_f) - i_innoinel_ftf
        i_inelpc_ftf = i_inel_ftf * frac2

        i_noscat_btf = np.exp(-k_tot_b * t_f)
        i_1el_btf = k_elin_b * t_f * i_noscat_btf
        i_innoinel_btf = np.exp(-(k_inelin_b + k_out_b + k_pi_b) * t_f)
        i_elpl_btf = i_innoinel_btf - i_noscat_btf - i_1el_btf
        i_out_btf = (k_out_b /
                     (k_out_b + k_pi_b)) * (1 -
                                            np.exp(-(k_out_b + k_pi_b) * t_f))
        i_pi_btf = (k_pi_b /
                    (k_out_b + k_pi_b)) * (1 -
                                           np.exp(-(k_out_b + k_pi_b) * t_f))
        i_inel_btf = np.exp(-(k_out_b + k_pi_b) * t_f) - i_innoinel_btf

        i_noscat_btb = np.exp(-k_tot_b * t_b)
        i_1el_btb = k_elin_b * t_b * i_noscat_btb
        i_innoinel_btb = np.exp(-(k_inelin_b + k_out_b + k_pi_b) * t_b)
        i_elpl_btb = i_innoinel_btb - i_noscat_btb - i_1el_btb
        i_out_btb = (k_out_b /
                     (k_out_b + k_pi_b)) * (1 -
                                            np.exp(-(k_out_b + k_pi_b) * t_b))
        i_pi_btb = (k_pi_b /
                    (k_out_b + k_pi_b)) * (1 -
                                           np.exp(-(k_out_b + k_pi_b) * t_b))
        i_inel_btb = np.exp(-(k_out_b + k_pi_b) * t_b) - i_innoinel_btb

        i_noscat_f = np.exp(-k_tot_b * t_b) * np.exp(-k_tot_f * t_f)
        i_1el_f = (k_elin_b * t_b + k_elin_f * t_f) * i_noscat_f
        i_innoinel_f = np.exp(-(k_out_b + k_inelin_b + k_pi_b) * t_b) * np.exp(
            -(k_out_f + k_inelin_f + k_pi_f) * t_f)
        i_elpl_f = i_innoinel_f - i_noscat_f - i_1el_f

        i_out_ff = (1 - i_out_b_func(t_b / 2) - i_pi_b_func(t_b / 2)) * (
            k_out_f /
            (k_out_f + k_pi_f)) * (1 - np.exp(-(k_out_f + k_pi_f) * t_f))
        i_pi_ff = (1 - i_out_b_func(t_b / 2) - i_pi_b_func(t_b / 2)) * (
            k_pi_f /
            (k_out_f + k_pi_f)) * (1 - np.exp(-(k_out_f + k_pi_f) * t_f))

        i_out_f = i_out_b_func(
            t_b / 2) + i_out_ff + (1 - i_out_b_func(t_b / 2) - i_pi_b_func(
                t_b / 2) - i_out_ff - i_pi_ff) * i_out_b_func(t_b / 2)
        # i_out_f = (1 - i_out_b_func(t_b / 2) - i_pi_b_func(t_b / 2)) * (k_out_f / (k_out_f + k_pi_f)) * (1 - np.exp(-(k_out_f + k_pi_f) * t_f)) + i_out_b_func(t_b)
        i_pi_f = i_pi_b_func(
            t_b / 2) + i_pi_ff + (1 - i_out_b_func(t_b / 2) - i_pi_b_func(
                t_b / 2) - i_out_ff - i_pi_ff) * i_pi_b_func(t_b / 2)
        # i_pi_f = (1 - i_out_b_func(t_b / 2) - i_pi_b_func(t_b / 2)) * (k_out_f / (k_out_f + k_pi_f)) * (1 - np.exp(-(k_out_f + k_pi_f) * t_f)) + i_pi_b_func(t_b)

        # i_inel_f = np.exp(-(k_out_f + k_pi_f) * t_f) - i_innoinel_f
        i_inel_f = 1 - i_out_f - i_pi_f - i_innoinel_f

        # print('inside i_inel', i_inel_f[0], i_inel_b[0])
        # print('inside i_innoinel', i_innoinel_f[0], i_innoinel_b[0])
        # print('inside i_out', i_out_f[0], i_out_b[0])
        # print('inside i_pi', i_pi_f[0], i_pi_b[0])
        print('i_out_ff', i_out_ff)
        print('i_pi_ff', i_pi_ff)
        print('i_out_f', i_out_f)
        print('i_pi_f', i_pi_f)
        print('i_out_b', i_out_f)
        print('i_pi_b', i_pi_b)

        x_matrix = result_holder(xray_beam,
                                 output,
                                 measurement,
                                 constants={
                                     'k_tot_b': k_tot_b,
                                     'k_pi_f': k_pi_f,
                                     'k_pi_b': k_pi_b,
                                     'k_el_b': k_el_b
                                 },
                                 i_noscat=i_noscat_b,
                                 i_1el=i_1el_b,
                                 i_innoinel=i_innoinel_b,
                                 i_elpl=i_elpl_b,
                                 i_out=i_out_b,
                                 i_pi=i_pi_b,
                                 i_inel=i_inel_b)
        x_feature = result_holder(xray_beam,
                                  output,
                                  measurement,
                                  constants={
                                      'k_tot_f': k_tot_f,
                                      'k_pi_f': k_pi_f,
                                      'k_pi_b': k_pi_b,
                                      'k_el_f': k_el_f
                                  },
                                  i_noscat=i_noscat_f,
                                  i_1el=i_1el_f,
                                  i_innoinel=i_innoinel_f,
                                  i_elpl=i_elpl_f,
                                  i_out=i_out_f,
                                  i_pi=i_pi_f,
                                  i_inel=i_inel_f)
        x_ftf = result_holder(xray_beam,
                              output,
                              measurement,
                              constants={
                                  'k_tot_b': k_tot_b,
                                  'k_pi_f': k_pi_f,
                                  'k_pi_b': k_pi_b,
                                  'k_el_b': k_el_b
                              },
                              i_noscat=i_noscat_ftf,
                              i_1el=i_1el_ftf,
                              i_1elpc=i_1elpc_ftf,
                              i_pc=i_pc_ftf,
                              i_innoinel=i_innoinel_ftf,
                              i_elpl=i_elpl_ftf,
                              i_elplpc=i_elplpc_ftf,
                              i_out=i_out_ftf,
                              i_pi=i_pi_ftf,
                              i_inel=i_inel_ftf,
                              i_inelpc=i_inelpc_ftf,
                              i_pi_ff=i_pi_ff)
        x_btf = result_holder(xray_beam,
                              output,
                              measurement,
                              constants={
                                  'k_tot_b': k_tot_b,
                                  'k_pi_f': k_pi_f,
                                  'k_pi_b': k_pi_b,
                                  'k_el_b': k_el_b
                              },
                              i_noscat=i_noscat_btf,
                              i_1el=i_1el_btf,
                              i_innoinel=i_innoinel_btf,
                              i_elpl=i_elpl_btf,
                              i_out=i_out_btf,
                              i_pi=i_pi_btf,
                              i_inel=i_inel_btf)
        x_btb = result_holder(xray_beam,
                              output,
                              measurement,
                              constants={
                                  'k_tot_b': k_tot_b,
                                  'k_pi_f': k_pi_f,
                                  'k_pi_b': k_pi_b,
                                  'k_el_b': k_el_b
                              },
                              i_noscat=i_noscat_btb,
                              i_1el=i_1el_btb,
                              i_innoinel=i_innoinel_btb,
                              i_elpl=i_elpl_btb,
                              i_out=i_out_btb,
                              i_pi=i_pi_btb,
                              i_inel=i_inel_btb)

        if return_aux:
            return x_matrix, x_feature, x_ftf, x_btb, x_btf
        else:
            return x_matrix, x_feature
예제 #4
0
def xoppy_calc_xraylib_widget(FUNCTION=0,ELEMENT=26,ELEMENTORCOMPOUND="FeSO4",COMPOUND="Ca5(PO4)3",TRANSITION_IUPAC_OR_SIEGBAHN=1,\
                              TRANSITION_IUPAC_TO=0,TRANSITION_IUPAC_FROM=0,TRANSITION_SIEGBAHN=0,SHELL=0,ENERGY=10.0):

    functions = [
        '0 Fluorescence line energy', '1 Absorption edge energy',
        '2 Atomic weight', '3 Elemental density',
        '4 Total absorption cross section', '5 Photoionization cross section',
        '6 Partial photoionization cross section',
        '7 Rayleigh scattering cross section',
        '8 Compton scattering cross section', '9 Klein-Nishina cross section',
        '10 Mass energy-absorption cross section',
        '11 Differential unpolarized Klein-Nishina cross section',
        '12 Differential unpolarized Thomson cross section',
        '13 Differential unpolarized Rayleigh cross section',
        '14 Differential unpolarized Compton cross section',
        '15 Differential polarized Klein-Nishina cross section',
        '16 Differential polarized Thomson cross section',
        '17 Differential polarized Rayleigh cross section',
        '18 Differential polarized Compton cross section',
        '19 Atomic form factor', '20 Incoherent scattering function',
        '21 Momentum transfer function',
        '22 Coster-Kronig transition probability', '23 Fluorescence yield',
        '24 Jump factor', '25 Radiative transition probability',
        '26 Energy after Compton scattering',
        '27 Anomalous scattering factor φ′',
        '28 Anomalous scattering factor φ″',
        '29 Electronic configuration',
        '30 X-ray fluorescence production cross section (with full cascade)',
        '31 X-ray fluorescence production cross section (with radiative cascade)',
        '32 X-ray fluorescence production cross section (with non-radiative cascade)',
        '33 X-ray fluorescence production cross section (without cascade)',
        '34 Atomic level width', '35 Auger yield', '36 Auger rate',
        '37 Refractive index', '38 Compton broadening profile',
        '39 Partial Compton broadening profile',
        '40 List of NIST catalog compounds',
        '41 Get composition of NIST catalog compound',
        '42 List of X-ray emitting radionuclides',
        '43 Get excitation profile of X-ray emitting radionuclide',
        '44 Compoundparser'
    ]

    print("\nInside xoppy_calc_xraylib with FUNCTION = %s. " %
          (functions[FUNCTION]))

    if FUNCTION == 0:
        if TRANSITION_IUPAC_OR_SIEGBAHN == 0:
            lines = [
                'K', 'L1', 'L2', 'L3', 'M1', 'M2', 'M3', 'M4', 'M5', 'N1',
                'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'O1', 'O2', 'O3', 'O4',
                'O5', 'O6', 'O7', 'P1', 'P2', 'P3', 'P4', 'P5', 'Q1', 'Q2',
                'Q3'
            ]
            line = lines[TRANSITION_IUPAC_TO] + lines[
                TRANSITION_IUPAC_FROM] + "_LINE"
            command = "result = xraylib.LineEnergy(%d,xraylib.%s)" % (ELEMENT,
                                                                      line)
            print("executing command: ", command)
            line = getattr(xraylib, line)
            result = xraylib.LineEnergy(ELEMENT, line)
            print("result: %f keV" % (result))
        if TRANSITION_IUPAC_OR_SIEGBAHN == 1:
            lines = [
                'KA1_LINE', 'KA2_LINE', 'KB1_LINE', 'KB2_LINE', 'KB3_LINE',
                'KB4_LINE', 'KB5_LINE', 'LA1_LINE', 'LA2_LINE', 'LB1_LINE',
                'LB2_LINE', 'LB3_LINE', 'LB4_LINE', 'LB5_LINE', 'LB6_LINE',
                'LB7_LINE', 'LB9_LINE', 'LB10_LINE', 'LB15_LINE', 'LB17_LINE',
                'LG1_LINE', 'LG2_LINE', 'LG3_LINE', 'LG4_LINE', 'LG5_LINE',
                'LG6_LINE', 'LG8_LINE', 'LE_LINE', 'LL_LINE', 'LS_LINE',
                'LT_LINE', 'LU_LINE', 'LV_LINE'
            ]
            line = lines[TRANSITION_SIEGBAHN]
            command = "result = xraylib.LineEnergy(%d,xraylib.%s)" % (ELEMENT,
                                                                      line)
            print("executing command: ", command)
            line = getattr(xraylib, line)
            result = xraylib.LineEnergy(ELEMENT, line)
            print("result: %f keV" % (result))
        if TRANSITION_IUPAC_OR_SIEGBAHN == 2:
            lines = [
                'K', 'L1', 'L2', 'L3', 'M1', 'M2', 'M3', 'M4', 'M5', 'N1',
                'N2', 'N3', 'N4', 'N5', 'N6', 'N7', 'O1', 'O2', 'O3', 'O4',
                'O5', 'O6', 'O7', 'P1', 'P2', 'P3', 'P4', 'P5', 'Q1', 'Q2',
                'Q3'
            ]
            for i1, l1 in enumerate(lines):
                for i2, l2 in enumerate(lines):
                    if i1 != i2:
                        line = l1 + l2 + "_LINE"

                        try:
                            line = getattr(xraylib, line)
                            result = xraylib.LineEnergy(ELEMENT, line)
                        except:
                            pass
                        else:
                            if result != 0.0:
                                print("%s%s  %f   keV" % (l1, l2, result))
    elif FUNCTION == 1:
        shells = [
            'All shells', 'K_SHELL', 'L1_SHELL', 'L2_SHELL', 'L3_SHELL',
            'M1_SHELL', 'M2_SHELL', 'M3_SHELL', 'M4_SHELL', 'M5_SHELL',
            'N1_SHELL', 'N2_SHELL', 'N3_SHELL', 'N4_SHELL', 'N5_SHELL',
            'N6_SHELL', 'N7_SHELL', 'O1_SHELL', 'O2_SHELL', 'O3_SHELL',
            'O4_SHELL', 'O5_SHELL', 'O6_SHELL', 'O7_SHELL', 'P1_SHELL',
            'P2_SHELL', 'P3_SHELL', 'P4_SHELL', 'P5_SHELL', 'Q1_SHELL',
            'Q2_SHELL', 'Q3_SHELL'
        ]
        if SHELL == 0:  #"all"
            for i, myshell in enumerate(shells):
                if i >= 1:
                    # command = "result = xraylib.EdgeEnergy(%d,xraylib.%s)"%(ELEMENT,myshell)
                    # print("executing command: ",command)
                    shell_index = getattr(xraylib, myshell)
                    try:
                        result = xraylib.EdgeEnergy(ELEMENT, shell_index)
                    except:
                        pass
                    else:
                        if result != 0.0:
                            print("%s  %f   keV" % (myshell, result))
                        else:
                            print("No result")
        else:
            shell_index = getattr(xraylib, shells[SHELL])
            try:
                command = "result = xraylib.EdgeEnergy(%d,xraylib.%s)" % (
                    ELEMENT, shells[SHELL])
                print("executing command: ", command)
                result = xraylib.EdgeEnergy(ELEMENT, shell_index)
            except:
                pass
            else:
                if result != 0.0:
                    print("Z=%d %s : %f   keV" %
                          (ELEMENT, shells[SHELL], result))
                else:
                    print("No result")
    elif FUNCTION == 2:
        result = xraylib.AtomicWeight(ELEMENT)
        if result != 0.0:
            print("Atomic weight for Z=%d : %f  g/mol" % (ELEMENT, result))
    elif FUNCTION == 3:
        result = xraylib.ElementDensity(ELEMENT)
        if result != 0.0:
            print("Element density for Z=%d : %f  g/cm3" % (ELEMENT, result))
        else:
            print("No result")
    elif FUNCTION == 4:
        command = "result = xraylib.CS_Total_CP('%s',%f)" % (ELEMENTORCOMPOUND,
                                                             ENERGY)
        print("executing command: ", command)
        result = xraylib.CS_Total_CP(ELEMENTORCOMPOUND, ENERGY)
        if result != 0.0:
            print("Total absorption cross section: %f  g/cm3" % (result))
        else:
            print("No result")
    elif FUNCTION == 5:
        command = "result = xraylib.CS_Photo_CP('%s',%f)" % (ELEMENTORCOMPOUND,
                                                             ENERGY)
        print("executing command: ", command)
        result = xraylib.CS_Photo_CP(ELEMENTORCOMPOUND, ENERGY)
        if result != 0.0:
            print("Photoionization cross section: %f  g/cm3" % (result))
        else:
            print("No result")
    elif FUNCTION == 6:
        shells = [
            'All shells', 'K_SHELL', 'L1_SHELL', 'L2_SHELL', 'L3_SHELL',
            'M1_SHELL', 'M2_SHELL', 'M3_SHELL', 'M4_SHELL', 'M5_SHELL',
            'N1_SHELL', 'N2_SHELL', 'N3_SHELL', 'N4_SHELL', 'N5_SHELL',
            'N6_SHELL', 'N7_SHELL', 'O1_SHELL', 'O2_SHELL', 'O3_SHELL',
            'O4_SHELL', 'O5_SHELL', 'O6_SHELL', 'O7_SHELL', 'P1_SHELL',
            'P2_SHELL', 'P3_SHELL', 'P4_SHELL', 'P5_SHELL', 'Q1_SHELL',
            'Q2_SHELL', 'Q3_SHELL'
        ]
        if SHELL == 0:  #"all"
            for index in range(1, len(shells)):
                shell_index = getattr(xraylib, shells[index])
                try:
                    command = "result = xraylib.xraylib.CS_Photo_Partial('%d',xraylib.%s,%f)" % (
                        ELEMENT, shells[index], ENERGY)
                    print("executing command: ", command)
                    result = xraylib.CS_Photo_Partial(ELEMENT, shell_index,
                                                      ENERGY)
                except:
                    pass
                else:
                    if result != 0.0:
                        print("Z=%d, %s at E=%f keV: %f   cm2/g" %
                              (ELEMENT, shells[index], ENERGY, result))
                    else:
                        print("No result")
        else:
            shell_index = getattr(xraylib, shells[SHELL])
            try:
                command = "result = xraylib.xraylib.CS_Photo_Partial('%d',xraylib.%s,%f)" % (
                    ELEMENT, shells[SHELL], ENERGY)
                print("executing command: ", command)
                result = xraylib.CS_Photo_Partial(ELEMENT, shell_index, ENERGY)
            except:
                pass
            else:
                if result != 0.0:
                    print("Z=%d, %s at E=%f keV: %f   cm2/g" %
                          (ELEMENT, shells[SHELL], ENERGY, result))
                else:
                    print("No result")
    elif FUNCTION == 7:
        command = "result = xraylib.CS_Rayl_CP('%s',%f)" % (ELEMENTORCOMPOUND,
                                                            ENERGY)
        print("executing command: ", command)
        result = xraylib.CS_Rayl_CP(ELEMENTORCOMPOUND, ENERGY)
        if result != 0.0: print("Rayleigh cross section: %f  cm2/g" % (result))
        else: print("No result")
    elif FUNCTION == 8:
        command = "result = xraylib.CS_Compt_CP('%s',%f)" % (ELEMENTORCOMPOUND,
                                                             ENERGY)
        print("executing command: ", command)
        result = xraylib.CS_Compt_CP(ELEMENTORCOMPOUND, ENERGY)
        if result != 0.0: print("Compton cross section: %f  cm2/g" % (result))
        else: print("No result")
    elif FUNCTION == 9:
        command = "result = xraylib.CS_KN(%f)" % (ENERGY)
        print("executing command: ", command)
        result = xraylib.CS_KN(ENERGY)
        if result != 0.0:
            print("Klein Nishina cross section: %f  cm2/g" % (result))
        else:
            print("No result")
    elif FUNCTION == 10:
        command = "result = xraylib.CS_Energy_CP('%s',%f)" % (
            ELEMENTORCOMPOUND, ENERGY)
        print("executing command: ", command)
        result = xraylib.CS_Energy_CP(ELEMENTORCOMPOUND, ENERGY)
        if result != 0.0:
            print("Mass-energy absorption cross section: %f  cm2/g" % (result))
        else:
            print("No result")
    else:
        print("\n#### NOT YET IMPLEMENTED ####")
예제 #5
0
 def compton(energy, compound):
     '''
     Compton scaterring crossection for a given compound in cm2g. Energy is given in KeV
     '''
     return xraylib.CS_Compt_CP(compound, energy)
예제 #6
0
    def get_xray_categories(self, xray_beam, measurement, output, new_sample=None):
        """
        :param energy: beam energy in keV
        :param thickness: sample thickness in cm
        :param step: step length in cm
        :return:
        """
        if new_sample is not None:
            self.sample = sample
        thickness = self.sample.thickness
        step = output.step
        energy = xray_beam.energy

        print("-----------------------------------------------")
        print("Energy: %.2f keV" % energy)
        print("Thickness limit: %.2f um" % thickness)
        print("Thickness resolution: %.2f um" % (step))

        # Abbe criterion applied
        wavelen = xray_beam.wavelength
        num_aperture = measurement.get_numerical_aperture(xray_beam)
        (eta_el, eta_inel) = scat_efficiencies(energy, self.sample.mw, self.sample.elements, self.sample.stoic)

        # frac1 is the fraction in forward scattered (detectable) photons that finally enter the aperture
        frac1 = inna_frac(wavelen, num_aperture)

        # frac2 is the fraction of forward scattered inelastic scattered or plural scattered photons that enter the
        # aperture and contribute to PCI background
        frac2 = num_aperture ** 2 / 2

        # retrieve cross sections in cm2/g
        cs_inel = xraylib.CS_Compt_CP(self.sample.compound, energy)
        cs_el = xraylib.CS_Rayl_CP(self.sample.compound, energy)
        cs_pi = xraylib.CS_Photo_CP(self.sample.compound, energy)
        cs_tot = xraylib.CS_Total_CP(self.sample.compound, energy)

        # probability per thickness
        k_el = cs_el * self.sample.density * 1e-4
        k_inel = cs_inel * self.sample.density * 1e-4
        k_elin = cs_el * (1 - eta_el) * self.sample.density * 1e-4
        k_inelin = cs_inel * (1 - eta_inel) * self.sample.density * 1e-4
        k_out = (cs_el * eta_el * self.sample.density + cs_inel * eta_inel * self.sample.density) * 1e-4
        k_pi = cs_pi * self.sample.density * 1e-4
        k_tot = k_inel + k_el + k_pi

        # intensity fractions relative to primary beam
        t = output.t
        i_noscat = np.exp(-k_tot * t)
        i_1el = k_elin * t * i_noscat
        i_1elpc = frac1 * i_1el
        i_pc = i_noscat + i_1elpc
        i_elpl = np.exp(-(k_inelin + k_out + k_pi) * t) - i_noscat - i_1el
        i_elplpc = i_elpl * frac2
        i_out = (k_out / (k_out + k_pi)) * (1 - np.exp(-(k_out + k_pi) * t))
        i_pi = (k_pi / (k_out + k_pi)) * (1 - np.exp(-(k_out + k_pi) * t))
        i_inel = np.exp(-(k_out + k_pi) * t) - np.exp(-(k_inelin + k_out + k_pi) * t)
        i_inelpc = i_inel * frac2

        # res = result_holder(xray_beam, output, measurement, i_noscat=i_noscat, i_1el=i_1el, i_1elpc=None, i_pc=i_pc,
        #                     i_elpl=i_elpl, i_elplpc=i_elplpc, i_out=i_out, i_pi=i_pi, i_inel=i_inel, i_inelpc=i_inelpc,
        #                     i_df=i_1elpc)
        res = result_holder(xray_beam, output, measurement, i_noscat=i_noscat, i_1el=i_1el,
                            i_elpl=i_elpl, i_out=i_out, i_pi=i_pi, i_inel=i_inel)
        self.results.append(res)

        return