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 or float) – Central wavelength of the Gaussian distribution. If passed as a float, the value is interpreted as being given in nm.

  • fwhm (quantity or float) – 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 by wl_res is used. If passed as an array, the value is interpreted as being given in nm.

  • wl_res (quantity or float, 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.

Parameters:

srf (path-like, Dataset) – Data set to trim.

Returns:

Dataset – Trimmed data set.

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:
  • srf (path-like, Dataset) – Data set to trim.

  • path (path-like) – Path to which to save the filtered dataset.

  • verbose (bool) – If True, display a summary of the trimming operation.

  • show_plot (bool) – If True, display a figure illustrating the filtered region.

  • dry_run (bool) – If True, displays where the trimmed data set would be saved but does not save it.

  • interactive (bool) – If True, prompt the user to proceed to saving the filtered dataset. This is useful in combination with verbose=True and show_plot=True.

See also

trim()

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:

ValueError

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 and wmax.

Parameters:
Returns:

Dataset – Filtered data set.

eradiate.srf_tools.threshold_filter(srf, value=0.001)[source]#

Drop data points where response is smaller or equal than a threshold value.

Parameters:
  • srf (path-like or Dataset) – Spectral response function data set to filter.

  • value (float) – Spectral response threshold value.

Raises:

ValueError

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) – If True, display a filtering summary table and the path to which filtered data set is saved.

  • show_plot (bool) – If True, display a figure emphasizing the filtered region.

  • dry_run (bool) – If True, display the path to which the filtered data set would be saved, but does not write the data set to the disk.

  • interactive (bool) – If True, prompt the user to proceed to saving the filtered dataset. This is useful in combination with verbose=True and show_plot=True.

  • trim_prior (bool) – Trim the data set prior to filtering.

  • threshold (float, optional) – Threshold value for the threshold filter. See threshold_filter(). If None, disable the threshold filter.

  • wmin (quantity, optional) – Lower wavelength bound for the spectral filter. See spectral_filter(). If both wmin and wmax are None, disable the spectral filter.

  • wmax (quantity, optional) – Upper wavelength bound for the spectral filter. See spectral_filter(). If both wmin and wmax are None, disable the spectral filter.

  • percentage (float, optional) – Percentage value for the integral filter. See integral_filter(). If None, 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

eradiate.srf_tools.pad_zeros(ds)[source]#

Pad an SRF dataset with zero values to the left and right.

Parameters:

ds (Dataset) – SRF dataset

Returns:

Dataset

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) – If True, 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.

Parameters:

srf (path-like, Dataset) – Spectral response function data set.

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.

Parameters:

srf (path-like, Dataset) – Spectral response function data set.

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.

Parameters:

srf (path-like, Dataset) – Spectral response function data set.

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.

eradiate.srf_tools.summarize(srf, filtered)[source]#

Produce a summary table of the spectral response function filtering operation.

Parameters:
  • srf (Dataset) – Initial spectral response function data set.

  • filtered (Dataset) – Filtered spectral response function data set.

Returns:

Table – Summary table.