Skip to content

Commit

Permalink
save_xps module to save XPS data in two column format (#9)
Browse files Browse the repository at this point in the history
* save_xps to save XPS data in two column format

* Update __init__.py

* Update glossary.md

* Update xps.md

* Update xps.md

* Update xps.md

* Update save_xps.py

* Add files via upload

* Update xps.md

* Update xps.md
  • Loading branch information
pranabdas committed Mar 25, 2022
1 parent b45c73a commit 2aa71ac
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 20 deletions.
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""
Purpose: Python libraries for ARPES data analysis
Version: 20210821
Version: 20220325
@author: Pranab Das (GitHub: @pranabdas)
"""
from arpespythontools.src.crop_2d import crop_2d
Expand All @@ -18,3 +18,4 @@
from arpespythontools.src.plane_slice import plane_slice
from arpespythontools.src.rotate_2d import rotate_2d
from arpespythontools.src.rotate_3d import rotate_3d
from arpespythontools.src.save_xps import save_xps
33 changes: 24 additions & 9 deletions docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@ URL address.
- `energy` : 1D vector (numpy ndarry) of kinetic energy values in eV.


## plane_slice

```python
surf = arp.plane_slice(data, x, x_min, x_max)
```
Returns the 2D slice along the first dimension of `data` and integrated in the
width [x_min, x_max].

**Inputs:**
- `data` : 3D matrix.
- `x` : axes scaling along the first dimension.
- `x_min`, `x_max` : integration bounds.

**Outputs:**
- `surf` : 2D array.


## rotate_2d

```python
Expand Down Expand Up @@ -264,18 +281,16 @@ set to `NaN` (not a number).
- `phi_r` : 1D array of axis scaling along the third dimension of `data_r`.


## slice_plane
## save_xps

```python
surf = arp.slice_plane(data, x, x_min, x_max)
arp.save_xps(energy, intensity, "xps_data.x_y")
```
Returns the 2D slice along the first dimension of `data` and integrated in the
width [x_min, x_max].
Save XPS energy and intensity in two column plaintext file.

**Inputs:**
- `data` : 3D matrix.
- `x` : axes scaling along the first dimension.
- `x_min`, `x_max` : integration bounds.
- `energy` : one dimensional vector
- `intensity` : one dimensional vector
- `filename` : string value corresponding to filename.

**Outputs:**
- `surf` : 2D array.
No output is returned, only the data file is saved at specified filename.
41 changes: 33 additions & 8 deletions docs/xps.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ import numpy as np

data, energy, angle = arp.load("xps_data.txt")
intensity = arp.line_profile(data, angle, -2.5, 2.5)
```

# energy is in terms of kinetic energy (eV)
# if you need in terms of binding energy:
# e_bin = fermi_energy - e_kin
If you require energy in terms of binding energy instead of kinetic energy, you
can convert using:

xps_data = np.array([energy, intensity]).T
np.savetxt("xps_data.x_y", xps_data)
```
$$
E_{bin} = E_F - E_{kin}
$$

In the above example, we have saved the data in two column (`.x_y`) format,
which is suitable for importing to other XPS analysis software (like CasaXPS).
$$
E_F = h\nu - W_{\phi}
$$

where $E_F$ is Fermi energy, and $W_{\phi}$ is work function which is about 4.5
eV for our setup.

:::tip

Expand All @@ -43,3 +47,24 @@ intensity = np.sum(data, axis=1)
```

:::

### Save/export XPS data

```python
xps_data = np.array([energy, intensity]).T
np.savetxt("xps_data.x_y", xps_data)
```

In the above example, we have saved the data in two column (`.x_y`) format,
which is suitable for importing to other XPS analysis software (like CasaXPS).

We may also use the module `save_xps` to save data.

```python
arp.save_xps(energy, intensity, "xps_data.x_y")
```

If you need to load the two column data using python:
```python
energy, intensity = np.loadtxt("xps_data.x_y", unpack=True)
```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"homepage": ".",
"name": "arpespythontools",
"version": "0.2.1",
"version": "0.3.0",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
Expand Down
22 changes: 22 additions & 0 deletions src/save_xps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Program: Save XPS data in two column format
Version: 20220325
@author: Pranab Das (GitHub: @pranabdas)
"""


def save_xps(energy, intensity, filename=""):
import numpy as np
import datetime

if (filename == ""):
filename = "XPS_data_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S") + ".x_y"

# check energy and intensity have same length
if (len(energy) != len(intensity)):
raise ValueError("Lengths of input arrays do not match")
else:
data = np.array([energy, intensity]).T
np.savetxt(filename, data)

0 comments on commit 2aa71ac

Please sign in to comment.