tidy3d.FreqRange#
- class FreqRange[source]#
Bases:
Tidy3dBaseModelConvenience class for handling frequency/wavelength conversion; it simplifies specification of frequency ranges and sample points for sources and monitors.
- Parameters:
freq0 (PositiveFloat) – [units = Hz]. Real-valued positive central frequency.
fwidth (PositiveFloat) – [units = Hz]. Real-valued positive width of the frequency range (bandwidth).
Notes
Depending on the context the user can define desired frequency range by specifying: - central frequency
freq0and frequency bandwidthfwidth; - frequency interval [fmin,``fmax``]; - central wavelengthwvl0and wavelength rangewvl_width; - wavelength interval [wvl_min,wvl_max].Example
>>> import tidy3d as td >>> freq0 = 1e12 >>> fwidth = 1e11 >>> freq_range = td.FreqRange(freq0=freq0, fwidth=fwidth) >>> central_freq = freq_range.freqs(num_points=1, spacing="uniform_freq") >>> freqs = freq_range.freqs(num_points=11, spacing="uniform_wvl") >>> source = freq_range.to_gaussian_pulse()
Attributes
Infer highest frequency
fmaxfrom central frequencyfreq0and bandwidthfwidth.Infer lowest frequency
fminfrom central frequencyfreq0and bandwidthfwidth.Get central wavelength from central frequency and bandwidth.
Methods
freqs(num_points[, spacing])method
freqs()returns a numpy array ofnum_pointfrequencies uniformly sampled from the specified frequency range; ifnum_points == 1method returns the central frequencyfreq0.from_freq_interval(fmin, fmax)method
from_freq_interval()creates instance of classFreqRangefrom frequency interval defined by argumentsfminandfmax.from_wvl(wvl0, wvl_width)method
from_wvl()updated instance of classFreqRangeby reassigning new frequency- and wavelength-related parameters.from_wvl_interval(wvl_min, wvl_max)method
from_wvl_interval()updated instance of classFreqRangeby reassigning new frequency- and wavelength-related parameters.sweep_decade(num_points_per_decade)Generate frequencies with logarithmic spacing across decades.
to_gaussian_pulse(**kwargs)to_gaussian_pulse(): Return a
GaussianPulseinstance based on this frequency range.wvls(num_points[, spacing])method
wvls()returns a numpy array ofnum_pointswavelengths uniformly sampled from the range of wavelengths; ifnum_points == 1the method returns central wavelengthwvl0.Inherited Common Usage
- freq0#
- fwidth#
- property fmin#
Infer lowest frequency
fminfrom central frequencyfreq0and bandwidthfwidth.
- property fmax#
Infer highest frequency
fmaxfrom central frequencyfreq0and bandwidthfwidth.
- property wvl0#
Get central wavelength from central frequency and bandwidth.
- classmethod from_freq_interval(fmin, fmax)[source]#
method
from_freq_interval()creates instance of classFreqRangefrom frequency interval defined by argumentsfminandfmax.NB: central frequency never corresponds to central wavelength!
freq0 = (fmin + fmax) / 2implies thatwvl0 != (wvl_min + wvl_max) / 2and vise-versa.
- classmethod from_wvl(wvl0, wvl_width)[source]#
method
from_wvl()updated instance of classFreqRangeby reassigning new frequency- and wavelength-related parameters.NB: central frequency never corresponds to central wavelength!
wvl0 = (wvl_min + wvl_max) / 2implies thatfreq0 != (fmin + fmax) / 2and vise versa.
- classmethod from_wvl_interval(wvl_min, wvl_max)[source]#
method
from_wvl_interval()updated instance of classFreqRangeby reassigning new frequency- and wavelength-related parameters.NB: central frequency never corresponds to central wavelength!
wvl0 = (wvl_min + wvl_max) / 2implies thatfreq0 != (fmin + fmax) / 2.
- freqs(num_points, spacing='uniform_freq')[source]#
method
freqs()returns a numpy array ofnum_pointfrequencies uniformly sampled from the specified frequency range; ifnum_points == 1method returns the central frequencyfreq0.- Parameters:
num_points (int) – Number of frequency points in a frequency range of interest.
spacing (str = "uniform_freq") – Mode of frequency sampling. If spacing is set to
uniform_freq, frequencies are sampled uniformly over the frequency interval. If set touniform_wvl, frequencies correspond to uniformly sampled wavelengths over the wavelength interval. Frequencies are sorted in ascending order.
- Returns:
a numpy array of uniformly distributed frequency samples in a frequency range of interest.
- Return type:
np.ndarray
- sweep_decade(num_points_per_decade)[source]#
Generate frequencies with logarithmic spacing across decades.
Notes
This method creates a logarithmically spaced frequency sweep. It is analogous to the SPICE AC analysis command for a decade sweep:
.ac dec <num_points_per_decade> <fmin> <fmax>- Parameters:
num_points_per_decade (int) – Number of frequency points per decade. Must be strictly positive.
- Returns:
Array of frequencies with logarithmic spacing across decades.
- Return type:
NDArray[np.float64]
- Raises:
ValueError – If
num_points_per_decadeis not positive, or if frequency range is invalid.
Examples
>>> import tidy3d as td >>> freq_range = td.FreqRange.from_freq_interval(1e3, 1e6) # 1 kHz to 1 MHz >>> freqs = freq_range.sweep_decade(10) # 10 points per decade
- wvls(num_points, spacing='uniform_wvl')[source]#
method
wvls()returns a numpy array ofnum_pointswavelengths uniformly sampled from the range of wavelengths; ifnum_points == 1the method returns central wavelengthwvl0.- Parameters:
num_points (int) – Number of wavelength points in a range of wavelengths of interest.
spacing (str = "uniform_wvl") – Mode of wavelength sampling. If spacing is set to
uniform_wvl, wavelengths are sampled uniformly over the wavelength interval. If set touniform_freq, wavelengths correspond to uniformly sampled frequencies over the frequency interval. Wavelengths are sorted in ascending order.
- Returns:
a numpy array of uniformly distributed wavelength samples in ascending order.
- Return type:
np.ndarray
- to_gaussian_pulse(**kwargs)[source]#
to_gaussian_pulse(): Return a
GaussianPulseinstance based on this frequency range.This method constructs a
GaussianPulseusingGaussianPulse.from_frequency_range(fmin=self.fmin, fmax=self.fmax, **kwargs).If you prefer to define the pulse using
freq0andfwidthdirectly, you should manually instantiate theGaussianPulseinstead.- Parameters:
kwargs (dict) – Keyword arguments passed to
GaussianPulse(), excludingfreq0&fwidth.- Returns:
A
GaussianPulsethat maximizes its amplitude in the frequency range [fmin,fmax].- Return type: