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 (Attribute: wvl_um) –

    Type

    ArrayLike[dtype=float, ndim=1]

    Default

    Units

    um

    Description

    Wavelength data in micrometers.

  • n_data (Attribute: n_data) –

    Type

    ArrayLike[dtype=float, ndim=1]

    Default

    Description

    Real part of the complex index of refraction.

  • k_data (Attribute: k_data) –

    Type

    Optional[ArrayLike[dtype=float, ndim=1]]

    Default

    = None

    Description

    Imaginary part of the complex index of refraction.

  • wvl_range (Attribute: wvl_range) –

    Type

    Tuple[float, float]

    Default

    = (None, None)

    Units

    um

    Description

    Truncate the wavelength, n and k data to the wavelength range ‘[wvl_min, wvl_max]’ for fitting.

Attributes

data_in_range

Filter the wavelength-nk data to wavelength range for fitting.

eps_data

Convert filtered input n(k) data into complex permittivity.

freqs

Convert filtered input wavelength data to frequency.

frequency_range

Frequency range of filtered input data

lossy

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) – A PoleResidue 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 data

  • wvl_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:
Returns:

A DispersionFitter instance.

Return type:

DispersionFitter

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 as skiprows, delimiter.

Hint

The data file should be in this format (delimiter and skiprows 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:

DispersionFitter

__hash__()#

Hash method.