Skip to content

Commit

Permalink
Add reader for accurion data (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
quentintanguy authored Oct 2, 2024
1 parent e141ce0 commit c1ebe1b
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/elli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .dispersions import *
from .dispersions.base_dispersion import *
from .experiment import Experiment
from .importer.accurion import read_accurion_psi_delta
from .importer.nexus import *
from .importer.spectraray import *
from .importer.woollam import read_woollam_psi_delta, read_woollam_rho, scale_to_nm
Expand Down
40 changes: 40 additions & 0 deletions src/elli/importer/accurion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""A helper class to load data from Accurion EP4 DAT files.
Typical files look like: Si3N4_on_4inBF33_W03_20240905-105631.ds.dat
"""

import numpy as np
import pandas as pd

from . import detect_encoding


def read_accurion_psi_delta(fname: str) -> pd.DataFrame:
r"""Read a psi/delta Accurion dat file.
Args:
fname (str): Filename of the measured dat file
Returns:
pd.DataFrame: DataFrame containing the psi/delta data in the pyElli-compatible format.
"""
encoding = detect_encoding(fname)
psi_delta_df = pd.read_csv(
fname, delimiter="\t", encoding=encoding, skiprows=0, header=0
)[1:].astype(float)
psi_delta_df = psi_delta_df.reindex(columns=list(["AOI", "Lambda", "Delta", "Psi"]))
psi_delta_df = psi_delta_df.rename(
columns={
"AOI": "Angle of Incidence",
"Lambda": "Wavelength",
"Delta": "Δ",
"Psi": "Ψ",
}
)
psi_delta_df = psi_delta_df.groupby(["Angle of Incidence", "Wavelength"]).sum()

# wrap delta range
psi_delta_df.loc[:, "Δ"] = psi_delta_df.loc[:, "Δ"].where(
psi_delta_df.loc[:, "Δ"] <= 180, psi_delta_df.loc[:, "Δ"] - 360
)

return psi_delta_df
73 changes: 73 additions & 0 deletions src/elli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,79 @@ def calc_rho(psi_delta: pd.DataFrame) -> pd.DataFrame:
)


def convert_psi_delta_to_isotropic_mueller_matrix(psi_delta_df) -> pd.DataFrame:
r"""Extract aois and wavelengths values from psi_delta pandas.DataFrame and convert it to a Muellermatrix;
only works for isotropic media.
Args:
psi_delta_df (pd.DataFrame): dataFrame returned from data importers'
Returns:
pd.DataFrame: pyElli-compatible DataFrame of the Mueller matrix
"""
aois = psi_delta_df.index.get_level_values("Angle of Incidence").unique().to_numpy()
wavelengths = psi_delta_df.index.get_level_values("Wavelength").unique().to_numpy()

# create empty Mueller matrix
MM = pd.DataFrame(
{},
columns=[
"M11",
"M12",
"M13",
"M14",
"M21",
"M22",
"M23",
"M24",
"M31",
"M32",
"M33",
"M34",
"M41",
"M42",
"M43",
"M44",
],
index=pd.MultiIndex.from_product(
[aois, wavelengths], names=["Angle of Incidence", "Wavelength"]
),
dtype=float,
)

# fill in the Mueller matrix coefficients for an isotropic material based equation in https://www.jawoollam.com/resources/ellipsometry-faq#toggle-id-15
for aoi in aois:
for λ in wavelengths:
Δ = psi_delta_df.loc[aoi, λ]["Δ"]
Ψ = psi_delta_df.loc[aoi, λ]["Ψ"]

N = np.cos(2 * Ψ)
C = np.sin(2 * Ψ) * np.cos(2 * Δ)
S = np.sin(2 * Ψ) * np.cos(2 * Δ)

MM.loc[(aoi, λ), "M11"] = 1
MM.loc[(aoi, λ), "M12"] = -N
MM.loc[(aoi, λ), "M13"] = 0
MM.loc[(aoi, λ), "M14"] = 0

MM.loc[(aoi, λ), "M21"] = -N
MM.loc[(aoi, λ), "M22"] = 1
MM.loc[(aoi, λ), "M23"] = 0
MM.loc[(aoi, λ), "M24"] = 0

MM.loc[(aoi, λ), "M31"] = 0
MM.loc[(aoi, λ), "M32"] = 0
MM.loc[(aoi, λ), "M33"] = C
MM.loc[(aoi, λ), "M34"] = S

MM.loc[(aoi, λ), "M41"] = 0
MM.loc[(aoi, λ), "M42"] = 0
MM.loc[(aoi, λ), "M43"] = -S
MM.loc[(aoi, λ), "M44"] = C

return MM


def get_qwp_thickness(material: "Material", lbda: float) -> float:
"""Return the thickness of a material in nm for a quarter wave plate at wavelength 'lbda'.
Expand Down
16 changes: 16 additions & 0 deletions tests/test_accurion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Tests for reading accurion files"""

import pytest
from fixtures import datadir # pylint: disable=unused-import

import elli


# pylint: disable=redefined-outer-name
def test_reading_of_psi_delta_woollam(datadir):
"""Psi/delta Accurion file is read w/o errors"""
data = elli.read_accurion_psi_delta(
datadir / "Si3N4_on_4inBF33_W02_20240903-150451.ds.dat"
)

assert data.shape == (114, 2)
116 changes: 116 additions & 0 deletions tests/test_accurion/Si3N4_on_4inBF33_W02_20240903-150451.ds.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#ROIidx AOI Lambda Bandwidth ExposureTime ROI_x ROI_y Delta Psi
#- deg nm nm us �m �m deg deg
0 40.000 365.0 6.1 115908 417.6 409.8 179.785156 32.535931
0 40.000 370.0 6.3 113546 417.6 409.8 179.815674 32.514015
0 40.000 375.1 5.1 108872 417.6 409.8 179.887863 32.167427
0 40.000 380.4 6.3 128641 417.7 409.9 179.846115 32.424763
0 40.000 385.9 6.1 116358 417.7 409.9 179.964935 32.358204
0 40.000 391.4 6.3 107241 417.7 409.9 180.198441 32.235497
0 40.000 397.2 5.3 106364 417.8 410.0 180.418350 32.211399
0 40.000 403.1 4.3 71897 417.9 410.1 180.286850 32.482040
0 40.000 409.2 4.4 65173 418.0 410.2 179.812210 32.669853
0 40.000 415.5 4.3 54421 418.0 410.2 179.373871 32.483944
0 40.000 422.0 4.3 53257 418.0 410.2 179.641830 31.710491
0 40.000 428.7 4.3 50623 418.0 410.2 181.694778 30.964096
0 40.000 435.6 4.2 36828 418.0 410.2 182.461807 31.806063
0 40.000 442.8 4.2 26359 418.0 410.2 180.825607 33.171253
0 40.000 450.2 4.2 19839 417.8 410.0 179.336304 33.702694
0 40.000 457.8 4.2 21279 417.7 409.9 177.524414 32.973022
0 40.000 465.7 4.2 31348 417.7 409.9 175.019714 29.624680
0 40.000 473.8 4.1 38385 417.7 409.9 184.791260 25.209936
0 40.000 482.3 4.2 19254 417.6 409.8 184.419479 30.734592
0 40.000 491.1 4.1 10388 417.6 409.8 180.833572 33.546158
0 40.000 500.2 4.1 8430 417.6 409.8 179.733200 34.397530
0 40.000 509.6 4.1 8864 417.5 409.8 178.651398 33.714882
0 40.000 519.4 4.1 11995 417.6 409.8 175.087067 30.998163
0 40.000 529.6 4.0 23893 417.6 409.8 173.824173 23.673731
0 40.000 540.2 4.1 21080 417.6 409.8 186.372284 26.547739
0 40.000 551.2 4.0 10855 417.5 409.7 182.173080 31.793457
0 40.000 562.7 4.0 7704 417.5 409.7 180.295517 33.912464
0 40.000 574.6 4.0 6862 417.5 409.7 179.983643 34.416878
0 40.000 587.1 4.0 7236 417.5 409.7 179.309082 33.597958
0 40.000 600.2 4.0 10360 417.5 409.8 176.537186 31.162548
0 40.000 613.8 4.0 19510 417.5 409.7 173.198044 25.677353
0 40.000 628.1 4.0 23063 417.6 409.8 184.833145 24.293219
0 40.000 643.0 4.0 14486 417.5 409.7 183.686890 30.058107
0 40.000 658.7 4.0 9899 417.5 409.7 180.956879 32.944775
0 40.000 675.2 3.9 9021 417.5 409.7 180.208603 34.125999
0 40.000 692.5 4.0 10334 417.5 409.7 180.069046 34.137150
0 40.000 710.7 3.9 14555 417.5 409.7 179.159897 33.001068
0 40.000 729.9 3.9 24887 417.5 409.7 176.283844 30.347702
0 40.000 750.2 3.9 48739 417.4 409.6 174.189240 25.170830
0 40.000 771.6 3.9 70770 417.4 409.6 184.720505 24.475565
0 40.000 794.3 3.9 55938 417.3 409.5 183.936996 29.644312
0 40.000 818.4 3.9 32599 417.1 409.3 181.270737 32.460072
0 40.000 843.9 3.8 31036 417.0 409.2 180.351196 33.767361
0 40.000 871.1 3.9 36529 416.9 409.1 180.189163 34.017212
0 40.000 900.2 4.0 37733 416.7 409.0 179.688858 33.218037
0 40.000 931.2 4.0 86622 416.6 408.8 177.657486 31.222305
0 40.000 964.5 4.1 10000 415.7 407.9 174.415024 27.342821
0 40.000 1000.2 4.0 10000 415.4 407.7 179.864182 23.185122
0 40.000 1038.6 16.2 2000 415.3 407.5 185.227509 27.188955
0 40.000 1080.1 15.2 1000 414.7 406.9 182.442734 30.897955
0 40.000 1125.1 15.8 500 414.4 406.7 180.780197 32.758415
0 40.000 1174.0 15.5 500 414.0 406.3 180.278580 33.568390
0 40.000 1227.4 15.7 500 413.6 405.8 180.096664 33.390888
0 40.000 1285.8 15.5 500 413.0 405.3 179.265884 32.347992
0 40.000 1350.1 15.3 1000 412.4 404.7 176.933167 30.021086
0 40.000 1421.1 15.2 2000 411.6 403.9 174.649048 25.813662
0 40.000 1500.0 15.2 5000 410.8 403.1 182.420883 23.373127
0 50.000 365.0 6.1 99304 417.6 485.7 178.843552 24.810665
0 50.000 370.0 6.3 96358 417.6 485.7 178.964462 24.749041
0 50.000 375.1 5.1 91951 417.6 485.7 178.991089 24.369781
0 50.000 380.4 6.3 108300 417.7 485.7 179.151871 24.492798
0 50.000 385.9 6.1 96309 417.7 485.8 179.468231 24.393005
0 50.000 391.4 6.3 86936 417.7 485.8 179.905609 24.277151
0 50.000 397.2 5.3 85390 417.8 485.9 179.974823 24.345858
0 50.000 403.1 4.3 67175 417.9 486.0 179.356766 24.122259
0 50.000 409.2 4.4 57323 418.0 486.1 178.460342 23.916300
0 50.000 415.5 4.3 48297 418.0 486.1 178.428604 23.070536
0 50.000 422.0 4.3 43320 418.0 486.1 181.111557 22.034977
0 50.000 428.7 4.3 34430 418.0 486.1 184.108292 22.852648
0 50.000 435.6 4.2 25365 418.0 486.1 182.401993 24.759832
0 50.000 442.8 4.2 21877 418.0 486.1 179.166245 25.732731
0 50.000 450.2 4.2 18965 417.8 485.9 175.415115 24.907017
0 50.000 457.8 4.2 23424 417.7 485.8 169.615677 20.826052
0 50.000 465.7 4.2 31343 417.7 485.8 183.419647 13.086155
0 50.000 473.8 4.1 17746 417.7 485.8 193.585648 20.067593
0 50.000 482.3 4.2 11155 417.6 485.7 184.293884 25.110468
0 50.000 491.1 4.1 8289 417.6 485.7 180.189148 26.755682
0 50.000 500.2 4.1 8141 417.6 485.6 177.149246 26.053429
0 50.000 509.6 4.1 9827 417.5 485.6 169.979736 22.458136
0 50.000 519.4 4.1 15171 417.6 485.6 156.773636 12.537899
0 50.000 529.6 4.0 16265 417.6 485.6 201.814850 12.629531
0 50.000 540.2 4.1 10301 417.6 485.6 189.228500 21.872118
0 50.000 551.2 4.0 7338 417.5 485.6 182.627640 25.587080
0 50.000 562.7 4.0 6563 417.5 485.6 180.329788 26.667652
0 50.000 574.6 4.0 6816 417.5 485.6 178.143707 25.687355
0 50.000 587.1 4.0 7921 417.5 485.6 172.502869 22.448210
0 50.000 600.2 4.0 12574 417.5 485.6 161.035736 15.129194
0 50.000 613.8 4.0 18119 417.5 485.6 192.533127 9.284990
0 50.000 628.1 4.0 11782 417.6 485.6 193.886444 18.633699
0 50.000 643.0 4.0 8968 417.5 485.6 185.192657 23.722578
0 50.000 658.7 4.0 7736 417.5 485.6 181.651688 25.889843
0 50.000 675.2 3.9 8269 417.5 485.6 180.103348 26.204470
0 50.000 692.5 4.0 10528 417.5 485.6 177.809525 24.845982
0 50.000 710.7 3.9 15806 417.5 485.5 172.054810 21.499920
0 50.000 729.9 3.9 28690 417.5 485.5 162.292297 14.670518
0 50.000 750.2 3.9 44296 417.4 485.5 189.283432 9.236492
0 50.000 771.6 3.9 39952 417.4 485.4 195.174866 17.400213
0 50.000 794.3 3.9 35874 417.3 485.3 186.524353 22.558216
0 50.000 818.4 3.9 25575 417.1 485.1 182.435684 25.054333
0 50.000 843.9 3.8 27811 417.0 485.0 180.672882 25.813696
0 50.000 871.1 3.9 35932 416.9 484.8 179.018112 25.151432
0 50.000 900.2 4.0 38666 416.7 484.7 175.388931 22.909077
0 50.000 931.2 4.0 91719 416.6 484.5 167.497238 18.352949
0 50.000 964.5 4.1 10000 415.7 483.5 165.032928 10.635195
0 50.000 1000.2 4.0 10000 415.4 483.1 198.076599 11.997488
0 50.000 1038.6 16.2 2000 415.3 483.0 191.590607 18.998974
0 50.000 1080.1 15.2 500 414.7 482.3 185.037201 22.836372
0 50.000 1125.1 15.8 500 414.4 482.0 181.917099 24.641211
0 50.000 1174.0 15.5 500 414.0 481.5 180.374390 25.096113
0 50.000 1227.4 15.7 500 413.6 481.0 178.537384 24.173182
0 50.000 1285.8 15.5 500 413.0 480.3 174.500931 21.820505
0 50.000 1350.1 15.3 1000 412.4 479.6 167.016602 17.229929
0 50.000 1421.1 15.2 2000 411.6 478.7 167.276932 10.099757
0 50.000 1500.0 15.2 2000 410.8 477.7 197.467300 11.875059

0 comments on commit c1ebe1b

Please sign in to comment.