Ejemplo n.º 1
0
def export_all_calib_data(calib_2D, angles_modif, import_XRD, main):
    from residual_stress_2D.calib_XRD_2D import calib_pyFai

    location = askdirectory(title="Please choose a directory")
    if location is not None and location is not '':
        for widget in main.Frame1_2.winfo_children():
            widget.destroy()
        Label(main.Frame1_2, text="Export").pack(side=LEFT)
        progress = Progressbar(main.Frame1_2,
                               orient="horizontal",
                               mode='determinate')
        progress.pack(side=LEFT)
        progress["value"] = 0
        progress["maximum"] = len(import_XRD.nfile)

        rotate = import_XRD.rotate
        flip = import_XRD.flip

        for i in range(len(import_XRD.nfile)):
            progress["value"] = progress["value"] + 1
            progress.update()

            f_split = (import_XRD.file_link[import_XRD.nfile[i]]).split("/")
            filename = f_split[len(f_split) - 1]
            name = str(location) + '/calib_' + str(
                filename.split('.')[0]) + '_' + str(
                    import_XRD.nimage_i[i]) + '.xlf'
            f = open(name, 'w')

            if calib_2D.angles_modif_valid == True:
                twotheta_x = angles_modif.twotheta_x
                gamma_y = angles_modif.gamma_y
                phi = angles_modif.phi[i]
                chi = angles_modif.chi[i]
                omega = angles_modif.omega[i]
                twotheta_center = angles_modif.twotheta_center[i]
            else:
                twotheta_x = calib_2D.twotheta_x
                gamma_y = calib_2D.gamma_y
                phi = calib_2D.phi[i]
                chi = calib_2D.chi[i]
                omega = calib_2D.omega[i]
                twotheta_center = calib_2D.twotheta_center[i]

            data = read_data_2D(i, import_XRD)

            if len(data.shape) == 3:
                data = data[import_XRD.nimage_i[i]]

            if len(data) == 0:
                showinfo(title="Warning",
                         message="Can not read data of " + str(filename))
                return

            if rotate == 0:
                nrow = import_XRD.nrow[i]
                ncol = import_XRD.ncol[i]
                center_row = import_XRD.center_row[i]
                center_col = import_XRD.center_col[i]

            if rotate == 90:
                data = np.rot90(data, k=1, axes=(0, 1))
                nrow = import_XRD.ncol[i]
                ncol = import_XRD.nrow[i]
                center_row = import_XRD.center_col[i]
                center_col = import_XRD.center_row[i]

            if rotate == 180:
                data = np.rot90(data, k=2, axes=(0, 1))
                nrow = import_XRD.nrow[i]
                ncol = import_XRD.ncol[i]
                center_row = import_XRD.center_row[i]
                center_col = import_XRD.center_col[i]

            if rotate == 270:
                data = np.rot90(data, k=3, axes=(0, 1))
                nrow = import_XRD.ncol[i]
                ncol = import_XRD.nrow[i]
                center_row = import_XRD.center_col[i]
                center_col = import_XRD.center_row[i]

            if flip == 1:
                data = np.flip(data, axis=0)

            if flip == 2:
                data = np.flip(data, axis=1)

            calib = calib_pyFai(import_XRD, data, nrow, ncol, center_row,
                                center_col, twotheta_center)
            if len(calib) > 0:
                data = calib[0]
            else:
                showinfo(title="Warning",
                         message="Can not calib file " + str(filename))
                return

            if float(calib_2D.Check_twotheta_flip.get()) == 1:
                data = np.flip(data, axis=1)

            if len(data) > 0:
                progress["value"] = progress["value"] + 1
                progress.update()
                data = calib[0]
                nrow = len(gamma_y)
                ncol = len(twotheta_x)

                f.write("Phi=" + str(phi) + "\n")
                f.write("Chi=" + str(chi) + "\n")
                f.write("Omega=" + str(omega) + "\n")
                f.write("2theta=" + str(twotheta_center) + "\n")
                f.write("Wavelength=" + str(import_XRD.k_alpha[i]) + "\n")
                f.write("Distance=" + str(import_XRD.distance[i]) + "\n")
                f.write("------------------------------------------\n")
                f.write("NRow=" + str(nrow) + "\n")
                f.write("Center Row=" + str(center_row) + "\n")
                for j in range(nrow):
                    f.write(str(gamma_y[j]) + " ")
                f.write("\n")
                f.write("NCol=" + str(ncol) + "\n")
                f.write("Center Col=" + str(center_col) + "\n")
                for j in range(ncol):
                    f.write(str(twotheta_x[j]) + " ")
                f.write("\n")
                f.write("------------------------------------------\n")
                f.write("------------------------------------------\n")

                progress["value"] = progress["value"] + 1
                progress.update()

                for i in range(nrow):
                    f.write(" ".join(str(e) for e in data[i]))
                    f.write("\n")
            f.close()

    for widget in main.Frame1_2.winfo_children():
        widget.destroy()
    main.root.mainloop()
Ejemplo n.º 2
0
def export_original_data(nfile, nimage, nimage_i, import_XRD, main):
    f = asksaveasfile(title="Export data",
                      mode='w',
                      defaultextension=".xlf",
                      filetypes=[('X-Light format', '.xlf'),
                                 ('all files', '.*')])
    if f is not None and f is not '':
        for widget in main.Frame1_2.winfo_children():
            widget.destroy()
        Label(main.Frame1_2, text="Export").pack(side=LEFT)
        progress = Progressbar(main.Frame1_2,
                               orient="horizontal",
                               mode='determinate')
        progress.pack(side=LEFT)
        progress["value"] = 0
        progress["maximum"] = 3

        f_split = (import_XRD.file_link[nfile]).split("/")
        filename = f_split[len(f_split) - 1]
        rotate = import_XRD.rotate
        flip = import_XRD.flip

        progress["value"] = progress["value"] + 1
        progress.update()

        data = read_data_2D(nimage, import_XRD)
        if len(data.shape) == 3:
            data = data[nimage_i]

        if len(data) == 0:
            showinfo(title="Warning",
                     message="Can not read data of " + str(filename))
            return

        progress["value"] = progress["value"] + 1
        progress.update()

        if rotate == 0:
            nrow = import_XRD.nrow[nimage]
            ncol = import_XRD.ncol[nimage]
            center_row = import_XRD.center_row[nimage]
            center_col = import_XRD.center_col[nimage]
            row_tick = import_XRD.row_tick[nimage]
            col_tick = import_XRD.col_tick[nimage]

        if rotate == 90:
            data = np.rot90(data, k=1, axes=(0, 1))
            nrow = import_XRD.ncol[nimage]
            ncol = import_XRD.nrow[nimage]
            center_row = import_XRD.center_col[nimage]
            center_col = import_XRD.center_row[nimage]
            row_tick = import_XRD.col_tick[nimage]
            col_tick = import_XRD.row_tick[nimage]

        if rotate == 180:
            data = np.rot90(data, k=2, axes=(0, 1))
            nrow = import_XRD.nrow[nimage]
            ncol = import_XRD.ncol[nimage]
            center_row = import_XRD.center_row[nimage]
            center_col = import_XRD.center_col[nimage]
            row_tick = import_XRD.row_tick[nimage]
            col_tick = import_XRD.col_tick[nimage]

        if rotate == 270:
            data = np.rot90(data, k=3, axes=(0, 1))
            nrow = import_XRD.ncol[nimage]
            ncol = import_XRD.nrow[nimage]
            center_row = import_XRD.center_col[nimage]
            center_col = import_XRD.center_row[nimage]
            row_tick = import_XRD.col_tick[nimage]
            col_tick = import_XRD.row_tick[nimage]

        if flip == 1:
            data = np.flip(data, axis=0)
        if flip == 2:
            data = np.flip(data, axis=1)

        f.write("Phi=" + str(import_XRD.phi[nimage]) + "\n")
        f.write("Chi=" + str(import_XRD.chi[nimage]) + "\n")
        f.write("Omega=" + str(import_XRD.omega[nimage]) + "\n")
        f.write("2theta=" + str(import_XRD.twotheta_center[nimage]) + "\n")
        f.write("Wavelength=" + str(import_XRD.k_alpha[nimage]) + "\n")
        f.write("Distance=" + str(import_XRD.distance[nimage]) + "\n")
        f.write("------------------------------------------\n")
        f.write("NRow=" + str(nrow) + "\n")
        f.write("Center Row=" + str(center_row) + "\n")
        for i in range(nrow):
            f.write(str(row_tick[i]) + " ")
        f.write("\n")
        f.write("NCol=" + str(ncol) + "\n")
        f.write("Center Col=" + str(center_col) + "\n")
        for i in range(ncol):
            f.write(str(col_tick[i]) + " ")
        f.write("\n")
        f.write("------------------------------------------\n")
        f.write("------------------------------------------\n")

        progress["value"] = progress["value"] + 1
        progress.update()

        for i in range(nrow):
            f.write(" ".join(str(e) for e in data[i]))
            if i < nrow - 1:
                f.write("\n")

        progress["value"] = progress["value"] + 1
        progress.update()

    f.close()
    for widget in main.Frame1_2.winfo_children():
        widget.destroy()
    main.root.mainloop()
Ejemplo n.º 3
0
def export_calib_data(calib_2D, angles_modif, import_XRD, main):
    from residual_stress_2D.calib_XRD_2D import calib_pyFai

    f = asksaveasfile(title="Export data",
                      mode='w',
                      defaultextension=".xlf",
                      filetypes=[('X-Light format', '.xlf'),
                                 ('all files', '.*')])
    if f is not None and f is not '':
        for widget in main.Frame1_2.winfo_children():
            widget.destroy()
        Label(main.Frame1_2, text="Export").pack(side=LEFT)
        progress = Progressbar(main.Frame1_2,
                               orient="horizontal",
                               mode='determinate')
        progress.pack(side=LEFT)
        progress["value"] = 0
        progress["maximum"] = 3

        rotate = import_XRD.rotate
        flip = import_XRD.flip

        if calib_2D.angles_modif_valid == True:
            twotheta_x = angles_modif.twotheta_x
            gamma_y = angles_modif.gamma_y
            phi = angles_modif.phi[calib_2D.nimage]
            chi = angles_modif.chi[calib_2D.nimage]
            omega = angles_modif.omega[calib_2D.nimage]
            twotheta_center = angles_modif.twotheta_center[calib_2D.nimage]
        else:
            twotheta_x = calib_2D.twotheta_x
            gamma_y = calib_2D.gamma_y
            phi = calib_2D.phi[calib_2D.nimage]
            chi = calib_2D.chi[calib_2D.nimage]
            omega = calib_2D.omega[calib_2D.nimage]
            twotheta_center = calib_2D.twotheta_center[calib_2D.nimage]

        progress["value"] = progress["value"] + 1
        progress.update()

        data = read_data_2D(calib_2D.nimage, import_XRD)

        if len(data.shape) == 3:
            data = data[import_XRD.nimage_i[calib_2D.nimage]]

        if len(data) == 0:
            showinfo(title="Warning",
                     message="Can not read data of " + str(filename))
            return

        if rotate == 0:
            nrow = import_XRD.nrow[calib_2D.nimage]
            ncol = import_XRD.ncol[calib_2D.nimage]
            center_row = import_XRD.center_row[calib_2D.nimage]
            center_col = import_XRD.center_col[calib_2D.nimage]

        if rotate == 90:
            data = np.rot90(data, k=1, axes=(0, 1))
            nrow = import_XRD.ncol[calib_2D.nimage]
            ncol = import_XRD.nrow[calib_2D.nimage]
            center_row = import_XRD.center_col[calib_2D.nimage]
            center_col = import_XRD.center_row[calib_2D.nimage]

        if rotate == 180:
            data = np.rot90(data, k=2, axes=(0, 1))
            nrow = import_XRD.nrow[calib_2D.nimage]
            ncol = import_XRD.ncol[calib_2D.nimage]
            center_row = import_XRD.center_row[calib_2D.nimage]
            center_col = import_XRD.center_col[calib_2D.nimage]

        if rotate == 270:
            data = np.rot90(data, k=3, axes=(0, 1))
            nrow = import_XRD.ncol[calib_2D.nimage]
            ncol = import_XRD.nrow[calib_2D.nimage]
            center_row = import_XRD.center_col[calib_2D.nimage]
            center_col = import_XRD.center_row[calib_2D.nimage]

        if flip == 1:
            data = np.flip(data, axis=0)

        if flip == 2:
            data = np.flip(data, axis=1)

        progress["value"] = progress["value"] + 1
        progress.update()
        calib = calib_pyFai(import_XRD, data, nrow, ncol, center_row,
                            center_col, twotheta_center)

        if len(calib) > 0:
            data = calib[0]
        else:
            showinfo(title="Warning",
                     message="Can not calib file " + str(filename))
            return

        if float(calib_2D.Check_twotheta_flip.get()) == 1:
            data = np.flip(data, axis=1)

        if len(data) > 0:
            progress["value"] = progress["value"] + 1
            progress.update()
            nrow = len(gamma_y)
            ncol = len(twotheta_x)

            f.write("Phi=" + str(phi) + "\n")
            f.write("Chi=" + str(chi) + "\n")
            f.write("Omega=" + str(omega) + "\n")
            f.write("2theta=" + str(twotheta_center) + "\n")
            f.write("Wavelength=" + str(import_XRD.k_alpha[calib_2D.nimage]) +
                    "\n")
            f.write("Distance=" + str(import_XRD.distance[calib_2D.nimage]) +
                    "\n")
            f.write("------------------------------------------\n")
            f.write("NRow=" + str(nrow) + "\n")
            f.write("Center Row=" + str(center_row) + "\n")
            for i in range(nrow):
                f.write(str(gamma_y[i]) + " ")
            f.write("\n")
            f.write("NCol=" + str(ncol) + "\n")
            f.write("Center Col=" + str(center_col) + "\n")
            for i in range(ncol):
                f.write(str(twotheta_x[i]) + " ")
            f.write("\n")
            f.write("------------------------------------------\n")
            f.write("------------------------------------------\n")

            progress["value"] = progress["value"] + 1
            progress.update()

            for i in range(nrow):
                f.write(" ".join(str(e) for e in data[i]))
                f.write("\n")

            progress["value"] = progress["value"] + 1
            progress.update()
    for widget in main.Frame1_2.winfo_children():
        widget.destroy()
    f.close()
    main.root.mainloop()
Ejemplo n.º 4
0
def export_all_original_data(import_XRD, main):
    location = askdirectory(title="Please choose a directory")
    if location is not None and location is not '':
        for widget in main.Frame1_2.winfo_children():
            widget.destroy()
        Label(main.Frame1_2, text="Export").pack(side=LEFT)
        progress = Progressbar(main.Frame1_2,
                               orient="horizontal",
                               mode='determinate')
        progress.pack(side=LEFT)
        progress["value"] = 0
        progress["maximum"] = len(import_XRD.nfile)

        rotate = import_XRD.rotate
        flip = import_XRD.flip

        for i in range(len(import_XRD.nfile)):
            progress["value"] = progress["value"] + 1
            progress.update()

            f_split = (import_XRD.file_link[import_XRD.nfile[i]]).split("/")
            filename = f_split[len(f_split) - 1]
            name = str(location) + '/' + str(
                filename.split('.')[0]) + '_' + str(
                    import_XRD.nimage_i[i]) + '.xlf'
            f = open(name, 'w')

            data = read_data_2D(i, import_XRD)
            if len(data.shape) == 3:
                data = data[import_XRD.nimage_i[i]]

            if len(data) == 0:
                showinfo(title="Warning",
                         message="Can not read data of " + str(filename))
                return

            if rotate == 0:
                nrow = import_XRD.nrow[i]
                ncol = import_XRD.ncol[i]
                center_row = import_XRD.center_row[i]
                center_col = import_XRD.center_col[i]
                row_tick = import_XRD.row_tick[i]
                col_tick = import_XRD.col_tick[i]

            if rotate == 90:
                data = np.rot90(data, k=1, axes=(0, 1))
                nrow = import_XRD.ncol[i]
                ncol = import_XRD.nrow[i]
                center_row = import_XRD.center_col[i]
                center_col = import_XRD.center_row[i]
                row_tick = import_XRD.col_tick[i]
                col_tick = import_XRD.row_tick[i]

            if rotate == 180:
                data = np.rot90(data, k=2, axes=(0, 1))
                nrow = import_XRD.nrow[i]
                ncol = import_XRD.ncol[i]
                center_row = import_XRD.center_row[i]
                center_col = import_XRD.center_col[i]
                row_tick = import_XRD.row_tick[i]
                col_tick = import_XRD.col_tick[i]

            if rotate == 270:
                data = np.rot90(data, k=3, axes=(0, 1))
                nrow = import_XRD.ncol[i]
                ncol = import_XRD.nrow[i]
                center_row = import_XRD.center_col[i]
                center_col = import_XRD.center_row[i]
                row_tick = import_XRD.col_tick[i]
                col_tick = import_XRD.row_tick[i]

            if flip == 1:
                data = np.flip(data, axis=0)
            if flip == 2:
                data = np.flip(data, axis=1)

            f.write("Phi=" + str(import_XRD.phi[i]) + "\n")
            f.write("Chi=" + str(import_XRD.chi[i]) + "\n")
            f.write("Omega=" + str(import_XRD.omega[i]) + "\n")
            f.write("2theta=" + str(import_XRD.twotheta_center[i]) + "\n")
            f.write("Wavelength=" + str(import_XRD.k_alpha[i]) + "\n")
            f.write("Distance=" + str(import_XRD.distance[i]) + "\n")
            f.write("------------------------------------------\n")
            f.write("NRow=" + str(nrow) + "\n")
            f.write("Center Row=" + str(center_row) + "\n")
            for j in range(nrow):
                f.write(str(row_tick[j]) + " ")
            f.write("\n")
            f.write("NCol=" + str(ncol) + "\n")
            f.write("Center Col=" + str(center_col) + "\n")
            for j in range(ncol):
                f.write(str(col_tick[j]) + " ")
            f.write("\n")
            f.write("------------------------------------------\n")
            f.write("------------------------------------------\n")

            progress["value"] = progress["value"] + 1
            progress.update()

            for i in range(nrow):
                f.write(" ".join(str(e) for e in data[i]))
                if i < nrow - 1:
                    f.write("\n")

            f.close()

    for widget in main.Frame1_2.winfo_children():
        widget.destroy()
    main.root.mainloop()