MERA Files API Reference
Docstrings for Mera's own save format, an LZ4-compressed JLD2 file that round-trips a loaded object far faster than re-reading the simulation. The narrative guides are Mera-Files and Converter.
The file stores the Julia object, so it is a Julia-side format: reload it with loaddata, not with h5py. To hand results to another language use exportdata (below), or export_vtk for ParaView and VisIt.
Save & load
Mera.savedata — Function
savedata(data; fmode, path="./", kwargs...)
savedata(data, fmode::Symbol; path="./", kwargs...)
savedata(data, path::String; fmode, kwargs...)
savedata(data, path::String, fmode::Symbol; kwargs...)Save a Mera data object to a compressed JLD2 file, a "Mera file", which reloads much faster than the original RAMSES output.
One file per output holds any number of data types (hydro, particles, gravity, clumps, RT, sinks). The file is named after the output number, e.g. output_00300.jld2, and keeps the table together with the simulation information and the options it was loaded with.
Arguments
data: the object to save, fromgethydro,getparticles,getgravity,getclumps,getrtorgetsinks.fmode::Symbol: what to do with the file. Nothing is written unless it is given, so a file is never overwritten by accident.:write: create the file, or replace an existing one.:append: add a further data type to an existing file. A data type that is already in the file is not replaced; that raises an error.
path::String = "./": the folder to write to.
Keywords
fname = "output_": the start of the file name; the five-digit output number follows.compress: LZ4 compression is on by default;compress=falseswitches it off. Older compressor objects are accepted, and Zlib or Bzip2 fall back to LZ4 with a warning.comments: a text stored with the data, e.g. a description of the simulation.dataformat::Symbol = :JLD2: the only format.merafile_version::Float64 = 1.0: the file layout version; there is only one.sidecar::Bool = true: also writeoutput_XXXXX.jld2.meta.json, a readable record of the data types in the file, their provenance and the environment; an append adds to it. The global switchsidecaroverrides this keyword.anonymize::Bool = false: in the sidecar, keep only the last two parts of the simulation path.note::String = "": a free text stored in the sidecar.include_script::Bool = false: also store the full text of the running script (or the code cells of the notebook) in the sidecar. Its name and SHA-256 are always recorded, when Julia knows the script.verbose::Bool = true: print what is written.
Examples
julia> savedata(gas, :write; path="mera_files/"); # new file output_00300.jld2
julia> savedata(part, :append; path="mera_files/"); # add the particles to it
julia> viewdata(300; path="mera_files/") # what the file holdsSee also loaddata, viewdata, infodata, convertdata.
Returns nothing.
Mera.loaddata — Function
loaddata(output::Int, datatype::Symbol; path="./", kwargs...)
loaddata(output::Int, path::String, datatype::Symbol; kwargs...)
loaddata(output::Int; datatype, path="./", kwargs...)
loaddata(output::Int, path::String; datatype, kwargs...)Load one data type from a Mera file written by savedata.
The stored table is read in full; a region given by the ranges is then cut out. Files written by any earlier Mera version can be read.
Arguments
output::Int: the output number in the file name, e.g.300foroutput_00300.jld2.datatype::Symbol: the data type to load::hydro,:particles,:gravity,:clumps,:rtor:sinks. It is required, as a positional argument or as a keyword.path::String = "./": the folder of the file.
Keywords
Selection:
xrange,yrange,zrange:[min, max]of the region to keep, inrange_unitand relative tocenter.missing(the default) means the full extent.center = [0, 0, 0]: the origin of the ranges, inrange_unit.[:bc]is the box centre.range_unit::Symbol = :standard: the unit of the ranges and the centre.:standardmeans fractions of the box (0 to 1); any length unit ininfo.scaleworks, e.g.:kpc.
File:
fname = "output_": the start of the file name, as given tosavedata.regenerate_scales::Bool = true: recompute the physical constants and unit scales with the current Mera version.falsekeeps exactly what was stored.
Output:
verbose::Bool = true: print what is read.myargs::ArgumentsType: set the ranges,center,range_unitandverbosein one object. A keyword given directly takes precedence.
Returns
The stored object, e.g. a HydroDataType for :hydro, the same as the function that first read it returned.
Examples
julia> gas = loaddata(300, :hydro; path="mera_files/");
julia> part = loaddata(300, "mera_files/", :particles; xrange=[-10, 10], yrange=[-10, 10],
zrange=[-2, 2], center=[:bc], range_unit=:kpc);Mera.viewdata — Function
viewdata(output::Int, path::String="./"; fname="output_", showfull=false, verbose=true) -> DictShow what a Mera file written by savedata contains, without loading the data.
For each stored data type it reports the Mera and file versions, the compression, the size on disk and in memory, and the conversion statistics when the file was made by convertdata.
Arguments
output::Int: the output number in the file name, e.g.300foroutput_00300.jld2.path::String = "./": the folder of the file; also a keyword.
Keywords
fname = "output_": the start of the file name, as given tosavedata.showfull::Bool = false: also print the full tree of the file.verbose::Bool = true: print the overview.
Returns
A Dict with one entry per stored data type (e.g. "hydro", "particles") and "FileSize".
Examples
julia> viewdata(300, "mera_files/");
julia> keys(viewdata(300, "mera_files/"; verbose=false))Mera.infodata — Function
Get the simulation overview from RAMSES, saved in JLD2 == function getinfo
infodata(output::Int;
path::String="./",
fname = "output_",
datatype::Any=:nothing,
verbose::Bool=true)
return InfoTypeKeyword Arguments
output: timestep numberpath: the path to the output JLD2 file relative to the current folder or absolute pathfname: "output"-> filename = "output***.jld2" by default, can be changed to "myname***.jld2"verbose:: informations are printed on the screen by default
Examples
# read simulation information from output `1` in current folder
julia> info = infodata(1) # filename="output_00001.jld2"
# read simulation information from output `420` in given folder (relative path to the current working folder)
julia> info = infodata(420, path="../MySimFolder/")
# or simply use
julia> info = infodata(420, "../MySimFolder/")
# get an overview of the returned field-names
julia> propertynames(info)
# a more detailed overview
julia> viewfields(info)
...
julia> viewallfields(info)
...
julia> namelist(info)
...
julia> makefile(info)
...
julia> timerfile(info)
...
julia> patchfile(info)
...Export for other tools
exportdata writes a projection, a profile, phase or pdf, a timeseries table, a movie, or plain arrays to .h5, .jld2, .csv, .npy, .npz, .json or .fits (the last after using FITSIO). The file holds plain arrays that Python, IDL or a spreadsheet read directly. The tutorial Exporting Data shows each format and how to read it in Python.
Mera.exportdata — Function
exportdata(result, file; format=:auto, vars=nothing, source=nothing,
length_unit=:standard, sidecar=true, anonymize=false, note="",
include_script=false, verbose=true) -> StringWrite a Mera result to a file that other tools read, and a sidecar <file>.meta.json that records what it holds and where it came from.
Use it to publish the data behind a figure, or to continue in Python, IDL or a spreadsheet. The file holds plain arrays; the sidecar holds the provenance, the units and the environment that ran (the Reproducibility page explains it). To keep a result for Mera itself, use savemap or savedata instead: they round-trip the full object.
Arguments
result: what to write.- a projection from
projection: every map, plus the pixel centresxandy; - a
profile,phaseorpdfresult; - a
timeseriestable; - a movie from
getmovie: the frames as a cube, plusoutputsandtimes; - an array, a number, or a NamedTuple of arrays, e.g.
getvarcolumns. Passsourceso the sidecar knows which snapshot they came from.
- a projection from
file::String: the file to write. Its extension selects the format.
| extension | format | holds |
|---|---|---|
.jld2 | JLD2 (HDF5 container) | all arrays, readable with h5py |
.h5, .hdf5 | HDF5 | all arrays, each with a unit attribute |
.csv | CSV | a table: one row per pixel of a map or phase diagram, or per bin of a profile |
.npy | NumPy | exactly one array |
.npz | NumPy archive | all arrays |
.json | JSON | all arrays, for small results (at most 10⁶ values) |
.fits | FITS | one image per array, maps with a linear WCS; needs using FITSIO |
Keywords
format::Symbol = :auto: the format,:jld2,:hdf5,:csv,:npy,:npz,:jsonor:fits;:autotakes it from the extension.vars = nothing: write only these arrays, e.g.vars=:sdorvars=[:mean, :median]. The coordinates (pixel centres, bin edges) are always kept.source = nothing: the data object orInfoTypethe result was computed from. Needed for arrays, numbers and timeseries tables, which do not carry it; a map, profile, phase or pdf carries it already.length_unit::Symbol = :standard: the unit of a map's pixel centres, extent and pixel size, e.g.:kpc.:standardkeeps code units. Maps only.sidecar::Bool = true: write<file>.meta.json. The global switchsidecaroverrides it.anonymize::Bool = false: in the sidecar, keep only the last two parts of the simulation path. The host name is never recorded.note::String = "": a free text stored in the sidecar, e.g. which figure this is.include_script::Bool = false: also store the full text of the running script (or the code cells of the notebook) in the sidecar. Its name and SHA-256 are always recorded, when Julia knows the script.verbose::Bool = true: print what was written.
Python and other C-order readers see the axes of an HDF5 or JLD2 array reversed (a Julia nx × ny map has shape (ny, nx) in h5py). NumPy files are written in Fortran order, so there a[i, j] is A[i+1, j+1]. The sidecar states the layout of each file.
Returns
The path of the data file, as a String.
Examples
p = projection(gas, [:sd, :T], [:Msol_pc2, :K])
exportdata(p, "fig3.h5"; length_unit=:kpc) # + fig3.h5.meta.json
exportdata(p, "fig3_sd.npy"; vars=:sd) # one map for numpy
exportdata(p, "fig3.csv"; length_unit=:kpc) # x, y, sd, T per pixel
prof = profile(gas, :r_cylinder, :rho; xunit=:kpc, unit=:nH)
exportdata(prof, "fig4.csv"; note="Figure 4, radial density")
exportdata((rho=getvar(gas, :rho, :nH), T=getvar(gas, :T, :K)), "cells.npz"; source=gas)
using FITSIO
exportdata(p, "fig3.fits"; length_unit=:kpc)See also savemap, savedata, provenance, export_vtk.
Next to every saved or exported file Mera writes a sidecar, <file>.meta.json: what the file holds and in which units, the SHA-256 of the file, the provenance of the snapshot, the SHA-256 of the run's namelist.txt, makefile.txt, patches.txt and compilation.txt, the Julia, Mera, CPU and thread count that ran, and the analysis around it: the SHA-256 of your Project.toml and Manifest.toml and of the script that ran. It is JSON, so any language reads it. The host name is never recorded. sidecar=false on a call, or sidecar(false) for the whole session, turns it off; so does the environment variable MERA_SIDECAR=0, without changing a script. The first sidecar of a session prints one line saying what the new file is. Mera also says once when the sidecar cannot pin down what ran: in the shared environment the recorded Manifest.toml changes with every package you add, and in a Mera checkout with uncommitted changes the recorded commit is not the code that ran.
A figure is saved by the plotting package, so Mera does not see it: call writesidecar right after the save to give it the same record, taken from the results it shows. save_clumps writes a sidecar too; pass source= to record the snapshot.
readsidecar prints one sidecar and checks that its data file still matches the recorded SHA-256; sidecaroverview lists every sidecar in a folder. The tutorial Sharing results shows them on a real simulation.
Before publishing, bundle joins the sidecars of an analysis folder into one RO-Crate record, ro-crate-metadata.json, with a software.bib to cite. meraproject starts a new analysis folder with its own environment, so the sidecars record exactly the packages that ran.
Mera.writesidecar — Function
writesidecar(file, source=nothing; note="", anonymize=false, include_script=false, verbose=true)Write the sidecar <file>.meta.json for a file that Mera did not write itself, typically a figure saved with Makie, PyPlot or Plots. The sidecar is the same as for exportdata: the SHA-256 of the file, the provenance of the snapshot, the input files of the run, the analysis environment and script, and the Julia and Mera that ran.
Call it right after the save:
save("fig3.png", fig) # Makie
writesidecar("fig3.png", p) # p: the projection shown in the figureArguments
file::String: an existing file.source: the Mera result the file shows (a projection, profile, data object, movie orInfoType), or a vector of them for a figure with several panels. Withnothingthe sidecar still records the file, the analysis and the environment, but no snapshot.
Keywords
note::String = "": a free text stored in the sidecar, e.g. "Figure 3 of the paper".anonymize::Bool = false: keep only the last two parts of the simulation path.include_script::Bool = false: also store the full text of the running script (or the code cells of the notebook). Its name and SHA-256 are always recorded, when Julia knows the script.verbose::Bool = true: print the sidecar's path.
Returns
The sidecar's path as a String, or nothing when sidecars are switched off with sidecar(false) or the sidecar could not be written (a warning says why). An existing sidecar of the file is replaced.
Examples
writesidecar("fig3.png", p; note="Figure 3")
writesidecar("evolution.pdf", [p10, p20, p30]) # one panel per snapshot
readsidecar("fig3.png") # read it backSee also readsidecar, sidecaroverview, exportdata.
Mera.readsidecar — Function
readsidecar(file; verify=true) -> SidecarRecordRead the sidecar of a file written by savedata, savemap, savemovie, save_clumps, exportdata or writesidecar, and print a short summary in the REPL.
Arguments
file::String: the data file (fig3.h5) or its sidecar (fig3.h5.meta.json).
Keywords
verify::Bool = true: compare the data file with the SHA-256 in the sidecar, sostatussays whether it changed since it was written. Reading a large Mera file takes a few seconds per GB;verify=falseskips it.
Returns
A SidecarRecord; r.data holds the whole record, e.g. r.data["source"]["output"].
Examples
r = readsidecar("fig3.h5") # prints what fig3.h5 holds and where it came from
r.status # :unchanged, :changed or :missing
r.data["environment"]["julia_version"]See also sidecaroverview, writesidecar, exportdata, sidecar.
Mera.sidecaroverview — Function
sidecaroverview(dir="."; recursive=false, verify=false, verbose=true) -> Vector{SidecarRecord}List every sidecar (*.meta.json) in a folder as a table: the file, what it holds, the snapshot it came from, when it was written, and whether the data file is still there.
Arguments
dir::String = ".": the folder to look in.
Keywords
recursive::Bool = false: also look in subfolders.verify::Bool = false: compare every data file with its recorded SHA-256 (slow for large files); the status column then saysunchangedorchanged.verbose::Bool = true: print the table.
Returns
A Vector of SidecarRecord, sorted by file name.
Examples
sidecaroverview("results/") # one line per saved or exported file
recs = sidecaroverview("results/"; verify=true, verbose=false)
filter(r -> r.status === :changed, recs) # files edited after they were writtenSee also readsidecar, exportdata.
Mera.bundle — Function
bundle(dir="."; title=nothing, description=nothing, creators=nothing, license=nothing,
keywords=String[], simulation=nothing, recursive=true, verify=true, verbose=true) -> StringDescribe a finished analysis folder in one record, ready to publish, for example on Zenodo. bundle reads the sidecars in the folder and writes three files into it:
ro-crate-metadata.json: an RO-Crate that lists every file with its size, type and SHA-256, and for each file written by Mera what made it: the Mera version, the script and the snapshot, from its sidecar;software.bib: the BibTeX fromcitation;simulation.json: thesimulationrecord, whensimulationis given.
Nothing is copied, so the folder needs no extra disk space. Running it again replaces the three files.
Arguments
dir::String = ".": the analysis folder.
Keywords
title,description,creators,license,keywords: who made the analysis and under which license, as fordatacite:creatorsas"Family, Given"or(name=…, orcid=…, affiliation=…),licenseas an SPDX identifier such as"CC-BY-4.0". Missing ones are read from ananalysis.tomlin the folder (the same fields assimulation.toml, seemeraproject); the title falls back to the folder name.simulation = nothing: the simulation the analysis used: a folder, anInfoTypeor aSimulationRecord. Its record is written tosimulation.json.recursive::Bool = true: include subfolders. Hidden files and folders are left out.verify::Bool = true: check each file against the SHA-256 in its sidecar, and warn about files that changed after they were written.verbose::Bool = true: print a summary.
Returns
The path of ro-crate-metadata.json.
Examples
bundle("galaxy_paper"; simulation="/data/mw_L10",
creators=["Behrendt, Manuel"], license="CC-BY-4.0")See also meraproject, sidecaroverview, citation, datacite.
Mera.meraproject — Function
meraproject(dir; title=nothing, verbose=true) -> StringStart a new analysis folder with its own Julia environment, so every sidecar records exactly the packages that ran. It writes:
Project.toml, with Mera at the version that runs now;analysis.jl, a first script;analysis.toml, the title, authors and license of the analysis, forbundle;README.md, the few steps from the first run to publishing.
Nothing is installed and no network is needed: the first julia --project=. in the folder, followed by ] instantiate, installs Mera there.
Arguments
dir::String: the new folder. It may exist, but must not hold aProject.tomlyet.
Keywords
title::String = nothing: the title of the analysis, stored inanalysis.toml; defaults to the folder name.verbose::Bool = true: print the next steps.
Returns
The folder's path.
Examples
meraproject("galaxy_paper")
# then, in a terminal:
# cd galaxy_paper
# julia --project=.
# ] instantiateSee also bundle, writesidecar.
Mera.SidecarRecord — Type
SidecarRecordWhat readsidecar and sidecaroverview return for one sidecar: file (the data file), sidecar (the .meta.json), data (the parsed JSON, index it like a dictionary, e.g. r.data["source"]["output"]) and status: :unchanged or :changed when the file's SHA-256 was checked, :missing when the data file is gone, :unchecked otherwise.
Mera.SimulationRecord — Type
SimulationRecordWhat simulationrecord returns: data, the record as an ordered dictionary (index it directly, e.g. rec["resolution"]["levelmax"]), and path, the simulation folder. It prints a short summary in the REPL. Write it as JSON with writesimulationrecord, or turn it into DataCite metadata with datacite.
Conversion
Mera.convertdata — Function
Converts full simulation data into a compressed/uncompressed JLD2 format:
This function provides a comprehensive data conversion workflow for RAMSES simulation data, converting multiple data types into compressed JLD2 format with full benchmarking and threading control capabilities.
Features:
- Multi-datatype support: Handles :hydro, :particles, :gravity, :clumps, :rt, :sinks data types
- Threading control: Configurable threading for performance optimization (excluding clumps)
- Compression options: Multiple compression algorithms with automatic selection
- Spatial filtering: Select specific data ranges with flexible unit support
- Benchmarking: Comprehensive timing and performance statistics storage
- Progress tracking: Optional progress bars and verbose output modes
- Memory management: Automatic memory cleanup and usage tracking
Data Processing Workflow:
- Configuration: Parse arguments and setup threading/compression parameters
- Data Loading: Sequential loading of requested datatypes with optional threading
- Data Writing: Compressed storage to JLD2 format with timing measurements
- Statistics: Comprehensive benchmark and threading information storage
function convertdata(output::Int; datatypes::Array{<:Any,1}=[missing], path::String="./", fpath::String="./", fname = "output", compress::Any=nothing, comments::Any=nothing, lmax::Union{Int, Missing}=missing, xrange::Array{<:Any,1}=[missing, missing], yrange::Array{<:Any,1}=[missing, missing], zrange::Array{<:Any,1}=[missing, missing], center::CenterType=[0., 0., 0.], rangeunit::Symbol=:standard, smallr::Real=0., smallc::Real=0., verbose::Bool=true, showprogress::Bool=true, maxthreads::Int=Threads.nthreads(), myargs::ArgumentsType=ArgumentsType() )
return statistics_dictionary
Arguments
Required:
output: RAMSES output number to convert
Optional Keywords:
datatypes: Array of datatypes to convert.- Default:
[missing]→ converts all available data (:hydro, :gravity, :particles, :clumps, :rt, :sinks) - Examples:
[:hydro, :particles],[:hydro],:particles
- Default:
path: Path to RAMSES simulation folders (default:"./").fpath: Output path for JLD2 files (default:"./")fname: Base filename for output files (default:"output_")- Final filename:
fname + output_number + ".jld2"
- Final filename:
compress: Compression settings- Default:
nothing→ automatic LZ4 compression - Options:
false(no compression),LZ4FrameCompressor(),Bzip2Compressor(),ZlibCompressor() - Requires: CodecZlib, CodecBzip2, or CodecLz4 packages for specific compressors
- Default:
comments: String description of the simulation (stored in file metadata)lmax: Maximum AMR level to process- Default:
missing→ uses all available levels - Limits data processing to specified refinement level
- Default:
xrange, yrange, zrange: Spatial selection ranges[min, max]- Default:
[missing, missing]→ full simulation box - Units specified by
range_unit, relative tocenter - Zero-length ranges (min=max=0) converted to maximum extent
- Default:
center: Coordinate center for spatial ranges- Default:
[0., 0., 0.]→ simulation origin - Special values:
[:bc],[:boxcenter]→ box center - Mixed:
[value, :bc, :bc]→ custom center per axis
- Default:
range_unit: Units for spatial ranges and center- Options:
:standard(code units),:Mpc,:kpc,:pc,:mpc,:ly,:au,:km,:cm - See
viewfields(info.scale)for available unit conversions
- Options:
smallr: Lower density threshold (0 = inactive)smallc: Lower thermal pressure threshold (0 = inactive)max_threads: Threading control for data loading operations- Default:
Threads.nthreads()→ uses all available Julia threads - Applied to: :hydro, :gravity, :particles data loading
- NOT applied to: :clumps and :sinks data (single-threaded)
- Examples:
max_threads=4(limit to 4 threads),max_threads=1(single-threaded)
- Default:
verbose: Enable detailed console output (default:true)show_progress: Enable progress bars during data loading (default:true)myargs: Pre-configured ArgumentsType struct to override multiple parameters
Return Value:
Returns a comprehensive statistics dictionary containing:
TimerOutputs: Detailed timing for reading/writing operationsthreading: Threading configuration and system informationbenchmark: Performance metrics, compression ratios, processing timesviewdata: Metadata about the converted datasetsize: Memory usage and file size information
Method Overloads:
convertdata(output::Int64; ...)→ Full parameter interfaceconvertdata(output::Int64, datatypes::Vector{Symbol}; ...)→ Direct datatype specificationconvertdata(output::Int64, datatypes::Symbol; ...)→ Single datatype conversion
Threading Behavior:
- Threaded operations: File-level parallelism for :hydro, :gravity, :particles
- Single-threaded: :clumps and :sinks data processing (threading not beneficial)
- Thread safety: All operations use thread-safe file I/O and memory management
- Performance: Optimal threading automatically balances CPU files across threads
Usage Examples:
Convert all datatypes with default settings and available threads
stats = convertdata(42, path, fpath)
Convert specific datatypes with threading control
stats = convertdata(42, [:hydro, :particles], path="source/folder", fpath="export/folder", max_threads=4)
Spatial selection with different compression
stats = convertdata(42, xrange=[-10, 10], yrange=[-10, 10], rangeunit=:Mpc, compress=Bzip2Compressor(), maxthreads=8)
Access performance statistics println("Total time: ", stats["benchmark"]["totalprocessingtimeseconds"]) println("Compression ratio: ", stats["benchmark"]["compressionratio"]) println("Threads used: ", stats["threading"]["effective_threads"])
Mera.batch_convert_mera — Function
batch_convert_mera(input_dir::String, output_dir::String,
start_output::Int, end_output::Int;
requested_threads::Int=Threads.nthreads(),
safety_margin::Float64=DEFAULT_SAFETY_MARGIN,
min_threads::Int=DEFAULT_MIN_THREADS,
max_threads::Int=DEFAULT_MAX_THREADS,
skip_existing::Bool=true,
show_confirmation::Bool=true,
compress=nothing) -> DictMain function for safe multithreaded batch conversion with active safety margin monitoring.
This function coordinates the entire conversion process including:
- System resource validation and safety checks
- File discovery and filtering by output number range
- Thread count optimization based on system constraints
- User confirmation and information display
- Multithreaded conversion with real-time monitoring
- Comprehensive results reporting and recommendations
Parameter Details
Required Parameters
input_dir: Source directory containing old JLD2 files with version issuesoutput_dir: Destination directory for converted files (created if doesn't exist)start_output: Starting output number for conversion range (inclusive)end_output: Ending output number for conversion range (inclusive)
Performance Tuning Parameters
requested_threads: Desired number of conversion threads (default: all available)safety_margin: Memory usage threshold as decimal 0.0-1.0 (default: 0.8 = 80%)min_threads: Minimum thread count even under resource constraints (default: 1)max_threads: Maximum thread count regardless of system capacity (default: 64)
Behavior Control Parameters
skip_existing: Skip files that already exist in output directory (default: true)show_confirmation: Display user confirmation prompt before starting (default: true)compress: Compression codec for the output files, matchingsavedata's API (default:nothing→LZ4FrameCompressor()). Passfalseto write uncompressed files, or a specific codec instance (LZ4FrameCompressor(),ZlibCompressor(),Bzip2Compressor()) for finer control.sidecar: also write<file>.meta.jsonnext to each converted file, assavedatadoes: the data types it holds, the provenance of the snapshot, the environment, and the file it was converted from (default:true). The global switchsidecaroverrides it.
Safety Margin System
The safety_margin parameter is now actively used throughout the process:
Pre-Conversion Phase
- Validates current system memory usage
- Adjusts thread recommendations based on available memory within safety limits
- Warns user if current usage already exceeds margin
During Conversion Phase
- Monitors memory usage before each file load operation
- Checks memory after data loading (peak usage point)
- Triggers automatic garbage collection on violations
- Counts total violations for reporting
Post-Conversion Phase
- Reports final memory state and violation statistics
- Provides recommendations for future conversions based on violation patterns
Return Value
Returns comprehensive dictionary with conversion statistics:
success: Number of files successfully convertedfailed: Number of files that failed conversionskipped: Number of files skipped (already existed)safety_violations: Number of times memory exceeded safety marginconversion_time: Total time spent in conversion (seconds)threads_used: Actual number of threads usedfinal_memory_usage_percent: Memory usage percentage at completion
Error Handling Strategy
The function handles errors gracefully:
- Individual file failures don't stop the batch
- Out-of-memory errors receive specific guidance
- System resource violations trigger automatic recovery
- All errors are logged with specific context
Example Usage
Basic conversion with default safety settings: results = batchconvertmera("/data/old", "/data/new", 100, 200)
Conservative conversion for large files: results = batchconvertmera("/data/old", "/data/new", 100, 200; requestedthreads=4, safetymargin=0.9)
High-performance conversion with monitoring: results = batchconvertmera("/data/old", "/data/new", 100, 200; requestedthreads=16, safetymargin=0.7, skip_existing=false)
Mera.interactive_mera_converter — Function
interactive_mera_converter(input_dir::String, output_dir::String;
safety_margin::Float64=DEFAULT_SAFETY_MARGIN,
min_threads::Int=DEFAULT_MIN_THREADS,
max_threads::Int=DEFAULT_MAX_THREADS)Interactive mode for file conversion with comprehensive user guidance and system information.
This function provides a user-friendly interface that:
- Displays comprehensive system information and constraints
- Analyzes available files and detects potential issues
- Guides user through range and thread count selection
- Provides intelligent recommendations based on system state
- Executes conversion with all safety monitoring features
User Experience Flow
System Information Display
- Shows CPU core count and memory configuration
- Displays current memory usage and safety margin status
- Indicates thread count limits and recommendations
- Warns about any current resource constraints
File Analysis and Validation
- Scans input directory for valid RAMSES files
- Reports total file count and available output ranges
- Detects and reports gaps in file sequences
- Helps user identify potential data integrity issues
Guided Parameter Selection
- Prompts for output number range with sensible defaults
- Recommends thread count based on system capacity and safety constraints
- Allows user override with explanation of implications
- Provides real-time feedback on selections
Safety-Monitored Execution
- Calls main conversion function with user-selected parameters
- Provides same comprehensive monitoring as batch function
- Returns complete results for user review
Parameters
input_dir: Source directory containing old JLD2 filesoutput_dir: Destination directory for converted filessafety_margin: Memory usage threshold (default: 0.8 = 80%)min_threads: Minimum thread count (default: 1)max_threads: Maximum thread count (default: 64)
Example Usage
Basic interactive mode interactivemeraconverter("/data/old", "/data/new")
Conservative interactive mode for large files interactivemeraconverter("/data/old", "/data/new"; safetymargin=0.9, maxthreads=8)
To write a plain-text or binary export instead of Mera's own format, see Export/Import data.
I/O tuning
Reading large outputs is usually I/O bound, so Mera exposes its buffer and cache settings. Most users never need these, optimize_mera_io picks settings for a given simulation and is the one entry point worth knowing.
Mera.optimize_mera_io — Function
optimize_mera_io(simulation_path::String, output_num::Int; benchmark=false, quiet=false)Automatically optimize Mera I/O settings based on your simulation characteristics.
This is the easiest way to get optimal performance - just provide your simulation path and output number, and Mera will analyze your data and apply the best settings.
Arguments
simulation_path: Path to your RAMSES simulation directoryoutput_num: Output number to analyze (e.g., 300)benchmark=false: Set totrueto run performance benchmarks for fine-tuningquiet=false: Set totrueto suppress output messages
Returns
trueif optimization was successful,falseotherwise
Examples
# Basic automatic optimization
optimize_mera_io("/Volumes/Storage/Simulations/mw_L10", 300)
# With benchmarking for maximum performance
optimize_mera_io("/Volumes/Storage/Simulations/mw_L10", 300, benchmark=true)
# Quiet mode for scripts
optimize_mera_io("/path/to/sim", 300, quiet=true)What it does
- Analyzes your simulation (file count, sizes, AMR structure)
- Recommends optimal buffer size based on simulation characteristics
- Enables file metadata caching for faster repeat operations
- Optionally benchmarks different settings to find the absolute best performance
Simulation size recommendations
- Small (< 50 files): 32KB buffer
- Medium (50-200 files): 64KB buffer
- Large (200-500 files): 128KB buffer
- Very large (500-1000 files): 256KB buffer
- Huge (> 1000 files): 512KB buffer
Mera.configure_mera_io — Function
configure_mera_io(; buffer_size="auto", cache=true, large_buffers=true, show_config=true)Manually configure Mera I/O settings with user-friendly parameters.
Arguments
buffer_size: Buffer size as string ("32KB", "64KB", "128KB", "256KB", "512KB") or "auto"cache=true: Enable file metadata caching for faster repeat operationslarge_buffers=true: Enable large buffer optimizationsshow_config=true: Display the applied configuration
Examples
# Use 128KB buffer with caching
configure_mera_io(buffer_size="128KB")
# Disable caching
configure_mera_io(buffer_size="64KB", cache=false)
# Maximum performance for very large simulations
configure_mera_io(buffer_size="512KB", cache=true, large_buffers=true)
# Minimal settings for small simulations
configure_mera_io(buffer_size="32KB", large_buffers=false)Buffer size recommendations
"32KB": Small simulations (< 50 CPU files)"64KB": Medium simulations (50-200 CPU files) - Default"128KB": Large simulations (200-500 CPU files)"256KB": Very large simulations (500-1000 CPU files)"512KB": Huge simulations (> 1000 CPU files)
Returns true.
Mera.show_mera_config — Function
show_mera_config()Display current Mera I/O configuration settings.
Shows buffer size, caching status, and performance-related settings in a user-friendly format.
Example
julia> show_mera_config()
🔧 MERA I/O CONFIGURATION
========================
Buffer size: 128KB (131072 bytes)
File caching: Enabled ✅
Large buffers: Enabled ✅
Cache entries: 3 files cached
Status: Optimized for large simulationsReturns nothing.
Mera.reset_mera_io — Function
reset_mera_io()Reset Mera I/O settings to default values.
This clears any custom buffer sizes, disables optimizations, and clears the cache. Useful if you want to start fresh or if you're experiencing issues.
Example
julia> reset_mera_io()
🔄 MERA I/O RESET
=================
✅ Buffer size reset to 64KB (default)
✅ File caching enabled (default)
✅ Cache cleared (0 entries removed)
✅ Settings reset to defaultsReturns nothing.
Mera.mera_io_status — Function
mera_io_status()Quick status check of Mera I/O configuration and performance.
Returns a summary of current settings and cache performance in a compact format.
Example
julia> mera_io_status()
"I/O: 128KB buffer, cache enabled (5 files), optimized ✅"Mera.benchmark_mera_io — Function
benchmark_mera_io(simulation_path::String, output_num::Int;
test_sizes=["32KB", "64KB", "128KB", "256KB"])Benchmark different I/O configurations to find optimal settings for your specific simulation.
This function tests various buffer sizes with your actual data to determine which configuration gives the best performance on your system.
Arguments
simulation_path: Path to your RAMSES simulation directoryoutput_num: Output number to test withtest_sizes: Array of buffer sizes to test (as strings)
Returns
- Dictionary with benchmark results and recommended optimal settings
Example
# Standard benchmark
results = benchmark_mera_io("/path/to/simulation", 300)
# Custom buffer sizes to test
results = benchmark_mera_io("/path/to/simulation", 300,
test_sizes=["64KB", "128KB", "256KB", "512KB"])
# Access results
optimal_buffer = results["optimal_buffer_size"]
performance_gain = results["performance_improvement"]What it does
- Tests each buffer size with your actual simulation data
- Measures getinfo() and gethydro() performance
- Identifies the optimal buffer size for your system
- Automatically applies the best settings
- Returns detailed performance comparison
Automatic tuning
These let Mera choose and re-choose settings as it sees a simulation, rather than fixing them once.
Mera.smart_io_setup — Function
smart_io_setup(simulation_path::String, output_num::Int; benchmark=false, verbose=true)Intelligent I/O setup that combines analysis and optional benchmarking.
Returns true when the automatic analysis worked and the settings were applied, false otherwise.
Mera.configure_adaptive_io — Function
configure_adaptive_io(simulation_path::String, output_num::Int; verbose=true)Automatically configure I/O settings based on simulation characteristics.
Returns true when the settings were applied, false when the simulation could not be analysed and the defaults are kept.
Mera.ensure_optimal_io! — Function
ensure_optimal_io!(info::InfoType; force_reoptimize=false, verbose=false)Automatically ensures optimal I/O settings based on simulation characteristics. This function is called transparently by gethydro(), getparticles(), and getgravity().
Arguments
info: InfoType object from getinfo()force_reoptimize=false: Force re-optimization even if already optimizedverbose=false: Enable detailed output (usually disabled for transparent operation)
Returns
trueif optimization was applied/verified,falseif failed
Mera.reset_auto_optimization! — Function
reset_auto_optimization!()Reset the automatic optimization state, forcing re-optimization on next data load.
Returns nothing.
Mera.show_auto_optimization_status — Function
show_auto_optimization_status()Display the current status of automatic I/O optimization.
Returns nothing.
Measurement & cache
Mera.benchmark_buffer_sizes — Function
benchmark_buffer_sizes(simulation_path::String, output_num::Int;
test_sizes=[32768, 65536, 131072, 262144], verbose=true)Benchmark different buffer sizes to find the optimal setting for this specific simulation.
Returns a Dict with "optimal_buffer", "optimal_time" and "all_results", or nothing when no buffer size could be timed.
Mera.get_simulation_characteristics — Function
get_simulation_characteristics(simulation_path::String, output_num::Int)Analyze simulation folder to determine optimal I/O settings. Returns a dictionary with simulation characteristics and recommended settings.
Mera.show_mera_cache_stats — Function
show_mera_cache_stats()Print what the simulation-metadata cache currently holds: the number of entries and the path behind each one.
Use it to check whether a getinfo call was served from cache before reaching for clear_mera_cache!.
Returns nothing.
Mera.clear_mera_cache! — Function
clear_mera_cache!()Empty the cache of simulation metadata that Mera keeps between getinfo calls, and report how many entries were dropped.
Useful when a simulation folder changed on disk during a session and you want the next getinfo to re-read it rather than reuse what it saw earlier. See show_mera_cache_stats to inspect the cache first.
Returns nothing.
Every docstring in the package is also on the Complete API Reference.