How to use
All tutorials use publicly available datasets hosted on the Zenodo repository: https://zenodo.org/records/17466183 The required data are downloaded automatically when running the scripts.
from pygid.datasets import get_dataset, clear_dataset_cache
files = get_dataset("tutorial_00")
# clean up downloaded dataset
clear_dataset_cache()
Below is a minimal working example demonstrating how to use pygid to convert 2D detector images
to reciprocal space coordinates in a grazing-incidence diffraction (GID) geometry.
Download example dataset from Zenodo or set your own files:
files = pygid.datasets.get_dataset("tutorial_00")
data_path = files["data_peaks"]
poni_path = files["poni_peaks"]
mask_path = files["mask_peaks"]
Load experimental parameters from the PONI file
import pygid
params = pygid.ExpParams(
poni_path=poni_path, # path to the PONI file
mask_path=mask_path, # path to the mask file (EDF/ NPY/ TIFF)
fliplr=True, # horizontal flipping of the image
flipud=True, # vertical flipping of the image
transp=False, # 90 deg rotation of the image
ai=0.075, # angle of incidence in degrees
)
Create coordinate maps based on geometry and experimental setup
matrix = pygid.CoordMaps(
params,
vert_positive=False, # Cut the positive values for the vertical axis
hor_positive=False, # Cut the positive values for the horizontal axis
)
Initialize pygid.Conversion instance and load the detector image
analysis = pygid.Conversion(
matrix=matrix,
path=data_path, # path to the data file
)
Perform GID geometry conversion and plot the result, returns the axes and the converted image (list of images)
q_xy, q_z, img = analysis.det2q_gid(
plot_result=True, # plot the result of conversion
clims=(600, 1e5), # image color limits
save_fig=True, path_to_save_fig="240124_PEN_DIP_polar.png", # save figure
return_result=True, # return arrays
save_result=True, path_to_save="240124_PEN_DIP_result.h5", # save data as a NXsas (NeXus) file
overwrite_file=False, # overwrite the existing file
)