Cosmonstants.jl
Cosmonstants.jl builds on top of PhysicalConstants.jl to deliver extra constants (astrophysics, high-energy physics, and Corpuscles-derived particle masses) together with simple utilities for working with multiple unit systems.
Highlights
Cosmonstants.Constantsexports CODATA2022 data as well as the extended sets defined inconstants/extended.jl,constants/hep.jl, andconstants/astro.jlso everything stays in sync with the registrar helpers used by the package.- The
@createConstantsForMassesmacro turns Corpuscles.jl particle masses into the same@constantentries used by PhysicalConstants; this is whyMassMuon,MassTau, and the quark masses live in the same table asSolarMassandPlanckConstant. Cosmonstants.Unitfullre-exports those constants under short aliases such asc_0,ħ, orM☉, whileCosmonstants.Unitlessstrips the units so you can work with raw SI numbers.getUnitSystem+getUnitSystemModuledispatch onRealversusAbstractQuantityso multi-method APIs can react to the caller's preferred system without manual branching.
Quick start
julia> using Cosmonstants
julia> Cosmonstants.SolarMass
mass of the Sun (M☉)
Value = 1.98847e30 kg
Standard uncertainty = 7.0e25 kg
Relative standard uncertainty = 3.5e-5
Reference = IAU1976julia> uf = getUnitSystem(Unitful.Quantity)
UnitfullSystem()
julia> uf.c_0
SpeedOfLightInVacuum (c_0)
Value = 2.99792458e8 m s^-1
Standard uncertainty = 0.0 m s^-1
Reference = CODATA2022
julia> ul = getUnitSystem(Float64)
UnitlessSystem()
julia> ul.c_0
2.99792458e8Helpers & references
getListOfConstants()lists the canonical constants that feed the modules above; use it to build tables, documentation, or introspection tools.correspondingSymbol(constant)returns the short alias forUnitfull(useful for generating tables or matching to external datasets).fullReference(shortRef)looks up the stored bibliography entries plus sensible fallbacks (CODATA2022, PDG2022, IAU resolutions, etc.).
Whenever you add new constants, keep constants/extended.jl, constants/hep.jl, or constants/astro.jl in sync with the relevant references and correspondingSymbol aliases.
Building the docs
This repository ships with a Documenter.jl build under docs/. To rebuild locally, run:
julia --project=docs docs/make.jlThe generated output lands in docs/build and mirrors what is hosted at https://rafaelab.github.io/Cosmonstants.jl/index.html.
Cosmonstants.referencesDict — Constant
The dictionary of references.
Cosmonstants.correspondingSymbol — Method
Given a constant, return its short name.
Cosmonstants.fullReference — Method
Get the full reference for a given source of information.
Cosmonstants.getCorpusclesParticleMassUncertainty — Method
Helper function (unexported) to get the mass uncertainty value of a particle in kg. If lower and upper uncertainties are different, return the largest one of the two. This is done to be fully consistent with PhysicalConstants.jl, which uses the package Measurements.jl, which does not accept asymmetric uncertainties.
Input
. p:: ParticleType object for Corpuscles.jl
Output
. Particle mass uncertainty (without explicit units) in kg.
Cosmonstants.getCorpusclesParticleMassValue — Method
Helper function (unexported) to get the mass value of a particle in kg.
Input
. p:: ParticleType object for Corpuscles.jl
Output
. Particle mass (without explicit units) in kg.
Cosmonstants.getListOfConstants — Method
Get list of constants. This is useful to remove items that are not constants to create table of constants.
Cosmonstants.getUnitSystem — Method
getUnitSystem(::Type{T}) where {T}
getUnitSystem(::T) where {T}Returns the unit system module (Unitfull or Unitless) corresponding to the type T. It acts as a dispatcher for functions that depend on the unit system.
Cosmonstants.getUnitSystemModule — Method
getUnitSystemModule(::Type{<: AbstractUnitSystem})
getUnitSystemModule(::<: AbstractUnitSystem)Returns the unit system module (Unitfull or Unitless) corresponding to the given AbstractUnitSystem type or instance.
Cosmonstants.@captureShowOutput — Macro
@captureShowOutput(ex)A macro that captures the output of evaluating an expression ex and returns a tuple containing the result of the evaluation and a string representation of the output.
Input
. ex: the expression to be evaluated (e.g., a constant or a mathematical expression).
Output
A tuple (val, output_string) where:
. val is the result of evaluating the expression ex
. output_string is a string containing the expression, its result, and its textual representation
Cosmonstants.@createConstantsForMasses — Macro
Macro to conveniently create objects like in PhysicalConstants.jl from particle masses contained in Corpuscles.jl.
Input
. particle: a Corpuscles's Particle-type object . name: explicit name of the variable of the corresponding constant . symbol: short alias for the corresponding quantity (must be explicitly imported) . info: string containing the details of the quantity.
To do
. automatically retrieve PDG year (Corpuscles._default_year).
Cosmonstants.Unitfull — Module
module UnitfullThis module defines a set of physical constants and derived quantities. It imports fundamental constants from external modules and provides shorthand notations for convenience. By using the module, the corresponding constants/units are scope-protected.
Cosmonstants.Unitless — Module
module UnitlessThis module defines a set of physical constants and derived quantities stripping its units. The default is S.I. units.