Commit 23b572b3 authored by payno's avatar payno
Browse files

[doc] add missing dimension in notebook

parent a9c30a41
Pipeline #39022 passed with stages
in 6 minutes and 13 seconds
%% Cell type:markdown id: tags:
# PyMca XAS treatments
## pymca functions
The est processes are made from pymca functions. The main class dealing with XAS in pymca is the `XASClass`
Here is the initialization of the class:
%% Cell type:code id: tags:
``` python
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
pymca_xas = XASClass()
```
%% Cell type:markdown id: tags:
The XASClass is associated to a `XASParameters`
%% Cell type:markdown id: tags:
Then we have to set some spectrum
%% Cell type:code id: tags:
``` python
from PyMca5.PyMcaIO import specfilewrapper as specfile
def read_spectrum(spec_file):
"""
:param spec_file: path to the spec file containing the spectrum definition
:return: (energy, mu)
:rtype: tuple
"""
scan = specfile.Specfile(spec_file)[0]
data = scan.data()
if data.shape[0] == 2:
energy = data[0, :]
mu = data[1, :]
else:
energy = None
mu = None
labels = scan.alllabels()
i = 0
for label in labels:
if label.lower() == "energy":
energy = data[i, :]
elif label.lower() in ["counts", "mu", "absorption"]:
mu = data[i, :]
i = i + 1
if (energy is None) or (mu is None):
if len(labels) == 3:
if labels[0].lower() == "point":
energy = data[1, :]
mu = data[2, :]
else:
energy = data[0, :]
mu = data[1, :]
else:
energy = data[0, :]
mu = data[1, :]
return energy, mu
```
%% Cell type:code id: tags:
``` python
import os
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
energy, mu = read_spectrum(data_file)
print(energy)
print(mu)
pymca_xas = XASClass()
pymca_xas.setSpectrum(energy, mu)
```
%% Cell type:markdown id: tags:
### normalization
%% Cell type:code id: tags:
``` python
ddict_norm = pymca_xas.normalize()
ddict_norm
```
%% Cell type:markdown id: tags:
output should be
%% Cell type:markdown id: tags:
### EXAFS (signal extraction)
%% Cell type:code id: tags:
``` python
from PyMca5.PyMcaPhysics.xas.XASClass import e2k
params = pymca_xas._configuration["DefaultBackend"]["EXAFS"]
e0 = ddict_norm["Edge"]
kValues = e2k(energy - e0)
ddict_pe = pymca_xas.postEdge(k=kValues, mu=mu, backend=None)
print(ddict_pe)
```
%% Cell type:markdown id: tags:
### k weight
%% Cell type:markdown id: tags:
will just update k in the EXAFS and Fourier transform classes.
%% Cell type:markdown id: tags:
### Fourier transform
%% Cell type:code id: tags:
``` python
from PyMca5.PyMcaPhysics.xas.XASClass import XASClass
pymca_xas = XASClass()
ddict = pymca_xas.fourierTransform(k=kValues, mu=mu, kMin=None, kMax=None)
```
%% Cell type:markdown id: tags:
## est - xas workflow
To keep compatibility and to normalize the process we defined processes from tomwer which are based on the pymca functions.
Those are simple function to be called with a configuration (as a dict)
%% Cell type:markdown id: tags:
TODO: present XASBase and PyMcaXAS classes
%% Cell type:markdown id: tags:
Reading a spectrum file (and a configuration file)
%% Cell type:code id: tags:
``` python
from PyMca5.PyMcaDataDir import PYMCA_DATA_DIR
import os
data_file = os.path.join(PYMCA_DATA_DIR, "EXAFS_Cu.dat")
```
%% Cell type:code id: tags:
``` python
from est.core.io import read as read_pymca_xas
from silx.io.url import DataUrl
from est.core.types import Dim
spec_url = DataUrl(file_path=data_file, scheme='PyMca')
print(spec_url.scheme())
xas_obj = read_pymca_xas(spectra_url=DataUrl(file_path=data_file, scheme='PyMca'), channel_url=DataUrl(file_path=data_file, scheme='PyMca'), dimensions=(Dim.X_DIM, Dim.Y_DIM))
xas_obj = read_pymca_xas(spectra_url=DataUrl(file_path=data_file, scheme='PyMca'), channel_url=DataUrl(file_path=data_file, scheme='PyMca'), dimensions=(Dim.CHANNEL_ENERGY_DIM, Dim.X_DIM, Dim.Y_DIM))
assert 'Mu' in xas_obj.spectra[0]
```
%% Cell type:markdown id: tags:
### normalization
%% Cell type:code id: tags:
``` python
from est.core.process.pymca.normalization import pymca_normalization
xas_obj = pymca_normalization(xas_obj.copy())
assert 'NormalizedMu' in xas_obj.spectra[0]
```
%% Cell type:markdown id: tags:
### exafs
%% Cell type:code id: tags:
``` python
from est.core.process.pymca.exafs import pymca_exafs
xas_obj = pymca_exafs(xas_obj.copy())
assert 'PostEdgeB' in xas_obj.spectra[0]
```
%% Cell type:markdown id: tags:
### k weight
%% Cell type:code id: tags:
``` python
from est.core.process.pymca.k_weight import pymca_k_weight
l_xas_obj = xas_obj.copy()
l_xas_obj.configuration['SET_KWEIGHT'] = 1
xas_obj = pymca_k_weight(l_xas_obj)
assert xas_obj.spectra[0]['KWeight'] == 1
```
%% Cell type:markdown id: tags:
### Fourier transform
%% Cell type:code id: tags:
``` python
from est.core.process.pymca.ft import pymca_ft
xas_obj = pymca_ft(xas_obj.copy())
assert 'FTRadius' in xas_obj.spectra[0]['FT']
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment