eradiate.srf_tools
#
Spectral response function (SRF) filtering algorithms.
Generators#
- eradiate.srf_tools.make_gaussian(wl_center, fwhm, cutoff=3.0, wl=None, wl_res=1.0, pad=False)[source]#
Generate a Gaussian spectral response function dataset from central wavelength and full width at half maximum values.
- Parameters:
wl_center (
quantity
orfloat
) – Central wavelength of the Gaussian distribution. If passed as a float, the value is interpreted as being given in nm.fwhm (
quantity
orfloat
) – Full width at half maximum of the Gaussian distribution. If passed as a float, the value is interpreted as being given in nm.cutoff (
float
, default:3.0
) – Cut-off, in multiples of the standard deviation σ.wl (
quantity
or array-like, optional) – Mesh used to evaluate the discretized distribution. If unset, a regular mesh with spacing given bywl_res
is used. If passed as an array, the value is interpreted as being given in nm.wl_res (
quantity
orfloat
, optional) – Resolution of the automatic spectral mesh if relevant. If passed as an array, the value is interpreted as being given in nm.pad (
bool
, default:False
) – If True, pad SRF data with leading and trailing zeros.
- Returns:
Dataset
– A dataset compliant with the Eradiate SRF format. The uncertainty variable is set to NaN.
Trimming algorithms#
- eradiate.srf_tools.trim(srf)[source]#
Trim all leading zeros except last and all trailing zeros except first.
- eradiate.srf_tools.trim_and_save(srf, path, verbose=False, show_plot=False, dry_run=False, interactive=False)[source]#
Wraps around
trim()
to save the filtered dataset.- Parameters:
path (path-like) – Path to which to save the filtered dataset.
verbose (
bool
) – IfTrue
, display a summary of the trimming operation.show_plot (
bool
) – IfTrue
, display a figure illustrating the filtered region.dry_run (
bool
) – IfTrue
, displays where the trimmed data set would be saved but does not save it.interactive (
bool
) – IfTrue
, prompt the user to proceed to saving the filtered dataset. This is useful in combination withverbose=True
andshow_plot=True
.
See also
Filtering algorithms#
- eradiate.srf_tools.integral_filter(srf, percentage=99.0, method='symmetry')[source]#
Keep only data that contribute to the integrated spectral response value to the amount of the specified percentage.
- Parameters:
srf (path-like or
Dataset
) – Spectral response function data set to filter.percentage (
float
) – Keep data that contribute to this percentage of the integrated spectral response.method (
"symmetry"
or"walk"
) – Trimming bound definition method. The"symmetry"
method ensures that the bounds are positioned symmetrically with respect to the mean wavelength of the SRF. The"walk"
method uses the cumulative integral of the SRF to position bounds eagerly while walking the spectral dimension.
- Raises:
- Returns:
Dataset
– Filtered data set.
- eradiate.srf_tools.spectral_filter(srf, wmin=None, wmax=None)[source]#
Drop points falling out of wavelength range specified by
wmin
andwmax
.
- eradiate.srf_tools.threshold_filter(srf, value=0.001)[source]#
Drop data points where response is smaller or equal than a threshold value.
- Parameters:
- Raises:
- Returns:
Dataset
– Filtered data set.
- eradiate.srf_tools.filter_srf(srf, path, verbose=False, show_plot=False, dry_run=False, interactive=False, trim_prior=True, threshold=None, wmin=None, wmax=None, percentage=None, pad=False)[source]#
Filter a spectral response function data set.
- Parameters:
srf (path-like,
Dataset
) – Spectral response function data set to filter.path (path-like) – Path to which to save the filtered data set.
verbose (
bool
) – IfTrue
, display a filtering summary table and the path to which filtered data set is saved.show_plot (
bool
) – IfTrue
, display a figure emphasizing the filtered region.dry_run (
bool
) – IfTrue
, display the path to which the filtered data set would be saved, but does not write the data set to the disk.interactive (
bool
) – IfTrue
, prompt the user to proceed to saving the filtered dataset. This is useful in combination withverbose=True
andshow_plot=True
.trim_prior (
bool
) – Trim the data set prior to filtering.threshold (
float
, optional) – Threshold value for the threshold filter. Seethreshold_filter()
. IfNone
, disable the threshold filter.wmin (
quantity
, optional) – Lower wavelength bound for the spectral filter. Seespectral_filter()
. If bothwmin
andwmax
areNone
, disable the spectral filter.wmax (
quantity
, optional) – Upper wavelength bound for the spectral filter. Seespectral_filter()
. If bothwmin
andwmax
areNone
, disable the spectral filter.percentage (
float
, optional) – Percentage value for the integral filter. Seeintegral_filter()
. IfNone
, disable the integral filter.pad (
bool
, default:False
) – If True, pad SRF data with leading and trailing zeros.
Notes
Select the filtering algorithms corresponding to the specified parameters.
If multiple filters are selected, they are applied in this order:
integral filter
spectral filter
threshold filter
See also
Plotting#
- eradiate.srf_tools.show(ds, trim_prior=True, title=None, threshold=None, wmin=None, wmax=None, percentage=None)[source]#
Show filtered region on spectral response function plot.
- Parameters:
ds (path-like,
Dataset
) – Spectral response function to be filtered.trim_prior (
bool
) – IfTrue
, trim spectral response function prior to filter.title (
str
, optional) – Figure title.threshold (
float
, optional) – Threshold value for the threshold filter.wmin (
quantity
, optional) – Lower wavelength value for the spectral filter.wmax (
quantity
, optional) – Upper wavelength value for the spectral filter.percentage (
float
, optional) – Percentage value for the integral filter (will use the ‘symmetry’ method).
- Raises:
ValueError: – If the threshold value is not in [0, 1[.
Utilities#
- eradiate.srf_tools.wavelength_range_width(srf)[source]#
Compute the wavelength range width of a spectral response function.
Notes
The wavelength range width is defined as the difference between the upper and lower wavelength bounds.
- eradiate.srf_tools.wavelength_bandwidth(srf)[source]#
Compute the wavelength bandwidth of a spectral response function.
Notes
The wavelength bandwidth is defined according to the following formula:
\[\Delta \lambda = \int \lambda \, \phi(\lambda) \mathrm{d} \lambda\]- where
\(\phi(\lambda)\) is the spectral response function.
\(\lambda\) is the wavelength.
\(\Delta \lambda\) is the wavelength bandwidth.
and the integral is performed over the wavelength range of the spectral response function.
- eradiate.srf_tools.mean_wavelength(srf)[source]#
Compute the mean wavelength of a spectral response function.
Notes
The mean wavelength is defined according to the following formula:
\[\overline{\lambda} = \frac{ \int \lambda \, \phi(\lambda) \, \mathrm{d} \lambda }{ \int \phi(\lambda) \, \mathrm{d} \lambda }\]- where
\(\phi(\lambda)\) is the spectral response function.
\(\lambda\) is the wavelength.
\(\overline{\lambda}\) is the mean wavelength.
and the integrals are performed over the wavelength range of the spectral response function.