qz = q_values["qz"] qy = q_values["qy"] print("Loaded: qx shape:", qx.shape, "qz shape:", qz.shape, "qy shape:", qy.shape) if ( not ( *qx.shape, *qz.shape, *qy.shape, ) == data.shape ): raise ValueError("q values and data shape are incompatible") # crop the q values to the region of interest used in plots qx = util.crop_pad_1d( array=qx, output_length=plot_range[0] + plot_range[1], crop_center=zcom ) qz = util.crop_pad_1d( array=qz, output_length=plot_range[2] + plot_range[3], crop_center=ycom ) qy = util.crop_pad_1d( array=qy, output_length=plot_range[4] + plot_range[5], crop_center=xcom ) print("Cropped: qx shape:", qx.shape, "qz shape:", qz.shape, "qy shape:", qy.shape) q_range = (qx.min(), qx.max(), qz.min(), qz.max(), qy.min(), qy.max()) else: # crop the q values to the region of interest used in plots q_range = ( 0, plot_range[0] + plot_range[1],
# crop q to accomodate a shape change of the original array # (e.g. cropping to fit FFT shape requirement) if qvalues_binned: if len(qx) < pynx_shape[0]: raise ValueError( "qx declared binned, its length should be >= " "pynx_shape[0]" ) if len(qy) < pynx_shape[2]: raise ValueError( "qy declared binned, its length should be >= " "pynx_shape[2]" ) if len(qz) < pynx_shape[1]: raise ValueError( "qz declared binned, its length should be >= " "pynx_shape[1]" ) qx = util.crop_pad_1d(qx, pynx_shape[0]) # qx along z qy = util.crop_pad_1d(qy, pynx_shape[2]) # qy along x qz = util.crop_pad_1d(qz, pynx_shape[1]) # qz along y else: if len(qx) < unbinned_shape[0]: raise ValueError( "qx declared unbinned, its length should be >= " "unbinned_shape[0]" ) if len(qy) < unbinned_shape[2]: raise ValueError( "qy declared unbinned, its length should be >= " "unbinned_shape[2]" ) if len(qz) < unbinned_shape[1]: raise ValueError( "qz declared unbinned, its length should be >= " "unbinned_shape[1]" )
fig.savefig(datadir + "S" + str(scan) + "_maskpynx" + comment + ".png") plt.close(fig) del mask gc.collect() if load_qvalues: file_path = filedialog.askopenfilename( initialdir=datadir, title="Select the file containing 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 qx = util.crop_pad_1d(qx, roi_size[0], crop_center=crop_center[0]) # qx along z qy = util.crop_pad_1d(qy, roi_size[2], crop_center=crop_center[2]) # qy along x qz = util.crop_pad_1d(qz, roi_size[1], crop_center=crop_center[1]) # qz along y numz, numy, numx = len(qx), len(qz), len(qy) qx = qx[: numz - (numz % binning[0]) : binning[0]] # along z downstream qz = qz[: numy - (numy % binning[1]) : binning[1]] # along y vertical qy = qy[: numx - (numx % binning[2]) : binning[2]] # along x outboard np.savez_compressed( datadir + "S" + str(scan) + "_qvalues_" + comment + ".npz", qx=qx, qz=qz, qy=qy ) print("End of script") plt.ioff() plt.show()
("width_x", width_x), ("cut_z", cut_z), ("cut_y", cut_y), ("cut_x", cut_x), ]) # define the maximum identical length that can share the linecuts # (we need to concatenate them) width_length = min(width_z.size, width_y.size, width_x.size) linecuts = np.empty( (6, width_length )) # rows 0:3 for the widths, rows 3:6 for the corresponding cuts idx = 0 for key in linecuts_dict.keys(): # order is maintained in OrderedDict linecuts[idx, :] = util.crop_pad_1d( linecuts_dict[key], output_length=width_length) # implicit crop from the center idx += 1 # create nb_fit sets of parameters, one per data set fit_params = Parameters() for idx in range( 3): # 3 linecuts in orthogonal directions to be fitted by a gaussian fit_params.add("amp_%i" % (idx + 1), value=1, min=0.1, max=100) fit_params.add( "cen_%i" % (idx + 1), value=linecuts[idx, :].mean(), min=linecuts[idx, :].min(), max=linecuts[idx, :].max(), ) fit_params.add("sig_%i" % (idx + 1), value=5, min=0.1, max=100)