| 1 |
+++ |
| 2 |
title = "Experiment at GALAXI" |
| 3 |
weight = 30 |
| 4 |
+++ |
| 5 |
|
| 6 |
## Experiment at GALAXI |
| 7 |
|
| 8 |
This is an example of a real data fit. We use our own measurements performed at the laboratory diffractometer [GALAXI](https://www.fz-juelich.de/en/jcns/jcns-2/expertise/in-house-x-ray/galaxi) in Forschungszentrum Jülich. |
| 9 |
|
| 10 |
{{< galleryscg >}} |
| 11 |
{{< figscg src="/img/draw/FitGALAXIData_setup.jpg" width="350px" caption="Real-space model">}} |
| 12 |
{{< figscg src="/img/draw/FitGALAXIData.png" width="350px" caption="Fit window">}} |
| 13 |
{{< /galleryscg >}} |
| 14 |
|
| 15 |
* The sample represents a 4 layer system (substrate, teflon, hmdso and air) with Ag nanoparticles placed inside the hmdso layer on top of the teflon layer. |
| 16 |
* The sample is generated with the help of a `SampleBuilder`, which is able to create samples depending on parameters defined in the constructor and passed through to the `create_sample` method. |
| 17 |
* The nanoparticles have a broad log-normal size distribution. |
| 18 |
* The detector is created to represent the PILATUS detector from the experiment (line 19). |
| 19 |
* In the simulation settings the beam is initialized and the detector is assigned to the simulation. A region of interest is assigned at line 39 to simulate only a small rectangular window. Additionally, a rectangular mask is added to exclude the reflected beam from the analysis (line 40). |
| 20 |
* The real data is loaded from a tiff file into a histogram representing the detector's channels. |
| 21 |
* The `run_fitting()` function contains the initialization of the fitting kernel: loading experimental data, assignment of fit pair, fit parameters selection (line 62). |
| 22 |
|
| 23 |
## Experiment description |
| 24 |
|
| 25 |
To successfully simulate and fit results of some real experiment it is important to have |
| 26 |
|
| 27 |
+ A good guess about the sample structure and the initial values of the sample parameters. |
| 28 |
+ Full information about the instrument geometry: size and angular range of the detector. |
| 29 |
+ A 2D numpy array containing the intensities measured in the detector channels. |
| 30 |
|
| 31 |
### Experiment |
| 32 |
|
| 33 |
As an example we will use our own measurements performed at the laboratory diffractometer [GALAXI](https://www.fz-juelich.de/en/jcns/jcns-2/expertise/in-house-x-ray/galaxi) in Forschungszentrum Jülich. |
| 34 |
|
| 35 |
Our sample represents a 3-layer system (substrate, teflon and air) |
| 36 |
with Ag nanoparticles sitting on top of the teflon layer. |
| 37 |
The PILATUS 1M detector was placed at a distance of 1730 mm from the sample. |
| 38 |
|
| 39 |
{{< figscg src="/img/draw/setup_galaxi_experiment.png" class="center" >}} |
| 40 |
|
| 41 |
The results of the measurement are represented by the intensity image taken in certain conditions |
| 42 |
(beam wavelength, grazing angle, detector angular range) and stored in a 32-bit tiff file. To be able to fit these data we have to |
| 43 |
|
| 44 |
* prepare a description of the simulation |
| 45 |
* load the experimental data in BornAgain's fitting engine |
| 46 |
|
| 47 |
### Preparing the simulation description |
| 48 |
|
| 49 |
From the experimental setup we know the number pixels and detector angular range. |
| 50 |
In BornAgain, we will represent this setup using the `SphericalDetector` object. |
| 51 |
A detector corresponding to a PILATUS detector: |
| 52 |
|
| 53 |
```python |
| 54 |
npx, npy = 981, 1043 |
| 55 |
phi_min, phi_max = (-1.7*deg, 1.7*deg) |
| 56 |
alpha_min, alpha_max = (-0.6*deg, 1.24*deg) |
| 57 |
|
| 58 |
detector = ba.SphericalDetector(npx, phi_min, phi_max, npy, alpha_min, alpha_max) |
| 59 |
``` |
| 60 |
|
| 61 |
### Setting the region of interest |
| 62 |
|
| 63 |
To speed-up the simulation and to avoid an influence from uninteresting areas on the fit flow it is often convenient to define a certain region of interest `roi`. In our example we set the `roi` to the rectangle with lower left corner coordinates and upper right corner coordinates, where coordinates are expressed in detector units ('deg') |
| 64 |
|
| 65 |
<!-- |
| 66 |
```python |
| 67 |
simulation.setRegionOfInterest(85.0, 70.0, 120.0, 92.) |
| 68 |
``` |
| 69 |
--> |
| 70 |
|
| 71 |
{{< galleryscg >}} |
| 72 |
{{< figscg src="/img/draw/galaxi_imported_data.png" width="350px" class="center">}} |
| 73 |
{{< figscg src="/img/draw/galaxi_cropped_data.png" width="350px" class="center">}} |
| 74 |
{{< /galleryscg >}} |
| 75 |
|
| 76 |
The final simulation setup looks as follows: |
| 77 |
|
| 78 |
```python |
| 79 |
simulation = ScatteringSimulation() |
| 80 |
simulation.setDetector(detector) # this is our rectangular detector |
| 81 |
simulation.setSample(sample) # sample creation is not covered by this tutorial |
| 82 |
simulation.setBeamParameters(1.34*angstrom, 0.463*degree, 0.0) |
| 83 |
simulation.setBeamIntensity(1.2e7) |
| 84 |
``` |
| 85 |
<!-- |
| 86 |
simulation.setRegionOfInterest(85.0, 70.0, 120.0, 92.) |
| 87 |
--> |
| 88 |
|
| 89 |
During the fit, only the part of the detector corresponding to the `roi` will be simulated and used for $\chi^2$ calculations. |
| 90 |
|
| 91 |
### Importing the real data using Fabio library |
| 92 |
|
| 93 |
The [Fabio library](https://github.com/silx-kit/fabio) provides a convenient way to import experimental data in the form of a `numpy` array. |
| 94 |
|
| 95 |
```python |
| 96 |
import fabio |
| 97 |
|
| 98 |
img = fabio.open("galaxi_data.tif.gz") |
| 99 |
data = img.data.astype("float64") |
| 100 |
``` |
| 101 |
|
| 102 |
The main requirement is that the shape of the numpy array coincides with the number of detector channels (i.e. `npx, npy = 981, 1043` for given example). |
| 103 |
|
| 104 |
{{< show-ex file="fit/scatter2d/expfit_galaxi.py" >}} |
| 105 |
|
| 106 |
Data to be fitted: {{% ref-data-scat2d galaxi_data.tif.gz %}} |