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:
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_file
(fname, **loadtxt_kwargs)Loads
DispersionFitter
from file containing wavelength, n, k 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).
- 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=data/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:
- __hash__()#
Hash method.