tidy3d.plugins.DispersionFitter#

class tidy3d.plugins.DispersionFitter#

Tool for fitting refractive index data to get a dispersive medium described by PoleResidue model.

Parameters
  • wvl_um (Union[Tuple[float, ...], Array]) – [units = um]. Wavelength data in micrometers.

  • n_data (Union[Tuple[float, ...], Array]) – Real part of the complex index of refraction.

  • k_data (Union[Tuple[float, ...], Array] = None) – Imaginary part of the complex index of refraction.

  • wvl_range (Tuple[float, float] = (None, None)) – [units = um]. Truncate the wavelength-nk data to wavelength range [wvl_min,wvl_max] for fitting

Show JSON schema
{
   "title": "DispersionFitter",
   "description": "Tool for fitting refractive index data to get a\ndispersive medium described by :class:`.PoleResidue` model.\n\nParameters\n----------\nwvl_um : Union[Tuple[float, ...], Array]\n    [units = um].  Wavelength data in micrometers.\nn_data : Union[Tuple[float, ...], Array]\n    Real part of the complex index of refraction.\nk_data : Union[Tuple[float, ...], Array] = None\n    Imaginary part of the complex index of refraction.\nwvl_range : Tuple[float, float] = (None, None)\n    [units = um].  Truncate the wavelength-nk data to wavelength range [wvl_min,wvl_max] for fitting",
   "type": "object",
   "properties": {
      "wvl_um": {
         "title": "Wavelength data",
         "description": "Wavelength data in micrometers.",
         "units": "um",
         "anyOf": [
            {
               "type": "array",
               "items": {
                  "type": "number"
               }
            },
            {
               "title": "Array Like",
               "description": "Accepts sequence (tuple, list, numpy array) and converts to tuple.",
               "type": "tuple",
               "properties": {},
               "required": []
            }
         ]
      },
      "n_data": {
         "title": "Index of refraction data",
         "description": "Real part of the complex index of refraction.",
         "anyOf": [
            {
               "type": "array",
               "items": {
                  "type": "number"
               }
            },
            {
               "title": "Array Like",
               "description": "Accepts sequence (tuple, list, numpy array) and converts to tuple.",
               "type": "tuple",
               "properties": {},
               "required": []
            }
         ]
      },
      "k_data": {
         "title": "Extinction coefficient data",
         "description": "Imaginary part of the complex index of refraction.",
         "anyOf": [
            {
               "type": "array",
               "items": {
                  "type": "number"
               }
            },
            {
               "title": "Array Like",
               "description": "Accepts sequence (tuple, list, numpy array) and converts to tuple.",
               "type": "tuple",
               "properties": {},
               "required": []
            }
         ]
      },
      "wvl_range": {
         "title": "Wavelength range [wvl_min,wvl_max] for fitting",
         "description": "Truncate the wavelength-nk data to wavelength range [wvl_min,wvl_max] for fitting",
         "default": [
            null,
            null
         ],
         "units": "um",
         "type": "array",
         "minItems": 2,
         "maxItems": 2,
         "items": [
            {
               "type": "number"
            },
            {
               "type": "number"
            }
         ]
      },
      "type": {
         "title": "Type",
         "default": "DispersionFitter",
         "enum": [
            "DispersionFitter"
         ],
         "type": "string"
      }
   },
   "required": [
      "wvl_um",
      "n_data"
   ],
   "additionalProperties": false
}

attribute k_data: Union[Tuple[float, ...], tidy3d.components.types.Array] = None#

Imaginary part of the complex index of refraction.

Validated by
  • _kdata_setup_and_length_match

attribute n_data: Union[Tuple[float, ...], tidy3d.components.types.Array] [Required]#

Real part of the complex index of refraction.

Validated by
  • _ndata_length_match_wvl

attribute wvl_range: Tuple[Optional[float], Optional[float]] = (None, None)#

Truncate the wavelength-nk data to wavelength range [wvl_min,wvl_max] for fitting

attribute wvl_um: Union[Tuple[float, ...], tidy3d.components.types.Array] [Required]#

Wavelength data in micrometers.

Validated by
  • _setup_wvl

fit(num_poles: int = 1, num_tries: int = 50, tolerance_rms: float = 0.01) Tuple[tidy3d.components.medium.PoleResidue, float]#

Fits 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 random initial guess.

  • tolerance_rms (float, optional) – RMS error below which the fit is successful and the result is returned.

Returns

Best results of multiple fits: (dispersive medium, RMS error).

Return type

Tuple[PoleResidue, float]

classmethod from_file(fname: str, **loadtxt_kwargs)#

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

classmethod from_url(url_file: str, delimiter: str = ',', ignore_k: bool = False, **kwargs)#

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

plot(medium: tidy3d.components.medium.PoleResidue = None, wvl_um: Tuple[float, ...] = None, ax: matplotlib.axes._axes.Axes = None) matplotlib.axes._axes.Axes#

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 (Tuple[float, ...] = 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

property eps_data: complex#

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

Returns

Complex-valued relative permittivty.

Return type

complex

property freqs: Tuple[float, ...]#

Convert filtered input wavelength data to frequency.

Returns

Frequency array converted from filtered input wavelength data

Return type

Tuple[float, …]

property frequency_range: Tuple[float, float]#

Frequency range of filtered input data

Returns

The minimal frequency and the maximal frequency

Return type

Tuple[float, float]

property lossy: bool#

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