tidy3d.plugins.DispersionFitter#

class tidy3d.plugins.DispersionFitter#

Tool for fitting refractive index data to get a dispersive Medium.

Show JSON schema
{
   "title": "DispersionFitter",
   "description": "Tool for fitting refractive index data to get a dispersive ``Medium``.",
   "type": "object",
   "properties": {
      "wvl_um": {
         "title": "Wavelength data",
         "description": "Wavelength data in micrometers.",
         "unit": "um",
         "anyOf": [
            {
               "title": "NumpyArray",
               "description": "Wrapper around numpy arrays that has a well defined json schema.",
               "type": "object",
               "properties": {
                  "data_list": {
                     "title": "Data List",
                     "type": "array",
                     "items": {}
                  }
               },
               "required": [
                  "data_list"
               ]
            },
            {
               "$ref": "#/definitions/NumpyArray"
            },
            {
               "type": "array",
               "items": {}
            }
         ]
      },
      "n_data": {
         "title": "Index of refraction data",
         "description": "Real part of the complex index of refraction.",
         "anyOf": [
            {
               "title": "NumpyArray",
               "description": "Wrapper around numpy arrays that has a well defined json schema.",
               "type": "object",
               "properties": {
                  "data_list": {
                     "title": "Data List",
                     "type": "array",
                     "items": {}
                  }
               },
               "required": [
                  "data_list"
               ]
            },
            {
               "$ref": "#/definitions/NumpyArray"
            },
            {
               "type": "array",
               "items": {}
            }
         ]
      },
      "k_data": {
         "title": "Extinction coefficient data",
         "description": "Imaginary part of the complex index of refraction.",
         "anyOf": [
            {
               "title": "NumpyArray",
               "description": "Wrapper around numpy arrays that has a well defined json schema.",
               "type": "object",
               "properties": {
                  "data_list": {
                     "title": "Data List",
                     "type": "array",
                     "items": {}
                  }
               },
               "required": [
                  "data_list"
               ]
            },
            {
               "$ref": "#/definitions/NumpyArray"
            },
            {
               "type": "array",
               "items": {}
            }
         ]
      },
      "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
         ],
         "unit": "um",
         "type": "array",
         "minItems": 2,
         "maxItems": 2,
         "items": [
            {
               "type": "number"
            },
            {
               "type": "number"
            }
         ]
      }
   },
   "required": [
      "wvl_um",
      "n_data"
   ],
   "definitions": {
      "NumpyArray": {
         "title": "NumpyArray",
         "description": "Wrapper around numpy arrays that has a well defined json schema.",
         "type": "object",
         "properties": {
            "data_list": {
               "title": "Data List",
               "type": "array",
               "items": {}
            }
         },
         "required": [
            "data_list"
         ]
      }
   }
}

Fields
  • k_data (Union[tidy3d.components.types.tidynumpy, tidy3d.components.types.NumpyArray, List])

  • n_data (Union[tidy3d.components.types.tidynumpy, tidy3d.components.types.NumpyArray, List])

  • wvl_range (Tuple[float, float])

  • wvl_um (Union[tidy3d.components.types.tidynumpy, tidy3d.components.types.NumpyArray, List])

attribute k_data: Union[tidy3d.components.types.tidynumpy, tidy3d.components.types.NumpyArray, List] = None#

Imaginary part of the complex index of refraction.

Validated by
  • _kdata_setup_and_length_match

attribute n_data: Union[tidy3d.components.types.tidynumpy, tidy3d.components.types.NumpyArray, List] [Required]#

Real part of the complex index of refraction.

Validated by
  • _ndata_length_match_wvl

attribute wvl_range: Tuple[float, float] = [None, None]#

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

attribute wvl_um: Union[tidy3d.components.types.tidynumpy, tidy3d.components.types.NumpyArray, List] [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[:class:PoleResidue, float]

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

Loads :class`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.

Returns

A :class`DispersionFitter` instance.

Return type

class`DispersionFitter`

classmethod from_url(url_file: str, delimiter: str = ',', **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 :class`DispersionFitter` instance.

Return type

class`DispersionFitter`

plot(medium: tidy3d.components.medium.PoleResidue = None, wvl_um: numpy.ndarray = 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 (Numpy = None) – Wavelengths to evaluate model at for plot in micrometers.

  • ax (Ax = 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: tidy3d.components.types.NumpyArray#

Convert filtered input wavelength data to frequency.

Returns

Frequency array converted from filtered input wavelength data

Return type

NumpyArray

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