Get and compare solar spectra

TSIS full, finer TSIS, and ASTM with skyloc

Load bundled solar spectra and compare TSIS and ASTM references.

Use sloc.get_solspect() to load the solar reference. Pass wavelength nodes to interpolate.

1. Load a spectrum

import pandas as pd
from astropy import units as u
from matplotlib import pyplot as plt

import skyloc as sloc

solar = sloc.get_solspect()
solar[:5]
QTable length=5
wlflamdflamfnuABmag
umW / (um m2)W / (um m2)MJymag
float64float64float64float64float64
0.11550.0177049580038985340.002620654640850261478.78402531777749-10.84102979391448
0.11650.0233276309814095980.0028674778604909075105.60920768308202-11.159188838733705
0.117500000000000010.077021000008748590.005257693374005611354.702445973736-12.474594835994
0.118500000000000010.0310873547426794780.003070978209507302145.61287166716878-11.507933794675163
0.119500000000000010.049985862266649180.00394866492570145238.1015901451787-12.041840117269139

With no wavelength arguments, the getter returns:

  • the native samples,
  • all available source columns,
  • two derived columns (fnu, ABmag).

The default "tsis_full" result contains:

Column Meaning Unit
wl Wavelength µm
flam Spectral irradiance per wavelength W m⁻² µm⁻¹
dflam Published absolute irradiance uncertainty W m⁻² µm⁻¹
fnu Spectral irradiance per frequency MJy
ABmag Monochromatic AB magnitude, using a 3631 Jy zero point mag
  • ABmag is monochromatic. It is not a magnitude integrated through an instrument filter.
  • Zero irradiance gives zero fnu and infinite ABmag.

Source uncertainty and bandwidth

Finer TSIS (source="tsis") has both source uncertainty (dflam) and Gaussian bandwidth (bandwidth):

fine_native = sloc.get_solspect(source="tsis")
fine_native[["wl", "flam", "dflam", "bandwidth"]][:5]
QTable length=5
wlflamdflambandwidth
umW / (um m2)W / (um m2)um
float64float64float64float64
0.2028.4460915679848170.10979918442899360.0001
0.2020258.4695794918227190.110104527266230420.0001
0.202058.3648079659664630.108742497104685740.0001
0.2020758.2504954076707350.107256440969649690.0001
0.20218.1693017211413380.10620091779856010.0001

All available source columns load by default. To drop columns:

  • cols2drop=("dflam", "bandwidth") omits both.
  • cols2drop="bandwidth" keeps uncertainty, drops the width.
  • Known columns absent from a source are ignored, so one call works across references.

For dataset selection and provenance, see Solar reference.

Uncertainty propagation

Interpolation drops bandwidth and logs an INFO message from skyloc.solspect. The native Gaussian FWHM no longer describes the interpolated response.

For neighboring uncertainties \(\sigma_0\), \(\sigma_1\) and interpolation weights \(1-t\), \(t\), the output variance is

\[ \sigma^2 = (1-t)^2\sigma_0^2 + t^2\sigma_1^2 + 2t(1-t)\rho\sigma_0\sigma_1. \]

The files contain no covariance. Assumption: dflam_rho=1.0 treats neighboring errors as fully correlated, giving an upper bound.

Choose the correlation:

  • dflam_rho=1.0 (default): fully correlated neighbors (upper bound).
  • dflam_rho=0: independent neighbors.
  • A scalar, or one correlation per source interval: another justified model.

Behavior:

  • Metadata records dflam_propagation="upper_bound" when all correlations are 1, otherwise "neighbor_correlation".
  • Exact source nodes keep their original uncertainty.

Excluded. Only the supplied marginal uncertainties propagate. The result leaves out:

  • wavelength errors,
  • interpolation model error,
  • output covariance.

Outputs that share source samples can be correlated even with dflam_rho=0. Reusing an interpolated table cannot reconstruct those correlations. No uncertainty columns are derived for fnu or ABmag.

Caution. Published TSIS uncertainty definitions vary by spectral region, including model comparisons in the infrared. They are not uniformly independent 1σ errors. See Coddington et al. (2023), §4.1.

2. Choose and compare references

Load each reference explicitly when comparing results:

spectra = {
    "tsis_full": solar,
    "tsis": fine_native,
    "astm": sloc.get_solspect(source="astm"),
}

pd.DataFrame(
    [
        {
            "source": source,
            "rows": len(spectrum),
            "minimum [µm]": spectrum["wl"][0].to_value(u.um),
            "maximum [µm]": spectrum["wl"][-1].to_value(u.um),
        }
        for source, spectrum in spectra.items()
    ]
)
source rows minimum [µm] maximum [µm]
0 tsis_full 199885 0.1155 199.999500
1 tsis 101120 0.2020 2.729975
2 astm 1697 0.1195 1000.000000

See Choose a reference for wavelength coverage, spectral resolution, and dataset differences.

Compare their native samples before choosing a grid for your analysis:

with plt.rc_context({"font.size": 10, "axes.grid": True, "grid.alpha": 0.2}):
    fig, axes = plt.subplots(1, 2, figsize=(11, 3.8), layout="constrained")
    for source, spectrum in spectra.items():
        wavelength = spectrum["wl"].to_value(u.um)
        irradiance = spectrum["flam"].to_value(u.W / u.m**2 / u.um)
        overview = (wavelength >= 0.2) & (wavelength <= 10)
        detail = (wavelength >= 0.585) & (wavelength <= 0.595)
        axes[0].loglog(wavelength[overview], irradiance[overview], label=source)
        axes[1].plot(
            wavelength[detail] * 1000,
            irradiance[detail],
            marker=".",
            markersize=3,
            linewidth=1,
            label=source,
        )
    axes[0].set(xlabel="Wavelength [µm]", ylabel="Irradiance [W m⁻² µm⁻¹]")
    axes[1].set(xlabel="Wavelength [nm]", ylabel="Irradiance [W m⁻² µm⁻¹]")
    axes[0].legend()
    axes[1].legend()
    plt.show()
Solar irradiance curves for TSIS full, finer TSIS, and ASTM, with a broad wavelength view and a visible-light close-up.
Figure 1: Native reference samples. Left: optical through infrared coverage. Right: a 585–595 nm close-up showing the different spectral detail. Lines connect samples; they do not represent matching instrumental resolution.

3. Interpolate, reuse, or select rows

Plain wavelength values are in micrometers. The getter loads the data for you:

sampled = sloc.get_solspect([0.6, 1.0, 3.0, 5.2])
sampled
QTable length=4
wlflamdflamfnuABmag
umW / (um m2)W / (um m2)MJymag
float64float64float64float64float64
0.61778.63347959610545.335900699719788213583776.2318217-26.923855029501027
1.0730.74790960639552.192243817262351243751265.28579834-27.06730157459512
3.025.841302559169270.222848051635083377577576.36201888-25.82427489640625
5.22.94093276168155260.0488187961309449726525958.12662812-24.65911207702044

To avoid re-reading the file, pass an existing table. Quantities in other length units are accepted:

sampled_nm = sloc.get_solspect([600, 1000] * u.nm, table=solar)
sampled_nm
QTable length=2
wlflamdflamfnuABmag
umW / (um m2)W / (um m2)MJymag
float64float64float64float64float64
0.61778.63347959610545.335900699719788213583776.2318217-26.923855029501027
1.0730.74790960639552.192243817262351243751265.28579834-27.06730157459512

source and table are mutually exclusive.

Custom table requirements (validated strictly):

  • wl and flam: finite, unmasked, with physical units.
  • Wavelengths positive; irradiances nonnegative.
  • Interpolation also needs a nonempty, strictly increasing source grid.
  • dflam (if present): finite, unmasked, nonnegative, with compatible units.
  • bandwidth (if present): finite, unmasked, positive, with compatible units.

Present dflam and bandwidth columns are included automatically. Other columns in a custom table are copied on its native grid. Interpolation raises ValueError if those extra columns remain; drop them with cols2drop.

For a wavelength cut without interpolation, select existing rows:

cut = solar[(solar["wl"] >= 0.6 * u.um) & (solar["wl"] <= 5.2 * u.um)]
cut[:5]
QTable length=5
wlflamdflamfnuABmag
umW / (um m2)W / (um m2)MJymag
float64float64float64float64float64
0.60051769.38114651817575.30814379453659212826996.3948663-26.92000116752824
0.60151748.95004999781085.246850196272134211070707.86511263-26.911004294297722
0.60251724.93960752279555.174818914383649208865780.87408787-26.899602612722763
0.60351793.73709807035775.381211638450622217917765.09490302-26.945665968342535
0.60451781.22226162349175.343666765838861217115096.38712186-26.94165943208947

A row selection keeps the existing derived columns. For interpolation, pass the complete reference so both neighbors exist at the requested boundaries.

Queries outside the selected reference raise ValueError. For example, the finer TSIS product does not cover 5.2 µm:

try:
    sloc.get_solspect([5.2], source="tsis")
except ValueError as exc:
    coverage_message = str(exc)

coverage_message
'wl_knots must lie within source coverage.'

Interpolation rules:

  • Linear in flam; query order and duplicates are preserved.
  • Magnitudes are computed after interpolating irradiance.

It samples irradiance at points. It does not integrate a filter, conserve flux when rebinning, or recover sub-bin structure.

4. Control and refresh derived columns

The add_fnu and add_abmag flags are independent and both default to True. To get only wl and flam, disable both and omit extras:

physical = sloc.get_solspect(
    [0.6, 1.0, 5.2], cols2drop=("dflam", "bandwidth"), add_fnu=False, add_abmag=False
)
physical
QTable length=3
wlflam
umW / (um m2)
float64float64
0.61778.6334795961054
1.0730.7479096063955
5.22.9409327616815526

Add only AB magnitudes to that table in place:

sloc.solspect_addcols(physical, add_fnu=False)
physical
QTable length=3
wlflamABmag
umW / (um m2)mag
float64float64float64
0.61778.6334795961054-26.923855029501027
1.0730.7479096063955-27.06730157459512
5.22.9409327616815526-24.65911207702044

After editing wavelength or irradiance, refresh the derived columns. Work on a copy when you want to retain the original values:

edited = sampled.copy(copy_data=True)
edited["flam"] *= 2
edited["dflam"] *= 2  # The same exact scale factor applies to uncertainty.
sloc.solspect_addcols(edited)

pd.DataFrame(
    {
        "wavelength [µm]": edited["wl"].to_value(u.um),
        "fnu ratio": (edited["fnu"] / sampled["fnu"]).value,
        "ABmag change": (edited["ABmag"] - sampled["ABmag"]).to_value(u.mag),
    }
)
wavelength [µm] fnu ratio ABmag change
0 0.6 2.0 -0.752575
1 1.0 2.0 -0.752575
2 3.0 2.0 -0.752575
3 5.2 2.0 -0.752575

Doubling irradiance doubles fnu and lowers ABmag by about 0.7526 mag.

solspect_addcols():

  • returns None;
  • preserves other columns and metadata;
  • computes AB magnitudes from wl and flam, independent of any existing fnu;
  • leaves dflam and bandwidth unchanged. Update dflam yourself to match your edit.

Stale columns. A disabled flag leaves an existing column unchanged, so that column can go stale after an edit.

5. Check integration, memory, and provenance

For the full product’s original bins, sum each bin-average irradiance times its width. This applies to the native bins only, not to an arbitrarily interpolated table:

bin_width = solar.meta["bin_width_nm"] * u.nm
integrated_irradiance = (solar["flam"].sum() * bin_width).to(u.W / u.m**2)
integrated_irradiance

\(1361.4892 \; \mathrm{\frac{W}{m^{2}}}\)

The bundled snapshot gives about 1361.489 W m⁻². Skyloc preserves these values and applies no additional normalization.

All three references can coexist. Measure the retained numeric arrays:

pd.DataFrame(
    [
        {
            "source": source,
            "numeric arrays [MiB]": sum(
                spectrum[column].value.nbytes for column in spectrum.colnames
            )
            / 2**20,
        }
        for source, spectrum in spectra.items()
    ]
)
source numeric arrays [MiB]
0 tsis_full 7.625008
1 tsis 4.628906
2 astm 0.051788

Memory for the numeric arrays in all three tables:

  • About 12.31 MiB with all available extras.
  • About 9.24 MiB with cols2drop=("dflam", "bandwidth") for each source.
  • Excludes Python object overhead and temporary loading buffers.

Every getter result owns its data. There is no shared spectrum cache and no import-time data loading.

Dataset versions, original files, conversion details, and checksums are in Source records.

Earlier API names

Earlier call Current form
SOLSPECT sloc.get_solspect(source="astm") to retain ASTM; omit source for TSIS full
solspect_wlcut() Table slicing for a cut; sloc.get_solspect(nodes, table=table) for interpolation
update_solspects(table) sloc.solspect_addcols(table)
add_fnu_ab=False add_fnu=False, add_abmag=False