Configuration API Reference

Functions that control Mera's global behaviour, and the constructors for the unit and constant tables that data objects carry.

Output Control

Global switches for how much Mera prints. Each one returns the current setting when called with no argument, so it can be queried as well as set.

Mera.verbose — Function
verbose(mode::Union{Bool,Nothing})
verbose()

Set or show the global verbose mode for all subsequent Mera operations. verbose(false) silences Mera's text messages, verbose(true) forces them on (the per-function verbose= argument is then ignored), and verbose(nothing) reverts to each function's own argument (the neutral default). verbose() with no argument prints the current state. See also showprogress and the combined master switch output_mode.

verbose(false)    # quiet
verbose()         # prints "verbose_mode: false"
verbose(nothing)  # back to per-function control

Returns the new setting; without an argument it prints the current one.

Mera.showprogress — Function
showprogress(mode::Union{Bool,Nothing})
showprogress()

Set or display the global progress-bar mode.

When called with a Bool, enables (true) or disables (false) progress bars for all subsequent Mera operations. Pass nothing to revert to each function's default behaviour. When called without arguments, prints the current setting.

Examples

showprogress(false)   # suppress all progress bars
showprogress()        # prints "showprogress_mode: false"
showprogress(nothing) # restore per-function defaults

Returns the new setting; without an argument it prints the current one.

Mera.output_mode — Function
output_mode(mode::Union{Bool,Nothing})
output_mode()

Master switch that sets both verbose and showprogress at once — so you don't toggle them separately. Same meaning as those: output_mode(false) silences all Mera text and progress bars globally, output_mode(true) forces both on, and output_mode(nothing) reverts both to each function's own verbose=/show_progress= argument (the neutral default). output_mode() with no argument prints the current state of both.

output_mode(false)    # quiet: no messages, no progress bars, anywhere
output_mode(nothing)  # back to per-function control
output_mode()         # show current state

Returns nothing; without an argument it prints the current settings.

Sidecar files

Every file that savedata, savemap, savemovie and exportdata write gets a small readable <file>.meta.json next to it, with the provenance, the units and the environment that ran. Each function has a sidecar keyword; this switch overrides all of them at once.

Mera.sidecar — Function
sidecar(mode::Union{Bool,Nothing})
sidecar()

Set or show the global sidecar mode. A sidecar is the small <file>.meta.json that savedata, savemap, savemovie, save_clumps, exportdata and writesidecar write next to each file, with the provenance, units and environment of the result.

sidecar(false) stops all of them from writing one, sidecar(true) makes all of them write one (the per-function sidecar= keyword is then ignored), and sidecar(nothing) reverts to each function's own keyword (the neutral default; the keywords default to true). sidecar() with no argument prints the current state.

sidecar(false)    # no sidecar files
sidecar()         # prints "sidecar_mode: false"
sidecar(nothing)  # back to per-function control

Without changing a script, the environment variable MERA_SIDECAR does the same for every session: MERA_SIDECAR=0 julia analysis.jl writes no sidecars (also false, no, off), and 1, true, yes or on writes them for every call. sidecar(true) or sidecar(false) in the session wins over it.

Returns the new setting; without an argument it prints the current one.

Mera.sidecar_mode — Constant

Global switch controlling whether saves and exports write a sidecar <file>.meta.json.

nothing (the default) leaves each function on its own sidecar keyword, which is true, unless the environment variable MERA_SIDECAR says otherwise; setting true or false overrides them all. Prefer sidecar to change it.

sidecar(false)     # no sidecar files from any save, export or writesidecar
sidecar(nothing)   # hand control back to the per-call keywords

Persistent Configuration

Settings that survive between sessions, stored in a configuration file rather than set per session.

Mera.mera_config — Function
mera_config(; reload=false) -> Dict{String,Dict{String,Any}}

The merged user configuration, as section => key => value.

Sources, lowest precedence first: the legacy email.txt/zulip.txt/bell.txt, then mera_config_path's TOML, then environment variables. So a ~/.mera.toml wins over the old files when both exist, and an env var wins over everything.

mera_config()["zulip"]["server"]

Results are cached; pass reload=true after editing the file in a live session. home redirects the legacy-file lookup, which exists so the resolution can be tested without reading the caller's real $HOME. See mera_config_example for a template.

Mera.mera_config_path — Function
mera_config_path() -> Union{String,Nothing}

Path of the ~/.mera.toml in effect, or nothing when no TOML config exists (in which case the legacy email.txt/zulip.txt/bell.txt are still read). Checks $MERA_CONFIG, then ~/.mera.toml, then ~/.config/mera/config.toml. home redirects the last two so resolution can be tested without reading the caller's real home directory.

Mera.mera_config_example — Function
mera_config_example([io]) -> nothing

Print a complete, commented ~/.mera.toml template covering email, Zulip and the bell sound. Copy it, fill in what you use, and chmod 600 it — it holds an API key.

Constants and Scales

Every data object carries a table of physical constants and a table of scale factors that convert code units to physical units. These build them directly, which is what makes it possible to construct a working Mera object without any simulation files on disk.

Mera.createconstants — Function
createconstants() -> PhysicalUnitsType

Return Mera's table of physical constants in CGS units — G, c, kB, mH, Msol, pc, yr and the rest. This is what info.constants holds, and what every derived quantity is built from.

Use it to get the constants without an InfoType in hand; createconstants! fills the field on an existing info instead.

c = createconstants()
c.G       # 6.6743e-8  cm³ g⁻¹ s⁻²
c.Msol    # 1.9891e33  g

Mixing these CGS constants with code-unit quantities is the classic source of silently wrong answers — convert first, e.g. getvar(gas, :rho, :g_cm3).

See also createconstants!, createscales, getunit.

Mera.createscales — Function
createscales(info::InfoType) -> ScalesType
createscales(unit_l, unit_d, unit_t, unit_m, constants) -> ScalesType

Build the unit-conversion table — the object behind info.scale. Every entry is the factor that takes a code-unit quantity into that unit, so getvar(gas, :rho) .* info.scale.g_cm3 and getvar(gas, :rho, :g_cm3) agree.

The four-number form builds scales without an InfoType, which is how the unit tests check the conversions against CODATA without reading a snapshot.

Note a scale of exactly 1.0 cannot detect an inverted conversion (x*1 == x/1) — a fixture whose scale.kpc is 1 will not catch a reciprocal bug.

See also createscales!, createconstants, getunit.

X_frac (0.76) is the hydrogen mass fraction behind :nH, and mu (1/X_frac) the mean molecular weight behind temperatures in :K; see setcomposition! to change them on an InfoType.

Mera.createscales! — Function

Create an object with predefined scale factors from code to pysical units

function createscales!(dataobject::InfoType)

return ScalesType003
Mera.setcomposition! — Function
setcomposition!(info; X_frac=0.76, mu=1/X_frac) -> InfoType

State the gas composition of a run, and rebuild the unit table from it.

Two quantities depend on composition, and most simulation outputs do not record it:

  • X_frac, the hydrogen mass fraction, converts a mass density to :nH
  • mu, the mean molecular weight, converts pressure over density to a temperature in :K

The defaults are the RAMSES convention, X = 0.76 with mu = 1/X, and they are what every reader starts from. Another code will assume something else. PLUTO without a chemistry module treats the gas as fully ionised, X = 0.711 and mu = 0.614, which makes its temperatures about a factor of two lower than the default would give.

Nothing changes unless you call this, so existing results are unaffected. The exception is a RAMSES-RT run: its info_rt file states X, and getinfo uses that value (with mu = 1/X). On such a run :T also takes μ per cell from the tracked ionisation, so the constant mu here only matters where the ionisation fractions are not loaded.

info = getinfo(5, path)
setcomposition!(info; X_frac=0.711, mu=0.614)   # PLUTO defaults, fully ionised
getvar(gas, :T, :K)

getvar(gas, :T, :K_mu) needs no composition at all: it is Kelvin per unit mu, so you can multiply by whatever value your run implies.

Unit resolution itself goes through getunit, documented with the calculations that use it.