Astrolabel is a lightweight Python package that allows to efficiently manage astronomy plot labels.
Installation
$ pip install astrolabel
Requirements
python>=3.9astropy>=5.0dacite>=1.8.0
Quick Start
Create a LabelLibrary object:
>>> from astrolabel import LabelLibrary
>>> ll = LabelLibrary.read()
Get a label by its key:
>>> ll.get_label('sfr') # output: '$\\mathrm{SFR}$ [$\\mathrm{M_{\\odot}\\,yr^{-1}}$]'
Change the label format:
>>> ll.get_label('sfr', fmt='log') # output: '$\\log_{10}\\,\\left(\\mathrm{SFR} / \\mathrm{M_{\\odot}\\,yr^{-1}}\\right)$'
Change the unit scale:
>>> ll.get_label('flam', scale=1e-20) # output: '$f_\\lambda$ [$\\mathrm{10^{-20}\\,erg\\,A^{-1}\\,s^{-1}\\,cm^{-2}}$]'
Print the list of available labels:
>>> ll.info() # prints the list of available labels to the console
Label Library
Overview
Astrolabel reads the label data from a YAML file, which we call a label library. Here is an example of a minimal label library which contains only one label:
formats:
linear: '__symbol__'
linear_u: '__symbol__ [__unit__]'
labels:
sfr:
symbol: '\mathrm{SFR}'
unit: 'Msun yr-1' # optional
description: 'Star-formation rate' # optional
wrap: false # optional, default: false
The formats section of the label library comprises custom template strings used by the get_label() method to format the label. When this method is called, the template string is modified as follows: __symbol__ is replaced with the symbol attribute of the label, and __unit__ is replaced with the unit attribute of the label. Note that all template strings must come in two variants: one for labels with a unit, and another one for labels without a unit. The name of the template string where units are used must end with _u (e.g., my_format_u).
Here is a more advanced example of template strings which can be used to create labels for plots with logarithmic axes:
log: '$\log_{10}\,__symbol__$'
log_u: '$\log_{10}\,\left(__symbol__ / __unit__\right)$'
The labels section of the label library comprises custom plot labels with the following attributes:
symbol: the symbol representing the plotted parameter. Math mode is applied to all symbols by default - use\mathrm{}in cases where the upright letter notation is preferable (e.g.,\mathrm{SFR});- [optional]
unit: the plotted parameter's unit of measurement. All units are converted to the LaTeX format using the Astropy'sQuantity.to_string()method. The list of units supported by Astropy and hence by Astrolabel can be found in the Astropy's official documentation here. This list covers most (if not all) units used in astronomy. However, if you want to define new units, follow the instructions on this page; - [optional]
description: the text description of the plotted parameter; - [optional]
wrap: if true, place the symbol in parentheses (default: false).
Note: due to the specifics of YAML, it is highly recommended to use single quotes (') when adding new labels or label formats to the label library.
Specifying the library location
The path to the label library can be passed to the LabelLibrary constructor:
>>> ll = LabelLibrary.read('/path/to/label/library.yml')
In case no arguments are passed to the constructor, Astrolabel looks for the label library in three locations, in the following order:
astrolabel.ymlin the current working directory.$ASTROLABEL- the best option for users who want to use the same library across different projects.- The default library location (see below). Note that the default library will be overwritten each time you reinstall or update the package.
The location of the current library is stored in the library_path attribute of the LabelLibrary object:
>>> ll.library_path # output: PosixPath('/home/foo/.../bar/astrolabel.yml')
The default library
The Astrolabel package comes with a label library which includes two label formats (linear and log) and some scripts and labels commonly used in astronomy plots. The location of the default label library is stored in the DEFAULT_LIBRARY_PATH constant:
>>> from astrolabel import DEFAULT_LIBRARY_PATH
>>> DEFAULT_LIBRARY_PATH # output: '/home/foo/.../astrolabel/astrolabel/data/astrolabel.yml'
Metadata
Release files for astrolabel 0.2.0
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 |
|---|---|---|---|---|
| astrolabel-0.2.0.tar.gz | 7.2 kB | Without provenance | Details for astrolabel-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| astrolabel-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for astrolabel-0.2.0-py3-none-any.whl |
Total release size: 15.7 kB
Release files / astrolabel-0.2.0.tar.gz
| Download URL | astrolabel-0.2.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f72b25449e852fd105560c5d6910556e3c0cfafda8a0b30e64e0cd990274261
|
|
BLAKE2b-256 checksum How to use checksums |
320411d9c1e108ceb6c11ea29d54d7e0011e4f287ec34cf31a496ee5923d6aff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.6 Linux/6.1.0-32-amd64
|
Release files / astrolabel-0.2.0-py3-none-any.whl
| Download URL | astrolabel-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2cc986612cd99f0dbb1084cdcd3254fd161437de284d06366868c1d81a7ba0b4
|
|
BLAKE2b-256 checksum How to use checksums |
1a225e41e55a9f2acdf8a2b2e444832101587a6fb88b1b4e2b080e5008cdd2ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.6 Linux/6.1.0-32-amd64
|
Security for astrolabel 0.2.0
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.