---
jupytext:
  formats: md:myst
  text_representation:
    extension: .md
    format_name: myst
    format_version: 0.13
    jupytext_version: 1.11.5
kernelspec:
  display_name: Python 3
  language: python
  name: python3
---

# The tutorial 3rd 

Provides a tutorial on analyzing amorphous signals.

## coding

> **1. Save your diffraction data to the root directory and rename the file to `intensity.csv`.**





```{code-cell}
# import PyXplore package
from PyXplore import WPEM
import pandas as pd
```

> **2. Parse your diffraction data (`2θ`, intensity) and perform background processing.**

```{code-cell}
intensity_csv = pd.read_csv(r'intensity.csv',header=None )
var = WPEM.BackgroundFit(intensity_csv,lowAngleRange=3.8,poly_n=12,bac_split=8,bac_num=100)
```
> **3. After running the code, a new folder named `ConvertedDocuments` will be created in the root directory. This folder contains the background information.**

> **Copy the two important files — `bac.csv` and `no_bac_intensity.csv` — from `ConvertedDocuments` into the root directory, as they are required for the next steps.**


> **Parse the `.cif` file as demonstrated in the crystal fitting section, and generate the `peak0.csv` file.**






```{code-cell}
# The wavelength is set according to the actual light source
wavelength = [1.03]
# The file name of non-background data (2theta-intensity data)
no_bac_intensity_file = "no_bac_intensity.csv" 
# The file name of raw/original data (2theta-intensity data)
original_file = "intensity.csv"  
# The file name of background data (2theta-intensity data)
bacground_file = "bac.csv"  


# Input the initial lattice constants {a, b, c, α, β, γ}, whose values need to be assumed at initialization.
Lattice_constants = [[17.53,17.53,6.47,90,90,120],]

# Execute the model

WPEM.XRDfit(
    wavelength, var, Lattice_constants,no_bac_intensity_file, original_file, bacground_file, 
    subset_number=3,low_bound=6,up_bound=16,bta = 0.78,iter_max = 50, asy_C = 0,InitializationEpoch=0, 
    )
```



> After coverage, the amorphous components (referred to as "holes") are derived. You can visualize each amorphous hole using the provided plotting functions. The results are saved in the `DecomposedComponents` folder.

```{code-cell}
WPEM.Plot_Components(lowboundary = 4, upboundary = 19, wavelength = wavelength, Macromolecule = True,phase = 1)
```


```{seealso}
For demonstration purposes, the code uses `iter_max = 5` to reduce computational cost. However, for practical applications, it is recommended to set `iter_max` to at least 50 for more reliable results.
```