Exemple #1
0
 def multi_phase_PM_func(self, n_concentration, magnetic_field, temperature, zero_index=None):
     # calc Brillouin function for multi-phase sample
     num = len(self.dict_of_magnetic_phases)
     len_of_x = len(magnetic_field)
     # vector for magnetic calculation:
     vec_x = np.zeros(len_of_x)
     #concentration of Mn atoms n[1/m^3*1e27]
     out = np.zeros(len_of_x)
     for i in self.dict_of_magnetic_phases:
         val = self.dict_of_magnetic_phases[i]
         n = n_concentration[i]
         J = val['data'].J_total_momentum
         g = val['data'].g_factor
         Mn_type = val['data'].Mn_type
         spin_type = val['data'].spin_type_cfg
         tmp = np.zeros(len_of_x)
         # create unique x-vector for Brillouin function:
         vec_x = (g * J * mu_Bohr * magnetic_field) \
                     / k_b / temperature
         # tmp = f_PM(x=vec_x, n=n, J=J, g_factor=g)
         tmp = f_PM_with_T(B=magnetic_field, n=n, J=J, T=temperature, g_factor=g)
         # fight with uncertainty in 0 vicinity:
         if zero_index is not None:
             tmp[zero_index] = 0
         out += tmp
     return out
    def subtract_PM_after_calc_diff_PM(self):
        if not (self.n_diffPM == 0):
            B = self.struct_of_data[self.diff_PM_keyName1].xx
            M = self.struct_of_data[self.diff_PM_keyName1].yy
            T = self.struct_of_data[self.diff_PM_keyName1].T
            J = 2.5
            M_sub_PM = M - f_PM_with_T(B=B, n=self.n_diffPM, J=J, T=T)

            self.ax.cla()

            print('->> sub PM after diff PM have been done. For m(T={0}K) - m(T={1}K) obtained n = {2:1.3g} *1e27 [1/m^3] or {3:1.3g} % of the n(GaAs)'\
                  .format(self.diff_PM_keyName1, self.diff_PM_keyName2, self.n_diffPM, self.n_diffPM/22.139136*100))

            # setup variables for plot:
            self.suptitle_txt = 'case: {}, '.format(self.selectCase) + '$Ga_{1-x}Mn_xAs$,' \
                                + ' where $x = {0:1.2g}\%$ '.format(self.how_many_Mn_in_percent)
            self.ylabel_txt = '$M\,(A/m)$'
            self.xlabel_txt = '$B\,(T)$'
            self.setupAxes()

            self.ax.plot(B, f_PM_with_T(B=B, n=self.n_diffPM, J=J, T=T), 'r-',
                         label='PM component $\left(T={0:1.2g}K \\right)$, '.format(T) +\
                        '$n_{{PM}}={:1.3g}\%$,'.format(self.n_diffPM / 22.139136 * 100) + \
                             '\n$n_{{[PM,\;x={0:1.3g}\%]}}={1:1.3g}\%$'.format(self.how_many_Mn_in_percent,
                            self.n_diffPM / 22.139136 * 100/self.how_many_Mn_in_percent*100) + \
                        ' $J={:1.2g}(Mn^{{2+}})$'.format(J/2.5)
                         )
            self.ax.scatter(B,
                            M,
                            label='raw $\left(T={0:1.2g}K \\right)$'.format(T),
                            alpha=.2,
                            color='g')
            self.ax.scatter(B,
                            M_sub_PM,
                            label='$M_{raw}-M_{PM}$' +
                            ' $\left(T={0:1.2g}K \\right)$'.format(T),
                            color='k',
                            alpha=.2)
            self.ax.legend(shadow=True, fancybox=True, loc='upper left')
            self.ax.grid(True)
            plt.draw()

            plt.draw()
 def fun_fit(B, n, j):
     # return f_SPM_with_T(B, n, J=J, T=T)
     return f_PM_with_T(B, n, J=j, T=T)
    def calc_SPM_Langevin(self):
        # fit data by using a Langevin function:
        if self.n_diffPM <= 0:
            self.calc_diff_PM()

        T = self.struct_of_data[self.SPM_keyName].T

        def fun_fit(B, n, j):
            # return f_SPM_with_T(B, n, J=J, T=T)
            return f_PM_with_T(B, n, J=j, T=T)

        B = self.struct_of_data[self.SPM_keyName].xx
        M = self.struct_of_data[self.SPM_keyName].yy
        T = self.struct_of_data[self.SPM_keyName].T
        J = 2.5
        eps = 0.001 * abs(abs(B[0]) - abs(B[1]))

        # reduce a noise:
        Mp = M[(B > eps)]
        Mn = M[(B < -eps)]
        M_for_fit = np.copy(M)

        # Find the intersection of two arrays to avoid conflict with numbers of elements.
        # if abs(self.struct_of_data[self.SPM_keyName].Hmin) == self.struct_of_data[self.SPM_keyName].Hmax:
        if len(M[(B > 0)]) != len(M[(B < 0)]):
            # reduce a noise:
            negVal = abs(np.min(B))
            pozVal = np.max(B)

            if pozVal >= negVal:
                limitVal = negVal
            else:
                limitVal = pozVal

            inx_B = np.logical_or((np.abs(B) <= limitVal + eps),
                                  (np.abs(B) <= eps))
            B = np.copy(B[inx_B])

            M_for_fit = np.copy(M[inx_B])

            Mp = M[np.where(B > eps)]
            Mn = M[np.where(B < -eps)]

        if len(M[np.where(B > 0)]) == len(M[np.where(B < 0)]):
            inx_B = np.logical_or((np.abs(B) <= eps), (np.abs(B) >= eps))
            B = np.copy(B[inx_B])

            M_for_fit = np.copy(M[np.where(inx_B)])
            # reduce a noise:
            Mp = M[np.where(B > eps)]
            Mn = M[np.where(B < -eps)]

        M_for_fit[np.where(B > eps)] = 0.5 * (Mp + np.abs(Mn[::-1]))
        M_for_fit[np.where(B < -eps)] = 0.5 * (Mn - np.abs(Mp[::-1]))
        # M_for_fit[(B > 0)] = 0.5*(Mp + np.abs(Mn))
        # M_for_fit[(B < 0)] = 0.5*(Mn - np.abs(Mp))

        if self.SPM_field_region_for_fit[0, 0] >= B.max():
            self.SPM_field_region_for_fit[0, 0] = np.fix(10 * B.max()) / 10 - \
                                                      5 * self.struct_of_data[self.SPM_keyName].Hstep

        # sabtruct a PM magnetic phase which is low temperature independent:
        M_for_fit = M_for_fit - f_PM_with_T(B, n=self.n_diffPM, J=J, T=T)

        condlist1 = (self.SPM_field_region_for_fit[0, 0] <
                     B) & (self.SPM_field_region_for_fit[0, 1] > B)
        initial_guess = [
            0.01,
            2,
        ]
        # fit the data:
        pres, pcov = curve_fit(fun_fit,
                               B[np.logical_or(condlist1, condlist1)],
                               M_for_fit[np.where(
                                   np.logical_or(condlist1, condlist1))],
                               p0=initial_guess,
                               bounds=([
                                   0,
                                   0,
                               ], [
                                   np.inf,
                                   np.inf,
                               ]))

        self.n_SPM = pres[0]
        self.J_SPM = pres[1]
        print('->> fit SPM have been done. For m(T={0}K) obtained n = {1:1.3g} *1e27 [1/m^3] or {2:1.3g} % of the n(GaAs)'\
          .format(self.SPM_keyName, self.n_SPM, self.n_SPM/22.139136*100))
        print('->> SPM magnetic phase has total momentum J = {0:1.3g} or {1:1.3g} numbers of J(Mn2+)'\
          .format(self.J_SPM, self.J_SPM/2.5))

        # setup variables for plot:
        self.ax.cla()
        self.suptitle_txt = 'case: {}, '.format(self.selectCase) + '$Ga_{1-x}Mn_xAs$,' \
                            + ' where $x = {0:1.2g}\%$ '.format(self.how_many_Mn_in_percent)
        self.ylabel_txt = '$M(T={0}K) (A/m)$'.format(T)
        self.xlabel_txt = '$B (T)$'
        self.setupAxes()

        self.ax.scatter(
            B[np.logical_or(condlist1, condlist1)],
            M_for_fit[np.where(np.logical_or(condlist1, condlist1))],
            label='region for $fit$',
            facecolor='none',
            alpha=.1,
            s=200,
            marker='s',
            edgecolors='k',
        )
        self.ax.plot(B, fun_fit(B, self.n_SPM, self.J_SPM), 'r-',
                     label='$fit$, $n_{{SPM}}={0:1.3g}\%$, \n$J={1:1.3g}(Mn^{{2+}})$'.format(self.n_SPM/22.139136*100,
                                                                                                  self.J_SPM/2.5)+\
                           ', $n_{{[SPM,\;x={0:1.3g}\%]}}={1:1.3g}\%$'.format(self.how_many_Mn_in_percent,
                            self.n_SPM / 22.139136 * 100/self.how_many_Mn_in_percent*100)
                     )
        self.ax.plot(B, f_PM_with_T(B, n=self.n_diffPM, J=J, T=T), 'b-',
                     label='$PM(T={2:1.2g}K)$, $n_{{PM}}={0:1.3g}\%$, \n$J={1:1.3g}(Mn^{{2+}})$'\
                     .format(self.n_diffPM/22.139136*100, 1, T, )+\
                           ', $n_{{[PM,\;x={0:1.3g}\%]}}={1:1.3g}\%$'.format(self.how_many_Mn_in_percent,
                            self.n_diffPM / 22.139136 * 100/self.how_many_Mn_in_percent*100))
        self.ax.scatter(B,
                        M[np.where(inx_B)],
                        label='$raw$',
                        alpha=.2,
                        color='g')
        self.ax.scatter(
            B,
            M_for_fit,
            label=
            'set for $fit$, $\\frac{{\left(M_++M_-\\right)}}{{2}} - PM(T={0:1.2g}K)$'
            .format(T),
            color='k',
            alpha=.2)
        self.ax.plot(B,
                     10 * (M_for_fit - fun_fit(B, self.n_SPM, self.J_SPM)),
                     'k.',
                     label='residuals $10*(raw - fit)$')

        self.ax.legend(shadow=True, fancybox=True, loc='upper left')
        self.ax.grid(True)
        plt.show()
        plt.draw()
    def subtract_Line(self):
        # try to subtract BG line: y=kx+b, which may be correspond to anisotropy effect
        # and then calculate FM phase concentration
        if not (self.n_diffPM == 0):
            B = self.struct_of_data[self.diff_PM_keyName1].xx
            M = self.struct_of_data[self.diff_PM_keyName1].yy
            T = self.struct_of_data[self.diff_PM_keyName1].T
            J = 2.5
            M_sub_PM = M - f_PM_with_T(B=B, n=self.n_diffPM, J=J, T=T)

            condlist1 = (self.FM_field_region_for_fit[0, 0] <
                         B) & (self.FM_field_region_for_fit[0, 1] > B)
            condlist2 = (self.FM_field_region_for_fit[1, 0] <
                         B) & (self.FM_field_region_for_fit[1, 1] > B)
            inx_condlist = np.logical_or(condlist2, condlist2)
            # fit the data:
            par, pcov = curve_fit(
                linearFunc,
                B[np.logical_or(condlist2, condlist2)],
                M_sub_PM[np.logical_or(condlist2, condlist2)],
            )
            k = par[0]
            b = par[1]
            M_sub_linear = M_sub_PM - (k * B)

            # calc M-saturation and FM phase concentration:
            M_FM_saturation = 0.5 * (abs(np.mean(M_sub_linear[condlist2])) +
                                     abs(np.mean(M_sub_linear[condlist1])))
            self.n_FM_phase = concentration_from_Ms(Ms=M_FM_saturation,
                                                    J=2.5) * (1e-27)
            print('->> subtract_Line have been done.')
            print(
                'For Ms, which we take from m(T={0}K)-PM-k*B we obtained n = {1:1.3g} *1e27 [1/m^3] or {2:1.3g} % of the n(GaAs)' \
                .format(self.diff_PM_keyName1, self.n_FM_phase, self.n_FM_phase / 22.139136 * 100))

            self.ax.cla()

            # setup variables for plot:
            self.suptitle_txt = 'case: {}, '.format(self.selectCase) + '$Ga_{1-x}Mn_xAs$,' \
                                + ' where $x = {0:1.2g}\%$ '.format(self.how_many_Mn_in_percent)
            self.ylabel_txt = '$M\, (A/m)$'
            self.xlabel_txt = '$B\, (T)$'
            self.setupAxes()

            self.ax.plot(B, f_PM_with_T(B=B, n=self.n_diffPM, J=J, T=T), 'r-',
                         label='PM component $\left(T={0:1.2g}K \\right)$, '.format(T) + \
                               '$n_{{PM}}={:1.3g}\%$,'.format(self.n_diffPM / 22.139136 * 100) + \
                             '\n$n_{{[PM,\;x={0:1.3g}\%]}}={1:1.3g}\%$'.format(self.how_many_Mn_in_percent,
                            self.n_diffPM / 22.139136 * 100/self.how_many_Mn_in_percent*100) + \
                               ' $J={:1.2g}(Mn^{{2+}})$'.format(J / 2.5)
                         )
            self.ax.plot(B, (k * B), 'b-', label='line')
            self.ax.scatter(B, M, label='raw', alpha=.2, color='g')
            self.ax.scatter(B,
                            M_sub_PM,
                            label='$M_{raw}-M_{PM}$' +
                            ' $\left(T={0:1.2g}K \\right)$'.format(T),
                            color='k',
                            alpha=.2)
            self.ax.scatter(B, M_sub_linear, label='$M_{PM}-(kx+b)$, '+\
                                                   '$n_{{FM}}={:1.3g}\%$,\n'.format(self.n_FM_phase / 22.139136 * 100) + \
                '$n_{{[FM,\;x={0:1.3g}\%]}}={1:1.3g}\%$'.format(self.how_many_Mn_in_percent,
                            self.n_FM_phase / 22.139136 * 100/self.how_many_Mn_in_percent*100) + \
                                                   ' $J={:1.2g}(Mn^{{2+}})$'.format(J / 2.5),
                            color='b', s=100,
                            alpha=.2)
            self.ax.scatter(B[inx_condlist],
                            M_sub_PM[inx_condlist],
                            label='for $linear\,fit$ $M_{raw}-M_{PM}$' +
                            ' $\left(T={0:1.2g}K \\right)$'.format(T),
                            color='k',
                            alpha=.2,
                            s=70)
            self.ax.legend(shadow=True, fancybox=True, loc='upper left')
            self.ax.grid(True)
            plt.draw()