ASTROMER Python library 🔭
ASTROMER is a transformer based model pretrained on millions of light curves. ASTROMER can be finetuned on specific datasets to create useful representations that can improve the performance of novel deep learning models.
❗ This version of ASTROMER can only works on single band light curves.
Install
pip install ASTROMER
How to use it
Currently, there are 2 pre-trained models: macho and atlas.
To load weights use:
from ASTROMER.models import SingleBandEncoder
model = SingleBandEncoder()
model = model.from_pretraining('macho')
It will automatically download the weights from this public github repository and load them into the SingleBandEncoder instance.
Assuming you have a list of vary-lenght (numpy) light curves.
import numpy as np
samples_collection = [ np.array([[5200, 0.3, 0.2],
[5300, 0.5, 0.1],
[5400, 0.2, 0.3]]),
np.array([[4200, 0.3, 0.1],
[4300, 0.6, 0.3]]) ]
Light curves are Lx3 matrices with time, magnitude, and magnitude std.
To encode samples use:
attention_vectors = model.encode(samples_collection,
oids_list=['1', '2'],
batch_size=1,
concatenate=True)
where
samples_collectionis a list of numpy array light curvesoids_listis a list with the light curves ids (needed to concatenate 200-len windows)batch_sizespecify the number of samples per forward pass- when
concatenate=TrueASTROMER concatenates every 200-lenght windows belonging the same object id. The output whenconcatenate=Trueis a list of vary-length attention vectors.
Finetuning or training from scratch
ASTROMER can be easly trained by using the fit. It include
from ASTROMER import SingleBandEncoder
model = SingleBandEncoder(num_layers= 2,
d_model = 256,
num_heads = 4,
dff = 128,
base = 1000,
dropout = 0.1,
maxlen = 200)
model.from_pretrained('macho')
where,
num_layers: Number of self-attention blocksd_model: Self-attention block dimension (must be divisible bynum_heads)num_heads: Number of heads within the self-attention blockdff: Number of neurons for the fully-connected layer applied after the attention blocksbase: Positional encoder base (see formula)dropout: Dropout applied to output of the fully-connected layermaxlen: Maximum length to process in the encoder Notice you can ignoremodel.from_pretrained('macho')for clean training.
mode.fit(train_data,
validation_data,
epochs=2,
patience=20,
lr=1e-3,
project_path='./my_folder',
verbose=0)
where,
train_data: Training data already formatted as tf.datavalidation_data: Validation data already formatted as tf.dataepochs: Number of epochs for trainingpatience: Early stopping patiencelr: Learning rateproject_path: Path for saving weights and training logsverbose: (0) Display information during training (1) don't
train_data and validation_data should be loaded using load_numpy or pretraining_records functions. Both functions are in the ASTROMER.preprocessing module.
For large datasets is recommended to use Tensorflow Records (see this tutorial to execute our data pipeline)
Resources
Contributing to ASTROMER 🤝
If you train your model from scratch, you can share your pre-trained weights by submitting a Pull Request on the weights repository
Metadata
Release files for ASTROMER 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| astromer-0.1.8.tar.gz | 3.0 MB | Without provenance | Details for astromer-0.1.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| astromer-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for astromer-0.1.8-py3-none-any.whl |
Total release size: 3.0 MB
Release files / astromer-0.1.8.tar.gz
| Download URL | astromer-0.1.8.tar.gz |
|---|---|
| Size | 3.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7aa7ba98389d39ba3e1d3e7ba8d8f5e85cbec53aba0df67378a7a3f556d7cb59
|
|
BLAKE2b-256 checksum How to use checksums |
98142e2f8252fad1e0eb0dc0d16166e0c340e4f253051841f62f166fde19d395
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|
Release files / astromer-0.1.8-py3-none-any.whl
| Download URL | astromer-0.1.8-py3-none-any.whl |
|---|---|
| Size | 28.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e2cf7cf01d39bc93f42bdbdbd95f1b3138ce1755a9b4c989c730790a067a078
|
|
BLAKE2b-256 checksum How to use checksums |
7b1925c1e8348967134e41b02826524d15b3476973dd761b084ba982b35baf5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|
Security for ASTROMER 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.