Esempio n. 1
0
    def get_data(self, file_name: str, file_path: str):
        wl_list = []  # 波长 / um
        n_list = []  # 折射率
        k_list = []  # 消光系数
        # 1 读入数据
        lines = self.open_file(path=file_path)
        for line_index in range(int(self.start_row) - 1, lines.__len__()):
            data = lines[line_index].replace('\n', '').split(',')
            wl_list.append(float(data[int(self.wl_start_rol) - 1]))
            n_list.append(float(data[int(self.n_start_rol) - 1]))
            k_list.append(float(data[int(self.k_start_rol) - 1]))
        # 2 波长单位变换到um
        from_unit = ScienceUnit.Length.um
        to_unit = ScienceUnit.Length.um
        if from_unit != to_unit:
            # X轴的单位变换
            for data in wl_list:
                data = ScienceUnitConverter.convert(
                    from_unit_class=from_unit.__class__,
                    to_unit_class=to_unit.__class__,
                    from_unit=from_unit.value,
                    to_unit=to_unit.value,
                    value=data)

        # 3 wl_bound单位变换,截取需要数据
        wl_unit_symbol = str(self.wl_bound[0])
        # 通过名称获取枚举的函数
        wl_unit = ScienceUnit.get_from_symbol(ScienceUnit.Length,
                                              wl_unit_symbol)

        self.wl_lower_bound = ScienceUnitConverter.convert(
            from_unit_class=wl_unit.__class__,
            to_unit_class=to_unit.__class__,
            from_unit=wl_unit.value,
            to_unit=to_unit.value,
            value=self.wl_bound[1])
        self.wl_upper_bound = ScienceUnitConverter.convert(
            from_unit_class=wl_unit.__class__,
            to_unit_class=to_unit.__class__,
            from_unit=wl_unit.value,
            to_unit=to_unit.value,
            value=self.wl_bound[2])

        for index in range(wl_list.__len__()):
            if wl_list[index] < self.wl_lower_bound <= wl_list[index + 1]:
                self.lower_index = index + 1
            elif wl_list[index] <= self.wl_upper_bound < wl_list[index + 1]:
                self.upper_index = index + 1
            else:
                pass
        print("Interception Index: ({},{})".format(self.lower_index,
                                                   self.upper_index))
        self.bound_valid = True
        if self.bound_valid:
            return wl_list[self.lower_index:self.upper_index], n_list[
                self.lower_index:self.
                upper_index], k_list[self.lower_index:self.upper_index]
        else:
            return wl_list, n_list, k_list
 def on_radioButton_ldc_dm_clicked(self):
     if self.radioButton_ldc_dm.isChecked():
         self.comboBox_ldc_units.addItems(['m', 'mm', 'um', 'nm', 'A'])
         self.comboBox_ldc_units.setCurrentText('nm')
         self.calculate_object = 'Dm'
         self.unit = ScienceUnit.get_from_symbol('nm')
     else:
         print(
             "UNKNOWN LognormalDistributionCalculatorDialog on_radioButton_ldc_dm_clicked"
         )
 def on_pushButton_ldc_calculate_clicked(self):
     # TODO:sigma是对于随机变量Y的,需要转化成X的sigma再进行计算才行
     self.miu = float(self.lineEdit_ldc_miu.text())
     self.x_from = float(self.lineEdit_ldc_from.text())
     self.x_to = float(self.lineEdit_ldc_to.text())
     self.sigma = float(self.lineEdit_ldc_sigma.text())
     self.unit = ScienceUnit.get_from_symbol(
         str(self.comboBox_ldc_units.currentText()))
     self.points = int(self.lineEdit_ldc_points.text())
     self.x_list = np.linspace(self.x_from, self.x_to, self.points)
     self.f_list = lognorm.pdf(self.x_list,
                               self.sigma,
                               loc=0,
                               scale=self.miu)
     print("miu={},x_from={},x_to={},sigma={},unit={},x_list={},f_list={}.".
           format(self.miu, self.x_from, self.x_to, self.sigma,
                  self.unit.get_symbol(), self.x_list, self.f_list))
    def on_pushButton_mdc_conversion_clicked(self):
        # 获取to_unit_dict目标单位
        length_unit = ScienceUnit.get_from_symbol(
            self.comboBox_mdc_length_CGS.currentText(
            )) if self.is_si_to_cgs else ScienceUnit.get_from_symbol(
                self.comboBox_mdc_length_SI.currentText())
        volume_unit = ScienceUnit.get_from_symbol(
            self.comboBox_mdc_volume_CGS.currentText(
            )) if self.is_si_to_cgs else ScienceUnit.get_from_symbol(
                self.comboBox_mdc_volume_SI.currentText())
        h_unit = ScienceUnit.get_from_symbol(
            self.comboBox_mdc_H_CGS.currentText(
            )) if self.is_si_to_cgs else ScienceUnit.get_from_symbol(
                self.comboBox_mdc_H_SI.currentText())
        m_unit = ScienceUnit.get_from_symbol(
            self.comboBox_mdc_M_CGS.currentText(
            )) if self.is_si_to_cgs else ScienceUnit.get_from_symbol(
                self.comboBox_mdc_M_SI.currentText())
        bj_unit = ScienceUnit.get_from_symbol(
            self.comboBox_mdc_BJ_CGS.currentText(
            )) if self.is_si_to_cgs else ScienceUnit.get_from_symbol(
                self.comboBox_mdc_BJ_SI.currentText())
        miu_unit = ScienceUnit.get_from_symbol(
            self.comboBox_mdc_miu_CGS.currentText(
            )) if self.is_si_to_cgs else ScienceUnit.get_from_symbol(
                self.comboBox_mdc_miu_SI.currentText())

        to_unit_dict = {
            'l': length_unit,
            'w': length_unit,
            't': length_unit,
            'V': volume_unit,
            'm': ScienceUnit.Mass.g.value,  # 这里暂时没有开放给前端
            'Ms_cal': m_unit,
            'J_cal': ScienceUnit.Dimensionless.DN.value,
            'Hm': h_unit,
            'Hcb': h_unit,
            'Hcj': h_unit,
            'Ms': m_unit,
            'Mm': m_unit,
            'Mr': m_unit,
            'Bs': bj_unit,
            'Bm': bj_unit,
            'Br': bj_unit,
            'Js': bj_unit,
            'Jm': bj_unit,
            'Jr': bj_unit,
            'Hk': h_unit,
            'Q': ScienceUnit.Dimensionless.DN.value,
            'Dm': length_unit,
            'sigma': ScienceUnit.Dimensionless.DN.value,
            'H_raw': h_unit,
            'M_raw': m_unit,
            'H': h_unit,
            'M': m_unit,
            'B': bj_unit,
            'J': bj_unit,
            'χ': ScienceUnit.Dimensionless.DN.value,  # FIXME:这里可能会有问题
            'μ': miu_unit,
            'μr': ScienceUnit.Dimensionless.DN.value,
        }
        # 对loaded_data进行单位转换
        self.converted_data = []
        for science_data in self.loaded_data:
            file_dic = science_data.get_file_dic()
            file_name = science_data.get_file_name()
            file_type = science_data.get_file_type()
            data_dict = {}
            for sheet_name, physical_quantity_list in science_data.get_data_dict(
            ).items():
                converted_physical_quantity_list = []
                for physical_quantity in physical_quantity_list:
                    converted_physical_quantity_list.append(
                        PhysicalQuantity(
                            name=physical_quantity.get_name(),
                            unit=to_unit_dict.get(
                                physical_quantity.get_name()),
                            data=science_unit_convert(
                                physical_quantity.get_data(),
                                physical_quantity.get_unit(),
                                to_unit_dict.get(
                                    physical_quantity.get_name()))))
                data_dict.update(
                    {sheet_name: converted_physical_quantity_list})
            file_name = file_name + '-CGS' if self.is_si_to_cgs else file_name + '-IS'
            self.converted_data.append(
                ScienceData(file_dic=file_dic,
                            file_name=file_name,
                            file_type=file_type,
                            data_dict=data_dict))
        print('on_pushButton_mdc_conversion_clicked: CONVERSION FINISHED.')
        # 开始写入
        for science_data in self.converted_data:
            ScienceWriter.write_file(science_data)
        print('on_pushButton_mdc_conversion_clicked: WRITE FINISHED.')
    def read_file(file_dic: str, file_full_name_list: list) -> (list, bool):
        is_si_to_cgs = False
        science_data_list = []
        for file_full_name in file_full_name_list:
            if file_full_name.split('.').__len__() == 1:
                print("Skip: No extension name.")
            else:
                file_name, file_extension_name = file_full_name.split('.')
                science_file_type = ScienceFileType.get_by_extension_name(
                    file_extension_name)
                print(file_name, science_file_type)

                if science_file_type == ScienceFileType.TXT or science_file_type == ScienceFileType.CSV:
                    with open(file_dic + '/' + file_full_name, 'r') as file:
                        # 读取CSV和TXT文件,n个文件组合起来是1个ScienceData,不过因为n个文件也是可以拆分开的,所以这里不依照para和data等名称对其进行合并
                        table_head_list = []
                        table_body_list = []
                        if science_file_type == ScienceFileType.TXT:
                            txt_str = file.read()
                            rows = txt_str.split('\n')
                            for row_index in range(rows.__len__()):
                                row_data = rows[row_index].split('\t')
                                if row_index == 0:
                                    table_head_list = row_data[:-1]
                                else:
                                    table_body_list.append(row_data[:-1])
                        else:
                            csv_reader = csv.reader(file)
                            table_head_list = next(csv_reader)
                            for row in csv.reader(file):
                                table_body_list.append(row)
                        table_body_cols = list(zip(*table_body_list))
                        physical_quantity_list = []
                        for index in range(table_head_list.__len__()):
                            name, unit_str = table_head_list[index].replace(
                                ')', '').split('(')
                            unit = ScienceUnit.get_from_symbol(unit_str)
                            physical_quantity_list.append(
                                PhysicalQuantity(name=name,
                                                 unit=unit,
                                                 data=list(
                                                     table_body_cols[index])))
                        science_data_list.append(
                            ScienceData(
                                file_dic=file_dic,
                                file_name=file_name,
                                file_type=science_file_type.value,
                                data_dict={file_name: physical_quantity_list}))
                elif science_file_type == ScienceFileType.XLSX:
                    # 读取XLSX文件,1个文件就是1个ScienceData
                    workbook = load_workbook(file_dic + '/' + file_full_name)
                    sheet_name_list = workbook.get_sheet_names()
                    data_dict = {}
                    for sheet_name in sheet_name_list:
                        worksheet = workbook.get_sheet_by_name(sheet_name)
                        physical_quantity_list = []
                        for col in worksheet.iter_cols():
                            name, unit_str = col[0].value.replace(
                                ')', '').split('(')
                            unit = ScienceUnit.get_from_symbol(unit_str)
                            data_list = []
                            for cell in col[1:]:
                                data_list.append(cell.value)
                            print(name, unit, data_list)
                            physical_quantity_list.append(
                                PhysicalQuantity(name=name,
                                                 unit=unit,
                                                 data=data_list))
                        data_dict.update({sheet_name: physical_quantity_list})
                    science_data_list.append(
                        ScienceData(file_dic=file_dic,
                                    file_name=file_name,
                                    file_type=science_file_type.value,
                                    data_dict=data_dict))
                else:
                    print('ScienceReader.read_file.ERROR UNKNOWN FILE TYPE.')
        only_once_flag = True
        for key, value in science_data_list[0].get_data_dict().items():
            if only_once_flag:
                is_si_to_cgs = value[0].get_unit() in SI_UNIT_LIST
                only_once_flag = False
        return science_data_list, is_si_to_cgs
Esempio n. 6
0
    def get_data(self, file_path_dict: dict):
        wl_list_m, [n_list_m, k_list_m] = self.iterate_data(
            file_path=file_path_dict.get('metal').get('nk'),
            start_row=self.start_row_m,
            x_start_col=self.wl_start_rol_m,
            y_start_col_list=[self.n_start_rol_m, self.k_start_rol_m])

        wl_list_epsilon_1_prime_m, [
            e_list_epsilon_1_prime_m
        ] = self.iterate_data(
            file_path=file_path_dict.get('metal').get('epsilon_1_prime'),
            start_row=self.start_row_epsilon_1_prime_m,
            x_start_col=self.wl_start_rol_epsilon_1_prime_m,
            y_start_col_list=[self.e_start_rol_epsilon_1_prime_m])
        wl_list_epsilon_2_prime_m, [
            e_list_epsilon_2_prime_m
        ] = self.iterate_data(
            file_path=file_path_dict.get('metal').get('epsilon_2_prime'),
            start_row=self.start_row_epsilon_2_prime_m,
            x_start_col=self.wl_start_rol_epsilon_2_prime_m,
            y_start_col_list=[self.e_start_rol_epsilon_2_prime_m])

        wl_list_d, [n_list_d, k_list_d] = self.iterate_data(
            file_path=file_path_dict.get('dielectric').get('nk'),
            start_row=self.start_row_d,
            x_start_col=self.wl_start_rol_d,
            y_start_col_list=[self.n_start_rol_d, self.k_start_rol_d])
        wl_list, [theta_list] = self.iterate_data(
            file_path=file_path_dict.get('theta_on_wl'),
            start_row=self.start_row_theta_on_wl,
            x_start_col=self.wl_start_rol,
            y_start_col_list=[self.theta_start_rol])
        # 2 波长的单位变换到um
        wl_to_unit = ScienceUnit.Length.um
        wl_from_unit_m = ScienceUnit.get_from_symbol(ScienceUnit.Length,
                                                     self.wl_unit_m)
        wl_from_unit_epsilon_1_prime_m = ScienceUnit.get_from_symbol(
            ScienceUnit.Length, self.wl_unit_epsilon_1_prime_m)
        wl_from_unit_epsilon_2_prime_m = ScienceUnit.get_from_symbol(
            ScienceUnit.Length, self.wl_unit_epsilon_2_prime_m)
        wl_from_unit_d = ScienceUnit.get_from_symbol(ScienceUnit.Length,
                                                     self.wl_unit_d)
        wl_from_unit_theta_on_wl = ScienceUnit.get_from_symbol(
            ScienceUnit.Length, self.wl_unit_theta_on_wl)
        if wl_from_unit_m != wl_to_unit:
            for index in range(wl_list_m.__len__()):
                wl_list_m[index] = ScienceUnitConverter.convert(
                    from_unit_class=wl_from_unit_m.__class__,
                    to_unit_class=wl_to_unit.__class__,
                    from_unit=wl_from_unit_m.value,
                    to_unit=wl_to_unit.value,
                    value=wl_list_m[index])
        if wl_from_unit_epsilon_1_prime_m != wl_to_unit:
            for index in range(wl_list_m.__len__()):
                wl_list_epsilon_1_prime_m[index] = ScienceUnitConverter.convert(
                    from_unit_class=wl_from_unit_epsilon_1_prime_m.__class__,
                    to_unit_class=wl_to_unit.__class__,
                    from_unit=wl_from_unit_epsilon_1_prime_m.value,
                    to_unit=wl_to_unit.value,
                    value=wl_list_epsilon_1_prime_m[index])
        if wl_from_unit_epsilon_2_prime_m != wl_to_unit:
            for index in range(wl_list_m.__len__()):
                wl_list_epsilon_2_prime_m[index] = ScienceUnitConverter.convert(
                    from_unit_class=wl_from_unit_epsilon_2_prime_m.__class__,
                    to_unit_class=wl_to_unit.__class__,
                    from_unit=wl_from_unit_epsilon_2_prime_m.value,
                    to_unit=wl_to_unit.value,
                    value=wl_list_epsilon_2_prime_m[index])
        if wl_from_unit_d != wl_to_unit:
            for index in range(wl_list_m.__len__()):
                wl_list_d[index] = ScienceUnitConverter.convert(
                    from_unit_class=wl_from_unit_d.__class__,
                    to_unit_class=wl_to_unit.__class__,
                    from_unit=wl_from_unit_d.value,
                    to_unit=wl_to_unit.value,
                    value=wl_list_d[index])
        if wl_from_unit_theta_on_wl != wl_to_unit:
            for index in range(wl_list.__len__()):
                wl_list[index] = ScienceUnitConverter.convert(
                    from_unit_class=wl_from_unit_theta_on_wl.__class__,
                    to_unit_class=wl_to_unit.__class__,
                    from_unit=wl_from_unit_theta_on_wl.value,
                    to_unit=wl_to_unit.value,
                    value=wl_list[index])
        # 3 wl_bound单位变换,截取需要数据
        wl_from_bound_unit = ScienceUnit.get_from_symbol(
            ScienceUnit.Length, self.wl_bound_unit)
        self.wl_lower_bound = ScienceUnitConverter.convert(
            from_unit_class=wl_from_bound_unit.__class__,
            to_unit_class=wl_to_unit.__class__,
            from_unit=wl_from_bound_unit.value,
            to_unit=wl_to_unit.value,
            value=self.wl_lower_bound)
        self.wl_upper_bound = ScienceUnitConverter.convert(
            from_unit_class=wl_from_bound_unit.__class__,
            to_unit_class=wl_to_unit.__class__,
            from_unit=wl_from_bound_unit.value,
            to_unit=wl_to_unit.value,
            value=self.wl_upper_bound)

        wl_lower_index, wl_upper_index = self.found_bound_index(
            wl_list, self.wl_lower_bound, self.wl_upper_bound)
        wl_lower_index_m, wl_upper_index_m = self.found_bound_index(
            wl_list_m, self.wl_lower_bound, self.wl_upper_bound)
        wl_lower_index_epsilon_1_prime_m, wl_upper_index_epsilon_1_prime_m = self.found_bound_index(
            wl_list_epsilon_1_prime_m, self.wl_lower_bound,
            self.wl_upper_bound)
        wl_lower_index_epsilon_2_prime_m, wl_upper_index_epsilon_2_prime_m = self.found_bound_index(
            wl_list_epsilon_2_prime_m, self.wl_lower_bound,
            self.wl_upper_bound)
        wl_lower_index_d, wl_upper_index_d = self.found_bound_index(
            wl_list_d, self.wl_lower_bound, self.wl_upper_bound)
        self.bound_valid = True
        if self.bound_valid:
            # 注意:list[a:b]是不包含b索引对应的内容的所以需要+1
            return (wl_list_m[wl_lower_index_m:wl_upper_index_m+1], n_list_m[wl_lower_index_m:wl_upper_index_m+1], k_list_m[wl_lower_index_m:wl_upper_index_m+1]), \
                   (wl_list_epsilon_1_prime_m[wl_lower_index_epsilon_1_prime_m:wl_upper_index_epsilon_1_prime_m+1], e_list_epsilon_1_prime_m[wl_lower_index_epsilon_1_prime_m:wl_upper_index_epsilon_1_prime_m+1]), \
                   (wl_list_epsilon_2_prime_m[wl_lower_index_epsilon_2_prime_m:wl_upper_index_epsilon_2_prime_m+1], e_list_epsilon_2_prime_m[wl_lower_index_epsilon_2_prime_m:wl_upper_index_epsilon_2_prime_m+1]), \
                   (wl_list_d[wl_lower_index_d:wl_upper_index_d+1], n_list_d[wl_lower_index_d:wl_upper_index_d+1], k_list_d[wl_lower_index_d:wl_upper_index_d+1]), \
                   (wl_list[wl_lower_index:wl_upper_index+1], theta_list[wl_lower_index:wl_upper_index+1])
        else:
            return (wl_list_m, n_list_m, k_list_m), \
                   (wl_list_epsilon_1_prime_m, e_list_epsilon_1_prime_m), \
                   (wl_list_epsilon_2_prime_m, e_list_epsilon_2_prime_m), \
                   (wl_list_d, n_list_d, k_list_d), \
                   (wl_list, theta_list)
    def get_data(self, file_name: str, file_path: str):
        h_list = []
        bg_m_list = []
        m_list = []
        bg_lines = self.open_file(path=self.bg_file_path)
        lines = self.open_file(path=file_path)
        length = self.size_dict[file_name][0]  # 单位 mm
        width = self.size_dict[file_name][1]  # 单位 mm
        thickness = self.size_dict[file_name][2]  # 单位 nm #S070

        volume = length * width * thickness * 1e-9  # 单位 cm^3
        # 有的文件会出现有H没有对应M的情况
        if self.H_start_row != self.M_start_row:
            print("WARNING: self.H_start_row != self.M_start_row.")

        for line_index in range(int(self.H_start_row) - 1, lines.__len__()):
            # print(line_index, ":", lines[line_index])
            try:
                bg_data = bg_lines[line_index].replace('\n', '').replace(
                    '\t', ',').split(',')
                data = lines[line_index].replace('\n',
                                                 '').replace('\t',
                                                             ',').split(',')
                h_list.append(float(data[int(self.H_start_col) - 1]))
                bg_m_list.append(float(bg_data[int(self.M_start_col) - 1]))
                m_list.append(float(data[int(self.M_start_col) - 1]))
            except IndexError:
                print(
                    "IndexError: list index out of range. It is normal for data from DENJIKEN."
                )
                break
        # 去背底
        if m_list.__len__() > bg_m_list.__len__():
            bg_m_list = bg_m_list + (m_list.__len__() -
                                     bg_m_list.__len__()) * [bg_m_list[-1]]
        m_list = np.subtract(m_list, bg_m_list[:m_list.__len__()])
        # Z轴校准(尽量让曲线是中心对称的)
        m_list = np.subtract(m_list, np.average(m_list))

        # 单位转换 [Oe,emu] 转 [A/m,A/m]
        print(self.H_start_unit)
        print(
            ScienceUnit.get_from_description_with_symbol_bracket(
                self.H_start_unit))
        h_list = science_unit_convert(
            from_list=h_list,
            from_unit=ScienceUnit.Magnetization.Oe.value,
            to_unit=ScienceUnit.Magnetization.A_m_1.value)
        if self.M_start_unit == "*Magn.Moment(emu)":
            m_list = np.divide(m_list, volume)
            self.M_start_unit = "emu/cm^3"
            m_list = science_unit_convert(
                from_list=m_list,
                from_unit=ScienceUnit.get_from_symbol(self.M_start_unit),
                to_unit=ScienceUnit.Magnetization.A_m_1.value)
        else:
            m_list = science_unit_convert(
                from_list=m_list,
                from_unit=ScienceUnit.get_from_symbol(self.M_start_unit),
                to_unit=ScienceUnit.Magnetization.A_m_1.value)

        # 调整数据:1切割正向和负向回线2把负向回线逆时针旋转180度3每一项取平均值合并
        # 1 切割
        # 最高级别注意!!! 这里需要进行2次切割:
        # 1次是时间梯度也就是按照磁场增减方向
        # 1次是磁场大小的正负切割,如果同时包含了正负的磁场那么在接近于0附近的时候ODEINT函数内部计算必定不收敛
        # 这里定义一个有4个数组的元组,按照顺序分别代表 H下降,H正 H下降,H负 H上升,H负 H上升,H正
        trend_break_index = 0
        sign_break_index = []
        for i in range(h_list.size):
            # 这里后方需要进行两次判断的理由是因为实际的H控制有一定的误差,不是一直单调变化的
            if (h_list[0] > h_list[1] and h_list[i] < h_list[i + 1]
                    and h_list[i + 1] < h_list[i + 2]
                    and h_list[i + 2] < h_list[i + 3]) or (
                        h_list[0] < h_list[1] and h_list[i] > h_list[i + 1]
                        and h_list[i + 1] > h_list[i + 2]
                        and h_list[i + 2] > h_list[i + 3]):
                trend_break_index = i
                break
        # 注意!此处判断H方向翻转的条件:i+1为0 i和i+2符号相反 OR i+1不为0 i和i+1符号相反
        for i in range(h_list.size):
            if len(sign_break_index) == 2:
                break
            elif (h_list[i] * h_list[i + 2] < 0 and h_list[i + 1]
                  == 0) or (h_list[i + 1] * h_list[i + 2] < 0):
                sign_break_index.append(i + 1)
        h1_list = []
        h2_list = []
        h3_list = []
        h4_list = []
        m1_list = []
        m2_list = []
        m3_list = []
        m4_list = []
        if sign_break_index[0] < trend_break_index < sign_break_index[1]:
            # 检查break index 的有效性
            h1_list = h_list[1:sign_break_index[0]]
            h2_list = h_list[sign_break_index[0] + 1:trend_break_index]
            h3_list = h_list[trend_break_index + 1:sign_break_index[1]]
            h4_list = h_list[sign_break_index[1] + 1:]
            m1_list = m_list[1:sign_break_index[0]]
            m2_list = m_list[sign_break_index[0] + 1:trend_break_index]
            m3_list = m_list[trend_break_index + 1:sign_break_index[1]]
            m4_list = m_list[sign_break_index[1] + 1:]
        else:
            print(
                'BREAK INDEX 错误L:trend_break_index={0},sign_break_index_1={1},sign_break_index_2={2}'
                .format(trend_break_index, sign_break_index[0],
                        sign_break_index[1]))
        # 2 旋转

        # 翻转第2和第4的横坐标,保证所有曲线的起点都是从m_max
        # 注意:曲线是有方向的切忌翻转,翻转后第2支和第4支全部都不收敛
        # h2_list = h2_list[::-1]
        # h4_list = h4_list[::-1]
        # m2_list = m2_list[::-1]
        # m4_list = m4_list[::-1]

        if np.mean(h1_list) > 0:
            # 第1象限开始的曲线
            self.begin_first_quadrant = True
            h2_list = np.multiply(h2_list, -1)
            h3_list = np.multiply(h3_list, -1)
            m2_list = np.multiply(m2_list, -1)
            m3_list = np.multiply(m3_list, -1)
        else:
            self.begin_first_quadrant = False
            # 第3象限开始的曲线
            h1_list = np.multiply(h1_list, -1)
            h4_list = np.multiply(h4_list, -1)
            m1_list = np.multiply(m1_list, -1)
            m4_list = np.multiply(m4_list, -1)
        # 3 拼装
        m_0_list = np.array([m1_list[0], m2_list[0], m3_list[0], m4_list[0]])
        break_index_list = np.array([
            h1_list.size, h1_list.size + h2_list.size,
            h1_list.size + h2_list.size + h3_list.size,
            h1_list.size + h2_list.size + h3_list.size + h4_list.size
        ])
        h_list = np.concatenate([h1_list, h2_list, h3_list, h4_list])
        m_list = np.concatenate([m1_list, m2_list, m3_list, m4_list])

        return h_list, m_list, m_0_list, break_index_list, length, width, thickness
    def __init__(self, parent):
        self.parent = parent
        # 模型 1:Jiles-Atherton,模型 2:Brillouin,模型 3:Langevin,模型 4:Takacs
        # 默认模型为3:Langevin
        self.model = 3
        # 饱和磁化强度(A/m)-LOG 10 kOe~795775A/m
        self.ms_min = 100.  # 0.00125664 kG
        self.ms_max = 100000000.  #
        # 磁耦合系数(J/(Tm^3))
        self.a_min = 1e3
        self.a_max = 1e5
        # 不可逆损耗系数(??)
        self.k_min = 1e3
        self.k_max = 1e5
        # 磁畴耦合系数(??)
        self.alfa_min = 0.0
        self.alfa_max = 1.0
        # 可逆磁化系数(1)
        self.c_min = 0.0
        self.c_max = 1.0
        # 轨道量子数,是自然数(1)
        self.j_min = 1.
        self.j_max = 1.e5
        # 颗粒尺寸分布的标准差(1)
        self.sigma_min = 0.
        self.sigma_max = 5.
        # 轨道量子数的朗德因子(1)
        self.g_j = sci_const.Lande_g_Factor(3 / 2, 3, 9 / 2)  # Co2+ ion
        # self.g_j = 1.60  # calculated
        # self.g_j = 1.72  #observed
        # 温度(K)
        self.temp = 300.
        # 初始化参数
        self.ms = self.ms_max
        self.a = self.a_max
        self.k = self.k_max
        self.alfa = self.alfa_min
        self.c = self.c_min
        self.j = self.j_min
        self.sigma = self.sigma_min
        # 录入文件相关系数和自定义UI组件
        self.file_path = []
        self.file_name = []
        self.table_view_file_model = QtGui.QStandardItemModel()
        self.resetTableViewHeaderItems(
            tableviewmodel=self.table_view_file_model)
        self.last_model_index = None
        # 结果的自定义UI组件
        self.list_view_results_model = QtGui.QStandardItemModel()

        # 结果字典,键是文件名
        self.result_dict = {}
        # plot相关的弹窗的UI及其初始化,用tabUI预留出可能出现的多张图片
        self.dialog_plot_M = QtWidgets.QDialog()
        self.tab_plot_M = QtWidgets.QTabWidget(self.dialog_plot_M)
        self.tab_plot_M.setGeometry(QtCore.QRect(10, 0, 1061, 678))
        self.tab_plot_M_magnetization = QtWidgets.QWidget()
        self.tab_plot_M.addTab(self.tab_plot_M_magnetization, "")
        _translate = QtCore.QCoreApplication.translate
        self.tab_plot_M.setTabText(
            self.tab_plot_M.indexOf(self.tab_plot_M_magnetization),
            _translate("MainWindow", "Magnetization Curves"))

        self.layout_plot_M_magnetization = QtWidgets.QVBoxLayout()
        self.fig_M_magnetization = plt.Figure()
        self.canvas_M_magnetization = FigureCanvas(self.fig_M_magnetization)

        self.magnetization_unit_list = ScienceUnit.get_unit_list_by_classification(
            ScienceUnit.Magnetization)