<jupyter_start><jupyter_text>Material```Material(params: Dict, rid: RiiDataFrame)```This class provides the dielectric function for the material specified by given id. If the argument __bound_check__ is True, ValueError is raised when the wavelength exeeds the domain of experimental data.__params__ can includes the following parameters,* 'PEC' (bool): True if you want to create perfect electric conductor. Defaults to False.* 'id' (int): ID number.* 'book' (str): book value in catalog of RiiDataFrame.* 'page' (str): page value in catalog of RiiDataFrame.* 'RI' (complex): Constant refractive index.* 'e' (complex): Constant permittivity.* 'bound_check' (bool): True if bound check should be done. Defaults to True.* 'im_factor' (floot): A magnification factor multiplied to the imaginary part of permittivity. Defaults to 1.0.This class extends the functionality of refractiveindex.info database:* It is possible to define dielectric materials that has constant permittivity.* Imaginary part of dielectric function can be magnified using 'im_factor' parameter.* Perfect Electric Conductor is defined as an artificial metal labeled "PEC", which has negative large permittivity (-1e8).* Material is callable with a single value argument, angular frequency argument ω. The evaluation process is omitted if it is called with the same argument.However, n, k and eps methos of this class are not numpy.ufunc. You can pass them only a single value.<jupyter_code>import riip
rid = riip.RiiDataFrame()
water = riip.Material({'id': 428}, rid)
print(f"{water.catalog['book']} {water.catalog['page']}")
print(f"{water.catalog['wl_min']} <= λ <= {water.catalog['wl_max']}")<jupyter_output>H2O Kedenburg
0.5 <= λ <= 1.6<jupyter_text>Reflactive Index __n__```n(wl: ArrayLike) -> numpy.ndarray``` Extinction Coefficient __k__```k(wl: ArrayLike) -> numpy.ndarray``` Dielectric Function __eps__```eps(wl: ArrayLike) -> numpy.ndarray```Wavelengths __wl__ can be given as a single complex value or an array of complex values.<jupyter_code>wl = 1.0
n = water.n(wl)
k = water.k(wl)
eps = water.eps(wl)
print(f"At λ={wl}μm:")
print(f"  n={n}")
print(f"  k={k}")
print(f"  ε={eps}")
import numpy as np
wls = np.linspace(0.5, 1.6)
water.eps(wls)<jupyter_output><empty_output><jupyter_text>Bound_checkBy default, __bound_check__ is set to __True__, so a ValueError is raised if the given range of wavelength exeeds the domain of experimental data.<jupyter_code>wls = np.linspace(1.0, 2.0)  # exeeds the domain of experimental data [wl_min, wl_max]
water = riip.Material({'id': 428}, rid)
try:
    water.eps(wls)
except ValueError as e:
    print("ValueError: ", e)<jupyter_output>ValueError:  Wavelength [1.0 2.0] is out of bounds [0.5 1.6][um]<jupyter_text>If the instance is created with _bound_check_=False, the dispersion formula is applied beyond the scope of experimental data.<jupyter_code>water = rid.material({'id': 428, 'bound_check': False})
water.eps(wls)<jupyter_output><empty_output><jupyter_text>__plot__```plot(wls: Sequence | np.ndarray, comp: str = "n", fmt1: Optional[str] = "-", fmt2: Optional[str] = "--", **kwargs)```* wls (Sequence | np.ndarray): Wavelength coordinates to be plotted [μm].* comp (str): 'n', 'k' or 'eps'* fmt1 (Optional[str]): Plot format for n and Re(eps).* fmt2 (Optional[str]): Plot format for k and Im(eps).Plot refractive index (if set comp="n"), extinction coefficient (comp="k") or permittivity (comp="eps").<jupyter_code>import matplotlib.pyplot as plt
water.plot(wls, "n")
plt.show()
water.plot(wls, "k")
plt.show()
water.plot(wls, "eps")<jupyter_output><empty_output><jupyter_text>You can change plot style usint rcParams.<jupyter_code>plt.style.use('seaborn-notebook')
plot_params = {
    'figure.figsize': [6.0, 6.0],
    'axes.labelsize': 'xx-large',
    'xtick.labelsize': 'x-large',
    'ytick.labelsize': 'x-large',
    'legend.fontsize': 'x-large',
}
plt.rcParams.update(plot_params)
water.plot(wls, "n")<jupyter_output><empty_output><jupyter_text>Water with constant RI<jupyter_code>import numpy as np
from riip import Material
water_const = Material({'RI': 1.333})
wl = [0.5, 1.0, 1.5]
n = water_const.n(wl)
k = water_const.k(wl)
eps = water_const.eps(wl)
print(f"At λ={wl}μm:")
print(f"  n={n}")
print(f"  k={k}")
print(f"  ε={eps}")<jupyter_output>At λ=[0.5, 1.0, 1.5]μm:
  n=[1.333 1.333 1.333]
  k=[0. 0. 0.]
  ε=[1.776889+0.j 1.776889+0.j 1.776889+0.j]<jupyter_text>A definition of water in RIID<jupyter_code>water = Material({"book": "H2O", "page": "Kedenburg"})
wl = [0.5, 1.0, 1.5]
n = water.n(wl)
k = water.k(wl)
eps = water.eps(wl)
print(f"At λ={wl} μm:")
print(f"  n={n}")
print(f"  k={k}")
print(f"  ε={eps}")<jupyter_output>At λ=[0.5, 1.0, 1.5] μm:
  n=[1.33704353 1.32487335 1.31644826]
  k=[1.89394e-09 3.19106e-06 2.56637e-04]
  ε=[1.78768541+5.06456045e-09j 1.75528941+8.45550074e-06j
 1.73303596+6.75698666e-04j]<jupyter_text>Plot them:<jupyter_code>wls = np.linspace(0.6, 1.0)
water_const.plot(wls)
water.plot(wls)<jupyter_output><empty_output><jupyter_text>Material as a function```Material__call__(w: float | complex) -> complex```* w (float | complex): A float indicating the angular frequencyIt returns the complex relative permittivity at given __angular frequency w__.We use a unit system where the speed of light in vacuum c is 1 and the unit of length is μm.So w is equal to the vacuum wavenumber ω/c [rad/μm]).It is much faster than __eps__ method because the formula is accelerated using cython. In the case of same argument, it's even more faster.<jupyter_code>gold = Material({'book': 'Au', 'page': 'Stewart-DLF'})
wls = [1.0, 1.5]
ws = [2 * np.pi / wl for wl in wls]
%%timeit
for i in range(1000):
    gold.eps(wls[i % 2])
%%timeit
for i in range(1000):
    gold.eps(wls[0])
%%timeit
for i in range(1000):
    gold(ws[i % 2])
%%timeit
for i in range(1000):
    gold(ws[0])<jupyter_output>286 µs ± 15.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)<jupyter_text>However, Material is __not__ a numpy.ufunc<jupyter_code>try:
    gold(np.array(ws))
except ValueError as e:
    print("ValueError: ", e)<jupyter_output>ValueError:  The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()<jupyter_text>im_factor<jupyter_code>gold_low_loss = Material({'book': 'Au', 'page': 'Stewart-DLF', 'im_factor': 0.1})
print("If im_factor=1.0: Im(ε)=", gold(6.28).imag)
print("If im_factor=0.1: Im(ε)=", gold_low_loss(6.28).imag)

print("Real parts are the same")
print(gold(6.28).real, gold_low_loss(6.28).real)<jupyter_output>If im_factor=1.0: Im(ε)= 3.3309657708104403
If im_factor=0.1: Im(ε)= 0.33309657708104407
Real parts are the same
-46.60902219575364 -46.60902219575364<jupyter_text>PEC<jupyter_code>pec = Material({"PEC": True})
print(pec.label, pec(1.0))<jupyter_output>PEC (-100000000+0j)
{'fraction_non_alphanumeric': 0.15090454478599793, 'fraction_numerical': 0.05368436534784527, 'mean_word_length': 5.513409961685824, 'pattern_counts': {'":': 3, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '290349', 'license': 'MIT', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2498, 'n_words': 720, 'path': 'docs/notebooks/03_Material.ipynb', 'repo_name': 'mnishida/refractiveindex.info-Pandas', 'size': '6799'}