Skip to content

04 — Spectral response functions ​

Spectral response functions (SRFs) are available for some instruments. Use has_srf to check their catalogue metadata without downloading anything. When no SRF exists, srf() returns None.

python
import xeo

with_srf = [
    instrument.id
    for instrument in xeo.instruments.values()
    if instrument.has_srf
]
print(f"{len(with_srf)} instruments have an SRF")
print(with_srf)

Handle unavailable SRFs ​

python
emit = xeo.instruments.EMIT
print("EMIT has an SRF:", emit.has_srf)
print("EMIT SRF result:", emit.srf())

Load an available SRF ​

The result contains a wavelength column followed by one response column per spectral band. On first use, srf() downloads the external CSV into a per-user cache organized by catalogue version. Later calls reuse the local file and work offline. Use msi.srf(refresh=True) to replace the cached copy with the current remote resource, or set XEO_CACHE_DIR to choose another writable cache root.

python
msi = xeo.instruments.MSI_S2A
srf = msi.srf()

print("Shape:", srf.shape)
print("Columns:", list(srf.columns))
srf.head()

Analyse selected response curves ​

Using wavelength as the index makes common pandas operations straightforward. Here, idxmax() estimates the wavelength of maximum response for selected bands.

python
curves = srf.set_index("wavelength")[["B2", "B3", "B4", "B8"]]
peak_wavelengths = curves.idxmax().rename("peak_wavelength_nm")
peak_wavelengths

Find the nearest sampled wavelength ​

python
target_wavelength = 665
nearest_position = (srf["wavelength"] - target_wavelength).abs().argmin()
srf.iloc[nearest_position][["wavelength", "B2", "B3", "B4", "B8"]]

Released under the MIT License.