Gadget2 I/O

The default units in Gadget-2 snapshots are collected as uGadget2. However, it is much more convenient to use uAstro in simulations:

julia> using PhysicalParticles, AstroIO
julia> uGadget27-element Vector{Unitful.FreeUnits{N, D, nothing} where {N, D}}: kpc kpc s km^-1 A K cd 1e10M⊙ mol
julia> uAstro7-element Vector{Unitful.FreeUnits{N, D, nothing} where {N, D}}: kpc Gyr A K cd M⊙ mol

Basic usage

Units are automatedly converted during I/O:

# read default uGadget2 units from file and convert to uAstro
header, data = read_gadget2("snapshot.gadget2", uAstro);

# manually set the units in snapshot file
header, data = read_gadget2("snapshot.gadget2", uAstro, uGadget2);

# read default uGadget2 units from file and convert to unitless
header, data = read_gadget2("snapshot.gadget2", nothing, uGadget2);

# write in default uGadget2 units
write_gadget2("output.Gadget2", header, data)

# write in uAstro units
write_gadget2("output.Gadget2", header, data, uAstro)
# and read in uAstro units
header, data = read_gadget2("snapshot.gadget2", uAstro, uAstro);

Be careful with these unit conversions!

In some cases (for example, visualization), it is more efficient to only read position data from file:

read_gadget2_pos("snapshot.gadget2", uAstro)
read_gadget2_pos("snapshot.gadget2", uAstro, uGadget2)

FileIO interfaces

FileIO provides load and save interfaces to I/O snapshots:

header, data = load("snapshot.gadget2")
save("FileIO.gadget2", header, data)

header, data = load("snapshot.gadget2", uAstro, uGadget2)
save("FileIO.gadget2", header, data, uGadget2)