Skip to main content

No project description provided

Project description

Transformer Payne

Python Version Build workflow Tests Coverage Status


Tomasz Różański, Yuan-Sen Ting and Maja Jabłońska, "Toward a Spectral Foundation Model: An Attention-Based Approach with Domain-Inspired Fine-Tuning and Wavelength Parameterization", https://arxiv.org/abs/2306.15703


Important note: The implementation of TransformerPayne in this repository includes slight modifications from the version described in the paper above. These changes involve most importantly the placement of residual connections and hyperparameter tuning. Detailed explanations will be provided in an upcoming paper.

Example usage:

import jax
jax.config.update("jax_enable_x64", True)

import transformer_payne as tp
import numpy as np
import matplotlib.pyplot as plt

emulator = tp.TransformerPayne.download() # Download weights for default emulator

wave = np.linspace(4670, 4960, 20000)
mu = 1.0 # Ray perpendicular to solar surface
parameters = emulator.solar_parameters # Pick solar parameters and abundances

spectrum = emulator(np.log10(wave), mu, parameters) # Emulate a spectrum

Visulize the results:

intensity = spectrum[:,0]
continuum = spectrum[:,1]
normalized_intensity = intensity / continuum

fig, axs = plt.subplots(2, sharex=True, figsize=(5, 4))
axs[0].plot(wave, intensity, color='black', label='Intensity')
axs[0].plot(wave, continuum, color='red', label='Intensity continuum')
axs[1].plot(wave, normalized_intensity, label="Normalized intensity", color='black')
axs[1].vlines(4862.721, 0, 1, color='C0', label=r'$H_\beta$ (vacuum wavelength)')  # Using raw string for LaTeX
axs[1].set_xlabel("Wavelength [$\AA$]")  # Corrected to set xlabel on the second subplot
axs[0].set_ylabel("Intensity [erg/s/cm$^3$/ster]")
axs[1].set_ylabel("Normalized Intensity")
axs[0].legend(loc="lower left")
axs[1].legend(loc="lower left")
plt.subplots_adjust(hspace=0.05)
plt.show()

example_spectrum

Installation

Installation using pip

Install transformer-payne along with the huggingface-hub and joblib modules, which enable easy downloading of model weights from the internet.
Make sure you also have matplotlib and numpy installed in order to run the example shown above.
If you plan to use the notebooks with additional examples located in the tutorial/ directory, please also install jupyterlab, notebook, and ipykernel.

pip install transformer-payne
pip install huggingface-hub joblib numpy matplotlib
pip install jupyterlab notebook ipykernel

Developer installation from local repository

git clone https://github.com/RozanskiT/transformer_payne.git
cd transformer_payne
pip install -e .[dev]

Available Emulators

MARCS, Korg.jl and Kurucz's linelist - default intensity emulator

Disclaimer: This is an experimental version of the emulator. We do not recommend using it to infer atmospheric parameters of stars, as it currently has significant limitations. However, it is valuable for method development and benchmarking. We are actively working on a future release of emulators with well-understood and validated precision suitable for inference. If you have any questions, concerns, or are interested in developing an emulator for your own spectral grid (in intensity, fluxes, or potentially including Stokes parameters), please don’t hesitate to contact me.

This document outlines an emulator built upon a slightly adapted version of the Korg.jl package and the MARCS stellar atmosphere grid. It simulates stellar spectra across a broad parameter space:

  • Effective Temperature (Teff): 4,000 - 8,000 K
  • Surface Gravity (logg): 2.0 - 5.0
  • Microturbulence (vmic): 0 - 5 km/s
  • Metallicity ([Fe/H]): -2.5 to 1.0
  • Alpha-element Enhancement ([alpha/Fe], ): -1.0 to 1.0
  • Carbon-to-Iron Ratio ([C/Fe]): -1.0 to 1.0
  • Elemental Abundances: Individual abundances can vary within a logarithmic range of ±0.3, from Helium to Uranium (with respect to given [Fe/H], [alpha/Fe] and [C/Fe])
  • Resolution: ~300,000
  • Wavelengths span: 1,500 to 20,000 angstroms

The emulator employs the Kurucz's linelist gfall08oct17.dat in Korg.jl code. For more information, visit the following links:

  • Korg.jl: link
  • Kurucz's linelist gfall08oct17.dat: link
  • MARCS Grid: link

Work in progress...

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

transformer_payne-0.9.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

transformer_payne-0.9-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file transformer_payne-0.9.tar.gz.

File metadata

  • Download URL: transformer_payne-0.9.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for transformer_payne-0.9.tar.gz
Algorithm Hash digest
SHA256 620260d301ba02460b19763dcd8fdc819ef368707d69d2e9231f9e7b57cb4e23
MD5 5e2fe1f63502e1d728ea6d47d5a6eb19
BLAKE2b-256 9a15659b0365d83d1a6e6fa658035b00dd63ce3d3f18f91d553c1e7c647753cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for transformer_payne-0.9.tar.gz:

Publisher: release.yml on RozanskiT/transformer_payne

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transformer_payne-0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for transformer_payne-0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 bb1d26621952906049b9e6b5f98a6e0e5caa29c39d25c3be22398d6541157746
MD5 39e7e356d4e2bef900693b923b25f007
BLAKE2b-256 d8a227e9979e0fcb25904cdee53b6a2f63d4bf3b098afda015c830e4727bf251

See more details on using hashes here.

Provenance

The following attestation bundles were made for transformer_payne-0.9-py3-none-any.whl:

Publisher: release.yml on RozanskiT/transformer_payne

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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