smooth#

iris.sg.background.smooth(obs, axis_wavelength, axis_detector_y)[source]#

Smooth the given observation using named_arrays.ndfilters.trimmed_mean_filter().

Parameters:
  • obs (SpectrographObservation) – The observation to be smoothed.

  • axis_wavelength (str) – The logical axis corresponding to increasing wavelength.

  • axis_detector_y (str) – The logical axis corresponding to increasing position along the slit.

Return type:

SpectrographObservation

Examples

Compute a smoothed version of an average spectrograph observation.

import matplotlib.pyplot as plt
import astropy.units as u
import astropy.visualization
import named_arrays as na
import iris

# Load a spectrograph observation
obs = iris.sg.SpectrographObservation.from_time_range(
    time_start=astropy.time.Time("2021-09-23T06:00"),
    time_stop=astropy.time.Time("2021-09-23T07:00"),
)

# Save the time and raster axes
axis = (obs.axis_time, obs.axis_detector_x)

# Compute the average along the time and raster axes
avg = iris.sg.background.average(
    obs=obs,
    axis=axis,
)

# Subtract the spectral line from the average
bg = iris.sg.background.smooth(
    obs=avg,
    axis_wavelength=obs.axis_wavelength,
    axis_detector_y=obs.axis_detector_y,
)

# Plot the result
with astropy.visualization.quantity_support():
    fig, ax = plt.subplots()
    img = na.plt.pcolormesh(
        bg.inputs.wavelength,
        bg.inputs.position.y,
        C=bg.outputs.value,
    )
    ax.set_xlabel(f"wavelength ({ax.get_xlabel()})")
    ax.set_ylabel(f"helioprojective $y$ ({ax.get_ylabel()})")
    fig.colorbar(
        mappable=img.ndarray.item(),
        ax=ax,
        label=f"average spectral radiance ({obs.outputs.unit})",
    )
../_images/iris.sg.background.smooth_0_1.png