Beispiel #1
0
def imshow():
    folder = r"G:\Group_Work\Wyatt_Experiment\Quantum_dot\20190505\40ps\interference\alter"
    file_list = fp.show_file(folder, ".dat")

    for file in file_list[2:3]:
        print(file)
        data = fp.load_dat_data(folder + "\\" + file)
        dp.show_image(data)

    plt.show()
def subtract_background(folder):
    sub_folder = fp.show_all_sub_folder(folder, name="alter")
    i = 0
    for sub in sub_folder:
        dat_file = fp.show_file(sub, fmt=".dat")
        for file in dat_file:
            ori_data = fp.load_dat_data(sub + "\\" + file)
            data = ori_data.copy()
            # print(np.average(ori_data[1:, 3]))
            if np.average(ori_data[1:, 3]) > 500:
                data[1:, 1:] = ori_data[1:, 1:] - bg_data[1:, 1:]
                np.savetxt(sub + "\\" + file, data, fmt='%s', delimiter='\t')
            i += 1
            print("\r***已完成   {}  个文件, 平均值为{} ***".format(
                i, np.average(ori_data[1:, 3])),
                  end="")
def sub_bg(sub):
    """
        sub文件夹下的文件去背景
    :param i: 文件数目
    :param sub: 文件夹路径
    """
    global i
    dat_file = fp.show_file(sub, fmt=".dat")
    for file in dat_file:
        ori_data = fp.load_dat_data(sub + "\\" + file)
        data = ori_data.copy()
        # print(np.average(ori_data[1:, 3]))
        if np.average(ori_data[1:, 3]) > 500:
            data[1:, 1:] = ori_data[1:, 1:] - bg_data[1:, 1:]
            np.savetxt(sub + "\\" + file, data, fmt='%s', delimiter='\t')
        i += 1
        print("\r***已完成   {}  个文件, 平均值为{} ***".format(
            i, np.average(ori_data[1:, 3])),
              end="")
def subtract_background(folder):
    sub_folder = fp.show_all_sub_folder(folder, name="alter")
    po = Pool(4)
    for sub in sub_folder:
        po.apply_async(sub_bg, (sub, ))

    print("----start----")
    po.close()  # 关闭进程池,关闭后po不再接收新的请求
    po.join()  # 等待po中所有子进程执行完成,必须放在close语句之后
    print("\n-----end-----")
    def run(self):
        """
        sub文件夹下的文件去背景
        :param
        sub: 文件夹路径
        """
        dat_file = fp.show_file(self.sub, fmt=".dat")
        for file in dat_file:
            ori_data = fp.load_dat_data(self.sub+"\\"+file)
            data = ori_data.copy()
            # print(np.average(ori_data[1:, 3]))
            if np.average(ori_data[1:, 3]) > 500:
                data[1:, 1:] = ori_data[1:, 1:] - bg_data[1:, 1:]
                np.savetxt(self.sub+"\\"+file, data, fmt='%s', delimiter='\t')
            metex_flag = self.mutex.acquire(False)
            if metex_flag:
                self.i += 1
                self.mutex.release()

            print("\r***已完成   {}  个文件, 平均值为{} ***".format(self.i, np.average(ori_data[1:, 3])), end="")
def main():
    global thread_status
    LENGTH = 135
    err_list = []

    client = StpCaComm()

    # 创建线程
    rec = Thread(target=receive, args=(client, ))
    rec.setDaemon(False)
    rec.start()

    # 启动程序
    client.send_command_get_response("AppStart()")
    if read_response()[0]:
        pub_folder = r"G:\Group_Work\Wyatt_Experiment\NanoSheets\TW\tangbing_sample\ColdTemp\20190617\inter"
        sub_folder = FP.show_all_sub_folder(pub_folder, name=None)
        i = 1
        for folder in sub_folder:
            file_list = FP.show_file(folder, fmt='.img')
            if len(file_list) > 0:
                # print(file_list)
                for file in file_list:
                    print("-" * LENGTH)
                    filename = folder + "\\" + file
                    print("{} . Start converting [{}]".format(i, filename))
                    try:
                        format_conversion(client, input_filename=filename)
                    except Exception as err:
                        print("**********{} {}:{}**********".format(
                            i, filename, err))
                        err_list.append("{}. {}".format(i, filename))
                    print("-" * LENGTH)
                    print("")
                    i += 1

    client.close()
    thread_status = False
Beispiel #7
0
def create_time(STATE):
    folder = r"G:\Group_Work\Wyatt_Experiment\Quantum_dot\20190505\20ps\interference\alter"
    file_list = fp.show_file(folder, fmt=".dat")
    for file in file_list:
        data = fp.load_dat_data(folder + "\\" + file)
        if STATE:
            print(file)
            dp.show_image(data)
        else:
            x_min, x_max = dp.get_xmin_xmax(data)
            X, Y = dp.plot_time_image(data, x_min, x_max, l_label=file)
            size = len(X)
            save_data = np.zeros((size, 2))
            save_data[:, 0] = X
            save_data[:, 1] = Y
            try:
                os.mkdir(folder + "\\time")
            except FileExistsError:
                pass
            # np.savetxt(folder + "\\time\\time_" + file, save_data, fmt='%s', delimiter='\t')
            plt.savefig(folder + "\\time\\" + str(file.split(".")[:-1]),
                        fmt='jpg')
    plt.show()
def subtract_background(folder):
    sub_folder = fp.show_all_sub_folder(folder, name="alter")
    for sub in sub_folder:
        t = MyThread(sub)
        t.start()
            data = ori_data.copy()
            # print(np.average(ori_data[1:, 3]))
            if np.average(ori_data[1:, 3]) > 500:
                data[1:, 1:] = ori_data[1:, 1:] - bg_data[1:, 1:]
                np.savetxt(self.sub+"\\"+file, data, fmt='%s', delimiter='\t')
            metex_flag = self.mutex.acquire(False)
            if metex_flag:
                self.i += 1
                self.mutex.release()

            print("\r***已完成   {}  个文件, 平均值为{} ***".format(self.i, np.average(ori_data[1:, 3])), end="")


# 背景图片
background = r"G:\Group_Work\Wyatt_Experiment\Quantum_dot\20190505\alter_1\background.dat"
bg_data = fp.load_dat_data(background)


def subtract_background(folder):
    sub_folder = fp.show_all_sub_folder(folder, name="alter")
    for sub in sub_folder:
        t = MyThread(sub)
        t.start()


def main(folder):
    print("--------开始去背景---------")
    subtract_background(folder)
    print("\n--------已全部完成去背景---------")

    if filename:
        temp = change_name(filename)

    center_wavelength = X[Y.argmax()]
    plt.plot(X,
             Y,
             label="P:{:s}um        {:.1f}nm".format(temp, center_wavelength))
    plt.legend()
    return temp, center_wavelength, Y.max()


folder = r"G:\Group_Work\Wyatt_Experiment\Quantum_dot\Tm_quantum dots1"
sub_folder = r"\800+400double_pulse\3\400+800change800power\alter"
whole_folder = folder + sub_folder
file_list = fp.show_file(whole_folder, '.dat')

temp_wave_data = np.zeros((len(file_list), 3))
i = 0
for file_name in file_list:
    #    if i in [19]:
    data = fp.load_dat_data(whole_folder + "\\" + file_name)
    ##        xmin, xmax = dp.get_xmin_xmax(data)
    ##        image_plot(data, xmin, xmax, l_label="T:{:s}K".format(file_name.split('.dat')[0]), style="-")
    ymin, ymax = dp.get_ymin_ymax(data)
    temp1, center_wavelength1, y_max = spec_plot(data,
                                                 ymin,
                                                 ymax,
                                                 filename=file_name)
    temp_wave_data[i, :] = [float(temp1), center_wavelength1, y_max]