Skip to main content

Spectrum encoder and decoder

Project description

Spender

Neural spectrum encoder and decoder

From a data-driven side, galaxy spectra have two fundamental degrees of freedom: their instrinsic spectral properties (or type, if you believe in such a thing) and their redshift. The latter makes them awkward to ingest because it stretches everything, which means spectral features don't appear at the same places. This is why most analyses of the intrinsic properties are done by transforming the observed spectrum to restframe.

We decided to do the opposite. We build a custom architecture, which describes the restframe spectrum by an autoencoder and transforms the restframe model to the observed redshift. While we're at it we also match the spectral resolution and line spread function of the instrument: sketch

Doing so clearly separates the responsibilities in the architecture. Spender establishes a restframe that has higher resolution and larger wavelength range than the spectra from which it is trained. The model can be trained from spectra at different redshifts or even from different instruments without the need to standardize the observations. Spender also has an explicit, differentiable redshift dependence, which can be coupled with a redshift estimator for a fully data-driven spectrum analysis pipeline.

Installation

The easiest way is pip install spender. When installing from a downloaded code repo, run pip install -e ..

Pretrained models

We make the best-fitting models discussed in the paper available through the Astro Data Lab Hub. Here's the workflow:

import os
import spender

# show list of pretrained models
spender.hub.list()

# print out details for SDSS model from paper II
print(spender.hub.help('sdss_II'))

# load instrument and spectrum model from the hub
sdss, model = spender.hub.load('sdss_II')

# if your machine does not have GPUs, specify the device
from accelerate import Accelerator
accelerator = Accelerator(mixed_precision='fp16')
sdss, model = spender.hub.load('sdss_II', map_location=accelerator.device)

Outliers Catalogs

catalog of latent-space probabilities for

Use

Documentation and tutorials are forthcoming. In the meantime, check out train/diagnostics.ipynb for a worked through example that generates the figures from the paper.

In short, you can run spender like this:

import os
import spender
import torch
from accelerate import Accelerator

# hardware optimization
accelerator = Accelerator(mixed_precision='fp16')

# get code, instrument, and pretrained spectrum model from the hub
sdss, model = spender.hub.load('sdss_II',  map_location=accelerator.device)

# get some SDSS spectra from the ids, store locally in data_path
data_path = "./DATA"
ids = ((412, 52254, 308), (412, 52250, 129))
spec, w, z, norm, zerr = sdss.make_batch(data_path, ids)

# run spender end-to-end
with torch.no_grad():
  spec_reco = model(spec, instrument=sdss, z=z)

# for more fine-grained control, run spender's internal _forward method
# which return the latents s, the model for the restframe, and the observed spectrum
with torch.no_grad():
  s, spec_rest, spec_reco = model._forward(spec, instrument=sdss, z=z)

# only encode into latents
with torch.no_grad():
  s = model.encode(spec)

Plotting the results of the above nicely shows what spender can do:

examples_2

Noteworthy aspects: The restframe model has an extended wavelength range, e.g. predicting the [O II] doublet that was not observed in the first example, and being unaffected by glitches like the skyline residuals at about 5840 A in the second example.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spender-0.2.7.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spender-0.2.7-py2.py3-none-any.whl (36.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file spender-0.2.7.tar.gz.

File metadata

  • Download URL: spender-0.2.7.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.7.0 pkginfo/1.9.6 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.65.0 CPython/3.8.16

File hashes

Hashes for spender-0.2.7.tar.gz
Algorithm Hash digest
SHA256 c5382e250f029aaf2088bfd4dc0f2cfe869a351089c1ba536642d8573b5a1fd9
MD5 f69ea12ce9446eda626ec08a89f50048
BLAKE2b-256 eaaf5403e75423027d8b67e55e53ce497679587f97a4d7ba51f2b26911c327c1

See more details on using hashes here.

File details

Details for the file spender-0.2.7-py2.py3-none-any.whl.

File metadata

  • Download URL: spender-0.2.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.7.0 pkginfo/1.9.6 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.65.0 CPython/3.8.16

File hashes

Hashes for spender-0.2.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2c527fae5258ca7a1bfb86b28ecf496c320c089392da980109bf660a70bb0a6e
MD5 3d5b1c9fc479fab3a62ed826af16b280
BLAKE2b-256 0229f5f59c1a10e6f718800d720c4ea37b994f89b702675b507410eb9e53b8df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page