Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## Version 0.22.4

### Bugfixes

- Fix for an error when copying of an IndexDispersion created from a Dispersion
- Fix for reading of woollam data if no dpolE is present

## Version 0.22.3

### Bugfixes
Expand Down
37 changes: 17 additions & 20 deletions src/elli/dispersions/base_dispersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Abstract base class and utility classes for pyElli dispersion"""

from abc import ABC, abstractmethod
from copy import deepcopy
from typing import List, Optional, Union

import numpy as np
Expand Down Expand Up @@ -239,15 +238,25 @@ def as_index(self):
Please ensure that you know what you are doing as building dielectric
and index based dispersions is normally mathematically wrong.
"""
index_class = deepcopy(self)
# pylint: disable=attribute-defined-outside-init
index_class.refractive_index = lambda lbda: sqrt(
index_class.dielectric_function(lbda)

AnonymousIndexDispersion = type(
"AnonymousIndexDispersion",
(IndexDispersion,),
{
"rep_params_template": self.rep_params_template,
"single_params_template": self.single_params_template,
"dielectric_function": self.dielectric_function,
"refractive_index": lambda self, lbda: sqrt(
self.dielectric_function(lbda)
),
},
)
index_class.__class__ = IndexDispersion # pylint: disable=invalid-name
index_class.dielectric_function = self.dielectric_function

return index_class
idx_dispersion = AnonymousIndexDispersion()
idx_dispersion.rep_params = self.rep_params
idx_dispersion.single_params = self.single_params

return idx_dispersion


class IndexDispersion(BaseDispersion):
Expand Down Expand Up @@ -301,18 +310,6 @@ def __add__(
def dielectric_function(self, lbda: npt.ArrayLike) -> npt.NDArray:
return self.refractive_index(lbda) ** 2

def as_dielectric(self):
"""
Returns this class as Dispersion.
This method may be used to add dielectric and index based dispersions.
Please ensure that you know what you are doing as building dielectric
and index based dispersions is normally mathematically wrong.
"""
diel_disp = deepcopy(self)
diel_disp.__class__ = Dispersion # pylint: disable=invalid-name
diel_disp.dielectric_function = self.dielectric_function
return diel_disp


class DispersionFactory:
"""A factory class for dispersion objects"""
Expand Down
12 changes: 8 additions & 4 deletions src/elli/importer/woollam.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import logging
import re
from typing import TextIO
from typing import TextIO, Union

import pandas as pd
from pint import DimensionalityError, UndefinedUnitError
Expand All @@ -20,7 +20,7 @@
is_float_regex = re.compile(r"[+-]?(\d+([.]\d*)?([eE][+-]?\d+)?|[.]\d+([eE][+-]?\d+)?)")


def is_float(line: str) -> bool:
def is_float(line: Union[float, int, str]) -> bool:
"""Checks whether the given line is a float

Args:
Expand All @@ -29,7 +29,11 @@ def is_float(line: str) -> bool:
Returns:
bool: True if it is a float, False otherwise
"""
return bool(is_float_regex.search(line))
if isinstance(line, (float, int)):
return True
if isinstance(line, str):
return bool(is_float_regex.search(line))
return False


def _is_wvase_tabular(line: str) -> bool:
Expand Down Expand Up @@ -126,7 +130,7 @@ def _read_wvase_dataframe(file_object: TextIO) -> pd.DataFrame:
header=None,
names=["Wavelength", "Angle of Incidence", "Ψ", "Δ", "Ψ_err", "Δ_err"],
)
print(dframe)

dframe = (
dframe[dframe.apply(lambda x: is_float(x.iloc[0]), axis=1)]
.set_index(["Wavelength", "Angle of Incidence"])
Expand Down
37 changes: 37 additions & 0 deletions tests/test_dispersions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for dispersion models"""

import os
from copy import deepcopy
from shutil import copytree, rmtree

import numpy as np
Expand All @@ -11,6 +12,7 @@

import elli
from elli.dispersions.base_dispersion import InvalidParameters
from elli.dispersions.sellmeier import Sellmeier


@fixture
Expand Down Expand Up @@ -233,3 +235,38 @@ def test_correct_reconstruction_with_pseudo_dielectric():
).get_dielectric_df(check_lbda),
gaussian.get_dielectric_df(check_lbda),
)


def test_deepcopy_of_index_dispersion():
sell = Sellmeier()
sell.add(1, 1)

deepcopy(sell.as_index())


def test_index_dispersion_conversion():
sell = Sellmeier()
sell.add(1, 1)

lbda = np.linspace(300, 900, 100)

assert_array_equal(
sell.as_index().get_dielectric(lbda),
sell.get_dielectric(lbda),
)

assert_array_equal(
sell.as_index().add(2, 2).get_dielectric(lbda), sell.get_dielectric(lbda)
)


def test_dispersion_conversion_to_other_type():
lbda = np.linspace(300, 900, 100)
RII = elli.db.RII()

disp = RII.get_dispersion("AgCl", "Tilton")

assert_array_equal(
disp.as_index().get_dielectric(lbda),
disp.get_dielectric(lbda),
)
5 changes: 5 additions & 0 deletions tests/test_wollam.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

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 Spectraray file is read w/o errors"""
data_wvase = elli.read_woollam_psi_delta(datadir / "wvase_example.dat")
data_wvase_wo_dpolE = elli.read_woollam_psi_delta(
datadir / "wvase_example_wo_dpolE.dat"
)
data_cease = elli.read_woollam_psi_delta(datadir / "complete_ease_example.dat")

assert data_wvase.shape == (542, 2)
assert data_wvase_wo_dpolE.shape == (542, 2)
assert data_cease.shape == (3263, 2)


Expand Down
Loading