tidy3d.plugins.dispersion.DispersionFitter#
- class DispersionFitter[source]#
Bases:
Tidy3dBaseModel
Tool for fitting refractive index data to get a dispersive medium described by
PoleResidue
model.- Parameters:
attrs (dict = {}) – Dictionary storing arbitrary metadata for a Tidy3D object. This dictionary can be freely used by the user for storing data without affecting the operation of Tidy3D as it is not used internally. Note that, unlike regular Tidy3D fields,
attrs
are mutable. For example, the following is allowed for setting anattr
obj.attrs['foo'] = bar
. Also note that Tidy3D` will raise aTypeError
ifattrs
contain objects that can not be serialized. One can check ifattrs
are serializable by callingobj.json()
.wvl_um (ArrayLike[dtype=float, ndim=1]) – [units = um]. Wavelength data in micrometers.
n_data (ArrayLike[dtype=float, ndim=1]) – Real part of the complex index of refraction.
k_data (Optional[ArrayLike[dtype=float, ndim=1]] = None) – Imaginary part of the complex index of refraction.
wvl_range (Tuple[float, float] = (None, None)) – [units = um]. Truncate the wavelength, n and k data to the wavelength range ‘[wvl_min, wvl_max]’ for fitting.
Attributes
Filter the wavelength-nk data to wavelength range for fitting.
Convert filtered input n(k) data into complex permittivity.
Convert filtered input wavelength data to frequency.
Frequency range of filtered input data
Find out if the medium is lossy or lossless based on the filtered input data.
Methods
fit
([num_poles, num_tries, tolerance_rms, guess])Fit data a number of times and returns best results.
from_complex_permittivity
(wvl_um, eps_real)Loads
DispersionFitter
from wavelength and complex relative permittivity datafrom_file
(fname, **loadtxt_kwargs)Loads
DispersionFitter
from file containing wavelength, n, k data.from_loss_tangent
(wvl_um, eps_real, loss_tangent)Loads
DispersionFitter
from wavelength and loss tangent data.from_url
(url_file[, delimiter, ignore_k])loads
DispersionFitter
from url linked to a csv/txt file that contains wavelength (micron), n, and optionally k data.plot
([medium, wvl_um, ax])Make plot of model vs data, at a set of wavelengths (if supplied).
Inherited Common Usage
- wvl_um#
- n_data#
- k_data#
- wvl_range#
- property data_in_range#
Filter the wavelength-nk data to wavelength range for fitting.
- Returns:
Filtered wvl_um, n_data, k_data
- Return type:
Tuple[ArrayFloat1D, ArrayFloat1D, ArrayFloat1D]
- property lossy#
Find out if the medium is lossy or lossless based on the filtered input data.
- Returns:
True for lossy medium; False for lossless medium
- Return type:
bool
- property eps_data#
Convert filtered input n(k) data into complex permittivity.
- Returns:
Complex-valued relative permittivty.
- Return type:
complex
- property freqs#
Convert filtered input wavelength data to frequency.
- Returns:
Frequency array converted from filtered input wavelength data
- Return type:
Tuple[float, …]
- property frequency_range#
Frequency range of filtered input data
- Returns:
The minimal frequency and the maximal frequency
- Return type:
Tuple[float, float]
- fit(num_poles=1, num_tries=50, tolerance_rms=0.01, guess=None)[source]#
Fit data a number of times and returns best results.
- Parameters:
num_poles (int, optional) – Number of poles in the model.
num_tries (int, optional) – Number of optimizations to run with different initial guesses.
tolerance_rms (float, optional) – RMS error below which the fit is successful and the result is returned.
guess (
PoleResidue
= None) – APoleResidue
medium to use as the initial guess in the first optimization run.
- Returns:
Best results of multiple fits: (dispersive medium, RMS error).
- Return type:
Tuple[
PoleResidue
, float]
- plot(medium=None, wvl_um=None, ax=None)[source]#
Make plot of model vs data, at a set of wavelengths (if supplied).
- Parameters:
medium (
PoleResidue
= None) – medium containing model to plot against datawvl_um (ArrayFloat1D = None) – Wavelengths to evaluate model at for plot in micrometers.
ax (matplotlib.axes._subplots.Axes = None) – Axes to plot the data on, if None, a new one is created.
- Returns:
Matplotlib axis corresponding to plot.
- Return type:
matplotlib.axis.Axes
- classmethod from_url(url_file, delimiter=',', ignore_k=False, **kwargs)[source]#
loads
DispersionFitter
from url linked to a csv/txt file that contains wavelength (micron), n, and optionally k data. Preferred from refractiveindex.info.Hint
The data file from url should be in this format (delimiter not displayed here, and note that the strings such as “wl”, “n” need to be included in the file):
For lossless media:
wl n [float] [float] . . . . . .
For lossy media:
wl n [float] [float] . . . . . . wl k [float] [float] . . . . . .
- Parameters:
url_file (str) – Url link to the data file. e.g. “https://refractiveindex.info/data_csv.php?datafile=database/data-nk/main/Ag/Johnson.yml”
delimiter (str = ",") – E.g. in refractiveindex.info, it’ll be “,” for csv file, and “\t” for txt file.
ignore_k (bool = False) – Ignore the k data if they are present, so the fitted material is lossless.
- Returns:
A
DispersionFitter
instance.- Return type:
- classmethod from_file(fname, **loadtxt_kwargs)[source]#
Loads
DispersionFitter
from file containing wavelength, n, k data.- Parameters:
fname (str) – Path to file containing wavelength (um), n, k (optional) data in columns.
**loadtxt_kwargs – Kwargs passed to
np.loadtxt
, such asskiprows
,delimiter
.
Hint
The data file should be in this format (
delimiter
andskiprows
can be customized in**loadtxt_kwargs
):For lossless media:
wl n [float] [float] . . . . . .
For lossy media:
wl n k [float] [float] [float] . . . . . . . . .
- Returns:
A
DispersionFitter
instance.- Return type:
- classmethod from_complex_permittivity(wvl_um, eps_real, eps_imag=None, wvl_range=(None, None))[source]#
Loads
DispersionFitter
from wavelength and complex relative permittivity data- Parameters:
wvl_um (ArrayFloat1D) – Wavelength data in micrometers.
eps_real (ArrayFloat1D) – Real parts of relative permittivity data
eps_imag (Optional[ArrayFloat1D]) – Imaginary parts of relative permittivity data; None for lossless medium.
wvg_range (Tuple[Optional[float], Optional[float]]) – Wavelength range [wvl_min,wvl_max] for fitting.
- Returns:
A
DispersionFitter
instance.- Return type:
- classmethod from_loss_tangent(wvl_um, eps_real, loss_tangent, wvl_range=(None, None))[source]#
Loads
DispersionFitter
from wavelength and loss tangent data.- Parameters:
wvl_um (ArrayFloat1D) – Wavelength data in micrometers.
eps_real (ArrayFloat1D) – Real parts of relative permittivity data
loss_tangent (Optional[ArrayFloat1D]) – Loss tangent data, defined as the ratio of imaginary and real parts of permittivity.
wvl_range (Tuple[Optional[float], Optional[float]]) – Wavelength range [wvl_min,wvl_max] for fitting.
- Returns:
A
DispersionFitter
instance.- Return type:
- __hash__()#
Hash method.