Package: astrolabel
Astrolabel is a lightweight Python package that allows to efficiently manage astronomy plot labels.Installation$pipinstallastrolabelRequirementspython>=3.8astropy>=5.0dacite>=1.8.0Quick StartCreate aLabelLibraryobject:>>>fromastrolabelimportLabelLibrary>>>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)$'Print the list of available labels:>>>ll.info()# prints the list of available labels to the consoleLabel LibraryOverviewAstrolabel reads the label data from aYAMLfile, which we call alabel library. Here is an example of a minimal label library which contains only one label:formats:default:'__symbol__'default_u:'__symbol__[__unit__]'labels:sfr:symbol:'\mathrm{SFR}'unit:'Msunyr-1'# optionaldescription:'Star-formationrate'# optionalTheformatssections contains the list of custom template strings used by theget_label()method to format the label. When this method is called, the template string is modified as follows:__symbol__is replaced with thesymbolattribute of the label, and__unit__is replaced with theunitattribute 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)$'Thelabelssection of the label library contains the list of custom plot labels, each of which has the following attributes:symbol: the symbol representing the plotted parameter. Note that math mode is applied to all symbols by default. Therefore, 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 documentationhere. This list covers most (if not all) units used in astronomy. However, if you want to define new units, follow the instructions onthis page;[optional]description: the text description of the plotted parameter.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 locationThe path to the label library can be passed to theLabelLibraryconstructor:>>>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.To check the location of the currently active library, call thelibrary_fname()method of theLabelLibraryobject:>>>ll.library_fname()# output: PosixPath('/home/foo/.../bar/astrolabel.yml')The default libraryThe Astrolabel package comes with a label library which includes two label formats (defaultandlog) and some labels commonly used for astronomy plots. The location of the default label library is stored in theDEFAULT_LIBRARY_PATHconstant:>>>fromastrolabelimportDEFAULT_LIBRARY_PATH>>>DEFAULT_LIBRARY_PATH# output: '/home/foo/.../astrolabel/astrolabel/data/astrolabel.yml'