예제 #1
0
파일: Geometry.py 프로젝트: Gaozmmm/LASDiA
def geometry_correction(Q, I_Q, Qbkg, Ibkg_Q, variables, phi_matrix_flag):
    """Function to calcultate all intensity geometrical corrections.
    
    Parameters
    ----------
    Q               : numpy array
                      momentum transfer (nm^-1)
    I_Q             : numpy array
                      measured scattering intensity
    Qbkg            : numpy array
                      background momentum transfer (nm^-1)
    Ibkg_Q          : numpy array
                      background scattering intensity
    variables       : module
                      input variables setted by the user
    phi_matrix_flag : string
                      flag for the phi matrix calculation:
                      "y": calculate phi matrix and save on file
                      "n": read the phi matrix from file
    
    Returns
    -------
    I_Q             : numpy array
                      corrected measured sample intensity
    Ibkg_Q          : numpy array
                      corrected background intensity
    """

    two_theta = UtilityAnalysis.Qto2theta(Q)

    abs_corr_factor = calcAbsCorrection(variables.abs_length, \
        two_theta, variables.dac_thickness, 0)

    num_point = 1000

    phi_matrix_path = "./phi_matrix_" + variables.molecule

    if phi_matrix_flag.lower() == "y":
        ws1, ws2, r1, r2, d = Utility.read_MCC_file(variables.MCC_path,
                                                    variables.MCC_type)
        thickness_sampling, phi_matrix = calc_phi_matrix(variables.phi_matrix_thickness, \
            two_theta, ws1, ws2, r1, r2, d, num_point)
        np.save(phi_matrix_path, phi_matrix)
    else:
        thickness_sampling = np.linspace(0,
                                         variables.phi_matrix_thickness,
                                         num=num_point)
        phi_matrix = np.load(phi_matrix_path + ".npy")

    T_MCC_sample3, T_MCC_DAC3, T_MCC_ALL3 = calc_T_MCC(0.003, thickness_sampling, \
        phi_matrix, "y")
    T_MCC_sample4, T_MCC_DAC4, T_MCC_ALL4 = calc_T_MCC(0.004, thickness_sampling, \
        phi_matrix, "y")
    T_MCC_corr_factor_bkg = calc_T_DAC_MCC_bkg_corr(T_MCC_DAC4, T_MCC_DAC3)

    I_Q = I_Q / (abs_corr_factor * T_MCC_sample4)
    Ibkg_Q = Ibkg_Q * T_MCC_corr_factor_bkg / (abs_corr_factor * T_MCC_sample4)

    return (I_Q, Ibkg_Q)
예제 #2
0
파일: Geometry.py 프로젝트: Gaozmmm/LASDiA
def calc_abs_correction(Q, abs_length, thickness, angle):
    """Function to calculate the absorption correction.
    This function can be used to calculate the absorption correction for the diamond
    or for any other object between the sample and the detector.

    The characteristics for some diamonds can be found here:
    http://www.almax-easylab.com/DiamondSelectionPage.aspx

    Parameters
    ----------
    Q           : numpy array
                  momentum transfer (nm^-1)
    abs_length  : float
                  absorption length (cm), @33keV 1.208cm
    thickness   : float
                  object thickness (cm)
    angle       : float
                  object rotation angle respect the XRay beam (deg)

    Returns
    -------
    corr_factor : numpy array
                  correction factor
    """

    # for now...
    # wavelenght  : float
    #               XRay beam wavelenght (nm), @ESRF ID27 0.03738nm
    # wavelenght = 0.03738 # nm
    # two_theta = Qto2theta(Q) # rad

    two_theta = UtilityAnalysis.Qto2theta(Q)

    mu_l = 1 / abs_length
    angle = np.radians(angle)

    path_lenght = thickness / np.cos(two_theta - angle)

    corr_factor = np.exp(-mu_l * path_lenght)

    # I_Qeff = I_Q / corr_factor

    return corr_factor
예제 #3
0
파일: Geometry.py 프로젝트: Gaozmmm/LASDiA
def check_phi_matrix(Q, ws1, ws2, r1, r2, d, phiMatrixCalcFlag, phiMatrixPath):
    """Function to make or read from file the phi matrix.

    Parameters
    ----------
    Q                 : numpy array
                        momentum transfer (nm^-1)
    ws1               : float
                        distance between the slits of first set (cm)
    ws2               : float
                        distance between the slits of second set (cm)
    r1                : float
                        first radius
    r2                : float
                        second radius
    d                 : float
                        dimension of slit
    phiMatrixCalcFlag : string
                        flag for the phi matrix calculation
    phiMatrixPath     : string
                        phi matrix path

    Returns
    -------
    phi_matrix        : 2D numpy array
                        dispersion angle matrix for sample+DAC (rad)                     
    """

    two_theta = UtilityAnalysis.Qto2theta(Q)

    if phiMatrixCalcFlag.lower() == "y":
        phi_matrix = calc_phi_matrix(two_theta, ws1, ws2, r1, r2, d)
        np.save(phiMatrixPath, phi_matrix)
    else:
        phi_matrix = np.load(phiMatrixPath)

    thickness_sampling = np.linspace(0, 0.17, num=1000)
    return (thickness_sampling, phi_matrix)
예제 #4
0
    def SQ(self):
        """Function to calculate and plot the structure factor S(Q)"""

        self.elementList = Utility.molToElemList(self.molecule)
        # self.elementList = Utility.molToElemList("Ar")
        self.elementParameters = Utility.read_parameters(
            self.elementList, "./elementParameters.txt")

        # print(elementList)
        # print(elementParameters)

        self.Q, self.I_Q, self.Qbkg, self.Ibkg_Q = UtilityAnalysis.check_data_length(
            self.Q, self.I_Q, self.Qbkg, self.Ibkg_Q, self.ui.minQ.value(),
            self.ui.maxQ.value())

        two_theta = UtilityAnalysis.Qto2theta(self.Q)
        absCorrFactor = Geometry.calcAbsCorrection(
            self.ui.absLength.value(), two_theta, self.ui.dacThickness.value(),
            self.ui.dacAngle.value())
        self.I_Q = self.I_Q / absCorrFactor
        self.Ibkg_Q = self.Ibkg_Q / absCorrFactor

        self.fe_Q, self.Ztot = MainFunctions.calc_eeff(self.elementList,
                                                       self.Q,
                                                       self.elementParameters)
        self.Iincoh_Q = MainFunctions.calc_Iincoh(self.elementList, self.Q,
                                                  self.elementParameters)
        self.J_Q = MainFunctions.calc_JQ(self.Iincoh_Q, self.Ztot, self.fe_Q)
        self.Sinf = MainFunctions.calc_Sinf(self.elementList, self.fe_Q,
                                            self.Q, self.Ztot,
                                            self.elementParameters)

        self.dampingFunct = UtilityAnalysis.calc_dampingFunction(
            self.Q,
            self.ui.dampingFactor.value(), self.ui.QmaxIntegrate.value(),
            self.ui.dampingFunction.currentText())

        Isample_Q = MainFunctions.calc_IsampleQ(
            self.I_Q, self.ui.scaleFactorValue.value(), self.Ibkg_Q)
        alpha = MainFunctions.calc_alpha(
            self.J_Q[self.Q <= self.ui.QmaxIntegrate.value()], self.Sinf,
            self.Q[self.Q <= self.ui.QmaxIntegrate.value()],
            Isample_Q[self.Q <= self.ui.QmaxIntegrate.value()],
            self.fe_Q[self.Q <= self.ui.QmaxIntegrate.value()], self.Ztot,
            self.ui.densityValue.value())
        Icoh_Q = MainFunctions.calc_Icoh(alpha, Isample_Q, self.Iincoh_Q)

        S_Q = MainFunctions.calc_SQ(Icoh_Q, self.Ztot, self.fe_Q, self.Sinf,
                                    self.Q, self.ui.minQ.value(),
                                    self.ui.QmaxIntegrate.value(),
                                    self.ui.maxQ.value())
        Ssmooth_Q = UtilityAnalysis.calc_SQsmoothing(
            self.Q, S_Q, self.Sinf, self.ui.smoothingFactor.value(),
            self.ui.minQ.value(), self.ui.QmaxIntegrate.value(),
            self.ui.maxQ.value())
        self.SsmoothDamp_Q = UtilityAnalysis.calc_SQdamp(
            Ssmooth_Q, self.Sinf, self.dampingFunct)

        # self.ui.factorPlot.canvas.ax.plot(self.Q, self.SsmoothDamp_Q, "b", label=r"$S(Q)$")
        # self.ui.factorPlot.canvas.ax.legend()
        # self.ui.factorPlot.canvas.draw()

        return self.SsmoothDamp_Q