=============== LIBRARY RULES =============== From library maintainers: - Always pass a unit: getvar(gas, :T, :K), msum(gas, :Msol), projection(gas, :sd, :Msol_pc2). Without a unit the values are in code units. - Load RAMSES data with info = getinfo(400, path), then gethydro(info), getparticles(info), getgravity(info), getclumps(info) or getsinks(info). loadall(path, 400; components=[:hydro, :particles]) reads RAMSES folders and Mera files alike. - Limit a read while loading with xrange, yrange, zrange together with center=[:bc] and range_unit=:kpc, instead of trimming afterwards. - Regions are values built with the lowercase constructors sphere, cuboid, cylinder, sphericalshell and cylindricalshell. Combine them with ∩ ∪ \ ! (ASCII: &, |, setdiff, !) and apply them with subregion(obj, region). - Select by value with filterdata(obj, Above(:T, 1e4, unit=:K)); Below and InRange work the same way and combine with & | !. - In projection use pxsize=[value, :unit] rather than res. - savedata writes nothing without :write or :append. Reload with loaddata; for a folder of Mera files use infodata, not getinfo. - The current release is Mera 1.11.3 (pkg> add Mera); version numbers in docstring examples are illustrations. - The registered release reads RAMSES only; RAMSES particles have no temperature. Readers for GADGET/AREPO, PLUTO, Athena++, FLASH, Chombo and AMReX/Quokka are in development on the multicode branch. - The compact grounding for assistants is https://manuelbehrendt.github.io/Mera.jl/stable/llms.txt ### Activate and instantiate the recipe environment Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/gallery/001_coin_flip_movie.md Activates the local Project.toml and Manifest.toml and installs the exact package versions on first run. Use this at the start of the notebook to ensure reproducibility. ```julia using Pkg Pkg.activate(@__DIR__) # the Project.toml and Manifest.toml next to this notebook Pkg.instantiate() # first run only: fetches exactly those versions ``` -------------------------------- ### Setup test data and quicklook function Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/test_simulations.md Sets up the example data root via MERA_EXAMPLES or download_testdata(), activates CairoMakie, and defines a helper that runs quicklook while timing it. The TIMES array collects name, elapsed seconds, and cell count for the table at the end of the page. ```julia # Example-data root. Point this at your own copy, or set the MERA_EXAMPLES environment variable. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); TESTDATA = joinpath(MERA_EXAMPLES, "RAMSES-PUBLIC") # or: TESTDATA = download_testdata() using Mera, CairoMakie CairoMakie.activate!() sim(name) = joinpath(TESTDATA, name) # quicklook, noting how long it took for the table at the end of the page TIMES = Tuple{String,Float64,Int}[] function look(output, name) t = @elapsed q = quicklook(output; path=sim(name)) push!(TIMES, (name, t, q.summary.ncells)); q end; ``` -------------------------------- ### Setup: load data and define view and show_image! Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/17_multi_Volume_Rendering.md Sets up example data paths via MERA_EXAMPLES, loads a RAMSES simulation with Mera and CairoMakie, defines a 32x32x12 kpc view at 70 degrees inclination, and creates a coarser panel view by changing pxsize. Defines show_image! to display the rendered image with axes. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); using Mera, CairoMakie CairoMakie.activate!() info = getinfo(300, joinpath(MERA_EXAMPLES, "RAMSES/mw_L10"), verbose=false) gas = gethydro(info, verbose=false, show_progress=false) # a 32 × 32 × 12 kpc box, seen at 70 degrees from the spin axis view = (inclination=70, axis=:angmom, center=[:bc], range_unit=:kpc, xrange=[-16, 16], yrange=[-16, 16], zrange=[-6, 6], pxsize=[30, :pc], verbose=false) panel = Base.setindex(view, [60, :pc], :pxsize) # the same view, coarser, for comparison grids function show_image!(pos, m; title="") x0, x1, y0, y1 = getextent(m, :kpc) ax = Axis(pos, title=title, xlabel="x [kpc]", ylabel="y [kpc]", aspect=DataAspect()) image!(ax, x0..x1, y0..y1, m.image) # the image is indexed [ix, iy], like a map return ax end ``` -------------------------------- ### Example setup: getinfo, gethydro, projection, exportdata Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/export_sidecars.md Sets up example data from MERA_EXAMPLES or a default path, loads gas data, creates a projection map, and exports it as HDF5 and CSV. All files go to a fresh temporary folder via cd(mktempdir()). The exportdata calls include length_unit=:kpc and a note for the HDF5 file. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); using Mera info = getinfo(300, joinpath(MERA_EXAMPLES, "RAMSES/mw_L10"), verbose=false) gas = gethydro(info, verbose=false, show_progress=false); # All files of this page go to a fresh folder, and the page works inside it. # In your own work this is a folder next to your script, e.g. "results/". cd(mktempdir()) # A map and two exported files to work with; Exporting Data explains the formats. m = projection(gas, [:sd, :T], [:Msol_pc2, :K]; pxsize=[100., :pc], verbose=false, show_progress=false) exportdata(m, "fig3_maps.h5"; length_unit=:kpc, note="Figure 3: gas surface density and temperature") exportdata(m, "fig3_maps.csv"; length_unit=:kpc, verbose=false) ``` -------------------------------- ### Zulip bot credentials configuration Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/notifications/setup_and_usage.md Example [zulip] section using a bot's credentials. The server must include the https:// scheme; a bare domain fails to connect. ```toml [zulip] bot_email = "mera-bot@yourlab.zulipchat.com" api_key = "abcd1234…" server = "https://yourlab.zulipchat.com" ``` -------------------------------- ### notifyme() basic usage examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/notifications/setup_and_usage.md Sends a notification with a message. Default message is "done!". Supports positional or keyword message, and optional Zulip channel and topic parameters. ```julia notifyme() # default message "done!" notifyme("Calculation finished!") # positional message notifyme(msg="Calculation finished!") # keyword form (equivalent) # Choose the Zulip channel and topic notifyme(msg="Run finished!", zulip_channel="alerts", zulip_topic="Run Status") ``` -------------------------------- ### Load Mera example data and get info for provenance Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/provenance.md Sets the example-data root from the MERA_EXAMPLES environment variable or a default path, then loads Mera and retrieves info for a RAMSES simulation. The gas data is read quietly by disabling verbose and progress output. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); using Mera info = getinfo(300, joinpath(MERA_EXAMPLES, "RAMSES/mw_L10")) # The loading messages add nothing on this page, so the data reads below are quiet. gas = gethydro(info, verbose=false, show_progress=false); ``` -------------------------------- ### bell() sound selection examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/notifications/setup_and_usage.md Plays a bundled sound when a long calculation finishes. No configuration needed. Accepts a Symbol, String, or number; bell(:list) prints the numbered catalogue of 19 bundled sounds. On headless machines it warns instead of erroring. ```julia bell() # default sound (the original Mera :strum) bell(:gong) # pick a sound by name (Symbol or String) bell("chime") bell(14) # …or by number, as shown by bell(:list) bell(:list) # print the numbered catalogue of bundled sounds ``` -------------------------------- ### checksimulations usage examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Two usage examples: scan every run under a folder, or restrict to a named subfolder with filternames. ```julia checksimulations("/data/simulations") # every run under the folder checksimulations("/data", filternames=["mw_L10"]) # just one ``` -------------------------------- ### meraproject example usage Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example call to meraproject with a folder name, followed by terminal commands to install Mera in the new environment. The function returns the folder's path. ```julia meraproject("galaxy_paper") # then, in a terminal: # cd galaxy_paper # julia --project=. # ] instantiate ``` -------------------------------- ### Get hydro data with getinfo and gethydro Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/04_multi_Basic_Calculations.md Loads hydro data from a RAMSES example directory and extracts density and velocity fields. Requires the MERA_EXAMPLES environment variable to point to the examples directory. ```julia info = getinfo(1, "$MERA_EXAMPLES/RAMSES/manu_stable_2019", verbose=false); gas = gethydro(info, [:rho, :vx, :vy, :vz], verbose=false); ``` -------------------------------- ### provenance_string output examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example output strings from `provenance_string`. The version names the build: plain version on normal install, branch/commit and uncommitted marker on git checkout. Set `MERA_PROVENANCE_PLAIN=1` to force the plain version. ```julia Mera v1.8.0 | mw_L10/output_00300 | 445.89 Myr | L=48.0 ndim=3 lmin=6 lmax=10 | ScalesType003 Mera v1.8.0 (dev master @ 3a91f2c +uncommitted) | mw_L10/output_00300 | 445.89 Myr | ... ``` -------------------------------- ### Set up example data paths and temporary output directory Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/07_1_multi_Mera_Files_Converter.md Configures the example-data root from the MERA_EXAMPLES environment variable or a default path, loads Mera, and creates a temporary directory for all .jld2 output. Every file written by the notebook goes to this temporary directory to avoid polluting the repo. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); using Mera run = joinpath(MERA_EXAMPLES, "RAMSES/timeseries_sedov3d") # RAMSES outputs output_00001 … output_00013 jld_dir = mktempdir() # all .jld2 output goes here ``` -------------------------------- ### Create a ReportPlan with projection and phase cards Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/first_look.md Builds a report plan with a projection card and a phase card, then previews it. `preview` prints the plan's actions and expected cost, estimated from a model with per-file cost scaled by CPU domain count. ```julia plan = ReportPlan(output; path=path, cards = [ProjectionCard(:hydro, :sd; unit=:Msol_pc2, direction=:z), PhaseCard(:hydro, :rho, :T; weight=:mass, xunit=:nH, yunit=:K)]) preview(plan) ``` -------------------------------- ### getparticles usage examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example workflow: get output info, load all particles, load selected variables, inspect columns, load a slab without stars, and compute stellar ages. The `getvar` call uses the loaded particle table. ```julia julia> info = getinfo(300, "path/to/simulation"); julia> part = getparticles(info); # every variable, the whole box julia> part = getparticles(info, [:mass, :birth]); # two variables julia> propertynames(part.data.columns) (:level, :x, :y, :z, :id, :family, :tag, :mass, :birth) julia> dm = getparticles(info; stars=false, xrange=[-10, 10], yrange=[-10, 10], zrange=[-2, 2], center=[:bc], range_unit=:kpc); # no stars, a slab julia> getvar(part, :age, :Myr) # stellar ages ``` -------------------------------- ### Start Julia with multiple threads Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/troubleshooting.md Threads are set when Julia starts, not from inside a session. Use the -t flag or the JULIA_NUM_THREADS environment variable. ```bash julia -t 8 # or export JULIA_NUM_THREADS=8 ``` -------------------------------- ### meraproject function signature Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Signature for the meraproject function that starts a new analysis folder with its own Julia environment. It writes Project.toml, analysis.jl, analysis.toml, and README.md. Nothing is installed and no network is needed; the first julia --project=. followed by ] instantiate installs Mera there. ```julia meraproject(dir; title=nothing, verbose=true) -> String ``` -------------------------------- ### Full quickstart workflow: load, project, plot Source: https://github.com/manuelbehrendt/mera.jl/blob/master/README.md Reads simulation metadata, loads gas in a physical sub-box with multi-threading, computes a mass-conserving surface-density projection, and plots it with CairoMakie. Uses getinfo, gethydro, projection, and heatmap. ```julia using Mera # 1. read simulation metadata info = getinfo(output=100, path="/path/to/ramses/output") # 2. load gas (multi-threaded), restricted to a physical sub-box about the box centre gas = gethydro(info, lmax=10, xrange=[-10., 10.], yrange=[-10., 10.], zrange=[-5., 5.], center=[:bc], range_unit=:kpc) # 3. mass-conserving surface-density projection proj = projection(gas, :sd, :Msol_pc2; direction=:z, pxsize=[10., :pc]) # 4. plot with your favourite backend using CairoMakie heatmap(log10.(proj.maps[:sd]), colormap=:inferno) ``` -------------------------------- ### Get provenance from cosmological simulation info Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/provenance.md Reads provenance metadata from a cosmological test simulation. The example uses getinfo with verbose=false and then provenance(cinfo). ```julia cinfo = getinfo(80, joinpath(MERA_EXAMPLES, "RAMSES/yt_cosmo"), verbose=false) pc = provenance(cinfo) ``` -------------------------------- ### mera_config_example() Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/llms.txt Prints a template for the configuration file. ```APIDOC ## mera_config_example() ### Description Prints a template for the configuration file. ### Method Function call ``` -------------------------------- ### Set up Mera and define simulation path Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/first_look.md Loads Mera and sets the simulation path using the MERA_EXAMPLES environment variable, falling back to a default path. The output variable is set to 300 for the example run. ```julia using Mera MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests") path = "$MERA_EXAMPLES/RAMSES/mw_L10" output = 300; ``` -------------------------------- ### getunit usage example Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Get conversion factor and apply manually. With uname=true returns unit name alongside factor for plotting labels. ```julia getunit(info, :Msol) # grams-per-code-mass -> Msol factor rho_cgs = getvar(gas, :rho) .* getunit(info, :g_cm3) # equivalent to getvar(gas, :rho, :g_cm3) ``` -------------------------------- ### Set example data root and load simulation info Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/00_multi_FirstSteps.md Sets the MERA_EXAMPLES environment variable (or uses a default path) and loads simulation output 300 from the given path using getinfo. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); info = getinfo(300, "$MERA_EXAMPLES/RAMSES/mw_L10"); # output=300 in given path ``` -------------------------------- ### Load example data with getinfo Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/magnetic_fields.md Sets the example-data root from the MERA_EXAMPLES environment variable or a default path, then loads the RAMSES ABC flow simulation info. getinfo prints the MHD note and moves pressure to index 11. ```julia MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); using Mera info = getinfo(2, "$MERA_EXAMPLES/RAMSES-PUBLIC/ramses_abc_flow"); ``` -------------------------------- ### Get full install record with mera_install Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/provenance.md Returns a struct with fields `source` and `registered`. `source` indicates how Mera was installed (`:registry`, `:repository`, `:checkout`, `:path`). `registered` compares the code's content hash with the registry: `true` for exact release, `false` for differences or uncommitted changes, `nothing` when unknown. ```julia mi = mera_install() ``` -------------------------------- ### Add Mera package via juliapkg Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/switching_to_mera.md Install Mera once before Julia starts using juliapkg.add with the package UUID. This avoids breaking dependent packages that can occur if a package is replaced while loaded. ```python import juliapkg juliapkg.add("Mera", "02f895e8-fdb1-4346-8fe6-c721699f5126") # once ``` -------------------------------- ### Get a single photon field with getvar(rt, :Np1) Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/10_multi_RadiativeTransfer.md Returns one array per leaf cell in code units. The example also computes the minimum and maximum of the returned array. ```julia Np1 = getvar(rt, :Np1) # one photon group, code units (Np1_min = minimum(Np1), Np1_max = maximum(Np1)) ``` -------------------------------- ### Full pipeline example with ArgumentsType and withargs Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/pipelines.md Complete runnable example from the notebook: activates CairoMakie, sets up a Milky-Way simulation path, creates an ArgumentsType, derives a zoom variant, and prints both xranges. Works with any RAMSES output or converted MERA file. ```julia using Mera, CairoMakie CairoMakie.activate!() # This page runs on mw_L10 output 300, a 48 kpc Milky-Way box with 640 CPU files. # Point MW at any RAMSES output or converted MERA file of your own: every step below # works the same either way. MW = get(ENV, "MERA_MW", "/Volumes/FASTStorage/Simulations/Mera-Tests/RAMSES/mw_L10") # the selection, written once args = ArgumentsType(lmax=9, xrange=[-12., 12.], yrange=[-12., 12.], zrange=[-2., 2.], center=[:bc], range_unit=:kpc) # a variant, without touching the original zoom = withargs(args; xrange=[-4., 4.], yrange=[-4., 4.]) (args.xrange, zoom.xrange) ``` -------------------------------- ### Activate and instantiate project environment Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/gallery/005_ramses_any_rank_count.md Activates the Project.toml next to the notebook and fetches the exact package versions on first run. ```julia using Pkg Pkg.activate(@__DIR__) # the Project.toml next to this notebook Pkg.instantiate() # first run only: fetches those versions ``` -------------------------------- ### Show quicklook budget Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/first_look.md Displays the global snapshot budget: masses and the current star-formation rate. ```julia # the global snapshot budget: masses and the current star-formation rate q.budget ``` -------------------------------- ### Activate and instantiate the recipe environment Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/gallery/003_probe_through_a_galaxy.md Activates the recipe's own Project.toml and installs the pinned package versions. Run this cell first to ensure reproducibility. ```julia using Pkg Pkg.activate(@__DIR__) Pkg.instantiate() ``` -------------------------------- ### Install recommended Julia packages with Pkg.add Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/recommended_packages.md Use this snippet to install a curated set of Julia packages for astronomy and data analysis. The list includes plotting, data frames, units, FITS I/O, interpolation, distributions, FFT, cosmology, and coordinate libraries. The tip suggests starting with CairoMakie and DataFrames and adding the rest as needed. ```julia using Pkg Pkg.add([ "CairoMakie", "DataFrames", "Unitful", "UnitfulAstro", "FITSIO", "Interpolations", "Distributions", "FFTW", "Cosmology", "AstroLib", "SkyCoords", "WCS" ]) ``` -------------------------------- ### Quicklook simulation summary with quicklook Source: https://github.com/manuelbehrendt/mera.jl/blob/master/README.md Summarizes a simulation on disk as a text census covering box, refinement levels, time, redshift, particle/cell counts, component masses, SFR, and density/temperature ranges. Requires a simulation path. ```julia using Mera q = quicklook(80; path="/path/to/simulation") ``` -------------------------------- ### covering_grid usage example Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Shows the recommended workflow: first call covering_grid_memory to check size, then build the grid. The result is a CoveringGridResult that supports indexing like cg[:rho] to get the 3-D array. ```julia gas = gethydro(getinfo(output, path)) covering_grid_memory(gas, [:rho, :T]; lmax=8) # check size first cg = covering_grid(gas, [:rho, :T], [:nH, :K]; lmax=8) # then build cg[:rho] # the 3-D array ``` -------------------------------- ### Create a projection with same view and fov Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/06_offaxis_Projection.md Use `projection` with `fov` to get the same ±15 kpc camera frame as the slice example. It takes the same view keywords and uses `fov` instead of `xrange`/`yrange`. This is the particle equivalent for finite thickness (Chapter 11). ```julia # projection: same view, and `fov` is how you get the SAME ±15 kpc camera frame pr = projection(gas, :rho, :nH; view..., fov=15, fov_unit=:kpc, aperture=:square, pxsize=[0.1,:kpc], verbose=false, show_progress=false) ``` -------------------------------- ### quicklook with directions=[:z, :x] for stars Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/first_look.md Requests face-on and edge-on stellar maps. Edge-on views are returned as stars_x and stars_y. ```julia q_stars = quicklook(output; path=path, datatypes=[:stars], directions=[:z, :x], verbose=false) keys(q_stars.maps) ``` -------------------------------- ### Get provenance and build info Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/assistant.md Returns version, git branch and commit, dirty flag, snapshot, and time. mera_build() distinguishes a registry install from a checkout of a branch. pkgversion reports the same string either way, so use mera_build for shared results. ```julia provenance_string(gas) # version, git branch and commit, dirty flag, snapshot, time mera_build() # tells a registry install from a checkout of a branch ``` -------------------------------- ### Create dashboard with quicklookplot and CairoMakie Source: https://github.com/manuelbehrendt/mera.jl/blob/master/README.md Turns the quicklook result into a dashboard with mass-weighted gas surface density (face-on and two edge-on views), stellar and dark-matter surface density, and the ρ–T phase diagram. Requires a Makie backend such as CairoMakie. ```julia using CairoMakie fig = quicklookplot(q) ``` -------------------------------- ### quicklook(output; path) Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/llms.txt Draws a first look at an unknown snapshot in physical units picked for the run. ```APIDOC ## quicklook(output; path) ### Description Draws a first look at an unknown snapshot in physical units picked for the run. ### Method Function call ### Parameters - `output` - The output to look at. - `path` - The path to the output. ``` -------------------------------- ### Set up example data for exportdata Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/exporting_data.md Sets the example-data root from the MERA_EXAMPLES environment variable or a default path, loads simulation info and hydro data, and changes to a fresh temporary directory for the page's output files. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); using Mera info = getinfo(300, joinpath(MERA_EXAMPLES, "RAMSES/mw_L10"), verbose=false) gas = gethydro(info, verbose=false, show_progress=false); # All files of this page go to a fresh folder, and the page works inside it. # In your own work this is a folder next to your script, e.g. "results/". cd(mktempdir()) ``` -------------------------------- ### timerfile Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/00_multi_FirstSteps.md Retrieves performance data from simulation metadata. ```APIDOC ## timerfile ### Description Retrieves performance data from simulation metadata. ### Usage ```julia timer_info = timerfile(info) # Performance data ``` ### Parameters - `info` (InfoType) - Required - Simulation metadata object. ### Returns - `timer_info` (TimerFile) - Performance data. ``` -------------------------------- ### Quick start: bell and notifyme Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/notifications/index.md Basic usage of Mera's notification functions. bell() plays a local sound without configuration; notifyme sends an email and/or Zulip message after one-time setup in ~/.mera.toml. With no configuration, notifyme does nothing harmful. ```julia using Mera bell() # local sound when something finishes bell(:gong) # …or pick one: bell(:list) shows all 19 notifyme("Calculation finished!") # email and/or Zulip (after one-time setup) ``` -------------------------------- ### quicklook Source: https://github.com/manuelbehrendt/mera.jl/blob/master/README.md Point it at a snapshot you have never seen. Budgeted read, maps along all three axes, a phase diagram, and a census of masses, densities and temperatures. ```APIDOC ## quicklook ### Description Point it at a snapshot you have never seen. Budgeted read, maps along all three axes, a phase diagram, and a census of masses, densities and temperatures. ### Function - `quicklook` ``` -------------------------------- ### construct_datatype usage example Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Reads simulation info with `getinfo(420)`, gets hydro data with `gethydro`, filters the data table using `@filter` with a density threshold, then constructs a new `HydroDataType` comparable to the original `gas` object but only with filtered data. ```julia # read simulation information julia> info = getinfo(420) julia> gas = gethydro(info) # filter and create a new` data table julia> density = 3. /gas.scale.Msol_pc3 julia> filtered_db = @filter gas.data :rho >= density # construct a new HydroDataType # (comparable to the object "gas" but only with filtered data) julia> gas_new = construct_datatype(filtered_db, gas) ``` -------------------------------- ### Calibrate cost model with calibrate! Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/first_look.md Runs one tiny report and fits cost-model coefficients to the current disk. Default coefficients are measured on another machine, so uncalibrated estimates are only within a factor of two. ```julia calibrate!(output; path=path) ``` -------------------------------- ### Load Sedov test data and get gas info Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/checking_claims.md Starts a Julia session with Mera loaded. Downloads the Sedov blast wave test data (7 outputs, 2 MB) and retrieves the gas table for the 7th output. The units are cm, g, and s, so numbers are small. ```julia using Mera sedov = download_testdata("sedov3d_amr") # a blast wave in a periodic box, 7 outputs, 2 MB info = getinfo(7, sedov) gas = gethydro(info) # a table, one row per leaf cell ``` -------------------------------- ### loadall(path, output; components=[:hydro, :particles]) Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/llms.txt Loads all requested components from either a RAMSES output folder or a MERA file folder, dispatching automatically. Prefer this when the code should work on both. ```APIDOC ## loadall(path, output; components=[:hydro, :particles]) ### Description Loads all requested components from either a RAMSES output folder or a MERA file folder, dispatching automatically. Prefer this when the code should work on both. ### Method Function call ### Endpoint `loadall(path, output; components=[:hydro, :particles])` ### Parameters - **path** (string) - Required - Path to the simulation folder. - **output** (integer) - Required - The output number. - **components** (array of symbols) - Optional - Which components to load. Default is `[:hydro, :particles]`. ### Response Returns a named tuple with the requested components and the info object. ### Example ```julia (; hydro, particles, info) = loadall(path, 400; components=[:hydro, :particles]) ``` ``` -------------------------------- ### checkoutputs examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Two examples: look in current folder (default) and look in given path without keywords. Shows how to access returned fields N.outputs, N.miss, N.path. ```julia # Example 1: # look in current folder julia> N = checkoutputs(); julia> N.outputs julia> N.miss julia> N.path # Example 2: # look in given path # without any keyword julia>N = checkoutputs("simulation001"); ``` -------------------------------- ### Get Mera build version with mera_build Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/provenance.md Returns the version field of every record. On a normal install it is just the version; a GitHub branch adds branch and content hash; a git checkout adds branch and commit, marking uncommitted changes. Set `MERA_PROVENANCE_PLAIN=1` to force the plain version. ```julia mera_build() ``` -------------------------------- ### Set up RAMSES output, mera file, work folder, and rank counts Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/gallery/005_ramses_any_rank_count.md Defines the RAMSES run, output number, mera file, scratch folder, and rank counts. Creates work and media folders, then prints simulation info. ```julia using Mera, CairoMakie, Printf, Dates, Random # ---- the reader changes these --------------------------------------------------------- const SIM = "/data1/mabe/Simulations/MilkyWay/RAMSESFiles/heikou/L13_SN5_CD_null" # RAMSES run const OUTPUT = 201 const MERAFILES = "/data1/mabe/Simulations/MilkyWay/JLD2Files/heikou/L13_SN_CD_null" # its mera file const WORK = "/data1/mabe/Simulations/MilkyWay/RAMSESFiles/heikou/rewrite_tests_201" # scratch const RANKS = [512, 5120, 10240] # --------------------------------------------------------------------------------------- const RW = Mera.RamsesWriter # the file-format machinery, used here only to look inside mkpath(WORK); mkpath(joinpath(@__DIR__, "media")) info = getinfo(OUTPUT, SIM, verbose=false) println("ncpu = ", info.ncpu, ", levels ", info.levelmin, " to ", info.levelmax, ", time ", round(gettime(info, :Myr), digits=1), " Myr") ``` -------------------------------- ### Download public test simulations and run full data-backed tests Source: https://github.com/manuelbehrendt/mera.jl/blob/master/README.md Downloads the public test simulations (307 MB) once, then runs the full test suite. The suite finds the downloaded data by itself. ```bash julia --project -e 'using Mera; download_testdata()' ``` ```bash julia --project -e 'using Pkg; Pkg.test("Mera")' ``` -------------------------------- ### Export map to FITS and read header Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/exporting_data.md Requires the FITSIO package, which is not installed with Mera; add it once with `pkg> add FITSIO`. Exports a map as one image per variable, with the unit in BUNIT and a linear WCS in the length unit. The example then reads the header of the 'sd' image and prints selected keywords. ```julia using FITSIO exportdata(m, "fig3_maps.fits"; length_unit=:kpc) FITS("fig3_maps.fits") do f h = read_header(f["sd"]) for k in ("BUNIT", "CTYPE1", "CUNIT1", "CRVAL1", "CDELT1") println(rpad(k, 7), "= ", h[k]) end end ``` -------------------------------- ### slice usage examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Examples showing axis-aligned and off-axis usage of slice. The axis-aligned example returns a CoveringGridResult with a 2-D array, while the off-axis example returns a NamedTuple with a camera-plane map. ```julia sl = slice(gas, :rho, :nH; slice_axis=:z, slice_pos=0.5) # axis-aligned mid-plane n_H map sl[:rho] # 2-D array oa = slice(gas, :rho, :nH; inclination=60, axis=:angmom, # off-axis cutting plane xrange=[-16,16], yrange=[-16,16], range_unit=:kpc, pxsize=[0.3,:kpc]) oa.map # 2-D camera-plane array ``` -------------------------------- ### makefile Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/00_multi_FirstSteps.md Retrieves compilation information from simulation metadata. ```APIDOC ## makefile ### Description Retrieves compilation information from simulation metadata. ### Usage ```julia make_info = makefile(info) # Compilation info ``` ### Parameters - `info` (InfoType) - Required - Simulation metadata object. ### Returns - `make_info` (Makefile) - Compilation information. ``` -------------------------------- ### Load data from a sequence of snapshots Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/examples/LoadFromExistingOutputs.md Sets the example-data root from the MERA_EXAMPLES environment variable or a default path, then loops over output 300 to load simulation info. Output 301 is incomplete and not loaded. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); # mw_L10 has one complete output (300); 301 is an incomplete output for i in [300] info = getinfo(output=i, "$MERA_EXAMPLES/RAMSES/mw_L10", verbose=false) #...gethydro(info)...getparticles(info)... etc. end ``` -------------------------------- ### Compute PDFs for particles, gravity, and projected maps Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/statistics.md Shows how to compute PDFs for different data types (particles, gravity, and projected maps) using Mera.pdf. For signed fields like :vx or :epot, pass logbins=false because log bins require positive values. The projected map example uses :sd to get the column-density PDF (N-PDF), with :area weighting by default. ```julia parts = getparticles(info, verbose=false) Pp = pdf(parts, :vx; weight=:mass, logbins=false) # particle velocity PDF grav = getgravity(info, verbose=false) Pe = pdf(grav, :epot; weight=:volume, logbins=false) # potential PDF p = projection(gas, :sd; verbose=false) N = pdf(p, :sd) # area-weighted N-PDF of the map ``` -------------------------------- ### savemovie usage examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example calls for savemovie showing tag options, frame saving, and JLD2 persistence. The last example stores the MeraMovie object for later reload with loadmovie. ```julia savemovie(m, "density.gif"; tags=:time, fps=12) savemovie(m, "density.gif"; tags=(:output, :time), tag_position=:bottomright, tag_color=:yellow) savemovie(m, "density.gif"; tags=:output, tag_scale=3, save_frames="frames/") savemovie(m, "density.jld2") # persist the MeraMovie object (→ loadmovie) ``` -------------------------------- ### Load example data and gas snapshot Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/galaxyframe.md Sets the example-data root from the MERA_EXAMPLES environment variable or a default path, then loads the gas data for output 300 of the mw_L10 snapshot. Required before using center_of or face_on/edge_on. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); using Mera info = getinfo(300, joinpath(MERA_EXAMPLES, "RAMSES/mw_L10")) gas = gethydro(info); ``` -------------------------------- ### storageoverview usage example Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example calls to storageoverview with verbose=true and verbose=false. ```julia # Get storage overview for hydro data storageoverview(info, true) # Brief storage information storageoverview(info, false) ``` -------------------------------- ### mera_io_status example output Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example output of mera_io_status showing a compact summary string. ```julia julia> mera_io_status() "I/O: 128KB buffer, cache enabled (5 files), optimized ✅" ``` -------------------------------- ### Load gas, gravity, and particles from one snapshot with Mera.jl Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/15_multi_Profiles_Phase.md Sets up example data paths, loads gas, gravity, and particles from the same snapshot, and defines star and dark matter masks. Requires the MERA_EXAMPLES environment variable or a custom path; the center is set to the box center. ```julia # Example-data root. Point this at your own simulation folder, or set the # MERA_EXAMPLES environment variable; every path below is built from it. MERA_EXAMPLES = get(ENV, "MERA_EXAMPLES", "/Volumes/FASTStorage/Simulations/Mera-Tests"); using Mera, CairoMakie, Statistics # Statistics: quantile, used in §2 and §5 CairoMakie.activate!() BASE = MERA_EXAMPLES # <-- change me info = getinfo(100, joinpath(BASE,"RAMSES/spiral_clumps"), verbose=false) gas = gethydro(info, verbose=false, show_progress=false) grav = getgravity(info, lmax=gas.lmax, verbose=false, show_progress=false) parts = getparticles(info, verbose=false, show_progress=false) # SAME snapshot as the gas ctr = [:bc] # box centre; [50.,50.,50.] with range_unit=:kpc is the same point # One true/false per particle: `mask=mstars` restricts any profile to the stars, `mask=mdm` to the dark matter. mstars = getparticlemask(parts, :stars; verbose=false) mdm = getparticlemask(parts, :dm; verbose=false) ``` -------------------------------- ### reset_mera_io example output Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example output of reset_mera_io showing reset confirmation messages. ```julia 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 defaults ``` -------------------------------- ### Activate and instantiate the recipe environment Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/gallery/002_word_in_a_galaxy.md Activates the Project.toml next to this notebook and instantiates it. On first run it downloads the exact package versions the recipe was written against; later runs do nothing. ```julia using Pkg Pkg.activate(@__DIR__) # the Project.toml next to this notebook Pkg.instantiate() # first run only: fetches exactly those versions ``` -------------------------------- ### sidecaroverview usage examples Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Examples of listing sidecars, verifying them, and filtering for changed files. ```julia 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 written ``` -------------------------------- ### storageoverview Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/00_multi_FirstSteps.md Provides an analysis of storage requirements for the simulation. ```APIDOC ## storageoverview ### Description Provides an analysis of storage requirements for the simulation. ### Usage ```julia storage = storageoverview(info) # Storage analysis ``` ### Parameters - `info` (InfoType) - Required - Simulation metadata object. ### Returns - `storage` (StorageOverview) - Storage analysis result. ``` -------------------------------- ### getpositions usage example Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example call returning positions in kpc from the box centre. ```julia julia> x, y, z = getpositions(gas, :kpc; center=[:bc]); # in kpc, from the box centre ``` -------------------------------- ### Register a custom reader with register_reader! Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/adding_a_reader.md Complete example of registering a reader from an external package or script. Defines getinfo_toy and gethydro_toy, then calls register_reader! with simcodes = ["TOY"]. The fake grid is 8³ with constant density. ```julia using Mera using Mera.IndexedTables # reached through Mera, so nothing extra to install function getinfo_toy(output::Int, path::String; verbose=true, kwargs...) info = InfoType() info.simcode = "TOY"; info.output = output; info.path = path; info.ndim = 3 info.levelmin = 3; info.levelmax = 3; info.boxlen = 10.0 info.time = 0.0; info.aexp = 1.0; info.H0 = 0.0; info.omega_m = 0.0; info.omega_l = 0.0 info.unit_l = 3.086e21; info.unit_d = 1.67e-24; info.unit_t = 3.156e13 # CGS: kpc, m_p, Myr info.gamma = 5/3; info.hydro = true; info.nvarh = 1; info.variable_list = [:rho] info.descriptor = DescriptorType() createconstants!(info); createscales!(info) return info end function gethydro_toy(info::InfoType; kwargs...) n = 2^info.levelmin lv, cx, cy, cz, rho = Int[], Int[], Int[], Int[], Float64[] for i in 1:n, j in 1:n, k in 1:n push!(lv, info.levelmin); push!(cx, i); push!(cy, j); push!(cz, k); push!(rho, 1.0) end d = HydroDataType() d.data = table((level=lv, cx=cx, cy=cy, cz=cz, rho=rho); pkey=[:level, :cx, :cy, :cz]) d.info = info; d.lmin = info.levelmin; d.lmax = info.levelmax; d.boxlen = info.boxlen d.ranges = [0.,1.,0.,1.,0.,1.] d.selected_hydrovars = [1] # variable INDICES, not symbols d.used_descriptors = Dict(); d.smallr = 0.0; d.smallc = 0.0; d.scale = info.scale return d end register_reader!(:toy; simcodes = ["TOY"], name = "Toy (external package)", info = getinfo_toy, hydro = gethydro_toy) ``` -------------------------------- ### mera_install example output Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example output from `mera_install()` showing a registered release. The `registered` field compares the code's git tree hash with the registry's; `true` means exactly the registered release, `false` means differs or uncommitted changes, `nothing` means unknown (e.g., outdated local registry). ```julia mera_install() # (version = v"1.2.3", source = :registry, registered = true, branch = nothing, ...) ``` -------------------------------- ### getextent usage example Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example call returning the extent in kpc from the box centre. ```julia julia> getextent(gas, :kpc; center=[:bc]) ((-24.0, 24.0), (-24.0, 24.0), (-24.0, 24.0)) ``` -------------------------------- ### iscosmological usage example Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/api_reference.md Example of calling iscosmological on an info object from a cosmological run. ```julia info = getinfo(80, "…/yt_cosmo") iscosmological(info) # true ``` -------------------------------- ### Show quicklook summary Source: https://github.com/manuelbehrendt/mera.jl/blob/master/docs/context7/pages/first_look.md Displays the header facts and read-derived estimates from the quicklook result. ```julia # the header facts and the read-derived estimates q.summary ```