Ejemplo n.º 1
0
    if not flag_interact:
        plt.close(fig)

    fig, _, _ = gu.multislices_plot(mask, sum_frames=True, scale='linear', plot_colorbar=True, vmin=0,
                                    vmax=(nz, ny, nx), title='Mask', is_orthogonal=not use_rawdata,
                                    reciprocal_space=True)
    plt.savefig(savedir + 'mask_S' + str(scans[scan_nb]) + '_' + str(nz) + '_' + str(ny) + '_' +
                str(nx) + '_' + str(binning[0]) + '_' + str(binning[1]) + '_' + str(binning[2]) + comment + '.png')
    if not flag_interact:
        plt.close(fig)

    if detector.binning[0] != 1:
        ################################################################################################
        # bin the stacking axis if needed, the detector plane was already binned when loading the data #
        ################################################################################################
        data = pu.bin_data(data, (detector.binning[0], 1, 1), debugging=False)
        mask = pu.bin_data(mask, (detector.binning[0], 1, 1), debugging=False)
        mask[np.nonzero(mask)] = 1
        if not use_rawdata and len(q_vector) != 0:
            qx = qx[::binning[0]]  # along Z

        ############################
        # plot binned data and mask #
        ############################
        nz, ny, nx = data.shape
        print('Data size after binning the stacking dimension:', data.shape)
        comment = comment + "_" + str(nz) + "_" + str(ny) + "_" + str(nx)

        fig, _, _ = gu.multislices_plot(data, sum_frames=True, scale='log', plot_colorbar=True, vmin=0,
                                        title='Final data', is_orthogonal=not use_rawdata,
                                        reciprocal_space=True)
Ejemplo n.º 2
0
###################
colormap = gu.Colormap()
my_cmap = colormap.cmap

##############################
# load reciprocal space data #
##############################
plt.ion()
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(initialdir=root_folder,
                                       title="Select the diffraction pattern",
                                       filetypes=[("NPZ", "*.npz")])
npzfile = np.load(file_path)
diff_pattern = pu.bin_data(npzfile[list(npzfile.files)[0]].astype(int),
                           (bin_factor, bin_factor, bin_factor),
                           debugging=False)
diff_pattern[diff_pattern < threshold] = 0
nz, ny, nx = diff_pattern.shape
print('Data shape after binning:', nz, ny, nx)
gu.multislices_plot(diff_pattern,
                    sum_frames=True,
                    plot_colorbar=True,
                    cmap=my_cmap,
                    title='diffraction pattern',
                    scale='log',
                    vmin=np.nan,
                    vmax=np.nan,
                    reciprocal_space=True,
                    is_orthogonal=True)
#############
Ejemplo n.º 3
0
file_path = filedialog.askopenfilename(initialdir=homedir,
                                       title="Select q values",
                                       filetypes=[("NPZ", "*.npz")])
q_values = np.load(file_path)
qx = q_values['qx']  # 1D array
qy = q_values['qy']  # 1D array
qz = q_values['qz']  # 1D array

############
# bin data #
############
qx = qx[:nz - (nz % binning[0]):binning[0]]
qz = qz[:ny - (ny % binning[1]):binning[1]]
qy = qy[:nx - (nx % binning[2]):binning[2]]
data = pu.bin_data(data, (binning[0], binning[1], binning[2]), debugging=False)
print('Diffraction data shape after binning', data.shape)
nz, ny, nx = data.shape

##########################################
# take the largest data symmetrical in q #
##########################################
if crop_symmetric:
    if geometry == 'SAXS':
        # the reference if the center of reciprocal space at qx=qy=qz=0
        qx_com, qz_com, qy_com = 0, 0, 0
    elif geometry == 'Bragg':
        # find the position of the Bragg peak
        zcom, ycom, xcom = center_of_mass(data)
        zcom, ycom, xcom = int(np.rint(zcom)), int(np.rint(ycom)), int(
            np.rint(xcom))
Ejemplo n.º 4
0
# The shape will be equal to 'roi_final' parameter of the .cxi file
if len(crop_roi) == 6:
    diff_pattern = diff_pattern[crop_roi[0]:crop_roi[1], crop_roi[2]:crop_roi[3], crop_roi[4]:crop_roi[5]]
    mask = mask[crop_roi[0]:crop_roi[1], crop_roi[2]:crop_roi[3], crop_roi[4]:crop_roi[5]]
elif len(crop_roi) != 0:
    print('Crop_roi should be a list of 6 integers or a blank list!')
    sys.exit()

# bin the diffraction pattern and the mask to compensate the "rebin" option used in PyNX.
# update also the detector pixel sizes to take into account the binning
detector.pixelsize_y = detector.pixelsize_y * phasing_binning[1]
detector.pixelsize_x = detector.pixelsize_x * phasing_binning[2]
final_binning = np.multiply(pre_binning, phasing_binning)
detector.binning = final_binning
print('Pixel sizes after phasing_binning (vertical, horizontal): ', detector.pixelsize_y, detector.pixelsize_x, '(m)')
diff_pattern = pu.bin_data(array=diff_pattern, binning=phasing_binning, debugging=False)
mask = pu.bin_data(array=mask, binning=phasing_binning, debugging=False)

numz, numy, numx = diff_pattern.shape  # this shape will be used for the calculation of q values
print('\nMeasured data shape =', numz, numy, numx, ' Max(measured amplitude)=', np.sqrt(diff_pattern).max())
diff_pattern[np.nonzero(mask)] = 0

z0, y0, x0 = center_of_mass(diff_pattern)
z0, y0, x0 = [int(z0), int(y0), int(x0)]
print("COM of measured pattern after masking: ", z0, y0, x0, ' Number of unmasked photons =', diff_pattern.sum())

fig, _, _ = gu.multislices_plot(np.sqrt(diff_pattern), sum_frames=False, title='3D diffraction amplitude', vmin=0,
                                vmax=3.5, is_orthogonal=False, reciprocal_space=True, slice_position=[z0, y0, x0],
                                scale='log', plot_colorbar=True)

plt.figure()
Ejemplo n.º 5
0
    slice_2D = slice_2D[crop_roi[0]:crop_roi[1], crop_roi[2]:crop_roi[3]]
    mask_2D = mask_2D[crop_roi[0]:crop_roi[1], crop_roi[2]:crop_roi[3]]
elif len(crop_roi) != 0:
    print('Crop_roi should be a list of 6 integers or a blank list!')
    sys.exit()

# bin the diffraction pattern and the mask to compensate the "rebin" option used in PyNX.
# update also the detector pixel sizes to take into account the binning
detector.pixelsize_y = detector.pixelsize_y * phasing_binning[1]
detector.pixelsize_x = detector.pixelsize_x * phasing_binning[2]
final_binning = np.multiply(pre_binning, phasing_binning)
detector.binning = final_binning
print('Pixel sizes after phasing_binning (vertical, horizontal): ',
      detector.pixelsize_y, detector.pixelsize_x, '(m)')
slice_2D = pu.bin_data(array=slice_2D,
                       binning=(phasing_binning[1], phasing_binning[2]),
                       debugging=False)
mask_2D = pu.bin_data(array=mask_2D,
                      binning=(phasing_binning[1], phasing_binning[2]),
                      debugging=False)

slice_2D[np.nonzero(mask_2D)] = 0

plt.figure()
plt.imshow(np.log10(np.sqrt(slice_2D)), cmap=my_cmap, vmin=0, vmax=3.5)
plt.title('2D diffraction amplitude')
plt.colorbar()
plt.pause(0.1)

######################
# calculate q values #
Ejemplo n.º 6
0
                                       title="Select diffraction pattern",
                                       filetypes=[("NPZ", "*.npz")])
npzfile = np.load(file_path)
diff_pattern = npzfile['data']
diff_pattern = diff_pattern.astype(float)

file_path = filedialog.askopenfilename(initialdir=detector.datadir,
                                       title="Select mask",
                                       filetypes=[("NPZ", "*.npz")])
npzfile = np.load(file_path)
mask = npzfile['mask']

if not rawdata_binned:
    if binning[1] != 1 or binning[2] != 1:
        diff_pattern = pu.bin_data(array=diff_pattern,
                                   binning=binning,
                                   debugging=True)
        mask = pu.bin_data(array=mask, binning=binning, debugging=True)
        mask[np.nonzero(mask)] = 1

numz, numy, numx = diff_pattern.shape
print('\nMeasured data shape =', numz, numy, numx, ' Max(measured amplitude)=',
      np.sqrt(diff_pattern).max())
diff_pattern[np.nonzero(mask)] = 0

z0, y0, x0 = center_of_mass(diff_pattern)
z0, y0, x0 = [int(z0), int(y0), int(x0)]
print("COM of measured pattern after masking: ", z0, y0, x0,
      ' Number of unmasked photons =', diff_pattern.sum())

plt.figure()