Projections API Reference

Functions for creating 2D projections from 3D simulation data.

Exported Functions

Main Projection Function

Function: projection - Create 2D projections from 3D simulation data

The projection function uses Julia's multiple dispatch to provide specialized implementations for different data types. Since the complete API documentation is extensive, this section provides focused guidance for each data type.

Performance & Threading Functions

Data Type Support

Hydro and RT projections

The hydro methods dispatch on Union{HydroDataType, RtDataType} — the same call works on an object from getrt.

# Single variable, code units / with a unit
projection(dataobject::Union{HydroDataType, RtDataType}, var::Symbol)
projection(dataobject::Union{HydroDataType, RtDataType}, var::Symbol, unit::Symbol)

# Several variables, one unit each / one unit for all
projection(dataobject::Union{HydroDataType, RtDataType}, vars::Array{Symbol,1}, units::Array{Symbol,1})
projection(dataobject::Union{HydroDataType, RtDataType}, vars::Array{Symbol,1}, unit::Symbol)

Gravity (combined form)

Gravity quantities are projected by passing the gravity object alongside the hydro one — the cells come from the hydro object, the quantity from gravity:

projection(hydro::HydroDataType, gravity::GravDataType, var::Symbol, unit::Symbol)

Common keyword arguments

KeywordWhat it does
pxsize=[value, :unit]physical size of a map pixel — the preferred way to set resolution
resgrid cells per side instead of a physical pixel size
lmaxcap the AMR level used; defaults to the object's own lmax
direction:x, :y, :z (default :z), or :faceon/:edgeon after galaxyframe
los, up, theta, phi, inclination, azimuthoff-axis line of sight — see Off-axis
weightinghow intensive quantities are averaged (see the note below)
mode:standard normalises per area; :sum returns the raw weighted sum
maska boolean array from getmask, applied before projecting
center, range_unitwhich part of the box to project, and in what units
data_center, data_center_unitorigin the map axes and cylindrical/spherical quantities are measured from
xrange, yrange, zrangerestrict the projected volume
max_threadscap the threads used
myargspass a bundle instead of repeating keywords — see Bundling Arguments
`weighting` has a different type for particles

Hydro, gravity and RT take an array: weighting=[:mass], weighting=[:volume], or [:quantity, unit]. Particle projections take a bare symbol: weighting=:mass, :volume, :sph or :voronoi. Passing a symbol to a hydro projection raises TypeError: expected Vector, got Symbol.

Key features:

  • AMR-aware grid mapping with conservative mass preservation
  • Variable-based parallel processing (8+ threads)
  • Mass-weighted averaging for intensive quantities

Common variables: :rho, :T, :sd, :v, :p, :cs, velocity dispersion (:σx, :σy, :σz)

Tutorial: Hydro Projections - Complete examples and usage

Particle Data Projections (PartDataType)

Key Method Signatures:

# Single variable with default units
projection(dataobject::PartDataType, var::Symbol)

# Single variable with custom units
projection(dataobject::PartDataType, var::Symbol, unit::Symbol)

# Multiple variables with custom units
projection(dataobject::PartDataType, vars::Array{Symbol,1}, units::Array{Symbol,1})

# Multiple variables with same units
projection(dataobject::PartDataType, vars::Array{Symbol,1}, unit::Symbol)

Key features:

  • Mass-weighted binning for discrete particles
  • getvar with :age returns stellar ages relative to the snapshot time

Common variables: :mass, :age, :sd, :v, :birth, :metal, :id, :family

Tutorial: Particle Projections - Complete examples and usage

Quick Usage Examples

# Hydro data projections
hydro = gethydro(info, ...)
projection(hydro, :rho, :g_cm3)              # Density projection
projection(hydro, :sd, :Msol_pc2)            # Surface density
projection(hydro, [:T, :v], [:K, :km_s])     # Multi-variable

# Particle data projections  
particles = getparticles(info, ...)
projection(particles, :age, :Myr)            # Stellar age
projection(particles, :sd, :Msol_pc2)        # Stellar surface density
projection(particles, :mass, :Msol)          # Mass distribution

General Projection Types

Both data types support:

  • Density projections - Surface density maps (:sd)
  • Mass-weighted projections - Intensive quantities with proper averaging
  • Velocity projections - Velocity fields and dispersion maps
  • Custom derived quantities - Temperature, pressure, kinematic analysis

Drawing the AMR grid on a map

Overlay the cell boundaries of a refinement level on a finished projection — useful for showing where resolution changes relative to a structure. gridoverlay! draws into an existing axis; gridoverlay returns the segments so you can draw them yourself.

Mera.gridoverlayFunction
gridoverlay(dataobject; level=:max, direction=:z, center=[:boxcenter], range_unit=:standard,
            xrange=[missing,missing], yrange=[missing,missing], zrange=[missing,missing],
            unit=:standard) -> (segments, extent, level)

Cell-boundary line segments of the AMR cells at one refinement level, viewed along direction (:x/:y/:z), for overlaying the AMR structure on a map. level is :max (default, the finest), :min, or an integer. The cell edges are de-duplicated.

The result is the 2-D footprint of that level's cells (collapsed along direction), so it suits both a projection and a slice:

  • slice — pass a thin zrange (the slice plane) → the exact in-plane cell grid there;
  • projection — use the full column → where that level's cells project to along the line of sight.

(The two coincide when the refined region is a column-aligned box, and differ for irregular refinement.)

Off-axis views work too: pass the same view keywords as projectionlos/up, inclination/azimuth (or theta/phi, position_angle), axis=:angmom, or direction=:faceon/:edgeon. Each cell centre is projected through the camera basis and drawn as a cell-sized square (an approximate indicator; the true tilted-cube silhouette is a hexagon). Off-axis overlays are not edge-de-duplicated, so on dense AMR pick a coarser level or a sub-region to keep the segment count manageable.

Returns a NamedTuple: segments (a Vector{NTuple{4,Float64}} of (x1,y1,x2,y2) in the plane coordinates and unit), extent [xmin,xmax,ymin,ymax], and the level used. Plot with linesegments! — or, after using Makie, the convenience gridoverlay!(ax, go).

p  = projection(gas, :sd)
go = gridoverlay(gas; level=:max)         # the finest-cell grid, where it exists
# overlay go.segments on the heatmap of p.maps[:sd]
Mera.gridoverlay!Function
gridoverlay!(ax, go; color=(:white,0.3), linewidth=0.4)

Draw a gridoverlay result go onto a Makie axis ax (the AMR cell boundaries). Available after using Makie/CairoMakie.

Performance & Threading

Mera.benchmark_projection_hydroFunction
benchmark_projection_hydro(gas_data, thread_counts::Vector{Int}, n_runs::Int=10, output_file::String="") → Dict

Execute comprehensive AMR hydro projection benchmark with robust statistical analysis.

This function serves as the main coordinator for hydro projection performance testing. It performs AMR structure analysis, data quality validation, executes both single-variable and multi-variable projection benchmarks across specified thread counts, and exports results in multiple formats with comprehensive statistical analysis.

Benchmark Methodology

  • Single-Variable Test: Surface density projection (:sd → Msun/pc²)
  • Multi-Variable Test: 10 simultaneous variable projections: vars = [:v, :σ, :σx, :σy, :σz, :vrcylinder, :vϕcylinder, :σrcylinder, :σϕcylinder, :cs]
  • Statistical Robustness: several repetitions per configuration with coefficient of variation
  • Quality Control: Success rate monitoring (>80% threshold for reliable data)
  • Memory Profiling: Peak memory usage and garbage collection analysis

Threading Analysis

Evaluates performance across thread counts with derived metrics:

  • Speedup: Performance improvement vs single-threaded execution
  • Efficiency: Speedup per thread (percentage of ideal scaling)
  • Memory Scaling: Memory usage patterns across thread configurations

Output Files Generated

  • {output_file}.csv: Structured data for spreadsheet analysis and plotting
  • {output_file}.json: Machine-readable structured data for programmatic access
  • {output_file}_summary.txt: Human-readable performance report with insights

Arguments

  • gas_data: HydroDataType object from loaddata() or gethydrodata()
  • thread_counts::Vector{Int}: Thread counts to benchmark [1, 2, 4, 8, 16, ...]
  • n_runs::Int=10: Statistical repetitions per configuration (10 for robust analysis)
  • output_file::String="": Output filename base (auto-generated timestamp if empty)

Returns

Dictionary containing complete benchmark results with keys:

  • n_threads, test_type, mean_time, std_time, speedup, efficiency
  • mean_memory, success_rate, min_time, max_time, n_runs

Example Usage

# Load RAMSES hydro data
gas_data = loaddata(300, "/path/to/ramses/output/", :hydro)

# Run comprehensive benchmark (single + multi-variable)
results = benchmark_projection_hydro(gas_data, [1, 2, 4, 8, 16], 10, "performance_test")

# Results saved as:
# - performance_test.csv (for plotting with plot_results.jl)
# - performance_test.json (for programmatic analysis)  
# - performance_test_summary.txt (human-readable report)

Performance Insights

The benchmark automatically analyzes threading efficiency and provides guidance:

  • Identifies optimal thread counts for your system and data size
  • Detects threading bottlenecks and memory constraints
  • Quantifies single vs multi-variable projection performance differences
  • Provides statistical confidence intervals for all measurements

Integration Workflow

  1. Data Loading: Use Mera's loaddata() for your RAMSES simulation
  2. Benchmarking: Execute this function with desired thread counts
  3. Visualization: Use plot_results.jl to create performance dashboards
  4. Analysis: Review summary.txt for optimization recommendations
Mera.show_threading_infoFunction
show_threading_info()

Display information about Julia threading configuration and recommendations.


For complete function documentation, see the Complete API Reference.