eradiate.srf_tools#

Spectral response function (SRF) filtering algorithms.

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)[source]#

Keep only data that contribute to the integrated spectral response value to the amount of the specified percentage.

The integrated spectral reponse is computed from the cumulative sum of the spectral response function interpolated on a regular grid with the smallest wavelength step of the initial data set.

Parameters:
  • ds (path-like or Dataset) – Dataset to filter.

  • percentage (float) – Keep data that contribute to this percentage of the integrated spectral response.

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)[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.

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

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.

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.