licenses
sequencelengths 1
3
| version
stringclasses 677
values | tree_hash
stringlengths 40
40
| path
stringclasses 1
value | type
stringclasses 2
values | size
stringlengths 2
8
| text
stringlengths 25
67.1M
| package_name
stringlengths 2
41
| repo
stringlengths 33
86
|
---|---|---|---|---|---|---|---|---|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2251 | using Documenter, Mera
makedocs(modules = [Mera],
sitename = "Mera.jl",
doctest = false,
clean = true,
checkdocs = :all,
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true", sidebar_sitename = false),
authors = "Manuel Behrendt",
pages = Any[ "Home" => "index.md",
"First Steps" => "00_multi_FirstSteps.md",
"1-Data Inspection" => Any[ "Hydro" => "01_hydro_First_Inspection.md",
"Particles" => "01_particles_First_Inspection.md",
"Clumps" => "01_clumps_First_Inspection.md"],
"2-Load by Selection" => Any[ "Hydro" => "02_hydro_Load_Selections.md",
"Particles" => "02_particles_Load_Selections.md",
"Clumps" => "02_clumps_Load_Selections.md"],
"3-Get Subregions" => Any[ "Hydro" => "03_hydro_Get_Subregions/03_hydro_Get_Subregions.md",
"Particles" => "03_particles_Get_Subregions/03_particles_Get_Subregions.md",
"Clumps" => "03_clumps_Get_Subregions/03_clumps_Get_Subregions.md"],
"4-Basic Calculations" => "04_multi_Basic_Calculations.md",
"5-Mask/Filter/Meta" => "05_multi_Masking_Filtering/05_multi_Masking_Filtering.md",
"6-Projection" => Any[ "Hydro" => "06_hydro_Projection/06_hydro_Projection.md",
"Particles" => "06_particles_Projection/06_particles_Projection.md"],
"7-MERA-Files" => "07_multi_Mera_Files.md",
"8-Miscellaneous" => "Miscellaneous.md",
"Examples" => "examples.md",
"API Documentation" => "api.md"
]
)
deploydocs(repo = "github.com/ManuelBehrendt/Mera.jl.git")
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 5107 | __precompile__(true)
module Mera
# ==================================================================
# Read/Save and process large AMR/particle data sets
# of hydrodynamic simulations with Julia!
#
# Manuel Behrendt, since 2017
# Max-Planck-Institute for extraterrestrial Physics, Garching
# Ludwig-Maximillians-University, Munich
#
# https://github.com/ManuelBehrendt/Mera.jl
#
# Credits:
# The RAMSES-files reader are strongly influenced
# by Romain Teyssier's amr2map.f90 and part2mapf.90
# ==================================================================
# Julia libraries
using Printf
using Dates
using Statistics
using Pkg
# external libraries
using FortranFiles
using JuliaDB
using DataStructures
using ElasticArrays
using StructArrays
using ProgressMeter
using StatsBase
using OnlineStats
using ImageTransformations
using JLD2, CodecZlib, CodecBzip2, CodecLz4
using TimerOutputs
using WAV
global verbose_mode = nothing
global showprogress_mode = nothing
export
verbose_mode,
verbose,
showprogress_mode,
showprogress,
# data reader
getunit,
getinfo,
createpath,
gethydro,
getgravity,
getparticles,
getclumps,
# mera files
savedata,
loaddata,
viewdata,
infodata,
convertdata,
# data_overview
printtime,
usedmemory,
viewfields,
namelist,
makefile,
timerfile,
patchfile,
viewallfields,
storageoverview,
amroverview,
dataoverview,
checkoutputs,
checksimulations,
gettime,
# basic calcs
msum,
center_of_mass,
com,
bulk_velocity,
average_velocity,
average_mweighted,
getvar,
getmass,
getpositions,
getvelocities,
getextent,
wstat,
#
projection,
#slice,
#profile,
#remap,
subregion,
shellregion,
# miscellaneous
viewmodule,
construct_datatype,
createscales,
humanize,
bell,
notifyme,
#types
ScalesType001,
ScalesType,
ArgumentsType,
PhysicalUnitsType001,
PhysicalUnitsType,
GridInfoType,
PartInfoType,
FileNamesType,
CompilationInfoType,
InfoType,
DescriptorType,
DataSetType,
ContainMassDataSetType,
HydroPartType,
HydroDataType,
GravDataType,
PartDataType,
ClumpDataType,
DataMapsType,
HydroMapsType,
PartMapsType,
Histogram2DMapType,
MaskType,
MaskArrayType,
MaskArrayAbstractType
include("types.jl")
include("types_old.jl")
include("functions/miscellaneous.jl")
include("functions/overview.jl")
include("functions/basic_calc.jl")
# Get variables/quantities
include("functions/getvar.jl")
include("functions/getvar_hydro.jl")
include("functions/getvar_gravity.jl")
include("functions/getvar_particles.jl")
include("functions/getvar_clumps.jl")
# ============================================
include("read_data/RAMSES/filepaths.jl")
include("read_data/RAMSES/getinfo.jl")
include("functions/viewfields.jl")
include("functions/checks.jl")
include("functions/prepranges.jl")
include("read_data/RAMSES/prepvariablelist.jl")
include("read_data/RAMSES/hilbert3d.jl")
# Data reader
include("read_data/RAMSES/gethydro.jl")
include("read_data/RAMSES/reader_hydro.jl")
include("read_data/RAMSES/getgravity.jl")
include("read_data/RAMSES/reader_gravity.jl")
include("read_data/RAMSES/getparticles.jl")
include("read_data/RAMSES/reader_particles.jl")
include("read_data/RAMSES/getclumps.jl")
# ============================================
# Mera files
# new: JLD2 format
include("functions/data_save.jl")
include("functions/data_load.jl")
include("functions/data_view.jl")
include("functions/data_info.jl")
include("functions/data_convert.jl")
# ============================================
# projection, slice
include("functions/projection.jl")
#include("functions/slice.jl")
include("functions/projection_hydro.jl")
include("functions/projection_particles.jl")
# ============================================
# profile
#include("functions/profile.jl")
# ============================================
# Subregion
include("functions/subregion.jl")
include("functions/subregion_hydro.jl")
include("functions/subregion_gravity.jl")
include("functions/subregion_particles.jl")
include("functions/subregion_clumps.jl")
# ============================================
# Shellregion
include("functions/shellregion.jl")
include("functions/shellregion_hydro.jl")
include("functions/shellregion_gravity.jl")
include("functions/shellregion_particles.jl")
include("functions/shellregion_clumps.jl")
# ============================================
# Functions under development
pkgdir = joinpath(@__DIR__, "dev/dev.jl")
if isfile(pkgdir)
include(pkgdir)
end
# ============================================
println()
println( "*__ __ _______ ______ _______ ")
println( "| |_| | | _ | | _ |")
println( "| | ___| | || | |_| |")
println( "| | |___| |_||_| |")
println( "| | ___| __ | |")
println( "| ||_|| | |___| | | | _ |")
println( "|_| |_|_______|___| |_|__| |__|")
println()
end # module
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 13081 |
"""
Mutable Struct: Contains the created scale factors from code to physical units
"""
mutable struct ScalesType001
# exported
# length
Mpc::Float64
kpc::Float64
pc::Float64
mpc::Float64
ly::Float64
Au::Float64
km::Float64
m::Float64
cm::Float64
mm::Float64
μm::Float64
# volume
Mpc3::Float64
kpc3::Float64
pc3::Float64
mpc3::Float64
ly3::Float64
Au3::Float64
km3::Float64
m3::Float64
cm3::Float64
mm3::Float64
μm3::Float64
# density
Msol_pc3::Float64
Msun_pc3::Float64
g_cm3::Float64
# surface
Msol_pc2::Float64
Msun_pc2::Float64
g_cm2::Float64
# time
Gyr::Float64
Myr::Float64
yr::Float64
s::Float64
ms::Float64
# mass
Msol::Float64
Msun::Float64
Mearth::Float64
Mjupiter::Float64
g::Float64
# speed
km_s::Float64
m_s::Float64
cm_s::Float64
nH::Float64
erg::Float64
g_cms2::Float64
T_mu::Float64
K_mu::Float64
T::Float64
K::Float64
Ba::Float64
g_cm_s2::Float64
p_kB::Float64
K_cm3::Float64
ScalesType001() = new()
end
"""
Mutable Struct: Contains the physical constants in cgs units
"""
mutable struct PhysicalUnitsType001
# exported
# in cgs units
Au::Float64#cm: Astronomical unit
Mpc::Float64 #cm: Parsec
kpc::Float64 #cm: Parsec
pc::Float64 #cm: Parsec
mpc::Float64 #cm: MilliParsec
ly::Float64 #cm: Light year
Msol::Float64 #g: Solar mass
Msun::Float64 #g: Sun mass
Mearth::Float64 #g: Earth mass
Mjupiter::Float64 #g: Jupiter mass
Rsol::Float64 #cm: Solar radius
Rsun::Float64
# Lsol = #erg s-2: Solar luminosity
# Mearth = #g: Earh mass
me::Float64 #g: electron mass
mp::Float64 #g: proton mass
mn::Float64 #g: neutron mass
mH::Float64 #g: hydrogen mass
amu::Float64 #g: atomic mass unit
NA::Float64 # Avagadro's number
c::Float64 #cm s-1: speed of light in a vacuum
# h = #erg s: Planck constant
# hbar = #erg s
G::Float64 # cm3 g-1 g-2 Gravitational constant
kB::Float64 #erg k-1 Boltzmann constant
Gyr::Float64 #sec: defined as 365.25 days
Myr::Float64 #sec: defined as 365.25 days
yr::Float64 #sec: defined as 365.25 days
PhysicalUnitsType001() = new()
end
mutable struct FileNamesType
output::String
info::String
amr::String
hydro::String
hydro_descriptor::String
gravity::String
particles::String
part_descriptor::String
rt::String
rt_descriptor::String
rt_descriptor_v0::String
clumps::String
timer::String
header::String
namelist::String
compilation::String
makefile::String
patchfile::String
FileNamesType() = new()
end
"""
Mutable Struct: Contains the collected information about grid
"""
mutable struct GridInfoType
# exported
ngridmax::Int
nstep_coarse::Int
nx::Int
ny::Int
nz::Int
nlevelmax::Int
nboundary::Int
ngrid_current::Int
bound_key::Array{Float64,1}
cpu_read::Array{Bool,1}
GridInfoType() = new()
end
"""
Mutable Struct: Contains the collected information about particles
"""
mutable struct PartInfoType
# exported
eta_sn::Float64
age_sn::Float64
f_w::Float64
Npart::Int
Ndm::Int
Nstars::Int
Nsinks::Int
Ncloud::Int
Ndebris::Int
Nother::Int
Nundefined::Int
other_tracer1::Int
debris_tracer::Int
cloud_tracer::Int
star_tracer::Int
other_tracer2::Int
gas_tracer::Int
PartInfoType() = new()
end
"""
Mutable Struct: Contains the collected information about the compilation of RAMSES
"""
mutable struct CompilationInfoType
# exported
compile_date::String
patch_dir::String
remote_repo::String
local_branch::String
last_commit::String
CompilationInfoType() = new()
end
"""
Mutable Struct: Contains the collected information about the descriptors
"""
mutable struct DescriptorType
# exported
hversion::Int
hydro::Array{Symbol,1}
htypes::Array{String,1}
usehydro::Bool
hydrofile::Bool
pversion::Int
particles::Array{Symbol,1}
ptypes::Array{String,1}
useparticles::Bool
particlesfile::Bool
gravity::Array{Symbol,1}
usegravity::Bool
gravityfile::Bool
rtversion::Int
rt::Dict{Any,Any}
rtPhotonGroups::Dict{Any,Any}
usert::Bool
rtfile::Bool
clumps::Array{Symbol,1}
useclumps::Bool
clumpsfile::Bool
sinks::Array{Symbol,1}
usesinks::Bool
sinksfile::Bool
DescriptorType() = new()
end
mutable struct FilesContentType
makefile::Array{String,1}
timerfile::Array{String,1}
patchfile::Array{String,1}
FilesContentType() = new()
end
"""
Mutable Struct: Collected information about the selected simulation output
"""
mutable struct InfoType
# exported
output::Real
path::String
fnames::FileNamesType
simcode::String
mtime::DateTime
ctime::DateTime
ncpu::Int
ndim::Int
levelmin::Int
levelmax::Int
boxlen::Float64
time::Float64
aexp::Float64
H0::Float64
omega_m::Float64
omega_l::Float64
omega_k::Float64
omega_b::Float64
unit_l::Float64
unit_d::Float64
unit_m::Float64
unit_v::Float64
unit_t::Float64
gamma::Float64
hydro::Bool
nvarh::Int # number of hydro variables
nvarp::Int # number of particle variables
nvarrt::Int # number of rt variables
variable_list::Array{Symbol,1} # hydro variable list
gravity_variable_list::Array{Symbol,1}
particles_variable_list::Array{Symbol,1}
rt_variable_list::Array{Symbol,1}
clumps_variable_list::Array{Symbol,1}
sinks_variable_list::Array{Symbol,1}
descriptor::DescriptorType
amr::Bool
gravity::Bool
particles::Bool
rt::Bool
clumps::Bool
sinks::Bool
namelist::Bool
namelist_content::Dict{Any,Any}
headerfile::Bool
makefile::Bool
files_content::FilesContentType
timerfile::Bool
compilationfile::Bool
patchfile::Bool
Narraysize::Int
scale::ScalesType001
grid_info::GridInfoType
part_info::PartInfoType
compilation::CompilationInfoType
constants::PhysicalUnitsType001
#overview::simulation_overview
#cpu_overview::cpu_overview_type
#boxcenter::Array{Float64,1}
InfoType() = new()
end
mutable struct LevelType
imin::Int
imax::Int
jmin::Int
jmax::Int
kmin::Int
kmax::Int
end
"""
Abstract Supertype of all the different dataset types
> HydroPartType <: ContainMassDataSetType <: DataSetType
"""
abstract type DataSetType end # exported
"""
Abstract Supertype of all datasets that contain mass variables
> HydroPartType <: ContainMassDataSetType <: DataSetType
"""
abstract type ContainMassDataSetType <: DataSetType end # exported
"""
Abstract Supertype of data-sets that contain hydro and particle data
> HydroPartType <: ContainMassDataSetType <: DataSetType
"""
abstract type HydroPartType <: ContainMassDataSetType end # exported
"""
Mutable Struct: Contains hydro data and information about the selected simulation
> HydroDataType <: HydroPartType
"""
mutable struct HydroDataType <: HydroPartType
# exported
data::JuliaDB.AbstractIndexedTable
info::InfoType
lmin::Int
lmax::Int
boxlen::Float64
ranges::Array{Float64,1}
selected_hydrovars::Array{Int,1}
used_descriptors::Dict{Any,Any}
smallr::Float64
smallc::Float64
scale::ScalesType001
HydroDataType() = new()
end
# exported
mutable struct GravDataType <: DataSetType
data::JuliaDB.AbstractIndexedTable
info::InfoType
lmin::Int
lmax::Int
boxlen::Float64
ranges::Array{Float64,1}
selected_gravvars::Array{Int,1}
used_descriptors::Dict{Any,Any}
scale::ScalesType001
GravDataType() = new()
end
"""
Mutable Struct: Contains particle data and information about the selected simulation
> PartDataType <: HydroPartType
"""
mutable struct PartDataType <: HydroPartType
#exported
data::JuliaDB.AbstractIndexedTable
info::InfoType
lmin::Int
lmax::Int
boxlen::Float64
ranges::Array{Float64,1}
selected_partvars::Array{Symbol,1}
used_descriptors::Dict{Any,Any}
scale::ScalesType001
PartDataType() = new()
end
"""
Mutable Struct: Contains clump data and information about the selected simulation
> ClumpDataType <: ContainMassDataSetType
"""
mutable struct ClumpDataType <: ContainMassDataSetType
# exported
data
info::InfoType
boxlen::Float64
ranges::Array{Float64,1}
selected_clumpvars::Array{Symbol,1}
used_descriptors::Dict{Any,Any}
scale::ScalesType001
ClumpDataType() = new()
end
"""
Union Type: Mask-array that is of type Bool or BitArray
MaskType = Union{Array{Bool,1},BitArray{1}}
"""
MaskType = Union{Array{Bool,1},BitArray{1}} # exported
MaskArrayType = Union{ Array{Array{Bool,1},1}, Array{BitArray{1},1} }
MaskArrayAbstractType = Union{ MaskArrayType, Array{AbstractArray{Bool,1},1} } # used for the combined center_of_mass function
#HydroPartType = Union{HydroDataType, PartDataType}
"""
Mutable Struct: Contains the output statistics returned by wstat
"""
mutable struct WStatType
mean::Float64
median::Float64
std::Float64
skewness::Float64
kurtosis::Float64
min::Float64
max::Float64
end
"""
Abstract Supertype of all the different dataset type maps
HydroMapsType <: DataMapsType
PartMapsType <: DataMapsType
"""
abstract type DataMapsType end # exported
"""
Mutable Struct: Contains the maps/units returned by the hydro-projection information about the selected simulation
"""
mutable struct HydroMapsType <: DataMapsType
maps::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
maps_unit::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
maps_lmax::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
maps_weight::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
maps_mode::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
lmax_projected::Real
lmin::Int
lmax::Int
ranges::Array{Float64,1}
extent::Array{Float64,1}
cextent::Array{Float64,1}
ratio::Float64
effres::Int
pixsize::Float64
boxlen::Float64
smallr::Float64
smallc::Float64
scale::ScalesType001
info::InfoType
end
"""
Mutable Struct: Contains the maps/units returned by the particles-projection information about the selected simulation
"""
mutable struct PartMapsType <: DataMapsType
maps::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
maps_unit::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
maps_lmax::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
maps_mode::DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering}
lmax_projected::Real
lmin::Int
lmax::Int
ref_time::Real
ranges::Array{Float64,1}
extent::Array{Float64,1}
cextent::Array{Float64,1}
ratio::Float64
effres::Int
pixsize::Float64
boxlen::Float64
scale::ScalesType001
info::InfoType
end
"""
Mutable Struct: Contains the 2D histogram returned by the function: histogram2 and information about the selected simulation
"""
mutable struct Histogram2DMapType
map::Array{Float64,2}
closed::Symbol
weight::Tuple{Symbol,Symbol}
nbins::Array{Int,1}
xrange::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}
yrange::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}
extent::Array{Float64,1}
ratio::Float64
scale::ScalesType001
info::InfoType
end
"""
Mutable Struct: Contains the existing simulation snapshots in a folder and a list of the empty output-folders
"""
mutable struct CheckOutputNumberType
outputs::Array{Int,1}
miss::Array{Int,1}
path::String
end
"""
Mutable Struct: Contains fields to use as arguments in functions
"""
Base.@kwdef mutable struct ArgumentsType
pxsize::Union{Array{<:Any,1}, Missing} = missing
res::Union{Real, Missing} = missing
lmax::Union{Real, Missing} = missing
xrange::Union{Array{<:Any,1}, Missing} = missing
yrange::Union{Array{<:Any,1}, Missing} = missing
zrange::Union{Array{<:Any,1}, Missing} = missing
radius::Union{Array{<:Real,1}, Missing} = missing
height::Union{Real, Missing} = missing
direction::Union{Symbol, Missing} = missing
plane::Union{Symbol, Missing} = missing
plane_ranges::Union{Array{<:Any,1}, Missing} = missing
thickness::Union{Real, Missing} = missing
position::Union{Real, Missing} = missing
center::Union{Array{<:Any,1}, Missing} = missing
range_unit::Union{Symbol, Missing} = missing
data_center::Union{Array{<:Any,1}, Missing} = missing
data_center_unit::Union{Symbol, Missing} = missing
verbose::Union{Bool, Missing} = missing
show_progress::Union{Bool, Missing} = missing
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2358 | """
Mutable Struct: Contains the created scale factors from code to physical units
"""
mutable struct ScalesType
# exported
# length
Mpc::Float64
kpc::Float64
pc::Float64
mpc::Float64
ly::Float64
Au::Float64
km::Float64
m::Float64
cm::Float64
mm::Float64
μm::Float64
# volume
Mpc3::Float64
kpc3::Float64
pc3::Float64
mpc3::Float64
ly3::Float64
Au3::Float64
km3::Float64
m3::Float64
cm3::Float64
mm3::Float64
μm3::Float64
# density
Msol_pc3::Float64
g_cm3::Float64
# surface
Msol_pc2::Float64
g_cm2::Float64
# time
Gyr::Float64
Myr::Float64
yr::Float64
s::Float64
ms::Float64
# mass
Msol::Float64
Mearth::Float64
Mjupiter::Float64
g::Float64
# speed
km_s::Float64
m_s::Float64
cm_s::Float64
nH::Float64
erg::Float64
g_cms2::Float64
T_mu::Float64
Ba::Float64
ScalesType() = new()
end
"""
Mutable Struct: Contains the physical constants in cgs units
"""
mutable struct PhysicalUnitsType
# exported
# in cgs units
Au::Float64#cm: Astronomical unit
Mpc::Float64 #cm: Parsec
kpc::Float64 #cm: Parsec
pc::Float64 #cm: Parsec
mpc::Float64 #cm: MilliParsec
ly::Float64 #cm: Light year
Msol::Float64 #g: Solar mass
Mearth::Float64 #g: Earth mass
Mjupiter::Float64 #g: Jupiter mass
Rsol::Float64 #cm: Solar radius
# Lsol = #erg s-2: Solar luminosity
# Mearth = #g: Earh mass
me::Float64 #g: electron mass
mp::Float64 #g: proton mass
mn::Float64 #g: neutron mass
mH::Float64 #g: hydrogen mass
amu::Float64 #g: atomic mass unit
NA::Float64 # Avagadro's number
c::Float64 #cm s-1: speed of light in a vacuum
# h = #erg s: Planck constant
# hbar = #erg s
G::Float64 # cm3 g-1 g-2 Gravitational constant
kB::Float64 #erg k-1 Boltzmann constant
Gyr::Float64 #sec: defined as 365.25 days
Myr::Float64 #sec: defined as 365.25 days
yr::Float64 #sec: defined as 365.25 days
PhysicalUnitsType() = new()
end
#------------------
# prepare with rconvert to load also older data types
JLD2.rconvert(::Type{ScalesType001}, nt::NamedTuple) = ScalesType001()
JLD2.rconvert(::Type{PhysicalUnitsType001}, nt::NamedTuple) = PhysicalUnitsType001()
#------------------ | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 12460 | """
#### Calculate the total mass of any ContainMassDataSetType:
```julia
msum(dataobject::ContainMassDataSetType; unit::Symbol=:standard, mask::MaskType=[false])
return Float64
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "ContainMassDataSetType"
##### Optional Keywords:
- **`unit`:** the unit of the result (can be used w/o keyword): :standard (code units) :Msol, :Mearth, :Mjupiter, :g, :kg (of typye Symbol) ..etc. ; see for defined mass-scales viewfields(info.scale)
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
"""
function msum(dataobject::ContainMassDataSetType, unit::Symbol; mask::MaskType=[false])
return msum(dataobject, unit=unit, mask=mask)
end
function msum(dataobject::ContainMassDataSetType; unit::Symbol=:standard, mask::MaskType=[false])
return sum( getvar(dataobject, :mass, unit=unit, mask=mask) )
end
"""
#### Calculate the center-of-mass of any ContainMassDataSetType:
```julia
center_of_mass(dataobject::ContainMassDataSetType; unit::Symbol=:standard, mask::MaskType=[false])
return Tuple{Float64, Float64, Float64,}
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "ContainMassDataSetType"
##### Optional Keywords:
- **`unit`:** the unit of the result (can be used w/o keyword): :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
"""
function center_of_mass(dataobject::ContainMassDataSetType, unit::Symbol; mask::MaskType=[false])
return center_of_mass(dataobject, unit=unit, mask=mask)
end
function center_of_mass(dataobject::ContainMassDataSetType; unit::Symbol=:standard, mask::MaskType=[false])
selected_unit = getunit(dataobject.info, unit)
return ( average_mweighted(dataobject, :x, mask=mask), average_mweighted(dataobject, :y, mask=mask), average_mweighted(dataobject, :z, mask=mask) ) .* selected_unit
end
"""
#### Calculate the center-of-mass of any ContainMassDataSetType:
```julia
com(dataobject::ContainMassDataSetType; unit::Symbol=:standard, mask::MaskType=[false])
return Tuple{Float64, Float64, Float64,}
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "ContainMassDataSetType"
##### Optional Keywords:
- **`unit`:** the unit of the result (can be used w/o keyword): :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
"""
function com(dataobject::ContainMassDataSetType, unit::Symbol; mask::MaskType=[false])
return center_of_mass(dataobject, unit, mask=mask)
end
function com(dataobject::ContainMassDataSetType; unit::Symbol=:standard, mask::MaskType=[false])
return center_of_mass(dataobject, unit=unit, mask=mask)
end
"""
#### Calculate the joint center-of-mass of any HydroPartType:
```julia
center_of_mass(dataobject::Array{HydroPartType,1}, unit::Symbol; mask::MaskArrayAbstractType=[[false],[false]])
return Tuple{Float64, Float64, Float64,}
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "Array{HydroPartType,1}""
##### Optional Keywords:
- **`unit`:** the unit of the result (can be used w/o keyword): :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`mask`:** needs to be of type MaskArrayAbstractType which contains two entries with supertype of Array{Bool,1} or BitArray{1} and the length of the database (rows)
"""
function center_of_mass(dataobject::Array{HydroPartType,1}, unit::Symbol; mask::MaskArrayAbstractType=[[false],[false]])
return center_of_mass(dataobject; unit=unit, mask=mask)
end
function center_of_mass(dataobject::Array{HydroPartType,1}; unit::Symbol=:standard, mask::MaskArrayAbstractType=[[false],[false]])
selected_unit = getunit(dataobject[1].info, unit) # assuming both datasets are from same simulation output
if length(mask[1]) == 1 && length(mask[2]) == 1
m1 = getvar(dataobject[1], :mass)
m1_sum = sum(m1)
m2 = getvar(dataobject[2], :mass)
m2_sum = sum(m2)
m_sum = m1_sum + m2_sum
x_weighted = (sum( getvar(dataobject[1], :x) .* m1 ) + sum( getvar(dataobject[2], :x) .* m2) ) / m_sum
y_weighted = (sum( getvar(dataobject[1], :y) .* m1 ) + sum( getvar(dataobject[2], :y) .* m2) ) / m_sum
z_weighted = (sum( getvar(dataobject[1], :z) .* m1 ) + sum( getvar(dataobject[2], :z) .* m2) ) / m_sum
else
m1 = getvar(dataobject[1], :mass)[mask[1]]
m1_sum = sum(m1)
m2 = getvar(dataobject[2], :mass)[mask[2]]
m2_sum = sum(m2)
m_sum = m1_sum + m2_sum
x_weighted = (sum( getvar(dataobject[1], :x)[mask[1]] .* m1 ) + sum( getvar(dataobject[2], :x)[mask[2]] .* m2) ) / m_sum
y_weighted = (sum( getvar(dataobject[1], :y)[mask[1]] .* m1 ) + sum( getvar(dataobject[2], :y)[mask[2]] .* m2) ) / m_sum
z_weighted = (sum( getvar(dataobject[1], :z)[mask[1]] .* m1 ) + sum( getvar(dataobject[2], :z)[mask[2]] .* m2) ) / m_sum
end
return ( x_weighted, y_weighted, z_weighted ) .* selected_unit
end
"""
#### Calculate the joint center-of-mass of any HydroPartType:
```julia
com(dataobject::Array{HydroPartType,1}, unit::Symbol; mask::MaskArrayAbstractType=[[false],[false]])
return Tuple{Float64, Float64, Float64,}
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "Array{HydroPartType,1}""
##### Optional Keywords:
- **`unit`:** the unit of the result (can be used w/o keyword): :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`mask`:** needs to be of type MaskArrayAbstractType which contains two entries with supertype of Array{Bool,1} or BitArray{1} and the length of the database (rows)
"""
function com(dataobject::Array{HydroPartType,1}, unit::Symbol; mask::MaskArrayAbstractType=[[false],[false]])
return center_of_mass(dataobject, unit, mask=mask)
end
function com(dataobject::Array{HydroPartType,1}; unit::Symbol=:standard, mask::MaskArrayAbstractType=[[false],[false]])
return center_of_mass(dataobject, unit=unit, mask=mask)
end
function average_mweighted(dataobject::ContainMassDataSetType, var::Symbol; mask::MaskType=[false])
return sum( getvar(dataobject, var, mask=mask) .* getvar(dataobject, :mass, mask=mask) ) ./ sum( getvar(dataobject, :mass, mask=mask))
end
"""
#### Calculate the average velocity (w/o mass-weight) of any ContainMassDataSetType:
```julia
bulk_velocity(dataobject::ContainMassDataSetType; unit::Symbol=:standard, weighting::Symbol=:mass, mask::MaskType=[false])
return Tuple{Float64, Float64, Float64,}
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "ContainMassDataSetType"
##### Optional Keywords:
- **`unit`:** the unit of the result (can be used w/o keyword): :standard (code units) :km_s, :m_s, :cm_s (of typye Symbol) ..etc. ; see for defined velocity-scales viewfields(info.scale)
- **`weighting`:** use different weightings: :mass (default), :volume (hydro), :no
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
"""
function bulk_velocity(dataobject::ContainMassDataSetType, unit::Symbol; weighting::Symbol=:mass, mask::MaskType=[false])
return bulk_velocity(dataobject, unit=unit, weighting=weighting, mask=mask)
end
function bulk_velocity(dataobject::ContainMassDataSetType; unit::Symbol=:standard, weighting::Symbol=:mass, mask::MaskType=[false])
selected_unit = getunit(dataobject.info, unit)
if weighting == :mass
return ( average_mweighted(dataobject, :vx, mask=mask), average_mweighted(dataobject, :vy, mask=mask), average_mweighted(dataobject, :vz, mask=mask) ) .* selected_unit
elseif weighting == :volume && typeof(dataobject) == HydroDataType
isamr = checkuniformgrid(dataobject, dataobject.lmax)
if isamr
return ( sum( getvar(dataobject, :vx, mask=mask) .* getvar(dataobject, :volume, mask=mask) ) ./ sum( getvar(dataobject, :volume, mask=mask) ),
sum( getvar(dataobject, :vy, mask=mask) .* getvar(dataobject, :volume, mask=mask) ) ./ sum( getvar(dataobject, :volume, mask=mask) ),
sum( getvar(dataobject, :vz, mask=mask) .* getvar(dataobject, :volume, mask=mask) ) ./ sum( getvar(dataobject, :volume, mask=mask) ) ) .* selected_unit
else
return ( mean( getvar(dataobject, :vx, mask=mask) ), mean( getvar(dataobject, :vy, mask=mask) ), mean( getvar(dataobject, :vz, mask=mask)) ) .* selected_unit
end
elseif weighting == :no # for AMR
return ( mean( getvar(dataobject, :vx, mask=mask) ), mean( getvar(dataobject, :vy, mask=mask) ), mean( getvar(dataobject, :vz, mask=mask)) ) .* selected_unit
end
end
"""
#### Calculate the average velocity (w/o mass-weight) of any ContainMassDataSetType:
```julia
average_velocity(dataobject::ContainMassDataSetType; unit::Symbol=:standard, weighting::Symbol=:mass, mask::MaskType=[false])
return Tuple{Float64, Float64, Float64,}
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "ContainMassDataSetType"
##### Optional Keywords:
- **`unit`:** the unit of the result (can be used w/o keyword): :standard (code units) :km_s, :m_s, :cm_s (of typye Symbol) ..etc. ; see for defined velocity-scales viewfields(info.scale)
- **`weighting`:** use different weightings: :mass (default), :volume (hydro), :no
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
"""
function average_velocity(dataobject::ContainMassDataSetType, unit::Symbol; weighting::Symbol=:mass, mask::MaskType=[false])
return bulk_velocity(dataobject, unit, weighting=weighting, mask=mask)
end
function average_velocity(dataobject::ContainMassDataSetType; unit::Symbol=:standard, weighting::Symbol=:mass, mask::MaskType=[false])
return bulk_velocity(dataobject, unit=unit, weighting=weighting, mask=mask)
end
"""
#### Calculate statistical values w/o weighting of any Array:
```julia
wstat(array::Array{<:Real,1}; weight::Array{<:Real,1}=[1.], mask::MaskType=[false])
WStatType(mean, median, std, skewness, kurtosis, min, max)
```
#### Arguments
##### Required:
- **`array`:** Array needs to be of type: "<:Real"
##### Optional Keywords:
- **`weight`:** Array needs to be of type: "<:Real" (can be used w/o keyword)
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the Array
"""
function wstat(array::Array{<:Real,1}, weight::Array{<:Real,1}; mask::MaskType=[false])
return wstat(array, weight=weight, mask=mask)
end
function wstat(array::Array{<:Real,1}; weight::Array{<:Real,1}=[1.], mask::MaskType=[false])
if length(mask) > 1
array=array[mask]
if length(weight) > 1
weight=weight[mask]
end
end
if length(weight)==1
mean_ = mean(array)
median_ = median(array)
std_ = std(array, mean=mean_)
skewness_ = skewness(array, mean_)
kurtosis_ = kurtosis(array, mean_)
min_ = minimum(array)
max_ = maximum(array)
return WStatType(mean_, median_, std_, skewness_, kurtosis_, min_, max_)
else length(weight) > 1
mean_ = mean( array, weights( weight ))
median_ = median(array, weights( weight ))
std_ = std(array, mean=mean_, weights( weight ), corrected=false)
skewness_ = skewness(array, mean_)
kurtosis_ = kurtosis(array, mean_)
min_ = minimum(array)
max_ = maximum(array)
return WStatType(mean_, median_, std_, skewness_, kurtosis_, min_, max_)
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2349 | function checkfortype(dataobject::InfoType, datatype::Symbol)
if !dataobject.hydro && datatype==:hydro
error("[Mera]: Simulation has no hydro files!")
elseif !dataobject.amr && datatype==:amr
error("[Mera]: Simulation has no amr files!")
elseif !dataobject.gravity && datatype==:gravity
error("[Mera]: Simulation has no gravity files!")
elseif !dataobject.rt && datatype==:rt
error("[Mera]: Simulation has no rt files!")
elseif !dataobject.particles && datatype==:particles
error("[Mera]: Simulation has no particle files!")
elseif !dataobject.clumps && datatype==:clumps
error("[Mera]: Simulation has no clump files!")
elseif !dataobject.sinks && datatype==:sinks
error("[Mera]: Simulation has no sink files!")
end
end
function checklevelmax(dataobject::InfoType, lmax::Real)
if dataobject.levelmax < lmax
error("[Mera]: Simulation lmax=$(dataobject.levelmax) < your lmax=$lmax")
elseif lmax < dataobject.levelmin
error("[Mera]: Simulation lmin=$(dataobject.levelmin) > your lmin=$lmax")
end
end
# use lmax in case user forces to load a uniform grid from amr data (lmax=levelmin)
function checkuniformgrid(dataobject::InfoType, lmax::Real)
isamr = true
if lmax == dataobject.levelmin
isamr = false
end
return isamr
end
function checkuniformgrid(dataobject::DataSetType, lmax::Real)
isamr = true
if lmax == dataobject.info.levelmin
isamr = false
end
return isamr
end
# global verbose mode ===========================
function checkverbose(verbose::Bool)
if verbose_mode != nothing
verbose = copy(verbose_mode)
end
return verbose
end
function verbose(mode::Union{Bool,Nothing})
global verbose_mode = mode
@eval(Mera, verbose_mode)
end
function verbose()
println("verbose_mode: ", verbose_mode)
end
# global showprogress mode ===========================
function checkprogress(show_progress::Bool)
if showprogress_mode != nothing
show_progress = copy(showprogress_mode)
end
return show_progress
end
function showprogress(mode::Union{Bool,Nothing})
global showprogress_mode = mode
@eval(Mera, showprogress_mode)
end
function showprogress()
println("showprogress_mode: ", showprogress_mode)
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 16054 | """
#### Converts full simulation data into a compressed/uncompressed JLD2 format:
- all existing datatypes are sequentially loaded and stored
- supports :hydro, :particles, :hydro, :clumps
- running number is taken from original RAMSES folders
- use different compression methods
- select a certain data range, smallr, smallc, lmax
- add a string to describe the simulation
- the individual loading and storing processes are timed and stored into the file (and more statistics)
- toggle progressbar mode
- toggle verbose mode
```julia
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::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
smallr::Real=0.,
smallc::Real=0.,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return statistics (dictionary)
```
#### Arguments
##### Required:
- **`output`:** output number
##### Predefined/Optional Keywords:
- **`datatypes`:** default -> all available (known) data is converted; pass an array with only selected datatypes, e.g.: datatypes=[:hydro, :particles]
- **`fname`:** default name of the files "output_" and the running number is added. Change the string to apply a user-defined name.
- **`compress`:** by default compression is activated. compress=false (deactivate).
If necessary, choose between different compression types: LZ4FrameCompressor() (default), Bzip2Compressor(), ZlibCompressor().
Load the required package to choose the compression type and to see their parameters: CodecZlib, CodecBzip2 or CodecLz4
- **`comments`:** add a string that includes e.g. a description about your simulation
- **`lmax`:** the maximum level to be read from the data
- **`path`:** path to the RAMSES folders; default is local path.
- **`fpath`:** path to the JLD23 file; default is local path.
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`smallr`:** set lower limit for density; zero means inactive
- **`smallc`:** set lower limit for thermal pressure; zero means inactive
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of xrange, yrange, zrange, center, range_unit, verbose
- **`verbose`:** print timestamp and further information on screen; default: true
### Defined Methods - function defined for different arguments
- convertdata(output::Int64; ...)
- convertdata(output::Int64, datatypes::Vector{Symbol}; ...)
- convertdata(output::Int64, datatypes::Symbol; ...)
"""
function convertdata(output::Int, datatypes::Array{Symbol, 1};
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::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
smallr::Real=0.,
smallc::Real=0.,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return convertdata(output, datatypes=datatypes,
path=path, fpath=fpath,
fname = fname,
compress=compress,
comments=comments,
lmax=lmax,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
smallr=smallr,
smallc=smallc,
verbose=verbose,
show_progress=show_progress,
myargs=myargs )
end
function convertdata(output::Int, datatypes::Symbol; 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::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
smallr::Real=0.,
smallc::Real=0.,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return convertdata(output, datatypes=[datatypes],
path=path, fpath=fpath,
fname = fname,
compress=compress,
comments=comments,
lmax=lmax,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
smallr=smallr,
smallc=smallc,
verbose=verbose,
show_progress=show_progress,
myargs=myargs )
end
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::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
smallr::Real=0.,
smallc::Real=0.,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
# take values from myargs if given
if !(myargs.lmax === missing) lmax = myargs.lmax end
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
if !(myargs.show_progress === missing) show_progress = myargs.show_progress end
verbose = checkverbose(verbose)
show_progress = checkprogress(show_progress)
printtime("",verbose)
if length(datatypes) == 1 && datatypes[1] === missing || length(datatypes) == 0 || length(datatypes) == 1 && datatypes[1] == :all
datatypes = [:hydro, :gravity, :particles, :clumps]
else
if !(:hydro in datatypes) && !(:gravity in datatypes) && !(:particles in datatypes) && !(:clumps in datatypes)
error("unknown datatype(s) given...")
end
end
if verbose
println("Requested datatypes: ", datatypes)
println()
end
memtot = 0.
storage_tot = 0.
overview = Dict()
rw = Dict()
mem = Dict()
lt = TimerOutput() # timer for loading data
wt = TimerOutput() # timer for writing data
info = getinfo(output, path, verbose=false)
if lmax === missing lmax = info.levelmax end
si = storageoverview(info, verbose=false)
#------------------
# convert given ranges and print overview on screen
ranges = prepranges(info, range_unit, verbose, xrange, yrange, zrange, center)
#------------------
# reading =============================
if verbose
ctype = check_compression(compress, true)
println()
println("reading/writing lmax: ", lmax, " of ", info.levelmax)
println("-----------------------------------")
println("Compression: ", ctype)
println("-----------------------------------")
end
first_amrflag = true
first_flag = true
if info.hydro && :hydro in datatypes
if verbose println("- hydro") end
@timeit lt "hydro" gas = gethydro(info, lmax=lmax, smallr=smallr,
smallc=smallc,
xrange=xrange, yrange=yrange, zrange=zrange,
center=center, range_unit=range_unit,
verbose=false, show_progress=show_progress)
memtot += Base.summarysize(gas)
storage_tot += si[:hydro]
if first_amrflag
storage_tot += si[:amr]
first_amrflag = false
end
# write
first_flag, fmode = JLD2flag(first_flag)
@timeit wt "hydro" savedata(gas, path=fpath, fname=fname,
fmode=fmode, compress=compress,
comments=comments, verbose=false)
# clear mem
gas = 0.
end
if info.gravity && :gravity in datatypes
if verbose println("- gravity") end
@timeit lt "gravity" grav = getgravity(info, lmax=lmax,
xrange=xrange, yrange=yrange, zrange=zrange,
center=center, range_unit=range_unit,
verbose=false, show_progress=show_progress)
memtot += Base.summarysize(grav)
storage_tot += si[:gravity]
if first_amrflag
storage_tot += si[:amr]
first_amrflag = false
end
# write
first_flag, fmode = JLD2flag(first_flag)
@timeit wt "gravity" savedata(grav, path=fpath, fname=fname,
fmode=fmode, compress=compress,
comments=comments, verbose=false)
# clear mem
grav = 0.
end
if info.particles && :particles in datatypes
if verbose println("- particles") end
@timeit lt "particles" part = getparticles(info,
xrange=xrange, yrange=yrange, zrange=zrange,
center=center, range_unit=range_unit,
verbose=false, show_progress=show_progress)
memtot += Base.summarysize(part)
storage_tot += si[:particle]
if first_amrflag
storage_tot += si[:amr]
first_amrflag = false
end
# write
first_flag, fmode = JLD2flag(first_flag)
@timeit wt "particles" savedata(part, path=fpath, fname=fname,
fmode=fmode, compress=compress,
comments=comments, verbose=false)
# clear mem
part = 0.
end
if info.clumps && :clumps in datatypes
if verbose println("- clumps") end
@timeit lt "clumps" clumps = getclumps(info,
xrange=xrange, yrange=yrange, zrange=zrange,
center=center, range_unit=range_unit,
verbose=false)
memtot += Base.summarysize(clumps)
storage_tot += si[:clump]
# write
first_flag, fmode = JLD2flag(first_flag)
@timeit wt "clumps" savedata(clumps, path=fpath, fname=fname,
fmode=fmode, compress=compress,
comments=comments, verbose=false)
# clear mem
clumps = 0.
end
#
# # writing =============================
# if verbose
# println()
# println("writing:")
# end
#
#
# first_flag = true
# if info.hydro && :hydro in datatypes
# if verbose println("- hydro") end
# first_flag, fmode = JLD2flag(first_flag)
# @timeit wt "hydro" savedata(gas, path=fpath, fname=fname, fmode=fmode, verbose=false)
#
# end
#
# if info.gravity && :gravity in datatypes
# if verbose println("- gravity") end
# first_flag, fmode = JLD2flag(first_flag)
# @timeit wt "gravity" savedata(grav, path=fpath, fname=fname, fmode=fmode, verbose=false)
#
# end
#
# if info.particles && :particles in datatypes
# if verbose println("- particles") end
# first_flag, fmode = JLD2flag(first_flag)
# @timeit wt "particles" savedata(part, path=fpath, fname=fname, fmode=fmode, verbose=false)
#
# end
#
# if info.clumps && :clumps in datatypes
# if verbose println("- clumps") end
# first_flag, fmode = JLD2flag(first_flag)
# @timeit wt "clumps" savedata(clumps, path=fpath, fname=fname, fmode=fmode, verbose=false)
# end
# return =============================
icpu= info.output
filename = outputname(fname, icpu) * ".jld2"
fullpath = checkpath(fpath, filename)
s = filesize(fullpath)
foldersize = si[:folder]
mem["folder"] = [foldersize, "Bytes"]
mem["selected"] = [storage_tot, "Bytes"]
mem["used"] = [memtot, "Bytes"]
mem["ondisc"] = [s, "Bytes"]
if verbose
fvalue, funit = humanize(Float64(foldersize), 3, "memory")
ovalue, ounit = humanize(Float64(storage_tot), 3, "memory")
mvalue, munit = humanize(Float64(memtot), 3, "memory")
svalue, sunit = humanize(Float64(s), 3, "memory")
println()
println("Total datasize:")
println("- total folder: ", fvalue, " ", funit)
println("- selected: ", ovalue, " ", ounit)
println("- used: ", mvalue, " ", munit)
println("- new on disc: ", svalue, " ", sunit)
end
rw["reading"] = lt
rw["writing"] = wt
overview["TimerOutputs"] = rw
overview["viewdata"] = viewdata(output, path=fpath, fname=fname, verbose=false)
overview["size"] = mem
jld2mode = "a+" # append
jldopen(fullpath, jld2mode) do f
f["convertstat"] = overview
end
return overview
end
function JLD2flag(first_flag::Bool)
if first_flag
fmode=:write
first_flag=false
else
fmode=:append
end
return first_flag, fmode
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 4139 | """
#### Get the simulation overview from RAMSES, saved in JLD2 == function getinfo
```julia
infodata(output::Int;
path::String="./",
fname = "output_",
datatype::Any=:nothing,
verbose::Bool=true)
return InfoType
```
#### Keyword Arguments
- **`output`:** timestep number
- **`path`:** the path to the output JLD2 file relative to the current folder or absolute path
- **`fname`:** "output_"-> filename = "output_***.jld2" by default, can be changed to "myname***.jld2"
- **`verbose:`:** informations are printed on the screen by default
#### Examples
```julia
# 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)
...
```
"""
function infodata(output::Int, datatype::Symbol;
path::String="./",
fname = "output_",
verbose::Bool=true)
return infodata(output, path=path,
fname=fname,
datatype=datatype,
verbose=verbose)
end
function infodata(output::Int, path::String, datatype::Symbol;
fname = "output_",
verbose::Bool=true)
return infodata(output, path=path,
fname=fname,
datatype=datatype,
verbose=verbose)
end
function infodata(output::Int, path::String;
fname = "output_",
datatype::Any=:nothing,
verbose::Bool=true)
return infodata(output, path=path,
fname=fname,
datatype=datatype,
verbose=verbose)
end
function infodata(output::Int;
path::String="./",
fname = "output_",
datatype::Any=:nothing,
verbose::Bool=true)
verbose = checkverbose(verbose)
printtime("",verbose)
filename = outputname(fname, output) * ".jld2"
fpath = checkpath(path, filename)
# get root-list with datatypes
#filename = fpath * "L1_Zlib_0019.jld2"
f = jldopen(fpath)
froot = f.root_group
fkeys = keys(froot.written_links)
close(f)
# check if request exists
if datatype == :nothing
find_dt_flag = true
if "hydro" in fkeys && find_dt_flag
dtype = "hydro"
find_dt_flag = false
end
if "particles" in fkeys && find_dt_flag
dtype = "particles"
find_dt_flag = false
end
if "clumps" in fkeys && find_dt_flag
dtype = "clumps"
find_dt_flag = false
end
if "gravity" in fkeys && find_dt_flag
dtype = "gravity"
find_dt_flag = false
end
if find_dt_flag
error("No datatype found...")
end
else
if string(datatype) in fkeys
dtype = string(datatype)
else
error("Datatype $datatype does not exist...")
end
end
if verbose println("Use datatype: ", dtype) end
inflink = string(dtype) * "/info"
dataobject = JLD2.load(fpath, inflink,
typemap=Dict("Mera.PhysicalUnitsType" => JLD2.Upgrade(PhysicalUnitsType001),
"Mera.ScalesType" => JLD2.Upgrade(ScalesType001)))
# update constants and scales
dataobject.constants = Mera.createconstants()
dataobject.scale = Mera.createscales(dataobject)
printsimoverview(dataobject, verbose) # print overview on screen
return dataobject
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 7876 | """
#### Read stored simulation data into a dataobject:
- supported datatypes: HydroDataType, PartDataType, GravDataType, ClumpDataType
- select a certain data range (data is fully loaded; the selected subregion is returned)
- toggle verbose mode
```julia
function loaddata(output::Int; path::String="./",
fname = "output_",
datatype::Symbol,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
verbose::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return dataobject
```
#### Arguments
##### Required:
- **`output`:** output number
- **`datatype`:** :hydro, :particles, :gravity or :clumps
##### Predefined/Optional Keywords:
- **`path`:** path to the file; default is local path.
- **`fname`:** default name of the files "output_" and the running number is added. Change the string to apply a user-defined name.
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of xrange, yrange, zrange, center, range_unit, verbose
- **`verbose`:** print timestamp and further information on screen; default: true
### Defined Methods - function defined for different arguments
- loaddata(output::Int64; ...) # opens first datatype in the file
- loaddata(output::Int64, datatype::Symbol; ...)
- loaddata(output::Int64, path::String; ...)
- loaddata(output::Int64, path::String, datatype::Symbol; ...)
"""
function loaddata(output::Int, datatype::Symbol;
path::String="./",
fname = "output_",
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
verbose::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return loaddata(output, path=path,
fname=fname,
datatype=datatype,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
verbose=verbose,
myargs=myargs )
end
function loaddata(output::Int, path::String, datatype::Symbol;
fname = "output_",
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
verbose::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return loaddata(output, path=path,
fname=fname,
datatype=datatype,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
verbose=verbose,
myargs=myargs )
end
function loaddata(output::Int, path::String;
fname = "output_",
datatype::Symbol,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
verbose::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return loaddata(output, path=path,
fname=fname,
datatype=datatype,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
verbose=verbose,
myargs=myargs )
end
function loaddata(output::Int; path::String="./",
fname = "output_",
datatype::Symbol,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
verbose::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
# take values from myargs if given
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
printtime("",verbose)
filename = outputname(fname, output) * ".jld2"
fpath = checkpath(path, filename)
if verbose
println("Open Mera-file $filename:")
println()
end
info = infodata(output, path=path,
fname = fname,
datatype=datatype,
verbose=false)
#------------------
# convert given ranges and print overview on screen
ranges = prepranges(info, range_unit, verbose, xrange, yrange, zrange, center)
#------------------
# get root-list with datatypes
f = jldopen(fpath)
froot = f.root_group
fkeys = keys(froot.written_links)
close(f)
# todo: check if request exists
dlink = string(datatype) * "/data"
dataobject = JLD2.load(fpath, dlink,
typemap=Dict("Mera.PhysicalUnitsType" => JLD2.Upgrade(PhysicalUnitsType001),
"Mera.ScalesType" => JLD2.Upgrade(ScalesType001)))
# update constants and scales
dataobject.info.constants = Mera.createconstants()
dataobject.info.scale = Mera.createscales(dataobject.info)
dataobject.scale = dataobject.info.scale
# filter selected data region
dataobject = subregion(dataobject, :cuboid,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
verbose=false)
printtablememory(dataobject, verbose)
return dataobject
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 11225 | """
#### Save loaded simulation data into a compressed/uncompressed JLD2 format:
- write new file; add datatype to existing file
- running number is taken from original RAMSES folders
- use different compression methods
- add a string to describe the simulation
- toggle verbose mode
```julia
function savedata( dataobject::DataSetType;
path::String="./",
fname = "output_",
fmode::Any=nothing,
dataformat::Symbol=:JLD2,
compress::Any=nothing,
comments::Any=nothing,
merafile_version::Float64=1.,
verbose::Bool=true)
return
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "HydroDataType", "PartDataType", "GravDataType", "ClumpDataType"
- **`fmode`:** nothing is written/appended by default to avoid overwriting files by accident. Need: fmode=:write (new file or overwriting existing file); fmode=:append further datatype. (overwriting of existing datatypes is not possible)
##### Predefined/Optional Keywords:
- **`path`:** path to save the file; default is local path.
- **`fname`:** default name of the files "output_" and the running number is added. Change the string to apply a user-defined name.
- **`dataformat`:** currently, only JLD2 can be selected.
- **`compress`:** by default compression is activated. compress=false (deactivate).
If necessary, choose between different compression types: LZ4FrameCompressor() (default), Bzip2Compressor(), ZlibCompressor().
Load the required package to choose the compression type and to see their parameters: CodecZlib, CodecBzip2 or CodecLz4
- **`comments`:** add a string that includes e.g. a description about your simulation
- **`merafile_version`:** default: 1.; current only version
- **`verbose`:** print timestamp and further information on screen; default: true
### Defined Methods - function defined for different arguments
- savedata( dataobject::DataSetType; ...) # note: fmode needs to be given for action!
- savedata( dataobject::DataSetType, fmode::Symbol; ...)
- savedata( dataobject::DataSetType, path::String; ...)
- savedata( dataobject::DataSetType, path::String, fmode::Symbol; ...)
"""
function savedata( dataobject::DataSetType, fmode::Symbol;
path::String="./",
fname = "output_",
dataformat::Symbol=:JLD2,
compress::Any=nothing,
comments::Any=nothing,
merafile_version::Float64=1.,
verbose::Bool=true)
return savedata( dataobject,
path=path,
fname=fname,
fmode=fmode,
dataformat=dataformat,
compress=compress,
comments=comments,
merafile_version=merafile_version,
verbose=verbose)
end
function savedata( dataobject::DataSetType, path::String, fmode::Symbol;
fname = "output_",
dataformat::Symbol=:JLD2,
compress::Any=nothing,
comments::Any=nothing,
merafile_version::Float64=1.,
verbose::Bool=true)
return savedata( dataobject,
path=path,
fname=fname,
fmode=fmode,
dataformat=dataformat,
compress=compress,
comments=comments,
merafile_version=merafile_version,
verbose=verbose)
end
function savedata( dataobject::DataSetType, path::String;
fname = "output_",
fmode::Any=nothing,
dataformat::Symbol=:JLD2,
compress::Any=nothing,
comments::Any=nothing,
merafile_version::Float64=1.,
verbose::Bool=true)
return savedata( dataobject,
path=path,
fname=fname,
fmode=fmode,
dataformat=dataformat,
compress=compress,
comments=comments,
merafile_version=merafile_version,
verbose=verbose)
end
function savedata( dataobject::DataSetType;
path::String="./",
fname = "output_",
fmode::Any=nothing,
dataformat::Symbol=:JLD2,
compress::Any=nothing,
comments::Any=nothing,
merafile_version::Float64=1.,
verbose::Bool=true)
verbose = checkverbose(verbose)
printtime("",verbose)
datatype, use_descriptor, descriptor_names = check_datasource(dataobject)
icpu= dataobject.info.output
filename = outputname(fname, icpu) * ".jld2"
fpath = checkpath(path, filename)
fexist, wdata, jld2mode = check_file_mode(fmode, datatype, path, filename, verbose)
ctype = check_compression(compress, wdata)
column_names = propertynames(dataobject.data.columns)
if verbose
println("Directory: ", dataobject.info.path )
println("-----------------------------------")
println("merafile_version: ", merafile_version, " - Simulation code: ", dataobject.info.simcode)
println("-----------------------------------")
println("DataType: ", datatype, " - Data variables: ", column_names)
if use_descriptor
println("Descriptor: ", descriptor_names)
end
println("-----------------------------------")
println("I/O mode: ", fmode, " - Compression: ", ctype)
println("-----------------------------------")
end
if wdata
jldopen(fpath, jld2mode; compress = ctype) do f
#mygroup = JLD2.Group(f, string(datatype))
dt = string(datatype)
#myinfgroup = JLD2.Group(mygroup, "information")
df = "/information/"
f[dt * df * "compression"] = ctype
f[dt * df * "comments"] = comments
f[dt * df * "versions/merafile_version"] = merafile_version
f[dt * df * "versions/JLD2compatible_versions"] = JLD2.COMPATIBLE_VERSIONS
pkg = Pkg.dependencies()
check_pkg = ["Mera","JLD2", "CodecZlib", "CodecBzip2", "CodecLz4"]
for i in keys(pkg)
ipgk = pkg[i]
if ipgk.name in check_pkg
if ipgk.is_tracking_repo
f[dt * df * "versions/" * ipgk.name] = [ipgk.version, ipgk.git_source]
else
f[dt * df * "versions/" * ipgk.name] = [ipgk.version]
end
if verbose
if ipgk.is_tracking_repo
println(ipgk.name, " ", ipgk.version, " ", ipgk.git_source)
else
println(ipgk.name, " ", ipgk.version)
end
end
end
end
f[dt * df * "storage"] = storageoverview(dataobject.info, verbose=false)
f[dt * df * "memory"] = usedmemory(dataobject, false)
#mydatagroup = JLD2.Group(mygroup, "data")
f[dt * "/data"] = dataobject
f[dt * "/info"] = dataobject.info
end
end
if verbose
println("-----------------------------------")
mem = usedmemory(dataobject, false)
println("Memory size: ", round(mem[1], digits=3)," ", mem[2], " (uncompressed)")
s = filesize(fpath)
svalue, sunit = humanize(Float64(s), 3, "memory")
if wdata println("Total file size: ", svalue, " ", sunit) end
println("-----------------------------------")
println()
end
return
end
function outputname(fname::String, icpu::Int)
if icpu < 10
return string(fname, "0000", icpu)
elseif icpu < 100 && icpu > 9
return string(fname, "000", icpu)
elseif icpu < 1000 && icpu > 99
return string(fname, "00", icpu)
elseif icpu < 10000 && icpu > 999
return string(fname, "0", icpu)
elseif icpu < 100000 && icpu > 9999
return string(fname, icpu)
end
end
function check_file_mode(fmode::Any, datatype::Symbol, fullpath::String, fname::String, verbose::Bool)
if verbose println() end
jld2mode = ""
if fmode in [nothing]
wdata = false
else
wdata = true
if fmode == :write
jld2mode = "w"
elseif fmode == :append
jld2mode = "a+"
else
error("Unknown fmode...")
end
end
if !isfile(fullpath) && wdata && verbose
println("Create file: ", fname)
fexist = false
elseif !wdata && !isfile(fullpath) && verbose
println("Not existing file: ", fname)
fexist = false
else
if verbose println("Existing file: ", fname) end
fexist = true
end
return fexist, wdata, jld2mode
end
function check_compression(compress, wdata)
if compress == nothing && wdata
ctype = LZ4FrameCompressor() #ZlibCompressor(level=9)
elseif typeof(compress) == ZlibCompressor && wdata
ctype = compress
elseif typeof(compress) == Bzip2Compressor && wdata
ctype = compress
elseif typeof(compress) == LZ4FrameCompressor && wdata
ctype = compress
elseif compress == false || !wdata
ctype = :nothing
end
return ctype
end
function checkpath(path, filename)
if path == "./"
fpath = path * filename
elseif path == "" || path == " "
fpath = filename
else
if string(path[end]) == "/"
fpath = path * filename
else
fpath = path * "/" * filename
end
end
return fpath
end
function check_datasource(dataobject::DataSetType)
if typeof(dataobject) == HydroDataType
datatype = :hydro
use_descriptor = dataobject.info.descriptor.usehydro
descriptor_names = dataobject.info.descriptor.hydro
elseif typeof(dataobject) == GravDataType
datatype = :gravity
use_descriptor = dataobject.info.descriptor.usegravity
descriptor_names = dataobject.info.descriptor.gravity
elseif typeof(dataobject) == PartDataType
datatype = :particles
use_descriptor = dataobject.info.descriptor.useparticles
descriptor_names = dataobject.info.descriptor.particles
elseif typeof(dataobject) == ClumpDataType
datatype = :clumps
use_descriptor = dataobject.info.descriptor.useclumps
descriptor_names = dataobject.info.descriptor.clumps
end
return datatype, use_descriptor, descriptor_names
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 5075 | """
#### Get overview of stored datatypes:
- compression
- versions of the used/loaded compression
- MERA/MERA-file version
- compressed/uncompressed data size
- returns stored conversion statistics, when available (created by convertdata-function)
```julia
function viewdata(output::Int;
path::String="./",
fname = "output_",
showfull::Bool=false,
verbose::Bool=true)
return overview (dictionary)
```
#### Arguments
##### Required:
- **`output`:** output number
- **`datatype`:** :hydro, :particles, :gravity or :clumps
##### Predefined/Optional Keywords:
- **`path`:** the path to the output JLD2 file relative to the current folder or absolute path
- **`fname`:** "output_"-> filename = "output_***.jld2" by default, can be changed to "myname***.jld2"
- **`showfull`:** shows the full data tree of the datafile
- **`verbose:`:** informations are printed on the screen by default
"""
function viewdata(output::Int, path::String;
fname = "output_",
showfull::Bool=false,
verbose::Bool=true)
return viewdata(output, path=path,
fname=fname,
showfull=showfull,
verbose=verbose)
end
# todo : simulation code
# check known types
function viewdata(output::Int;
path::String="./",
fname = "output_",
showfull::Bool=false,
verbose::Bool=true)
verbose = checkverbose(verbose)
printtime("",verbose)
filename = outputname(fname, output) * ".jld2"
fpath = checkpath(path, filename)
if verbose
println("Mera-file $filename contains:")
println()
end
if showfull
f = jldopen(fpath, "r"; )
printtoc(f)
close(f)
println()
println()
end
# get root-list with datatypes
#filename = fpath * "L1_Zlib_0019.jld2"
f = jldopen(fpath)
froot = f.root_group
fkeys = keys(froot.written_links)
close(f)
# get information/versions-list of each datatype
ikeys = Dict() # information keys
vkeys = Dict() # versions keys
for rname in fkeys
if rname != "_types" && rname in string.([:hydro, :gravity, :particles, :clumps])
#println(rname)
ilink = rname * "/information"
ifk = JLD2.load(fpath, ilink)
ikeys[rname] = keys(ifk)
#println(ikeys[rname])
vlink = ilink * "/versions"
vfk = JLD2.load(fpath, vlink)
vkeys[rname] = keys(vfk)
#println(vkeys[rname])
#println()
end
end
# load information/versions into dictionary of each datatype
viewoutput = Dict()
convertstat = false
for rname in fkeys
if rname != "_types" && rname in string.([:hydro, :gravity, :particles, :clumps])
idata = Dict()
vdata = Dict()
for i in ikeys[rname]
if i != "versions"
ilink = rname * "/information/" * i
idata[i] = JLD2.load(fpath, ilink)
end
end
for v in vkeys[rname]
vlink = rname * "/information/" * "versions/" * v
vdata[v] = JLD2.load(fpath, vlink)
end
idata["versions"] = vdata
viewoutput[rname] = idata
elseif rname == "convertstat"
convertstat = JLD2.load(fpath, rname)
end
end
# print overview
if verbose
for i in keys(viewoutput)
iroot = viewoutput[i]
println("Datatype: ", i)
println("merafile_version: ", iroot["versions"]["merafile_version"])
println("Compression: ", iroot["compression"])
for v in keys(iroot["versions"])
iversions = iroot["versions"][v]
println(v, ": ", iversions)
end
println("-------------------------")
mem = iroot["memory"]
println("Memory: ", mem[1], " ", mem[2], " (uncompressed)")
println()
println()
end
end
s = filesize(fpath)
svalue, sunit = humanize(Float64(s), 3, "memory")
viewoutput["FileSize"] = (svalue, sunit)
if verbose
println("-----------------------------------")
if convertstat != false
println("convert stat: true")
else
println("convert stat: false")
end
println("-----------------------------------")
println("Total file size: ", svalue, " ", sunit)
println("-----------------------------------")
println()
end
if convertstat != false
viewoutput["convertstat"] = convertstat
end
#close(file)
return viewoutput
end
# function known_datatype(datatype::Symbol)
# knowntypes = [:hydro, :gravity, :particles, :clumps]
# if in(datatype, knowntypes)
# return true
# else
# return false
# end
# end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 18908 |
function getvar()
println("Predefined vars that can be calculated for each cell/particle:")
println("----------------------------------------------------------------")
println("=============================[gas]:=============================")
println(" -all the non derived hydro vars-")
println(":cpu, :level, :rho, :cx, :cy, :cz, :vx, :vy, :vz, :p, var6,...")
println()
println(" -derived hydro vars-")
println(":x, :y, :z")
println(":mass, :cellsize, :volume, :freefall_time")
println(":cs, :mach, :jeanslength, :jeansnumber")
println(":T, :Temp, :Temperature with p/rho")
println()
println(":h, :hx, :hy, :hz (specific angular momentum)")
println()
println("==========================[particles]:==========================")
println(" -all the non derived particle vars-")
println(":cpu, :level, :id, :family, :tag ")
println(":x, :y, :z, :vx, :vy, :vz, :mass, :birth, :metal....")
println()
println(" -derived particle vars-")
println(":age")
println()
println("===========================[gravity]:===========================")
println(" -all the non derived gravity vars-")
println(":cpu, :level, cx, cy, cz, :epot, :ax, :ay, :az")
println()
println(" -derived gravity vars-")
println(":x, :y, :z")
println(":cellsize, :volume")
println()
println("===========================[clumps]:===========================")
println(":peak_x or :x, :peak_y or :y, :peak_z or :z")
println(":v, :ekin,...")
println()
#println("===========================[sinks]:============================")
println("=====================[gas or particles]:=======================")
println(":v, :ekin")
println()
println("related to a given center:")
println("---------------------------")
println(":r_cylinder, :r_sphere (radial components)")
println(":ϕ") # , :θ
println(":vr_cylinder") #, vr_sphere (radial components)")
println(":vϕ_cylinder") #", :vθ")
#println(":l, :lx, :ly, :lz :lr, :lϕ, :lθ (angular momentum)")
println("----------------------------------------------------------------")
return
end
"""
#### Get variables or derived quantities from the dataset:
- overview the list of predefined quantities with: getinfo()
- select variable(s) and their unit(s)
- give the spatial center (with units) of the data within the box (relevant e.g. for radius dependency)
- relate the coordinates to a direction (x,y,z)
- pass a modified database
- pass a mask to exclude elements (cells/particles/...) from the calculation
```julia
getvar( dataobject::DataSetType, var::Symbol;
filtered_db::JuliaDB.AbstractIndexedTable=JuliaDB.table([1]),
center::Array{<:Any,1}=[0.,0.,0.],
center_unit::Symbol=:standard,
direction::Symbol=:z,
unit::Symbol=:standard,
mask::MaskType=[false],
ref_time::Real=dataobject.info.time)
return Array{Float64,1}
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "DataSetType"
- **`var(s)`:** select a variable from the database or a predefined quantity (see field: info, function getvar(), dataobject.data)
##### Predefined/Optional Keywords:
- **`filtered_db`:** pass a filtered or manipulated database together with the corresponding DataSetType object (required argument)
- **`center`:** in units given by argument `center_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`center_unit`:** :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`direction`:** todo
- **`unit(s)`:** return the variable in given units
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
- **`ref_time`:** reference zero-time for particle age calculation
### Defined Methods - function defined for different arguments
- getvar( dataobject::DataSetType, var::Symbol; ...) # one given variable -> returns 1d array
- getvar( dataobject::DataSetType, var::Symbol, unit::Symbol; ...) # one given variable with its unit -> returns 1d array
- getvar( dataobject::DataSetType, vars::Array{Symbol,1}; ...) # several given variables -> array needed -> returns dictionary with 1d arrays
- getvar( dataobject::DataSetType, vars::Array{Symbol,1}, units::Array{Symbol,1}; ...) # several given variables and their corresponding units -> both arrays -> returns dictionary with 1d arrays
- getvar( dataobject::DataSetType, vars::Array{Symbol,1}, unit::Symbol; ...) # several given variables that have the same unit -> array for the variables and a single Symbol for the unit -> returns dictionary with 1d arrays
#### Examples
```julia
# read simulation information
julia> info = getinfo(420)
julia> gas = gethydro(info)
# Example 1: get the mass for each cell of the hydro data (1dim array)
mass1 = getvar(gas, :mass) # in [code units]
mass = getvar(gas, :mass) * gas.scale.Msol # scale the result from code units to solar masses
mass = getvar(gas, :mass, unit=:Msol) # unit calculation, provided by a keyword argument
mass = getvar(gas, :mass, :Msol) # unit calculation provided by an argument
# Example 2: get the mass and |v| (several variables) for each cell of the hydro data
quantities = getvar(gas, [:mass, :v]) # in [code units]
returns: Dict{Any,Any} with 2 entries:
:mass => [8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407e-7, 8…
:v => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 2.28274e-7, 2.…
quantities = getvar(gas, [:mass, :v], units=[:Msol, :km_s]) # unit calculation, provided by a keyword argument
quantities = getvar(gas, [:mass, :v], [:Msol, :km_s]) # unit calculation provided by an argument
# Example 3: get several variables in the same units by providing a single argument
quantities = getvar(gas, [:vx, :vy, :vz], :km_s)
...
"""
function getvar( dataobject::DataSetType, var::Symbol;
filtered_db::JuliaDB.AbstractIndexedTable=JuliaDB.table([1]),
center::Array{<:Any,1}=[0.,0.,0.],
center_unit::Symbol=:standard,
direction::Symbol=:z,
unit::Symbol=:standard,
mask::MaskType=[false],
ref_time::Real=dataobject.info.time)
center = center_in_standardnotation(dataobject.info, center, center_unit)
# construct corresponding DataSetType from filtered database to use the calculations below
if typeof(filtered_db) != IndexedTable{StructArrays.StructArray{Tuple{Int64},1,Tuple{Array{Int64,1}},Int64}}
dataobject = construct_datatype(filtered_db, dataobject);
end
return get_data(dataobject, [var], [unit], direction, center, mask, ref_time )
end
function getvar( dataobject::DataSetType, var::Symbol, unit::Symbol;
filtered_db::JuliaDB.AbstractIndexedTable=JuliaDB.table([1]),
center::Array{<:Any,1}=[0.,0.,0.],
center_unit::Symbol=:standard,
direction::Symbol=:z,
mask::MaskType=[false],
ref_time::Real=dataobject.info.time)
center = center_in_standardnotation(dataobject.info, center, center_unit)
# construct corresponding DataSetType from filtered database to use the calculations below
if typeof(filtered_db) != IndexedTable{StructArrays.StructArray{Tuple{Int64},1,Tuple{Array{Int64,1}},Int64}}
dataobject = construct_datatype(filtered_db, dataobject);
end
return get_data(dataobject, [var], [unit], direction, center, mask, ref_time )
end
function getvar( dataobject::DataSetType, vars::Array{Symbol,1}, units::Array{Symbol,1};
filtered_db::JuliaDB.AbstractIndexedTable=JuliaDB.table([1]),
center::Array{<:Any,1}=[0.,0.,0.],
center_unit::Symbol=:standard,
direction::Symbol=:z,
mask::MaskType=[false],
ref_time::Real=dataobject.info.time)
center = center_in_standardnotation(dataobject.info, center, center_unit)
# construct corresponding DataSetType from filtered database to use the calculations below
if typeof(filtered_db) != IndexedTable{StructArrays.StructArray{Tuple{Int64},1,Tuple{Array{Int64,1}},Int64}}
dataobject = construct_datatype(filtered_db, dataobject);
end
return get_data(dataobject, vars, units, direction, center, mask, ref_time )
end
function getvar( dataobject::DataSetType, vars::Array{Symbol,1}, unit::Symbol;
filtered_db::JuliaDB.AbstractIndexedTable=JuliaDB.table([1]),
center::Array{<:Any,1}=[0.,0.,0.],
center_unit::Symbol=:standard,
direction::Symbol=:z,
mask::MaskType=[false],
ref_time::Real=dataobject.info.time)
center = center_in_standardnotation(dataobject.info, center, center_unit)
units = fill(unit, length(vars)) # use given unit for all variables
# construct corresponding DataSetType from filtered database to use the calculations below
if typeof(filtered_db) != IndexedTable{StructArrays.StructArray{Tuple{Int64},1,Tuple{Array{Int64,1}},Int64}}
dataobject = construct_datatype(filtered_db, dataobject);
end
return get_data(dataobject, vars, units, direction, center, mask, ref_time )
end
function getvar( dataobject::DataSetType, vars::Array{Symbol,1};
filtered_db::JuliaDB.AbstractIndexedTable=JuliaDB.table([1]),
center::Array{<:Any,1}=[0.,0.,0.],
center_unit::Symbol=:standard,
direction::Symbol=:z,
units::Array{Symbol,1}=[:standard],
mask::MaskType=[false],
ref_time::Real=dataobject.info.time)
center = center_in_standardnotation(dataobject.info, center, center_unit)
# construct corresponding DataSetType from filtered database to use the calculations below
if typeof(filtered_db) != IndexedTable{StructArrays.StructArray{Tuple{Int64},1,Tuple{Array{Int64,1}},Int64}}
dataobject = construct_datatype(filtered_db, dataobject);
end
#vars = unique(vars)
return get_data(dataobject, vars, units, direction, center, mask, ref_time )
end
function center_in_standardnotation(dataobject::InfoType, center::Array{<:Any,1}, center_unit::Symbol)
# check for :bc, :boxcenter
Ncenter = length(center)
if Ncenter == 1
if in(:bc, center) || in(:boxcenter, center)
bc = 0.5
center = [bc, bc, bc]
end
else
for i = 1:Ncenter
if center[i] == :bc || center[i] == :boxcenter
bc = 0.5
center[i] = bc
elseif center_unit != :standard
center[i] = center[i] / dataobject.boxlen .* getunit(dataobject, center_unit)
end
end
end
return center
end
"""
#### Get mass-array from the dataset (cells/particles/clumps/...):
```julia
getmass(dataobject::HydroDataType)
getmass(dataobject::PartDataType)
getmass(dataobject::ClumpDataType)
return Array{Float64,1}
```
"""
function getmass(dataobject::HydroDataType;)
lmax = dataobject.lmax
boxlen = dataobject.boxlen
isamr = checkuniformgrid(dataobject, lmax)
#return select(dataobject.data, :rho) .* (dataobject.boxlen ./ 2. ^(select(dataobject.data, :level))).^3
if isamr
return select( dataobject.data, (:rho, :level)=>p->p.rho * (boxlen / 2^p.level)^3 )
else # if uniform grid
return select( dataobject.data, :rho=>p->p * (boxlen / 2^lmax)^3 )
end
end
function getmass(dataobject::PartDataType;)
return getvar(dataobject, :mass)
end
function getmass(dataobject::ClumpDataType;)
return getvar(dataobject, :mass)
end
"""
#### Get the x,y,z positions from the dataset (cells/particles/clumps/...):
```julia
getpositions( dataobject::DataSetType, unit::Symbol;
direction::Symbol=:z,
center::Array{<:Any,1}=[0., 0., 0.],
center_unit::Symbol=:standard,
mask::MaskType=[false])
return x, y, z
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "DataSetType"
##### Predefined/Optional Keywords:
- **`center`:** in unit given by argument `center_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`center_unit`:** :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`direction`:** todo
- **`unit`:** return the variables in given unit
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
### Defined Methods - function defined for different arguments
- getpositions( dataobject::DataSetType; ...) # one given dataobject
- getpositions( dataobject::DataSetType, unit::Symbol; ...) # one given dataobject and position unit
"""
function getpositions( dataobject::DataSetType, unit::Symbol;
direction::Symbol=:z,
center::Array{<:Any,1}=[0., 0., 0.],
center_unit::Symbol=:standard,
mask::MaskType=[false])
positions = getvar(dataobject, [:x, :y, :z],
center=center,
center_unit=center_unit,
direction=direction,
units=[unit, unit, unit],
mask=mask)
return positions[:x], positions[:y], positions[:z]
end
function getpositions( dataobject::DataSetType;
unit::Symbol=:standard,
direction::Symbol=:z,
center::Array{<:Any,1}=[0., 0., 0.],
center_unit::Symbol=:standard,
mask::MaskType=[false])
positions = getvar(dataobject, [:x, :y, :z],
center=center,
center_unit=center_unit,
direction=direction,
units=[unit, unit, unit],
mask=mask)
return positions[:x], positions[:y], positions[:z]
end
"""
#### Get the vx,vy,vz velocities from the dataset (cells/particles/clumps/...):
```julia
function getvelocities( dataobject::DataSetType, unit::Symbol;
mask::MaskType=[false])
return vx, vy, vz
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "DataSetType"
##### Predefined/Optional Keywords:
- **`unit`:** return the variables in given unit
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
### Defined Methods - function defined for different arguments
- getvelocities( dataobject::DataSetType; ...) # one given dataobject
- getvelocities( dataobject::DataSetType, unit::Symbol; ...) # one given dataobject and velocity unit
"""
function getvelocities( dataobject::DataSetType, unit::Symbol;
mask::MaskType=[false])
velocities = getvar(dataobject, [:vx, :vy, :vz],
units=[unit, unit, unit],
mask=mask)
return velocities[:vx], velocities[:vy], velocities[:vz]
end
function getvelocities( dataobject::DataSetType;
unit::Symbol=:standard,
mask::MaskType=[false])
velocities = getvar(dataobject, [:vx, :vy, :vz],
units=[unit, unit, unit],
mask=mask)
return velocities[:vx], velocities[:vy], velocities[:vz]
end
"""
#### Get the extent of the dataset-domain:
```julia
function getextent( dataobject::DataSetType;
unit::Symbol=:standard,
center::Array{<:Any,1}=[0., 0., 0.],
center_unit::Symbol=:standard,
direction::Symbol=:z)
return (xmin, xmax), (ymin ,ymax ), (zmin ,zmax )
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "DataSetType"
##### Predefined/Optional Keywords:
- **`center`:** in unit given by argument `center_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`center_unit`:** :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`direction`:** todo
- **`unit`:** return the variables in given unit
### Defined Methods - function defined for different arguments
- getextent( dataobject::DataSetType; # one given variable
- getextent( dataobject::DataSetType, unit::Symbol; ...) # one given variable with its unit
"""
function getextent( dataobject::DataSetType, unit::Symbol;
center::Array{<:Any,1}=[0., 0., 0.],
center_unit::Symbol=:standard,
direction::Symbol=:z)
return getextent( dataobject,
center=center,
center_unit=center_unit,
direction=direction,
unit=unit)
end
function getextent( dataobject::DataSetType;
unit::Symbol=:standard,
center::Array{<:Any,1}=[0., 0., 0.],
center_unit::Symbol=:standard,
direction::Symbol=:z)
range = dataobject.ranges
boxlen = dataobject.boxlen
selected_unit = 1. # :standard
conv = 1. # :standard, variable used to convert to standard units
if center_unit != :standard
selected_unit = getunit(dataobject.info, center_unit)
conv = dataobject.boxlen * selected_unit
end
center = Mera.prepboxcenter(dataobject.info, center_unit, center) # code units
center = center ./ conv
selected_unit = getunit(dataobject.info, unit)
xmin = ( range[1] - center[1] ) * boxlen * selected_unit
xmax = ( range[2] - center[1] ) * boxlen * selected_unit
ymin = ( range[3] - center[2] ) * boxlen * selected_unit
ymax = ( range[4] - center[2] ) * boxlen * selected_unit
zmin = ( range[5] - center[3] ) * boxlen * selected_unit
zmax = ( range[6] - center[3] ) * boxlen * selected_unit
if direction == :y
xmin_buffer = xmin
xmax_buffer = xmax
xmin= zmin
xmax= zmax
zmin= ymin
zmax= ymax
ymin= xmin_buffer
ymax= xmax_buffer
elseif direction == :x
xmin_buffer = xmin
xmax_buffer = xmax
xmin= zmin
xmax= zmax
zmin= xmin_buffer
zmax= xmax_buffer
end
return (xmin, xmax), (ymin ,ymax ), (zmin ,zmax )
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 3145 | function get_data(dataobject::ClumpDataType,
vars::Array{Symbol,1},
units::Array{Symbol,1},
direction::Symbol,
center::Array{<:Any,1},
mask::MaskType,
ref_time::Real)
vars_dict = Dict()
#vars = unique(vars)
boxlen = dataobject.boxlen
descriptor =[:x, :y, :z, :mass]
if direction == :z
apos = :peak_x
bpos = :peak_y
cpos = :peak_z
avel = :vx
bvel = :vy
cvel = :vz
elseif direction == :y
apos = :peak_z
bpos = :peak_x
cpos = :peak_y
avel = :vz
bvel = :vx
cvel = :vy
elseif direction == :x
apos = :peak_z
bpos = :peak_y
cpos = :peak_x
avel = :vz
bvel = :vy
cvel = :vx
end
column_names = propertynames(dataobject.data.columns)
for i in vars
# quantities that are in the datatable
if in(i, column_names) || in(i, descriptor)#|| occursin("var", string(i))
selected_unit = getunit(dataobject, i, vars, units)
if i == :peak_x || i == :x
vars_dict[i] = ( select(dataobject.data, apos) .- boxlen * center[1]) .* selected_unit
elseif i == :peak_y || i == :y
vars_dict[i] = ( select(dataobject.data, bpos) .- boxlen * center[2]) .* selected_unit
elseif i == :peak_z || i == :z
vars_dict[i] = ( select(dataobject.data, cpos) .- boxlen * center[3]) .* selected_unit
elseif i == :vx
vars_dict[i] = select(dataobject.data, avel) .* selected_unit
elseif i == :vy
vars_dict[i] = select(dataobject.data, bvel) .* selected_unit
elseif i == :vz
vars_dict[i] = select(dataobject.data, cvel) .* selected_unit
elseif i == :mass
vars_dict[i] = select(dataobject.data, :mass_cl) .* selected_unit
else
vars_dict[i] = select(dataobject.data, i) .* selected_unit
end
# quantities that are derived from the variables in the data table
elseif i == :v
selected_unit = getunit(dataobject, :v, vars, units)
vars_dict[:v] = sqrt.(select(dataobject.data, :vx).^2 .+
select(dataobject.data, :vy).^2 .+
select(dataobject.data, :vz).^2 ) .* selected_unit
elseif i == :ekin
selected_unit = getunit(dataobject, :ekin, vars, units)
vars_dict[:ekin] = 0.5 .* getvar(dataobject, vars=[:mass_cl]) .*
(select(dataobject.data, :vx).^2 .+
select(dataobject.data, :vy).^2 .+
select(dataobject.data, :vz).^2 ) .* selected_unit
end
end
if length(mask) > 1
for i in keys(vars_dict)
vars_dict[i]=vars_dict[i][mask]
end
end
if length(vars)==1
return vars_dict[vars[1]]
else
return vars_dict
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 4508 | function get_data(dataobject::GravDataType,
vars::Array{Symbol,1},
units::Array{Symbol,1},
direction::Symbol,
center::Array{<:Any,1},
mask::MaskType,
ref_time::Real)
boxlen = dataobject.boxlen
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
vars_dict = Dict()
if direction == :z
apos = :cx
bpos = :cy
cpos = :cz
avel = :vx
bvel = :vy
cvel = :vz
elseif direction == :y
apos = :cz
bpos = :cx
cpos = :cy
avel = :vz
bvel = :vx
cvel = :vy
elseif direction == :x
apos = :cz
bpos = :cy
cpos = :cx
avel = :vz
bvel = :vy
cvel = :vx
end
column_names = propertynames(dataobject.data.columns)
for i in vars
# quantities that are in the datatable
if in(i, column_names)
selected_unit = getunit(dataobject, i, vars, units)
if i == :cx
if isamr
vars_dict[i] = select(dataobject.data, apos) .- 2 .^getvar(dataobject, :level) .* center[1]
else # if uniform grid
vars_dict[i] = select(dataobject.data, apos) .- 2^lmax .* center[1]
end
elseif i == :cy
if isamr
vars_dict[i] = select(dataobject.data, bpos) .- 2 .^getvar(dataobject, :level) .* center[2]
else # if uniform grid
vars_dict[i] = select(dataobject.data, bpos) .- 2^lmax .* center[2]
end
elseif i == :cx
if isamr
vars_dict[i] = select(dataobject.data, cpos) .- 2 .^getvar(dataobject, :level) .* center[3]
else # if uniform grid
vars_dict[i] = select(dataobject.data, cpos) .- 2^lmax .* center[3]
end
else
#if selected_unit != 1.
#println(i)
vars_dict[i] = select(dataobject.data, i) .* selected_unit
#else
#vars_dict[i] = select(dataobject.data, i)
#end
end
# quantities that are derived from the variables in the data table
elseif i == :cellsize
selected_unit = getunit(dataobject, :cellsize, vars, units)
if isamr
vars_dict[:cellsize] = map(row-> dataobject.boxlen / 2^row.level * selected_unit , dataobject.data)
else # if uniform grid
vars_dict[:cellsize] = map(row-> dataobject.boxlen / 2^lmax * selected_unit , dataobject.data)
end
elseif i == :volume
selected_unit = getunit(dataobject, :volume, vars, units)
vars_dict[:volume] = convert(Array{Float64,1}, getvar(dataobject, :cellsize) .^3 .* selected_unit)
elseif i == :x
selected_unit = getunit(dataobject, :x, vars, units)
if isamr
vars_dict[:x] = (getvar(dataobject, apos) .* boxlen ./ 2 .^getvar(dataobject, :level) .- boxlen * center[1] ) .* selected_unit
else # if uniform grid
vars_dict[:x] = (getvar(dataobject, apos) .* boxlen ./ 2^lmax .- boxlen * center[1] ) .* selected_unit
end
elseif i == :y
selected_unit = getunit(dataobject, :y, vars, units)
if isamr
vars_dict[:y] = (getvar(dataobject, bpos) .* boxlen ./ 2 .^getvar(dataobject, :level) .- boxlen * center[2] ) .* selected_unit
else # if uniform grid
vars_dict[:y] = (getvar(dataobject, bpos) .* boxlen ./ 2^lmax .- boxlen * center[2] ) .* selected_unit
end
elseif i == :z
selected_unit = getunit(dataobject, :z, vars, units)
if isamr
vars_dict[:z] = (getvar(dataobject, cpos) .* boxlen ./ 2 .^getvar(dataobject, :level) .- boxlen * center[3] ) .* selected_unit
else # if uniform grid
vars_dict[:z] = (getvar(dataobject, cpos) .* boxlen ./ 2^lmax .- boxlen * center[3] ) .* selected_unit
end
end
end
if length(mask) > 1
for i in keys(vars_dict)
vars_dict[i]=vars_dict[i][mask]
end
end
if length(vars)==1
return vars_dict[vars[1]]
else
return vars_dict
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 13270 | function get_data( dataobject::HydroDataType,
vars::Array{Symbol,1},
units::Array{Symbol,1},
direction::Symbol,
center::Array{<:Any,1},
mask::MaskType,
ref_time::Real)
boxlen = dataobject.boxlen
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
vars_dict = Dict()
#vars = unique(vars)
if direction == :z
apos = :cx
bpos = :cy
cpos = :cz
avel = :vx
bvel = :vy
cvel = :vz
elseif direction == :y
apos = :cz
bpos = :cx
cpos = :cy
avel = :vz
bvel = :vx
cvel = :vy
elseif direction == :x
apos = :cz
bpos = :cy
cpos = :cx
avel = :vz
bvel = :vy
cvel = :vx
end
column_names = propertynames(dataobject.data.columns)
for i in vars
# quantities that are in the datatable
if in(i, column_names)
selected_unit = getunit(dataobject, i, vars, units)
if i == :cx
if isamr
vars_dict[i] = select(dataobject.data, apos) .- 2 .^getvar(dataobject, :level) .* center[1]
else # if uniform grid
vars_dict[i] = select(dataobject.data, apos) .- 2^lmax .* center[1]
end
elseif i == :cy
if isamr
vars_dict[i] = select(dataobject.data, bpos) .- 2 .^getvar(dataobject, :level) .* center[2]
else # if uniform grid
vars_dict[i] = select(dataobject.data, bpos) .- 2^lmax .* center[2]
end
elseif i == :cx
if isamr
vars_dict[i] = select(dataobject.data, cpos) .- 2 .^getvar(dataobject, :level) .* center[3]
else # if uniform grid
vars_dict[i] = select(dataobject.data, cpos) .- 2^lmax .* center[3]
end
else
#if selected_unit != 1.
#println(i)
vars_dict[i] = select(dataobject.data, i) .* selected_unit
#else
#vars_dict[i] = select(dataobject.data, i)
#end
end
# quantities that are derived from the variables in the data table
elseif i == :cellsize
selected_unit = getunit(dataobject, :cellsize, vars, units)
if isamr
vars_dict[:cellsize] = map(row-> dataobject.boxlen / 2^row.level * selected_unit , dataobject.data)
else # if uniform grid
vars_dict[:cellsize] = map(row-> dataobject.boxlen / 2^lmax * selected_unit , dataobject.data)
end
elseif i == :volume
selected_unit = getunit(dataobject, :volume, vars, units)
vars_dict[:volume] = convert(Array{Float64,1}, getvar(dataobject, :cellsize) .^3 .* selected_unit)
elseif i == :jeanslength
selected_unit = getunit(dataobject, :jeanslength, vars, units)
vars_dict[:jeanslength] = getvar(dataobject, :cs, unit=:cm_s) .*
sqrt(3. * pi / (32. * dataobject.info.constants.G)) ./
sqrt.( getvar(dataobject, :rho, unit=:g_cm3) ) ./ dataobject.info.scale.cm .* selected_unit
elseif i == :jeansnumber
selected_unit = getunit(dataobject, :jeansnumber, vars, units)
vars_dict[:jeansnumber] = getvar(dataobject, :jeanslength) ./ getvar(dataobject, :cellsize) ./ selected_unit
elseif i == :freefall_time
selected_unit = getunit(dataobject, :freefall_time, vars, units)
vars_dict[:freefall_time] = sqrt.( 3. * pi / (32. * dataobject.info.constants.G) ./ getvar(dataobject, :rho, unit=:g_cm3) ) .* selected_unit
elseif i == :mass
selected_unit = getunit(dataobject, :mass, vars, units)
vars_dict[:mass] = getmass(dataobject) .* selected_unit
elseif i == :cs
selected_unit = getunit(dataobject, :cs, vars, units)
vars_dict[:cs] = sqrt.( dataobject.info.gamma .*
select( dataobject.data, :p) ./
select( dataobject.data, :rho) ) .* selected_unit
elseif i == :T || i == :Temp || i == :Temperature
selected_unit = getunit(dataobject, i, vars, units)
vars_dict[i] = select( dataobject.data, :p) ./ select( dataobject.data, :rho) .* selected_unit
elseif i == :vx2
selected_unit = getunit(dataobject, :vx2, vars, units)
vars_dict[:vx2] = select(dataobject.data, :vx).^2 .* selected_unit.^2
elseif i == :vy2
selected_unit = getunit(dataobject, :vy2, vars, units)
vars_dict[:vy2] = select(dataobject.data, :vy).^2 .* selected_unit.^2
elseif i == :vz2
selected_unit = getunit(dataobject, :vz2, vars, units)
vars_dict[:vz2] = select(dataobject.data, :vz).^2 .* selected_unit.^2
elseif i == :v
selected_unit = getunit(dataobject, :v, vars, units)
vars_dict[:v] = sqrt.(select(dataobject.data, :vx).^2 .+
select(dataobject.data, :vy).^2 .+
select(dataobject.data, :vz).^2 ) .* selected_unit
elseif i == :v2
selected_unit = getunit(dataobject, :v2, vars, units)
vars_dict[:v2] = (select(dataobject.data, :vx).^2 .+
select(dataobject.data, :vy).^2 .+
select(dataobject.data, :vz).^2 ) .* selected_unit .^2
elseif i == :vϕ_cylinder
x = getvar(dataobject, :x, center=center)
y = getvar(dataobject, :y, center=center)
vx = getvar(dataobject, :vx)
vy = getvar(dataobject, :vy)
# vϕ = omega x radius
# vϕ = |(x*vy - y*vx) / (x^2 + y^2)| * sqrt(x^2 + y^2)
# vϕ = |x*vy - y*vx| / sqrt(x^2 + y^2)
selected_unit = getunit(dataobject, :vϕ_cylinder, vars, units)
aval = @. x * vy - y * vx # without abs to get direction
bval = @. (x^2 + y^2)^(-0.5)
vϕ_cylinder = @. aval .* bval .* selected_unit
vϕ_cylinder[isnan.(vϕ_cylinder)] .= 0. # overwrite NaN due to radius = 0
vars_dict[:vϕ_cylinder] = vϕ_cylinder
elseif i == :vϕ_cylinder2
selected_unit = getunit(dataobject, :vϕ_cylinder2, vars, units)
vars_dict[:vϕ_cylinder2] = (getvar(dataobject, :vϕ_cylinder, center=center) .* selected_unit).^2
elseif i == :vz2
vz = getvar(dataobject, :vz)
selected_unit = getunit(dataobject, :vz2, vars, units)
vars_dict[:vz2] = (vz .* selected_unit ).^2
elseif i == :vr_cylinder
x = getvar(dataobject, :x, center=center)
y = getvar(dataobject, :y, center=center)
vx = getvar(dataobject, :vx)
vy = getvar(dataobject, :vy)
selected_unit = getunit(dataobject, :vr_cylinder, vars, units)
vr = @. (x * vx + y * vy) * (x^2 + y^2)^(-0.5) * selected_unit
vr[isnan.(vr)] .= 0 # overwrite NaN due to radius = 0
vars_dict[:vr_cylinder] = vr
elseif i == :vr_cylinder2
selected_unit = getunit(dataobject, :vr_cylinder2, vars, units)
vars_dict[:vr_cylinder2] = (getvar(dataobject, :vr_cylinder, center=center) .* selected_unit).^2
elseif i == :x
selected_unit = getunit(dataobject, :x, vars, units)
if isamr
vars_dict[:x] = (getvar(dataobject, apos) .* boxlen ./ 2 .^getvar(dataobject, :level) .- boxlen * center[1] ) .* selected_unit
else # if uniform grid
vars_dict[:x] = (getvar(dataobject, apos) .* boxlen ./ 2^lmax .- boxlen * center[1] ) .* selected_unit
end
elseif i == :y
selected_unit = getunit(dataobject, :y, vars, units)
if isamr
vars_dict[:y] = (getvar(dataobject, bpos) .* boxlen ./ 2 .^getvar(dataobject, :level) .- boxlen * center[2] ) .* selected_unit
else # if uniform grid
vars_dict[:y] = (getvar(dataobject, bpos) .* boxlen ./ 2^lmax .- boxlen * center[2] ) .* selected_unit
end
elseif i == :z
selected_unit = getunit(dataobject, :z, vars, units)
if isamr
vars_dict[:z] = (getvar(dataobject, cpos) .* boxlen ./ 2 .^getvar(dataobject, :level) .- boxlen * center[3] ) .* selected_unit
else # if uniform grid
vars_dict[:z] = (getvar(dataobject, cpos) .* boxlen ./ 2^lmax .- boxlen * center[3] ) .* selected_unit
end
elseif i == :hx # specific angular momentum
# y * vz - z * vy
selected_unit = getunit(dataobject, :hx, vars, units)
ypos = getvar(dataobject, :y, center=center)
zpos = getvar(dataobject, :z, center=center)
vy = getvar(dataobject, :vy, center=center)
vz = getvar(dataobject, :vz, center=center)
vars_dict[:hx] = (ypos .* vz .- zpos .* vy) .* selected_unit
elseif i == :hy # specific angular momentum
# z * vx - x * vz
selected_unit = getunit(dataobject, :hy, vars, units)
xpos = getvar(dataobject, :x, center=center)
zpos = getvar(dataobject, :z, center=center)
vx = getvar(dataobject, :vx, center=center)
vz = getvar(dataobject, :vz, center=center)
vars_dict[:hy] = (zpos .* vx .- xpos .* vz) .* selected_unit
elseif i == :hz # specific angular momentum
# x * vy - y * vx
selected_unit = getunit(dataobject, :hz, vars, units)
xpos = getvar(dataobject, :x, center=center)
ypos = getvar(dataobject, :y, center=center)
vx = getvar(dataobject, :vx, center=center)
vy = getvar(dataobject, :vy, center=center)
vars_dict[:hz] = (xpos .* vy .- ypos .* vx) .* selected_unit
elseif i == :h # specific angular momentum
selected_unit = getunit(dataobject, :h, vars, units)
hx = getvar(dataobject, :hx, center=center)
hy = getvar(dataobject, :hy, center=center)
hz = getvar(dataobject, :hz, center=center)
vars_dict[:h] = sqrt.(hx .^2 .+ hy .^2 .+ hz .^2) .* selected_unit
elseif i == :mach #thermal; no unit needed
vars_dict[:mach] = getvar(dataobject, :v) ./ getvar(dataobject, :cs)
elseif i == :ekin
selected_unit = getunit(dataobject, :ekin, vars, units)
vars_dict[:ekin] = 0.5 .* getmass(dataobject) .* getvar(dataobject, :v).^2 .* selected_unit
elseif i == :r_cylinder
selected_unit = getunit(dataobject, :r_cylinder, vars, units)
if isamr
vars_dict[:r_cylinder] = convert(Array{Float64,1}, select( dataobject.data, (apos, bpos, :level)=>p->
selected_unit * sqrt( (p[apos] * boxlen / 2^p.level - boxlen * center[1] )^2 +
(p[bpos] * boxlen / 2^p.level - boxlen * center[2] )^2 ) ) )
else # if uniform grid
vars_dict[:r_cylinder] = convert(Array{Float64,1}, select( dataobject.data, (apos, bpos)=>p->
selected_unit * sqrt( (p[apos] * boxlen / 2^lmax - boxlen * center[1] )^2 +
(p[bpos] * boxlen / 2^lmax - boxlen * center[2] )^2 ) ) )
end
elseif i == :r_sphere
selected_unit = getunit(dataobject, :r_sphere, vars, units)
if isamr
vars_dict[:r_sphere] = select( dataobject.data, (apos, bpos, cpos, :level)=>p->
selected_unit * sqrt( (p[apos] * boxlen / 2^p.level - boxlen * center[1] )^2 +
(p[bpos] * boxlen / 2^p.level - boxlen * center[2] )^2 +
(p[cpos] * boxlen / 2^p.level - boxlen * center[3] )^2 ) )
else # if uniform grid
vars_dict[:r_sphere] = select( dataobject.data, (apos, bpos, cpos)=>p->
selected_unit * sqrt( (p[apos] * boxlen / 2^lmax - boxlen * center[1] )^2 +
(p[bpos] * boxlen / 2^lmax - boxlen * center[2] )^2 +
(p[cpos] * boxlen / 2^lmax - boxlen * center[3] )^2 ) )
end
end
end
if length(mask) > 1
for i in keys(vars_dict)
vars_dict[i]=vars_dict[i][mask]
end
end
if length(vars)==1
return vars_dict[vars[1]]
else
return vars_dict
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 6390 | function get_data(dataobject::PartDataType,
vars::Array{Symbol,1},
units::Array{Symbol,1},
direction::Symbol,
center::Array{<:Any,1},
mask::MaskType,
ref_time::Real)
vars_dict = Dict()
#vars = unique(vars)
boxlen = dataobject.boxlen
if direction == :z
apos = :x
bpos = :y
cpos = :z
avel = :vx
bvel = :vy
cvel = :vz
elseif direction == :y
apos = :z
bpos = :x
cpos = :y
avel = :vz
bvel = :vx
cvel = :vy
elseif direction == :x
apos = :z
bpos = :y
cpos = :x
avel = :vz
bvel = :vy
cvel = :vx
end
column_names = propertynames(dataobject.data.columns)
for i in vars
# quantities that are in the datatable
if in(i, column_names)
selected_unit = getunit(dataobject, i, vars, units)
if i == :x
#selected_unit = (dataobject, :x, vars, units)
vars_dict[:x] = (select(dataobject.data, apos) .- boxlen * center[1] ) .* selected_unit
elseif i == :y
#selected_unit = (dataobject, :y, vars, units)
vars_dict[:y] = (select(dataobject.data, bpos) .- boxlen * center[2] ) .* selected_unit
elseif i == :z
#selected_unit = (dataobject, :z, vars, units)
vars_dict[:z] = (select(dataobject.data, cpos) .- boxlen * center[3] ) .* selected_unit
else
vars_dict[i] = select(dataobject.data, i) .* selected_unit
end
# quantities that are derived from the variables in the data table
elseif i == :vx2
selected_unit = getunit(dataobject, :vx2, vars, units)
vars_dict[:vx2] = (getvar(dataobject, :vx) .* selected_unit ) .^2
elseif i == :vy2
selected_unit = getunit(dataobject, :vy2, vars, units)
vars_dict[:vy2] = (getvar(dataobject, :vy) .* selected_unit ) .^2
elseif i == :v
selected_unit = getunit(dataobject, :v, vars, units)
vars_dict[:v] = sqrt.(select(dataobject.data, :vx).^2 .+
select(dataobject.data, :vy).^2 .+
select(dataobject.data, :vz).^2 ) .* selected_unit
elseif i == :v2
selected_unit = getunit(dataobject, :v2, vars, units)
vars_dict[:v2] = (select(dataobject.data, :vx).^2 .+
select(dataobject.data, :vy).^2 .+
select(dataobject.data, :vz).^2 ) .* selected_unit .^2
elseif i == :vϕ_cylinder
x = getvar(dataobject, :x, center=center)
y = getvar(dataobject, :y, center=center)
vx = getvar(dataobject, :vx)
vy = getvar(dataobject, :vy)
# vϕ = omega x radius
# vϕ = |(x*vy - y*vx) / (x^2 + y^2)| * sqrt(x^2 + y^2)
# vϕ = |x*vy - y*vx| / sqrt(x^2 + y^2)
selected_unit = getunit(dataobject, :vϕ_cylinder, vars, units)
aval = @. x * vy - y * vx # without abs to get direction
bval = @. (x^2 + y^2)^(-0.5)
vϕ_cylinder = @. aval .* bval .* selected_unit
vϕ_cylinder[isnan.(vϕ_cylinder)] .= 0. # overwrite NaN due to radius = 0
vars_dict[:vϕ_cylinder] = vϕ_cylinder
elseif i == :vϕ_cylinder2
selected_unit = getunit(dataobject, :vϕ_cylinder2, vars, units)
vars_dict[:vϕ_cylinder2] = (getvar(dataobject, :vϕ_cylinder, center=center) .* selected_unit).^2
elseif i == :vr_cylinder
x = getvar(dataobject, :x, center=center)
y = getvar(dataobject, :y, center=center)
vx = getvar(dataobject, :vx)
vy = getvar(dataobject, :vy)
selected_unit = getunit(dataobject, :vr_cylinder, vars, units)
vr = @. (x * vx + y * vy) * (x^2 + y^2)^(-0.5) * selected_unit
vr[isnan.(vr)] .= 0 # overwrite NaN due to radius = 0
vars_dict[:vr_cylinder] = vr
elseif i == :vz2
vz = getvar(dataobject, :vz)
selected_unit = getunit(dataobject, :vz2, vars, units)
vars_dict[:vz2] = (vz .* selected_unit ).^2
elseif i == :vr_cylinder2
selected_unit = getunit(dataobject, :vr_cylinder2, vars, units)
vars_dict[:vr_cylinder2] = (getvar(dataobject, :vr_cylinder, center=center) .* selected_unit).^2
elseif i == :r_cylinder
selected_unit = getunit(dataobject, :r_cylinder, vars, units)
vars_dict[:r_cylinder] = select( dataobject.data, (apos, bpos)=>p->
selected_unit * sqrt( (p[apos] - center[1] * boxlen )^2 +
(p[bpos] - center[2] * boxlen )^2 ) )
elseif i == :r_sphere
selected_unit = getunit(dataobject, :r_sphere, vars, units)
vars_dict[:r_sphere] = select( dataobject.data, (apos, bpos, cpos)=>p->
selected_unit * sqrt( (p[apos] - center[1] * boxlen )^2 +
(p[bpos] - center[2] * boxlen )^2 +
(p[cpos] - center[3] * boxlen )^2 ) )
elseif i == :ekin
selected_unit = getunit(dataobject, :ekin, vars, units)
vars_dict[:ekin] = 0.5 .* getvar(dataobject, :mass) .*
(select(dataobject.data, :vx).^2 .+
select(dataobject.data, :vy).^2 .+
select(dataobject.data, :vz).^2 ) .* selected_unit
elseif i == :age
selected_unit = getunit(dataobject, :age, vars, units)
vars_dict[:age] = ( ref_time .- getvar(dataobject, :birth) ) .* selected_unit
end
end
for i in keys(vars_dict)
vars_dict[i][isnan.(vars_dict[i])] .= 0
end
if length(mask) > 1
for i in keys(vars_dict)
vars_dict[i]=vars_dict[i][mask]
end
end
if length(vars)==1
return vars_dict[vars[1]]
else
return vars_dict
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 15766 | function createconstants!(dataobject::InfoType)
dataobject.constants = createconstants()
return dataobject
end
function createconstants()
#---------------------------------------------------
# define constants in cgs units
#---------------------------------------------------
# Sources:
# http://www.astro.wisc.edu/~dolan/constants.html
# IAU
# RAMSES
constants = PhysicalUnitsType001() #zeros(Float64, 17)...)
constants.Au = 149597870700e-13 # [cm] Astronomical unit -> from IAU
constants.pc = 3.08567758128e18 # [cm] Parsec -> from IAU
constants.kpc = constants.pc * 1e3
constants.Mpc = constants.pc * 1e6
constants.mpc = constants.pc * 1e-3
constants.ly = 9.4607304725808e17 # [cm] Light year -> from IAU
constants.Msol = 1.9891e33 # [g] Solar mass -> from IAU
constants.Msun = constants.Msol
constants.Rsol = 6.96e10 #cm: Solar radius
constants.Rsun = constants.Rsol
# Lsol = #erg s-2: Solar luminosity
constants.Mearth = 5.9722e27 # [g] Earth mass -> from IAU
constants.Mjupiter = 1.89813e30 # [g] Jupiter -> from IAU
constants.me = 9.1093897e-28 #g: electron mass
constants.mp = 1.6726231e-24 #g: proton mass
constants.mn = 1.6749286e-24 #g: neutron mass
constants.mH = 1.66e-24 # [g] H-Atom mass -> from RAMSES
constants.amu = 1.6605402e-24 #g: atomic mass unit
constants.NA = 6.0221367e23 # Avagadro's number
constants.c = 2.99792458e10 #cm s-1: speed of light in a vacuum
# h = #erg s: Planck constant
# hbar = #erg s
constants.G = 6.67259e-8 # cm3 g-1 s-2 Gravitational constant
constants.kB = 1.3806200e-16 # [cm2 g s-2 K-1] Boltzmann constant -> cooling_module.f90 RAMSES
constants.yr = 3.15576e7 # [s] Year -> from IAU
constants.Myr = constants.yr *1e6
constants.Gyr = constants.yr *1e9
return constants
end
"""
### Create an object with predefined scale factors from code to pysical units
```julia
function createscales!(dataobject::InfoType)
return ScalesType001
```
"""
function createscales!(dataobject::InfoType)
dataobject.scale = createscales(dataobject)
return dataobject
end
# create scales-field from existing InfoType
function createscales(dataobject::InfoType)
unit_l = dataobject.unit_l
unit_d = dataobject.unit_d
unit_t = dataobject.unit_t
unit_m = dataobject.unit_m
constants = dataobject.constants
return createscales(unit_l, unit_d, unit_t, unit_m, constants)
end
function createscales(unit_l::Float64, unit_d::Float64, unit_t::Float64, unit_m::Float64, constants::PhysicalUnitsType001)
#Initialize scale-object
scale = ScalesType001() #zeros(Float64, 32)...)
# Conversion factors from user units to astronomical units
mH = constants.mH # [g] H-Atom mass -> from RAMSES
kB = constants.kB # [cm2 g s-2 K-1] = [erg K-1] Boltzmann constant -> cooling_module.f90 RAMSES
#Mpc = constants.pc /1e6 # [cm] MegaParsec -> from IAU
#kpc = constants.pc /1e3 # [cm] KiloParsec -> from IAU
pc = constants.pc # [cm] Parsec -> from IAU
#mpc = constants.pc *1e3 # [cm] MilliParsec -> from IAU
Au = constants.Au # [cm] Astronomical unit -> from IAU
ly = constants.ly # [cm] Light year -> from IAU
Msol = constants.Msol # [g] Solar mass -> from IAU
Mearth = constants.Mearth # [g] Earth mass -> from IAU
Mjupiter= constants.Mjupiter # [g] Jupiter -> from IAU
#Gyr = constants.yr /1e9 # [s] GigaYear -> from IAU
#Myr = constants.yr /1e6 # [s] MegaYear -> from IAU
yr = constants.yr # [s] Year -> from IAU
X_frac = 0.76 # Hydrogen fraction by mass -> cooling_module.f90 RAMSES
μ = 1/X_frac # mean molecular weight
scale.Mpc = unit_l / pc / 1e6
scale.kpc = unit_l / pc / 1e3
scale.pc = unit_l / pc
scale.mpc = unit_l / pc * 1e3
scale.ly = unit_l / ly
scale.Au = unit_l / Au
scale.km = unit_l / 1.0e5
scale.m = unit_l / 1.0e2
scale.cm = unit_l
scale.mm = unit_l * 10.
scale.μm = unit_l * 1e4
scale.Mpc3 = scale.Mpc^3
scale.kpc3 = scale.kpc^3
scale.pc3 = scale.pc^3
scale.mpc3 = scale.mpc^3
scale.ly3 = scale.ly^3
scale.Au3 = scale.Au^3
scale.km3 = scale.km^3
scale.m3 = scale.m^3
scale.cm3 = scale.cm^3
scale.mm3 = scale.mm^3
scale.μm3 = scale.μm^3
scale.Msol_pc3 = unit_d * pc^3 / Msol
scale.Msun_pc3 = scale.Msol_pc3
scale.g_cm3 = unit_d
scale.Msol_pc2 = unit_d * unit_l * pc^2 / Msol
scale.Msun_pc2 = scale.Msol_pc2
scale.g_cm2 = unit_d * unit_l
scale.Gyr = unit_t / yr / 1e9
scale.Myr = unit_t / yr / 1e6
scale.yr = unit_t / yr
scale.s = unit_t
scale.ms = unit_t * 1e3
scale.Msol = unit_d * unit_l^3 / Msol
scale.Msun = scale.Msol
scale.Mearth = unit_d * unit_l^3 / Mearth
scale.Mjupiter = unit_d * unit_l^3 / Mjupiter
scale.g = unit_d * unit_l^3
scale.km_s = unit_l / unit_t / 1e5
scale.m_s = unit_l / unit_t / 1e2
scale.cm_s = unit_l / unit_t
scale.nH = X_frac / mH * unit_d # Hydrogen number density in [H/cc]
scale.erg = unit_m * (unit_l / unit_t)^2 # [g (cm/s)^2]
scale.g_cms2 = unit_m / (unit_l * unit_t^2)
scale.T_mu = mH / kB * (unit_l / unit_t)^2 # T/mu [Kelvin]
scale.K_mu = scale.T_mu
scale.T = scale.T_mu * μ # T [Kelvin]
scale.K = scale.T
scale.Ba = unit_m / unit_l / unit_t^2 # Barye (pressure) [cm-1 g s-2]
scale.g_cm_s2 = scale.Ba
scale.p_kB = scale.g_cm_s2 / kB # [K cm-3]
scale.K_cm3 = scale.p_kB # p/kB
return scale
end
"""
### Get a list of all exported Mera types and functions:
```julia
function viewmodule(modulename::Module)
```
"""
function viewmodule(modulename::Module)
println()
printstyled("[Mera]: Get a list of all exported Mera types and functions:\n", bold=true, color=:normal)
printstyled("===============================================================\n", bold=true, color=:normal)
module_list = names(modulename, all=false,imported= true)
show(IOContext(stdout), "text/plain", module_list )
return module_list
end
"""
### Convert a value to human-readable astrophysical units and round to ndigits
(pass the value in code units and the quantity specification (length, time) )
```julia
function humanize(value::Float64, scale::ScalesType001, ndigits::Int, quantity::String)
return value, value_unit
```
"""
function humanize(value::Float64, scale::ScalesType001, ndigits::Int, quantity::String)
if quantity == ""
round(value, digits=ndigits)
elseif value == 0
value_buffer = 0.
value_unit = "x"
return round(value_buffer, digits=ndigits), value_unit
else
if quantity == "length"
sign_buffer = sign(value)
value_buffer = value * scale.Mpc * sign_buffer
value_unit = "Mpc"
if value_buffer <= 1.
value_buffer = value * scale.kpc * sign_buffer
value_unit = "kpc"
if value_buffer <= 1.
value_buffer = value * scale.pc * sign_buffer
value_unit = "pc"
if value_buffer <= 1.
value_buffer = value * scale.mpc * sign_buffer
value_unit = "mpc"
#if value_buffer < 1. #todo check
# value_buffer = value * scale.au
# value_unit = "au"
if value_buffer <= .1
value_buffer = value * scale.cm * sign_buffer
value_unit = "cm"
if value_buffer <= .1
value_buffer = value * scale.μm * sign_buffer
value_unit = "μm"
end
end
#end
end
end
end
value_buffer = value_buffer * sign_buffer
end
if quantity == "time"
sign_buffer = sign(value)
value_buffer = value * scale.Gyr * sign_buffer
value_unit = "Gyr"
if value_buffer <= 1.
value_buffer = value * scale.Myr * sign_buffer
value_unit = "Myr"
if value_buffer <= .1
value_buffer = value * scale.yr * sign_buffer
value_unit = "yr"
if value_buffer <= 1.
value_buffer = value * scale.s * sign_buffer
value_unit = "s"
if value_buffer <= 1.
value_buffer = value * scale.ms * sign_buffer
value_unit = "ms"
end
end
end
end
value_buffer = value_buffer * sign_buffer
end
return round(value_buffer, digits=ndigits), value_unit
end
end
function humanize(value::Float64, ndigits::Int, quantity::String)
if quantity == ""
round(value, digits=ndigits)
else
if quantity == "memory"
value_buffer = value
value_unit = "Bytes"
if value_buffer > 1000.
value_buffer = value_buffer / 1024.
value_unit = "KB"
if value_buffer > 1000.
value_buffer = value_buffer / 1024.
value_unit = "MB"
if value_buffer > 1000.
value_buffer = value_buffer / 1024.
value_unit = "GB"
if value_buffer > 1000.
value_buffer = value_buffer / 1024.
value_unit = "TB"
end
end
end
end
end
return round(value_buffer, digits=ndigits), value_unit
end
end
#todo: define file type?
function skiplines(file, nlines::Int)
for i=1:nlines
read(file)
end
return
end
function getunit(dataobject, quantity::Symbol, vars::Array{Symbol,1}, units::Array{Symbol,1}; uname::Bool=false)
idx = findall(x->x==quantity, vars)
if length(idx) >= 1
idx = idx[1]
if length(units) >= idx
unit = units[idx]
else
unit = :standard
end
else
unit = :standard
end
if unit == :standard
if uname == false
return 1.
else
return 1., unit
end
else
if uname == false
return getfield(dataobject.info.scale, unit)
else
return getfield(dataobject.info.scale, unit), unit
end
end
end
function getunit(dataobject::InfoType, unit::Symbol; uname::Bool=false)
if unit == :standard
if uname == false
return 1.
else
return 1., unit
end
else
if uname == false
return getfield(dataobject.scale, unit)
else
return getfield(dataobject.scale, unit), unit
end
end
end
"""
### Create a New DataSetType from a Filtered Data Table
```julia
function construct_datatype(data::JuliaDB.AbstractIndexedTable, dataobject::HydroDataType)
return HydroDataType
function construct_datatype(data::JuliaDB.AbstractIndexedTable, dataobject::PartDataType)
return PartDataType
function construct_datatype(data::JuliaDB.AbstractIndexedTable, dataobject::ClumpDataType)
return ClumpDataType
function construct_datatype(data::JuliaDB.AbstractIndexedTable, dataobject::GravDataType)
return GravDataType
```
### Example
```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)
```
"""
function construct_datatype(data::JuliaDB.AbstractIndexedTable, dataobject::HydroDataType)
hydrodata = HydroDataType()
hydrodata.data = data
hydrodata.info = dataobject.info
hydrodata.lmin = dataobject.lmin
hydrodata.lmax = dataobject.lmax
hydrodata.boxlen = dataobject.boxlen
hydrodata.ranges = dataobject.ranges
hydrodata.selected_hydrovars = dataobject.selected_hydrovars
hydrodata.used_descriptors = dataobject.used_descriptors
hydrodata.smallr = dataobject.smallr
hydrodata.smallc = dataobject.smallc
hydrodata.scale = dataobject.scale
return hydrodata
end
function construct_datatype(data::JuliaDB.AbstractIndexedTable, dataobject::PartDataType)
partdata = PartDataType()
partdata.data = data
partdata.info = dataobject.info
partdata.lmin = dataobject.lmin
partdata.lmax = dataobject.lmax
partdata.boxlen = dataobject.boxlen
partdata.ranges = dataobject.ranges
partdata.selected_partvars = dataobject.selected_partvars
partdata.used_descriptors = dataobject.used_descriptors
partdata.scale = dataobject.scale
return partdata
end
function construct_datatype(data::JuliaDB.AbstractIndexedTable, dataobject::GravDataType)
gravitydata = GravDataType()
gravitydata.data = data
gravitydata.info = dataobject.info
gravitydata.lmin = dataobject.lmin
gravitydata.lmax = dataobject.lmax
gravitydata.boxlen = dataobject.boxlen
gravitydata.ranges = dataobject.ranges
gravitydata.selected_gravvars = dataobject.selected_gravvars
gravitydata.used_descriptors = dataobject.used_descriptors
gravitydata.scale = dataobject.scale
return gravitydata
end
function construct_datatype(data::JuliaDB.AbstractIndexedTable, dataobject::ClumpDataType)
clumpdata = ClumpDataType()
clumpdata.data = data
clumpdata.info = dataobject.info
clumpdata.boxlen = dataobject.boxlen
clumpdata.ranges = dataobject.ranges
clumpdata.selected_clumpvars = dataobject.selected_clumpvars
clumpdata.used_descriptors = dataobject.used_descriptors
clumpdata.scale = dataobject.scale
return clumpdata
end
"""
### Get a notification sound, e.g., when your calculations are finished.
This may not apply when working remotely on a server:
```julia
julia> bell()
```
"""
function bell()
# Sound folder
sounddir = joinpath(@__DIR__, "../sounds/")
y, fs = wavread(sounddir * "strum.wav")
wavplay(y, fs)
return
end
"""
### Get an email notification, e.g., when your calculations are finished.
Mandatory:
- the email client "mail" needs to be installed
- put a file with the name "email.txt" in your home folder that contains your email address in the first line
```julia
julia> notifyme()
```
or:
```julia
julia> notifyme("Calculation 1 finished!")
```
"""
function notifyme(msg::String)
return notifyme(msg=msg)
end
function notifyme(;msg="done!")
f = open(homedir() * "/email.txt")
email = read(f, String)
close(f)
email = strip(email, '\n')
email = filter(x -> !isspace(x), email)
run(pipeline(`echo "$msg"`, `mail -s "MERA" $email`));
return
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 30454 |
"""
### print a Mera timestamp on the screen if the global variable: verbose_mode == true
```julia
function printtime(text::String="", verbose::Bool=verbose_mode)
```
"""
function printtime(text::String="", verbose::Bool=verbose_mode)
if verbose
printstyled( "[Mera]: $text",now(), "\n", bold=true, color=:normal)
println()
end
end
function printtablememory(data, verbose::Bool)
if verbose
arg_value, arg_unit = usedmemory(data, false)
println("Memory used for data table :", arg_value, " ", arg_unit)
println("-------------------------------------------------------")
println()
end
end
"""
### Get the memory that is used for an object in human-readable units
```julia
function usedmemory(object, verbose::Bool=true)
return value, unit
```
"""
function usedmemory(object, verbose::Bool=true)
obj_value = Base.summarysize(object)
return usedmemory(obj_value, verbose)
end
function usedmemory(obj_value::Real, verbose::Bool=true)
value_buffer = obj_value
value_unit = "Bytes"
if obj_value > 1000.
value_buffer = obj_value / 1024.
value_unit = "KB"
if value_buffer > 1000.
value_buffer = value_buffer / 1024.
value_unit = "MB"
if value_buffer > 1000.
value_buffer = value_buffer / 1024.
value_unit = "GB"
if value_buffer > 1000.
value_buffer = value_buffer / 1024.
value_unit = "TB"
end
end
end
end
if verbose == true
println("Memory used: ", round(value_buffer, digits=3), " ", value_unit)
end
return value_buffer, value_unit
end
"""
#### Print overview of the used storage per file type for a given timestep
```julia
function storageoverview(dataobject::InfoType, verbose::Bool=true)
function storageoverview(dataobject::InfoType; verbose::Bool=true)
return dictionary in bytes
```
"""
function storageoverview(dataobject::InfoType, verbose::Bool)
return storageoverview(dataobject, verbose=verbose)
end
function storageoverview(dataobject::InfoType; verbose::Bool=true)
# todo simplyfy to single function calls
verbose = checkverbose(verbose)
dictoutput = Dict()
output = dataobject.output
if verbose
printstyled("Overview of the used disc space for output: [$output]\n", bold=true, color=:normal)
printstyled("------------------------------------------------------\n", bold=true, color=:normal)
end
#path = dataobject.path
#fnames = createpath(output, path)
#println(fnames)
fnames = dataobject.fnames
all_files = readdir(fnames.output)
folder = filesize.( fnames.output .* "/" .* all_files)
folder_size = sum( folder )
folder_mean = mean( folder )
folder_value, folder_unit = usedmemory(folder_size, false)
folder_meanvalue, folder_meanunit = usedmemory(folder_mean, false)
if verbose
println( "Folder: ", round(folder_value,digits=2), " ", folder_unit, " \t<", round(folder_meanvalue, digits=2), " ", folder_meanunit,">/file" )
end
amr_files = all_files[ occursin.( "amr", all_files) ]
amr = filesize.( fnames.output .* "/" .* amr_files )
amr_size = sum( amr )
amr_mean = mean( amr )
amr_value, amr_unit = usedmemory(amr_size, false)
amr_meanvalue, amr_meanunit = usedmemory(amr_mean, false)
if verbose
println( "AMR-Files: ", round(amr_value, digits=2), " ", amr_unit, " \t<", round(amr_meanvalue, digits=2), " ", amr_meanunit,">/file" )
end
if dataobject.hydro
hydro_files = all_files[ occursin.( "hydro", all_files) ]
hydro = filesize.( fnames.output .* "/" .* hydro_files )
hydro_size = sum( hydro )
hydro_mean = mean( hydro )
hydro_value, hydro_unit = usedmemory(hydro_size, false)
hydro_meanvalue, hydro_meanunit = usedmemory(hydro_mean, false)
if verbose
println( "Hydro-Files: ", round(hydro_value, digits=2), " ", hydro_unit, " \t<", round(hydro_meanvalue, digits=2), " ", hydro_meanunit,">/file" )
end
else
hydro_size = 0.
end
if dataobject.gravity
gravity_files = all_files[ occursin.( "grav", all_files) ]
gravity = filesize.(fnames.output .* "/" .* gravity_files )
gravity_size = sum( gravity )
gravity_mean = mean( gravity )
gravity_value, gravity_unit = usedmemory(gravity_size, false)
gravity_meanvalue, gravity_meanunit = usedmemory(gravity_mean, false)
if verbose
println( "Gravity-Files: ", round(gravity_value, digits=2), " ", gravity_unit, " \t<", round(gravity_meanvalue, digits=2), " ", gravity_meanunit,">/file" )
end
else
gravity_size = 0.
end
if dataobject.particles
particle_files = all_files[ occursin.( "part", all_files) ]
particle = filesize.( fnames.output .* "/" .* particle_files )
particle_size = sum( particle )
particle_mean = mean( particle )
particle_value, particle_unit = usedmemory(particle_size, false)
particle_meanvalue, particle_meanunit = usedmemory(particle_mean, false)
if verbose
println( "Particle-Files: ", round(particle_value, digits=2)," ", particle_unit," \t<", round(particle_meanvalue, digits=2)," ", particle_meanunit,">/file" )
end
else
particle_size = 0.
end
if dataobject.clumps
clump_files = all_files[ occursin.( "clump", all_files) ]
clump = filesize.( fnames.output .* "/" .* clump_files )
clump_size = sum( clump )
clump_mean = mean( clump )
clump_value, clump_unit = usedmemory(clump_size, false)
clump_meanvalue, clump_meanunit = usedmemory(clump_mean, false)
if verbose
println( "Clump-Files: ", round(clump_value, digits=2), " ", clump_unit, " \t<", round(clump_meanvalue, digits=2), " ", clump_meanunit,">/file" )
end
else
clump_size = 0.
end
if dataobject.rt
rt_files = all_files[ occursin.( "rt", all_files) ]
rt = filesize.( fnames.output .* "/" .* rt_files )
rt_size = sum( rt )
rt_mean = mean( rt )
rt_value, rt_unit = usedmemory(rt_size, false)
rt_meanvalue, rt_meanunit = usedmemory(rt_mean, false)
if verbose
println( "RT-Files: ", round(rt_value, digits=2), " ", rt_unit, " \t<", round(rt_meanvalue, digits=2), " ", rt_meanunit,">/file" )
end
else
rt_size = 0.
end
# todo: check for sink files
if dataobject.sinks
sink_files = all_files[ occursin.( "sink", all_files) ]
sink = filesize.( fnames.output .* "/" .* sink_files )
sink_size = sum( sink )
sink_mean = mean( sink )
sink_value, sink_unit = usedmemory(sink_size, false)
sink_meanvalue, sink_meanunit = usedmemory(sink_mean, false)
if verbose
println( "Sink-Files: ", round(sink_value, digits=2), " ", sink_unit, " \t<", round(sink_meanvalue, digits=2), " ", sink_meanunit,">/file" )
end
else
sink_size = 0.
end
if verbose
println()
println()
println("mtime: ", dataobject.mtime)
println("ctime: ", dataobject.ctime)
end
# prepare output
dictoutput[:folder] = folder_size
dictoutput[:amr] = amr_size
dictoutput[:hydro] = hydro_size
dictoutput[:gravity] = gravity_size
dictoutput[:particle] = particle_size
dictoutput[:clump] = clump_size
dictoutput[:rt] = rt_size
dictoutput[:sink] = sink_size
return dictoutput
end
"""
### Get the number of cells and/or the CPUs per level
```julia
function overview_amr(dataobject::HydroDataType, verbose::Bool=true)
function overview_amr(dataobject::HydroDataType; verbose::Bool=true)
return a JuliaDB table
```
"""
function amroverview(dataobject::HydroDataType, verbose::Bool)
amroverview(dataobject, verbose=verbose)
end
function amroverview(dataobject::HydroDataType; verbose::Bool=true)
checkforAMR(dataobject)
verbose = checkverbose(verbose)
# check if cpu column exists
fn = propertynames(dataobject.data.columns)
cpu_col = false
Ncols = 2
if in(Symbol("cpu"), fn)
cpu_col = true
Ncols = 3
end
cells = zeros(Int, dataobject.lmax - dataobject.lmin + 1, Ncols)
cellsize = zeros(Float64, dataobject.lmax - dataobject.lmin + 1,1)
if verbose println("Counting...") end
@showprogress 1 "" for ilevel=dataobject.lmin:dataobject.lmax
if cpu_col
cpus_ilevel = length( unique( select( filter(p->p.level==ilevel, select(dataobject.data, (:level, :cpu) ) ), :cpu) ) )
cells[Int(ilevel-dataobject.lmin+1),3] = cpus_ilevel
end
cells[Int(ilevel-dataobject.lmin+1),1] = ilevel
cellsize[Int(ilevel-dataobject.lmin+1)] = dataobject.boxlen / 2^ilevel
end
cells_per_level = fit!(CountMap(Int), select(dataobject.data, (:level)) )
#Nlevels = length(cells_per_level.value.keys)
#for ilevel=1:(dataobject.lmax-dataobject.lmin)
#if ilevel <= Nlevels
for (ilevel,j) in enumerate(cells_per_level.value.keys)
cells[j-dataobject.lmin+1,2] = cells_per_level.value.vals[ilevel]
#else
# cells[ilevel,2] = 0.
end
#end
if cpu_col
amr_hydro_table = table(cells[:,1], cells[:,2], cellsize[:], cells[:,3], names=[:level, :cells, :cellsize, :cpus])
else
amr_hydro_table = table(cells[:,1], cells[:,2], cellsize[:], names=[:level, :cells, :cellsize])
end
return amr_hydro_table
end
"""
### Get the number of cells and/or the CPUs per level
```julia
function overview_amr(dataobject::GravDataType, verbose::Bool=true)
function overview_amr(dataobject::GravDataType; verbose::Bool=true)
return a JuliaDB table
```
"""
function amroverview(dataobject::GravDataType, verbose::Bool)
amroverview(dataobject, verbose=verbose)
end
function amroverview(dataobject::GravDataType; verbose::Bool=true)
checkforAMR(dataobject)
verbose = checkverbose(verbose)
# check if cpu column exists
fn = propertynames(dataobject.data.columns)
cpu_col = false
Ncols = 2
if in(Symbol("cpu"), fn)
cpu_col = true
Ncols = 3
end
cells = zeros(Int, dataobject.lmax - dataobject.lmin + 1, Ncols)
cellsize = zeros(Float64, dataobject.lmax - dataobject.lmin + 1,1)
if verbose println("Counting...") end
@showprogress 1 "" for ilevel=dataobject.lmin:dataobject.lmax
if cpu_col
cpus_ilevel = length( unique( select( filter(p->p.level==ilevel, select(dataobject.data, (:level, :cpu) ) ), :cpu) ) )
cells[Int(ilevel-dataobject.lmin+1),3] = cpus_ilevel
end
cells[Int(ilevel-dataobject.lmin+1),1] = ilevel
cellsize[Int(ilevel-dataobject.lmin+1)] = dataobject.boxlen / 2^ilevel
end
cells_per_level = fit!(CountMap(Int), select(dataobject.data, (:level)) )
#Nlevels = length(cells_per_level.value.keys)
#for ilevel=1:(dataobject.lmax-dataobject.lmin)
#if ilevel <= Nlevels
for (ilevel,j) in enumerate(cells_per_level.value.keys)
cells[j-dataobject.lmin+1,2] = cells_per_level.value.vals[ilevel]
#else
# cells[ilevel,2] = 0.
end
#end
if cpu_col
amr_grav_table = table(cells[:,1], cells[:,2], cellsize[:], cells[:,3], names=[:level, :cells, :cellsize, :cpus])
else
amr_grav_table = table(cells[:,1], cells[:,2], cellsize[:], names=[:level, :cells, :cellsize])
end
return amr_grav_table
end
"""
### Get the number of particles and/or the CPUs per level
```julia
function overview_amr(dataobject::PartDataType, verbose::Bool=true)
function overview_amr(dataobject::PartDataType; verbose::Bool=true)
return a JuliaDB table
```
"""
function amroverview(dataobject::PartDataType, verbose::Bool)
amroverview(dataobject, verbose=verbose)
end
function amroverview(dataobject::PartDataType; verbose::Bool=true)
checkforAMR(dataobject)
verbose = checkverbose(verbose)
# check if cpu column exists
fn = propertynames(dataobject.data.columns)
cpu_col = false
Ncols = 2
if in(Symbol("cpu"), fn)
cpu_col = true
Ncols = 3
end
parts = zeros(Int, dataobject.lmax - dataobject.lmin + 1, Ncols)
part_tot = 0
part_masstot = 0
if verbose println("Counting...") end
@showprogress 1 "" for ilevel=dataobject.lmin:dataobject.lmax
if cpu_col
cpus_ilevel = length( unique( select( filter(p->p.level==ilevel, select(dataobject.data, (:level, :cpu) ) ), :cpu) ) )
parts[Int(ilevel-dataobject.lmin+1),3] = cpus_ilevel
end
parts[Int(ilevel-dataobject.lmin+1),1] = ilevel
end
part_per_level = fit!(CountMap(Int32), select(dataobject.data, (:level)) )
Nlevels = length(part_per_level.value.keys)
for ilevel=1:Nlevels
if ilevel <= Nlevels
parts[ilevel,2] = part_per_level.value.vals[ilevel]
else
parts[ilevel,2] = 0.
end
end
if cpu_col
amr_part_table = table(parts[:,1], parts[:,2], parts[:,3], names=[:level, :particles, :cpus])
else
amr_part_table = table(parts[:,1], parts[:,2], names=[:level, :particles])
end
return amr_part_table
end
function checkforAMR(dataobject::DataSetType)
if dataobject.lmax == dataobject.lmin
error("[Mera]: Works only with AMR data!")
end
end
"""
### Get the mass and min/max value of each variable in the database per level
```julia
function dataoverview(dataobject::HydroDataType, verbose::Bool=true)
function dataoverview(dataobject::HydroDataType; verbose::Bool=true)
return a JuliaDB table
```
"""
function dataoverview(dataobject::HydroDataType, verbose::Bool)
return dataoverview(dataobject, verbose=verbose)
end
function dataoverview(dataobject::HydroDataType; verbose::Bool=true)
verbose = checkverbose(verbose)
nvarh = dataobject.info.nvarh
lmin = dataobject.lmin
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
cells_tot = 0
cells_masstot = 0
density_var = :rho
skip_vars = [:cpu, :level, :cx, :cy, :cz]
if dataobject.info.descriptor.usehydro == true
if haskey(dataobject.used_descriptors, 1)
density_var = dataobject.used_descriptors[1]
end
end
names_constr = [Symbol("level")]
fn = propertynames(dataobject.data.columns)
for i in fn
if !in(i, skip_vars)
if i == density_var
append!(names_constr, [Symbol("mass")] )
end
append!(names_constr, [Symbol("$(i)_min")] )
append!(names_constr, [Symbol("$(i)_max")] )
end
end
cells = Array{Any,2}(undef, (dataobject.lmax - dataobject.lmin + 1,length(names_constr) ) )
if verbose println("Calculating...") end
@showprogress 1 "" for ilevel=lmin:lmax
cell_iterator = 1
if isamr
filtered_level = filter(p->p.level==ilevel, dataobject.data )
else # if uniform grid
filtered_level = dataobject.data
end
cells[Int(ilevel-lmin+1),cell_iterator] = ilevel
cell_iterator= cell_iterator + 1
for ifn in fn
if !in(ifn, skip_vars)
if ifn == density_var
cells_msum = sum(select(filtered_level , density_var)) * (dataobject.boxlen / 2^ilevel)^3
#todo: introduce humanize for mass
#cells_masstot = cells_masstot + cells_msum
cells[Int(ilevel-lmin+1),cell_iterator] = cells_msum
cell_iterator= cell_iterator + 1
if length(select(filtered_level, density_var)) != 0
rho_minmax = reduce((min, max), filtered_level, select=density_var)
rhomin= rho_minmax.min
rhomax= rho_minmax.max
else
rhomin= 0.
rhomax= 0.
end
cells[Int(ilevel-lmin+1),cell_iterator] = rhomin
cell_iterator= cell_iterator + 1
cells[Int(ilevel-lmin+1),cell_iterator] = rhomax
cell_iterator= cell_iterator + 1
else
if length(select(filtered_level, ifn)) != 0
value_minmax = reduce((min, max), filtered_level, select=ifn)
valuemin = value_minmax.min
valuemax = value_minmax.max
else
valuemin = 0.
valuemax = 0.
end
cells[Int(ilevel-lmin+1),cell_iterator] = valuemin
cell_iterator= cell_iterator + 1
cells[Int(ilevel-lmin+1),cell_iterator] = valuemax
cell_iterator= cell_iterator + 1
end
end
end
end
hydro_overview_table = table( [cells[:, i ] for i = 1:length(names_constr)]..., names=[names_constr...] )
return hydro_overview_table
end
"""
todo: needs to be tested
### Get the total epot and min/max value of each variable in the database per level
```julia
function dataoverview(dataobject::GravDataType, verbose::Bool=true)
function dataoverview(dataobject::GravDataType; verbose::Bool=true)
return a JuliaDB table
```
"""
function dataoverview(dataobject::GravDataType, verbose::Bool)
return dataoverview(dataobject, verbose=verbose)
end
function dataoverview(dataobject::GravDataType; verbose::Bool=true)
verbose = checkverbose(verbose)
nvarh = length(dataobject.info.gravity_variable_list)
lmin = dataobject.lmin
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
cells_tot = 0
cells_masstot = 0
epot_var = :epot
skip_vars = [:cpu, :level, :cx, :cy, :cz]
if dataobject.info.descriptor.usegravity == true
if haskey(dataobject.used_descriptors, 1)
density_var = dataobject.used_descriptors[1]
end
end
names_constr = [Symbol("level")]
fn = propertynames(dataobject.data.columns)
for i in fn
if !in(i, skip_vars)
if i == epot_var
append!(names_constr, [Symbol("epot_tot")] )
end
append!(names_constr, [Symbol("$(i)_min")] )
append!(names_constr, [Symbol("$(i)_max")] )
end
end
cells = Array{Any,2}(undef, (dataobject.lmax - dataobject.lmin + 1,length(names_constr) ) )
if verbose println("Calculating...") end
@showprogress 1 "" for ilevel=lmin:lmax
cell_iterator = 1
if isamr
filtered_level = filter(p->p.level==ilevel, dataobject.data )
else # if uniform grid
filtered_level = dataobject.data
end
cells[Int(ilevel-lmin+1),cell_iterator] = ilevel
cell_iterator= cell_iterator + 1
for ifn in fn
if !in(ifn, skip_vars)
if ifn == epot_var
cells_msum = sum(select(filtered_level , epot_var))
#todo: introduce humanize for mass
#cells_masstot = cells_masstot + cells_msum
cells[Int(ilevel-lmin+1),cell_iterator] = cells_msum
cell_iterator= cell_iterator + 1
if length(select(filtered_level, epot_var)) != 0
epot_minmax = reduce((min, max), filtered_level, select=epot_var)
epotmin= epot_minmax.min
epotmax= epot_minmax.max
else
epotmin= 0.
epotmax= 0.
end
cells[Int(ilevel-lmin+1),cell_iterator] = epotmin
cell_iterator= cell_iterator + 1
cells[Int(ilevel-lmin+1),cell_iterator] = epotmax
cell_iterator= cell_iterator + 1
else
if length(select(filtered_level, ifn)) != 0
value_minmax = reduce((min, max), filtered_level, select=ifn)
valuemin = value_minmax.min
valuemax = value_minmax.max
else
valuemin = 0.
valuemax = 0.
end
cells[Int(ilevel-lmin+1),cell_iterator] = valuemin
cell_iterator= cell_iterator + 1
cells[Int(ilevel-lmin+1),cell_iterator] = valuemax
cell_iterator= cell_iterator + 1
end
end
end
end
grav_overview_table = table( [cells[:, i ] for i = 1:length(names_constr)]..., names=[names_constr...] )
return grav_overview_table
end
"""
### Get the extrema of each variable in the database
```julia
function dataoverview(dataobject::ClumpDataType)
return a JuliaDB table
```
"""
function dataoverview(dataobject::ClumpDataType)
fn = propertynames(dataobject.data.columns)
s = Series(Extrema())
Ncolumns = length(fn)
values = Array{Any}(undef, Ncolumns+1, 2)
values[1,1] = "min"
values[1,2] = "max"
for i = 1:Ncolumns
a = reduce(s, dataobject.data; select = fn[i])
values[i+1, 1] = a.stats[1].min
values[i+1, 2] = a.stats[1].max
end
column_names = [Symbol("extrema")]
append!(column_names, fn )
clump_overview_table = table( [values[k, : ] for k = 1:(Ncolumns+1) ]...,names=collect(column_names) )
return clump_overview_table
end
"""
### Get the min/max value of each variable in the database per level
```julia
function dataoverview(dataobject::PartDataType, verbose::Bool=true)
function dataoverview(dataobject::PartDataType; verbose::Bool=true)
return a JuliaDB table
```
"""
function dataoverview(dataobject::PartDataType, verbose::Bool)
return dataoverview(dataobject, verbose=verbose)
end
function dataoverview(dataobject::PartDataType; verbose::Bool=true)
verbose = checkverbose(verbose)
lmin = dataobject.lmin
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
parts_tot = 0
parts_masstot = 0
skip_vars = [:cpu, :level]
fn = propertynames(dataobject.data.columns)
#fn = convert(Array{String,1}, fn) #todo delte
names_constr = [Symbol("level")]
if verbose println("Calculating...") end
for i in fn
if !in(i, skip_vars)
append!(names_constr, [Symbol("$(i)_min")] )
append!(names_constr, [Symbol("$(i)_max")] )
end
end
parts = Array{Any,2}(undef, (dataobject.lmax - dataobject.lmin + 1,length(names_constr) ) )
#@showprogress 1 "Searching..."
for ilevel=lmin:lmax
part_iterator = 1
if isamr
filtered_level = filter(p->p.level==ilevel, dataobject.data )
else # if uniform grid
filtered_level = dataobject.data
end
parts[Int(ilevel-lmin+1),part_iterator] = ilevel
part_iterator= part_iterator + 1
for ifn in fn
if !in(ifn, skip_vars)
if length(select(filtered_level, ifn)) != 0
value_minmax = reduce((min, max), filtered_level, select=ifn)
valuemin = value_minmax.min
valuemax = value_minmax.max
else
valuemin = 0.
valuemax = 0.
end
parts[Int(ilevel-lmin+1),part_iterator] = valuemin
part_iterator= part_iterator + 1
parts[Int(ilevel-lmin+1),part_iterator] = valuemax
part_iterator= part_iterator + 1
end
end
end
particle_overview_table = table( [parts[:, i ] for i = 1:length(names_constr)]..., names=[names_constr...] )
return particle_overview_table
end
"""
#### Get the existing simulation snapshots in a given folder
- returns field `outputs` with Array{Int,1} containing the output-numbers of the existing simulations
- returns field `miss` with Array{Int,1} containing the output-numbers of empty simulation folders
- returns field `path` as String
```julia
checkoutputs(path::String="./"; verbose::Bool=true)
return CheckOutputNumberType
```
#### Examples
```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");
```
"""
function checkoutputs(path::String="./"; verbose::Bool=true)
verbose = checkverbose(verbose)
if path == "" || path == " " path="./" end
folder = readdir(path)
# filter "output_" - names
ftrue = occursin.("output_", folder)
folder = folder[ftrue]
# create full path to supposed folders
output_path = joinpath.(path,folder)
# filter real folders
folder = folder[isdir.(output_path)]
# get existing output numbers
missing_outputs = Int[]
existing_outputs = Int[]
Nfolders = length(folder)
if Nfolders > 0
Noutputs_string = [folder[x][8:end] for x in 1:Nfolders]
Noutputs = parse.(Int, Noutputs_string)
# find missing output numbers
maxoutput = maximum(Noutputs)
#expected_outputs = 1:maxoutput
for Nout in Noutputs
fnames = createpath(Nout, path)
isinfofile = isfile(fnames.info)
if isinfofile
append!(existing_outputs, Nout)
else
append!(missing_outputs, Nout)
end
end
end
if verbose
N_exist = length(existing_outputs)
if N_exist !=0
Min_exist = minimum(existing_outputs)
Max_exist = maximum(existing_outputs)
N_miss = length(missing_outputs)
println( "Outputs - existing: $N_exist betw. $Min_exist:$Max_exist - missing: $N_miss")
else
println( "Outputs - 0")
end
println()
end
return CheckOutputNumberType(existing_outputs, missing_outputs, path)
end
"""
#### List the existing simulation snapshots in a given folder
- returns a Dictonary with existing simulations and their folder names with:
- field `outputs` with Array{Int,1} containing the output-numbers of the existing simulations
- field `miss` with Array{Int,1} containing the output-numbers of empty simulation folders
- field `path` as String
```julia
checksimulations(path::String="./"; verbose::Bool=true, filternames=String[])
return Dict with named Tuple: simulation name and N=CheckOutputNumberType
```
"""
function checksimulations(path::String="./"; verbose::Bool=true, filternames=String[])
verbose = checkverbose(verbose)
fulldirpaths=filter(isdir,readdir(path,join=true))
dirnames=basename.(fulldirpaths)
# filter folders
filter!(e->e ≠ ".ipynb_checkpoints",dirnames)
if length(filternames) != 0
for ifnames in filternames
filter!(e->e ≠ ifnames,dirnames)
end
end
# check folders for simulation outputs
sims = Dict()
namesize = 0
for (i, idir) in enumerate(dirnames)
ipath = joinpath(path, idir)
N = checkoutputs(ipath, verbose=false)
if length(N.outputs) !=0 || length(N.miss) !=0
sims[i] = (name=idir, N=N)
if length(idir) > namesize
namesize = length(idir)
end
end
end
if verbose
if length(sims) != 0
for i = 1:length(sims)
isim = sims[i]
N_exist = length(isim.N.outputs)
Min_exist = minimum(isim.N.outputs)
Max_exist = maximum(isim.N.outputs)
N_miss = length(isim.N.miss)
lname = length(isim.name)
namediff = namesize-lname
emptyspace = ""
if namediff > 0
for i = 1: namediff
emptyspace *= " "
end
end
println("Sim $i \t", isim.name, emptyspace, "\t - Outputs - existing: $N_exist betw. $Min_exist:$Max_exist - missing: $N_miss")
end
else
println("no simulation data found" )
end
println()
end
return sims
end
"""
#### Get physical time in selected units
returns Float
```julia
gettime(output::Real; path::String="./", unit::Symbol=:standard)
gettime(dataobject::DataSetType; unit::Symbol=:standard)
gettime(dataobject::InfoType, unit::Symbol=:standard)
return time
```
#### Arguments Function 1
##### Required:
- **`output`:** give the output-number of the simulation
##### Predefined/Optional Keywords:
- **`path`:** the path to the output folder relative to the current folder or absolute path
- **`unit`:** return the variable in given unit
#### Arguments Function 2
##### Required:
- **`dataobject`:** needs to be of type: "DataSetType"
##### Predefined/Optional Keywords:
- **`unit`:** return the variable in given unit
#### Arguments Function 3
##### Required:
- **`dataobject`:** needs to be of type: "InfoType"
##### Predefined/Optional Keywords:
- **`unit`:** return the variable in given unit
"""
function gettime(output::Real, path::String, unit::Symbol;)
return gettime(output, path=path, unit=unit)
end
function gettime(output::Real, path::String; unit::Symbol=:standard)
return gettime(output, path=path, unit=unit)
end
function gettime(output::Real; path::String="./", unit::Symbol=:standard)
info = getinfo(output, path, verbose=false)
return info.time * getunit(info, unit)
end
function gettime(dataobject::DataSetType, unit::Symbol;)
return gettime(dataobject, unit=unit)
end
function gettime(dataobject::DataSetType; unit::Symbol=:standard)
return dataobject.info.time * getunit(dataobject.info, unit)
end
function gettime(dataobject::InfoType, unit::Symbol;)
return gettime(dataobject, unit=unit)
end
function gettime(dataobject::InfoType; unit::Symbol=:standard)
return dataobject.time * getunit(dataobject, unit)
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 22332 |
"""
cuboid ranges
convert given ranges and print overview on screen
used for gethydro, getparticles, getgravity, getclumps..., subregions...
"""
function prepranges( dataobject::InfoType,
range_unit::Symbol,
verbose::Bool,
xrangem::Array{<:Any,1},
yrangem::Array{<:Any,1},
zrangem::Array{<:Any,1},
center::Array{<:Any,1};
dataranges::Array{<:Real,1}=[0.,1., 0.,1., 0.,1.] )
xrange = zeros(Float64,2)
yrange = zeros(Float64,2)
zrange = zeros(Float64,2)
selected_unit = 1. # :standard
conv = 1. # :standard, variable used to convert to standard units
if range_unit != :standard
selected_unit = getunit(dataobject, range_unit)
conv = dataobject.boxlen * selected_unit
end
center = prepboxcenter(dataobject, range_unit, center)
# assign ranges to selected data range or missing ranges = full box
if xrangem[1] === missing
xmin = dataranges[1]
else
xrange[1]=xrangem[1]
xmin = (xrange[1] + center[1]) / conv
end
if xrangem[2] === missing
xmax = dataranges[2]
else
xrange[2]=xrangem[2]
xmax = (xrange[2] + center[1]) / conv
end
if yrangem[1] === missing
ymin = dataranges[3]
else
yrange[1]=yrangem[1]
ymin = (yrange[1] + center[2]) / conv
end
if yrangem[2] === missing
ymax = dataranges[4]
else
yrange[2] = yrangem[2]
ymax = (yrange[2] + center[2]) / conv
end
if zrangem[1] === missing
zmin = dataranges[5]
else
zrange[1] = zrangem[1]
zmin = (zrange[1] + center[3]) / conv
end
if zrangem[2] === missing
zmax = dataranges[6]
else
zrange[2]=zrangem[2]
zmax = (zrange[2] + center[3]) / conv
end
center = center ./ conv
# ensure that min-var is minimum and max-var is maximum of each dimension
if xmin > xmax error("[Mera]: xmin > xmax") end
if ymin > ymax error("[Mera]: ymin > ymax") end
if zmin > zmax error("[Mera]: zmin > zmax") end
if xmax < xmin error("[Mera]: xmax < xmin") end
if ymax < ymin error("[Mera]: ymax < ymin") end
if zmax < zmin error("[Mera]: zmax < zmin") end
# ensure that ranges are inside the box
xmin = maximum( [xmin, dataranges[1]] )
ymin = maximum( [ymin, dataranges[3]] )
zmin = maximum( [zmin, dataranges[5]] )
xmax = minimum( [xmax, dataranges[2]] )
ymax = minimum( [ymax, dataranges[4]] )
zmax = minimum( [zmax, dataranges[6]] )
if verbose
if center != [0., 0., 0.]
print("center: $(round.(center, digits=7)) ")
center_val1, center_unit1= humanize(center[1] * dataobject.boxlen , dataobject.scale, 3, "length")
center_val2, center_unit2= humanize(center[2] * dataobject.boxlen , dataobject.scale, 3, "length")
center_val3, center_unit3= humanize(center[3] * dataobject.boxlen , dataobject.scale, 3, "length")
if center_val1 == 0. center_unit1 = xmax_unit end
if center_val2 == 0. center_unit2 = xmax_unit end
if center_val3 == 0. center_unit3 = xmax_unit end
print("==> [$center_val1 [$center_unit1] :: $center_val2 [$center_unit2] :: $center_val3 [$center_unit3]]\n")
println()
end
#println("domain \t \t \t \thuman-readable units")
println("domain:")
print("xmin::xmax: $(round(xmin, digits=7)) :: $(round(xmax, digits=7)) \t")
xmin_val, xmin_unit = humanize(xmin * dataobject.boxlen, dataobject.scale, 3, "length")
xmax_val, xmax_unit = humanize(xmax * dataobject.boxlen, dataobject.scale, 3, "length")
if xmin_val == 0. xmin_unit = xmax_unit end
print("==> $xmin_val [$xmin_unit] :: $xmax_val [$xmax_unit]\n")
print("ymin::ymax: $(round(ymin, digits=7)) :: $(round(ymax, digits=7)) \t")
ymin_val, ymin_unit = humanize(ymin * dataobject.boxlen, dataobject.scale, 3, "length")
ymax_val, ymax_unit = humanize(ymax * dataobject.boxlen, dataobject.scale, 3, "length")
if ymin_val == 0. ymin_unit = xmax_unit end
print("==> $ymin_val [$ymin_unit] :: $ymax_val [$ymax_unit]\n")
print("zmin::zmax: $(round(zmin, digits=7)) :: $(round(zmax, digits=7)) \t")
zmin_val, zmin_unit = humanize(zmin * dataobject.boxlen, dataobject.scale, 3, "length")
zmax_val, zmax_unit = humanize(zmax * dataobject.boxlen, dataobject.scale, 3, "length")
if zmin_val == 0. zmin_unit = xmax_unit end
print("==> $zmin_val [$zmin_unit] :: $zmax_val [$zmax_unit]\n")
println()
end
ranges = [xmin, xmax, ymin, ymax, zmin, zmax]
return ranges
end
"""
cylinder ranges (height != 0.), sphere ranges (height==0.)
convert given ranges + radius and print overview on screen
used for subregions...
"""
function prepranges( dataobject::InfoType,
center::Array{<:Any,1},
radius::Real,
height::Real,
range_unit::Symbol,
verbose::Bool)
center = prepboxcenter(dataobject, range_unit, center)
selected_unit = 1.
if range_unit == :standard
xmin = -radius + center[1]
xmax = radius + center[1]
ymin = -radius + center[2]
ymax = radius + center[2]
if height != 0.
zmin = - height + center[3]
zmax = height + center[3]
else
zmin = - radius + center[3]
zmax = radius + center[3]
end
# given center relative to the data range in units: cell centers
#todo
else
selected_unit = getunit(dataobject, range_unit)
xmin = (-radius + center[1]) * selected_unit /dataobject.boxlen
xmax = ( radius + center[1]) * selected_unit /dataobject.boxlen
ymin = (-radius + center[2]) * selected_unit /dataobject.boxlen
ymax = ( radius + center[2]) * selected_unit /dataobject.boxlen
if height != 0.
zmin = ( -height + center[3]) * selected_unit /dataobject.boxlen
zmax = ( height + center[3]) * selected_unit /dataobject.boxlen
else
zmin = ( -radius + center[3]) * selected_unit /dataobject.boxlen
zmax = ( radius + center[3]) * selected_unit /dataobject.boxlen
end
# given center relative to the data range in units: cell centers
cx_shift = center[1] * selected_unit /dataobject.boxlen
cy_shift = center[2] * selected_unit /dataobject.boxlen
cz_shift = center[3] * selected_unit /dataobject.boxlen
radius_shift = radius * selected_unit /dataobject.boxlen
if height != 0. height_shift = height * selected_unit /dataobject.boxlen end
center = center / (dataobject.boxlen * selected_unit )
end
if verbose
if center != [0., 0., 0.]
print("center: $(round.(center,digits=7)) ")
center_val1, center_unit1= humanize(center[1] * dataobject.boxlen , dataobject.scale, 3, "length")
center_val2, center_unit2= humanize(center[2] * dataobject.boxlen , dataobject.scale, 3, "length")
center_val3, center_unit3= humanize(center[3] * dataobject.boxlen , dataobject.scale, 3, "length")
if center_val1 == 0. center_unit1 = xmax_unit end
if center_val2 == 0. center_unit2 = xmax_unit end
if center_val3 == 0. center_unit3 = xmax_unit end
print("==> [$center_val1 [$center_unit1] :: $center_val2 [$center_unit2] :: $center_val3 [$center_unit3]]\n")
println()
end
#println("domain \t \t \t \thuman-readable units")
println("domain:")
print("xmin::xmax: $(round(xmin,digits=7)) :: $(round(xmax,digits=7)) \t")
xmin_val, xmin_unit = humanize(xmin * dataobject.boxlen , dataobject.scale, 3, "length")
xmax_val, xmax_unit = humanize(xmax * dataobject.boxlen, dataobject.scale, 3, "length")
if xmin_val == 0. xmin_unit = xmax_unit end
print("==> $xmin_val [$xmin_unit] :: $xmax_val [$xmax_unit]\n")
print("ymin::ymax: $(round(ymin,digits=7)) :: $(round(ymax,digits=7)) \t")
ymin_val, ymin_unit = humanize(ymin * dataobject.boxlen, dataobject.scale, 3, "length")
ymax_val, ymax_unit = humanize(ymax * dataobject.boxlen, dataobject.scale, 3, "length")
if ymin_val == 0. ymin_unit = xmax_unit end
print("==> $ymin_val [$ymin_unit] :: $ymax_val [$ymax_unit]\n")
print("zmin::zmax: $(round(zmin,digits=7)) :: $(round(zmax,digits=7)) \t")
zmin_val, zmin_unit = humanize(zmin * dataobject.boxlen, dataobject.scale, 3, "length")
zmax_val, zmax_unit = humanize(zmax * dataobject.boxlen, dataobject.scale, 3, "length")
if zmin_val == 0. zmin_unit = xmax_unit end
print("==> $zmin_val [$zmin_unit] :: $zmax_val [$zmax_unit]\n")
println()
R_val, R_unit = humanize(radius_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Radius: $R_val [$R_unit]")
if height != 0.
h_val, h_unit = humanize(height_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Height: $h_val [$h_unit]")
end
end
# if xmin < 0. || ymin < 0. || zmin < 0. || xmax > 1. || ymax > 1. || zmax > 1.
# error("[Mera]: Given range(s) outside of box!")
# end
ranges = [xmin, xmax, ymin, ymax, zmin, zmax]
if height != 0.
return ranges, cx_shift, cy_shift, cz_shift, radius_shift, height_shift
else
return ranges, cx_shift, cy_shift, cz_shift, radius_shift
end
end
"""
cylindrical shell ranges
convert given ranges + radius and print overview on screen
used for shellregions...
"""
function prep_cylindrical_shellranges( dataobject::InfoType,
center::Array{<:Any,1},
radius_in::Real,
radius_out::Real,
height::Real,
range_unit::Symbol,
verbose::Bool)
center = prepboxcenter(dataobject, range_unit, center)
selected_unit = 1.
if range_unit == :standard
xmin = -radius_out + center[1]
xmax = radius_out + center[1]
ymin = -radius_out + center[2]
ymax = radius_out + center[2]
zmin = - height + center[3]
zmax = height + center[3]
# given center relative to the data range in units: cell centers
#todo
else
selected_unit = getunit(dataobject, range_unit)
xmin = (-radius_out + center[1]) * selected_unit /dataobject.boxlen
xmax = ( radius_out + center[1]) * selected_unit /dataobject.boxlen
ymin = (-radius_out + center[2]) * selected_unit /dataobject.boxlen
ymax = ( radius_out + center[2]) * selected_unit /dataobject.boxlen
zmin = ( -height + center[3]) * selected_unit /dataobject.boxlen
zmax = ( height + center[3]) * selected_unit /dataobject.boxlen
# given center relative to the data range in units: cell centers
cx_shift = center[1] * selected_unit /dataobject.boxlen
cy_shift = center[2] * selected_unit /dataobject.boxlen
cz_shift = center[3] * selected_unit /dataobject.boxlen
radius_in_shift = radius_in * selected_unit /dataobject.boxlen
radius_out_shift = radius_out * selected_unit /dataobject.boxlen
height_shift = height * selected_unit /dataobject.boxlen
center = center / (dataobject.boxlen * selected_unit )
end
if verbose
if center != [0., 0., 0.]
print("center: $(round.(center,digits=7)) ")
center_val1, center_unit1= humanize(center[1] * dataobject.boxlen , dataobject.scale, 3, "length")
center_val2, center_unit2= humanize(center[2] * dataobject.boxlen , dataobject.scale, 3, "length")
center_val3, center_unit3= humanize(center[3] * dataobject.boxlen , dataobject.scale, 3, "length")
if center_val1 == 0. center_unit1 = xmax_unit end
if center_val2 == 0. center_unit2 = xmax_unit end
if center_val3 == 0. center_unit3 = xmax_unit end
print("==> [$center_val1 [$center_unit1] :: $center_val2 [$center_unit2] :: $center_val3 [$center_unit3]]\n")
println()
end
#println("domain \t \t \t \thuman-readable units")
println("domain:")
print("xmin::xmax: $(round(xmin,digits=7)) :: $(round(xmax,digits=7)) \t")
xmin_val, xmin_unit = humanize(xmin * dataobject.boxlen , dataobject.scale, 3, "length")
xmax_val, xmax_unit = humanize(xmax * dataobject.boxlen, dataobject.scale, 3, "length")
if xmin_val == 0. xmin_unit = xmax_unit end
print("==> $xmin_val [$xmin_unit] :: $xmax_val [$xmax_unit]\n")
print("ymin::ymax: $(round(ymin,digits=7)) :: $(round(ymax,digits=7)) \t")
ymin_val, ymin_unit = humanize(ymin * dataobject.boxlen, dataobject.scale, 3, "length")
ymax_val, ymax_unit = humanize(ymax * dataobject.boxlen, dataobject.scale, 3, "length")
if ymin_val == 0. ymin_unit = xmax_unit end
print("==> $ymin_val [$ymin_unit] :: $ymax_val [$ymax_unit]\n")
print("zmin::zmax: $(round(zmin,digits=7)) :: $(round(zmax,digits=7)) \t")
zmin_val, zmin_unit = humanize(zmin * dataobject.boxlen, dataobject.scale, 3, "length")
zmax_val, zmax_unit = humanize(zmax * dataobject.boxlen, dataobject.scale, 3, "length")
if zmin_val == 0. zmin_unit = xmax_unit end
print("==> $zmin_val [$zmin_unit] :: $zmax_val [$zmax_unit]\n")
println()
Rin_val, Rin_unit = humanize(radius_in_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Inner radius: $Rin_val [$Rin_unit]")
Rout_val, Rout_unit = humanize(radius_out_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Outer radius: $Rout_val [$Rout_unit]")
radius_diff_shift = radius_out_shift - radius_in_shift
Rdiff_val, Rdiff_unit = humanize(radius_diff_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Radius diff: $Rdiff_val [$Rdiff_unit]")
h_val, h_unit = humanize(height_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Height: $h_val [$h_unit]")
end
# if xmin < 0. || ymin < 0. || zmin < 0. || xmax > 1. || ymax > 1. || zmax > 1.
# error("[Mera]: Given range(s) outside of box!")
# end
ranges = [xmin, xmax, ymin, ymax, zmin, zmax]
return ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift, height_shift
end
"""
spherical shell ranges
convert given ranges + radius and print overview on screen
used for shellregions...
"""
function prep_spherical_shellranges( dataobject::InfoType,
center::Array{<:Any,1},
radius_in::Real,
radius_out::Real,
range_unit::Symbol,
verbose::Bool)
center = prepboxcenter(dataobject, range_unit, center)
selected_unit = 1.
if range_unit == :standard
xmin = -radius_out + center[1]
xmax = radius_out + center[1]
ymin = -radius_out + center[2]
ymax = radius_out + center[2]
zmin = - radius_out + center[3]
zmax = radius_out + center[3]
# given center relative to the data range in units: cell centers
#todo
else
selected_unit = getunit(dataobject, range_unit)
xmin = (-radius_out + center[1]) * selected_unit /dataobject.boxlen
xmax = ( radius_out + center[1]) * selected_unit /dataobject.boxlen
ymin = (-radius_out + center[2]) * selected_unit /dataobject.boxlen
ymax = ( radius_out + center[2]) * selected_unit /dataobject.boxlen
zmin = ( -radius_out + center[3]) * selected_unit /dataobject.boxlen
zmax = ( radius_out + center[3]) * selected_unit /dataobject.boxlen
# given center relative to the data range in units: cell centers
cx_shift = center[1] * selected_unit /dataobject.boxlen
cy_shift = center[2] * selected_unit /dataobject.boxlen
cz_shift = center[3] * selected_unit /dataobject.boxlen
radius_in_shift = radius_in * selected_unit /dataobject.boxlen
radius_out_shift = radius_out * selected_unit /dataobject.boxlen
center = center / (dataobject.boxlen * selected_unit )
end
if verbose
if center != [0., 0., 0.]
print("center: $(round.(center,digits=7)) ")
center_val1, center_unit1= humanize(center[1] * dataobject.boxlen , dataobject.scale, 3, "length")
center_val2, center_unit2= humanize(center[2] * dataobject.boxlen , dataobject.scale, 3, "length")
center_val3, center_unit3= humanize(center[3] * dataobject.boxlen , dataobject.scale, 3, "length")
if center_val1 == 0. center_unit1 = xmax_unit end
if center_val2 == 0. center_unit2 = xmax_unit end
if center_val3 == 0. center_unit3 = xmax_unit end
print("==> [$center_val1 [$center_unit1] :: $center_val2 [$center_unit2] :: $center_val3 [$center_unit3]]\n")
println()
end
#println("domain \t \t \t \thuman-readable units")
println("domain:")
print("xmin::xmax: $(round(xmin,digits=7)) :: $(round(xmax,digits=7)) \t")
xmin_val, xmin_unit = humanize(xmin * dataobject.boxlen , dataobject.scale, 3, "length")
xmax_val, xmax_unit = humanize(xmax * dataobject.boxlen, dataobject.scale, 3, "length")
if xmin_val == 0. xmin_unit = xmax_unit end
print("==> $xmin_val [$xmin_unit] :: $xmax_val [$xmax_unit]\n")
print("ymin::ymax: $(round(ymin,digits=7)) :: $(round(ymax,digits=7)) \t")
ymin_val, ymin_unit = humanize(ymin * dataobject.boxlen, dataobject.scale, 3, "length")
ymax_val, ymax_unit = humanize(ymax * dataobject.boxlen, dataobject.scale, 3, "length")
if ymin_val == 0. ymin_unit = xmax_unit end
print("==> $ymin_val [$ymin_unit] :: $ymax_val [$ymax_unit]\n")
print("zmin::zmax: $(round(zmin,digits=7)) :: $(round(zmax,digits=7)) \t")
zmin_val, zmin_unit = humanize(zmin * dataobject.boxlen, dataobject.scale, 3, "length")
zmax_val, zmax_unit = humanize(zmax * dataobject.boxlen, dataobject.scale, 3, "length")
if zmin_val == 0. zmin_unit = xmax_unit end
print("==> $zmin_val [$zmin_unit] :: $zmax_val [$zmax_unit]\n")
println()
Rin_val, Rin_unit = humanize(radius_in_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Inner radius: $Rin_val [$Rin_unit]")
Rout_val, Rout_unit = humanize(radius_out_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Outer radius: $Rout_val [$Rout_unit]")
radius_diff_shift = radius_out_shift - radius_in_shift
Rdiff_val, Rdiff_unit = humanize(radius_diff_shift * dataobject.boxlen, dataobject.scale, 3, "length")
println("Radius diff: $Rdiff_val [$Rdiff_unit]")
end
# if xmin < 0. || ymin < 0. || zmin < 0. || xmax > 1. || ymax > 1. || zmax > 1.
# error("[Mera]: Given range(s) outside of box!")
# end
ranges = [xmin, xmax, ymin, ymax, zmin, zmax]
return ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift
end
function prepboxcenter(dataobject::InfoType, range_unit::Symbol, center::Array{<:Any,1})
selected_unit = 1.
if range_unit != :standard
selected_unit = getunit(dataobject, range_unit)
end
# check for :bc, :boxcenter
Ncenter = length(center)
if Ncenter == 1
if in(:bc, center) || in(:boxcenter, center)
if range_unit == :standard
bc = 0.5
else
bc = dataobject.boxlen * 0.5 * selected_unit # use range_unit
end
centerm = [bc, bc, bc]
end
else
centerm = zeros(Float64, length(center))
for i = 1:Ncenter
if center[i] == :bc || center[i] == :boxcenter
if range_unit == :standard
bc =0.5
else
bc = dataobject.boxlen * 0.5 * selected_unit # use range_unit
end
centerm[i] = bc
else
centerm[i] = center[i]
end
end
end
return centerm
end
function prepboxcenter(dataobject::InfoType, selected_unit::Real, centerm::Any)
Nc = length(centerm)
center = zeros(Float64, Nc)
if centerm == :bc || centerm == :boxcenter
center = dataobject.boxlen * 0.5 * selected_unit
else
center = centerm ./ dataobject.boxlen .* selected_unit
end
return center
end
function prepdatacenter(dataobject::InfoType, center::Array{<:Any,1}, range_unit::Symbol, data_centerm::Array{<:Any,1}, data_center_unit::Symbol)
center = center_in_standardnotation(dataobject, center, range_unit)
selected_unit = 1.
if data_center_unit != :standard
selected_unit = getunit(dataobject, data_center_unit)
end
Ndc = length(center)
data_center = zeros(Float64, Ndc)
if Ndc == 3
if data_centerm[1] === missing
data_center[1] = center[1]
else
data_center[1] = prepboxcenter(dataobject, selected_unit, data_centerm[1])
end
if data_centerm[2] === missing
data_center[2] = center[2]
else
data_center[2] = prepboxcenter(dataobject, selected_unit, data_centerm[2])
end
if data_centerm[3] === missing
data_center[3] = center[3]
else
data_center[3] = prepboxcenter(dataobject, selected_unit, data_centerm[3])
end
elseif Ndc == 1
data_center[1] = data_center[2] = data_center[3] = prepboxcenter(dataobject, selected_unit, data_centerm[1])
end
return data_center
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2438 |
function projection()
println("Predefined vars for projections:")
println("------------------------------------------------")
println("=====================[gas]:=====================")
println(" -all the non derived hydro vars-")
println(":cpu, :level, :rho, :cx, :cy, :cz, :vx, :vy, :vz, :p, var6,...")
println("further possibilities: :rho, :density, :ρ")
println(" -derived hydro vars-")
println(":x, :y, :z")
println(":sd or :Σ or :surfacedensity")
println(":mass, :cellsize, :freefall_time")
println(":cs, :mach, :jeanslength, :jeansnumber")
println(":t, :Temp, :Temperature with p/rho")
println()
println("==================[particles]:==================")
println(" all the non derived vars:")
println(":cpu, :level, :id, :family, :tag ")
println(":x, :y, :z, :vx, :vy, :vz, :mass, :birth, :metal....")
println()
println(" -derived particle vars-")
println(":age")
println()
println("==============[gas or particles]:===============")
println(":v, :ekin")
println("squared => :vx2, :vy2, :vz2")
println("velocity dispersion => σx, σy, σz, σ")
println()
println("related to a given center:")
println("---------------------------")
println(":vr_cylinder, vr_sphere (radial components)")
println(":vϕ_cylinder, :vθ")
println("squared => :vr_cylinder2, :vϕ_cylinder2")
println("velocity dispersion => σr_cylinder, σϕ_cylinder ")
#println(":l, :lx, :ly, :lz :lr, :lϕ, :lθ")
println()
println("2d maps (not projected) => :r_cylinder, :ϕ")
#println(":r_cylinder") #, :r_sphere")
#println(":ϕ") # :θ
println()
println("------------------------------------------------")
println()
return
end
# check if only variables from ranglecheck are selected
function checkformaps(selected_vars::Array{Symbol,1}, reference_vars::Array{Symbol,1})
Nvars = length(selected_vars)
cw = 0
for iw in selected_vars
if in(iw,reference_vars)
cw +=1
end
end
Ndiff = Nvars-cw
return Ndiff != 0
end
# function checkformaps(dataobject::DataMapsType, reference_vars::Array{Symbol,1})
# Nvars =0
# cw = 0
# for iw in keys(dataobject.maps)
# Nvars +=1
# if in(iw,reference_vars)
# cw +=1
# end
# end
# Ndiff = Nvars-cw
# return Ndiff != 0
# end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 38765 | """
#### Project variables or derived quantities from the **hydro-dataset**:
- projection to an arbitrary large grid: give pixelnumber for each dimension = res
- overview the list of predefined quantities with: projection()
- select variable(s) and their unit(s)
- limit to a maximum range
- select a coarser grid than the maximum resolution of the loaded data (maps with both resolutions are created)
- give the spatial center (with units) of the data within the box (relevant e.g. for radius dependency)
- relate the coordinates to a direction (x,y,z)
- select arbitrary weighting: mass (default), volume weighting, etc.
- pass a mask to exclude elements (cells) from the calculation
- toggle verbose mode
- toggle progress bar
- pass a struct with arguments (myargs)
```julia
projection( dataobject::HydroDataType, vars::Array{Symbol,1};
units::Array{Symbol,1}=[:standard],
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask::Union{Vector{Bool}, MaskType}=[false],
direction::Symbol=:z,
weighting::Array{<:Any,1}=[:mass, missing],
mode::Symbol=:standard,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return HydroMapsType
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "HydroDataType"
- **`var(s)`:** select a variable from the database or a predefined quantity (see field: info, function projection(), dataobject.data)
##### Predefined/Optional Keywords:
- **`unit(s)`:** return the variable in given units
- **`pxsize``:** creates maps with the given pixel size in physical/code units (dominates over: res, lmax) : pxsize=[physical size (Number), physical unit (Symbol)]
- **`res`** create maps with the given pixel number for each deminsion; if res not given by user -> lmax is selected; (pixel number is related to the full boxsize)
- **`lmax`:** create maps with 2^lmax pixels for each dimension
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`weighting`:** select between `:mass` weighting (default) and any other pre-defined quantity, e.g. `:volume`. Pass an array with the weighting=[quantity (Symbol), physical unit (Symbol)]
- **`data_center`:** to calculate the data relative to the data_center; in units given by argument `data_center_unit`; by default the argument data_center = center ;
- **`data_center_unit`:** :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`direction`:** select between: :x, :y, :z
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
- **`mode`:** :standard (default) handles projections other than surface density. mode=:standard (default) -> weighted average; mode=:sum sums-up the weighted quantities in projection direction.
- **`show_progress`:** print progress bar on screen
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of lmax, xrange, yrange, zrange, center, range_unit, verbose, show_progress
### Defined Methods - function defined for different arguments
- projection( dataobject::HydroDataType, var::Symbol; ...) # one given variable
- projection( dataobject::HydroDataType, var::Symbol, unit::Symbol; ...) # one given variable with its unit
- projection( dataobject::HydroDataType, vars::Array{Symbol,1}; ...) # several given variables -> array needed
- projection( dataobject::HydroDataType, vars::Array{Symbol,1}, units::Array{Symbol,1}; ...) # several given variables and their corresponding units -> both arrays
- projection( dataobject::HydroDataType, vars::Array{Symbol,1}, unit::Symbol; ...) # several given variables that have the same unit -> array for the variables and a single Symbol for the unit
#### Examples
...
"""
function projection( dataobject::HydroDataType, var::Symbol;
unit::Symbol=:standard,
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask::Union{Vector{Bool}, MaskType}=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Array{<:Any,1}=[:mass, missing],
mode::Symbol=:standard,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return projection(dataobject, [var], units=[unit],
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
mode=mode,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
verbose=verbose,
show_progress=show_progress,
myargs=myargs )
end
function projection( dataobject::HydroDataType, var::Symbol, unit::Symbol;
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask::Union{Vector{Bool}, MaskType}=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Array{<:Any,1}=[:mass, missing],
mode::Symbol=:standard,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return projection(dataobject, [var], units=[unit],
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
mode=mode,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function projection( dataobject::HydroDataType, vars::Array{Symbol,1}, units::Array{Symbol,1};
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask::Union{Vector{Bool}, MaskType}=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Array{<:Any,1}=[:mass, missing],
mode::Symbol=:standard,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return projection(dataobject, vars, units=units,
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
mode=mode,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function projection( dataobject::HydroDataType, vars::Array{Symbol,1}, unit::Symbol;
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask::Union{Vector{Bool}, MaskType}=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Array{<:Any,1}=[:mass, missing],
mode::Symbol=:standard,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return projection(dataobject, vars, units=fill(unit, length(vars)),
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
mode=mode,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function projection( dataobject::HydroDataType, vars::Array{Symbol,1};
units::Array{Symbol,1}=[:standard],
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask::Union{Vector{Bool}, MaskType}=[false],
direction::Symbol=:z,
weighting::Array{<:Any,1}=[:mass, missing],
mode::Symbol=:standard,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
# take values from myargs if given
if !(myargs.pxsize === missing) pxsize = myargs.pxsize end
if !(myargs.res === missing) res = myargs.res end
if !(myargs.lmax === missing) lmax = myargs.lmax end
if !(myargs.direction === missing) direction = myargs.direction end
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.data_center === missing) data_center = myargs.data_center end
if !(myargs.data_center_unit === missing) data_center_unit = myargs.data_center_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
if !(myargs.show_progress === missing) show_progress = myargs.show_progress end
verbose = Mera.checkverbose(verbose)
show_progress = Mera.checkprogress(show_progress)
printtime("", verbose)
lmin = dataobject.lmin
#lmax = dataobject.lmax
simlmax=dataobject.lmax
#simlmax=lmax
##Nlevel = simlmax-lmin
boxlen = dataobject.boxlen
if res === missing res = 2^lmax end
if !(pxsize[1] === missing)
px_unit = 1. # :standard
if length(pxsize) != 1
if !(pxsize[2] === missing)
if pxsize[2] != :standard
px_unit = getunit(dataobject.info, pxsize[2])
end
end
end
px_scale = pxsize[1] / px_unit
res = boxlen/px_scale
end
res = ceil(Int, res) # be sure to have Integer
if !(weighting[1] === missing)
weight_scale = 1. # :standard
if length(weighting) != 1
if !(weighting[2] === missing)
if weighting[2] != :standard
weight_scale = getunit(dataobject.info, weighting[2])
end
end
end
end
#ranges = [xrange[1],xrange[1],yrange[1],yrange[1],zrange[1],zrange[1]]
scale = dataobject.scale
nvarh = dataobject.info.nvarh
lmax_projected = lmax
isamr = Mera.checkuniformgrid(dataobject, dataobject.lmax)
selected_vars = deepcopy(vars) #unique(vars)
#sd_names = [:sd, :Σ, :surfacedensity]
density_names = [:density, :rho, :ρ]
rcheck = [:r_cylinder, :r_sphere]
anglecheck = [:ϕ]
σcheck = [:σx, :σy, :σz, :σ, :σr_cylinder, :σϕ_cylinder]
σ_to_v = SortedDict( :σx => [:vx, :vx2],
:σy => [:vy, :vy2],
:σz => [:vz, :vz2],
:σ => [:v, :v2],
:σr_cylinder => [:vr_cylinder, :vr_cylinder2],
:σϕ_cylinder => [:vϕ_cylinder, :vϕ_cylinder2] )
# checks to use maps instead of projections
notonly_ranglecheck_vars = check_for_maps(selected_vars, rcheck, anglecheck, σcheck, σ_to_v)
selected_vars = check_need_rho(dataobject, selected_vars, weighting[1], notonly_ranglecheck_vars)
# convert given ranges and print overview on screen
ranges = Mera.prepranges(dataobject.info,range_unit, verbose, xrange, yrange, zrange, center, dataranges=dataobject.ranges)
data_centerm = Mera.prepdatacenter(dataobject.info, center, range_unit, data_center, data_center_unit)
if verbose
println("Selected var(s)=$(tuple(selected_vars...)) ")
println("Weighting = :", weighting[1])
println()
end
x_coord, y_coord, z_coord, extent, extent_center, ratio , length1, length2, length1_center, length2_center, rangez = prep_maps(direction, data_centerm, res, boxlen, ranges, selected_vars)
pixsize = dataobject.boxlen / res # in code units
if verbose
println("Effective resolution: $res^2")
println("Map size: $length1 x $length2")
px_val, px_unit = humanize(pixsize, dataobject.scale, 3, "length")
pxmin_val, pxmin_unit = humanize(boxlen/2^dataobject.lmax, dataobject.scale, 3, "length")
println("Pixel size: $px_val [$px_unit]")
println("Simulation min.: $pxmin_val [$pxmin_unit]")
println()
end
skipmask = check_mask(dataobject, mask, verbose)
# prepare data
# =================================
maps = SortedDict( )
maps_unit = SortedDict( )
maps_weight = SortedDict( )
maps_mode = SortedDict( )
if notonly_ranglecheck_vars
newmap_w = zeros(Float64, (length1, length2) )
data_dict, xval, yval, leveldata, weightval, maps = prep_data(dataobject, x_coord, y_coord, z_coord, mask, ranges, weighting[1], res, selected_vars, maps, center, range_unit, anglecheck, rcheck, σcheck, skipmask, rangez, length1, length2, isamr, simlmax)
closed=:left
if show_progress
p = 1 # show updates
else
p = simlmax+2 # do not show updates
end
#if show_progress p = Progress(simlmax-lmin) end
@showprogress p for level = lmin:simlmax #@showprogress 1 ""
#println()
#println("level: ", level)
mask_level = leveldata .== level
new_level_range1, new_level_range2, length_level1, length_level2 = prep_level_range(direction, level, ranges)
# bin data on current level grid and resize map
fcorrect = (2^level / res) ^ 2
map_weight = hist2d_weight(xval,yval, [new_level_range1,new_level_range2], mask_level, weightval, isamr) .* weight_scale
newmap_w += imresize(map_weight, (length1, length2)) .* fcorrect
for ivar in keys(data_dict)
if ivar == :sd || ivar == :mass
#if ivar == :mass println(ivar) end
map = hist2d_weight(xval,yval, [new_level_range1,new_level_range2], mask_level, data_dict[ivar], isamr)
else
map = hist2d_data(xval,yval, [new_level_range1,new_level_range2], mask_level, weightval, data_dict[ivar], isamr) .* weight_scale
end
maps[ivar] += imresize(map, (length1, length2)) .* fcorrect
end
#if show_progress next!(p, showvalues = [(:Level, level )]) end # ProgressMeter
end #for level
# velocity dispersion maps
for ivar in selected_vars
if in(ivar, σcheck)
selected_unit, unit_name= getunit(dataobject, ivar, selected_vars, units, uname=true)
selected_v = σ_to_v[ivar]
# revert weighting
if mode == :standard
iv = maps[selected_v[1]] = maps[selected_v[1]] ./newmap_w
iv2 = maps[selected_v[2]] = maps[selected_v[2]] ./newmap_w
elseif mode == :sum
iv = maps[selected_v[1]] = maps[selected_v[1]]
iv2 = maps[selected_v[2]] = maps[selected_v[2]]
end
delete!(data_dict, selected_v[1])
delete!(data_dict, selected_v[2])
# create vdisp map
maps[ivar] = sqrt.( iv2 .- iv .^2 ) .* selected_unit
maps_unit[ivar] = unit_name
maps_weight[ivar] = weighting
maps_mode[ivar] = mode
# assign units
selected_unit, unit_name= getunit(dataobject, selected_v[1], selected_vars, units, uname=true)
maps_unit[selected_v[1]] = unit_name
maps[selected_v[1]] = maps[selected_v[1]] .* selected_unit
maps_weight[selected_v[1]] = weighting
maps_mode[selected_v[1]] = mode
selected_unit, unit_name= getunit(dataobject, selected_v[2], selected_vars, units, uname=true)
maps_unit[selected_v[2]] = unit_name
maps[selected_v[2]] = maps[selected_v[2]] .* selected_unit^2
maps_weight[selected_v[2]] = weighting
maps_mode[selected_v[2]] = mode
end
end
# finish projected data and revise weighting
for ivar in keys(data_dict)
selected_unit, unit_name= getunit(dataobject, ivar, selected_vars, units, uname=true)
if ivar == :sd
maps_weight[ivar] = :nothing
maps_mode[ivar] = :nothing
maps[ivar] = maps[ivar] ./ (boxlen / res)^2 .* selected_unit # sd = mass/A * unit
elseif ivar == :mass
maps_weight[ivar] = :nothing
maps_mode[ivar] = :sum
maps[ivar] = maps[ivar] .* selected_unit
else
maps_weight[ivar] = weighting
maps_mode[ivar] = mode
if mode == :standard
maps[ivar] = maps[ivar] ./ newmap_w .* selected_unit
elseif mode == :sum
maps[ivar] = maps[ivar].* selected_unit
end
end
maps_unit[ivar] = unit_name
end
end # notonly_ranglecheck_vars
# create radius map
for ivar in selected_vars
if in(ivar, rcheck)
selected_unit, unit_name= getunit(dataobject, ivar, selected_vars, units, uname=true)
map_R = zeros(Float64, length1, length2 );
for i = 1:(length1)
for j = 1:(length2)
x = i * dataobject.boxlen / res
y = j * dataobject.boxlen / res
radius = sqrt((x-length1_center)^2 + (y-length2_center)^2)
map_R[i,j] = radius * selected_unit
end
end
maps_mode[ivar] = :nothing
maps_weight[ivar] = :nothing
maps[ivar] = map_R
maps_unit[ivar] = unit_name
end
end
# create ϕ-angle map
for ivar in selected_vars
if in(ivar, anglecheck)
map_ϕ = zeros(Float64, length1, length2 );
for i = 1:(length1)
for j = 1:(length2)
x = i * dataobject.boxlen /res - length1_center
y = j * dataobject.boxlen / res - length2_center
if x > 0. && y >= 0.
map_ϕ[i,j] = atan(y / x)
elseif x > 0. && y < 0.
map_ϕ[i,j] = atan(y / x) + 2. * pi
elseif x < 0.
map_ϕ[i,j] = atan(y / x) + pi
elseif x==0 && y > 0
map_ϕ[i,j] = pi/2.
elseif x==0 && y < 0
map_ϕ[i,j] = 3. * pi/2.
end
end
end
maps_mode[ivar] = :nothing
maps_weight[ivar] = :nothing
maps[ivar] = map_ϕ
maps_unit[ivar] = :radian
end
end
maps_lmax = SortedDict( )
return HydroMapsType(maps, maps_unit, maps_lmax, maps_weight, maps_mode, lmax_projected, lmin, simlmax, ranges, extent, extent_center, ratio, res, pixsize, boxlen, dataobject.smallr, dataobject.smallc, dataobject.scale, dataobject.info)
#return maps, maps_unit, extent_center, ranges
end
# check if only variables from ranglecheck are selected
function check_for_maps(selected_vars::Array{Symbol,1}, rcheck, anglecheck, σcheck, σ_to_v)
# checks to use maps instead of projections
ranglecheck = [rcheck..., anglecheck...]
# for velocity dispersion add necessary velocity components
# ========================================================
rσanglecheck = [rcheck...,σcheck...,anglecheck...]
for i in σcheck
idx = findall(x->x==i, selected_vars) #[1]
if length(idx) >= 1
selected_v = σ_to_v[i]
for j in selected_v
jdx = findall(x->x==j, selected_vars)
if length(jdx) == 0
append!(selected_vars, [j])
end
end
end
end
# ========================================================
Nvars = length(selected_vars)
cw = 0
for iw in selected_vars
if in(iw,ranglecheck)
cw +=1
end
end
Ndiff = Nvars-cw
return Ndiff != 0
end
function check_need_rho(dataobject, selected_vars, weighting, notonly_ranglecheck_vars)
if weighting == :mass
# only add :sd if there are also other variables than in ranglecheck
if !in(:sd, selected_vars) && notonly_ranglecheck_vars
append!(selected_vars, [:sd])
end
if !in(:rho, keys(dataobject.data[1]) )
error("""[Mera]: For mass weighting variable "rho" is necessary.""")
end
end
return selected_vars
end
function prep_maps(direction, data_centerm, res, boxlen, ranges, selected_vars)
x_coord = :cx
y_coord = :cy
z_coord = :cz
r1 = floor(Int, ranges[1] * res)
r2 = ceil(Int, ranges[2] * res)
r3 = floor(Int, ranges[3] * res)
r4 = ceil(Int, ranges[4] * res)
r5 = floor(Int, ranges[5] * res)
r6 = ceil(Int, ranges[6] * res)
rl1 = data_centerm[1] .* res
rl2 = data_centerm[2] .* res
rl3 = data_centerm[3] .* res
xmin, xmax, ymin, ymax, zmin, zmax = ranges
if direction == :z
#x_coord = :cx
#y_coord = :cy
#z_coord = :cz
rangez = [zmin, zmax]
# get range for given resolution
newrange1 = range(r1, stop=r2, length=(r2-r1)+1)
newrange2 = range(r3, stop=r4, length=(r4-r3)+1)
# export img properties for plots
extent=[r1,r2,r3,r4]
ratio = (extent[2]-extent[1]) / (extent[4]-extent[3])
extent_center = [0.,0.,0.,0.]
extent_center[1:2] = [extent[1]-rl1, extent[2]-rl1] * boxlen / res
extent_center[3:4] = [extent[3]-rl2, extent[4]-rl2] * boxlen / res
extent = extent .* boxlen ./ res
# for radius and ϕ-angle map
length1_center = (data_centerm[1] -xmin ) * boxlen
length2_center = (data_centerm[2] -ymin ) * boxlen
elseif direction == :y
x_coord = :cx
y_coord = :cz
z_coord = :cy
rangez = [ymin, ymax]
# get range for given resolution
newrange1 = range(r1, stop=r2, length=(r2-r1)+1)
newrange2 = range(r5, stop=r6, length=(r6-r5)+1)
# export img properties for plots
extent=[r1,r2,r5,r6]
ratio = (extent[2]-extent[1]) / (extent[4]-extent[3])
extent_center = [0.,0.,0.,0.]
extent_center[1:2] = [extent[1]-rl1, extent[2]-rl1] * boxlen / res
extent_center[3:4] = [extent[3]-rl3, extent[4]-rl3] * boxlen / res
extent = extent .* boxlen ./ res
# for radius and ϕ-angle map
length1_center = (data_centerm[1] -xmin ) * boxlen
length2_center = (data_centerm[3] -zmin ) * boxlen
elseif direction == :x
x_coord = :cy
y_coord = :cz
z_coord = :cx
rangez = [xmin, xmax]
# get range for given resolution
newrange1 = range(r3, stop=r4, length=(r4-r3)+1)
newrange2 = range(r5, stop=r6, length=(r6-r5)+1)
# export img properties for plots
extent=[r3,r4,r5,r6]
ratio = (extent[2]-extent[1]) / (extent[4]-extent[3])
extent_center = [0.,0.,0.,0.]
extent_center[1:2] = [extent[1]-rl2, extent[2]-rl2] * boxlen / res
extent_center[3:4] = [extent[3]-rl3, extent[4]-rl3] * boxlen / res
extent = extent .* boxlen ./ res
# for radius and ϕ-angle map
length1_center = (data_centerm[2] -ymin ) * boxlen
length2_center = (data_centerm[3] -zmin ) * boxlen
end
# prepare maps
length1=length( newrange1) -1
length2=length( newrange2) -1
#map = zeros(Float64, length1, length2, length(selected_vars) ) # 2d map vor each variable
#map_weight = zeros(Float64, length1 , length2, length(selected_vars) );
return x_coord, y_coord, z_coord, extent, extent_center, ratio , length1, length2, length1_center, length2_center, rangez
end
function prep_data(dataobject, x_coord, y_coord, z_coord, mask, ranges, weighting, res, selected_vars, maps, center, range_unit, anglecheck, rcheck, σcheck, skipmask,rangez, length1, length2, isamr, simlmax)
# mask thickness of projection
zval = getvar(dataobject, z_coord)
if isamr
lvl = getvar(dataobject, :level)
else
lvl = simlmax
end
#println(rangez)
if rangez[1] != 0.
mask_zmin = zval .>= floor.(Int, rangez[1] .* 2 .^lvl)
if !skipmask
#println("mask zmin 1")
mask = mask .* mask_zmin
else
#println("mask zmin 1")
mask = mask_zmin
end
else
#println("mask zmin no")
end
if rangez[2] != 1.
mask_zmax = zval .<= ceil.(Int, rangez[2] .* 2 .^lvl)
if !skipmask
#println("mask zmax 1")
mask = mask .* mask_zmax
else
if rangez[1] != 0.
#println("mask zmax 2")
mask = mask .* mask_zmax
else
#println("mask zmax 3")
mask = mask_zmax
end
end
else
#println("mask zmax no")
end
if length(mask) == 1
xval = select(dataobject.data, x_coord)
yval = select(dataobject.data, y_coord)
weightval = getvar(dataobject, weighting)
if isamr
leveldata = select(dataobject.data, :level)
else
leveldata = simlmax
end
else
xval = select(dataobject.data, x_coord)[mask] #getvar(dataobject, x_coord, mask=mask)
yval = select(dataobject.data, y_coord)[mask] #getvar(dataobject, y_coord, mask=mask)
#if weighting == nothing
# weightval = 1.
#else
weightval = getvar(dataobject, weighting, mask=mask)
#end
if isamr
leveldata = select(dataobject.data, :level)[mask] #getvar(dataobject, :level, mask=mask)
else
leveldata = simlmax
end
#end
end
data_dict = SortedDict( )
for ivar in selected_vars
if !in(ivar, anglecheck) && !in(ivar, rcheck) && !in(ivar, σcheck)
maps[ivar] = zeros(Float64, (length1, length2) )
if ivar !== :sd
if length(mask) == 1
data_dict[ivar] = getvar(dataobject, ivar, center=center, center_unit=range_unit)
elseif !(ivar in σcheck)
data_dict[ivar] = getvar(dataobject, ivar, mask=mask, center=center, center_unit=range_unit)
end
elseif ivar == :sd || ivar == :mass
if weighting == :mass
data_dict[ivar] = weightval
else
if length(mask) == 1
data_dict[ivar] = getvar(dataobject, :mass)
else
data_dict[ivar] = getvar(dataobject, :mass, mask=mask)
end
end
end
end
end
# =================================
return data_dict, xval, yval, leveldata, weightval, maps
end
function prep_level_range(direction, level, ranges)
if direction == :z
# rebin data on the current level grid
rl1 = floor(Int, ranges[1] * 2^level) +1
rl2 = ceil(Int, ranges[2] * 2^level) +1
rl3 = floor(Int, ranges[3] * 2^level) +1
rl4 = ceil(Int, ranges[4] * 2^level) +1
# range of current level grid
new_level_range1 = range(rl1, stop=rl2, length=(rl2-rl1)+1 )
new_level_range2 = range(rl3, stop=rl4, length=(rl4-rl3)+1 )
elseif direction == :y
# rebin data on the current level grid
rl1 = floor(Int, ranges[1] * 2^level) +1
rl2 = ceil(Int, ranges[2] * 2^level) +1
rl3 = floor(Int, ranges[5] * 2^level) +1
rl4 = ceil(Int, ranges[6] * 2^level) +1
# range of current level grid
new_level_range1 = range(rl1, stop=rl2, length=(rl2-rl1)+1 )
new_level_range2 = range(rl3, stop=rl4, length=(rl4-rl3)+1 )
elseif direction == :x
# rebin data on the current level grid
rl1 = floor(Int, ranges[3] * 2^level) +1
rl2 = ceil(Int, ranges[4] * 2^level) +1
rl3 = floor(Int, ranges[5] * 2^level) +1
rl4 = ceil(Int, ranges[6] * 2^level) +1
# range of current level grid
new_level_range1 = range(rl1, stop=rl2, length=(rl2-rl1)+1 )
new_level_range2 = range(rl3, stop=rl4, length=(rl4-rl3)+1 )
end
# length of current level grid
length_level1=length( new_level_range1 )
length_level2=length( new_level_range2 )
return new_level_range1, new_level_range2, length_level1, length_level2
end
function check_mask(dataobject, mask, verbose)
skipmask=true
rows = length(dataobject.data)
if length(mask) > 1
if length(mask) !== rows
error("[Mera] ",now()," : array-mask length: $(length(mask)) does not match with data-table length: $(rows)")
else
skipmask = false
if verbose
println(":mask provided by function")
println()
end
end
end
return skipmask
end
function nrange(start::Int, stop::Int, len::Int, nshift::Int)
return range(start, stop=stop + nshift, length=len + nshift )
end
#function hist2d_weight(x::Vector{Int64}, y::Vector{Int64},
# s::Vector{StepRangeLen{Float64,
# Base.TwicePrecision{Float64},
# Base.TwicePrecision{Float64}}},
# mask::MaskType, w::Vector{Float64})
function hist2d_weight(x, y, s, mask, w, isamr)
if isamr
h = fit(Histogram, (x[mask], y[mask]), weights(w[mask]), (s[1],s[2]))
else
h = fit(Histogram, (x, y), weights(w), (s[1],s[2]))
end
return h.weights
end
#function hist2d_data(x::Vector{Int64}, y::Vector{Int64},
# s::Vector{StepRangeLen{Float64,
# Base.TwicePrecision{Float64},
# Base.TwicePrecision{Float64}}},
# mask::MaskType, w::Vector{Float64},
# data::Vector{Float64})
function hist2d_data(x, y, s, mask, w, data, isamr)
if isamr
h = fit(Histogram, (x[mask], y[mask]), weights(data[mask] .* w[mask]), (s[1],s[2]))
else
h = fit(Histogram, (x, y), weights(data .* w), (s[1],s[2]))
end
return h.weights
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 43818 |
# #select particle types
# function spt( parttypes, id)
# if in(:all, parttypes)
# return id >=-1
# elseif in(:negative, parttypes)
# return id < 0
# elseif in(:m1, parttypes)
# return id == -1
# elseif in(:stars, parttypes)
# return id >0
# elseif in(:dm, parttypes)
# return id ==0
# elseif in(:stars, parttypes) && in(parttypes, :dm)
# return id >=0
# end
# end
#
# # select vars and filter parttypes
# function select_data(data, parttypes, var)
# return select( filter( p-> spt( parttypes, p.id), data, select=(:id, var)), var )
# end
"""
#### Project variables or derived quantities from the **particle-dataset**:
- projection to a grid related to a given level
- overview the list of predefined quantities with: projection()
- select variable(s) and their unit(s)
- limit to a maximum range
- give the spatial center (with units) of the data within the box (relevant e.g. for radius dependency)
- relate the coordinates to a direction (x,y,z)
- select between mass (default) and volume weighting
- pass a mask to exclude elements (cells/particles/...) from the calculation
- toggle verbose mode
- toggle progress bar
- pass a struct with arguments (myargs)
```julia
projection( dataobject::PartDataType, vars::Array{Symbol,1};
units::Array{Symbol,1}=[:standard],
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask=[false],
direction::Symbol=:z,
weighting::Symbol=:mass,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
ref_time::Real=dataobject.info.time,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return HydroMapsType
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "PartDataType"
- **`var(s)`:** select a variable from the database or a predefined quantity (see field: info, function projection(), dataobject.data)
##### Predefined/Optional Keywords:
- **`unit(s)`:** return the variable in given units
- **`pxsize``:** creates maps with the given pixel size in physical/code units (dominates over: res, lmax) : pxsize=[physical size (Number), physical unit (Symbol)]
- **`res`** create maps with the given pixel number for each deminsion; if res not given by user -> lmax is selected; (pixel number is related to the full boxsize)
- **`lmax`:** create maps with 2^lmax pixels for each dimension
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`weighting`:** select between `:mass` weighting (default) and `:volume` weighting
- **`data_center`:** to calculate the data relative to the data_center; in units given by argument `data_center_unit`; by default the argument data_center = center ;
- **`data_center_unit`:** :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`direction`:** select between: :x, :y, :z
- **`mask`:** needs to be of type MaskType which is a supertype of Array{Bool,1} or BitArray{1} with the length of the database (rows)
- **`ref_time`:** the age quantity relative to a given time (code_units); default relative to the loaded snapshot time
- **`show_progress`:** print progress bar on screen
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of lmax, xrange, yrange, zrange, center, range_unit, verbose, show_progress
### Defined Methods - function defined for different arguments
- projection( dataobject::PartDataType, var::Symbol; ...) # one given variable
- projection( dataobject::PartDataType, var::Symbol, unit::Symbol; ...) # one given variable with its unit
- projection( dataobject::PartDataType, vars::Array{Symbol,1}; ...) # several given variables -> array needed
- projection( dataobject::PartDataType, vars::Array{Symbol,1}, units::Array{Symbol,1}; ...) # several given variables and their corresponding units -> both arrays
- projection( dataobject::PartDataType, vars::Array{Symbol,1}, unit::Symbol; ...) # several given variables that have the same unit -> array for the variables and a single Symbol for the unit
#### Examples
...
"""
function projection( dataobject::PartDataType, vars::Array{Symbol,1};
#parttypes::Array{Symbol,1}=[:stars],
units::Array{Symbol,1}=[:standard],
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Symbol=:mass,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
ref_time::Real=dataobject.info.time,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return create_projection( dataobject, vars, units=units,
#parttypes=parttypes,
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
ref_time=ref_time,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function projection( dataobject::PartDataType, vars::Array{Symbol,1},
units::Array{Symbol,1};
#parttypes::Array{Symbol,1}=[:stars],
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Symbol=:mass,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
ref_time::Real=dataobject.info.time,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return create_projection( dataobject, vars, units=units,
#parttypes=parttypes,
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
ref_time=ref_time,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function projection( dataobject::PartDataType, var::Symbol;
#parttypes::Array{Symbol,1}=[:stars],
unit::Symbol=:standard,
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Symbol=:mass,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
ref_time::Real=dataobject.info.time,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return create_projection( dataobject, [var], units=[unit],
#parttypes=parttypes,
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
ref_time=ref_time,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function projection( dataobject::PartDataType, var::Symbol, unit::Symbol,;
#parttypes::Array{Symbol,1}=[:stars],
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Symbol=:mass,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
ref_time::Real=dataobject.info.time,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return create_projection( dataobject, [var], units=[unit],
#parttypes=parttypes,
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
ref_time=ref_time,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function projection( dataobject::PartDataType, vars::Array{Symbol,1}, unit::Symbol;
#parttypes::Array{Symbol,1}=[:stars],
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Symbol=:mass,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
ref_time::Real=dataobject.info.time,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return create_projection( dataobject, vars, units=fill(unit, length(vars)),
#parttypes=parttypes,
lmax=lmax,
res=res,
pxsize=pxsize,
mask=mask,
direction=direction,
#plane_orientation=plane_orientation,
weighting=weighting,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
data_center=data_center,
data_center_unit=data_center_unit,
ref_time=ref_time,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function create_projection( dataobject::PartDataType, vars::Array{Symbol,1};
#parttypes::Array{Symbol,1}=[:stars],
units::Array{Symbol,1}=[:standard],
lmax::Real=dataobject.lmax,
res::Union{Real, Missing}=missing,
pxsize::Array{<:Any,1}=[missing, missing],
mask=[false],
direction::Symbol=:z,
#plane_orientation::Symbol=:perpendicular,
weighting::Symbol=:mass,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
data_center::Array{<:Any,1}=[missing, missing, missing],
data_center_unit::Symbol=:standard,
ref_time::Real=dataobject.info.time,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
# take values from myargs if given
if !(myargs.pxsize === missing) pxsize = myargs.pxsize end
if !(myargs.res === missing) res = myargs.res end
if !(myargs.lmax === missing) lmax = myargs.lmax end
if !(myargs.direction === missing) direction = myargs.direction end
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.data_center === missing) data_center = myargs.data_center end
if !(myargs.data_center_unit === missing) data_center_unit = myargs.data_center_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
if !(myargs.show_progress === missing) show_progress = myargs.show_progress end
verbose = Mera.checkverbose(verbose)
show_progress = Mera.checkprogress(show_progress)
printtime("", verbose)
boxlen = dataobject.boxlen
selected_vars = deepcopy(vars)
#ranges = [xrange[1],xrange[1],yrange[1],yrange[1],zrange[1],zrange[1]]
scale = dataobject.scale
nvarh = dataobject.info.nvarh
if res === missing res = 2^lmax end
if !(pxsize[1] === missing)
px_unit = 1. # :standard
if length(pxsize) != 1
if !(pxsize[2] === missing)
if pxsize[2] != :standard
px_unit = getunit(dataobject.info, pxsize[2])
end
end
end
px_scale = pxsize[1] / px_unit
res = boxlen/px_scale
end
res = ceil(Int, res) # be sure to have Integer
sd_names = [:sd, :Σ, :surfacedensity]
density_names = [:density, :rho, :ρ]
# checks to use maps instead of projections
rcheck = [:r_cylinder, :r_sphere]
anglecheck = [:ϕ]
ranglecheck = [rcheck..., anglecheck...]
# for velocity dispersion add necessary velocity components
# ========================================================
σcheck = [:σx, :σy, :σz, :σ, :σr_cylinder, :σϕ_cylinder]
rσanglecheck = [rcheck...,σcheck...,anglecheck...]
σ_to_v = SortedDict( :σx => [:vx, :vx2],
:σy => [:vy, :vy2],
:σz => [:vz, :vz2],
:σ => [:v, :v2],
:σr_cylinder => [:vr_cylinder, :vr_cylinder2],
:σϕ_cylinder => [:vϕ_cylinder, :vϕ_cylinder2] )
for i in σcheck
idx = findall(x->x==i, selected_vars) #[1]
if length(idx) >= 1
selected_v = σ_to_v[i]
for j in selected_v
jdx = findall(x->x==j, selected_vars)
if length(jdx) == 0
append!(selected_vars, [j])
end
end
end
end
# ========================================================
if weighting == :mass
use_sd_map = Mera.checkformaps(selected_vars, ranglecheck)
# only add :sd if there are also other variables than in ranglecheck
if !in(:sd, selected_vars) && use_sd_map
append!(selected_vars, [:sd])
end
if !in(:mass, keys(dataobject.data[1]) )
error("""[Mera]: For mass weighting variable "mass" is necessary.""")
end
end
# convert given ranges and print overview on screen
ranges = Mera.prepranges(dataobject.info,range_unit, verbose, xrange, yrange, zrange, center, dataranges=dataobject.ranges)
data_centerm = Mera.prepdatacenter(dataobject.info, center, range_unit, data_center, data_center_unit)
xmin, xmax, ymin, ymax, zmin, zmax = ranges
# rebin data on the maximum used grid
r1 = floor(Int, ranges[1] * res) + 1
r2 = ceil(Int, ranges[2] * res) + 1
r3 = floor(Int, ranges[3] * res) + 1
r4 = ceil(Int, ranges[4] * res) + 1
r5 = floor(Int, ranges[5] * res) + 1
r6 = ceil(Int, ranges[6] * res) + 1
pixsize = dataobject.boxlen / res # in code units
if verbose
println("Effective resolution: $res^2")
#println("Map size: $length1 x $length2")
px_val, px_unit = humanize(pixsize, dataobject.scale, 3, "length")
pxmin_val, pxmin_unit = humanize(boxlen/2^dataobject.lmax, dataobject.scale, 3, "length")
println("Pixel size: $px_val [$px_unit]")
println("Simulation min.: $pxmin_val [$pxmin_unit]")
println()
end
var_a = :x
var_b = :y
finished = zeros(Float64, res,res)
rl = data_centerm .* dataobject.boxlen
if direction == :z
# range on maximum used grid
newrange1 = range(r1, stop=r2-1, length=(r2-r1)+1 ) ./ res .* dataobject.boxlen
newrange2 = range(r3, stop=r4-1, length=(r4-r3)+1 ) ./ res .* dataobject.boxlen
#println(newrange1)
#println(newrange2)
var_a = :x
var_b = :y
extent=[r1-1,r2-1,r3-1,r4-1] .* dataobject.boxlen ./ res
ratio = (extent[2]-extent[1]) / (extent[4]-extent[3])
extent_center= [extent[1]-rl[1], extent[2]-rl[1], extent[3]-rl[2], extent[4]-rl[2]]
length1_center = (data_centerm[1] -xmin) * boxlen
length2_center = (data_centerm[2] -ymin) * boxlen
elseif direction == :y
# range on maximum used grid
newrange1 = range(r1, stop=r2-1, length=(r2-r1)+1 ) ./ res .* dataobject.boxlen
newrange2 = range(r5, stop=r6-1, length=(r6-r5)+1 ) ./ res .* dataobject.boxlen
#println(newrange1)
#println(newrange2)
var_a = :x
var_b = :z
extent=[r1-1,r2-1,r5-1,r6-1] .* dataobject.boxlen ./ res
ratio = (extent[2]-extent[1]) / (extent[4]-extent[3])
extent_center= [extent[1]-rl[1], extent[2]-rl[1], extent[3]-rl[3], extent[4]-rl[3]]
length1_center = (data_centerm[1] -xmin) * boxlen
length2_center = (data_centerm[3] -zmin) * boxlen
elseif direction == :x
# range on maximum used grid
newrange1 = range(r3, stop=r4-1, length=(r4-r3)+1 ) ./ res .* dataobject.boxlen
newrange2 = range(r5, stop=r6-1, length=(r6-r5)+1 ) ./ res .* dataobject.boxlen
#println(newrange1)
#println(newrange2)
var_a = :y
var_b = :z
extent=[r3-1,r4-1,r5-1,r6-1] .* dataobject.boxlen ./ res
ratio = (extent[2]-extent[1]) / (extent[4]-extent[3])
extent_center= [extent[1]-rl[2], extent[2]-rl[2], extent[3]-rl[3], extent[4]-rl[3]]
length1_center = (data_centerm[2] -ymin) * boxlen
length2_center = (data_centerm[3] -zmin) * boxlen
end
length1=length( newrange1) - 1
length2=length( newrange2) - 1
map = zeros(Float64, length1, length2, length(selected_vars) )
map_weight = zeros(Float64, length1 , length2 );
#println("length1,2: (final maps) ", length1 , " ", length2 )
#println("-------------------------------------")
#println()
rows = length(dataobject.data)
mera_mask_inserted = false
if length(mask) > 1
if length(mask) !== rows
error("[Mera] ",now()," : array-mask length: $(length(mask)) does not match with data-table length: $(rows)")
else
if in(:mask, colnames(dataobject.data))
if verbose
println(":mask provided by datatable")
println()
end
else
Nafter = JuliaDB.ncols(dataobject.data)
dataobject.data = JuliaDB.insertcolsafter(dataobject.data, Nafter, :mask => mask)
if verbose
println(":mask provided by function")
println()
end
mera_mask_inserted = true
end
end
end
filtered_data = filter(p->
p.x >= (xmin * dataobject.boxlen) &&
p.x <= (xmax * dataobject.boxlen) &&
p.y >= (ymin * dataobject.boxlen) &&
p.y <= (ymax * dataobject.boxlen) &&
p.z >= (zmin * dataobject.boxlen) &&
p.z <= (zmax * dataobject.boxlen), dataobject.data)
closed=:left
maps = SortedDict( )
maps_mode = SortedDict( )
maps_unit = SortedDict( )
if show_progress
p = 1 # show updates
else
p = length(selected_vars)+2 # do not show updates
end
#if show_progress p = Progress(length(selected_vars)) end
@showprogress p for i_var in selected_vars #dependencies_part_list @showprogress 1 ""
#println(i_var)
if !in(i_var, rσanglecheck) # exclude velocity dispersion symbols and radius/angle maps
if weighting == :mass
if in(i_var, sd_names)
if length(mask) == 1
global h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) ) ,
closed=closed,
(newrange1, newrange2) )
else
global h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) .* select(filtered_data, :mask)) ,
closed=closed,
(newrange1, newrange2) )
end
selected_unit, unit_name= getunit(dataobject, i_var, selected_vars, units, uname=true)
if selected_unit != 1.
maps[Symbol(i_var)] = h.weights ./ (dataobject.info.boxlen / res )^2 .* selected_unit
else
maps[Symbol(i_var)] = h.weights ./ (dataobject.info.boxlen / res )^2
end
maps_unit[Symbol( string(i_var) )] = unit_name
maps_mode[Symbol( string(i_var) )] = :mass_weighted
elseif in(i_var, density_names)
if length(mask) == 1
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) ) ,
closed=closed,
(newrange1, newrange2) )
else
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) .* select(filtered_data, :mask) ) ,
closed=closed,
(newrange1, newrange2) )
end
selected_unit, unit_name= getunit(dataobject, i_var, selected_vars, units, uname=true)
if selected_unit != 1.
maps[Symbol(i_var)] = h.weights ./ ( (dataobject.info.boxlen / res )^3 * res) .* selected_unit
else
maps[Symbol(i_var)] = h.weights ./ ( (dataobject.info.boxlen / res )^3 * res)
end
maps_unit[Symbol( string(i_var) )] = unit_name
maps_mode[Symbol( string(i_var) )] = :mass_weighted
else
if length(mask) == 1
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( getvar(dataobject, i_var, filtered_db=filtered_data, center=data_centerm, direction=direction, ref_time=ref_time) .* select(filtered_data, :mass) ),
closed=closed,
(newrange1, newrange2) )
h_mass = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) ),
closed=closed,
(newrange1, newrange2) )
else
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( getvar(dataobject, i_var, filtered_db=filtered_data, center=data_centerm, direction=direction, ref_time=ref_time) .* select(filtered_data, :mass) .* select(filtered_data, :mask) ),
closed=closed,
(newrange1, newrange2) )
h_mass = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) .* select(filtered_data, :mask) ),
closed=closed,
(newrange1, newrange2) )
end
selected_unit, unit_name= getunit(dataobject, i_var, selected_vars, units, uname=true)
if selected_unit != 1.
maps[Symbol(i_var)] = h.weights ./ h_mass.weights .* selected_unit
else
maps[Symbol(i_var)] = h.weights ./ h_mass.weights
end
maps_unit[Symbol( string(i_var) )] = unit_name
maps_mode[Symbol( string(i_var) )] = :mass_weighted
end
elseif weighting == :volume
if in(i_var, sd_names)
if length(mask) == 1
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) ),
closed=closed,
(newrange1, newrange2) )
else
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) .* select(filtered_data, :mask) ),
closed=closed,
(newrange1, newrange2) )
end
selected_unit, unit_name= getunit(dataobject, i_var, selected_vars, units, uname=true)
if selected_unit != 1.
maps[Symbol(i_var)] = h.weights ./ (dataobject.info.boxlen / res )^2 .* selected_unit
else
maps[Symbol(i_var)] = h.weights ./ (dataobject.info.boxlen / res )^2
end
maps_unit[Symbol( string(i_var) )] = unit_name
maps_mode[Symbol( string(i_var) )] = :volume_weighted
elseif in(i_var, density_names)
if length(mask) == 1
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) ),
closed=closed,
(newrange1, newrange2) )
else
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( select(filtered_data, :mass) .* select(filtered_data, :mask) ),
closed=closed,
(newrange1, newrange2) )
end
selected_unit, unit_name= getunit(dataobject, i_var, selected_vars, units, uname=true)
if selected_unit != 1.
maps[Symbol(i_var)] = h.weights ./ ( (dataobject.info.boxlen / res )^3 * res) .* selected_unit
else
maps[Symbol(i_var)] = h.weights ./ ( (dataobject.info.boxlen / res )^3 * res)
end
maps_unit[Symbol( string(i_var) )] = unit_name
maps_mode[Symbol( string(i_var) )] = :volume_weighted
else
if length(mask) == 1
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( getvar(dataobject, i_var, filtered_db=filtered_data, center=data_centerm, direction=direction, ref_time=ref_time) ),
#weights( select(filtered_data, Symbol(i_var)) ),
closed=closed,
(newrange1, newrange2) )
else
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( getvar(dataobject, i_var, filtered_db=filtered_data, center=data_centerm, direction=direction, ref_time=ref_time) .* select(filtered_data, :mask) ),
#weights( select(filtered_data, Symbol(i_var)) ),
closed=closed,
(newrange1, newrange2) )
end
selected_unit, unit_name= getunit(dataobject, i_var, selected_vars, units, uname=true)
if selected_unit != 1.
maps[Symbol(i_var)] = h.weights ./ ( (dataobject.info.boxlen / res )^3 * res) .* selected_unit
else
maps[Symbol(i_var)] = h.weights ./ ( (dataobject.info.boxlen / res )^3 * res)
end
maps_unit[Symbol( string(i_var) )] = unit_name
maps_mode[Symbol( string(i_var) )] = :volume_weighted
end
elseif mode == :sum
if length(mask) == 1
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( getvar(dataobject, i_var, filtered_db=filtered_data, center=data_centerm, direction=direction, ref_time=ref_time) ),
#weights( select(filtered_data, Symbol(i_var)) ),
closed=closed,
(newrange1, newrange2) )
else
h = fit(Histogram, (select(filtered_data, var_a) ,
select(filtered_data, var_b) ),
weights( getvar(dataobject, i_var, filtered_db=filtered_data, center=data_centerm, direction=direction, ref_time=ref_time) .* select(filtered_data, :mask) ),
#weights( select(filtered_data, Symbol(i_var)) ),
closed=closed,
(newrange1, newrange2) )
end
selected_unit, unit_name= getunit(dataobject, i_var, selected_vars, units, uname=true)
if selected_unit != 1.
maps[Symbol(i_var)] = h.weights .* selected_unit
else
maps[Symbol(i_var)] = h.weights
end
maps_unit[Symbol( string(i_var) )] = unit_name
maps_mode[Symbol( string(i_var) )] = :sum
end
end
#if show_progress next!(p, showvalues = [(:Nvars, i_var)]) end # ProgressMeter
end #for
# create velocity dispersion maps, after all other maps are created
counter = 0
for ivar in selected_vars
counter = counter + 1
if in(ivar, σcheck)
#for iσ in σcheck
selected_unit, unit_name= getunit(dataobject, ivar, selected_vars, units, uname=true)
selected_v = σ_to_v[ivar]
iv = maps[selected_v[1]]
iv_unit = maps_unit[Symbol( string(selected_v[1]) )]
iv2 = maps[selected_v[2]]
iv2_unit = maps_unit[Symbol( string(selected_v[2]) )]
if iv_unit == iv2_unit
diff_iv = iv2 .- iv .^2
diff_iv[ diff_iv .< 0. ] .= 0.
if iv_unit == unit_name
maps[Symbol(ivar)] = sqrt.( diff_iv )
elseif iv_unit == :standard
maps[Symbol(ivar)] = sqrt.( diff_iv ) .* selected_unit
elseif iv_unit == :km_s
maps[Symbol(ivar)] = sqrt.( diff_iv ) ./ dataobject.info.scale.km_s
end
elseif iv_unit != iv2_unit
if iv_unit == :km_s && unit_name == :standard
iv = iv ./ dataobject.info.scale.km_s
elseif iv_unit == :standard && unit_name == :km_s
iv = iv .* dataobject.info.scale.km_s
end
if iv2_unit == :km_s && unit_name == :standard
iv2 = iv2 ./ dataobject.info.scale.km_s.^2
elseif iv2_unit == :standard && unit_name == :km_s
iv2 = iv2 .* dataobject.info.scale.km_s.^2
end
# overwrite NaN due to radius = 0
#iv2 = iv2[isnan.(iv2)] .= 0
#iv = iv[isnan.(iv)] .= 0
diff_iv = iv2 .- iv .^2
diff_iv[ diff_iv .< 0. ] .= 0.
maps[Symbol(ivar)] = sqrt.( diff_iv )
end
maps_unit[Symbol( string(ivar) )] = unit_name
#end
#end
end
end
# create radius map
for ivar in selected_vars
if in(ivar, rcheck)
selected_unit, unit_name= getunit(dataobject, ivar, selected_vars, units, uname=true)
map_R = zeros(Float64, length1, length2 );
for i = 1:(length1)
for j = 1:(length2)
x = i * dataobject.boxlen / res
y = j * dataobject.boxlen / res
radius = sqrt( ((x-length1_center) )^2 + ( (y-length2_center) )^2)
map_R[i,j] = radius * selected_unit
end
end
maps[Symbol(ivar)] = map_R
maps_unit[Symbol( string(ivar) )] = unit_name
end
end
# create ϕ-angle map
for ivar in selected_vars
if in(ivar, anglecheck)
map_ϕ = zeros(Float64, length1, length2 );
for i = 1:(length1)
for j = 1:(length2)
x = i * dataobject.boxlen / res - length1_center
y = j * dataobject.boxlen / res - length2_center
if x > 0. && y >= 0.
map_ϕ[i,j] = atan(y / x)
elseif x > 0. && y < 0.
map_ϕ[i,j] = atan(y / x) + 2. * pi
elseif x < 0.
map_ϕ[i,j] = atan(y / x) + pi
elseif x==0 && y > 0
map_ϕ[i,j] = pi/2.
elseif x==0 && y < 0
map_ϕ[i,j] = 3. * pi/2.
end
end
end
maps[Symbol(ivar)] = map_ϕ
maps_unit[Symbol( string(ivar) )] = :radian
end
end
if mera_mask_inserted # delete column :mask
dataobject.data = select(dataobject.data, Not(:mask))
end
maps_lmax = SortedDict( )
return PartMapsType(maps, maps_unit, maps_lmax, maps_mode, lmax, dataobject.lmin, lmax, ref_time, ranges, extent, extent_center, ratio, res, pixsize, boxlen, dataobject.scale, dataobject.info)
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 5785 | """
### Cutout sub-regions of the data base of DataSetType
- select shape of a shell-region
- select size of a region (with or w/o intersecting cells)
- give the spatial center (with units) of the data relative to the full box
- relate the coordinates to a direction (x,y,z)
- inverse the selected region
- pass a struct with arguments (myargs)
```julia
shellregion(dataobject::DataSetType, shape::Symbol=:cylinder;
radius::Array{<:Real,1}=[0.,0.], # cylinder, sphere;
height::Real=0., # cylinder
direction::Symbol=:z, # cylinder
center::Array{<:Any,1}=[0., 0., 0.], # all
range_unit::Symbol=:standard, # all
cell::Bool=true, # hydro and gravity
inverse::Bool=false, # all
verbose::Bool=true, # all
myargs::ArgumentsType=ArgumentsType() ) # all
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "DataSetType"
- **`shape`:** select between region shapes: :cylinder/:disc, :sphere
##### Predefined/Optional Keywords:
**For cylindrical shell-region, related to a given center:**
- **`radius`:** the inner and outer radius of the shell in units given by argument `range_unit` and relative to the given `center`
- **`height`:** the hight above and below a plane [-height, height] in units given by argument `range_unit` and relative to the given `center`
- **`direction`:** todo
**For spherical shell-region, related to a given center:**
- **`radius`:** the inner and outer radius of the shell in units given by argument `range_unit` and relative to the given `center`
**Keywords related to all region shapes**
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`inverse`:** inverse the region selection = get the data outside of the region
- **`cell`:** take intersecting cells of the region boarder into account (true) or only the cells-centers within the selected region (false)
- **`verbose`:** print timestamp, selected vars and ranges on screen; default: true
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of radius, height, direction, center, range_unit, verbose
"""
function shellregion(dataobject::DataSetType, shape::Symbol=:cylinder;
radius::Array{<:Real,1}=[0.,0.], # cylinder, sphere;
height::Real=0., # cylinder
direction::Symbol=:z, # cylinder
center::Array{<:Any,1}=[0., 0., 0.], # all
range_unit::Symbol=:standard, # all
cell::Bool=true, # hydro and gravity
inverse::Bool=false, # all
verbose::Bool=true, # all
myargs::ArgumentsType=ArgumentsType() ) # all
# take values from myargs if given
if !(myargs.direction === missing) direction = myargs.direction end
if !(myargs.radius === missing) radius = myargs.radius end
if !(myargs.height === missing) height = myargs.height end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
verbose = checkverbose(verbose)
# subregion = wrapper over all subregion shell functions
if shape == :cylinder || shape == :disc
if typeof(dataobject) == HydroDataType || typeof(dataobject) == GravDataType
return shellregioncylinder(dataobject,
radius=radius,
height=height,
center=center,
range_unit=range_unit,
direction=direction,
cell=cell,
inverse=inverse,
verbose=verbose)
else
return shellregioncylinder(dataobject,
radius=radius,
height=height,
center=center,
range_unit=range_unit,
direction=direction,
inverse=inverse,
verbose=verbose)
end
elseif shape == :sphere
if typeof(dataobject) == HydroDataType || typeof(dataobject) == GravDataType
return shellregionsphere( dataobject,
radius=radius,
center=center,
range_unit=range_unit,
cell=cell,
inverse=inverse,
verbose=verbose)
else
return shellregionsphere( dataobject,
radius=radius,
center=center,
range_unit=range_unit,
inverse=inverse,
verbose=verbose)
end
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 5506 | # -----------------------------------------------------------------------------
##### CYLINDER/SHELL #####-----------------------------------------------------
function shellregioncylinder(dataobject::ClumpDataType;
radius::Array{<:Real,1}=[0.,0.],
height::Real=0.,
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
direction::Symbol=:z,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
radius_in = radius[1]
radius_out = radius[2]
if radius_in == 0. || radius_out == 0. || height == 0. || in(0., center)
error("[Mera]: given radius, height or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift, height_shift = prep_cylindrical_shellranges(dataobject.info, center, radius_in, radius_out, height, range_unit, verbose)
if inverse == false
sub_data = filter(p-> sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2)
>= ( radius_in_shift*boxlen ) &&
sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2)
<= ( radius_out_shift*boxlen ) &&
abs(p.peak_z - cz_shift*boxlen) <= ( height_shift*boxlen),
dataobject.data)
elseif inverse == true
sub_data = filter(p-> sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2)
< ( radius_in_shift*boxlen ) ||
sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2)
> ( radius_out_shift*boxlen ) ||
abs(p.peak_z - cz_shift*boxlen) > ( height_shift*boxlen),
dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
clumpdata = ClumpDataType()
clumpdata.data = sub_data
clumpdata.info = dataobject.info
clumpdata.boxlen = dataobject.boxlen
clumpdata.ranges = ranges
clumpdata.selected_clumpvars = dataobject.selected_clumpvars
clumpdata.used_descriptors = dataobject.used_descriptors
clumpdata.scale = dataobject.scale
return clumpdata
end
# -----------------------------------------------------------------------------
##### SPHERE/SHELL #####-------------------------------------------------------
function shellregionsphere(dataobject::ClumpDataType;
radius::Array{<:Real,1}=[0.,0.],
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
radius_in = radius[1]
radius_out = radius[2]
if radius_in == 0. || radius_out == 0. || in(0., center)
error("[Mera]: given inner and outer radius or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift = prep_spherical_shellranges(dataobject.info, center, radius_in, radius_out, range_unit, verbose)
if inverse == false
sub_data = filter(p-> sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2+
(p.peak_z - cz_shift*boxlen)^2 )
>= ( radius_in_shift*boxlen ) &&
sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2+
(p.peak_z - cz_shift*boxlen)^2 )
<= ( radius_out_shift*boxlen ),
dataobject.data)
elseif inverse == true
sub_data = filter(p-> sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2+
(p.peak_z - cz_shift*boxlen)^2 )
< ( radius_in_shift*boxlen ) ||
sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2+
(p.peak_z - cz_shift*boxlen)^2 )
> ( radius_out_shift*boxlen ),
dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
clumpdata = ClumpDataType()
clumpdata.data = sub_data
clumpdata.info = dataobject.info
clumpdata.boxlen = dataobject.boxlen
clumpdata.ranges = ranges
clumpdata.selected_clumpvars = dataobject.selected_clumpvars
clumpdata.used_descriptors = dataobject.used_descriptors
clumpdata.scale = dataobject.scale
return clumpdata
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 7790 | # -----------------------------------------------------------------------------
##### CYLINDER/SHELL #####-----------------------------------------------------
function shellregioncylinder(dataobject::GravDataType;
radius::Array{<:Real,1}=[0.,0.],
height::Real=0.,
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
direction::Symbol=:z,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
radius_in = radius[1]
radius_out = radius[2]
if radius_in == 0. || radius_out == 0. || height == 0. || in(0., center)
error("[Mera]: given radius, height or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift, height_shift = prep_cylindrical_shellranges(dataobject.info, center, radius_in, radius_out, height, range_unit, verbose)
if inverse == false
if isamr
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
>= (cell_shift(p.level, radius_in_shift,cell)) &&
get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
<= (cell_shift(p.level, radius_out_shift,cell)) &&
get_height_cylinder(p.cz, p.level, cz_shift)
<= (cell_shift(p.level, height_shift,cell)),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
>= (cell_shift(lmax, radius_in_shift,cell)) &&
get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
<= (cell_shift(lmax, radius_out_shift,cell)) &&
get_height_cylinder(p.cz, lmax, cz_shift)
<= (cell_shift(lmax, height_shift,cell)),
dataobject.data)
end
elseif inverse == true
if isamr
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
< (cell_shift(p.level, radius_in_shift,cell)) ||
get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
> (cell_shift(p.level, radius_out_shift,cell)) ||
get_height_cylinder(p.cz, p.level, cz_shift)
> (cell_shift(p.level, height_shift,cell)),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
< (cell_shift(lmax, radius_in_shift,cell)) ||
get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
> (cell_shift(lmax, radius_out_shift,cell)) ||
get_height_cylinder(p.cz, lmax, cz_shift)
> (cell_shift(lmax, height_shift,cell)),
dataobject.data)
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
gravitydata = GravDataType()
gravitydata.data = sub_data
gravitydata.info = dataobject.info
gravitydata.lmin = dataobject.lmin
gravitydata.lmax = dataobject.lmax
gravitydata.boxlen = dataobject.boxlen
gravitydata.ranges = ranges
gravitydata.selected_gravvars = dataobject.selected_gravvars
gravitydata.used_descriptors = dataobject.used_descriptors
gravitydata.scale = dataobject.scale
return gravitydata
end
# -----------------------------------------------------------------------------
##### SPHERE/SHELL #####-------------------------------------------------------
function shellregionsphere(dataobject::GravDataType;
radius::Array{<:Real,1}=[0.,0.],
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
radius_in = radius[1]
radius_out = radius[2]
if radius_in == 0. || radius_out == 0. || in(0., center)
error("[Mera]: given inner and outer radius or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift = prep_spherical_shellranges(dataobject.info, center, radius_in, radius_out, range_unit, verbose)
if inverse == false
if isamr
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
>= cell_shift(p.level, radius_in_shift, cell) &&
get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
<= cell_shift(p.level, radius_out_shift,cell),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
>= cell_shift(lmax, radius_in_shift, cell) &&
get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
<= cell_shift(lmax, radius_out_shift,cell),
dataobject.data)
end
elseif inverse == true
if isamr
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
< cell_shift(p.level, radius_in_shift, cell) ||
get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
> cell_shift(p.level, radius_out_shift, cell),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
< cell_shift(lmax, radius_in_shift, cell) ||
get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
> cell_shift(lmax, radius_out_shift, cell),
dataobject.data)
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
gravitydata = GravDataType()
gravitydata.data = sub_data
gravitydata.info = dataobject.info
gravitydata.lmin = dataobject.lmin
gravitydata.lmax = dataobject.lmax
gravitydata.boxlen = dataobject.boxlen
gravitydata.ranges = ranges
gravitydata.selected_gravvars = dataobject.selected_gravvars
gravitydata.used_descriptors = dataobject.used_descriptors
gravitydata.scale = dataobject.scale
return gravitydata
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 7926 | # -----------------------------------------------------------------------------
##### CYLINDER/SHELL #####-----------------------------------------------------
function shellregioncylinder(dataobject::HydroDataType;
radius::Array{<:Real,1}=[0.,0.],
height::Real=0.,
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
direction::Symbol=:z,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
radius_in = radius[1]
radius_out = radius[2]
if radius_in == 0. || radius_out == 0. || height == 0. || in(0., center)
error("[Mera]: given radius, height or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift, height_shift = prep_cylindrical_shellranges(dataobject.info, center, radius_in, radius_out, height, range_unit, verbose)
if inverse == false
if isamr
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
>= (cell_shift(p.level, radius_in_shift,cell)) &&
get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
<= (cell_shift(p.level, radius_out_shift,cell)) &&
get_height_cylinder(p.cz, p.level, cz_shift)
<= (cell_shift(p.level, height_shift,cell)),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
>= (cell_shift(lmax, radius_in_shift,cell)) &&
get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
<= (cell_shift(lmax, radius_out_shift,cell)) &&
get_height_cylinder(p.cz, lmax, cz_shift)
<= (cell_shift(lmax, height_shift,cell)),
dataobject.data)
end
elseif inverse == true
if isamr
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
< (cell_shift(p.level, radius_in_shift,cell)) ||
get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
> (cell_shift(p.level, radius_out_shift,cell)) ||
get_height_cylinder(p.cz, p.level, cz_shift)
> (cell_shift(p.level, height_shift,cell)),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
< (cell_shift(lmax, radius_in_shift,cell)) ||
get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
> (cell_shift(lmax, radius_out_shift,cell)) ||
get_height_cylinder(p.cz, lmax, cz_shift)
> (cell_shift(lmax, height_shift,cell)),
dataobject.data)
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
hydrodata = HydroDataType()
hydrodata.data = sub_data
hydrodata.info = dataobject.info
hydrodata.lmin = dataobject.lmin
hydrodata.lmax = dataobject.lmax
hydrodata.boxlen = dataobject.boxlen
hydrodata.ranges = ranges
hydrodata.selected_hydrovars = dataobject.selected_hydrovars
hydrodata.used_descriptors = dataobject.used_descriptors
hydrodata.smallr = dataobject.smallr
hydrodata.smallc = dataobject.smallc
hydrodata.scale = dataobject.scale
return hydrodata
end
# -----------------------------------------------------------------------------
##### SPHERE/SHELL #####-------------------------------------------------------
function shellregionsphere(dataobject::HydroDataType;
radius::Array{<:Real,1}=[0.,0.],
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
radius_in = radius[1]
radius_out = radius[2]
if radius_in == 0. || radius_out == 0. || in(0., center)
error("[Mera]: given inner and outer radius or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift = prep_spherical_shellranges(dataobject.info, center, radius_in, radius_out, range_unit, verbose)
if inverse == false
if isamr
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
>= cell_shift(p.level, radius_in_shift, cell) &&
get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
<= cell_shift(p.level, radius_out_shift,cell),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
>= cell_shift(lmax, radius_in_shift, cell) &&
get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
<= cell_shift(lmax, radius_out_shift,cell),
dataobject.data)
end
elseif inverse == true
if isamr
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
< cell_shift(p.level, radius_in_shift, cell) ||
get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
> cell_shift(p.level, radius_out_shift, cell),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
< cell_shift(lmax, radius_in_shift, cell) ||
get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
> cell_shift(lmax, radius_out_shift, cell),
dataobject.data)
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
hydrodata = HydroDataType()
hydrodata.data = sub_data
hydrodata.info = dataobject.info
hydrodata.lmin = dataobject.lmin
hydrodata.lmax = dataobject.lmax
hydrodata.boxlen = dataobject.boxlen
hydrodata.ranges = ranges
hydrodata.selected_hydrovars = dataobject.selected_hydrovars
hydrodata.used_descriptors = dataobject.used_descriptors
hydrodata.smallr = dataobject.smallr
hydrodata.smallc = dataobject.smallc
hydrodata.scale = dataobject.scale
return hydrodata
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 5502 | # -----------------------------------------------------------------------------
##### CYLINDER/SHELL #####-----------------------------------------------------
function shellregioncylinder(dataobject::PartDataType;
radius::Array{<:Real,1}=[0.,0.],
height::Real=0.,
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
direction::Symbol=:z,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
radius_in = radius[1]
radius_out = radius[2]
if radius_in == 0. || radius_out == 0. || height == 0. || in(0., center)
error("[Mera]: given radius, height or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift, height_shift = prep_cylindrical_shellranges(dataobject.info, center, radius_in, radius_out, height, range_unit, verbose)
if inverse == false
sub_data = filter(p-> sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2)
>= ( radius_in_shift*boxlen ) &&
sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2)
<= ( radius_out_shift*boxlen ) &&
abs(p.z - cz_shift*boxlen) <= ( height_shift*boxlen),
dataobject.data)
elseif inverse == true
sub_data = filter(p-> sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2)
< ( radius_in_shift*boxlen ) ||
sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2)
> ( radius_out_shift*boxlen ) ||
abs(p.z - cz_shift*boxlen) > ( height_shift*boxlen),
dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
partdata = PartDataType()
partdata.data = sub_data
partdata.info = dataobject.info
partdata.lmin = dataobject.lmin
partdata.lmax = dataobject.lmax
partdata.boxlen = dataobject.boxlen
partdata.ranges = ranges
partdata.selected_partvars = dataobject.selected_partvars
partdata.used_descriptors = dataobject.used_descriptors
partdata.scale = dataobject.scale
return partdata
end
# -----------------------------------------------------------------------------
##### SPHERE/SHELL #####-------------------------------------------------------
function shellregionsphere(dataobject::PartDataType;
radius::Array{<:Real,1}=[0.,0.],
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
radius_in = radius[1]
radius_out = radius[2]
if radius_in == 0. || radius_out == 0. || in(0., center)
error("[Mera]: given inner and outer radius or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_in_shift, radius_out_shift = prep_spherical_shellranges(dataobject.info, center, radius_in, radius_out, range_unit, verbose)
if inverse == false
sub_data = filter(p-> sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2 +
(p.z - cz_shift*boxlen)^2 )
>= ( radius_in_shift*boxlen ) &&
sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2 +
(p.z - cz_shift*boxlen)^2 )
<= ( radius_out_shift*boxlen ),
dataobject.data)
elseif inverse == true
sub_data = filter(p-> sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2 +
(p.z - cz_shift*boxlen)^2 )
< ( radius_in_shift*boxlen ) ||
sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2 +
(p.z - cz_shift*boxlen)^2 )
> ( radius_out_shift*boxlen ),
dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
partdata = PartDataType()
partdata.data = sub_data
partdata.info = dataobject.info
partdata.lmin = dataobject.lmin
partdata.lmax = dataobject.lmax
partdata.boxlen = dataobject.boxlen
partdata.ranges = ranges
partdata.selected_partvars = dataobject.selected_partvars
partdata.used_descriptors = dataobject.used_descriptors
partdata.scale = dataobject.scale
return partdata
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 7330 | """
### Cutout sub-regions of the data base of DataSetType
- select shape of a region
- select size of a region (with or w/o intersecting cells)
- give the spatial center (with units) of the data relative to the full box
- relate the coordinates to a direction (x,y,z)
- inverse the selected region
- pass a struct with arguments (myargs)
```julia
subregion(dataobject::DataSetType, shape::Symbol=:cuboid;
xrange::Array{<:Any,1}=[missing, missing], # cuboid
yrange::Array{<:Any,1}=[missing, missing], # cuboid
zrange::Array{<:Any,1}=[missing, missing], # cuboid
radius::Real=0., # cylinder, sphere
height::Real=0., # cylinder
direction::Symbol=:z, # cylinder
center::Array{<:Any,1}=[0.,0.,0.], # all
range_unit::Symbol=:standard, # all
cell::Bool=true, # hydro and gravity
inverse::Bool=false, # all
verbose::Bool=true, # all
myargs::ArgumentsType=ArgumentsType() ) # all
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "DataSetType"
- **`shape`:** select between region shapes: :cuboid, :cylinder/:disc, :sphere
##### Predefined/Optional Keywords:
**For cuboid region, related to a given center:**
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
**For cylindrical region, related to a given center:**
- **`radius`:** the radius between [0., radius] in units given by argument `range_unit` and relative to the given `center`
- **`height`:** the hight above and below a plane [-height, height] in units given by argument `range_unit` and relative to the given `center`
- **`direction`:** todo
**For spherical region, related to a given center:**
- **`radius`:** the radius between [0., radius] in units given by argument `range_unit` and relative to the given `center`
**Keywords related to all region shapes**
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`inverse`:** inverse the region selection = get the data outside of the region
- **`cell`:** take intersecting cells of the region boarder into account (true) or only the cells-centers within the selected region (false)
- **`verbose`:** print timestamp, selected vars and ranges on screen; default: true
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of xrange, yrange, zrange, radius, height, direction, center, range_unit, verbose
"""
function subregion(dataobject::DataSetType, shape::Symbol=:cuboid;
xrange::Array{<:Any,1}=[missing, missing], # cuboid
yrange::Array{<:Any,1}=[missing, missing], # cuboid
zrange::Array{<:Any,1}=[missing, missing], # cuboid
radius::Real=0., # cylinder, sphere
height::Real=0., # cylinder
direction::Symbol=:z, # cylinder
center::Array{<:Any,1}=[0.,0.,0.], # all
range_unit::Symbol=:standard, # all
cell::Bool=true, # hydro and gravity
inverse::Bool=false, # all
verbose::Bool=true, # all
myargs::ArgumentsType=ArgumentsType() ) # all
# take values from myargs if given
if !(myargs.direction === missing) direction = myargs.direction end
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.radius === missing) radius = myargs.radius end
if !(myargs.height === missing) height = myargs.height end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
verbose = checkverbose(verbose)
# subregion = wrapper over all subregion functions
if shape == :cuboid
if typeof(dataobject) == HydroDataType || typeof(dataobject) == GravDataType
return subregioncuboid(dataobject,
xrange=xrange, yrange=yrange, zrange=zrange,
center=center,
range_unit=range_unit,
cell=cell,
inverse=inverse,
verbose=verbose)
else
return subregioncuboid(dataobject,
xrange=xrange, yrange=yrange, zrange=zrange,
center=center,
range_unit=range_unit,
inverse=inverse,
verbose=verbose)
end
elseif shape == :cylinder || shape == :disc
if typeof(dataobject) == HydroDataType || typeof(dataobject) == GravDataType
return subregioncylinder(dataobject,
radius=radius,
height=height,
center=center,
range_unit=range_unit,
direction=direction,
cell=cell,
inverse=inverse,
verbose=verbose)
else
return subregioncylinder(dataobject,
radius=radius,
height=height,
center=center,
range_unit=range_unit,
direction=direction,
inverse=inverse,
verbose=verbose)
end
elseif shape == :sphere
if typeof(dataobject) == HydroDataType || typeof(dataobject) == GravDataType
return subregionsphere(dataobject,
radius=radius,
center=center,
range_unit=range_unit,
cell=cell,
inverse=inverse,
verbose=verbose)
else
return subregionsphere(dataobject,
radius=radius,
center=center,
range_unit=range_unit,
inverse=inverse,
verbose=verbose)
end
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 6984 | # -----------------------------------------------------------------------------
##### CUBOID #####-------------------------------------------------------------
function subregioncuboid(dataobject::ClumpDataType;
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
boxlen = dataobject.boxlen
# convert given ranges and print overview on screen
ranges = prepranges(dataobject.info,range_unit, verbose, xrange, yrange, zrange, center)
xmin, xmax, ymin, ymax, zmin, zmax = ranges
#if !(xrange == [dataobject.ranges[1], dataobject.ranges[2]] &&
# yrange == [dataobject.ranges[3], dataobject.ranges[4]] &&
# zrange == [dataobject.ranges[5], dataobject.ranges[6]])
if !(xrange[1] === missing && xrange[2] === missing &&
yrange[1] === missing && yrange[2] === missing &&
zrange[1] === missing && zrange[2] === missing)
if inverse == false
sub_data = filter(p-> p.peak_x >= xmin * boxlen &&
p.peak_x <= xmax * boxlen &&
p.peak_y >= ymin * boxlen &&
p.peak_y <= ymax * boxlen &&
p.peak_z >= zmin * boxlen &&
p.peak_z <= zmax * boxlen, dataobject.data)
elseif inverse == true
sub_data = filter(p-> (p.peak_x < xmin * boxlen ||
p.peak_x > xmax * boxlen) ||
(p.peak_y < ymin * boxlen ||
p.peak_y > ymax * boxlen) ||
(p.peak_z < zmin * boxlen ||
p.peak_z > zmax * boxlen), dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
clumpdata = ClumpDataType()
clumpdata.data = sub_data
clumpdata.info = dataobject.info
clumpdata.boxlen = dataobject.boxlen
clumpdata.ranges = ranges
clumpdata.selected_clumpvars = dataobject.selected_clumpvars
clumpdata.used_descriptors = dataobject.used_descriptors
clumpdata.scale = dataobject.scale
return clumpdata
else
return dataobject
# println("[Mera]: Nothing to do! Given ranges match data ranges!")
# println()
end
end
# -----------------------------------------------------------------------------
##### CYLINDER #####-----------------------------------------------------------
function subregioncylinder(dataobject::ClumpDataType;
radius::Real=0.,
height::Real=0.,
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
direction::Symbol=:z,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
if radius == 0. || height == 0. || in(0., center)
error("[Mera]: given radius, height or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_shift, height_shift = prepranges(dataobject.info, center, radius, height, range_unit, verbose)
if inverse == false
sub_data = filter(p-> sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2)
<= ( radius_shift*boxlen ) &&
abs(p.peak_z - cz_shift*boxlen) <= ( height_shift*boxlen),
dataobject.data)
elseif inverse == true
sub_data = filter(p-> sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2)
> ( radius_shift*boxlen ) ||
abs(p.peak_z - cz_shift*boxlen) > ( height_shift*boxlen),
dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
clumpdata = ClumpDataType()
clumpdata.data = sub_data
clumpdata.info = dataobject.info
clumpdata.boxlen = dataobject.boxlen
clumpdata.ranges = ranges
clumpdata.selected_clumpvars = dataobject.selected_clumpvars
clumpdata.used_descriptors = dataobject.used_descriptors
clumpdata.scale = dataobject.scale
return clumpdata
end
# -----------------------------------------------------------------------------
##### SPHERE #####-------------------------------------------------------------
function subregionsphere(dataobject::ClumpDataType;
radius::Real=0.,
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
if radius == 0. || in(0., center)
error("[Mera]: given radius or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
# convert given ranges and print overview on screen
height = 0.
ranges, cx_shift, cy_shift, cz_shift, radius_shift = prepranges(dataobject.info, center, radius, height, range_unit, verbose)
if inverse == false
sub_data = filter(p-> sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2+
(p.peak_z - cz_shift*boxlen)^2 )
<= ( radius_shift*boxlen ),
dataobject.data)
elseif inverse == true
sub_data = filter(p-> sqrt( (p.peak_x - cx_shift*boxlen)^2 +
(p.peak_y - cy_shift*boxlen )^2+
(p.peak_z - cz_shift*boxlen)^2 )
> ( radius_shift*boxlen ),
dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
clumpdata = ClumpDataType()
clumpdata.data = sub_data
clumpdata.info = dataobject.info
clumpdata.boxlen = dataobject.boxlen
clumpdata.ranges = ranges
clumpdata.selected_clumpvars = dataobject.selected_clumpvars
clumpdata.used_descriptors = dataobject.used_descriptors
clumpdata.scale = dataobject.scale
return clumpdata
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 12277 | # -----------------------------------------------------------------------------
##### CUBOID #####-------------------------------------------------------------
function subregioncuboid(dataobject::GravDataType;
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
boxlen = dataobject.boxlen
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
ranges = prepranges(dataobject.info,range_unit, verbose, xrange, yrange, zrange, center)
xmin, xmax, ymin, ymax, zmin, zmax = ranges
#if !(xrange == [dataobject.ranges[1], dataobject.ranges[2]] &&
# yrange == [dataobject.ranges[3], dataobject.ranges[4]] &&
# zrange == [dataobject.ranges[5], dataobject.ranges[6]])
if !(xrange[1] === missing && xrange[2] === missing &&
yrange[1] === missing && yrange[2] === missing &&
zrange[1] === missing && zrange[2] === missing)
if inverse == false
if isamr
if cell == true
sub_data = filter(p-> p.cx >=floor(Int, 2^p.level * xmin) &&
p.cx <=ceil(Int, 2^p.level * xmax) &&
p.cy >=floor(Int, 2^p.level * ymin) &&
p.cy <=ceil(Int, 2^p.level * ymax) &&
p.cz >=floor(Int, 2^p.level * zmin) &&
p.cz <=ceil(Int, 2^p.level * zmax), dataobject.data)
else
sub_data = filter(p-> p.cx >=( 2^p.level * xmin) &&
p.cx <=( 2^p.level * xmax) &&
p.cy >=( 2^p.level * ymin) &&
p.cy <=( 2^p.level * ymax) &&
p.cz >=( 2^p.level * zmin) &&
p.cz <=( 2^p.level * zmax), dataobject.data)
end
else # for uniform grid
if cell == true
sub_data = filter(p-> p.cx >=floor(Int, 2^lmax * xmin) &&
p.cx <=ceil(Int, 2^lmax * xmax) &&
p.cy >=floor(Int, 2^lmax * ymin) &&
p.cy <=ceil(Int, 2^lmax * ymax) &&
p.cz >=floor(Int, 2^lmax * zmin) &&
p.cz <=ceil(Int, 2^lmax * zmax), dataobject.data)
else
sub_data = filter(p-> p.cx >=( 2^lmax * xmin) &&
p.cx <=( 2^lmax * xmax) &&
p.cy >=( 2^lmax * ymin) &&
p.cy <=( 2^lmax * ymax) &&
p.cz >=( 2^lmax * zmin) &&
p.cz <=( 2^lmax * zmax), dataobject.data)
end
end
elseif inverse == true
if cell == true
if isamr
sub_data = filter(p-> p.cx <floor(Int, 2^p.level * xmin) ||
p.cx >ceil(Int, 2^p.level * xmax) ||
p.cy <floor(Int, 2^p.level * ymin) ||
p.cy >ceil(Int, 2^p.level * ymax) ||
p.cz <floor(Int, 2^p.level * zmin) ||
p.cz >ceil(Int, 2^p.level * zmax) , dataobject.data)
else # for uniform grid
sub_data = filter(p-> p.cx <floor(Int, 2^lmax * xmin) ||
p.cx >ceil(Int, 2^lmax * xmax) ||
p.cy <floor(Int, 2^lmax * ymin) ||
p.cy >ceil(Int, 2^lmax * ymax) ||
p.cz <floor(Int, 2^lmax * zmin) ||
p.cz >ceil(Int, 2^lmax * zmax) , dataobject.data)
end
else
if isamr
sub_data = filter(p-> p.cx <( 2^p.level * xmin) ||
p.cx >( 2^p.level * xmax) ||
p.cy <( 2^p.level * ymin) ||
p.cy >( 2^p.level * ymax) ||
p.cz <( 2^p.level * zmin) ||
p.cz >( 2^p.level * zmax), dataobject.data)
else # for uniform grid
sub_data = filter(p-> p.cx <( 2^lmax * xmin) ||
p.cx >( 2^lmax * xmax) ||
p.cy <( 2^lmax * ymin) ||
p.cy >( 2^lmax * ymax) ||
p.cz <( 2^lmax * zmin) ||
p.cz >( 2^lmax * zmax), dataobject.data)
end
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
gravitydata = GravDataType()
gravitydata.data = sub_data
gravitydata.info = dataobject.info
gravitydata.lmin = dataobject.lmin
gravitydata.lmax = dataobject.lmax
gravitydata.boxlen = dataobject.boxlen
gravitydata.ranges = ranges
gravitydata.selected_gravvars = dataobject.selected_gravvars
gravitydata.used_descriptors = dataobject.used_descriptors
gravitydata.scale = dataobject.scale
return gravitydata
else
return dataobject
#println("[Mera]: Nothing to do! Given ranges match data ranges!")
end
end
# -----------------------------------------------------------------------------
##### CYLINDER #####-----------------------------------------------------------
function subregioncylinder(dataobject::GravDataType;
radius::Real=0.,
height::Real=0.,
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
direction::Symbol=:z,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
if radius == 0. || height == 0. || in(0., center)
error("[Mera]: given radius, height or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_shift, height_shift = prepranges(dataobject.info, center, radius, height, range_unit, verbose)
if inverse == false
if isamr
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
<= (cell_shift(p.level, radius_shift,cell)) &&
get_height_cylinder(p.cz, p.level, cz_shift)
<= (cell_shift(p.level, height_shift,cell)),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
<= (cell_shift(lmax, radius_shift,cell)) &&
get_height_cylinder(p.cz, lmax, cz_shift)
<= (cell_shift(lmax, height_shift,cell)),
dataobject.data)
end
elseif inverse == true
if isamr
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
> (cell_shift(p.level, radius_shift,cell)) ||
get_height_cylinder(p.cz, p.level, cz_shift)
> (cell_shift(p.level, height_shift,cell)),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
> (cell_shift(lmax, radius_shift,cell)) ||
get_height_cylinder(p.cz, lmax, cz_shift)
> (cell_shift(lmax, height_shift,cell)),
dataobject.data)
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
gravitydata = GravDataType()
gravitydata.data = sub_data
gravitydata.info = dataobject.info
gravitydata.lmin = dataobject.lmin
gravitydata.lmax = dataobject.lmax
gravitydata.boxlen = dataobject.boxlen
gravitydata.ranges = ranges
gravitydata.selected_gravvars = dataobject.selected_gravvars
gravitydata.used_descriptors = dataobject.used_descriptors
gravitydata.scale = dataobject.scale
return gravitydata
end
# -----------------------------------------------------------------------------
##### SPHERE #####-------------------------------------------------------------
function subregionsphere(dataobject::GravDataType;
radius::Real=0.,
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
if radius == 0. || in(0., center)
error("[Mera]: given radius or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
height = 0.
ranges, cx_shift, cy_shift, cz_shift, radius_shift = prepranges(dataobject.info, center, radius, height, range_unit, verbose)
if inverse == false
if isamr
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
<= cell_shift(p.level, radius_shift, cell),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
<= cell_shift(lmax, radius_shift, cell),
dataobject.data)
end
elseif inverse == true
if isamr
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
> cell_shift(p.level, radius_shift, cell),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
> cell_shift(lmax, radius_shift, cell),
dataobject.data)
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
gravitydata = GravDataType()
gravitydata.data = sub_data
gravitydata.info = dataobject.info
gravitydata.lmin = dataobject.lmin
gravitydata.lmax = dataobject.lmax
gravitydata.boxlen = dataobject.boxlen
gravitydata.ranges = ranges
gravitydata.selected_gravvars = dataobject.selected_gravvars
gravitydata.used_descriptors = dataobject.used_descriptors
gravitydata.scale = dataobject.scale
return gravitydata
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 13270 | # -----------------------------------------------------------------------------
##### CUBOID #####-------------------------------------------------------------
function subregioncuboid(dataobject::HydroDataType;
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
boxlen = dataobject.boxlen
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
ranges = prepranges(dataobject.info,range_unit, verbose, xrange, yrange, zrange, center)
xmin, xmax, ymin, ymax, zmin, zmax = ranges
#if !(xrange == [dataobject.ranges[1], dataobject.ranges[2]] &&
# yrange == [dataobject.ranges[3], dataobject.ranges[4]] &&
# zrange == [dataobject.ranges[5], dataobject.ranges[6]])
if !(xrange[1] === missing && xrange[2] === missing &&
yrange[1] === missing && yrange[2] === missing &&
zrange[1] === missing && zrange[2] === missing)
if inverse == false
if isamr
if cell == true
sub_data = filter(p-> p.cx >=floor(Int, 2^p.level * xmin) &&
p.cx <=ceil(Int, 2^p.level * xmax) &&
p.cy >=floor(Int, 2^p.level * ymin) &&
p.cy <=ceil(Int, 2^p.level * ymax) &&
p.cz >=floor(Int, 2^p.level * zmin) &&
p.cz <=ceil(Int, 2^p.level * zmax), dataobject.data)
else
sub_data = filter(p-> p.cx >=( 2^p.level * xmin) &&
p.cx <=( 2^p.level * xmax) &&
p.cy >=( 2^p.level * ymin) &&
p.cy <=( 2^p.level * ymax) &&
p.cz >=( 2^p.level * zmin) &&
p.cz <=( 2^p.level * zmax), dataobject.data)
end
else # for uniform grid
if cell == true
sub_data = filter(p-> p.cx >=floor(Int, 2^lmax * xmin) &&
p.cx <=ceil(Int, 2^lmax * xmax) &&
p.cy >=floor(Int, 2^lmax * ymin) &&
p.cy <=ceil(Int, 2^lmax * ymax) &&
p.cz >=floor(Int, 2^lmax * zmin) &&
p.cz <=ceil(Int, 2^lmax * zmax), dataobject.data)
else
sub_data = filter(p-> p.cx >=( 2^lmax * xmin) &&
p.cx <=( 2^lmax * xmax) &&
p.cy >=( 2^lmax * ymin) &&
p.cy <=( 2^lmax * ymax) &&
p.cz >=( 2^lmax * zmin) &&
p.cz <=( 2^lmax * zmax), dataobject.data)
end
end
elseif inverse == true
if cell == true
if isamr
sub_data = filter(p-> p.cx <floor(Int, 2^p.level * xmin) ||
p.cx >ceil(Int, 2^p.level * xmax) ||
p.cy <floor(Int, 2^p.level * ymin) ||
p.cy >ceil(Int, 2^p.level * ymax) ||
p.cz <floor(Int, 2^p.level * zmin) ||
p.cz >ceil(Int, 2^p.level * zmax) , dataobject.data)
else # for uniform grid
sub_data = filter(p-> p.cx <floor(Int, 2^lmax * xmin) ||
p.cx >ceil(Int, 2^lmax * xmax) ||
p.cy <floor(Int, 2^lmax * ymin) ||
p.cy >ceil(Int, 2^lmax * ymax) ||
p.cz <floor(Int, 2^lmax * zmin) ||
p.cz >ceil(Int, 2^lmax * zmax) , dataobject.data)
end
else
if isamr
sub_data = filter(p-> p.cx <( 2^p.level * xmin) ||
p.cx >( 2^p.level * xmax) ||
p.cy <( 2^p.level * ymin) ||
p.cy >( 2^p.level * ymax) ||
p.cz <( 2^p.level * zmin) ||
p.cz >( 2^p.level * zmax), dataobject.data)
else # for uniform grid
sub_data = filter(p-> p.cx <( 2^lmax * xmin) ||
p.cx >( 2^lmax * xmax) ||
p.cy <( 2^lmax * ymin) ||
p.cy >( 2^lmax * ymax) ||
p.cz <( 2^lmax * zmin) ||
p.cz >( 2^lmax * zmax), dataobject.data)
end
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
hydrodata = HydroDataType()
hydrodata.data = sub_data
hydrodata.info = dataobject.info
hydrodata.lmin = dataobject.lmin
hydrodata.lmax = dataobject.lmax
hydrodata.boxlen = dataobject.boxlen
hydrodata.ranges = ranges
hydrodata.selected_hydrovars = dataobject.selected_hydrovars
hydrodata.used_descriptors = dataobject.used_descriptors
hydrodata.smallr = dataobject.smallr
hydrodata.smallc = dataobject.smallc
hydrodata.scale = dataobject.scale
return hydrodata
else
return dataobject
#println("[Mera]: Nothing to do! Given ranges match data ranges!")
end
end
# -----------------------------------------------------------------------------
##### CYLINDER #####-----------------------------------------------------------
function cell_shift(level, value_shift, cell)
if cell == false
return 2^level * value_shift
else
return (ceil(Int, 2^level * value_shift))
end
end
function get_radius_cylinder(x,y, level, cx_shift, cy_shift)
xcenter = 2^level * cx_shift
ycenter = 2^level * cy_shift
x = (x - xcenter)
y = (y - ycenter)
return sqrt( x^2 + y^2)
end
function get_height_cylinder(z, level, cz_shift)
center = 2^level * cz_shift
z = (z - center)
return abs(z)
end
function subregioncylinder(dataobject::HydroDataType;
radius::Real=0.,
height::Real=0.,
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
direction::Symbol=:z,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
if radius == 0. || height == 0. || in(0., center)
error("[Mera]: given radius, height or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_shift, height_shift = prepranges(dataobject.info, center, radius, height, range_unit, verbose)
if inverse == false
if isamr
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
<= (cell_shift(p.level, radius_shift,cell)) &&
get_height_cylinder(p.cz, p.level, cz_shift)
<= (cell_shift(p.level, height_shift,cell)),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
<= (cell_shift(lmax, radius_shift,cell)) &&
get_height_cylinder(p.cz, lmax, cz_shift)
<= (cell_shift(lmax, height_shift,cell)),
dataobject.data)
end
elseif inverse == true
if isamr
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, p.level, cx_shift, cy_shift)
> (cell_shift(p.level, radius_shift,cell)) ||
get_height_cylinder(p.cz, p.level, cz_shift)
> (cell_shift(p.level, height_shift,cell)),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_cylinder(p.cx, p.cy, lmax, cx_shift, cy_shift)
> (cell_shift(lmax, radius_shift,cell)) ||
get_height_cylinder(p.cz, lmax, cz_shift)
> (cell_shift(lmax, height_shift,cell)),
dataobject.data)
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
hydrodata = HydroDataType()
hydrodata.data = sub_data
hydrodata.info = dataobject.info
hydrodata.lmin = dataobject.lmin
hydrodata.lmax = dataobject.lmax
hydrodata.boxlen = dataobject.boxlen
hydrodata.ranges = ranges
hydrodata.selected_hydrovars = dataobject.selected_hydrovars
hydrodata.used_descriptors = dataobject.used_descriptors
hydrodata.smallr = dataobject.smallr
hydrodata.smallc = dataobject.smallc
hydrodata.scale = dataobject.scale
return hydrodata
end
# -----------------------------------------------------------------------------
##### SPHERE #####-------------------------------------------------------------
function get_radius_sphere(x,y,z, level, cx_shift, cy_shift, cz_shift)
xcenter = 2^level * cx_shift
ycenter = 2^level * cy_shift
zcenter = 2^level * cz_shift
x = (x - xcenter)
y = (y - ycenter)
z = (z - zcenter)
return sqrt( x^2 + y^2 + z^2)
end
function subregionsphere(dataobject::HydroDataType;
radius::Real=0.,
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
cell::Bool=true,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
if radius == 0. || in(0., center)
error("[Mera]: given radius or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
lmax = dataobject.lmax
isamr = checkuniformgrid(dataobject, lmax)
# convert given ranges and print overview on screen
height = 0.
ranges, cx_shift, cy_shift, cz_shift, radius_shift = prepranges(dataobject.info, center, radius, height, range_unit, verbose)
if inverse == false
if isamr
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
<= cell_shift(p.level, radius_shift, cell),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
<= cell_shift(lmax, radius_shift, cell),
dataobject.data)
end
elseif inverse == true
if isamr
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, p.level, cx_shift, cy_shift, cz_shift)
> cell_shift(p.level, radius_shift, cell),
dataobject.data)
else # for uniform grid
sub_data = filter(p-> get_radius_sphere(p.cx, p.cy, p.cz, lmax, cx_shift, cy_shift, cz_shift)
> cell_shift(lmax, radius_shift, cell),
dataobject.data)
end
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
hydrodata = HydroDataType()
hydrodata.data = sub_data
hydrodata.info = dataobject.info
hydrodata.lmin = dataobject.lmin
hydrodata.lmax = dataobject.lmax
hydrodata.boxlen = dataobject.boxlen
hydrodata.ranges = ranges
hydrodata.selected_hydrovars = dataobject.selected_hydrovars
hydrodata.used_descriptors = dataobject.used_descriptors
hydrodata.smallr = dataobject.smallr
hydrodata.smallc = dataobject.smallc
hydrodata.scale = dataobject.scale
return hydrodata
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 6741 | # -----------------------------------------------------------------------------
##### CUBOID #####-------------------------------------------------------------
function subregioncuboid(dataobject::PartDataType;
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
boxlen = dataobject.boxlen
# convert given ranges and print overview on screen
ranges = prepranges(dataobject.info,range_unit, verbose, xrange, yrange, zrange, center)
xmin, xmax, ymin, ymax, zmin, zmax = ranges
#if !(xrange == [dataobject.ranges[1], dataobject.ranges[2]] &&
# yrange == [dataobject.ranges[3], dataobject.ranges[4]] &&
# zrange == [dataobject.ranges[5], dataobject.ranges[6]])
if !(xrange[1] === missing && xrange[2] === missing &&
yrange[1] === missing && yrange[2] === missing &&
zrange[1] === missing && zrange[2] === missing)
if inverse == false
sub_data = filter(p-> p.x >= xmin * boxlen &&
p.x <= xmax * boxlen &&
p.y >= ymin * boxlen &&
p.y <= ymax * boxlen &&
p.z >= zmin * boxlen &&
p.z <= zmax * boxlen, dataobject.data)
elseif inverse == true
sub_data = filter(p-> (p.x < xmin * boxlen ||
p.x > xmax * boxlen) ||
(p.y < ymin * boxlen ||
p.y > ymax * boxlen) ||
(p.z < zmin * boxlen ||
p.z > zmax * boxlen), dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
partdata = PartDataType()
partdata.data = sub_data
partdata.info = dataobject.info
partdata.lmin = dataobject.lmin
partdata.lmax = dataobject.lmax
partdata.boxlen = dataobject.boxlen
partdata.ranges = ranges
partdata.selected_partvars = dataobject.selected_partvars
partdata.used_descriptors = dataobject.used_descriptors
partdata.scale = dataobject.scale
return partdata
else
return dataobject
# println("[Mera]: Nothing to do! Given ranges match data ranges!")
# println()
end
end
function subregioncylinder(dataobject::PartDataType;
radius::Real=0.,
height::Real=0.,
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
direction::Symbol=:z,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
if radius == 0. || height == 0. || in(0., center)
error("[Mera]: given radius, height or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
# convert given ranges and print overview on screen
ranges, cx_shift, cy_shift, cz_shift, radius_shift, height_shift = prepranges(dataobject.info, center, radius, height, range_unit, verbose)
if inverse == false
sub_data = filter(p-> sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2)
<= ( radius_shift*boxlen ) &&
abs(p.z - cz_shift*boxlen) <= ( height_shift*boxlen),
dataobject.data)
elseif inverse == true
sub_data = filter(p-> sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2)
> ( radius_shift*boxlen ) ||
abs(p.z - cz_shift*boxlen) > ( height_shift*boxlen),
dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
partdata = PartDataType()
partdata.data = sub_data
partdata.info = dataobject.info
partdata.lmin = dataobject.lmin
partdata.lmax = dataobject.lmax
partdata.boxlen = dataobject.boxlen
partdata.ranges = ranges
partdata.selected_partvars = dataobject.selected_partvars
partdata.used_descriptors = dataobject.used_descriptors
partdata.scale = dataobject.scale
return partdata
end
# -----------------------------------------------------------------------------
##### SPHERE #####-------------------------------------------------------------
function subregionsphere(dataobject::PartDataType;
radius::Real=0.,
center::Array{<:Any,1}=[0.,0.,0.],
range_unit::Symbol=:standard,
inverse::Bool=false,
verbose::Bool=verbose_mode)
printtime("", verbose)
if radius == 0. || in(0., center)
error("[Mera]: given radius or center should be != 0.")
end
boxlen = dataobject.boxlen
scale = dataobject.scale
# convert given ranges and print overview on screen
height = 0.
ranges, cx_shift, cy_shift, cz_shift, radius_shift = prepranges(dataobject.info, center, radius, height, range_unit, verbose)
if inverse == false
sub_data = filter(p-> sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2 +
(p.z - cz_shift*boxlen)^2 )
<= ( radius_shift*boxlen ),
dataobject.data)
elseif inverse == true
sub_data = filter(p-> sqrt( (p.x - cx_shift*boxlen)^2 +
(p.y - cy_shift*boxlen )^2 +
(p.z - cz_shift*boxlen)^2 )
> ( radius_shift*boxlen ),
dataobject.data)
ranges = dataobject.ranges
end
printtablememory(sub_data, verbose)
partdata = PartDataType()
partdata.data = sub_data
partdata.info = dataobject.info
partdata.lmin = dataobject.lmin
partdata.lmax = dataobject.lmax
partdata.boxlen = dataobject.boxlen
partdata.ranges = ranges
partdata.selected_partvars = dataobject.selected_partvars
partdata.used_descriptors = dataobject.used_descriptors
partdata.scale = dataobject.scale
return partdata
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 10183 | # todo: skip not assigned fields
"""Get an overview of the fields from MERA composite types:
```julia
viewfields(object)
```
"""
function viewfields(object::InfoType)
list_field = propertynames(object)
for i=list_field
if i == :scale
println()
printstyled(i, " ==> subfields: ", propertynames(object.scale), "\n", bold=true, color=:normal)
println()
elseif i == :grid_info
printstyled(i, " ==> subfields: ", propertynames(object.grid_info), "\n", bold=true, color=:normal)
println()
elseif i == :part_info
printstyled(i, " ==> subfields: ", propertynames(object.part_info), "\n", bold=true, color=:normal)
println()
elseif i == :compilation
printstyled(i, " ==> subfields: ", propertynames(object.compilation), "\n", bold=true, color=:normal)
println()
elseif i == :constants
printstyled(i, " ==> subfields: ", propertynames(object.constants), "\n", bold=true, color=:normal)
println()
elseif i == :fnames
printstyled(i, " ==> subfields: ", propertynames(object.fnames), "\n", bold=true, color=:normal)
println()
elseif i == :descriptor
printstyled(i, " ==> subfields: ", propertynames(object.descriptor), "\n", bold=true, color=:normal)
println()
elseif i == :namelist_content
printstyled(i, " ==> dictionary: ", tuple(keys(object.namelist_content)...), "\n", bold=true, color=:normal)
println()
elseif i == :files_content
printstyled(i, " ==> subfields: ", propertynames(object.files_content), "\n", bold=true, color=:normal)
println()
else
println(i, "\t= ", getfield(object, i))
end
end
println()
return
end
function viewfields(object::ArgumentsType)
list_field = propertynames(object)
println()
printstyled("[Mera]: Fields to use as arguments in functions\n", bold=true, color=:normal)
printstyled("=======================================================================\n", bold=true, color=:normal)
for (j,i)=enumerate(list_field)
#fname = fieldname(field, i)
if isdefined(object, j)
println(i, "\t= ", getfield(object, i)) #, "\t\t", "[",typeof(getfield(object, i)),"]")
else
println(i, "\t= #undef")
end
end
println()
return
end
function viewfields(object::ScalesType001)
list_field = propertynames(object)
println()
printstyled("[Mera]: Fields to scale from user/code units to selected units\n", bold=true, color=:normal)
printstyled("=======================================================================\n", bold=true, color=:normal)
for i=list_field
#fname = fieldname(field, i)
println(i, "\t= ", getfield(object, i)) #, "\t\t", "[",typeof(getfield(object, i)),"]")
end
println()
return
end
function viewfields(object::PartInfoType)
list_field = propertynames(object)
println()
printstyled("[Mera]: Particle overview\n", bold=true, color=:normal)
printstyled("===============================\n", bold=true, color=:normal)
for i=list_field
#fname = fieldname(field, i)
println(i, "\t= ", getfield(object, i)) #, "\t\t", "[",typeof(getfield(object, i)),"]")
end
println()
return
end
function viewfields(object::GridInfoType)
list_field = propertynames(object)
println()
printstyled("[Mera]: Grid overview \n", bold=true, color=:normal)
printstyled("============================\n", bold=true, color=:normal)
for i=list_field
if i == :ngridmax || i == :nstep_coarse || i == :nx || i == :ny ||
i == :nz || i == :nlevelmax || i == :nboundary ||
i == :ngrid_current
println(i, "\t= ", getfield(object, i) )
elseif i == :bound_key
array_length = length(object.bound_key)
println(i, " ==> length($array_length)" )
elseif i == :cpu_read
array_length = length(object.bound_key)
println(i, " ==> length($array_length)" )
end
end
println()
return
end
function viewfields(object::CompilationInfoType)
list_field = propertynames(object)
println()
printstyled("[Mera]: Compilation file overview\n", bold=true, color=:normal)
printstyled("========================================\n", bold=true, color=:normal)
for i=list_field
#fname = fieldname(field, i)
println(i, "\t= ", getfield(object, i)) #, "\t\t", "[",typeof(getfield(object, i)),"]")
end
println()
return
end
function viewfields(object::FileNamesType)
list_field = propertynames(object)
println()
printstyled("[Mera]: Paths and file-names\n", bold=true, color=:normal)
printstyled("=================================\n", bold=true, color=:normal)
for i=list_field
println(i, "\t= ", getfield(object, i) )
end
println()
return
end
function viewfields(object::DescriptorType)
list_field = propertynames(object)
println()
printstyled("[Mera]: Descriptor overview\n", bold=true, color=:normal)
printstyled("=================================\n", bold=true, color=:normal)
for i=list_field
println(i, "\t= ", getfield(object, i) )
end
println()
return
end
function viewfields(object::FilesContentType)
list_field = propertynames(object)
println()
printstyled("[Mera]: List of files-content\n", bold=true, color=:normal)
printstyled("=================================\n", bold=true, color=:normal)
println(propertynames(object))
println()
return
end
function viewfields(object::PhysicalUnitsType001)
list_field = propertynames(object)
println()
printstyled("[Mera]: Constants given in cgs units\n", bold=true, color=:normal)
printstyled("=========================================\n", bold=true, color=:normal)
for i=list_field
println(i, "\t= ", getfield(object, i) )
end
println()
return
end
# todo: check
function viewfields(object::DataSetType)
list_field = propertynames(object)
println()
for i=list_field
if i== :data
printstyled(i, " ==> JuliaDB table: ", colnames(object.data), "\n", bold=true, color=:normal)
println()
elseif i== :info
printstyled(i, " ==> subfields: ", propertynames(object.info), "\n", bold=true, color=:normal)
println()
elseif i== :scale
println()
printstyled(i, " ==> subfields: ", propertynames(object.scale), "\n", bold=true, color=:normal)
println()
elseif i == :used_descriptors
if object.info.descriptor.usehydro
println(i, "\t= ", getfield(object, i) )
end
else
println(i, "\t= ", getfield(object, i) )
end
end
println()
return
end
function namelist(object::InfoType)
println()
printstyled("[Mera]: Namelist file content\n", bold=true, color=:normal)
printstyled("=================================\n", bold=true, color=:normal)
keylist_header = keys(object.namelist_content)
for i in keylist_header
println(i)
icontent = object.namelist_content[i]
keylist_parameters = keys(icontent)
for j in keylist_parameters
println(j, " \t=", icontent[j] )
end
println()
end
return
end
function namelist(object::Dict{Any,Any})
println()
printstyled("[Mera]: Namelist file content\n", bold=true, color=:normal)
printstyled("=================================\n", bold=true, color=:normal)
keylist_header = keys(object)
for i in keylist_header
println(i)
icontent = object[i]
keylist_parameters = keys(icontent)
for j in keylist_parameters
println(j, " \t=", icontent[j] )
end
println()
end
println()
return
end
"""Get a printout of the makefile:
```julia
makefile(object::InfoType)
```
"""
function makefile(object::InfoType)
println()
printstyled("[Mera]: Makefile content\n", bold=true, color=:normal)
printstyled("=================================\n", bold=true, color=:normal)
if object.makefile
for i in object.files_content.makefile
println(i)
end
else
println("[Mera]: No Makefile found!")
end
println()
return
end
"""Get a printout of the timerfile:
```julia
timerfile(object::InfoType)
```
"""
function timerfile(object::InfoType)
println()
printstyled("[Mera]: Timer-file content\n", bold=true, color=:normal)
printstyled("=================================\n", bold=true, color=:normal)
if object.timerfile
for i in object.files_content.timerfile
println(i)
end
else
println("[Mera]: No Timer-file found!")
end
println()
return
end
"""Get a printout of the patchfile:
```julia
patchfile(object::InfoType)
```
"""
function patchfile(object::InfoType)
println()
printstyled("[Mera]: Patch-file content\n", bold=true, color=:normal)
printstyled("=================================\n", bold=true, color=:normal)
if object.patchfile
for i in object.files_content.patchfile
println(i)
end
else
println("[Mera]: No Patch-file found!")
end
println()
return
end
"""Get a detailed overview of many fields from the MERA InfoType:
```julia
viewallfields(dataobject::InfoType)
```
"""
function viewallfields(dataobject::InfoType)
viewfields(dataobject)
viewfields(dataobject.scale)
viewfields(dataobject.constants)
viewfields(dataobject.fnames)
viewfields(dataobject.descriptor)
namelist(dataobject)
viewfields(dataobject.grid_info)
viewfields(dataobject.part_info)
viewfields(dataobject.compilation)
makefile(dataobject)
timerfile(dataobject)
return
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 5166 | """
```julia
createpath(output::Real, path::String; namelist::String="")
return FileNamesType
```
"""
function createpath(output::Real, path::String; namelist::String="")
if output < 10
Path_folder = "output_0000$output"
Info_file = "info_0000$output.txt"
AMR_file = "amr_0000$output."
Hydro_file = "hydro_0000$output."
Grav_file = "grav_0000$output."
RT_file = "rt_0000$output."
RT_descriptor = "info_rt_0000$output.txt"
Part_file = "part_0000$output."
Clump_file = "clump_0000$output."
Timer_file = "timer_0000$output.txt"
Header_file = "header_0000$output.txt"
elseif output < 100 && output > 9
Path_folder = "output_000$output"
Info_file = "info_000$output.txt"
AMR_file = "amr_000$output."
Hydro_file = "hydro_000$output."
Grav_file = "grav_000$output."
RT_file = "rt_000$output."
RT_descriptor = "info_rt_000$output.txt"
Part_file = "part_000$output."
Clump_file = "clump_000$output."
Timer_file = "timer_000$output.txt"
Header_file = "header_000$output.txt"
elseif output < 1000 && output > 99
Path_folder = "output_00$output"
Info_file = "info_00$output.txt"
AMR_file = "amr_00$output."
Hydro_file = "hydro_00$output."
Grav_file = "grav_00$output."
RT_file = "rt_00$output."
RT_descriptor = "info_rt_00$output.txt"
Part_file = "part_00$output."
Clump_file = "clump_00$output."
Timer_file = "timer_00$output.txt"
Header_file = "header_00$output.txt"
elseif output < 10000 && output > 999
Path_folder = "output_0$output"
Info_file = "info_0$output.txt"
AMR_file = "amr_0$output."
Hydro_file = "hydro_0$output."
Grav_file = "grav_0$output."
RT_file = "rt_0$output."
RT_descriptor = "info_rt_0$output.txt"
Part_file = "part_0$output."
Clump_file = "clump_0$output."
Timer_file = "timer_0$output.txt"
Header_file = "header_0$output.txt"
elseif output < 100000 && output > 9999
Path_folder = "output_$output"
Info_file = "info_$output.txt"
AMR_file = "amr_$output."
Hydro_file = "hydro_$output."
Grav_file = "grav_$output."
RT_file = "rt_$output."
RT_descriptor = "info_rt_$output.txt"
Part_file = "part_$output."
Clump_file = "clump_$output."
Timer_file = "timer_$output.txt"
Header_file = "header_$output.txt"
end
fnames = FileNamesType()
fnames.output = joinpath(path, Path_folder)
fnames.info = joinpath(path, Path_folder, Info_file)
fnames.amr = joinpath(path, Path_folder, AMR_file)
fnames.hydro = joinpath(path, Path_folder, Hydro_file)
fnames.hydro_descriptor = joinpath(path, Path_folder, "hydro_file_descriptor.txt")
fnames.gravity = joinpath(path, Path_folder, Grav_file)
fnames.particles = joinpath(path, Path_folder, Part_file)
fnames.part_descriptor = joinpath(path, Path_folder, "part_file_descriptor.txt")
fnames.rt = joinpath(path, Path_folder, RT_file)
fnames.rt_descriptor = joinpath(path, Path_folder, "rt_file_descriptor.txt") # newer version
fnames.rt_descriptor_v0 = joinpath(path, Path_folder, RT_descriptor) # older version
fnames.clumps = joinpath(path, Path_folder, Clump_file)
fnames.timer = joinpath(path, Path_folder, Timer_file)
fnames.header = joinpath(path, Path_folder, Header_file)
fnames.compilation = joinpath(path, Path_folder, "compilation.txt")
fnames.makefile = joinpath(path, Path_folder, "makefile.txt")
fnames.patchfile = joinpath(path, Path_folder, "patches.txt")
if namelist == "" || namelist == "./"
fnames.namelist = joinpath(path, Path_folder, "namelist.txt")
else
fnames.namelist = namelist
end
return fnames
end
function createpath!(dataobject::InfoType; namelist::String="")
dataobject.fnames = createpath(dataobject.output, dataobject.path, namelist=namelist)
return dataobject
end
function getproc2string(path::String, icpu::Int32)
if icpu < 10
return string(path, "out0000", icpu)
elseif icpu < 100 && icpu > 9
return string(path, "out000", icpu)
elseif icpu < 1000 && icpu > 99
return string(path, "out00", icpu)
elseif icpu < 10000 && icpu > 999
return string(path, "out0", icpu)
elseif icpu < 100000 && icpu > 9999
return string(path, "out", icpu)
end
end
function getproc2string(path::String, textfile::Bool, icpu::Int)
if icpu < 10
return string(path, "txt0000", icpu)
elseif icpu < 100 && icpu > 9
return string(path, "txt000", icpu)
elseif icpu < 1000 && icpu > 99
return string(path, "txt00", icpu)
elseif icpu < 10000 && icpu > 999
return string(path, "txt0", icpu)
elseif icpu < 100000 && icpu > 9999
return string(path, "txt", icpu)
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 11101 | # function getclumps(dataobject::InfoType, var::Symbol;
# xrange::Array{<:Any,1}=[missing, missing],
# yrange::Array{<:Any,1}=[missing, missing],
# zrange::Array{<:Any,1}=[missing, missing],
# center::Array{<:Any,1}=[0., 0., 0.],
# range_unit::Symbol=:standard,
# print_filenames::Bool=false,
# verbose::Bool=verbose_mode)
#
# return getclumps(dataobject, vars=[var],
# xrange=xrange,
# yrange=yrange,
# zrange=zrange,
# center=center,
# range_unit=range_unit,
# print_filenames=print_filenames,
# verbose=verbose)
#
# end
"""
#### Read the clump-data:
- selected variables
- limited to a spatial range
- print the name of each data-file before reading it
- toggle verbose mode
- pass a struct with arguments (myargs)
```julia
getclumps( dataobject::InfoType;
vars::Array{Symbol,1}=[:all],
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
print_filenames::Bool=false,
verbose::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
```
#### Returns an object of type ClumpDataType, containing the clump-data table, the selected options and the simulation ScaleType and summary of the InfoType
```julia
return ClumpDataType()
# get an overview of the returned fields:
# e.g.:
julia> info = getinfo(100)
julia> clumps = getclumps(info)
julia> viewfields(clumps)
#or:
julia> fieldnames(clumps)
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "InfoType", created by the function *getinfo*
##### Predefined/Optional Keywords:
- **`vars`:** Currently, the length of the loaded variable list can be modified *(see examples below).
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`print_filenames`:** print on screen the current processed particle file of each CPU
- **`verbose`:** print timestamp, selected vars and ranges on screen; default: true
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of xrange, yrange, zrange, center, range_unit, verbose
### Defined Methods - function defined for different arguments
- getclumps(dataobject::InfoType; ...) # no given variables -> all variables loaded
- getclumps(dataobject::InfoType, vars::Array{Symbol,1}; ...) # one or several given variables -> array needed
#### Examples
```julia
# read simulation information
julia> info = getinfo(420)
# Example 1:
# read clump data of all variables, full-box
julia> clumps = getclumps(info)
# Example 2:
# read clump data of all variables
# data range 20x20x4 kpc; ranges are given in kpc relative to the box (here: 48 kpc) center at 24 kpc
julia> clumps = getclumps( info,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24., 24., 24.],
range_unit=:kpc )
# Example 3:
# give the center of the box by simply passing: center = [:bc] or center = [:boxcenter]
# this is equivalent to center=[24.,24.,24.] in Example 2
# the following combination is also possible: e.g. center=[:bc, 12., 34.], etc.
julia> clumps = getclumps( info,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[33., bc:, 10.],
range_unit=:kpc )
# Example 4:
# Load less than the found 12 columns from the header of the clump files;
# Pass an array with the variables to the keyword argument *vars*.
# The order of the variables has to be consistent with the header in the clump files:
julia> lumps = getclumps(info, [ :index, :lev, :parent, :ncell,
:peak_x, :peak_y, :peak_z ])
# Example 5:
# Load more than the found 12 columns from the header of the clump files.
# E.g. the list can be extended with more names if there are more columns
# in the data than given by the header in the files.
# The order of the variables has to be consistent with the header in the clump files:
julia> clumps = getclumps(info, [ :index, :lev, :parent, :ncell,
:peak_x, :peak_y, :peak_z,
Symbol("rho-"), Symbol("rho+"),
:rho_av, :mass_cl, :relevance,
:vx, :vy, :vz ])
...
```
"""
function getclumps(dataobject::InfoType, vars::Array{Symbol,1};
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
print_filenames::Bool=false,
verbose::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return getclumps(dataobject,
vars=vars,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
print_filenames=print_filenames,
verbose=verbose,
myargs=myargs)
end
function getclumps(dataobject::InfoType;
vars::Array{Symbol,1}=[:all],
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
print_filenames::Bool=false,
verbose::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
# take values from myargs if given
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
verbose = checkverbose(verbose)
printtime("Get clump data: ", verbose)
checkfortype(dataobject, :clumps)
boxlen = dataobject.boxlen
# convert given ranges and print overview on screen
ranges = prepranges(dataobject, range_unit, verbose, xrange, yrange, zrange, center)
fnames = createpath(dataobject.output, dataobject.path)
# read clumps-data of the selected variables
column_names, NColumns = getclumpvariables(dataobject, vars, fnames)
if verbose
println("Read $NColumns colums: ")
println(column_names)
end
data = readclumps(dataobject, fnames, NColumns, column_names, print_filenames)
# filter data out of selected ranges
if ranges[1] !=0. || ranges[2] !=1. || ranges[3] !=0. || ranges[4] !=1. || ranges[5] !=0. || ranges[6] !=1.
data = filter(p-> p.peak_x >= ranges[1] * boxlen &&
p.peak_x <= ranges[2] * boxlen &&
p.peak_y >= ranges[3] * boxlen &&
p.peak_y <= ranges[4] * boxlen &&
p.peak_z >= ranges[5] * boxlen &&
p.peak_z <= ranges[6] * boxlen, data)
end
printtablememory(data, verbose)
clumpdata = ClumpDataType()
clumpdata.data = data
clumpdata.info = dataobject
clumpdata.boxlen = dataobject.boxlen
clumpdata.ranges = ranges
clumpdata.selected_clumpvars = column_names
clumpdata.used_descriptors = Dict()
clumpdata.scale = dataobject.scale
return clumpdata
end
function getclumpvariables(dataobject::InfoType, vars::Array{Symbol,1}, fnames::FileNamesType)
if vars == [:all]
# MERA: Read column names
#--------------------------------------------
# get header of first clump file
f = open(dataobject.fnames.clumps * "txt00001")
lines = readlines(f)
column_names = Symbol.( split(lines[1]) )
NColumns = length(split(lines[1]))
close(f)
else
NColumns = length(vars)
column_names = vars
end
return column_names, NColumns
end
function readclumps(dataobject::InfoType, fnames::FileNamesType, NColumns::Int, column_names::Array{Symbol,1}, print_filenames::Bool=false)
clcol = zeros(Float64, 1, NColumns)
NCpu = dataobject.ncpu
data = 0.
create_table = 1
line_beginning = 1
for NC=1:NCpu
clumpspath = getproc2string(fnames.clumps, true, NC)
if print_filenames println(clumpspath) end
f = open(clumpspath)
lines = readlines(f)
if length(lines) > 1
for i=2:length(lines)
#NColumns = length(split(lines[i]))
for j = 1:NColumns
#println(i, " ", j)
clcol[j] = parse(Float64, split(lines[i])[j] )
end
if create_table == 0
data_buffer = table( [clcol[:, k ] for k = 1:NColumns ]...,names=collect(column_names) )
data = merge(data, data_buffer)
end
if create_table == 1
data = table( [clcol[:, k ] for k = 1:NColumns ]...,names=collect(column_names) )
create_table = 0
end
end
end
close(f)
end
return data
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 12782 | """
#### Read the leaf-cells of the gravity-data:
- select variables
- limit to a maximum level
- limit to a spatial range
- print the name of each data-file before reading it
- toggle verbose mode
- toggle progress bar
- pass a struct with arguments (myargs)
```julia
getgravity( dataobject::InfoType;
lmax::Real=dataobject.levelmax,
vars::Array{Symbol,1}=[:all],
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
```
#### Returns an object of type GravDataType, containing the gravity-data table, the selected options and the simulation ScaleType and summary of the InfoType
```julia
return GravDataType()
# get an overview of the returned fields:
# e.g.:
julia> info = getinfo(100)
julia> grav = getgravity(info)
julia> viewfields(grav)
#or:
julia> fieldnames(grav)
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "InfoType", created by the function *getinfo*
##### Predefined/Optional Keywords:
- **`lmax`:** the maximum level to be read from the data
- **`var(s)`:** the selected gravity variables in arbitrary order: :all (default), :cpu, :epot, :ax, :ay, :az
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`print_filenames`:** print on screen the current processed gravity file of each CPU
- **`verbose`:** print timestamp, selected vars and ranges on screen; default: true
- **`show_progress`:** print progress bar on screen
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of lmax, xrange, yrange, zrange, center, range_unit, verbose, show_progress
### Defined Methods - function defined for different arguments
- getgravity( dataobject::InfoType; ...) # no given variables -> all variables loaded
- getgravity( dataobject::InfoType, var::Symbol; ...) # one given variable -> no array needed
- getgravity( dataobject::InfoType, vars::Array{Symbol,1}; ...) # several given variables -> array needed
#### Examples
```julia
# read simulation information
julia> info = getinfo(420)
# Example 1:
# read gravity data of all variables, full-box, all levels
julia> grav = getgravity(info)
# Example 2:
# read gravity data of all variables up to level 8
# data range 20x20x4 kpc; ranges are given in kpc relative to the box (here: 48 kpc) center at 24 kpc
julia> grav = getgravity( info,
lmax=8,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24., 24., 24.],
range_unit=:kpc )
# Example 3:
# give the center of the box by simply passing: center = [:bc] or center = [:boxcenter]
# this is equivalent to center=[24.,24.,24.] in Example 2
# the following combination is also possible: e.g. center=[:bc, 12., 34.], etc.
julia> grav = getgravity( info,
lmax=8,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[33., bc:, 10.],
range_unit=:kpc )
# Example 4:
# read gravity data of the variables epot and the x-acceleration, full-box, all levels
julia> grav = getgravity( info, [:epot, :ax] ) # use array for the variables
# Example 5:
# read gravity data of the single variable epot, full-box, all levels
julia> grav = getgravity( info, :epot ) # no array for a single variable needed
...
```
"""
function getgravity( dataobject::InfoType, var::Symbol;
lmax::Real=dataobject.levelmax,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return getgravity(dataobject, vars=[var],
lmax=lmax,
xrange=xrange, yrange=yrange, zrange=zrange, center=center,
range_unit=range_unit,
print_filenames=print_filenames,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function getgravity( dataobject::InfoType, vars::Array{Symbol,1};
lmax::Real=dataobject.levelmax,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return getgravity(dataobject,
vars=vars,
lmax=lmax,
xrange=xrange, yrange=yrange, zrange=zrange, center=center,
range_unit=range_unit,
print_filenames=print_filenames,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function getgravity( dataobject::InfoType;
lmax::Real=dataobject.levelmax,
vars::Array{Symbol,1}=[:all],
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
# take values from myargs if given
if !(myargs.lmax === missing) lmax = myargs.lmax end
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
if !(myargs.show_progress === missing) show_progress = myargs.show_progress end
verbose = checkverbose(verbose)
printtime("Get gravity data: ", verbose)
checkfortype(dataobject, :gravity)
checklevelmax(dataobject, lmax)
isamr = checkuniformgrid(dataobject, lmax)
# create variabe-list and vector-mask (nvarg_corr) for getgravitydata-function
# print selected variables on screen
nvarg_list, nvarg_i_list, nvarg_corr, read_cpu, used_descriptors = prepvariablelist(dataobject, :gravity, vars, lmax, verbose)
# convert given ranges and print overview on screen
ranges = prepranges(dataobject, range_unit, verbose, xrange, yrange, zrange, center)
# read gravity-data of the selected variables
if read_cpu
vars_1D, pos_1D, cpus_1D = getgravitydata( dataobject, length(nvarg_list),
nvarg_corr, lmax, ranges,
print_filenames, show_progress, read_cpu, isamr )
else
vars_1D, pos_1D = getgravitydata( dataobject, length(nvarg_list),
nvarg_corr, lmax, ranges,
print_filenames, show_progress, read_cpu, isamr )
end
# prepare column names for the data table
names_constr = preptablenames_gravity(length(dataobject.gravity_variable_list), nvarg_list, used_descriptors, read_cpu, isamr)
# create data table
# decouple pos_1D/vars_1D from ElasticArray with ElasticArray.data
if read_cpu # load also cpu number related to cell
if isamr
@inbounds data = table( pos_1D[4,:].data, cpus_1D[:], pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data,
[vars_1D[nvarg_corr[i],: ].data for i in nvarg_i_list]...,
names=collect(names_constr), pkey=[:level, :cx, :cy, :cz], presorted = false ) #[names_constr...]
else # if uniform grid
@inbounds data = table(cpus_1D[:], pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data,
[vars_1D[nvarg_corr[i],: ].data for i in nvarg_i_list]...,
names=collect(names_constr), pkey=[:cx, :cy, :cz], presorted = false ) #[names_constr...]
end
else
if isamr
@inbounds data = table( pos_1D[4,:].data, pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data,
[vars_1D[nvarg_corr[i],: ].data for i in nvarg_i_list]...,
names=collect(names_constr), pkey=[:level, :cx, :cy, :cz], presorted = false ) #[names_constr...]
else # if uniform grid
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data,
[vars_1D[ nvarg_corr[i],: ].data for i in nvarg_i_list]...,
names=collect(names_constr), pkey=[:cx, :cy, :cz], presorted = false ) #[names_constr...]
end
end
printtablememory(data, verbose)
# Return data
gravitydata = GravDataType()
gravitydata.data = data
gravitydata.info = dataobject
gravitydata.lmin = dataobject.levelmin
gravitydata.lmax = lmax
gravitydata.boxlen = dataobject.boxlen
gravitydata.ranges = ranges
if read_cpu
gravitydata.selected_gravvars = [-1, nvarg_list...]
else
gravitydata.selected_gravvars = nvarg_list
end
gravitydata.used_descriptors = used_descriptors
gravitydata.scale = dataobject.scale
return gravitydata
end
function preptablenames_gravity(nvarg::Int, nvarg_list::Array{Int, 1}, used_descriptors::Dict{Any,Any}, read_cpu::Bool, isamr::Bool)
if read_cpu
if isamr
names_constr = [Symbol("level") ,Symbol("cpu"), Symbol("cx"), Symbol("cy"), Symbol("cz")]
else #if uniform grid
names_constr = [Symbol("cpu"), Symbol("cx"), Symbol("cy"), Symbol("cz")]
end
#, Symbol("x"), Symbol("y"), Symbol("z")
else
if isamr
names_constr = [Symbol("level") , Symbol("cx"), Symbol("cy"), Symbol("cz")]
else #if uniform grid
names_constr = [Symbol("cx"), Symbol("cy"), Symbol("cz")]
end
end
for i=1:nvarg
if in(i, nvarg_list)
if length(used_descriptors) == 0 || !haskey(used_descriptors, i)
if i == 1
append!(names_constr, [Symbol("epot")] )
elseif i == 2
append!(names_constr, [Symbol("ax")] )
elseif i == 3
append!(names_constr, [Symbol("ay")] )
elseif i == 4
append!(names_constr, [Symbol("az")] )
end
else append!(names_constr, [used_descriptors[i]] )
end
end
end
return names_constr
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 15603 | """
#### Read the leaf-cells of the hydro-data:
- select variables
- limit to a maximum level
- limit to a spatial range
- set a minimum density or sound speed
- check for negative values in density and thermal pressure
- print the name of each data-file before reading it
- toggle verbose mode
- toggle progress bar
- pass a struct with arguments (myargs)
```julia
gethydro( dataobject::InfoType;
lmax::Real=dataobject.levelmax,
vars::Array{Symbol,1}=[:all],
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
smallr::Real=0.,
smallc::Real=0.,
check_negvalues::Bool=false,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
```
#### Returns an object of type HydroDataType, containing the hydro-data table, the selected options and the simulation ScaleType and summary of the InfoType
```julia
return HydroDataType()
# get an overview of the returned fields:
# e.g.:
julia> info = getinfo(100)
julia> gas = gethydro(info)
julia> viewfields(gas)
#or:
julia> fieldnames(gas)
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "InfoType", created by the function *getinfo*
##### Predefined/Optional Keywords:
- **`lmax`:** the maximum level to be read from the data
- **`var(s)`:** the selected hydro variables in arbitrary order: :all (default), :cpu, :rho, :vx, :vy, :vz, :p, :var6, :var7...
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`smallr`:** set lower limit for density; zero means inactive
- **`smallc`:** set lower limit for thermal pressure; zero means inactive
- **`check_negvalues`:** check loaded data of "rho" and "p" on negative values; false by default
- **`print_filenames`:** print on screen the current processed hydro file of each CPU
- **`verbose`:** print timestamp, selected vars and ranges on screen; default: true
- **`show_progress`:** print progress bar on screen
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of lmax, xrange, yrange, zrange, center, range_unit, verbose, show_progress
### Defined Methods - function defined for different arguments
- gethydro( dataobject::InfoType; ...) # no given variables -> all variables loaded
- gethydro( dataobject::InfoType, var::Symbol; ...) # one given variable -> no array needed
- gethydro( dataobject::InfoType, vars::Array{Symbol,1}; ...) # several given variables -> array needed
#### Examples
```julia
# read simulation information
julia> info = getinfo(420)
# Example 1:
# read hydro data of all variables, full-box, all levels
julia> gas = gethydro(info)
# Example 2:
# read hydro data of all variables up to level 8
# data range 20x20x4 kpc; ranges are given in kpc relative to the box (here: 48 kpc) center at 24 kpc
julia> gas = gethydro( info,
lmax=8,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24., 24., 24.],
range_unit=:kpc )
# Example 3:
# give the center of the box by simply passing: center = [:bc] or center = [:boxcenter]
# this is equivalent to center=[24.,24.,24.] in Example 2
# the following combination is also possible: e.g. center=[:bc, 12., 34.], etc.
julia> gas = gethydro( info,
lmax=8,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[33., bc:, 10.],
range_unit=:kpc )
# Example 4:
# read hydro data of the variables density and the thermal pressure, full-box, all levels
julia> gas = gethydro( info, [:rho, :p] ) # use array for the variables
# Example 5:
# read hydro data of the single variable density, full-box, all levels
julia> gas = gethydro( info, :rho ) # no array for a single variable needed
...
```
"""
function gethydro( dataobject::InfoType, var::Symbol;
lmax::Real=dataobject.levelmax,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
smallr::Real=0.,
smallc::Real=0.,
check_negvalues::Bool=false,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return gethydro(dataobject, vars=[var],
lmax=lmax,
xrange=xrange, yrange=yrange, zrange=zrange, center=center,
range_unit=range_unit,
smallr=smallr,
smallc=smallc,
check_negvalues=check_negvalues,
print_filenames=print_filenames,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function gethydro( dataobject::InfoType, vars::Array{Symbol,1};
lmax::Real=dataobject.levelmax,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
smallr::Real=0.,
smallc::Real=0.,
check_negvalues::Bool=false,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return gethydro(dataobject,
vars=vars,
lmax=lmax,
xrange=xrange, yrange=yrange, zrange=zrange, center=center,
range_unit=range_unit,
smallr=smallr,
smallc=smallc,
check_negvalues=check_negvalues,
print_filenames=print_filenames,
verbose=verbose,
show_progress=show_progress,
myargs=myargs)
end
function gethydro( dataobject::InfoType;
lmax::Real=dataobject.levelmax,
vars::Array{Symbol,1}=[:all],
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
smallr::Real=0.,
smallc::Real=0.,
check_negvalues::Bool=false,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
# take values from myargs if given
if !(myargs.lmax === missing) lmax = myargs.lmax end
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
if !(myargs.show_progress === missing) show_progress = myargs.show_progress end
verbose = checkverbose(verbose)
show_progress = checkprogress(show_progress)
printtime("Get hydro data: ", verbose)
checkfortype(dataobject, :hydro)
checklevelmax(dataobject, lmax)
isamr = checkuniformgrid(dataobject, lmax)
# create variabe-list and vector-mask (nvarh_corr) for gethydrodata-function
# print selected variables on screen
nvarh_list, nvarh_i_list, nvarh_corr, read_cpu, used_descriptors = prepvariablelist(dataobject, :hydro, vars, lmax, verbose)
# convert given ranges and print overview on screen
ranges = prepranges(dataobject, range_unit, verbose, xrange, yrange, zrange, center)
# read hydro-data of the selected variables
if read_cpu
vars_1D, pos_1D, cpus_1D = gethydrodata( dataobject, length(nvarh_list),
nvarh_corr, lmax, ranges,
print_filenames, show_progress, read_cpu, isamr )
else
vars_1D, pos_1D = gethydrodata( dataobject, length(nvarh_list),
nvarh_corr, lmax, ranges,
print_filenames, show_progress, read_cpu, isamr )
end
# set minimum density in cells and check vor negative values
vars_1D = manageminvalues(vars_1D, check_negvalues, smallr, smallc, nvarh_list, nvarh_corr)
# prepare column names for the data table
names_constr = preptablenames(dataobject.nvarh, nvarh_list, used_descriptors, read_cpu, isamr)
# create data table
# decouple pos_1D/vars_1D from ElasticArray with ElasticArray.data
if read_cpu # load also cpu number related to cell
if isamr
@inbounds data = table(pos_1D[4,:].data, cpus_1D[:], pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data,
[vars_1D[nvarh_corr[i],: ].data for i in nvarh_i_list]...,
names=collect(names_constr), pkey=[:level,:cx, :cy, :cz], presorted = false ) #[names_constr...]
else # if uniform grid
@inbounds data = table(cpus_1D[:], pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data,
[vars_1D[nvarh_corr[i],: ].data for i in nvarh_i_list]...,
names=collect(names_constr), pkey=[:cx, :cy, :cz], presorted = false ) #[names_constr...]
end
else
if isamr
@inbounds data = table(pos_1D[4,:].data, pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data,
[vars_1D[ nvarh_corr[i],: ].data for i in nvarh_i_list]...,
names=collect(names_constr), pkey=[:level,:cx, :cy, :cz], presorted = false ) #[names_constr...]
else # if uniform grid
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data,
[vars_1D[ nvarh_corr[i],: ].data for i in nvarh_i_list]...,
names=collect(names_constr), pkey=[:cx, :cy, :cz], presorted = false ) #[names_constr...]
end
end
printtablememory(data, verbose)
# Return data
hydrodata = HydroDataType()
hydrodata.data = data
hydrodata.info = dataobject
hydrodata.lmin = dataobject.levelmin
hydrodata.lmax = lmax
hydrodata.boxlen = dataobject.boxlen
hydrodata.ranges = ranges
if read_cpu
hydrodata.selected_hydrovars = [-1, nvarh_list...]
else
hydrodata.selected_hydrovars = nvarh_list
end
hydrodata.used_descriptors = used_descriptors
hydrodata.smallr = smallr
hydrodata.smallc = smallc
hydrodata.scale = dataobject.scale
return hydrodata
end
function manageminvalues(vars_1D::ElasticArray{Float64,2,1}, check_negvalues::Bool, smallr::Real, smallc::Real, nvarh_list::Array{Int,1}, nvarh_corr::Array{Int,1})
# set minimum density in cells
if smallr != 0. && in(1, nvarh_list)
@inbounds vars_1D[1,:] =clamp.(vars_1D[nvarh_corr[1],:], smallr, maximum(vars_1D[nvarh_corr[1],:]) + 1 )
else
# check for negative values in density
if check_negvalues == true
if in(1, nvarh_list)
@inbounds count_nv = count(x->x<0., vars_1D[nvarh_corr[1],:])
if count_nv > 0
println()
println("[Mera]: Found $count_nv negative value(s) in density data.")
end
end
end
end
# set minimum thermal pressure in cells
if smallc != 0. && in(5, nvarh_list)
@inbounds vars_1D[5,:] =clamp.(vars_1D[nvarh_corr[5],:], smallc, maximum(vars_1D[nvarh_corr[5],:]) + 1 )
else
# check for negative values in thermal pressure
if check_negvalues == true
if in(5, nvarh_list)
@inbounds count_nv = count(x->x<0., vars_1D[nvarh_corr[5],:])
if count_nv > 0
println()
println("[Mera]: Found $count_nv negative value(s) in thermal pressure data.")
end
end
end
end
return vars_1D
end
function preptablenames(nvarh::Int, nvarh_list::Array{Int, 1}, used_descriptors::Dict{Any,Any}, read_cpu::Bool, isamr::Bool)
if read_cpu
if isamr
names_constr = [Symbol("level") ,Symbol("cpu"), Symbol("cx"), Symbol("cy"), Symbol("cz")]
else #if uniform grid
names_constr = [Symbol("cpu"), Symbol("cx"), Symbol("cy"), Symbol("cz")]
end
#, Symbol("x"), Symbol("y"), Symbol("z")
else
if isamr
names_constr = [Symbol("level") , Symbol("cx"), Symbol("cy"), Symbol("cz")]
else #if uniform grid
names_constr = [Symbol("cx"), Symbol("cy"), Symbol("cz")]
end
end
for i=1:nvarh
if in(i, nvarh_list)
if length(used_descriptors) == 0 || !haskey(used_descriptors, i)
if i == 1
append!(names_constr, [Symbol("rho")] )
elseif i == 2
append!(names_constr, [Symbol("vx")] )
elseif i == 3
append!(names_constr, [Symbol("vy")] )
elseif i == 4
append!(names_constr, [Symbol("vz")] )
elseif i == 5
append!(names_constr, [Symbol("p")] )
elseif i > 5
append!(names_constr, [Symbol("var$i")] )
end
else append!(names_constr, [used_descriptors[i]] )
end
end
end
return names_constr
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 30811 | """
#### Get the simulation overview from RAMSES info, descriptor and output header files
```julia
getinfo(; output::Real=1, path::String="", namelist::String="", verbose::Bool=true)
return InfoType
```
#### Keyword Arguments
- **`output`:** timestep number (default=1)
- **`path`:** the path to the output folder relative to the current folder or absolute path
- **`namelist`:** give the path to a namelist file (by default the namelist.txt-file in the output-folder is read)
- **`verbose:`:** informations are printed on the screen by default
#### Examples
```julia
# read simulation information from output `1` in current folder
julia> info = getinfo()
# read simulation information from output `420` in given folder (relative path to the current working folder)
julia> info = getinfo(output=420, path="../MySimFolder/")
# or simply use
julia> info = getinfo(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)
...
```
"""
function getinfo(output::Real; path::String="", namelist::String="", verbose::Bool=true)
return getinfo(output=output, path=path, namelist=namelist, verbose=verbose)
end
function getinfo(output::Real, path::String; namelist::String="", verbose::Bool=true)
return getinfo(output=output, path=path, namelist=namelist, verbose=verbose)
end
function getinfo(path::String; output::Real=1, namelist::String="", verbose::Bool=true)
return getinfo(output=output, path=path, namelist=namelist, verbose=verbose)
end
function getinfo(; output::Real=1, path::String="", namelist::String="", verbose::Bool=true)
verbose = checkverbose(verbose)
printtime("",verbose)
info = InfoType() # predeclare InfoType
info.descriptor = DescriptorType()
info.files_content = FilesContentType()
info.output = output
info.path = joinpath(pwd(), path) # store full path
info.simcode = "RAMSES"
info.Narraysize = 0
createpath!(info, namelist=namelist) # create path to the files
readinfofile!(info) # infofile overview
createconstants!(info) # predefined constants (create before scales)
createscales!(info) # get predefined scales and the corresponding cgs units
readnamelistfile!(info) # read namelist, check for ASCII file
readamrfile1!(info) # amr overview
readhydrofile1!(info) # hydro overview
isgravityfile1!(info) # gravity overview
readparticlesfile1!(info) # particles overview
readrtfile1!(info) # rt overview
readclumpfile1!(info) # clumps overview
# todo: check for sinks
info.sinks = false
info.sinks_variable_list = Symbol[]
info.descriptor.sinks = Symbol[]
info.descriptor.usesinks = false
info.descriptor.sinksfile = false
readtimerfile!(info) # check for timer-file
readcompilationfile!(info) # compilation overview
readmakefile!(info) # check for makefile
readpatchfile!(info) # check for patchfile
printsimoverview(info, verbose) # print overview on screen
return info
end
# ============================================
# 'getinfo' related functions
# ============================================
function readinfofile!(dataobject::InfoType)
if !isfile(dataobject.fnames.info)
println()
error("[Mera]: File or folder does not exist: $(dataobject.fnames.info) !")
end
mtime = Dates.unix2datetime(stat(dataobject.fnames.info).mtime)
ctime = Dates.unix2datetime(stat(dataobject.fnames.info).ctime)
f = open(dataobject.fnames.info)
lines = readlines(f)
ncpu = parse(Int32, rsplit(lines[1],"=")[2] )
ndim = parse(Int32, rsplit(lines[2],"=")[2] )
levelmin = parse(Int32, rsplit(lines[3],"=")[2] )
levelmax = parse(Int32, rsplit(lines[4],"=")[2] )
dataobject.grid_info = GridInfoType() #0,0,0,0,0,0,0,0,zeros(Float64, ncpu+1) ,falses(ncpu) )
dataobject.grid_info.bound_key = zeros(Float64, ncpu+1)
dataobject.grid_info.cpu_read = falses(ncpu)
dataobject.grid_info.ngridmax = parse(Int32, rsplit(lines[5],"=")[2] )
dataobject.grid_info.nstep_coarse = parse(Int32, rsplit(lines[6],"=")[2] )
boxlen = parse(Float64, rsplit(lines[8],"=")[2] )
time = parse(Float64, rsplit(lines[9],"=")[2] )
aexp = parse(Float64, rsplit(lines[10],"=")[2] )
H0 = parse(Float64, rsplit(lines[11],"=")[2] )
omega_m = parse(Float64, rsplit(lines[12],"=")[2] )
omega_l = parse(Float64, rsplit(lines[13],"=")[2] )
omega_k = parse(Float64, rsplit(lines[14],"=")[2] )
omega_b = parse(Float64, rsplit(lines[15],"=")[2] )
unit_l = parse(Float64, rsplit(lines[16],"=")[2] )
unit_d = parse(Float64, rsplit(lines[17],"=")[2] )
unit_t = parse(Float64, rsplit(lines[18],"=")[2] )
unit_v = unit_l / unit_t
unit_m = unit_d * unit_l^3
hilbert_ordering = occursin(r"(?i)hilbert", lines[20])
if ndim != 3
error("[Mera]: Program only works with 3D data!")
end
dataobject.grid_info.bound_key[1] = parse( Float64, split(lines[22])[2] )
for i = 1:ncpu
#println( parse( Float64, split(lines[21+i])[1] ), " ", parse( Float64, split(lines[21+i])[2] ), " ", parse( Float64, split(lines[21+i])[3] ) )
dataobject.grid_info.bound_key[i+1] = parse( Float64, split(lines[21+i])[3] )
end
close(f)
dataobject.ndim = ndim
#dataobject.grid_info = grid_info
dataobject.mtime = mtime
dataobject.ctime = ctime
dataobject.ncpu = ncpu
dataobject.levelmin = levelmin
dataobject.levelmax = levelmax
dataobject.boxlen = boxlen
dataobject.time = time
dataobject.aexp = aexp
dataobject.H0 = H0
dataobject.omega_m = omega_m
dataobject.omega_l = omega_l
dataobject.omega_k = omega_k
dataobject.omega_b = omega_b
dataobject.unit_l = unit_l
dataobject.unit_d = unit_d
dataobject.unit_m = unit_m
dataobject.unit_v = unit_v
dataobject.unit_t = unit_t
return dataobject
end
function readamrfile1!(dataobject::InfoType)
dataobject.amr = true
if !isfile(dataobject.fnames.amr * "out00001")
dataobject.amr = false
#println()
#error("""[Mera]: File or folder does not exist: $(dataobject.fnames.amr * "out00001")!""")
else
f = FortranFile(dataobject.fnames.amr * "out00001")
#read(f) # ncpu = read(f, Int32)
#read(f) # ndim = read(f, Int32)
skiplines(f, 2)
dataobject.grid_info.nx, dataobject.grid_info.ny, dataobject.grid_info.nz = read(f, Int32,Int32,Int32 )
dataobject.grid_info.nlevelmax = read(f, Int32)
dataobject.grid_info.ngridmax = read(f, Int32)
dataobject.grid_info.nboundary = read(f, Int32)
dataobject.grid_info.ngrid_current = read(f, Int32)
#info.boxlen = read(f, Float64)
close(f)
end
return dataobject
end
function readhydrofile1!(dataobject::InfoType)
# read descriptor file
descriptor_file = false
variable_descriptor_list = Symbol[]
variable_types = String[]
version = 0
if isfile(dataobject.fnames.hydro_descriptor)
descriptor_file = true
f = open(dataobject.fnames.hydro_descriptor)
lines = readlines(f)
# check for descriptor version
if occursin("nvar", String(lines[1])) # =< stable_17_09
version = 0
elseif occursin("version", String(lines[1])) # > stable_17_09
version = parse(Int, rsplit(lines[1], ":" )[2])
end
# read descriptor variables
if version == 0
dnvar = parse(Int, rsplit(lines[1],"=")[2] )
for i = 1:dnvar
ivar = String(rsplit(lines[i+1], ":" )[2])
ivar = strip(ivar)
append!(variable_descriptor_list, [Symbol(ivar)])
end
elseif version == 1
dnvar = length(lines)
for i = 3:dnvar
ivar = String(rsplit(lines[i], "," )[2])
itype = String(rsplit(lines[i], "," )[3])
ivar = strip(ivar)
itype = strip(itype)
append!(variable_descriptor_list, [Symbol(ivar)])
append!(variable_types, [itype])
end
else
# version not supported,
# descriptor variables not read
end
close(f)
end
#read header from first cpu file
hydro_files = false
nvarh = 0
variable_list = Symbol[]
if isfile(dataobject.fnames.hydro * "out00001")
f_hydro = FortranFile(dataobject.fnames.hydro * "out00001")
skiplines(f_hydro, 1)
nvarh = read(f_hydro, Int32)
skiplines(f_hydro, 3)
###skiplines(f_hydro, 3)
dataobject.gamma = read(f_hydro, Float64)
close(f_hydro)
variable_list = [:rho,:vx,:vy,:vz,:p]
if nvarh > 5
for ivar=6:nvarh
append!(variable_list, [Symbol("var$ivar")])
end
end
hydro_files = true
end
if !isfile(dataobject.fnames.hydro_descriptor)
variable_descriptor_list = variable_list
end
dataobject.hydro = hydro_files
dataobject.nvarh = nvarh
dataobject.variable_list = variable_list
# descriptor
dataobject.descriptor.hversion = version
dataobject.descriptor.hydro = variable_descriptor_list
dataobject.descriptor.htypes = variable_types
dataobject.descriptor.usehydro = false
dataobject.descriptor.hydrofile = descriptor_file
return dataobject
end
# in work
function readrtfile1!(dataobject::InfoType)
# read descriptor file
descriptor_file = false
rtPhotonGroups = Dict()
descriptor_list= Dict()
version = 0
if isfile(dataobject.fnames.rt_descriptor)
version = 1
descriptor_file = true
elseif isfile(dataobject.fnames.rt_descriptor_v0)
descriptor_file = true
end
if descriptor_file
if version == 0
f = open(dataobject.fnames.rt_descriptor_v0)
elseif version == 1
f = open(dataobject.fnames.rt_descriptor)
end
lines = readlines(f)
if length(lines) != 0 # check for empty file
# read descriptor variables
descriptor_list[Symbol("nRTvar")] = parse(Int, rsplit(lines[1],"=")[2] )
descriptor_list[Symbol("nIons")] = parse(Int, rsplit(lines[2],"=")[2] )
descriptor_list[Symbol("nGroups")] = parse(Int, rsplit(lines[3],"=")[2] )
descriptor_list[Symbol("iIons")] = parse(Int, rsplit(lines[4],"=")[2] )
descriptor_list[Symbol("X_fraction")] = parse(Float64, rsplit(lines[6],"=")[2] )
descriptor_list[Symbol("Y_fraction")] = parse(Float64, rsplit(lines[7],"=")[2] )
descriptor_list[Symbol("unit_np")] = parse(Float64, rsplit(lines[9],"=")[2] )
descriptor_list[Symbol("unit_pf")] = parse(Float64, rsplit(lines[10],"=")[2] )
descriptor_list[Symbol("rt_c_frac")] = parse(Float64, rsplit(lines[11],"=")[2] )
descriptor_list[Symbol("n_star")] = parse(Float64, rsplit(lines[13],"=")[2] )
descriptor_list[Symbol("T2_star")] = parse(Float64, rsplit(lines[14],"=")[2] )
descriptor_list[Symbol("g_star")] = parse(Float64, rsplit(lines[15],"=")[2] )
#todo read photon groups
#rtPhotonGroups
else # if file is empty
descriptor_file = false
end
end
#read header from first cpu file
rt_files = false
nvarrt = 0
if isfile(dataobject.fnames.rt * "out00001")
rt_files = true
f_rt = FortranFile(dataobject.fnames.rt * "out00001")
skiplines(f_rt, 1)
nvarrt = read(f_rt, Int32)
skiplines(f_rt, 3)
#println(read(f_rt, Float64)) # gamma
close(f_rt)
end
dataobject.rt = rt_files
dataobject.nvarrt = nvarrt
dataobject.rt_variable_list = Symbol[]
# descriptor
dataobject.descriptor.rtversion = version
dataobject.descriptor.rt = descriptor_list
dataobject.descriptor.rtPhotonGroups = rtPhotonGroups
dataobject.descriptor.usert = false
dataobject.descriptor.rtfile = descriptor_file
return dataobject
end
function isgravityfile1!(dataobject::InfoType)
grav_files = false
# grav file of first cpu
if isfile(dataobject.fnames.gravity * "out00001")
grav_files = true
end
dataobject.gravity = grav_files
dataobject.gravity_variable_list = [:epot,:ax,:ay,:az]
# descriptor
dataobject.descriptor.gravity = [:epot,:ax,:ay,:az]
dataobject.descriptor.usegravity = false
dataobject.descriptor.gravityfile = false
return dataobject
end
# todo: introduce new RAMSES version
function readparticlesfile1!(dataobject::InfoType)
Npart = 0
Ndm = 0
Nstars = 0
Nsinks = 0
other_tracer1 = 0
debris_tracer = 0
cloud_tracer = 0
star_tracer = 0
other_tracer2 = 0
gas_tracer = 0
Ncloud = 0
Ndebris = 0
Nother = 0
Nundefined = 0
part_files = false
part_header = false
version=0
if isfile(dataobject.fnames.particles * "out00001")
part_files = true
if isfile(dataobject.fnames.header)
part_header = true
f = open(dataobject.fnames.header)
line = readline(f)
# check for header version
if occursin("Total", String(line)) # =< stable_18_09
version = 0
elseif occursin("Family", String(line)) # > stable_18_09
version = 1
else
version =-1
end
if version == 0
Npart = parse(Int, readline(f) )
line = readline(f)
Ndm = parse(Int, readline(f) )
line = readline(f)
Nstars = parse(Int, readline(f) )
line = readline(f)
Nsinks = parse(Int, readline(f) )
elseif version == 1
other_tracer1 = parse(Int, rsplit(readline(f))[2] )
debris_tracer = parse(Int, rsplit(readline(f))[2] )
cloud_tracer = parse(Int, rsplit(readline(f))[2] )
star_tracer = parse(Int, rsplit(readline(f))[2] )
other_tracer2 = parse(Int, rsplit(readline(f))[2] )
gas_tracer = parse(Int, rsplit(readline(f))[2] )
Ndm = parse(Int, rsplit(readline(f))[2] )
Nstars = parse(Int, rsplit(readline(f))[2] )
Ncloud = parse(Int, rsplit(readline(f))[2] )
Ndebris = parse(Int, rsplit(readline(f))[2] )
Nother = parse(Int, rsplit(readline(f))[2] )
Nundefined = parse(Int, rsplit(readline(f))[2] )
end
close(f)
#if Npart != 0
# part_files = true
#end
end
end
dataobject.part_info = PartInfoType()
dataobject.part_info.eta_sn = 0.
dataobject.part_info.age_sn = 10. / dataobject.scale.Myr
dataobject.part_info.f_w = 0.
# overwrite some default parameters from namelist file
if dataobject.namelist
keylist_header = keys(dataobject.namelist_content)
for i in keylist_header
icontent = dataobject.namelist_content[i]
keylist_parameters = keys(icontent)
for j in keylist_parameters
if j == "eta_sn"
dataobject.part_info.eta_sn = parse(Float64,icontent[j])
elseif j == "age_sn"
dataobject.part_info.age_sn = parse(Float64,icontent[j])
elseif j == "f_w"
dataobject.part_info.f_w = parse(Float64,icontent[j])
end
end
end
end
# read descriptor file
descriptor_file = false
variable_descriptor_list = Symbol[]
variable_types = String[]
dnvar = 0
version = 0
if isfile(dataobject.fnames.part_descriptor)
descriptor_file = true
f = open(dataobject.fnames.part_descriptor)
lines = readlines(f)
# read descriptor version # > stable_18_09
version = parse(Int, rsplit(lines[1], ":" )[2])
# read descriptor variables
if version == 1
dnvar = length(lines)
for i = 3:dnvar
ivar = String(rsplit(lines[i], "," )[2])
itype = String(rsplit(lines[i], "," )[3])
ivar = strip(ivar)
itype = strip(itype)
append!(variable_descriptor_list, [Symbol(ivar)])
append!(variable_types, [itype])
end
else
# version not supported,
# descriptor variables not read
end
close(f)
end
dataobject.nvarp = 5
if version <= 0
dataobject.particles_variable_list=[:vx, :vy, :vz, :mass, :birth]
else
if in(:metallicity, variable_descriptor_list)
pre_variable_list = [:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z,
:mass, :identity, :levelp, :birth_time, :metallicity, :family, :tag]
addvar_index = Int[]
for (i,ival) in enumerate(variable_descriptor_list)
if !in(ival, pre_variable_list)
append!(addvar_index, [i])
end
end
particles_variable_list=[:vx, :vy, :vz, :mass, :family, :tag, :birth, :metals]
if length(addvar_index) != 0
addvar = variable_descriptor_list[addvar_index]
append!(particles_variable_list, addvar)
end
dataobject.particles_variable_list=particles_variable_list
dataobject.nvarp = length(particles_variable_list)
else
dataobject.particles_variable_list=[:vx, :vy, :vz, :mass, :family, :tag, :birth]
dataobject.nvarp = 7
end
# todo: automatic detection of more variables
#if (dnvar-3) > dataobject.nvarp + 7 # variables + (id,x,y,z,level,family,tag)
# for invar = (dataobject.nvarp+7):(dnvar-3)
# icount = invar - 3
# append!(dataobject.particles_variable_list, [Symbol("var$icount")])
# dataobject.nvarp = dataobject.nvarp + 1
# end
#end
end
dataobject.part_info.Npart = Npart
dataobject.part_info.Ndm = Ndm
dataobject.part_info.Nstars = Nstars
dataobject.part_info.Nsinks = Nsinks
dataobject.part_info.Ncloud = Ncloud
dataobject.part_info.Ndebris = Ndebris
dataobject.part_info.Nother = Nother
dataobject.part_info.Nundefined = Nundefined
dataobject.part_info.other_tracer1 = other_tracer1
dataobject.part_info.debris_tracer = debris_tracer
dataobject.part_info.cloud_tracer = cloud_tracer
dataobject.part_info.star_tracer = star_tracer
dataobject.part_info.other_tracer2 = other_tracer2
dataobject.part_info.gas_tracer = gas_tracer
dataobject.particles = part_files
dataobject.headerfile = part_header
dataobject.descriptor.pversion = version
if version == 0
dataobject.descriptor.particles = dataobject.particles_variable_list
dataobject.descriptor.ptypes = String[]
elseif version > 0
dataobject.descriptor.particles = variable_descriptor_list
dataobject.descriptor.ptypes = variable_types
end
dataobject.descriptor.useparticles=false
dataobject.descriptor.particlesfile=descriptor_file
return dataobject
end
function readnamelistfile!(dataobject::InfoType)
namelist_file = false
asciifile = false
namelist = Dict()
variables = Dict()
if isfile(dataobject.fnames.namelist)
f = open(dataobject.fnames.namelist )
lines = readlines(f)
#check for ASCII content
for i in lines
if occursin("&RUN_PARAMS", i)
asciifile = true
namelist_file = true
end
end
if asciifile
iheader = "false"
Nlines = length(lines)
for (j,i) in enumerate(lines)
if iheader != "false"
if occursin("=", i)
variable = String(rsplit(i, "=" )[1])
content = String(rsplit(i, "=" )[2])
variables[variable] = content
end
end
if occursin("&", i) || j == Nlines
if iheader != "false"
namelist[iheader]= variables
variables = Dict()
end
iheader = i
end
end
end
end
dataobject.namelist = namelist_file
dataobject.namelist_content = namelist
return dataobject
end
function readclumpfile1!(dataobject::InfoType)
# clump file of first cpu
clump_files = false
header= Symbol[]
if isfile(dataobject.fnames.clumps * "txt00001")
clump_files = true
header, NColumns = getclumpvariables(dataobject, [:all], dataobject.fnames)
end
dataobject.clumps = clump_files
dataobject.clumps_variable_list = header
# descriptor
dataobject.descriptor.clumps = header
dataobject.descriptor.useclumps = false
dataobject.descriptor.clumpsfile = false
return dataobject
end
function readtimerfile!(dataobject::InfoType)
timer_file = false
dataobject.files_content.timerfile = [""]
if isfile(dataobject.fnames.timer )
timer_file = true
f = open(dataobject.fnames.timer);
dataobject.files_content.timerfile = readlines(f)
end
dataobject.timerfile = timer_file
return dataobject
end
function readcompilationfile!(dataobject::InfoType)
compilation_file = false
compile_date = ""
patch_dir = ""
remote_repo = ""
local_branch= ""
last_commit= ""
if isfile(dataobject.fnames.compilation )
compilation_file = true
f = open(dataobject.fnames.compilation )
lines = readlines(f)
if !occursin("\0", String(rsplit(lines[1], "=" )[2])) # skip embedded NULs
compile_date = String(rsplit(lines[1], "=" )[2])
patch_dir = String(rsplit(lines[2], "=" )[2])
remote_repo = String(rsplit(lines[3], "=" )[2])
local_branch = String(rsplit(lines[4], "=" )[2])
last_commit = String(rsplit(lines[5], "=" )[2])
end
close(f)
end
dataobject.compilation = CompilationInfoType() #"", "" ,"" , "", "" )
dataobject.compilation.compile_date = compile_date
dataobject.compilation.patch_dir = patch_dir
dataobject.compilation.remote_repo = remote_repo
dataobject.compilation.local_branch= local_branch
dataobject.compilation.last_commit= last_commit
dataobject.compilationfile = compilation_file
return dataobject
end
function readmakefile!(dataobject::InfoType)
make_file = false
dataobject.files_content.makefile = [""]
if isfile(dataobject.fnames.makefile)
make_file = true
f = open(dataobject.fnames.makefile);
dataobject.files_content.makefile = readlines(f)
end
dataobject.makefile = make_file
return dataobject
end
function readpatchfile!(dataobject::InfoType)
patch_file = false
dataobject.files_content.patchfile = [""]
if isfile(dataobject.fnames.patchfile)
patch_file = true
f = open(dataobject.fnames.patchfile);
dataobject.files_content.patchfile = readlines(f)
end
dataobject.patchfile = patch_file
return dataobject
end
function printsimoverview(info::InfoType, verbose::Bool)
if verbose
println("Code: ", info.simcode)
println("output [$(info.output)] summary:")
println("mtime: ", info.mtime)
println("ctime: ", info.ctime)
printstyled("=======================================================\n", bold=true, color=:normal)
time_val, time_unit = humanize(info.time, info.scale, 2, "time")
println("simulation time: ", time_val, " [$time_unit]")
boxlen_val, boxlen_unit = humanize(info.boxlen, info.scale, 2, "length")
println("boxlen: ", boxlen_val, " [$boxlen_unit]")
println("ncpu: ", info.ncpu)
println("ndim: ", info.ndim)
println("-------------------------------------------------------")
min_cellsize, min_unit = humanize(info.boxlen / 2^info.levelmin, info.scale, 2, "length")
max_cellsize, max_unit = humanize(info.boxlen / 2^info.levelmax, info.scale, 2, "length")
println("amr: ", info.amr)
if info.levelmin != info.levelmax # if AMR
println("level(s): ", info.levelmin, " - ", info.levelmax, " --> cellsize(s): ", min_cellsize ," [$min_unit]", " - ", max_cellsize," [$max_unit]")
else
println("level of uniform grid: ", info.levelmax, " --> cellsize(s): ", max_cellsize," [$max_unit]")
end
if info.hydro
println("-------------------------------------------------------")
else
println()
end
println("hydro: ", info.hydro)
if info.hydro
println("hydro-variables: ", info.nvarh, " --> ", tuple(info.variable_list...) )
if info.descriptor.hydrofile
println("hydro-descriptor: ", tuple(info.descriptor.hydro...) )
end
println("γ: ", info.gamma)
end
if info.gravity
println("-------------------------------------------------------")
end
println("gravity: ", info.gravity)
if info.gravity
println("gravity-variables: ", tuple(info.gravity_variable_list...))
end
if info.particles
println("-------------------------------------------------------")
end
print("particles: ", info.particles)
if info.particles
if info.headerfile == false
print(" (no particle header file) \n")
else
print("\n")
if info.part_info.other_tracer1 != 0 @printf "- other_tracer1: %e \n" info.part_info.other_tracer1 end
if info.part_info.debris_tracer != 0 @printf "- debris_tracer: %e \n" info.part_info.debris_tracer end
if info.part_info.cloud_tracer != 0 @printf "- cloud_tracer: %e \n" info.part_info.cloud_tracer end
if info.part_info.star_tracer != 0 @printf "- star_tracer: %e \n" info.part_info.star_tracer end
if info.part_info.other_tracer2 != 0 @printf "- other_tracer2: %e \n" info.part_info.other_tracer2 end
if info.part_info.gas_tracer != 0 @printf "- gas_tracer: %e \n" info.part_info.gas_tracer end
if info.part_info.Npart != 0 @printf "- Npart: %e \n" info.part_info.Npart end
if info.part_info.Nstars != 0 @printf "- Nstars: %e \n" info.part_info.Nstars end
if info.part_info.Ndm != 0 @printf "- Ndm: %e \n" info.part_info.Ndm end
if info.part_info.Nsinks != 0 @printf "- Nsinks: %e \n" info.part_info.Nsinks end
if info.part_info.Ncloud != 0 @printf "- Ncloud: %e \n" info.part_info.Ncloud end
if info.part_info.Ndebris != 0 @printf "- Ndebris: %e \n" info.part_info.Ndebris end
if info.part_info.Nother != 0 @printf "- Nother: %e \n" info.part_info.Nother end
if info.part_info.Nundefined != 0 @printf "- Nundefined: %e \n" info.part_info.Nundefined end
end
else
print("\n")
end
if info.particles
println("particle-variables: ", info.nvarp, " --> ", tuple(info.particles_variable_list...) )
if info.descriptor.particlesfile
println("particle-descriptor: ", tuple(info.descriptor.particles...) )
end
if !info.rt
println("-------------------------------------------------------")
end
end
if info.rt
println("-------------------------------------------------------")
end
println("rt: ", info.rt)
if info.rt
println("rt-variables: ", info.nvarrt)
if info.descriptor.rtfile
#println("nRTvar: ", info.descriptor.rt[:nRTvar] )
println("nIons: ", info.descriptor.rt[:nIons] )
println("nGroups: ", info.descriptor.rt[:nGroups] )
println("iIons: ", info.descriptor.rt[:iIons] )
end
if !info.clumps
println("-------------------------------------------------------")
end
end
if info.clumps
println("-------------------------------------------------------")
end
println("clumps: ", info.clumps)
if info.clumps
println("clump-variables: ", tuple(info.clumps_variable_list...) )
println("-------------------------------------------------------")
end
if info.namelist
if !info.clumps
println("-------------------------------------------------------")
end
println("namelist-file: ", tuple(keys(info.namelist_content)...) )
println("-------------------------------------------------------")
else
println("namelist-file: ", info.namelist)
end
println("timer-file: ", info.timerfile)
println("compilation-file: ", info.compilationfile)
println("makefile: ", info.makefile)
println("patchfile: ", info.patchfile)
#println("nx, ny, nz: ", overview.nx, ", ", overview.ny, ", ",overview.nz)
#println("infofile creation-time: ", DateTime(ctime) ) #todo: format
#println("infofile modification-time: ", DateTime(mtime) ) #todo: format
printstyled("=======================================================\n", bold=true, color=:normal)
println()
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 22085 | """
#### Read the particle-data
- select variables
- limit to a maximum range
- print the name of each data-file before reading it
- toggle verbose mode
- toggle progress bar
- pass a struct with arguments (myargs)
```julia
getparticles( dataobject::InfoType;
lmax::Real=dataobject.levelmax,
vars::Array{Symbol,1}=[:all],
stars::Bool=true,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
presorted::Bool=true,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
```
#### Returns an object of type PartDataType, containing the particle-data table, the selected and the simulation ScaleType and summary of the InfoType
```julia
return PartDataType()
# get an overview of the returned fields:
# e.g.:
julia> info = getinfo(100)
julia> particles = getparticles(info)
julia> viewfields(particles)
#or:
julia> fieldnames(particles)
```
#### Arguments
##### Required:
- **`dataobject`:** needs to be of type: "InfoType", created by the function *getinfo*
##### Predefined/Optional Keywords:
- **`lmax`:** not defined
- **`stars`:** not defined
- **`var(s)`:** the selected particle variables in arbitrary order: :all (default), :cpu, :mass, :vx, :vy, :vz, :birth :metals, ...
- **`xrange`:** the range between [xmin, xmax] in units given by argument `range_unit` and relative to the given `center`; zero length for xmin=xmax=0. is converted to maximum possible length
- **`yrange`:** the range between [ymin, ymax] in units given by argument `range_unit` and relative to the given `center`; zero length for ymin=ymax=0. is converted to maximum possible length
- **`zrange`:** the range between [zmin, zmax] in units given by argument `range_unit` and relative to the given `center`; zero length for zmin=zmax=0. is converted to maximum possible length
- **`range_unit`:** the units of the given ranges: :standard (code units), :Mpc, :kpc, :pc, :mpc, :ly, :au , :km, :cm (of typye Symbol) ..etc. ; see for defined length-scales viewfields(info.scale)
- **`center`:** in units given by argument `range_unit`; by default [0., 0., 0.]; the box-center can be selected by e.g. [:bc], [:boxcenter], [value, :bc, :bc], etc..
- **`presorted`:** presort data according to the key vars (by default)
- **`print_filenames`:** print on screen the current processed particle file of each CPU
- **`verbose`:** print timestamp, selected vars and ranges on screen; default: true
- **`show_progress`:** print progress bar on screen
- **`myargs`:** pass a struct of ArgumentsType to pass several arguments at once and to overwrite default values of lmax not!, xrange, yrange, zrange, center, range_unit, verbose, show_progress
### Defined Methods - function defined for different arguments
- getparticles( dataobject::InfoType; ...) # no given variables -> all variables loaded
- getparticles( dataobject::InfoType, var::Symbol; ...) # one given variable -> no array needed
- getparticles( dataobject::InfoType, vars::Array{Symbol,1}; ...) # several given variables -> array needed
#### Examples
```julia
# read simulation information
julia> info = getinfo(420)
# Example 1:
# read particle data of all variables, full-box, all levels
julia> particles = getparticles(info)
# Example 2:
# read particle data of all variables
# data range 20x20x4 kpc; ranges are given in kpc relative to the box (here: 48 kpc) center at 24 kpc
julia> particles = getparticles( info,
xrange=[-10., 10.],
yrange=[-10., 10.],
zrange=[-2., 2.],
center=[24., 24., 24.],
range_unit=:kpc )
# Example 3:
# give the center of the box by simply passing: center = [:bc] or center = [:boxcenter]
# this is equivalent to center=[24.,24.,24.] in Example 2
# the following combination is also possible: e.g. center=[:bc, 12., 34.], etc.
julia> particles = getparticles( info,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[33., bc:, 10.],
range_unit=:kpc )
# Example 4:
# read particle data of the variables mass and the birth-time, full-box, all levels
julia> particles = getparticles( info, [:mass, :birth] ) # use array for the variables
# Example 5:
# read particle data of the single variable mass, full-box, all levels
julia> particles = getparticles( info, :mass ) # no array for a single variable needed
...
```
"""
function getparticles( dataobject::InfoType, var::Symbol;
lmax::Real=dataobject.levelmax,
stars::Bool=true,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
presorted::Bool=true,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return getparticles( dataobject, vars=[var],
lmax=lmax,
stars=stars,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
presorted=presorted,
print_filenames=print_filenames,
verbose=verbose,
show_progress=show_progress,
myargs=myargs )
end
function getparticles( dataobject::InfoType, vars::Array{Symbol,1};
lmax::Real=dataobject.levelmax,
stars::Bool=true,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
presorted::Bool=true,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
return getparticles( dataobject, vars=vars,
lmax=lmax,
stars=stars,
xrange=xrange,
yrange=yrange,
zrange=zrange,
center=center,
range_unit=range_unit,
presorted=presorted,
print_filenames=print_filenames,
verbose=verbose,
show_progress=show_progress,
myargs=myargs )
end
function getparticles( dataobject::InfoType;
lmax::Real=dataobject.levelmax,
vars::Array{Symbol,1}=[:all],
stars::Bool=true,
xrange::Array{<:Any,1}=[missing, missing],
yrange::Array{<:Any,1}=[missing, missing],
zrange::Array{<:Any,1}=[missing, missing],
center::Array{<:Any,1}=[0., 0., 0.],
range_unit::Symbol=:standard,
presorted::Bool=true,
print_filenames::Bool=false,
verbose::Bool=true,
show_progress::Bool=true,
myargs::ArgumentsType=ArgumentsType() )
# take values from myargs if given
if !(myargs.lmax === missing) lmax = myargs.lmax end
if !(myargs.xrange === missing) xrange = myargs.xrange end
if !(myargs.yrange === missing) yrange = myargs.yrange end
if !(myargs.zrange === missing) zrange = myargs.zrange end
if !(myargs.center === missing) center = myargs.center end
if !(myargs.range_unit === missing) range_unit = myargs.range_unit end
if !(myargs.verbose === missing) verbose = myargs.verbose end
if !(myargs.show_progress === missing) show_progress = myargs.show_progress end
verbose = checkverbose(verbose)
printtime("Get particle data: ", verbose)
checkfortype(dataobject, :particles)
#Todo: limit to a given lmax
lmax=dataobject.levelmax # overwrite given lmax
#checklevelmax(dataobject, lmax)
isamr = checkuniformgrid(dataobject, lmax)
#time = dataobject.time
# create variabe-list and vector-mask (nvarh_corr) for getparticledata-function
# print selected variables on screen
nvarp_list, nvarp_i_list, nvarp_corr, read_cpu, used_descriptors = prepvariablelist(dataobject, :particles, vars, lmax, verbose)
# convert given ranges and print overview on screen
ranges = prepranges(dataobject, range_unit, verbose, xrange, yrange, zrange, center)
# read particle-data of the selected variables
if read_cpu
if dataobject.descriptor.pversion == 0
pos_1D, vars_1D, cpus_1D, identity_1D, levels_1D = getparticledata( dataobject, length(nvarp_list), nvarp_corr, stars, lmax, ranges,
print_filenames, show_progress, verbose, read_cpu)
elseif dataobject.descriptor.pversion > 0
pos_1D, vars_1D, cpus_1D, identity_1D, family_1D, tag_1D, levels_1D = getparticledata( dataobject, length(nvarp_list), nvarp_corr, stars, lmax, ranges,
print_filenames, show_progress, verbose, read_cpu)
end
else
if dataobject.descriptor.pversion == 0
pos_1D, vars_1D, identity_1D, levels_1D = getparticledata( dataobject, length(nvarp_list), nvarp_corr, stars, lmax, ranges,
print_filenames, show_progress, verbose, read_cpu)
elseif dataobject.descriptor.pversion > 0
pos_1D, vars_1D, identity_1D, family_1D, tag_1D, levels_1D = getparticledata( dataobject, length(nvarp_list), nvarp_corr, stars, lmax, ranges,
print_filenames, show_progress, verbose, read_cpu)
end
end
if verbose
@printf "Found %e particles\n" size(pos_1D)[2]
end
# prepare column names for the data table
names_constr = preptablenames_particles(dataobject, dataobject.nvarp, nvarp_list, used_descriptors, read_cpu, lmax, dataobject.levelmin)
if lmax != dataobject.levelmin # if AMR
if dataobject.descriptor.pversion == 0
Nkeys = [:level, :x, :y, :z, :id]
elseif dataobject.descriptor.pversion > 0
Nkeys = [:level, :x, :y, :z, :id, :family, :tag]
end
else # if uniform grid
if dataobject.descriptor.pversion == 0
Nkeys = [:x, :y, :z, :id]
elseif dataobject.descriptor.pversion > 0
Nkeys = [:x, :y, :z, :id, :family, :tag]
end
end
# create data table
# decouple pos_1D/vars_1D from ElasticArray with ElasticArray.data
if read_cpu # read also cpu number related to particle
if isamr
if dataobject.descriptor.pversion == 0
if presorted
@inbounds data = table( levels_1D[:],
pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], cpus_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), pkey=collect(Nkeys), presorted = false )
else
@inbounds data = table( levels_1D[:],
pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], cpus_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), presorted = false )
end
elseif dataobject.descriptor.pversion > 0
filter!(x->x≠6,nvarp_i_list)
filter!(x->x≠5,nvarp_i_list)
if presorted
@inbounds data = table( levels_1D[:],
pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], family_1D[:], tag_1D[:], cpus_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), pkey=collect(Nkeys), presorted = false )
else
@inbounds data = table( levels_1D[:],
pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], family_1D[:], tag_1D[:], cpus_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), presorted = false )
end
end
else # if uniform grid
if dataobject.descriptor.pversion == 0
if presorted
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], cpus_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), pkey=collect(Nkeys), presorted = false )
else
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], cpus_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), presorted = false )
end
elseif dataobject.descriptor.pversion > 0
filter!(x->x≠6,nvarp_i_list)
filter!(x->x≠5,nvarp_i_list)
if presorted
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], family_1D[:], tag_1D[:], cpus_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), pkey=collect(Nkeys), presorted = false )
else
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], family_1D[:], tag_1D[:], cpus_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), presorted = false )
end
end
end
else
if isamr
if dataobject.descriptor.pversion == 0
if presorted
@inbounds data = table( levels_1D[:],
pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), pkey=collect(Nkeys), presorted = false )
else
@inbounds data = table( levels_1D[:],
pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), presorted = false )
end
elseif dataobject.descriptor.pversion > 0
filter!(x->x≠6,nvarp_i_list)
filter!(x->x≠5,nvarp_i_list)
if presorted
@inbounds data = table( levels_1D[:],
pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], family_1D[:], tag_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), pkey=collect(Nkeys), presorted = false )
else
@inbounds data = table( levels_1D[:],
pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], family_1D[:], tag_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), presorted = false )
end
end
else # if uniform grid
if dataobject.descriptor.pversion == 0
if presorted
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), pkey=collect(Nkeys), presorted = false )
else
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), presorted = false )
end
elseif dataobject.descriptor.pversion > 0
filter!(x->x≠6,nvarp_i_list)
filter!(x->x≠5,nvarp_i_list)
if presorted
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], family_1D[:], tag_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), pkey=collect(Nkeys), presorted = false )
else
@inbounds data = table(pos_1D[1,:].data, pos_1D[2,:].data, pos_1D[3,:].data, identity_1D[:], family_1D[:], tag_1D[:],
[vars_1D[ nvarp_corr[i],: ].data for i in nvarp_i_list]...,
names=collect(names_constr), presorted = false )
end
end
end
end
printtablememory(data, verbose)
partdata = PartDataType()
partdata.data = data
partdata.info = dataobject
partdata.lmin = dataobject.levelmin
partdata.lmax = lmax
partdata.boxlen = dataobject.boxlen
partdata.ranges = ranges
partdata.selected_partvars = names_constr
partdata.used_descriptors = used_descriptors
partdata.scale = dataobject.scale
return partdata
end
function preptablenames_particles(dataobject::InfoType, nvarp::Int, nvarp_list::Array{Int, 1}, used_descriptors::Dict{Any,Any}, read_cpu::Bool, lmax::Real, levelmin::Real)
if read_cpu
if lmax != levelmin # if AMR
if dataobject.descriptor.pversion == 0
names_constr = [:level, :x, :y, :z, :id, :cpu]
elseif dataobject.descriptor.pversion > 0
names_constr = [:level, :x, :y, :z, :id, :family, :tag, :cpu]
end
else # if uniform grid
if dataobject.descriptor.pversion == 0
names_constr = [:x, :y, :z, :id, :cpu]
elseif dataobject.descriptor.pversion > 0
names_constr = [:x, :y, :z, :id, :family, :tag, :cpu]
end
end
#, Symbol("x"), Symbol("y"), Symbol("z")
else
if lmax != levelmin # if AMR
if dataobject.descriptor.pversion == 0
names_constr = [:level, :x, :y, :z, :id]
elseif dataobject.descriptor.pversion > 0
names_constr = [:level, :x, :y, :z, :id, :family, :tag]
end
else # if uniform grid
if dataobject.descriptor.pversion == 0
names_constr = [:x, :y, :z, :id]
elseif dataobject.descriptor.pversion > 0
names_constr = [:x, :y, :z, :id, :family, :tag]
end
end
end
for i=1:nvarp
if in(i, nvarp_list)
#if length(used_descriptors) == 0 || !haskey(used_descriptors, i)
if dataobject.descriptor.pversion == 0
if i == 1
append!(names_constr, [Symbol("vx")] )
elseif i == 2
append!(names_constr, [Symbol("vy")] )
elseif i == 3
append!(names_constr, [Symbol("vz")] )
elseif i == 4
append!(names_constr, [Symbol("mass")] )
elseif i == 5
append!(names_constr, [Symbol("birth")] )
elseif i > 5
append!(names_constr, [Symbol("var$i")] )
end
elseif dataobject.descriptor.pversion > 0
if i == 1
append!(names_constr, [Symbol("vx")] )
elseif i == 2
append!(names_constr, [Symbol("vy")] )
elseif i == 3
append!(names_constr, [Symbol("vz")] )
elseif i == 4
append!(names_constr, [Symbol("mass")] )
elseif i == 7
append!(names_constr, [Symbol("birth")] )
elseif i == 8
append!(names_constr, [Symbol("metals")] )
elseif i > 8
append!(names_constr, [Symbol("var$i")] )
end
end
#else append!(names_constr, [used_descriptors[i]] )
#end
end
end
return names_constr
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2828 | function btest(i::Int,pos::Int)
return (((i)>>(pos)) & 1) == 1
end
function hilbert3d(x::Int,y::Int,z::Int,bit_length::Int,npoint::Int)
state_diagram = [ 1, 2, 3, 2, 4, 5, 3, 5,
0, 1, 3, 2, 7, 6, 4, 5,
2, 6, 0, 7, 8, 8, 0, 7,
0, 7, 1, 6, 3, 4, 2, 5,
0, 9,10, 9, 1, 1,11,11,
0, 3, 7, 4, 1, 2, 6, 5,
6, 0, 6,11, 9, 0, 9, 8,
2, 3, 1, 0, 5, 4, 6, 7,
11,11, 0, 7, 5, 9, 0, 7,
4, 3, 5, 2, 7, 0, 6, 1,
4, 4, 8, 8, 0, 6,10, 6,
6, 5, 1, 2, 7, 4, 0, 3,
5, 7, 5, 3, 1, 1,11,11,
4, 7, 3, 0, 5, 6, 2, 1,
6, 1, 6,10, 9, 4, 9,10,
6, 7, 5, 4, 1, 0, 2, 3,
10, 3, 1, 1,10, 3, 5, 9,
2, 5, 3, 4, 1, 6, 0, 7,
4, 4, 8, 8, 2, 7, 2, 3,
2, 1, 5, 6, 3, 0, 4, 7,
7, 2,11, 2, 7, 5, 8, 5,
4, 5, 7, 6, 3, 2, 0, 1,
10, 3, 2, 6,10, 3, 4, 4,
6, 1, 7, 0, 5, 2, 4, 3 ]
state_diagram = reshape(state_diagram, 8 ,2, 12)
x_bit_mask = falses(bit_length)
y_bit_mask = falses(bit_length)
z_bit_mask = falses(bit_length)
i_bit_mask = falses(3*bit_length)
order=0. #zeros(npoint); npoint=1, therefore no array
#for ip=1:npoint
# convert to binary
for i=1:bit_length
x_bit_mask[i]=btest(x,i-1)
y_bit_mask[i]=btest(y,i-1)
z_bit_mask[i]=btest(z,i-1)
end
# interleave bits
for i=0:(bit_length-1)
i_bit_mask[3*i+2+1]=x_bit_mask[i+1]
i_bit_mask[3*i+1+1]=y_bit_mask[i+1]
i_bit_mask[3*i+1]=z_bit_mask[i+1]
end
# build Hilbert ordering using state diagram
cstate=0
staterange = range(bit_length-1, stop=0, step=-1)
for i in staterange
#println(i)
if i_bit_mask[3*i+2+1] b2=1 else b2=0 end
if i_bit_mask[3*i+1+1] b1=1 else b1=0 end
if i_bit_mask[3*i+1] b0=1 else b0=0 end
sdigit=b2*4+b1*2+b0
nstate=state_diagram[sdigit+1,1,cstate+1]
hdigit=state_diagram[sdigit+1,2,cstate+1]
#println("nstate: ", nstate)
#println("hdigit: ", hdigit)
i_bit_mask[3*i+2+1]=btest(hdigit,2)
i_bit_mask[3*i+1+1]=btest(hdigit,1)
i_bit_mask[3*i+1] =btest(hdigit,0)
#println("i_bit_mask: ", i_bit_mask[3*i+2+1])
#println("i_bit_mask: ", i_bit_mask[3*i+1+1])
#println("i_bit_mask: ", i_bit_mask[3*i+1])
cstate=nstate
end
# save Hilbert key as double precision real
#order[ip]=0.
order=0. #zeros(npoint); npoint=1, therefore no array
for i=1:(3*bit_length)
if i_bit_mask[i] b0=1 else b0=0 end
#order[ip]=order[ip]+b0*2^i
order=order+b0*2^(i-1)
#println(i-1, " ", order[ip])
end
#end
return order
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 17314 | function prepvariablelist(dataobject::InfoType, datatype::Symbol, vars::Array{Symbol,1}, lmax::Real, verbose::Bool)
if datatype == :hydro
nvarh = dataobject.nvarh
# manage user selected variables
#-------------------------------------
nvarh_list=Int[]
ivar=1
read_cpu = false # do not load cpu number by default
hydrovar_buffer = copy(vars)
used_descriptors = Dict()
if in(:all, hydrovar_buffer) #hydrovar_buffer == [:all]
nvarh_list=[1,2,3,4,5]
# read_cpu = true
if in(:cpu, hydrovar_buffer) || in(:varn1, hydrovar_buffer)
read_cpu = true
end
if nvarh > 5
for ivar=6:nvarh
append!(nvarh_list, [ivar])
end
end
#if dataobject.descriptor.usehydro == true
# for (i,idvar) in enumerate(dataobject.descriptor.hydro)
# used_descriptors[i] = idvar
# end
#end
else
if in(:cpu, hydrovar_buffer) || in(:varn1, hydrovar_buffer)
read_cpu = true
filter!(e->e≠:cpu, hydrovar_buffer)
filter!(e->e≠:varn1, hydrovar_buffer)
end
if in(:rho, hydrovar_buffer) || in(:var1, hydrovar_buffer)
append!(nvarh_list, 1)
filter!(e->e≠:rho, hydrovar_buffer)
filter!(e->e≠:var1, hydrovar_buffer)
end
if in(:vx, hydrovar_buffer) || in(:var2, hydrovar_buffer)
append!(nvarh_list, 2)
filter!(e->e≠:vx, hydrovar_buffer)
filter!(e->e≠:var2, hydrovar_buffer)
end
if in(:vy, hydrovar_buffer) || in(:var3, hydrovar_buffer)
append!(nvarh_list, 3)
filter!(e->e≠:vy, hydrovar_buffer)
filter!(e->e≠:var3, hydrovar_buffer)
end
if in(:vz, hydrovar_buffer) || in(:var4, hydrovar_buffer)
append!(nvarh_list, 4)
filter!(e->e≠:vz, hydrovar_buffer)
filter!(e->e≠:var4, hydrovar_buffer)
end
if in(:p, hydrovar_buffer) || in(:var5, hydrovar_buffer)
append!(nvarh_list, 5)
filter!(e->e≠:p, hydrovar_buffer)
filter!(e->e≠:var5, hydrovar_buffer)
end
# if dataobject.descriptor.hydro != dataobject.variable_list
# for (ivar,idvar) in enumerate(dataobject.descriptor.hydro)
# if in(idvar, vars)
# append!(nvarh_list, ivar)
# used_descriptors[ivar] = idvar
# end
# end
# end
if length(hydrovar_buffer)>0
for x in hydrovar_buffer
if occursin("var", string(x))
append!( nvarh_list, parse(Int, string(x)[4:end]) )
end
end
#append!( nvarh_list, map(x->parse(Int, string(x)[4:end]), hydrovar_buffer) ) #for Symbols
#append!( nvarh_list, map(x->parse(Int,x), hydrovar_buffer) ) #for Strings
end
end
if length(nvarh_list) == 0
error("[Mera]: Simulation vars array is empty!")
end
#clean for double assignment
nvarh_list = unique(nvarh_list)
if maximum(nvarh_list) > maximum(nvarh)
error("[Mera]: Simulation maximum variable=$(maximum(nvarh)) < your maximum variable=$(maximum(nvarh_list))")
end
# create vector to use selected hydrovars
nvarh = dataobject.nvarh
nvarh_corr = zeros(Int, nvarh )
nvarh_i_list=[]
for i =1:nvarh
if in(i,nvarh_list)
nvarh_corr[i] = findall(x -> x == i, nvarh_list)[1]
append!(nvarh_i_list, i)
end
end
nvarh_list_strings= Symbol[]
if read_cpu append!(nvarh_list_strings, [:cpu]) end
for i in nvarh_list
#if !haskey(used_descriptors, i)
if i < 6
append!(nvarh_list_strings, [Symbol("$(indices_tovariables[i])")])
elseif i > 5
append!(nvarh_list_strings, [Symbol("var$i")])
end
#else
# append!(nvarh_list_strings, [used_descriptors[i]])
#end
end
#println("nvarh_list",nvarh_list)
#println("nvarh_corr",nvarh_corr)
if verbose
if lmax != dataobject.levelmin # if AMR
println("Key vars=(:level, :cx, :cy, :cz)")
else # if uniform grid
println("Key vars=(:cx, :cy, :cz)")
end
if read_cpu
println("Using var(s)=$(tuple(-1, nvarh_list...)) = $(tuple(nvarh_list_strings...)) ")
else
println("Using var(s)=$(tuple(nvarh_list...)) = $(tuple(nvarh_list_strings...)) ")
end
println()
end
return nvarh_list, nvarh_i_list, nvarh_corr, read_cpu, used_descriptors
elseif datatype == :particles
nvarp = dataobject.nvarp # vx, vy, vz, mass, birth
#:level, :x, :y, :z, :id, :cpu, :vx, :vy, :vz, :mass, :birth]
# manage user selected variables
#-------------------------------------
nvarp_list=Int[]
ivar=1
read_cpu = false
particlesvar_buffer = copy(vars)
used_descriptors = Dict()
if in(:all, particlesvar_buffer) #particlesvar_buffer == [:all]
for invarp = 1:nvarp
append!(nvarp_list, invarp)
end
# read_cpu = true
if in(:cpu, particlesvar_buffer) || in(:varn1, particlesvar_buffer)
read_cpu = true
end
if nvarp > 5 && dataobject.descriptor.pversion <= 0
for ivar=6:nvarp
append!(nvarp_list, [ivar])
end
elseif nvarp > 8 && dataobject.descriptor.pversion > 0
for ivar=9:nvarp
append!(nvarp_list, [ivar])
end
end
# if dataobject.use_particles_descriptor == true
# for (i,idvar) in enumerate(dataobject.particles_descriptor)
# used_descriptors[i] = idvar
# end
# end
else
if in(:cpu, particlesvar_buffer) || in(:varn1, particlesvar_buffer)
read_cpu = true
filter!(e->e≠:cpu, particlesvar_buffer)
filter!(e->e≠:varn1, particlesvar_buffer)
end
if in(:vx, particlesvar_buffer) || in(:var1, particlesvar_buffer)
append!(nvarp_list, 1)
filter!(e->e≠:vx, particlesvar_buffer)
filter!(e->e≠:var1, particlesvar_buffer)
end
if in(:vy, particlesvar_buffer) || in(:var2, particlesvar_buffer)
append!(nvarp_list, 2)
filter!(e->e≠:vy, particlesvar_buffer)
filter!(e->e≠:var2, particlesvar_buffer)
end
if in(:vz, particlesvar_buffer) || in(:var3, particlesvar_buffer)
append!(nvarp_list, 3)
filter!(e->e≠:vz, particlesvar_buffer)
filter!(e->e≠:var3, particlesvar_buffer)
end
if in(:mass, particlesvar_buffer) || in(:var4, particlesvar_buffer)
append!(nvarp_list, 4)
filter!(e->e≠:mass, particlesvar_buffer)
filter!(e->e≠:var4, particlesvar_buffer)
end
if in(:birth, particlesvar_buffer) || in(:var5, particlesvar_buffer) || in(:var7, particlesvar_buffer)
if dataobject.descriptor.pversion <= 0 || in(:var5, particlesvar_buffer)
append!(nvarp_list, 5)
filter!(e->e≠:var5, particlesvar_buffer)
elseif dataobject.descriptor.pversion > 0 || in(:var7, particlesvar_buffer)
append!(nvarp_list, 7)
filter!(e->e≠:var7, particlesvar_buffer)
end
filter!(e->e≠:birth, particlesvar_buffer)
end
if in(:metals, particlesvar_buffer) || in(:var8, particlesvar_buffer)
if dataobject.descriptor.pversion > 0
append!(nvarp_list, 8)
filter!(e->e≠:var8, particlesvar_buffer)
end
filter!(e->e≠:metals, particlesvar_buffer)
end
# if dataobject.particles_descriptor != dataobject.particles_variable_list
# for (ivar,idvar) in enumerate(dataobject.particles_descriptor)
# if in(idvar, vars)
# append!(nvarp_list, ivar)
# used_descriptors[ivar] = idvar
# filter!(e->e≠idvar, particlesvar_buffer)
# end
# end
# end
if length(particlesvar_buffer)>0
for x in particlesvar_buffer
if occursin("var", string(x))
append!( nvarp_list, parse(Int, string(x)[4:end]) )
end
end
#append!( nvarp_list, map(x->parse(Int, string(x)[4:end]), particlesvar_buffer) ) #for Symbols
end
end
if length(nvarp_list) == 0
error("[Mera]: Simulation vars array is empty!")
end
#clean for double assignment
nvarp_list = unique(nvarp_list)
if maximum(nvarp_list) > maximum(nvarp)
error("[Mera]: Simulation maximum variable=$(maximum(nvarp)) < your maximum variable=$(maximum(nvarp_list))")
end
# create vector to use selected particlevars
nvarp = dataobject.nvarp
nvarp_corr = zeros(Int, nvarp )
nvarp_i_list=[]
for i =1:nvarp
if in(i,nvarp_list)
nvarp_corr[i] = findall(x -> x == i, nvarp_list)[1]
append!(nvarp_i_list, i)
end
end
nvarp_list_strings= Symbol[]
if read_cpu append!(nvarp_list_strings, [:cpu]) end
for i in nvarp_list
#if !haskey(used_descriptors, i)
if dataobject.descriptor.pversion == 0
if i < 6
append!(nvarp_list_strings, [Symbol("$(indices_toparticlevariables[i])")])
elseif i > 5
append!(nvarp_list_strings, [Symbol("var$i")])
end
elseif dataobject.descriptor.pversion > 0
if i < 9 && i != 5 && i != 6
append!(nvarp_list_strings, [Symbol("$(indices_toparticlevariables_v1[i])")])
elseif i > 8
append!(nvarp_list_strings, [Symbol("var$i")])
end
end
#else
# append!(nvarp_list_strings, [used_descriptors[i]])
#end
end
if verbose
if dataobject.descriptor.pversion == 0
println("Key vars=(:level, :x, :y, :z, :id)")
elseif dataobject.descriptor.pversion > 0
println("Key vars=(:level, :x, :y, :z, :id, :family, :tag)")
end
if read_cpu
println("Using var(s)=$(tuple(-1, nvarp_list...)) = $(tuple(nvarp_list_strings...)) ")
else
nvarp_i_list_buffer = nvarp_i_list
if dataobject.descriptor.pversion > 0
filter!(x->x≠6,nvarp_i_list_buffer)
filter!(x->x≠5,nvarp_i_list_buffer)
end
println("Using var(s)=$(tuple(nvarp_i_list_buffer...)) = $(tuple(nvarp_list_strings...)) ")
end
println()
end
return nvarp_list, nvarp_i_list, nvarp_corr, read_cpu, used_descriptors
elseif datatype == :gravity
nvarg = length(dataobject.gravity_variable_list) # :epot, :ax, :ay, :az
#:level, :x, :y, :z, :id, :cpu, :epot, :ax, :ay, :az]
# manage user selected variables
#-------------------------------------
nvarg_list=Int[]
ivar=1
read_cpu = false # do not load cpu number by default
gravvar_buffer = copy(vars)
used_descriptors = Dict()
if in(:all, gravvar_buffer) #gravvar_buffer == [:all]
nvarg_list=[1,2,3,4]
# read_cpu = true
if in(:cpu, gravvar_buffer) || in(:varn1, gravvar_buffer)
read_cpu = true
end
else
if in(:cpu, gravvar_buffer) || in(:varn1, gravvar_buffer)
read_cpu = true
filter!(e->e≠:cpu, gravvar_buffer)
filter!(e->e≠:varn1, gravvar_buffer)
end
if in(:epot, gravvar_buffer) || in(:var1, gravvar_buffer)
append!(nvarg_list, 1)
filter!(e->e≠:epot, gravvar_buffer)
filter!(e->e≠:var1, gravvar_buffer)
end
if in(:ax, gravvar_buffer) || in(:var2, gravvar_buffer)
append!(nvarg_list, 2)
filter!(e->e≠:ax, gravvar_buffer)
filter!(e->e≠:var2, gravvar_buffer)
end
if in(:ay, gravvar_buffer) || in(:var3, gravvar_buffer)
append!(nvarg_list, 3)
filter!(e->e≠:ay, gravvar_buffer)
filter!(e->e≠:var3, gravvar_buffer)
end
if in(:az, gravvar_buffer) || in(:var4, gravvar_buffer)
append!(nvarg_list, 4)
filter!(e->e≠:az, gravvar_buffer)
filter!(e->e≠:var4, gravvar_buffer)
end
end
if length(nvarg_list) == 0
error("[Mera]: Simulation vars array is empty!")
end
#clean for double assignment
nvarg_list = unique(nvarg_list)
if maximum(nvarg_list) > maximum(nvarg)
error("[Mera]: Simulation maximum variable=$(maximum(nvarg)) < your maximum variable=$(maximum(nvarg_list))")
end
# create vector to use selected gravvars
nvarg = length(dataobject.gravity_variable_list)
nvarg_corr = zeros(Int, nvarg )
nvarg_i_list=[]
for i =1:nvarg
if in(i,nvarg_list)
nvarg_corr[i] = findall(x -> x == i, nvarg_list)[1]
append!(nvarg_i_list, i)
end
end
nvarg_list_strings= Symbol[]
if read_cpu append!(nvarg_list_strings, [:cpu]) end
for i in nvarg_list
#if !haskey(used_descriptors, i)
if i < 5
append!(nvarg_list_strings, [Symbol("$(indices_togravvariables[i])")])
#elseif i > 4
# append!(nvarg_list_strings, [Symbol("var$i")])
end
#else
# append!(nvarg_list_strings, [used_descriptors[i]])
#end
end
#println("nvarg_list",nvarg_list)
#println("nvarg_corr",nvarg_corr)
if verbose
if lmax != dataobject.levelmin # if AMR
println("Key vars=(:level, :cx, :cy, :cz)")
else # if uniform grid
println("Key vars=(:cx, :cy, :cz)")
end
if read_cpu
println("Using var(s)=$(tuple(-1, nvarg_list...)) = $(tuple(nvarg_list_strings...)) ")
else
println("Using var(s)=$(tuple(nvarg_list...)) = $(tuple(nvarg_list_strings...)) ")
end
println()
end
return nvarg_list, nvarg_i_list, nvarg_corr, read_cpu, used_descriptors
end
end
# index to variable assignment
global indices_tovariables = SortedDict( -1 => "cpu",
0 => "level",
1 => "rho",
2 => "vx",
3 => "vy",
4 => "vz",
5 => "p")
global indices_togravvariables = SortedDict( -1 => "cpu",
0 => "level",
1 => "epot",
2 => "ax",
3 => "ay",
4 => "az")
global indices_toparticlevariables = SortedDict(
-1 => "cpu",
0 => "level",
1 => "vx",
2 => "vy",
3 => "vz",
4 => "mass",
5 => "birth")
global indices_toparticlevariables_v1 = SortedDict(
-1 => "cpu",
0 => "level",
1 => "vx",
2 => "vy",
3 => "vz",
4 => "mass",
7 => "birth",
8 => "metallicity")
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 9427 |
function getgravitydata( dataobject::InfoType,
Nnvarh::Int,
nvarh_corr::Array{Int,1},
lmax::Real,
ranges::Array{Float64,1},
print_filenames::Bool,
show_progress::Bool,
read_cpu::Bool,
read_level::Bool)
if show_progress println("Reading data...") end
# Narraysize::Int,
kind = Float64 #data type
xmin, xmax, ymin, ymax, zmin, zmax = ranges # 6 elements
idom = zeros(Int32, 8)
jdom = zeros(Int32, 8)
kdom = zeros(Int32, 8)
bounding_min = zeros(Float64, 8)
bounding_max = zeros(Float64, 8)
cpu_min = zeros(Int32, 8)
cpu_max = zeros(Int32, 8)
#vars_1D = zeros(kind, Narraysize, Nnvarh)
#pos_1D = zeros(Int32, Narraysize, 4)
vars_1D = ElasticArray{Float64}(undef, Nnvarh, 0) # to append multidim array
if read_level # if AMR
pos_1D = ElasticArray{Int}(undef, 4, 0) # to append multidim array
else # if uniform grid
pos_1D = ElasticArray{Int}(undef, 3, 0) # to append multidim array
end
#if read_cpu cpus_1D = zeros(Int, Narraysize) end
cpus_1D = zeros(Int, 0) # zero size to use for append function
path = dataobject.path
overview = dataobject.grid_info
nvarh = length(dataobject.gravity_variable_list)
cpu_overview = dataobject.grid_info
twotondim=2^dataobject.ndim
twotondim_float=2. ^dataobject.ndim
xbound=[round( dataobject.grid_info.nx/2, RoundDown),
round( dataobject.grid_info.ny/2, RoundDown),
round( dataobject.grid_info.nz/2, RoundDown)]
ngridfile = zeros(Int32, dataobject.ncpu+dataobject.grid_info.nboundary, dataobject.grid_info.nlevelmax)
ngridlevel = zeros(Int32, dataobject.ncpu, dataobject.grid_info.nlevelmax)
if dataobject.grid_info.nboundary > 0
ngridbound = zeros(Int32, dataobject.grid_info.nboundary, dataobject.grid_info.nlevelmax)
end
dmax= maximum([xmax-xmin,ymax-ymin,zmax-zmin])
ilevel = 1 # define ilevel before loop
for il=1:lmax
ilevel=il
dx=0.5^ilevel
if dx < dmax break end
end
bit_length=ilevel-1
maxdom=2^bit_length
#for positive valuse: Julia floor == Fotran int
if bit_length > 0
imin=floor(Int32, xmin * maxdom)
imax=imin+1
jmin=floor(Int32, ymin * maxdom)
jmax=jmin+1
kmin=floor(Int32, zmin * maxdom)
kmax=kmin+1
else
imin=0
imax=0
jmin=0
jmax=0
kmin=0
kmax=0
end
dkey=(2^(dataobject.grid_info.nlevelmax+1)/maxdom)^dataobject.ndim
if bit_length>0 ndom=8 else ndom=1 end
idom = [imin, imax, imin, imax, imin, imax, imin, imax]
jdom = [jmin, jmin, jmax, jmax, jmin, jmin, jmax, jmax]
kdom = [kmin, kmin, kmin, kmin, kmax, kmax, kmax, kmax]
order_min=0.0e0 #todo: predeclare
for i=1:ndom
if bit_length > 0
order_min = hilbert3d(idom[i],jdom[i],kdom[i],bit_length,1)
else
order_min=0.0e0
end
bounding_min[i]=(order_min)*dkey
bounding_max[i]=(order_min+1.)*dkey
end
for impi=1:dataobject.ncpu
for i=1:ndom
if (dataobject.grid_info.bound_key[impi] <= bounding_min[i] &&
dataobject.grid_info.bound_key[impi+1] > bounding_min[i])
cpu_min[i]=impi
end
if (dataobject.grid_info.bound_key[impi] < bounding_max[i] &&
dataobject.grid_info.bound_key[impi+1] >= bounding_max[i])
cpu_max[i]=impi
end
end
end
cpu_read = copy(dataobject.grid_info.cpu_read)
cpu_list = zeros(Int32, dataobject.ncpu)
ncpu_read=Int32(0)
for i=1:ndom #Todo
for j=(cpu_min[i]):(cpu_max[i])
if cpu_read[j]==false
ncpu_read=ncpu_read+1
cpu_list[ncpu_read]=j
cpu_read[j]=true
end
end
end
# -----------------------------------------------------------
grid = fill(LevelType(0,0,0,0,0,0), lmax)
# Compute hierarchy
for ilevel=1:lmax
nx_full=Int32(2^ilevel)
ny_full=nx_full
nz_full=nx_full
imin=floor(Int32, xmin * nx_full) +1
imax=floor(Int32, xmax * nx_full) +1
jmin=floor(Int32, ymin * ny_full) +1
jmax=floor(Int32, ymax * ny_full) +1
kmin=floor(Int32, zmin * nz_full) +1
kmax=floor(Int32, zmax * nz_full) +1
grid[ilevel] = LevelType( imin, imax, jmin, jmax, kmin, kmax )
end
fnames = createpath(dataobject.output, path)
xc = zeros(kind, 8,3)
dummy1 = 0
read_data= 0
lmax2 =2^lmax
var_firsttime =1
var1 = 0.
var_x = 0
var_level = 0
#get_var_totsize = 0
if show_progress
p = 1 # show updates
else
p = ncpu_read+2 # do not show updates
end
@showprogress p for k=1:ncpu_read #Reading files... @showprogress 1 ""
icpu=cpu_list[k]
#println("icpu ",icpu)
# Open AMR file and skip header
###if print_filenames println(Full_Path_AMR_cpufile) end
amrpath = getproc2string(fnames.amr, icpu)
f_amr = FortranFile(amrpath)
# Open AMR file and skip header
skiplines(f_amr, 21)
# Read grid numbers
read(f_amr, ngridlevel)
ngridfile[1:dataobject.ncpu, 1:dataobject.grid_info.nlevelmax] = ngridlevel
skiplines(f_amr, 1)
if dataobject.grid_info.nboundary > 0
skiplines(f_amr, 2)
read(f_amr, ngridbound)
ngridfile[(dataobject.ncpu+1):(dataobject.ncpu+overview.nboundary),1:dataobject.grid_info.nlevelmax]=ngridbound
end
skiplines(f_amr, 6)
# Open GRAVITY file and skip header
gravpath = getproc2string(fnames.gravity, icpu)
if print_filenames println(gravpath) end
f_grav = FortranFile(gravpath)
skiplines(f_grav, 4)
# Loop over levels
for ilevel=1:lmax
# Geometry
dx=0.5^ilevel
nx_full=Int32(2^ilevel)
ny_full=nx_full
nz_full=nx_full
xc = geometry(twotondim_float, ilevel, xc) # @trace
# Allocate work arrays
ngrida=ngridfile[icpu,ilevel] # integer
if ngrida>0
xg = zeros(kind, ngrida, dataobject.ndim)
son = zeros(Int32, ngrida, twotondim)
vara = zeros(kind, ngrida, twotondim, Nnvarh)
end
# Loop over domains
for j=1:(overview.nboundary+dataobject.ncpu)
# Read AMR data
if ngridfile[j,ilevel]>0
skiplines(f_amr, 3) # Skip grid index
# Read grid center
for idim=1:dataobject.ndim
if j == icpu
xg[:,idim] = read(f_amr, (kind, ngrida))
else
skiplines(f_amr, 1)
end
end
# Skip father index + Skip nbor index
skiplines(f_amr, 1 + (2*dataobject.ndim))
# Read son index
for ind=1:twotondim
if j == icpu
son[:,ind] = read(f_amr, (Int32, ngrida))
else
skiplines(f_amr, 1)
end
end
# Skip cpu map + refinement map
skiplines(f_amr, twotondim * 2)
end
# Read gravity data
skiplines(f_grav, 2)
if ngridfile[j,ilevel]>0
# Read gravity variables
for ind=1:twotondim
for ivar=1:nvarh
if j == icpu
if nvarh_corr[ivar] != 0
vara[:,ind,nvarh_corr[ivar]] = read(f_grav,(kind, ngrida) )
else
skiplines(f_grav, 1)
end
else
skiplines(f_grav, 1)
end
end
end
end
end
# Compute map
if ngrida>0
vars_1D, pos_1D, cpus_1D = loopovercellshydro(twotondim,
ngrida, ilevel, lmax,
xg, xc, son, xbound,
nx_full, ny_full, nz_full,
grid, vara, vars_1D, pos_1D,
read_cpu, cpus_1D, k, read_level) # for kind = Float64
end
end # End loop over levels
close(f_amr)
close(f_grav)
#if show_progress next!(p, showvalues = [(:Nfiles, k)]) end # ProgressMeter
end # End loop over cpu files
if read_cpu
return vars_1D, pos_1D, cpus_1D #arrays
else
return vars_1D, pos_1D #arrays
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 12535 |
function gethydrodata( dataobject::InfoType,
Nnvarh::Int,
nvarh_corr::Array{Int,1},
lmax::Real,
ranges::Array{Float64,1},
print_filenames::Bool,
show_progress::Bool,
read_cpu::Bool,
read_level::Bool)
if show_progress println("Reading data...") end
# Narraysize::Int,
kind = Float64 #data type
xmin, xmax, ymin, ymax, zmin, zmax = ranges # 6 elements
idom = zeros(Int32, 8)
jdom = zeros(Int32, 8)
kdom = zeros(Int32, 8)
bounding_min = zeros(Float64, 8)
bounding_max = zeros(Float64, 8)
cpu_min = zeros(Int32, 8)
cpu_max = zeros(Int32, 8)
#vars_1D = zeros(kind, Narraysize, Nnvarh)
#pos_1D = zeros(Int32, Narraysize, 4)
vars_1D = ElasticArray{Float64}(undef, Nnvarh, 0) # to append multidim array
if read_level # if AMR
pos_1D = ElasticArray{Int}(undef, 4, 0) # to append multidim array
else # if uniform grid
pos_1D = ElasticArray{Int}(undef, 3, 0) # to append multidim array
end
#if read_cpu cpus_1D = zeros(Int, Narraysize) end
cpus_1D = zeros(Int, 0) # zero size to use for append function
path = dataobject.path
overview = dataobject.grid_info
nvarh = dataobject.nvarh
cpu_overview = dataobject.grid_info
twotondim=2^dataobject.ndim
twotondim_float=2. ^dataobject.ndim
xbound=[round( dataobject.grid_info.nx/2, RoundDown),
round( dataobject.grid_info.ny/2, RoundDown),
round( dataobject.grid_info.nz/2, RoundDown)]
ngridfile = zeros(Int32, dataobject.ncpu+dataobject.grid_info.nboundary, dataobject.grid_info.nlevelmax)
ngridlevel = zeros(Int32, dataobject.ncpu, dataobject.grid_info.nlevelmax)
if dataobject.grid_info.nboundary > 0
ngridbound = zeros(Int32, dataobject.grid_info.nboundary, dataobject.grid_info.nlevelmax)
end
dmax= maximum([xmax-xmin,ymax-ymin,zmax-zmin])
ilevel = 1 # define ilevel before loop
for il=1:lmax
ilevel=il
dx=0.5^ilevel
if dx < dmax break end
end
bit_length=ilevel-1
maxdom=2^bit_length
#for positive valuse: Julia floor == Fotran int
if bit_length > 0
imin=floor(Int32, xmin * maxdom)
imax=imin+1
jmin=floor(Int32, ymin * maxdom)
jmax=jmin+1
kmin=floor(Int32, zmin * maxdom)
kmax=kmin+1
else
imin=0
imax=0
jmin=0
jmax=0
kmin=0
kmax=0
end
dkey=(2^(dataobject.grid_info.nlevelmax+1)/maxdom)^dataobject.ndim
if bit_length>0 ndom=8 else ndom=1 end
idom = [imin, imax, imin, imax, imin, imax, imin, imax]
jdom = [jmin, jmin, jmax, jmax, jmin, jmin, jmax, jmax]
kdom = [kmin, kmin, kmin, kmin, kmax, kmax, kmax, kmax]
order_min=0.0e0 #todo: predeclare
for i=1:ndom
if bit_length > 0
order_min = hilbert3d(idom[i],jdom[i],kdom[i],bit_length,1)
else
order_min=0.0e0
end
bounding_min[i]=(order_min)*dkey
bounding_max[i]=(order_min+1.)*dkey
end
for impi=1:dataobject.ncpu
for i=1:ndom
if (dataobject.grid_info.bound_key[impi] <= bounding_min[i] &&
dataobject.grid_info.bound_key[impi+1] > bounding_min[i])
cpu_min[i]=impi
end
if (dataobject.grid_info.bound_key[impi] < bounding_max[i] &&
dataobject.grid_info.bound_key[impi+1] >= bounding_max[i])
cpu_max[i]=impi
end
end
end
cpu_read = copy(dataobject.grid_info.cpu_read)
cpu_list = zeros(Int32, dataobject.ncpu)
ncpu_read=Int32(0)
for i=1:ndom #Todo
for j=(cpu_min[i]):(cpu_max[i])
if cpu_read[j]==false
ncpu_read=ncpu_read+1
cpu_list[ncpu_read]=j
cpu_read[j]=true
end
end
end
# -----------------------------------------------------------
grid = fill(LevelType(0,0,0,0,0,0), lmax)
# Compute hierarchy
for ilevel=1:lmax
nx_full=Int32(2^ilevel)
ny_full=nx_full
nz_full=nx_full
imin=floor(Int32, xmin * nx_full) +1
imax=floor(Int32, xmax * nx_full) +1
jmin=floor(Int32, ymin * ny_full) +1
jmax=floor(Int32, ymax * ny_full) +1
kmin=floor(Int32, zmin * nz_full) +1
kmax=floor(Int32, zmax * nz_full) +1
grid[ilevel] = LevelType( imin, imax, jmin, jmax, kmin, kmax )
end
fnames = createpath(dataobject.output, path)
xc = zeros(kind, 8,3)
dummy1 = 0
read_data= 0
lmax2 =2^lmax
var_firsttime =1
var1 = 0.
var_x = 0
var_level = 0
#get_var_totsize = 0
if show_progress
p = 1 # show updates
else
p = ncpu_read+2 # do not show updates
end
@showprogress p for k=1:ncpu_read #Reading files... @showprogress 1 ""
icpu=cpu_list[k]
#println("icpu ",icpu)
# Open AMR file and skip header
###if print_filenames println(Full_Path_AMR_cpufile) end
amrpath = getproc2string(fnames.amr, icpu)
f_amr = FortranFile(amrpath)
# Open AMR file and skip header
skiplines(f_amr, 21)
# Read grid numbers
read(f_amr, ngridlevel)
ngridfile[1:dataobject.ncpu, 1:dataobject.grid_info.nlevelmax] = ngridlevel
skiplines(f_amr, 1)
if dataobject.grid_info.nboundary > 0
skiplines(f_amr, 2)
read(f_amr, ngridbound)
ngridfile[(dataobject.ncpu+1):(dataobject.ncpu+overview.nboundary),1:dataobject.grid_info.nlevelmax]=ngridbound
end
skiplines(f_amr, 6)
# Open HYDRO file and skip header
hydropath = getproc2string(fnames.hydro, icpu)
if print_filenames println(hydropath) end
#println(Full_Path_Hydro_cpufile)
f_hydro = FortranFile(hydropath)
skiplines(f_hydro, 6)
# Loop over levels
for ilevel=1:lmax
# Geometry
dx=0.5^ilevel
nx_full=Int32(2^ilevel)
ny_full=nx_full
nz_full=nx_full
xc = geometry(twotondim_float, ilevel, xc) # @trace
# Allocate work arrays
ngrida=ngridfile[icpu,ilevel] # integer
if ngrida>0
xg = zeros(kind, ngrida, dataobject.ndim)
son = zeros(Int32, ngrida, twotondim)
vara = zeros(kind, ngrida, twotondim, Nnvarh)
end
# Loop over domains
for j=1:(overview.nboundary+dataobject.ncpu)
# Read AMR data
if ngridfile[j,ilevel]>0
skiplines(f_amr, 3) # Skip grid index
# Read grid center
for idim=1:dataobject.ndim
if j == icpu
xg[:,idim] = read(f_amr, (kind, ngrida))
else
skiplines(f_amr, 1)
end
end
# Skip father index + Skip nbor index
skiplines(f_amr, 1 + (2*dataobject.ndim))
# Read son index
for ind=1:twotondim
if j == icpu
son[:,ind] = read(f_amr, (Int32, ngrida))
else
skiplines(f_amr, 1)
end
end
# Skip cpu map + refinement map
skiplines(f_amr, twotondim * 2)
end
# Read hydro data
skiplines(f_hydro, 2)
if ngridfile[j,ilevel]>0
# Read hydro variables
for ind=1:twotondim
for ivar=1:nvarh
if j == icpu
if nvarh_corr[ivar] != 0
vara[:,ind,nvarh_corr[ivar]] = read(f_hydro,(kind, ngrida) )
else
skiplines(f_hydro, 1)
end
else
skiplines(f_hydro, 1)
end
end
end
end
end
# Compute map
if ngrida>0
vars_1D, pos_1D, cpus_1D = loopovercellshydro(twotondim,
ngrida, ilevel, lmax,
xg, xc, son, xbound,
nx_full, ny_full, nz_full,
grid, vara, vars_1D, pos_1D,
read_cpu, cpus_1D, k, read_level) # for kind = Float64
end
end # End loop over levels
close(f_amr)
close(f_hydro)
#if show_progress next!(p, showvalues = [(:Nfiles, k)]) end # ProgressMeter
end # End loop over cpu files
if read_cpu
return vars_1D, pos_1D, cpus_1D #arrays
else
return vars_1D, pos_1D #arrays
end
end
function geometry(twotondim_float::Float64, ilevel::Int, xc::Array{Float64,2})
dx=0.5^ilevel
for (ind,iind) =enumerate(1.:twotondim_float)
iiz=round( (iind-1)/4, RoundDown) #floor(Int32, (ind-1)/4)
iiy=round( (iind-1-4*iiz)/2, RoundDown) #floor(Int32, (ind-1-4*iiz)/2)
iix=round( (iind-1-2*iiy-4*iiz), RoundDown) #floor(Int32, (ind-1-2*iiy-4*iiz))
xc[ind,1]=(iix-0.5)*dx
xc[ind,2]=(iiy-0.5)*dx
xc[ind,3]=(iiz-0.5)*dx
end
return xc
end
function loopovercellshydro(twotondim::Int,
ngrida::Int32,
ilevel::Int,
lmax::Int,
xg::Array{Float64,2},
xc::Array{Float64,2},
son::Array{Int32,2},
xbound::Array{Float64,1},
nx_full::Int32,
ny_full::Int32,
nz_full::Int32,
grid::Array{LevelType,1},
vara::Array{Float64,3},
vars_1D::ElasticArray{Float64,2,1},
pos_1D::ElasticArray{Int,2,1},
read_cpu::Bool,
cpus_1D::Array{Int,1},
k::Int,
read_level::Bool)
for ind=1:twotondim # Loop over cells
# Store data cube
for i=1:ngrida
if !(son[i,ind]>0 && ilevel<lmax) #if !ref[i]
#=
ix = round( (xg[i,1]+xc[ind,1]-xbound[1]) *nx_full, RoundDown) +1.
iy = round( (xg[i,2]+xc[ind,2]-xbound[2]) *ny_full, RoundDown) +1.
iz = round( (xg[i,3]+xc[ind,3]-xbound[3]) *nz_full, RoundDown) +1.
=#
# todo: simplify "fortran int"
ix=floor(Int, (xg[i,1]+xc[ind,1]-xbound[1]) *nx_full)+1
iy=floor(Int, (xg[i,2]+xc[ind,2]-xbound[2]) *ny_full)+1
iz=floor(Int, (xg[i,3]+xc[ind,3]-xbound[3]) *nz_full)+1
#println(ilevel, ", ", ix, " ", iy, " ", iz, " ", grid[ilevel] )
if ix>=(grid[ilevel].imin) &&
iy>=(grid[ilevel].jmin) &&
iz>=(grid[ilevel].kmin) &&
ix<=(grid[ilevel].imax) &&
iy<=(grid[ilevel].jmax) &&
iz<=(grid[ilevel].kmax)
#println()
#println(ilevel, ", ", ix, " ", iy, " ", iz, " ", grid[ilevel] )
append!(vars_1D, vara[i,ind,:])
if read_level # if AMR
append!(pos_1D, [ix, iy, iz, ilevel])
else # if uniform grid
append!(pos_1D, [ix, iy, iz])
end
if read_cpu append!(cpus_1D, k) end
end
end
end
end # End loop over cell
return vars_1D, pos_1D, cpus_1D
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 13154 | function getparticledata( dataobject::InfoType,
Nvarp::Int,
nvarp_corr::Array{Int,1},
stars::Bool,
lmax::Real,
ranges::Array{Float64,1},
print_filenames::Bool,
show_progress::Bool,
verbose::Bool,
read_cpu::Bool )
output = dataobject.output
lmin = dataobject.levelmin
path = dataobject.path
ndim = dataobject.ndim
boxlen = dataobject.boxlen
omega_m = dataobject.omega_m
omega_l = dataobject.omega_l
omega_k = dataobject.omega_k
h0 = dataobject.H0
aexp = dataobject.aexp
xmin, xmax, ymin, ymax, zmin, zmax = ranges # 6 elements
idom = zeros(Int32, 8)
jdom = zeros(Int32, 8)
kdom = zeros(Int32, 8)
bounding_min = zeros(Float64, 8)
bounding_max = zeros(Float64, 8)
cpu_min = zeros(Int32, 8)
cpu_max = zeros(Int32, 8)
dmax= maximum([xmax-xmin,ymax-ymin,zmax-zmin])
ilevel = 1 # define ilevel before loop
for il=1:lmax
ilevel=il
dx=0.5^ilevel
if dx < dmax break end
end
bit_length=ilevel-1
maxdom=2^bit_length
# Todo: floor = fotran int ?
if bit_length > 0
imin=floor(Int32, xmin * maxdom)
imax=imin+1
jmin=floor(Int32, ymin * maxdom)
jmax=jmin+1
kmin=floor(Int32, zmin * maxdom)
kmax=kmin+1
else
imin=0
imax=0
jmin=0
jmax=0
kmin=0
kmax=0
end
dkey=(2^(dataobject.grid_info.nlevelmax+1)/maxdom)^dataobject.ndim
if bit_length>0 ndom=8 else ndom=1 end
idom = [imin, imax, imin, imax, imin, imax, imin, imax]
jdom = [jmin, jmin, jmax, jmax, jmin, jmin, jmax, jmax]
kdom = [kmin, kmin, kmin, kmin, kmax, kmax, kmax, kmax]
order_min=0.0e0 #todo: predeclare
for i=1:ndom
if bit_length > 0
order_min = hilbert3d(idom[i],jdom[i],kdom[i],bit_length,1)
else
order_min=0.0e0
end
bounding_min[i]=(order_min)*dkey
bounding_max[i]=(order_min+1.)*dkey
end
for impi=1:dataobject.ncpu
for i=1:ndom
if (dataobject.grid_info.bound_key[impi] <= bounding_min[i] &&
dataobject.grid_info.bound_key[impi+1] > bounding_min[i])
cpu_min[i]=impi
end
if (dataobject.grid_info.bound_key[impi] < bounding_max[i] &&
dataobject.grid_info.bound_key[impi+1] >= bounding_max[i])
cpu_max[i]=impi
end
end
end
cpu_read = copy(dataobject.grid_info.cpu_read)
cpu_list = zeros(Int32, dataobject.ncpu)
ncpu_read=Int32(0)
for i=1:ndom #Todo
for j=(cpu_min[i]):(cpu_max[i])
if cpu_read[j]==false
ncpu_read=ncpu_read+1
cpu_list[ncpu_read]=j
cpu_read[j]=true
end
end
end
if read_cpu
if dataobject.descriptor.pversion == 0
pos_1D, vars_1D, cpus_1D, identity_1D, levels_1D = readpart( dataobject,
Nvarp=Nvarp, nvarp_corr=nvarp_corr,
lmax=lmax,
ranges=ranges,
cpu_list=cpu_list,
ncpu_read=ncpu_read,
stars=stars,
read_cpu=read_cpu,
verbose=verbose,
print_filenames=print_filenames,
show_progress=show_progress )
return pos_1D, vars_1D, cpus_1D, identity_1D, levels_1D
elseif dataobject.descriptor.pversion > 0
pos_1D, vars_1D, cpus_1D, identity_1D, family_1D, tag_1D, levels_1D = readpart( dataobject,
Nvarp=Nvarp, nvarp_corr=nvarp_corr,
lmax=lmax,
ranges=ranges,
cpu_list=cpu_list,
ncpu_read=ncpu_read,
stars=stars,
read_cpu=read_cpu,
verbose=verbose,
print_filenames=print_filenames,
show_progress=show_progress )
return pos_1D, vars_1D, cpus_1D, identity_1D, family_1D, tag_1D, levels_1D
end # if pversion
else # if read_cpu
if dataobject.descriptor.pversion == 0
pos_1D, vars_1D, identity_1D, levels_1D = readpart( dataobject,
Nvarp=Nvarp, nvarp_corr=nvarp_corr,
lmax=lmax,
ranges=ranges,
cpu_list=cpu_list,
ncpu_read=ncpu_read,
stars=stars,
read_cpu=read_cpu,
verbose=verbose,
print_filenames=print_filenames,
show_progress=show_progress )
return pos_1D, vars_1D, identity_1D, levels_1D
elseif dataobject.descriptor.pversion > 0
pos_1D, vars_1D, identity_1D, family_1D, tag_1D, levels_1D = readpart( dataobject,
Nvarp=Nvarp, nvarp_corr=nvarp_corr,
lmax=lmax,
ranges=ranges,
cpu_list=cpu_list,
ncpu_read=ncpu_read,
stars=stars,
read_cpu=read_cpu,
verbose=verbose,
print_filenames=print_filenames,
show_progress=show_progress )
return pos_1D, vars_1D, identity_1D, family_1D, tag_1D, levels_1D
end # if pversion
end
end
function readpart(dataobject::InfoType;
Nvarp::Int,
nvarp_corr::Array{Int,1},
lmax::Int=dataobject.levelmax,
ranges::Array{Float64,1}=[0.,1.],
cpu_list::Array{Int32,1}=[1],
ncpu_read::Int=0,
stars::Bool=true,
read_cpu::Bool=false,
verbose::Bool=verbose_mode,
print_filenames::Bool=false,
show_progress::Bool=true)
boxlen = dataobject.boxlen
path = dataobject.path
ndim = dataobject.ndim
fnames = createpath(dataobject.output, path)
vars_1D = ElasticArray{Float64}(undef, Nvarp, 0)
r1, r2, r3, r4, r5, r6 = ranges .* boxlen
pos_1D = ElasticArray{Float64}(undef, 3, 0)
if read_cpu cpus_1D = Array{Int}(undef, 0) end #zeros(Int, npart)
identity_1D = Array{Int32}(undef, 0) #zeros(Int32, npart)
#if dataobject.descriptor.pversion == 0
if dataobject.descriptor.pversion > 0
#identity_1D = Array{Int32}(undef, 0) #zeros(Int32, npart)
family_1D = Array{Int8}(undef, 0) #zeros(Int32, npart)
tag_1D = Array{Int8}(undef, 0) #zeros(Int32, npart)
end
levels_1D = Array{Int32}(undef, 0) #zeros(Int32, npart) #manu
ndim2=Int32(0)
#ngrida=0
parti=Int32(0) # particle iterator
if show_progress
p = 1 # show updates
else
p = ncpu_read+2 # do not show updates
end
@showprogress p for k=1:ncpu_read # @showprogress 1 "Reading data..."
icpu=cpu_list[k]
partpath = getproc2string(fnames.particles, icpu)
f_part = FortranFile(partpath)
skiplines(f_part, 1) #ncpu2
ndim2 = read(f_part, Int32) #, (Int32, ndim2))
npart2 = read(f_part, Int32) #, (Int32, npart2))
skiplines(f_part, 1)
nstar = read(f_part, Int32)
skiplines(f_part, 3)
if npart2 != 0
pos_1D_buffer = zeros(Float64, 3, npart2)
vars_1D_buffer = zeros(Float64, Nvarp, npart2 )
if dataobject.descriptor.pversion > 0
family_1D_buffer = zeros(Int8, npart2)
tag_1D_buffer = zeros(Int8, npart2)
end
identity_1D_buffer = zeros(Int32, npart2)
levels_1D_buffer = zeros(Int32, npart2)
# Read position
for i=1:ndim
#x[:,i] = read(f_part, (Float64, npart2)
pos_1D_buffer[i, 1:npart2] = read(f_part, (Float64, npart2) )
end
pos_selected = (pos_1D_buffer[1,:] .>= r1) .& (pos_1D_buffer[1,:] .<= r2) .&
(pos_1D_buffer[2,:] .>= r3) .& (pos_1D_buffer[2,:] .<= r4) .&
(pos_1D_buffer[3,:] .>= r5) .& (pos_1D_buffer[3,:] .<= r6)
ls = Int32(length( pos_1D_buffer[1, pos_selected] ) ) #selected length #todo int32
if ls != 0
append!(pos_1D, pos_1D_buffer[:, pos_selected] )
# Read velocity
for i=1:ndim
if nvarp_corr[i] != 0
#vel[:,i] = read(f_part, (Float64, npart2)
vars_1D_buffer[nvarp_corr[i], 1:npart2] = read(f_part, (Float64, npart2) )
else
skiplines(f_part, 1)
end
#read(f_part)
end
# Read mass
if nvarp_corr[4] != 0
vars_1D_buffer[nvarp_corr[4], 1:npart2] = read(f_part, (Float64, npart2) )
else
skiplines(f_part, 1)
end
# Read identity
#if dataobject.descriptor.pversion == 0
identity_1D_buffer[1:npart2] = read(f_part, (Int32, npart2) ) # identity
append!(identity_1D, identity_1D_buffer[pos_selected]) # identity
#end
# Read level
levels_1D_buffer[1:npart2] = read(f_part, (Int32, npart2) ) # level
append!(levels_1D, levels_1D_buffer[pos_selected]) # level
# Read family, tag
if dataobject.descriptor.pversion > 0
#skiplines(f_part, 1) # skip identity
family_1D_buffer[1:npart2] = read(f_part, (Int8, npart2) ) # family
tag_1D_buffer[1:npart2] = read(f_part, (Int8, npart2) ) # tag
append!(family_1D, family_1D_buffer[pos_selected]) # family
append!(tag_1D, tag_1D_buffer[pos_selected]) # tag
# read birth
if nstar>0 && nvarp_corr[7] != 0
#birth = read(f_part, (Float64, npart2)
#skiplines(f_part, 1)
vars_1D_buffer[nvarp_corr[7], 1:npart2] = read(f_part, (Float64, npart2) ) #age (birth)
elseif nstar>0 && nvarp_corr[7] == 0
skiplines(f_part, 1)
end
elseif dataobject.descriptor.pversion == 0
# read birth
if nstar>0 && nvarp_corr[5] != 0
#birth = read(f_part, (Float64, npart2)
#skiplines(f_part, 1)
vars_1D_buffer[nvarp_corr[5], 1:npart2] = read(f_part, (Float64, npart2) ) #age (birth)
elseif nstar>0 && nvarp_corr[5] == 0
skiplines(f_part, 1)
end
end
# read additional variables
if Nvarp>7
for iN = 8:Nvarp
if nvarp_corr[iN] != 0
vars_1D_buffer[nvarp_corr[iN], 1:npart2] = read(f_part, (Float64, npart2) )
end
end
end
append!(vars_1D, vars_1D_buffer[:, pos_selected] )
if read_cpu append!(cpus_1D, fill(k,ls) ) end
parti = parti + ls
end
end
close(f_part)
#if show_progress next!(p, showvalues = [(:Nfiles, k)]) end # ProgressMeter
end #for
if read_cpu
if dataobject.descriptor.pversion == 0
return pos_1D, vars_1D, cpus_1D, identity_1D, levels_1D
elseif dataobject.descriptor.pversion > 0
return pos_1D, vars_1D, cpus_1D, identity_1D, family_1D, tag_1D, levels_1D
end
else
if dataobject.descriptor.pversion == 0
return pos_1D, vars_1D, identity_1D, levels_1D
elseif dataobject.descriptor.pversion > 0
return pos_1D, vars_1D, identity_1D, family_1D, tag_1D, levels_1D
end
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 792 | @testset "01 General Tests" begin
include("general.jl")
end
verbose(false)
showprogress(false)
@testset "02 getvar hydro" begin
printscreen("getvar hydro:")
include("values_hydro.jl")
end
@testset "03 getvar particles" begin
printscreen("getvar particles:")
include("values_particles.jl")
end
@testset "04 projection hydro" begin
printscreen("projection hydro:")
include("projection/projection_hydro.jl")
end
@testset "05 projection stars" begin
printscreen("projection particle/stars:")
include("projection/projection_particles.jl")
end
verbose(true)
@testset "06 MERA files" begin
printscreen("Write/Read MERA files:")
include("merafiles.jl")
end
@testset "07 Error Checks" begin
printscreen("data types:")
include("errors.jl")
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 1003 |
@testset "01 General Tests" begin
include("clumps/general.jl")
end
# verbose(false)
# showprogress(false)
# @testset "02 getvar clumps" begin
# printscreen("getvar clumps:")
# include("clumps/values_clumps.jl")
# end
# @testset "03 getvar clumps" begin
# printscreen("getvar clumps:")
# include("clumps/values_clumps.jl")
# end
# end
verbose(true)
@testset "04 MERA files" begin
printscreen("Write/Read MERA files:")
include("clumps/merafiles.jl")
@testset "saving" begin @test save_clumps_jld2(output, path) end
@testset "loading" begin @test load_data(output, path) end
@testset "save different order" begin @test save_clumps_different_order_jld2(output, path) end
@testset "converting" begin@test convert_clumps_jld2(output, path) end
@testset "compare stored clump data" begin @test load_uaclumps_data(output, path) end
end
# @testset "05 Error Checks" begin
# printscreen("data types:")
# include("clumps/errors.jl")
# end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 1576 | @test_throws ErrorException("[Mera]: Simulation has no hydro files!") checktypes_error(output, path, :hydro)
@test_throws ErrorException("[Mera]: Simulation has no particle files!") checktypes_error(output, path, :particles)
@test_throws ErrorException("[Mera]: Simulation has no gravity files!") checktypes_error(output, path, :gravity)
@test_throws ErrorException("[Mera]: Simulation has no rt files!") checktypes_error(output, path, :rt)
@test_throws ErrorException("[Mera]: Simulation has no clump files!") checktypes_error(output, path, :clumps)
@test_throws ErrorException("[Mera]: Simulation has no sink files!") checktypes_error(output, path, :sinks)
@test_throws ErrorException("[Mera]: Simulation has no amr files!") checktypes_error(output, path, :amr)
if info.levelmin !== info.levelmax
@test_throws ErrorException("[Mera]: Simulation lmax=7 < your lmax=10") checklevelmax_error(output, path)
@test_throws ErrorException("[Mera]: Simulation lmin=3 > your lmin=1") checklevelmin_error(output, path)
end
if Sys.iswindows()
@test_throws ErrorException("[Mera]: File or folder does not exist: " * pwd() *"\\./simulations/output_00003\\info_00003.txt !") checkfolder_error(path)
else
@test_throws ErrorException("[Mera]: File or folder does not exist: " * pwd() *"/./simulations/output_00003/info_00003.txt !") checkfolder_error(path)
end
@test_throws ErrorException("Datatype clumps does not exist...") infodata(output, :clumps)
@test_throws ErrorException("unknown datatype(s) given...") convertdata(output, [:anyname], path=path)
# savedata | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 13353 |
if !(Sys.iswindows()) # skip test for windows
@testset "file/folder-names" begin
printscreen("file/folder-names:")
@testset "createpath" begin
# =================================
fname = Mera.createpath(10, "./");
flag = Dict()
flag[1] = fname.amr == "./output_00010/amr_00010."
flag[2] = fname.clumps == "./output_00010/clump_00010."
flag[3] = fname.compilation == "./output_00010/compilation.txt"
flag[4] = fname.gravity == "./output_00010/grav_00010."
flag[5] = fname.header == "./output_00010/header_00010.txt"
flag[6] = fname.hydro == "./output_00010/hydro_00010."
flag[7] = fname.hydro_descriptor == "./output_00010/hydro_file_descriptor.txt"
flag[8] = fname.info == "./output_00010/info_00010.txt"
flag[9] = fname.makefile == "./output_00010/makefile.txt"
flag[10] = fname.namelist == "./output_00010/namelist.txt"
flag[11] = fname.output == "./output_00010"
flag[12] = fname.part_descriptor == "./output_00010/part_file_descriptor.txt"
flag[13] = fname.particles == "./output_00010/part_00010."
flag[14] = fname.patchfile == "./output_00010/patches.txt"
flag[15] = fname.rt == "./output_00010/rt_00010."
flag[16] = fname.rt_descriptor == "./output_00010/rt_file_descriptor.txt"
flag[17] = fname.rt_descriptor_v0 == "./output_00010/info_rt_00010.txt"
flag[18] = fname.timer == "./output_00010/timer_00010.txt"
ispos = true
for i in sort(collect(keys(flag)))
if flag[i] == false
ispos = false
println("test 10: flag: ", i, " = false")
end
end
# =================================
fname = Mera.createpath(100, "./");
flag = Dict()
flag[1] = fname.amr == "./output_00100/amr_00100."
flag[2] = fname.clumps == "./output_00100/clump_00100."
flag[3] = fname.compilation == "./output_00100/compilation.txt"
flag[4] = fname.gravity == "./output_00100/grav_00100."
flag[5] = fname.header == "./output_00100/header_00100.txt"
flag[6] = fname.hydro == "./output_00100/hydro_00100."
flag[7] = fname.hydro_descriptor == "./output_00100/hydro_file_descriptor.txt"
flag[8] = fname.info == "./output_00100/info_00100.txt"
flag[9] = fname.makefile == "./output_00100/makefile.txt"
flag[10] = fname.namelist == "./output_00100/namelist.txt"
flag[11] = fname.output == "./output_00100"
flag[12] = fname.part_descriptor == "./output_00100/part_file_descriptor.txt"
flag[13] = fname.particles == "./output_00100/part_00100."
flag[14] = fname.patchfile == "./output_00100/patches.txt"
flag[15] = fname.rt == "./output_00100/rt_00100."
flag[16] = fname.rt_descriptor == "./output_00100/rt_file_descriptor.txt"
flag[17] = fname.rt_descriptor_v0 == "./output_00100/info_rt_00100.txt"
flag[18] = fname.timer == "./output_00100/timer_00100.txt"
for i in sort(collect(keys(flag)))
if flag[i] == false
ispos = false
println("test 100: flag: ", i, " = false")
end
end
# =================================
fname = Mera.createpath(1000, "./");
flag = Dict()
flag[1] = fname.amr == "./output_01000/amr_01000."
flag[2] = fname.clumps == "./output_01000/clump_01000."
flag[3] = fname.compilation == "./output_01000/compilation.txt"
flag[4] = fname.gravity == "./output_01000/grav_01000."
flag[5] = fname.header == "./output_01000/header_01000.txt"
flag[6] = fname.hydro == "./output_01000/hydro_01000."
flag[7] = fname.hydro_descriptor == "./output_01000/hydro_file_descriptor.txt"
flag[8] = fname.info == "./output_01000/info_01000.txt"
flag[9] = fname.makefile == "./output_01000/makefile.txt"
flag[10] = fname.namelist == "./output_01000/namelist.txt"
flag[11] = fname.output == "./output_01000"
flag[12] = fname.part_descriptor == "./output_01000/part_file_descriptor.txt"
flag[13] = fname.particles == "./output_01000/part_01000."
flag[14] = fname.patchfile == "./output_01000/patches.txt"
flag[15] = fname.rt == "./output_01000/rt_01000."
flag[16] = fname.rt_descriptor == "./output_01000/rt_file_descriptor.txt"
flag[17] = fname.rt_descriptor_v0 == "./output_01000/info_rt_01000.txt"
flag[18] = fname.timer == "./output_01000/timer_01000.txt"
for i in sort(collect(keys(flag)))
if flag[i] == false
ispos = false
println("test 1000: flag: ", i, " = false")
end
end
# =================================
fname = Mera.createpath(10000, "./");
flag = Dict()
flag[1] = fname.amr == "./output_10000/amr_10000."
flag[2] = fname.clumps == "./output_10000/clump_10000."
flag[3] = fname.compilation == "./output_10000/compilation.txt"
flag[4] = fname.gravity == "./output_10000/grav_10000."
flag[5] = fname.header == "./output_10000/header_10000.txt"
flag[6] = fname.hydro == "./output_10000/hydro_10000."
flag[7] = fname.hydro_descriptor == "./output_10000/hydro_file_descriptor.txt"
flag[8] = fname.info == "./output_10000/info_10000.txt"
flag[9] = fname.makefile == "./output_10000/makefile.txt"
flag[10] = fname.namelist == "./output_10000/namelist.txt"
flag[11] = fname.output == "./output_10000"
flag[12] = fname.part_descriptor == "./output_10000/part_file_descriptor.txt"
flag[13] = fname.particles == "./output_10000/part_10000."
flag[14] = fname.patchfile == "./output_10000/patches.txt"
flag[15] = fname.rt == "./output_10000/rt_10000."
flag[16] = fname.rt_descriptor == "./output_10000/rt_file_descriptor.txt"
flag[17] = fname.rt_descriptor_v0 == "./output_10000/info_rt_10000.txt"
flag[18] = fname.timer == "./output_10000/timer_10000.txt"
for i in sort(collect(keys(flag)))
if flag[i] == false
ispos = false
println("test 10000: flag: ", i, " = false")
end
end
@test ispos
end
@testset "getproc2string - out" begin
fname = Mera.getproc2string("./", Int32(1) )
flag1 = fname == "./out00001"
fname = Mera.getproc2string("./", Int32(10) )
flag10 = fname == "./out00010"
fname = Mera.getproc2string("./", Int32(100) )
flag100 = fname == "./out00100"
fname = Mera.getproc2string("./", Int32(1000) )
flag1000 = fname == "./out01000"
fname = Mera.getproc2string("./", Int32(10000) )
flag10000 = fname == "./out10000"
@test flag1 == flag10 == flag100 == flag1000 == flag10000
end
@testset "getproc2string - txt" begin
fname = Mera.getproc2string("./",true , 1 )
flag1 = fname == "./txt00001"
fname = Mera.getproc2string("./", true, 10 )
flag10 = fname == "./txt00010"
fname = Mera.getproc2string("./", true, 100 )
flag100 = fname == "./txt00100"
fname = Mera.getproc2string("./", true, 1000 )
flag1000 = fname == "./txt01000"
fname = Mera.getproc2string("./", true, 10000 )
flag10000 = fname == "./txt10000"
@test flag1 == flag10 == flag100 == flag1000 == flag10000
end
end
end
# ===================================================================
@testset "getinfo general" begin
printscreen("general tests:")
verbose(true)
@test verbose_status(true)
verbose(false)
@test verbose_status(false)
verbose(nothing)
@test verbose_status(nothing)
showprogress(true)
@test showprogress_status(true)
showprogress(false)
@test showprogress_status(false)
showprogress(nothing)
@test showprogress_status(nothing)
@test view_argtypes()
@test view_namelist(output, path)
@test view_patchfile(output, path)
end
@test memory_units()
@test module_view()
#@test_broken call_bell() #skip=true # cannot test on GitHub
#@test_broken call_notifyme() #skip=true # cannot test on GitHub
# ===================================================================
@testset "getinfo" begin
# main functionality
printscreen("getinfo:")
@test infotest(output, path)
# simulation details
info = getinfo(output, path, verbose=false)
@test info.output == output
@test info.descriptor.hversion == 1 # hydro reader version
@test info.descriptor.pversion == 1 # particle reader version
if info.levelmin !== info.levelmax # for uniform grid sim time = 0.
@test info.time ≈ 0.330855641315456 rtol=1e-13
@test gettime(info) ≈ 0.330855641315456 rtol=1e-13
@test gettime(info, :Myr) ≈ 4.9320773034440295 rtol=1e-13
end
@test info.rt == false
@test info.sinks == false
@test info.clumps == false
@test info.particles == true
@test info.hydro == true
@test info.gravity == true
# check variables
end
# ===================================================================
@testset "info overview" begin
printscreen("info overview:")
@test_broken simoverview(output, simpath)
@test viewfieldstest(output, path)
@test viewfilescontent(output, path)
end
# ===================================================================
@testset "hydro data inspection" begin
printscreen("hydro data inspection:")
@test gethydro_infocheck(output, path)
@test gethydro_allvars(output, path)
@test gethydro_selectedvars(output, path)
@test gethydro_cpuvar(output, path)
@test gethydro_negvalues(output, path)
@test gethydro_lmaxEQlmin(output, path)
@test hydro_smallr(output, path)
@test hydro_smallc(output, path)
@test hydro_viewfields(output, path)
@test hydro_amroverview(output, path)
@test hydro_dataoverview(output, path)
@test hydro_gettime(output, path)
end
# ===================================================================
@testset "hydro selected ranges" begin
printscreen("hydro selected ranges:")
@test hydro_range_codeunit(output, path)
end
# ===================================================================
@testset "particle data inspection" begin
printscreen("particle data inspection:")
@test getparticles_infocheck(output, path)
info = getinfo(output, path, verbose=false)
if info.levelmin !== info.levelmax
@test_broken getparticles_number(output, path)
else
@test getparticles_number(output, path)
end
# test number of stars and dm
@test getparticles_allvars(output, path)
@test getparticles_selectedvars(output, path)
@test getparticles_cpuvar(output, path)
@test particles_viewfields(output, path)
@test particles_amroverview(output, path)
@test particles_dataoverview(output, path)
@test particles_gettime(output, path)
end
# ===================================================================
@testset "particles selected data" begin
printscreen("particle selected ranges:")
@test particles_range_codeunit(output, path)
end
# ===================================================================
@testset "gravity data inspection" begin
printscreen("gravity data inspection:")
@test getgravity_infocheck(output, path)
@test getgravity_allvars(output, path)
@test getgravity_selectedvars(output, path)
@test getgravity_cpuvar(output, path)
@test gravity_viewfields(output, path)
@test gravity_amroverview(output, path)
@test gravity_dataoverview(output, path)
@test gravity_gettime(output, path)
end
# ===================================================================
@testset "gravity selected data" begin
printscreen("gravity selected ranges:")
@test gravity_range_codeunit(output, path)
end
# =================================================================== | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 252 |
@test save_jld2(output, path)
@test load_data(output, path)
@test save_different_order_jld2(output, path)
@test convert_jld2(output, path)
@test info_jld2(output, path)
@test viewdata_all(output)
@test load_data(output, path)
@test check_filenames() | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2694 | using Mera
using Mera.JuliaDB
using Test
using Downloads
using Tar
#run(`mkdir simulations`)
#mkdir("simulations")
include("screen_output.jl")
include("overview/00_info.jl")
include("overview/00_simoverview.jl")
include("inspection/01_hydro_inspection.jl")
include("inspection/01_particle_inspection.jl")
include("inspection/01_gravity_inspection.jl")
include("varselection/02_hydro_selections.jl")
include("varselection/02_particles_selections.jl")
include("varselection/02_gravity_selections.jl")
include("getvar/03_hydro_getvar.jl")
include("getvar/03_particles_getvar.jl")
include("errors/04_error_checks.jl")
include("jld2files/05_mera_files.jl")
include("clumps/inspection.jl")
#simpath = "./simulations/"
#path = "./simulations/01_spiral/"
@testset "MERA tests" begin
global simpath = "./"
global path = "./simulations/"
global output = 2
@testset "AMR" begin
Downloads.download("www.usm.uni-muenchen.de/CAST/behrendt/simulations.tar", pwd() * "/simulations.tar")
tar = open("./simulations.tar")
dir = Tar.extract(tar, "simulations")
close(tar)
include("alltests.jl")
if Sys.iswindows()
#rm(pwd() * "\\simulations", recursive=true)
#rm(pwd() * "\\simulations.tar")
else
rm(pwd() * "/simulations", recursive=true)
rm(pwd() * "/simulations.tar")
end
end
global simpath = "./"
global path = "./simulations/"
global output = 1
@testset "Uniform Grid" begin
Downloads.download("www.usm.uni-muenchen.de/CAST/behrendt/simulation_ugrid.tar", pwd() * "/simulations.tar")
tar = open("./simulations.tar")
dir = Tar.extract(tar, "simulations")
close(tar)
include("alltests.jl")
if Sys.iswindows()
#rm(pwd() * "\\simulations", recursive=true)
#rm(pwd() * "\\simulations.tar")
else
rm(pwd() * "/simulations", recursive=true)
rm(pwd() * "/simulations.tar")
end
end
global simpath = "./"
global path = "./simulations/"
global output = 100
@testset "Clumps Simulation" begin
Downloads.download("www.usm.uni-muenchen.de/CAST/behrendt/simulation_clumps.tar", pwd() * "/simulations.tar")
tar = open("./simulations.tar")
dir = Tar.extract(tar, "simulations")
close(tar)
include("clumptests.jl")
end
end
# basic calcs: msum, com, bulk vel; average
# old RAMSES version: gethydro, getparticles
# humanize, getunit
# error amroverview for uniform grid (hydro, particles, etc.)
# hydro_range_codeunit,gravity_range_codeunit add test for uniform grid
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 255 | function printscreen(message)
println()
println()
println()
printstyled("--------------------------------------\n", color=:cyan)
@info(message)
printstyled("--------------------------------------\n", color=:cyan)
println()
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 3305 |
gas, irho1, ip1, ics1= prepare_data1(output, path)
@testset "show possible vars" begin
getvar()
end
@testset "rho" begin
@test test_rho(gas) ≈ irho1 rtol=1e-10
@test test_p(gas) ≈ ip1 rtol=1e-10
end
# test mass
@testset "mass" begin
mass_ref = 1.0000000000019456e16
mass_tot = sum( getvar(gas, :mass, :Msol) )
mass_tot_function1 = sum(getmass(gas)) .* gas.info.scale.Msol
mass_tot_function2 = msum(gas, :Msol)
@test mass_ref ≈ mass_tot rtol=1e-10
@test mass_tot ≈ mass_tot_function1 rtol=1e-10
@test mass_tot ≈ mass_tot_function2 rtol=1e-10
end
# test masking on mass
@testset "mass masking" begin
if gas.info.levelmin !== gas.info.levelmax
mask1 = getvar(gas, :level) .> 6
else
mask1 = getvar(gas, :rho, :nH) .< 0.1
end
mass1 = sum( getvar(gas, :mass, :Msol, mask=mask1))
mass1_function1 = sum(getmass(gas)[mask1]) .* gas.info.scale.Msol
mass1_function2 = msum(gas, :Msol, mask=mask1)
@test mass1 ≈ mass1_function1 rtol=1e-10
@test mass1 ≈ mass1_function2 rtol=1e-10
end
# test cs
@testset "cs" begin
cs = getvar(gas, :cs, :cm_s)
cs_av = sum(cs) / length(cs)
@test cs_av ≈ ics1 rtol=1e-10
end
# test vx, vy, vz
@testset "vx, vy, vz, |v|" begin
vxdata = getvar(gas, :vx, :km_s)
vxdata = sum(vxdata) / length(vxdata)
@test vxdata == 20. #km/s
vydata = getvar(gas, :vy, :km_s)
vydata = sum(vydata) / length(vydata)
@test vydata == 30. #km/s
vzdata = getvar(gas, :vz, :km_s)
vzdata = sum(vzdata) / length(vzdata)
@test vzdata == 40. #km/s
# test |v|
vref = sqrt(20. ^2 + 30. ^2 + 40. ^2)
vdata = getvar(gas, :v, :km_s)
vdata = sum(vdata) / length(vdata)
@test vref ≈ vdata rtol=1e-10
end
if gas.info.levelmin !== gas.info.levelmax
@testset "cellsize, volume" begin
leveldata = getvar(gas, :level)
cellsize_ref = gas.boxlen ./ 2 .^leveldata
cellsize_data = getvar(gas, :cellsize);
@test cellsize_ref == cellsize_data
volume_ref = cellsize_ref .^3
volume_data = getvar(gas, :volume)
@test volume_ref == volume_data
end
end
@testset "get positions/velocities" begin
@test check_positions_hydro(output, path)
#@test check_positions_part(output, path)
@test check_velocities_hydro(output, path)
end
@testset "get extent" begin
rx,ry,rz = getextent(gas, :kpc)
rxu, ryu, rzu = getextent(gas, unit=:kpc)
@test rx == rxu
@test ry == ryu
@test rz == rzu
rx,ry,rz = getextent(gas, :kpc, center=[:bc])
@test rx[1] ≈ -50 atol=1e-10
@test rx[2] ≈ 50 atol=1e-10
@test ry[1] ≈ -50 atol=1e-10
@test ry[2] ≈ 50 atol=1e-10
@test rz[1] ≈ -50 atol=1e-10
@test rz[2] ≈ 50 atol=1e-10
rx,ry,rz = getextent(gas, :kpc, center=[0.5,0.5,0.5])
@test rx[1] ≈ -50 atol=1e-10
@test rx[2] ≈ 50 atol=1e-10
@test ry[1] ≈ -50 atol=1e-10
@test ry[2] ≈ 50 atol=1e-10
@test rz[1] ≈ -50 atol=1e-10
@test rz[2] ≈ 50 atol=1e-10
rx,ry,rz = getextent(gas, :kpc, center=[0.5,0.5,0.5], center_unit=:kpc)
@test rx[1] ≈ -0.5 atol=1e-10
@test rx[2] ≈ 99.5 atol=1e-10
@test ry[1] ≈ -0.5 atol=1e-10
@test ry[2] ≈ 99.5 atol=1e-10
@test rz[1] ≈ -0.5 atol=1e-10
@test rz[2] ≈ 99.5 atol=1e-10
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 1190 | @testset "get positions/velocities" begin
@test check_positions_part(output, path)
@test check_velocities_part(output, path)
end
@testset "get extent" begin
info = getinfo(output, path, verbose=false)
part = getparticles(info, verbose=false)
rx,ry,rz = getextent(part, :kpc)
rxu, ryu, rzu = getextent(part, unit=:kpc)
@test rx == rxu
@test ry == ryu
@test rz == rzu
rx,ry,rz = getextent(part, :kpc, center=[:bc])
@test rx[1] ≈ -50 atol=1e-10
@test rx[2] ≈ 50 atol=1e-10
@test ry[1] ≈ -50 atol=1e-10
@test ry[2] ≈ 50 atol=1e-10
@test rz[1] ≈ -50 atol=1e-10
@test rz[2] ≈ 50 atol=1e-10
rx,ry,rz = getextent(part, :kpc, center=[0.5,0.5,0.5])
@test rx[1] ≈ -50 atol=1e-10
@test rx[2] ≈ 50 atol=1e-10
@test ry[1] ≈ -50 atol=1e-10
@test ry[2] ≈ 50 atol=1e-10
@test rz[1] ≈ -50 atol=1e-10
@test rz[2] ≈ 50 atol=1e-10
rx,ry,rz = getextent(part, :kpc, center=[0.5,0.5,0.5], center_unit=:kpc)
@test rx[1] ≈ -0.5 atol=1e-10
@test rx[2] ≈ 99.5 atol=1e-10
@test ry[1] ≈ -0.5 atol=1e-10
@test ry[2] ≈ 99.5 atol=1e-10
@test rz[1] ≈ -0.5 atol=1e-10
@test rz[2] ≈ 99.5 atol=1e-10
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 1561 |
# ===================================================================
@testset "getinfo" begin
printscreen("getinfo:")
info = getinfo(output, path);
@test info.clumps == true
end
# ===================================================================
@testset "clumps data inspection" begin
printscreen("clumps data inspection:")
@testset "info vars" begin
info = getinfo(output, path);
@test length(info.clumps_variable_list) == 12
end
@testset "all vars" begin
info = getinfo(output, path);
clumps = getclumps(info)
@test length( colnames(clumps.data) ) == 12
@test length(clumps.data) == 7
end
@testset "selected vars" begin
info = getinfo(output, path);
clumps = getclumps(info, [:peak_x, :peak_y, :peak_z]);
@test length(colnames(clumps.data)) == 3
Ncol = propertynames(clumps.data.columns)
@test :peak_x in Ncol && :peak_y in Ncol && :peak_z in Ncol
end
@testset "info overview" begin
printscreen("info overview:")
@test_broken simoverview(output, simpath)
@test viewfilescontent(output, path)
end
@testset "gravity data inspection" begin
printscreen("gravity data inspection:")
@test clumps_dataoverview(output, path)
@test clumps_gettime(output, path)
end
end
# ===================================================================
#@testset "clumps selected ranges" begin
# printscreen("clumps selected ranges:")
#
#end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 308 | function clumps_dataoverview(output, path)
info =getinfo(output, path)
clumps = getclumps(info)
dataoverview(clumps)
return true
end
function clumps_gettime(output, path)
info =getinfo(output, path)
clumps = getclumps(info)
return gettime(info, :Myr) == gettime(clumps, :Myr)
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 4342 |
function save_clumps_jld2(output, path)
info = getinfo(output, path)
clumps = getclumps(info)
savedata(clumps, :write)
savedata(clumps, "./", :write)
savedata(clumps, "./", fmode=:write)
vd = viewdata(output)
stdata = keys(vd)
flag1 = in("clumps", stdata)
println("flag1: clumps in jld2 file? ", flag1)
println()
gas = gethydro(info)
savedata(gas, fmode=:append)
vd = viewdata(output)
stdata = keys(vd)
flag2 = in("hydro", stdata)
println("flag2: hydro in jld2 file? ", flag2)
println()
part = getparticles(info)
savedata(part, fmode=:append)
grav = getgravity(info)
savedata(grav, fmode=:append)
vd = viewdata(output)
stdata = keys(vd)
flag3 = in("hydro", stdata)
flag4 = in("gravity", stdata)
flag5 = in("particles", stdata)
println("flag3: hydro in jld2 file? ", flag3)
println("flag4: gravity in jld2 file? ", flag4)
println("flag5: particles in jld2 file? ", flag5)
println()
println()
return flag1 == true && flag2 == true && flag3 == true && flag4 == true && flag5 == true
end
function save_clumps_different_order_jld2(output, path)
info = getinfo(output, path)
part = getparticles(info)
savedata(part, fmode=:write)
vd = viewdata(output)
stdata = keys(vd)
flag1 = in("particles", stdata)
flag1a = !in("clumps", stdata)
clumps = getclumps(info)
savedata(clumps, fmode=:write)
vd = viewdata(output)
stdata = keys(vd)
flag2 = in("clumps", stdata)
flag2a = !in("particles", stdata)
println("flag1: particles in jld2 file? ", flag1)
println("flag1a: no clumps in jld2 file? ", flag1a)
println()
println("flag2: clumps in jld2 file? ", flag2)
println("flag2a: no particles in jld2 file? ", flag2a)
println()
println()
return flag1 == true && flag1a == true && flag2 == true && flag2a == true
end
function convert_clumps_jld2(output, path)
st = convertdata(output, [:clumps], path=path)
vd = viewdata(output)
stdata = keys(vd)
flag1 = in("clumps", stdata)
println("flag1: clumps in jld2 file? ", flag1)
flag1a = !in("hydro", stdata)
println("flag1a: hydro not in jld2 file? ", flag1a)
println()
st = convertdata(output, :clumps, path=path)
vd = viewdata(output)
stdata = keys(vd)
flag2 = in("clumps", stdata)
println("flag2: hydro in jld2 file? ", flag2)
flag2a = !in("hydro", stdata)
println("flag2a: hydro not in jld2 file? ", flag2a)
println()
st = convertdata(output, path=path, fpath=".")
vd = viewdata(output)
stdata = keys(vd)
flag3 = in("hydro", stdata)
flag4 = in("gravity", stdata)
flag5 = in("particles", stdata)
flag6 = in("clumps", stdata)
println("flag3: hydro in jld2 file? ", flag3)
println("flag4: gravity in jld2 file? ", flag4)
println("flag5: particles in jld2 file? ", flag5)
println("flag6: clumps in jld2 file? ", flag6)
println()
return flag1 == flag1a == flag2 == flag2a ==flag3 == flag4 == flag5 == flag6 == true
end
function load_uaclumps_data(output, path)
info = getinfo(output, path)
gas = gethydro(info)
gasconv = loaddata(output, :hydro)
flag1 = gas.data == gasconv.data
println()
println("flag1: data load hydro: ", flag1)
println()
part = getparticles(info)
partconv = loaddata(output, :particles)
flag2 = part.data == partconv.data
println()
println("flag2: data load particles: ", flag2)
println()
grav = getgravity(info)
gravconv = loaddata(output, :gravity)
flag3 = grav.data == gravconv.data
println()
println("flag3: data load gravity: ", flag3)
println()
clumps = getclumps(info)
clumpconv = loaddata(output, :clumps)
flag4 = clumps.data == clumpconv.data
println()
println("flag4: data load clumps: ", flag4)
println()
clumpconv = loaddata(output, "./", :clumps)
flag5 = clumps.data == clumpconv.data
println()
println("flag5: data load clumps: ", flag5)
println()
clumpconv = loaddata(output, "./", datatype=:clumps)
flag6 = clumps.data == clumpconv.data
println()
println("flag6: data load clumps: ", flag6)
println()
return flag1 == flag2 == flag3 == flag4 == flag5 == flag6 == true
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 1113 |
function checktypes_error(output, path, datatype)
info = getinfo(output, path, verbose=false)
info.hydro = false
info.particles = false
info.gravity = false
info.amr = false
info.rt = false
info.clumps = false
info.sinks = false
if datatype == :hydro
gethydro(info)
elseif datatype == :particles
getparticles(info)
elseif datatype == :gravity
getgravity(info)
elseif datatype == :clumps
getclumps(info)
elseif datatype == :amr
Mera.checkfortype(info, :amr)
elseif datatype == :rt
Mera.checkfortype(info, :rt)
elseif datatype == :sinks
Mera.checkfortype(info, :sinks)
end
return
end
function checklevelmax_error(output, path)
info = getinfo(output, path, verbose=false)
gas = gethydro(info, lmax=10)
return
end
function checklevelmin_error(output, path)
info = getinfo(output, path, verbose=false)
gas = gethydro(info, lmax=1)
return
end
function checkfolder_error(path)
info = getinfo(3, path)
return
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 3577 | function prepare_data1(output, path)
info = getinfo(output, path, verbose=false)
gas = gethydro(info, verbose=false, show_progress=false)
if info.levelmin !== info.levelmax
t = select(gas.data, (:level, :cx, :cy, :cz) )
else
t = select(gas.data, (:cx, :cy, :cz) )
end
kB = gas.info.constants.kB #1.38062e-16 # erg/K
T = 1e4 #K
mu = 100. / 76.
mH = gas.info.constants.mH #1.66e-24 #g
irho = 6.770254302002489e-22 #!g/cm^3 = 10 Msol_pc^3
ip = irho * kB * T/ (mu * mH) # g/cm/s^2
gamma = gas.info.gamma
ics = sqrt.(ip/irho * gamma) #cm/s
N = length(t)
rho = fill( irho /gas.info.unit_d , N)
#vx = fill(20. * 1e5 / gas.info.unit_v, N );
#vy = fill(30. * 1e5 / gas.info.unit_v, N );
#vz = fill(40. * 1e5 / gas.info.unit_v, N );
vx = fill(20. / gas.info.scale.km_s, N );
vy = fill(30. / gas.info.scale.km_s, N );
vz = fill(40. / gas.info.scale.km_s, N );
p = fill( ip / gas.info.unit_d / gas.info.unit_v^2 , N);
if info.levelmin !== info.levelmax
shift = 0
else
shift = -1
end
t = insertcols(t, 5+shift, :rho => rho)
t = insertcols(t, 6+shift, :vx => vx)
t = insertcols(t, 7+shift, :vy => vy)
t = insertcols(t, 8+shift, :vz => vz)
t = insertcols(t, 9+shift, :p => p)
gas.data = t;
return gas, irho, ip / gas.info.unit_d / gas.info.unit_v^2, ics
end
function test_rho(dataobject)
rhodata = getvar(dataobject, :rho, :g_cm3)
rhodata = sum(rhodata) / length(rhodata)
return rhodata
end
function test_p(dataobject)
pdata = getvar(dataobject, :p)
pdata = sum(pdata) / length(pdata)
return pdata
end
function check_positions_hydro(output, path)
info = getinfo(output, path, verbose=false)
gas = gethydro(info, verbose=false)
x,y,z = getpositions(gas, :kpc, center=[:bc] )
xv = getvar(gas, :x, :kpc, center=[:bc])
yv = getvar(gas, :y, :kpc, center=[:bc])
zv = getvar(gas, :z, :kpc, center=[:bc]);
flag1 = x == xv
flag2 = y == yv
flag3 = z == zv
x,y,z = getpositions(gas, unit=:kpc, center=[:bc] )
xv = getvar(gas, :x, :kpc, center=[:bc])
yv = getvar(gas, :y, :kpc, center=[:bc])
zv = getvar(gas, :z, :kpc, center=[:bc]);
flag4 = x == xv
flag5 = y == yv
flag6 = z == zv
return flag1 == true && flag2 == true && flag3 == true && flag4 == true && flag5 == true && flag6 == true
end
function check_velocities_hydro(output, path)
info = getinfo(output, path, verbose=false)
gas = gethydro(info, verbose=false)
vx,vy,vz = getvelocities(gas, :km_s)
vxv = getvar(gas, :vx, :km_s)
vyv = getvar(gas, :vy, :km_s)
vzv = getvar(gas, :vz, :km_s);
flag1 = vx == vxv
flag2 = vy == vyv
flag3 = vz == vzv
vx,vy,vz = getvelocities(gas, unit=:km_s )
vxv = getvar(gas, :vx, :km_s)
vyv = getvar(gas, :vy, :km_s)
vzv = getvar(gas, :vz, :km_s);
flag4 = vx == vxv
flag5 = vy == vyv
flag6 = vz == vzv
vel = getvar(gas, [:vx, :vy, :vz], :km_s)
flag7 = vx == vel[:vx]
flag8 = vy == vel[:vy]
flag9 = vz == vel[:vz]
vel = getvar(gas, [:vx, :vy, :vz], [:km_s, :km_s, :km_s])
flag10 = vx == vel[:vx]
flag11 = vy == vel[:vy]
flag12 = vz == vel[:vz]
return flag1 == true && flag2 == true && flag3 == true &&
flag4 == true && flag5 == true && flag6 == true &&
flag7 == true && flag8 == true && flag9 == true &&
flag10 == true && flag11 == true && flag12 == true
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 1474 |
function check_positions_part(output, path)
info = getinfo(output, path, verbose=false)
part = getparticles(info, verbose=false)
x,y,z = getpositions(part, :kpc, center=[:bc] )
xv = getvar(part, :x, :kpc, center=[:bc])
yv = getvar(part, :y, :kpc, center=[:bc])
zv = getvar(part, :z, :kpc, center=[:bc]);
flag1 = x == xv
flag2 = y == yv
flag3 = z == zv
x,y,z = getpositions(part, unit=:kpc, center=[:bc] )
xv = getvar(part, :x, :kpc, center=[:bc])
yv = getvar(part, :y, :kpc, center=[:bc])
zv = getvar(part, :z, :kpc, center=[:bc]);
flag4 = x == xv
flag5 = y == yv
flag6 = z == zv
return flag1 == true && flag2 == true && flag3 == true && flag4 == true && flag5 == true && flag6 == true
end
function check_velocities_part(output, path)
info = getinfo(output, path, verbose=false)
part = getparticles(info, verbose=false)
vx,vy,vz = getvelocities(part, :km_s)
vxv = getvar(part, :vx, :km_s)
vyv = getvar(part, :vy, :km_s)
vzv = getvar(part, :vz, :km_s);
flag1 = vx == vxv
flag2 = vy == vyv
flag3 = vz == vzv
vx,vy,vz = getvelocities(part, unit=:km_s )
vxv = getvar(part, :vx, :km_s)
vyv = getvar(part, :vy, :km_s)
vzv = getvar(part, :vz, :km_s);
flag4 = vx == vxv
flag5 = vy == vyv
flag6 = vz == vzv
return flag1 == true && flag2 == true && flag3 == true && flag4 == true && flag5 == true && flag6 == true
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2714 |
function getgravity_infocheck(output, path)
info = getinfo(output, path)
grav = getgravity(info);
return grav.info == info
end
function getgravity_allvars(output, path)
info = getinfo(output, path)
grav = getgravity(info);
return length(grav.selected_gravvars) == 4
end
function getgravity_selectedvars(output, path)
info = getinfo(output, path)
grav = getgravity(info, :epot)
Ncol = propertynames(grav.data.columns)
Ncol_flag1 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 5 && :epot in Ncol Ncol_flag1 = true end
else
if length(Ncol) == 4 && :epot in Ncol Ncol_flag1 = true end
end
println("Ncol_flag1 = ", Ncol_flag1 )
grav = getgravity(info, [:epot, :ax])
Ncol = propertynames(grav.data.columns)
Ncol_flag2 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 6 && :epot in Ncol && :ax in Ncol Ncol_flag2 = true end
else
if length(Ncol) == 5 && :epot in Ncol && :ax in Ncol Ncol_flag2 = true end
end
println("Ncol_flag2 = ", Ncol_flag2 )
return Ncol_flag1 == true && Ncol_flag2 == true
end
function getgravity_cpuvar(output, path)
info = getinfo(output, path)
grav = getgravity(info, [:cpu, :epot])
Ncol = propertynames(grav.data.columns)
Ncol_flag1 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 6 && :epot in Ncol && :cpu in Ncol Ncol_flag1 = true end
else
if length(Ncol) == 5 && :epot in Ncol && :cpu in Ncol Ncol_flag1 = true end
end
println("Ncol_flag1 = ", Ncol_flag1 )
grav = getgravity(info, [:cpu, :all])
Ncol = propertynames(grav.data.columns)
Ncol_flag2 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 9 && :epot in Ncol && :cpu in Ncol Ncol_flag2 = true end
else
if length(Ncol) == 8 && :epot in Ncol && :cpu in Ncol Ncol_flag2 = true end
end
println("Ncol_flag2 = ", Ncol_flag2 )
return Ncol_flag1 == true && Ncol_flag2 == true
end
function gravity_amroverview(output, path)
info =getinfo(output, path)
if info.levelmin !== info.levelmax
grav = getgravity(info)
amroverview(grav)
end
return true
end
function gravity_dataoverview(output, path)
info =getinfo(output, path)
grav = getgravity(info)
dataoverview(grav)
return true
end
function gravity_viewfields(output, path)
info =getinfo(output, path)
grav = getgravity(info)
viewfields(grav)
return true
end
function gravity_gettime(output, path)
info =getinfo(output, path)
grav = getgravity(info)
return gettime(info, :Myr) == gettime(grav, :Myr)
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 4000 |
function gethydro_infocheck(output, path)
info = getinfo(output, path)
gas = gethydro(info);
return gas.info == info
end
function gethydro_lmaxEQlmin(output, path)
info = getinfo(output, path)
gas = gethydro(info, lmax=info.levelmin);
Ncol = propertynames(gas.data.columns)
return !(:level in Ncol) # lmax=levelmin -> treated as uniform grid
end
function gethydro_allvars(output, path)
info = getinfo(output, path)
gas = gethydro(info);
return length(gas.selected_hydrovars) == 6
end
function gethydro_selectedvars(output, path)
info = getinfo(output, path)
gas = gethydro(info, :rho)
Ncol = propertynames(gas.data.columns)
Ncol_flag1 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 5 && :rho in Ncol Ncol_flag1 = true end
else
if length(Ncol) == 4 && :rho in Ncol Ncol_flag1 = true end
end
println("Ncol_flag1 = ", Ncol_flag1 )
gas = gethydro(info, [:rho, :vx])
Ncol = propertynames(gas.data.columns)
Ncol_flag2 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 6 && :rho in Ncol && :vx in Ncol Ncol_flag2 = true end
else
if length(Ncol) == 5 && :rho in Ncol && :vx in Ncol Ncol_flag2 = true end
end
println("Ncol_flag2 = ", Ncol_flag2 )
gas = gethydro(info, [:rho, :vx, :vy, :vz, :p])
Ncol = propertynames(gas.data.columns)
Ncol_flag3 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 9 && :rho in Ncol && :vx in Ncol && :vy in Ncol &&
:vz in Ncol && :p in Ncol Ncol_flag3 = true end
else
if length(Ncol) == 8 && :rho in Ncol && :vx in Ncol && :vy in Ncol &&
:vz in Ncol && :p in Ncol Ncol_flag3 = true end
end
println("Ncol_flag3 = ", Ncol_flag3 )
return Ncol_flag1 == true && Ncol_flag2 == true && Ncol_flag3 == true
end
function gethydro_cpuvar(output, path)
info = getinfo(output, path)
gas = gethydro(info, [:cpu, :rho]);
Ncol = propertynames(gas.data.columns)
Ncol_flag1 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 6 && :cpu in Ncol Ncol_flag1 = true end
else
if length(Ncol) == 5 && :cpu in Ncol Ncol_flag1 = true end
end
println("flag1: CPU numbers loaded = ", Ncol_flag1 )
gas = gethydro(info, [:cpu, :all]);
Ncol = propertynames(gas.data.columns)
Ncol_flag2 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 11 && :cpu in Ncol Ncol_flag2 = true end
else
if length(Ncol) == 10 && :cpu in Ncol Ncol_flag2 = true end
end
println("flag2: CPU numbers loaded = ", Ncol_flag2 )
return Ncol_flag1 == true && Ncol_flag2 == true
end
function gethydro_negvalues(output, path)
info = getinfo(output, path)
gas = gethydro(info, check_negvalues=true);
return true
end
function hydro_smallr(output, path)
info = getinfo(output, path)
gas = gethydro(info, smallr=1e-11)
rho = select(gas.data, :rho)
println("min-rho: ", minimum(rho))
return minimum(rho) >= 1e-11 && gas.smallr >= 1e-11
end
function hydro_smallc(output, path)
info = getinfo(output, path)
gas = gethydro(info, smallc=1e-7)
p = select(gas.data, :p)
println("min-p: ", minimum(p))
return minimum(p) >= 1e-7 && gas.smallc >= 1e-7
end
function hydro_amroverview(output, path)
info =getinfo(output, path)
if info.levelmin !== info.levelmax
gas = gethydro(info)
amroverview(gas)
end
return true
end
function hydro_dataoverview(output, path)
info =getinfo(output, path)
gas = gethydro(info)
dataoverview(gas)
return true
end
function hydro_viewfields(output, path)
info =getinfo(output, path)
gas = gethydro(info)
viewfields(gas)
return true
end
function hydro_gettime(output, path)
info =getinfo(output, path)
gas = gethydro(info)
return gettime(info, :Myr) == gettime(gas, :Myr)
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 3164 |
function getparticles_infocheck(output, path)
info = getinfo(output, path)
part = getparticles(info);
return part.info == info
end
function getparticles_number(output, path)
info = getinfo(output, path)
part = getparticles(info);
println("loaded particles: ", length(part.data))
println("information from getinfo: ", info.part_info.Nstars + info.part_info.Ndm)
return length(part.data) == (info.part_info.Nstars + info.part_info.Ndm)
end
function getparticles_allvars(output, path)
info = getinfo(output, path)
part = getparticles(info);
if info.levelmin !== info.levelmax
return length(part.selected_partvars) == 13
else
return length(part.selected_partvars) == 12
end
end
function getparticles_selectedvars(output, path)
info = getinfo(output, path)
part = getparticles(info, :mass)
Ncol = propertynames(part.data.columns)
Ncol_flag1 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 8 && :mass in Ncol Ncol_flag1 = true end
else
if length(Ncol) == 7 && :mass in Ncol Ncol_flag1 = true end
end
println("Ncol_flag1 = ", Ncol_flag1 )
part = getparticles(info, [:mass, :metals])
Ncol = propertynames(part.data.columns)
Ncol_flag2 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 9 && :mass in Ncol && :metals in Ncol Ncol_flag2 = true end
else
if length(Ncol) == 8 && :mass in Ncol && :metals in Ncol Ncol_flag2 = true end
end
println("Ncol_flag2 = ", Ncol_flag2 )
return Ncol_flag1 == true && Ncol_flag2 == true
end
function getparticles_cpuvar(output, path)
info = getinfo(output, path)
part = getparticles(info, [:cpu, :mass]);
Ncol = propertynames(part.data.columns)
Ncol_flag1 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 9 && :cpu in Ncol Ncol_flag1 = true end
else
if length(Ncol) == 8 && :cpu in Ncol Ncol_flag1 = true end
end
println("flag1: CPU numbers loaded = ", Ncol_flag1 )
part = getparticles(info, [:cpu, :all]);
Ncol = propertynames(part.data.columns)
Ncol_flag2 = false
if info.levelmin !== info.levelmax
if length(Ncol) == 14 && :cpu in Ncol Ncol_flag2 = true end
else
if length(Ncol) == 13 && :cpu in Ncol Ncol_flag2 = true end
end
println("flag2: CPU numbers loaded = ", Ncol_flag2 )
return Ncol_flag1 == true && Ncol_flag2 == true
end
function particles_amroverview(output, path)
info =getinfo(output, path)
if info.levelmin !== info.levelmax
part = getparticles(info)
amroverview(part)
end
return true
end
function particles_dataoverview(output, path)
info =getinfo(output, path)
part = getparticles(info)
dataoverview(part)
return true
end
function particles_viewfields(output, path)
info =getinfo(output, path)
part = getparticles(info)
viewfields(part)
return true
end
function particles_gettime(output, path)
info =getinfo(output, path)
part = getparticles(info)
return gettime(info, :Myr) == gettime(part, :Myr)
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 7338 |
function save_jld2(output, path)
info = getinfo(output, path)
gas = gethydro(info)
savedata(gas, :write)
vd = viewdata(output)
stdata = keys(vd)
flag1 = in("hydro", stdata)
println("flag1: hydro in jld2 file? ", flag1)
println()
savedata(gas, "./", :write)
savedata(gas, "./", fmode=:write)
vd = viewdata(output)
stdata = keys(vd)
flag2 = in("hydro", stdata)
println("flag2: hydro in jld2 file? ", flag2)
println()
part = getparticles(info)
savedata(part, fmode=:append)
grav = getgravity(info)
savedata(grav, fmode=:append)
vd = viewdata(output)
stdata = keys(vd)
flag3 = in("hydro", stdata)
flag4 = in("gravity", stdata)
flag5 = in("particles", stdata)
println("flag3: hydro in jld2 file? ", flag3)
println("flag4: gravity in jld2 file? ", flag4)
println("flag5: particles in jld2 file? ", flag5)
println()
println()
return flag1 == true && flag2 == true && flag3 == true && flag4 == true && flag5 == true
end
function save_different_order_jld2(output, path)
info = getinfo(output, path)
part = getparticles(info)
savedata(part, fmode=:write)
vd = viewdata(output)
stdata = keys(vd)
flag1 = in("particles", stdata)
flag1a = !in("hydro", stdata)
grav = getgravity(info)
savedata(grav, fmode=:write)
vd = viewdata(output)
stdata = keys(vd)
flag2 = in("gravity", stdata)
flag2a = !in("hydro", stdata)
println("flag1: particles in jld2 file? ", flag1)
println("flag1a: no hydro in jld2 file? ", flag1a)
println()
println("flag2: gravity in jld2 file? ", flag2)
println("flag2a: no hydro in jld2 file? ", flag2a)
println()
println()
return flag1 == true && flag1a == true && flag2 == true && flag2a == true
end
function convert_jld2(output, path)
st = convertdata(output, [:hydro], path=path)
vd = viewdata(output)
stdata = keys(vd)
flag1 = in("hydro", stdata)
println("flag1: hydro in jld2 file? ", flag1)
flag1a = !in("particles", stdata)
println("flag1a: particles not in jld2 file? ", flag1a)
println()
st = convertdata(output, :hydro, path=path)
vd = viewdata(output)
stdata = keys(vd)
flag2 = in("hydro", stdata)
println("flag2: hydro in jld2 file? ", flag2)
flag2a = !in("particles", stdata)
println("flag2a: particles not in jld2 file? ", flag2a)
println()
st = convertdata(output, path=path, fpath=".")
vd = viewdata(output)
stdata = keys(vd)
flag3 = in("hydro", stdata)
flag4 = in("gravity", stdata)
flag5 = in("particles", stdata)
println("flag3: hydro in jld2 file? ", flag3)
println("flag4: gravity in jld2 file? ", flag4)
println("flag5: particles in jld2 file? ", flag5)
println()
return flag1 == flag1a == flag2 == flag2a == flag3 == flag4 == flag5 == true
end
function info_jld2(output, path)
info = getinfo(output, path)
infoconv = infodata(output)
infoconv = infodata(output, "./", :hydro)
infoconv = infodata(output, "./", datatype=:hydro)
infoconv = infodata(output, :hydro)
# test reading only
infopart = infodata(output, :particles)
infograv = infodata(output, :gravity)
# ===================
info_fields = propertynames(info)
field_comparison = true
field_comparison_data = true
for i in info_fields
fieldef = isdefined(infoconv, i)
if !fieldef
field_comparison = false
println("missing field: ", i)
else
field_data_infoconv = getfield(infoconv, i)
field_data_info = getfield(info, i)
if i == :fnames
comparefields(info.fnames, infoconv.fnames, field_comparison_data)
elseif i == :descriptor
comparefields(info.descriptor, infoconv.descriptor, field_comparison_data)
elseif i == :files_content
comparefields(info.files_content, infoconv.files_content, field_comparison_data)
elseif i == :scale
comparefields(info.scale, infoconv.scale, field_comparison_data)
elseif i == :grid_info
comparefields(info.grid_info, infoconv.grid_info, field_comparison_data)
elseif i == :part_info
comparefields(info.part_info, infoconv.part_info, field_comparison_data)
elseif i == :compilation
comparefields(info.compilation, infoconv.compilation, field_comparison_data)
elseif i == :constants
comparefields(info.constants, infoconv.constants, field_comparison_data)
else
compare_field_data = field_data_infoconv == field_data_info
if !compare_field_data
field_comparison_data = false
println("unequal data - field: ", i)
end
end
end
end
return field_comparison == true && field_comparison_data == true
end
function comparefields(info_field, infoconv_field, field_comparison_data)
inames = propertynames(info_field)
for j in inames
field_inames_infoconv = getfield(infoconv_field, j)
field_inames_info = getfield(info_field, j)
compare_field_inames = field_inames_infoconv == field_inames_info
if !compare_field_inames
field_comparison_data = false
println("unequal data - field: ", j)
end
end
return
end
function viewdata_all(output)
vd = viewdata(output, showfull=true)
return true
end
function load_data(output, path)
info = getinfo(output, path)
gas = gethydro(info)
gasconv = loaddata(output, :hydro)
flag1 = gas.data == gasconv.data
println()
println("flag1: data load hydro: ", flag1)
println()
part = getparticles(info)
partconv = loaddata(output, :particles)
flag2 = part.data == partconv.data
println()
println("flag2: data load particles: ", flag2)
println()
grav = getgravity(info)
gravconv = loaddata(output, :gravity)
flag3 = grav.data == gravconv.data
println()
println("flag3: data load gravity: ", flag3)
println()
gasconv = loaddata(output, "./", :hydro)
flag4 = gas.data == gasconv.data
println()
println("flag4: data load hydro: ", flag4)
println()
gasconv = loaddata(output, "./", datatype=:hydro)
flag5 = gas.data == gasconv.data
println()
println("flag5: data load hydro: ", flag5)
println()
return flag1 == true && flag2 == true && flag3 == true && flag4 == true && flag5 == true
end
function check_filenames()
fname="output_"
filename = Mera.outputname(fname, 10) * ".jld2"
flag1 = filename == "output_00010.jld2"
filename = Mera.outputname(fname, 100) * ".jld2"
flag2 = filename == "output_00100.jld2"
filename = Mera.outputname(fname, 1000) * ".jld2"
flag3 = filename == "output_01000.jld2"
filename = Mera.outputname(fname, 10000) * ".jld2"
flag4 = filename == "output_10000.jld2"
return flag1 == true && flag2 == true && flag3 == true && flag4 == true
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2163 |
function verbose_status(status)
verbose() # print status on screen
return verbose_mode == status # check status
end
function showprogress_status(status)
showprogress() # print status on screen
return showprogress_mode == status # check status
end
function view_argtypes() # test creation
myargs = ArgumentsType()
viewfields(myargs)
fields = propertynames(myargs)
flagpos = true
for i in fields
iif = getfield(myargs, i )
if !(iif === missing)
flagpos = false
println("false for field: ", iif)
end
end
return flagpos
end
function view_namelist(output, path)
info = getinfo(output, path)
namelist(info)
return true
end
function view_patchfile(output, path)
info = getinfo(output, path)
patchfile(info)
return true
end
function infotest(output, path)
info = getinfo(path)
info = getinfo(path, verbose=false)
info = getinfo(output, path)
info = getinfo(1, path, namelist= path * "/output_00001")
return true
end
function memory_units()
obj_value=1
op = usedmemory(obj_value, true)
op[1] == 1.0
flag1 = op[2] == "Bytes"
println("flag1: ", flag1)
obj_value=1024^1
op = usedmemory(obj_value, true)
op[1] == 1.0
flag2 = op[2] == "KB"
println("flag2: ", flag2)
obj_value=1024^2
op = usedmemory(obj_value, true)
op[1] == 1.0
flag3 = op[2] == "MB"
println("flag3: ", flag3)
obj_value=1024^3
op = usedmemory(obj_value, true)
op[1] == 1.0
flag4 = op[2] == "GB"
println("flag4: ", flag4)
obj_value=1024^4
op = usedmemory(obj_value, true)
op[1] == 1.0
flag5 = op[2] == "TB"
println("flag5: ", flag5)
return flag1 == true && flag2 == true && flag3 == true && flag4 == true && flag5 == true
end
function module_view()
viewmodule(Mera)
return true
end
function call_bell()
bell()
return true
end
function call_notifyme()
# prepare test
open(homedir() * "/email.txt", "w") do io
print(io, "[email protected]")
end
notifyme()
notifyme("GitHub runtest!")
return true
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 857 |
function simoverview(output, simpath)
sims = checksimulations(simpath);
path = sims[1].N.path
N = checkoutputs(path)
info = getinfo(output, path)
so = storageoverview(info)
so = storageoverview(info,true)
my_scales = createscales(info)
verbose(false)
showprogress(false)
sims = checksimulations(simpath);
path = sims[1].N.path
N = checkoutputs(path)
info = getinfo(output, path)
so = storageoverview(info);
verbose(nothing)
showprogress(nothing)
return true
end
function viewfieldstest(output, path)
info = getinfo(output, path, verbose=false)
viewfields(info)
viewallfields(info)
return true
end
function viewfilescontent(output, path)
info = getinfo(output, path, verbose=false)
viewfields(info.files_content)
return true
end | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 8620 | gas, irho1, ip1, ics1= prepare_data1(output, path)
@testset "default" begin
mtot = msum(gas, :Msol)
projection()
p = projection(gas, :mass, :Msol, mode=:sum, show_progress=false)
map = p.maps[:mass]
@test size(map) == (2^gas.lmax, 2^gas.lmax)
@test sum(map) ≈ mtot rtol=1e-10
@test p.maps_unit[:mass] == :Msol
@test p.maps_unit[:sd] == :standard
@test p.maps_mode[:mass] == :sum
@test p.maps_mode[:sd] == :nothing
@test p.extent == gas.ranges[1:4] .* gas.boxlen
@test p.cextent == gas.ranges[1:4] .* gas.boxlen
@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
@test p.boxlen == gas.boxlen
@test p.smallr == gas.smallr
@test p.smallc == gas.smallc
@test p.lmin == gas.lmin
@test p.lmax == gas.lmax
@test p.scale == gas.scale
@test p.info == gas.info
end
@testset "lmax, better resolution, center" begin
mtot = msum(gas, :Msol)
res=2^11
p = projection(gas, :mass, :Msol, mode=:sum, center=[:bc], res=res, verbose=false, show_progress=false)
map = p.maps[:mass]
@test size(map) == (res, res)
@test sum(map) ≈ mtot rtol=1e-10
@test p.maps_unit[:mass] == :Msol
@test p.maps_unit[:sd] == :standard
@test p.maps_mode[:mass] == :sum
@test p.maps_mode[:sd] == :nothing
@test p.extent == gas.ranges[1:4] .* gas.boxlen
@test p.cextent == gas.ranges[1:4] .* gas.boxlen .- gas.boxlen /2
@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
end
@testset "lmax, less resolution, center" begin
mtot = msum(gas, :Msol)
res = 2^5
p = projection(gas, :mass, :Msol, mode=:sum, res=res, center=[:bc], verbose=true, show_progress=false)
map = p.maps[:mass]
@test size(map) == (res, res)
@test sum(map) ≈ mtot rtol=1e-10
@test p.maps_unit[:mass] == :Msol
@test p.maps_unit[:sd] == :standard
@test p.maps_mode[:mass] == :sum
@test p.maps_mode[:sd] == :nothing
@test p.extent == gas.ranges[1:4] .* gas.boxlen
@test p.cextent == gas.ranges[1:4] .* gas.boxlen .- gas.boxlen /2
@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
end
@testset "pxsize - resolution, center" begin
verbose(true)
mtot = msum(gas, :Msol)
res=2^11
csize = gas.info.boxlen * gas.info.scale.pc / res
p = projection(gas, :mass, :Msol, mode=:sum, center=[:bc], pxsize=[csize, :pc], verbose=true, show_progress=false)
p2 = projection(gas, :mass, unit=:Msol, mode=:sum, center=[:bc], pxsize=[csize, :pc], verbose=true, show_progress=false)
@test p.maps == p2.maps
map = p.maps[:mass]
@test size(map) == (res, res)
@test sum(map) ≈ mtot rtol=1e-10
@test p.maps_unit[:mass] == :Msol
@test p.maps_unit[:sd] == :standard
@test p.maps_mode[:mass] == :sum
@test p.maps_mode[:sd] == :nothing
@test p.extent == gas.ranges[1:4] .* gas.boxlen
@test p.cextent == gas.ranges[1:4] .* gas.boxlen .- gas.boxlen /2
@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
verbose(nothing)
end
@testset "several vars" begin
mtot = msum(gas, :Msol)
p = projection(gas, [:mass], [:Msol], center=[:bc], mode=:sum, verbose=false, show_progress=false)
map = p.maps[:mass]
@test size(map) == (2^gas.lmax, 2^gas.lmax)
@test sum(map) ≈ mtot rtol=1e-10
@test p.maps_unit[:mass] == :Msol
@test p.maps_unit[:sd] == :standard
@test p.maps_mode[:mass] == :sum
@test p.maps_mode[:sd] == :nothing
p = projection(gas, [:sd, :cs], [:Msun_pc2, :cm_s], verbose=false, show_progress=false)
map = p.maps[:sd]
map_cs = p.maps[:cs]
cs = p.pixsize .* gas.info.scale.pc
@test size(map) == (2^gas.lmax, 2^gas.lmax)
@test sum(map) * cs^2 ≈ mtot rtol=1e-10
@test sum(map_cs) / length(map_cs[:]) ≈ ics1 rtol=1e-10
@test p.maps_unit[:sd] == :Msun_pc2
@test p.maps_unit[:cs] == :cm_s
@test p.maps_mode[:sd] == :nothing
p = projection(gas, [:cs, :v, :vx,:vy, :vz], :km_s, verbose=false, show_progress=false)
map_cs = p.maps[:cs]
map_v = p.maps[:v]
map_vx = p.maps[:vx]
map_vy = p.maps[:vy]
map_vz = p.maps[:vz]
vref = sqrt(20. ^2 + 30. ^2 + 40. ^2)
@test size(map_cs) == (2^gas.lmax, 2^gas.lmax)
@test sum(map_cs) / length(map_cs[:]) ≈ ics1 /1e5 rtol=1e-10
@test sum(map_vx) / length(map_vx[:]) ≈ 20. rtol=1e-10
@test sum(map_vy) / length(map_vy[:]) ≈ 30. rtol=1e-10
@test sum(map_vz) / length(map_vz[:]) ≈ 40. rtol=1e-10
@test sum(map_v) / length(map_v[:]) ≈ vref rtol=1e-10
@test p.maps_unit[:sd] == :standard
@test p.maps_unit[:cs] == :km_s
@test p.maps_unit[:vx] == :km_s
@test p.maps_unit[:vy] == :km_s
@test p.maps_unit[:vz] == :km_s
@test p.maps_unit[:v] == :km_s
@test p.maps_mode[:sd] == :nothing
@test p.maps_mode[:cs] == :standard
@test p.maps_mode[:vx] == :standard
@test p.maps_mode[:vy] == :standard
@test p.maps_mode[:vz] == :standard
@test p.maps_mode[:v] == :standard
# todo
"""
@test p.maps_weight[:cs] == Union{Missing, Symbol}[:mass, missing]
@test p.maps_weight[:sd] == :nothing
@test p.maps_weight[:v] == Union{Missing, Symbol}[:mass, missing]
@test p.maps_weight[:vx] == Union{Missing, Symbol}[:mass, missing]
@test p.maps_weight[:vy] == Union{Missing, Symbol}[:mass, missing]
@test p.maps_weight[:vz] == Union{Missing, Symbol}[:mass, missing]
"""
end
# ==========
@testset "fullbox, directions and mass conservation " begin
mtot = msum(gas, :Msol)
p = projection(gas, [:sd, :cs], [:Msun_pc2, :cm_s], direction=:x, verbose=false, show_progress=false)
map = p.maps[:sd]
map_cs = p.maps[:cs]
cellsize = p.pixsize * p.info.scale.pc
@test size(map) == (2^gas.lmax, 2^gas.lmax)
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-10
@test sum(map_cs) / length(map_cs[:]) ≈ ics1 rtol=1e-10
p = projection(gas, [:sd, :cs], [:Msun_pc2, :cm_s], direction=:y, verbose=false, show_progress=false)
map = p.maps[:sd]
map_cs = p.maps[:cs]
cellsize = p.pixsize * p.info.scale.pc
@test size(map) == (2^gas.lmax, 2^gas.lmax)
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-10
@test sum(map_cs) / length(map_cs[:]) ≈ ics1 rtol=1e-10
end
"""
@testset "subregions, direction and mass conservation " begin
xrange = yrange = [-12., 12.]
zrange = [-1., 1.]
gas_sub = subregion(gas,:cuboid,
xrange=xrange, yrange=yrange, zrange=zrange,
center=[:bc], range_unit=:kpc)
mtot = msum(gas_sub, :Msol)
p = projection(gas, [:mass], [:Msol], mode=:sum,
direction=:z,
xrange=xrange, yrange=yrange, zrange=zrange,
center=[:bc], range_unit=:kpc,
verbose=false, show_progress=false)
map = p.maps[:mass]
##map_cs = p.maps[:cs]
#@test size(map) == (2^gas.lmax, 2^gas.lmax)
@test sum(map) ≈ mtot rtol=1e-10
##@test sum(map_cs) / length(map_cs[:]) ≈ ics1 rtol=1e-10
@test p.extent == [-12., 12, -12., 12.] .+ gas.boxlen /2
@test p.cextent == [-12., 12, -12., 12.]
#@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
p = projection(gas, [:mass], [:Msol], mode=:sum,
direction=:x,
xrange=xrange, yrange=yrange, zrange=zrange,
center=[:bc], range_unit=:kpc,
verbose=false, show_progress=false)
map = p.maps[:mass]
##map_cs = p.maps[:cs]
@test size(map) == (2^gas.lmax, 2^gas.lmax)
@test sum(map) ≈ mtot rtol=1e-10
##@test sum(map_cs) / length(map_cs[:]) ≈ ics1 rtol=1e-10
@test p.extent == [-12., 12, -1., 1.] .+ gas.boxlen /2
@test p.cextent == [-12., 12, -1., 1.]
#@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
p = projection(gas, [:mass], [:Msol], mode=:sum,
direction=:y,
xrange=xrange, yrange=yrange, zrange=zrange,
center=[:bc], range_unit=:kpc,
verbose=false, show_progress=false)
map = p.maps[:mass]
##map_cs = p.maps[:cs]
@test size(map) == (2^gas.lmax, 2^gas.lmax)
@test sum(map) ≈ mtot rtol=1e-10
##@test sum(map_cs) / length(map_cs[:]) ≈ ics1 rtol=1e-10
@test p.extent == [-12., 12, -1., 1.] .+ gas.boxlen /2
@test p.cextent == [-12., 12, -1., 1.]
#@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
end
""" | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 4233 | info = getinfo(output, path, verbose=false)
part = getparticles(info, verbose=false)
mask_stars = getvar(part, :family) .== 2
@testset "default" begin
mtot = msum(part, :Msol, mask=mask_stars)
p = projection(part, :sd, :Msun_pc2, show_progress=false, mask=mask_stars)
p2 = projection(part, [:sd], units=[:Msun_pc2], show_progress=false, mask=mask_stars)
@test p.maps == p2.maps
map = p.maps[:sd]
@test size(map) == (2^part.lmax, 2^part.lmax)
cellsize = p.pixsize * info.scale.pc
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-10
@test p.maps_unit[:sd] == :Msun_pc2
@test p.maps_mode[:sd] == :mass_weighted
@test p.extent == part.ranges[1:4] .* part.boxlen
@test p.cextent == part.ranges[1:4] .* part.boxlen
@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
@test p.boxlen == part.boxlen
@test p.lmin == part.lmin
@test p.lmax == part.lmax
@test p.scale == part.scale
@test p.info == part.info
mtot = msum(part, :Msol)
p = projection(part, :sd, :Msun_pc2, show_progress=false, verbose=false)
map = p.maps[:sd]
cellsize = p.pixsize * info.scale.pc
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-4
end
@testset "lmax, better resolution, center" begin
mtot = msum(part, :Msol, mask=mask_stars)
res=2^11
p = projection(part, :sd, :Msun_pc2, center=[:bc], res=res, verbose=false, show_progress=false, mask=mask_stars)
map = p.maps[:sd]
@test size(map) == (res, res)
cellsize = p.pixsize * info.scale.pc
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-10
@test p.maps_unit[:sd] == :Msun_pc2
@test p.maps_mode[:sd] == :mass_weighted
@test p.extent == part.ranges[1:4] .* part.boxlen
@test p.cextent == part.ranges[1:4] .* part.boxlen .- part.boxlen /2
@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
end
@testset "lmax, less resolution, center" begin
mtot = msum(part, :Msol, mask=mask_stars)
res = 2^5
p = projection(part, :sd, :Msun_pc2, res=res, center=[:bc], verbose=true, show_progress=false, mask=mask_stars)
map = p.maps[:sd]
@test size(map) == (res, res)
cellsize = p.pixsize * info.scale.pc
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-10
@test p.maps_unit[:sd] == :Msun_pc2
@test p.maps_mode[:sd] == :mass_weighted
@test p.extent == part.ranges[1:4] .* part.boxlen
@test p.cextent == part.ranges[1:4] .* part.boxlen .- part.boxlen /2
@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
end
@testset "pxsize - resolution, center" begin
verbose(true)
mtot = msum(part, :Msol, mask=mask_stars)
res=2^11
csize = part.info.boxlen * part.info.scale.pc / res
p = projection(part, :sd, :Msun_pc2, center=[:bc], pxsize=[csize, :pc], verbose=true, show_progress=false, mask=mask_stars)
p2 = projection(part, :sd, unit=:Msun_pc2, center=[:bc], pxsize=[csize, :pc], verbose=true, show_progress=false, mask=mask_stars)
@test p.maps == p2.maps
map = p.maps[:sd]
@test size(map) == (res, res)
cellsize = p.pixsize * info.scale.pc
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-10
@test p.maps_unit[:sd] == :Msun_pc2
@test p.maps_mode[:sd] == :mass_weighted
@test p.extent == part.ranges[1:4] .* part.boxlen
@test p.cextent == part.ranges[1:4] .* part.boxlen .- part.boxlen /2
@test p.ratio == (p.extent[4] - p.extent[3]) / (p.extent[2] - p.extent[1])
verbose(nothing)
end
# ==========
@testset "fullbox, directions and mass conservation " begin
mtot = msum(part, :Msol, mask=mask_stars)
# todo add, e.g., age
p = projection(part, [:sd], [:Msun_pc2], direction=:x, verbose=false, show_progress=false, mask=mask_stars)
map = p.maps[:sd]
cellsize = p.pixsize * p.info.scale.pc
@test size(map) == (2^part.lmax, 2^part.lmax)
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-10
p = projection(part, [:sd], [:Msun_pc2], direction=:y, verbose=false, show_progress=false, mask=mask_stars)
map = p.maps[:sd]
cellsize = p.pixsize * p.info.scale.pc
@test size(map) == (2^part.lmax, 2^part.lmax)
@test sum(map) * cellsize^2 ≈ mtot rtol=1e-10
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2546 |
function gravity_range_codeunit(output, path)
info = getinfo(output, path)
if info.levelmin !== info.levelmax
gas00 = getgravity(info, lmax=5)
gas01 = getgravity(info, lmax=5,
xrange=[0.2,0.8],
yrange=[0.2,0.8],
zrange=[0.4,0.6]);
if gas01.ranges == [0.2, 0.8, 0.2, 0.8, 0.4, 0.6]
gas01_flag1 = true
else
gas01_flag1 = false
end
println("code unit ranges: ", gas01_flag1, " -flag01")
if gas01.lmax == 5
gas01_flag2 = true
else
gas01_flag2 = false
end
println("lmax: ", gas01_flag2, " -flag02")
if gas00.data != gas01.data
gas01_flag3 = true
else
gas01_flag3 = false
end
println("different data ", gas01_flag3, " -flag03")
gas02 = getgravity(info, lmax=5,
xrange=[-0.3,0.3],
yrange=[-0.3,0.3],
zrange=[-0.1,0.1],
center=[0.5,0.5,0.5])
if gas01.data == gas02.data
gas02_flag4 = true
else
gas02_flag4 = false
end
println("ranges relative to a given center gives same data: ", gas02_flag4, " -flag4")
gas03 = getgravity(info, lmax=5,
xrange=[-0.3 * 100, 0.3 * 100],
yrange=[-0.3 * 100, 0.3 * 100],
zrange=[-0.1 * 100, 0.1 * 100],
center=[50., 50., 50.],
range_unit=:kpc )
if gas03.data == gas01.data
gas03_flag5 = true
else
gas03_flag5 = false
end
println("ranges given in physical units gives same data: ", gas03_flag5, " -flag5")
gas04 = getgravity(info, lmax=5,
xrange=[-0.3 * 100, 0.3 * 100],
yrange=[-0.3 * 100, 0.3 * 100],
zrange=[-0.1 * 100, 0.1 * 100],
center=[:bc],
range_unit=:kpc)
if gas04.data == gas01.data
gas04_flag6 = true
else
gas04_flag6 = false
end
println(":bc call in center argument gives same data: ", gas04_flag6, " -flag6")
return gas01_flag1 = true && gas01_flag2 == true && gas01_flag3 == true && gas02_flag4 == true && gas03_flag5 == true && gas04_flag6 == true
else
return true
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2628 |
function hydro_range_codeunit(output, path)
info = getinfo(output, path)
if info.levelmin !== info.levelmax
gas00 = gethydro(info, lmax=5, smallr=1e-11)
gas01 = gethydro(info, lmax=5,
xrange=[0.2,0.8],
yrange=[0.2,0.8],
zrange=[0.4,0.6],
smallr = 1e-11);
if gas01.ranges == [0.2, 0.8, 0.2, 0.8, 0.4, 0.6]
gas01_flag1 = true
else
gas01_flag1 = false
end
println("code unit ranges: ", gas01_flag1, " -flag01")
if gas01.lmax == 5
gas01_flag2 = true
else
gas01_flag2 = false
end
println("lmax: ", gas01_flag2, " -flag02")
if gas00.data != gas01.data
gas01_flag3 = true
else
gas01_flag3 = false
end
println("different data ", gas01_flag3, " -flag03")
gas02 = gethydro(info, lmax=5,smallr=1e-11,
xrange=[-0.3,0.3],
yrange=[-0.3,0.3],
zrange=[-0.1,0.1],
center=[0.5,0.5,0.5])
if gas01.data == gas02.data
gas02_flag4 = true
else
gas02_flag4 = false
end
println("ranges relative to a given center gives same data: ", gas02_flag4, " -flag4")
gas03 = gethydro(info, lmax=5, smallr=1e-11,
xrange=[-0.3 * 100, 0.3 * 100],
yrange=[-0.3 * 100, 0.3 * 100],
zrange=[-0.1 * 100, 0.1 * 100],
center=[50., 50., 50.],
range_unit=:kpc )
if gas03.data == gas01.data
gas03_flag5 = true
else
gas03_flag5 = false
end
println("ranges given in physical units gives same data: ", gas03_flag5, " -flag5")
gas04 = gethydro(info, lmax=5, smallr=1e-11,
xrange=[-0.3 * 100, 0.3 * 100],
yrange=[-0.3 * 100, 0.3 * 100],
zrange=[-0.1 * 100, 0.1 * 100],
center=[:bc],
range_unit=:kpc)
if gas04.data == gas01.data
gas04_flag6 = true
else
gas04_flag6 = false
end
println(":bc call in center argument gives same data: ", gas04_flag6, " -flag6")
return gas01_flag1 = true && gas01_flag2 == true && gas01_flag3 == true && gas02_flag4 == true && gas03_flag5 == true && gas04_flag6 == true
else
return true
end
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | code | 2080 |
function particles_range_codeunit(output, path)
info = getinfo(output, path)
part00 = getparticles(info)
part01 = getparticles(info,
xrange=[0.2,0.8],
yrange=[0.2,0.8],
zrange=[0.4,0.6]);
if part01.ranges == [0.2, 0.8, 0.2, 0.8, 0.4, 0.6]
part01_flag1 = true
else
part01_flag1 = false
end
println("code unit ranges: ", part01_flag1, " -flag01")
if part00.data != part01.data
part01_flag3 = true
else
part01_flag3 = false
end
println("different data ", part01_flag3, " -flag03")
part02 = getparticles(info,
xrange=[-0.3,0.3],
yrange=[-0.3,0.3],
zrange=[-0.1,0.1],
center=[0.5,0.5,0.5])
if part01.data == part02.data
part02_flag4 = true
else
part02_flag4 = false
end
println("ranges relative to a given center gives same data: ", part02_flag4, " -flag4")
part03 = getparticles(info,
xrange=[-0.3 * 100, 0.3 * 100],
yrange=[-0.3 * 100, 0.3 * 100],
zrange=[-0.1 * 100, 0.1 * 100],
center=[50., 50., 50.],
range_unit=:kpc )
if part03.data == part01.data
part03_flag5 = true
else
part03_flag5 = false
end
println("ranges given in physical units gives same data: ", part03_flag5, " -flag5")
part04 = getparticles(info,
xrange=[-0.3 * 100, 0.3 * 100],
yrange=[-0.3 * 100, 0.3 * 100],
zrange=[-0.1 * 100, 0.1 * 100],
center=[:bc],
range_unit=:kpc)
if part04.data == part01.data
part04_flag6 = true
else
part04_flag6 = false
end
println(":bc call in center argument gives same data: ", part04_flag6, " -flag6")
return part01_flag1 == true && part01_flag3 == true && part02_flag4 == true && part03_flag5 == true && part04_flag6 == true
end
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 3355 | # Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 14578 | <img src="assets/repository_logo_small.jpg" alt="Mera.jl" width="200">
|**Version** | **Documentation** | **Cite**|
|:------------|:----------------- |:------------------ |
| [](https://juliahub.com/ui/Packages/Mera/7jlnw) | [![][docs-stable-img]][docs-stable-url] | [![][doi-img]][doi-url] |
[docs-stable-img]: https://img.shields.io/badge/docs-stable%20release-blue.svg
[docs-stable-url]: https://manuelbehrendt.github.io/Mera.jl/stable/
[docs-latest-img]: https://img.shields.io/badge/docs-in_development-orange.svg
[docs-latest-url]: https://manuelbehrendt.github.io/Mera.jl/dev/
[doi-img]: https://zenodo.org/badge/229728152.svg
[doi-url]: https://zenodo.org/badge/latestdoi/229728152
MERA is a package for working with large 3D AMR/uniform-grid and N-body particle data sets from astrophysical simulations.
It is entirely written in the language [Julia](https://julialang.org) and currently supports the hydrodynamic code [RAMSES](https://bitbucket.org/rteyssie/ramses/overview). With this package, I intend to provide essential functions to load and prepare the simulation data for calculations but try to avoid too high-level abstraction (black boxes).
> **Note**
> To get a first impression, look at the `Hands-On Session RUM2023` with downloadable simulation examples:
https://github.com/ManuelBehrendt/RUM2023
## Package Features
- Easy to install and update
- Fast and memory lightweight data reading/saving and handling
- The data is loaded and processed in a database framework [JuliaDB.jl](https://juliadb.org)
- Efficient workflow
- Many functionalities for advanced analysis
- Easy to extend
- Interactive and script functionality
- Many examples and tutorials
- Mera-files, a significant faster way to read/store the RAMSES data for time sequence analysis
## Dependencies
Find the main dependencies on [JuliaHub](https://juliahub.com/ui/Packages/Mera/7jlnw/1.4.2?page=1) or from the development version listed in the file [Project.toml](https://github.com/ManuelBehrendt/Mera.jl/blob/master/Project.toml).
## Tests
We are developing **unit-test** and **end-to-end** testing strategies to encounter bugs like general errors, incorrect data returns, and functionality issues. After new commits are pushed to GitHub, **different operating system environments** and **Julia versions** run **automated tests**, e. g. on outputs from various RAMSES simulations, to ensure important functionalities of MERA. The *test* folder contains all tests with the main function in the **runtest.jl** file.
**Development Version**|
|:---------------------|
|[](https://coveralls.io/github/ManuelBehrendt/Mera.jl?branch=master) [](https://codecov.io/gh/ManuelBehrendt/Mera.jl) [](https://github.com/ManuelBehrendt/Mera.jl/actions/workflows/CompatHelper.yml) |
[](https://github.com/ManuelBehrendt/Mera.jl/actions/workflows/documentation.yml) [![][docs-latest-img]][docs-latest-url]|
**Runtests for:** | **OS** |
|:---------------------|:---------------------|
[](https://github.com/ManuelBehrendt/Mera.jl/actions/workflows/CI_1.6.yml) | ubuntu-latest, macOS-latest|
[](https://github.com/ManuelBehrendt/Mera.jl/actions/workflows/CI_1.7.yml) | ubuntu-latest, macOS-latest |
[](https://github.com/ManuelBehrendt/Mera.jl/actions/workflows/CI_1.8.yml) | ubuntu-latest, macOS-latest |
[](https://github.com/ManuelBehrendt/Mera.jl/actions/workflows/CI_1.9.yml)| ubuntu-latest, macOS-latest |
## Julia Installation
- Binary download + installation instructions: https://julialang.org/downloads/
- Juliaup, an installer and version manager: https://github.com/JuliaLang/juliaup
- Apple Silicon: M1/M2 Chips: Julia 1.6.x can be installed without any trouble. But to use PyPlot, it is recommended to install/pin the package [email protected] ! https://pkgdocs.julialang.org/v1.6/managing-packages/#Pinning-a-package . If you encounter any problems with Julia 1.9, try the binary *macOS x86 (Intel or Rosetta)* instead of *macOS (Apple Silicon)*.
## Package Installation
The package is tested against the long-term supported Julia 1.6.x (recommended), 1.7.x, 1.8.x, 1.9.x and can be installed with the Julia package manager: https://pkgdocs.julialang.org/v1/
### Julia REPL
From the Julia REPL, type ] to enter the Pkg REPL mode and run:
```julia
pkg> add Mera
```
### Jupyter Notebook
Or, equivalently, via the Pkg API in the Jupyter notebook use
```julia
using Pkg
Pkg.add("Mera")
```
## Updates
Watch on [GitHub](https://github.com/ManuelBehrendt/Mera.jl).
Note: Before updating, always read the release notes. In Pkg REPL mode run:
```julia
pkg> update Mera
```
Or, equivalently, in a Jupyter notebook:
```julia
using Pkg
Pkg.update("Mera")
```
## Reproducibility
Reproducibility is an essential requirement of the scientific process. Therefore, I recommend working with environments.
Create independent projects that contain their list of used package dependencies and their versions.
The possibility of creating projects ensures reproducibility of your programs on your or other platforms if, e.g. the code is shared (toml-files are added to the project folder). For more information see [Julia environments]([https://julialang.github.io/Pkg.jl/v1.6/environments/](https://pkgdocs.julialang.org/v1.9/environments/)).
In order to create a new project "activate" your working directory:
```julia
shell> cd MyProject
/Users/you/MyProject
(v1.6) pkg> activate .
```
Now add packages like Mera and PyPlot in the favored version:
```julia
(MyProject) pkg> add Package
```
## Help and Documentation
The exported functions and types in MERA are listed in the API documentation, but can also be accessed in the REPL or Jupyter notebook.
In the REPL use e.g. for the function *getinfo*:
```julia
julia> ? # upon typing ?, the prompt changes (in place) to: help?>
help?> getinfo
search: getinfo SegmentationFault getindex getpositions MissingException
Get the simulation overview from RAMSES info, descriptor and output header files
----------------------------------------------------------------------------------
getinfo(; output::Real=1, path::String="", namelist::String="", verbose::Bool=verbose_mode)
return InfoType
Keyword Arguments
-------------------
• output: timestep number (default=1)
• path: the path to the output folder relative to the current folder or absolute path
• namelist: give the path to a namelist file (by default the namelist.txt-file in the output-folder is read)
• verbose:: informations are printed on the screen by default: gloval variable verbose_mode=true
Examples
----------
...........
```
In the Jupyter notebook use e.g.:
```julia
?getinfo
search: getinfo SegmentationFault getindex getpositions MissingException
Get the simulation overview from RAMSES info, descriptor and output header files
----------------------------------------------------------------------------------
getinfo(; output::Real=1, path::String="", namelist::String="", verbose::Bool=verbose_mode)
return InfoType
Keyword Arguments
-------------------
• output: timestep number (default=1)
• path: the path to the output folder relative to the current folder or absolute path
• namelist: give the path to a namelist file (by default the namelist.txt-file in the output-folder is read)
• verbose:: informations are printed on the screen by default: gloval variable verbose_mode=true
Examples
----------
...........
```
Get a list of the defined methods of a function:
```julia
julia> methods(viewfields)
# 10 methods for generic function "viewfields":
[1] viewfields(object::PhysicalUnitsType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:181
[2] viewfields(object::Mera.FilesContentType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:166
[3] viewfields(object::DescriptorType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:150
[4] viewfields(object::FileNamesType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:134
[5] viewfields(object::CompilationInfoType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:116
[6] viewfields(object::GridInfoType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:90
[7] viewfields(object::PartInfoType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:73
[8] viewfields(object::ScalesType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:57
[9] viewfields(object::InfoType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:12
[10] viewfields(object::DataSetType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:197
```
## Further Notes
- To use the **Jupyter** interactive environment, please install IJulia (see [IJulia](https://github.com/JuliaLang/IJulia.jl)) and/or the standalone "JupyterLab Desktop" app: https://github.com/jupyterlab/jupyterlab-desktop
- The **tutorials** in the documentation can be downloaded from [GitHub](https://github.com/ManuelBehrendt/Mera.jl/tree/master/tutorials) as Jupyter notebooks
- To get a first impression, look at the **Hands-On Session** RUM2023` with downloadable simulation examples:
https://github.com/ManuelBehrendt/RUM2023
- Mera is tested against the **RAMSES versions**: =< stable-17.09, stable-18-09, stable-19-10
- The variables from the **descriptor-files** are currently only read and can be used in a future Mera version
- For simulations with a **uniform grid**, the column **:level** is not created to reduce memory usage
## Why Julia?
In scientific computing, we are dealing with a steadily increasing amount of data. Highest performance is required, and therefore, most science-related libraries are written in low-level languages like C or Fortran with relatively long development times. The reduced data is often processed in a high-level language like Python.
Julia is a relatively new and modern language, and it combines high-level programming with high-performance numerical computing. The syntax is simple and great for math. The just-in-time compilation allows for interactive coding and to achieve an optimized machine code on the fly. Both enhance prototyping and code readability. Therefore, complex projects can be realized in relatively short development times.
Further features:
- Package manager
- Runs on multiple platform
- Multiple dispatch
- Build-in parallelism
- Metaprogramming
- Directly call C, Fortran, Python (e.g. Matplotlib), R libraries, ...
….
## Useful Links
- [Official Julia website](https://julialang.org)
- Alternatively use the Julia version manager and make Julia 1.6.* the default: https://github.com/JuliaLang/juliaup
- [Learning Julia](https://julialang.org/learning/)
- [Wikibooks](https://en.wikibooks.org/wiki/Introducing_Julia)
- [Julia Cheatsheet](https://juliadocs.github.io/Julia-Cheat-Sheet/)
- [Free book ThinkJulia](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html)
- [Synthax comparison: MATLAB–Python–Julia](https://cheatsheets.quantecon.org)
- [Julia forum JuliaDiscourse](https://discourse.julialang.org)
- [Courses on YouTube](https://www.youtube.com/user/JuliaLanguage)
- Database framework used in Mera: [JuliaDB.jl](https://juliadb.org)
- Interesting Packages: [JuliaAstro.jl](http://juliaastro.github.io), [JuliaObserver.com](https://juliaobserver.com)
- Use Matplotlib in Julia: [PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl)
- Call Python packages/functions from Julia: [PyCall.jl](https://github.com/JuliaPy/PyCall.jl)
- Visual Studio Code based Julia IDE [julia-vscode](https://github.com/julia-vscode/julia-vscode)
## Contact for Questions and Contributing
- If you have any questions about the package, please feel free to write an email to: mera[>]manuelbehrendt.com
- For bug reports, etc., please submit an issue on [GitHub](https://github.com/ManuelBehrendt/Mera.jl)
New ideas, feature requests are very welcome! MERA can be easily extended for other grid-based or N-body based data. Write an email to: mera[>]manuelbehrendt.com
## Supporting and Citing
To credit the Mera software, please star the repository on GitHub. If you use the Mera software as part of your research, teaching, or other activities, I would be grateful if you could cite my work. To give proper academic credit, follow the link for BibTeX export:
[](https://zenodo.org/badge/latestdoi/229728152)
## License
MIT License
Copyright (c) 2019 Manuel Behrendt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 834 | ---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 595 | ---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 32350 | # First Steps
## Simulation Overview
```julia
using Mera
```
Get information with the function ``getinfo`` about the simulation for a selected output and assign it to an object, here: "info" (composite type). The RAMSES output folders are assumed to be in the current working directory, and the user can give a relative or absolute path. The information is read from several files: info-file, header-file, from the header of the Fortran binary files of the first CPU (hydro, grav, part, clump, sink, ... if they exist), etc. Many familiar names and acronyms known from RAMSES are maintained. The function ``getinfo`` prints a small summary and the given units are printed in human-readable representation.
```julia
info = getinfo(300, "../../testing/simulations/mw_L10"); # output=300 in given path
```
[Mera]: 2023-04-10T10:09:57.797
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
The simulation output can be selected in several ways, which is realised by using multiple dispatch. See the different defined methods on the function ``getinfo``:
```julia
# info = getinfo(); # default: output=1 in current folder,
# info = getinfo("../simulations/"); # given path, default: output=1
# info = getinfo(output=400, path="../simulations/"); # pass path and output number by keywords
methods(getinfo)
```
4 methods for generic function <b>getinfo</b>:<ul><li> getinfo(; <i>output, path, namelist, verbose</i>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/read_data/RAMSES/getinfo.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/read_data/RAMSES/getinfo.jl:58</a></li> <li> getinfo(output::<b>Real</b>; <i>path, namelist, verbose</i>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/read_data/RAMSES/getinfo.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/read_data/RAMSES/getinfo.jl:46</a></li> <li> getinfo(output::<b>Real</b>, path::<b>String</b>; <i>namelist, verbose</i>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/read_data/RAMSES/getinfo.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/read_data/RAMSES/getinfo.jl:50</a></li> <li> getinfo(path::<b>String</b>; <i>output, namelist, verbose</i>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/read_data/RAMSES/getinfo.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/read_data/RAMSES/getinfo.jl:54</a></li> </ul>
## Fields
The created object ``info`` is of type ``InfoType`` (composite type):
```julia
typeof(info)
```
InfoType
The previously printed information and even more simulation properties are assigned to the object and can be accessed from fields and sub-fields.
Get an overview with:
```julia
viewfields(info);
```
output = 300
path = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10
fnames ==> subfields: (:output, :info, :amr, :hydro, :hydro_descriptor, :gravity, :particles, :part_descriptor, :rt, :rt_descriptor, :rt_descriptor_v0, :clumps, :timer, :header, :namelist, :compilation, :makefile, :patchfile)
simcode = RAMSES
mtime = 2023-04-09T05:34:09
ctime = 2023-04-10T08:08:14.488
ncpu = 640
ndim = 3
levelmin = 6
levelmax = 10
boxlen = 48.0
time = 29.9031937665063
aexp = 1.0
H0 = 1.0
omega_m = 1.0
omega_l = 0.0
omega_k = 0.0
omega_b = 0.045
unit_l = 3.085677581282e21
unit_d = 6.76838218451376e-23
unit_m = 1.9885499720830952e42
unit_v = 6.557528732282063e6
unit_t = 4.70554946422349e14
gamma = 1.6667
hydro = true
nvarh = 7
nvarp = 7
nvarrt = 0
variable_list = [:rho, :vx, :vy, :vz, :p, :var6, :var7]
gravity_variable_list = [:epot, :ax, :ay, :az]
particles_variable_list = [:vx, :vy, :vz, :mass, :family, :tag, :birth]
rt_variable_list = Symbol[]
clumps_variable_list = Symbol[]
sinks_variable_list = Symbol[]
descriptor ==> subfields: (:hversion, :hydro, :htypes, :usehydro, :hydrofile, :pversion, :particles, :ptypes, :useparticles, :particlesfile, :gravity, :usegravity, :gravityfile, :rtversion, :rt, :rtPhotonGroups, :usert, :rtfile, :clumps, :useclumps, :clumpsfile, :sinks, :usesinks, :sinksfile)
amr = true
gravity = true
particles = true
rt = false
clumps = false
sinks = false
namelist = true
namelist_content ==> dictionary: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
headerfile = true
makefile = true
files_content ==> subfields: (:makefile, :timerfile, :patchfile)
timerfile = true
compilationfile = false
patchfile = true
Narraysize = 0
scale ==> subfields: (:Mpc, :kpc, :pc, :mpc, :ly, :Au, :km, :m, :cm, :mm, :μm, :Mpc3, :kpc3, :pc3, :mpc3, :ly3, :Au3, :km3, :m3, :cm3, :mm3, :μm3, :Msol_pc3, :Msun_pc3, :g_cm3, :Msol_pc2, :Msun_pc2, :g_cm2, :Gyr, :Myr, :yr, :s, :ms, :Msol, :Msun, :Mearth, :Mjupiter, :g, :km_s, :m_s, :cm_s, :nH, :erg, :g_cms2, :T_mu, :K_mu, :T, :K, :Ba, :g_cm_s2, :p_kB, :K_cm3)
grid_info ==> subfields: (:ngridmax, :nstep_coarse, :nx, :ny, :nz, :nlevelmax, :nboundary, :ngrid_current, :bound_key, :cpu_read)
mpart_info ==> subfields: (:eta_sn, :age_sn, :f_w, :Npart, :Ndm, :Nstars, :Nsinks, :Ncloud, :Ndebris, :Nother, :Nundefined, :other_tracer1, :debris_tracer, :cloud_tracer, :star_tracer, :other_tracer2, :gas_tracer)
compilation ==> subfields: (:compile_date, :patch_dir, :remote_repo, :local_branch, :last_commit)
constants ==> subfields: (:Au, :Mpc, :kpc, :pc, :mpc, :ly, :Msol, :Msun, :Mearth, :Mjupiter, :Rsol, :Rsun, :me, :mp, :mn, :mH, :amu, :NA, :c, :G, :kB, :Gyr, :Myr, :yr)
Get a simple list of the fields of any object:
```julia
propertynames(info)
```
(:output, :path, :fnames, :simcode, :mtime, :ctime, :ncpu, :ndim, :levelmin, :levelmax, :boxlen, :time, :aexp, :H0, :omega_m, :omega_l, :omega_k, :omega_b, :unit_l, :unit_d, :unit_m, :unit_v, :unit_t, :gamma, :hydro, :nvarh, :nvarp, :nvarrt, :variable_list, :gravity_variable_list, :particles_variable_list, :rt_variable_list, :clumps_variable_list, :sinks_variable_list, :descriptor, :amr, :gravity, :particles, :rt, :clumps, :sinks, :namelist, :namelist_content, :headerfile, :makefile, :files_content, :timerfile, :compilationfile, :patchfile, :Narraysize, :scale, :grid_info, :part_info, :compilation, :constants)
## Physical Units
All calculations in **MERA** are processed in the code units of the loaded simulation. The **RAMSES** scaling factors from code- to cgs-units are given for the length, density, mass, velocity and time, assigned to the fields: unit_l, unit_d, unit_m, unit_v, unit_t
To make life easier, we provide more predefined scaling factors, assigned to the sub-field ``scale``:
```julia
viewfields(info.scale)
```
[Mera]: Fields to scale from user/code units to selected units
=======================================================================
Mpc = 0.0010000000000006482
kpc = 1.0000000000006481
pc = 1000.0000000006482
mpc = 1.0000000000006482e6
ly = 3261.5637769461323
Au = 2.0626480623310105e23
km = 3.0856775812820004e16
m = 3.085677581282e19
cm = 3.085677581282e21
mm = 3.085677581282e22
μm = 3.085677581282e25
Mpc3 = 1.0000000000019446e-9
kpc3 = 1.0000000000019444
pc3 = 1.0000000000019448e9
mpc3 = 1.0000000000019446e18
ly3 = 3.469585750743794e10
Au3 = 8.775571306099254e69
km3 = 2.9379989454983075e49
m3 = 2.9379989454983063e58
cm3 = 2.9379989454983065e64
mm3 = 2.937998945498306e67
μm3 = 2.937998945498306e76
Msol_pc3 = 0.9997234790001649
Msun_pc3 = 0.9997234790001649
g_cm3 = 6.76838218451376e-23
Msol_pc2 = 999.7234790008131
Msun_pc2 = 999.7234790008131
g_cm2 = 0.20885045168302602
Gyr = 0.014910986463557083
Myr = 14.910986463557084
yr = 1.4910986463557083e7
s = 4.70554946422349e14
ms = 4.70554946422349e17
Msol = 9.99723479002109e8
Msun = 9.99723479002109e8
Mearth = 3.329677459032007e14
Mjupiter = 1.0476363431814971e12
g = 1.9885499720830952e42
km_s = 65.57528732282063
m_s = 65575.28732282063
cm_s = 6.557528732282063e6
nH = 30.987773856809987
erg = 8.551000140274429e55
g_cms2 = 2.9104844143584656e-9
T_mu = 517028.3199143136
K_mu = 517028.3199143136
T = 680300.4209398864
K = 680300.4209398864
Ba = 2.910484414358466e-9
g_cm_s2 = 2.910484414358466e-9
p_kB = 2.1080995598777838e7
K_cm3 = 2.1080995598777838e7
```julia
list_field = propertynames( info.scale )
```
(:Mpc, :kpc, :pc, :mpc, :ly, :Au, :km, :m, :cm, :mm, :μm, :Mpc3, :kpc3, :pc3, :mpc3, :ly3, :Au3, :km3, :m3, :cm3, :mm3, :μm3, :Msol_pc3, :Msun_pc3, :g_cm3, :Msol_pc2, :Msun_pc2, :g_cm2, :Gyr, :Myr, :yr, :s, :ms, :Msol, :Msun, :Mearth, :Mjupiter, :g, :km_s, :m_s, :cm_s, :nH, :erg, :g_cms2, :T_mu, :K_mu, :T, :K, :Ba, :g_cm_s2, :p_kB, :K_cm3)
The underline in the unit representation corresponds to the fraction line, e.g.:
|field name | corresponding unit |
|---- | ----|
|Msun_pc3 | Msun * pc^-3|
|g_cm3 | g * cm^-3 |
|Msun_pc2 | Msun * pc^-2|
|g_cm2 | g * cm^-2|
| km_s| km * s^-1|
| m_s| m * s^-1|
| cm_s| cm * s^-1|
| g_cms2| g / (cm * s^2)|
| nH | cm^-3 |
| T_mu | T / μ |
| T_mu | K / μ |
| p_kB | p / kB |
| Ba | = Barye (pressure) [cm^-1 * g * s^-2] |
Access a scaling factor to use it in your calculations or plots by e.g.:
```julia
info.scale.km_s
```
65.57528732282063
To reduce the hierarchy of sub-fields, assign a new object:
```julia
scale = info.scale;
```
The scaling factor can now be accessed by:
```julia
scale.km_s
```
65.57528732282063
Furthermore, the scales can be assigned by applying the function ``createscales`` on an object of type ``InfoType`` (here: `info`):
```julia
typeof(info)
```
InfoType
```julia
my_scales = createscales(info)
my_scales.km_s
```
65.57528732282063
## Physical Constants
Some useful constants are assigned to the `InfoType` object:
```julia
viewfields(info.constants)
```
[Mera]: Constants given in cgs units
=========================================
Au = 0.01495978707
Mpc = 3.08567758128e24
kpc = 3.08567758128e21
pc = 3.08567758128e18
mpc = 3.08567758128e15
ly = 9.4607304725808e17
Msol = 1.9891e33
Msun = 1.9891e33
Mearth = 5.9722e27
Mjupiter = 1.89813e30
Rsol = 6.96e10
Rsun = 6.96e10
me = 9.1093897e-28
mp = 1.6726231e-24
mn = 1.6749286e-24
mH = 1.66e-24
amu = 1.6605402e-24
NA = 6.0221367e23
c = 2.99792458e10
G = 6.67259e-8
kB = 1.38062e-16
Gyr = 3.15576e16
Myr = 3.15576e13
yr = 3.15576e7
Reduce the hierarchy of sub-fields:
```julia
con = info.constants;
```
```julia
viewfields(con)
```
[Mera]: Constants given in cgs units
=========================================
Au = 0.01495978707
Mpc = 3.08567758128e24
kpc = 3.08567758128e21
pc = 3.08567758128e18
mpc = 3.08567758128e15
ly = 9.4607304725808e17
Msol = 1.9891e33
Msun = 1.9891e33
Mearth = 5.9722e27
Mjupiter = 1.89813e30
Rsol = 6.96e10
Rsun = 6.96e10
me = 9.1093897e-28
mp = 1.6726231e-24
mn = 1.6749286e-24
mH = 1.66e-24
amu = 1.6605402e-24
NA = 6.0221367e23
c = 2.99792458e10
G = 6.67259e-8
kB = 1.38062e-16
Gyr = 3.15576e16
Myr = 3.15576e13
yr = 3.15576e7
## InfoType Fields Overview
All fields and sub-fields that are assigned to the `InfoType` or from other objects can be viewed by the function **viewfields**, **namelist**, **makefile**, **timerfile**, **patchfile**.
See the methods list:
```julia
methods(viewfields)
```
11 methods for generic function <b>viewfields</b>:<ul><li> viewfields(object::<b>InfoType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:10</a></li> <li> viewfields(object::<b>ArgumentsType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:54</a></li> <li> viewfields(object::<b>ScalesType001</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:74</a></li> <li> viewfields(object::<b>PartInfoType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:90</a></li> <li> viewfields(object::<b>GridInfoType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:107</a></li> <li> viewfields(object::<b>CompilationInfoType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:133</a></li> <li> viewfields(object::<b>FileNamesType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:151</a></li> <li> viewfields(object::<b>DescriptorType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:167</a></li> <li> viewfields(object::<b>Mera.FilesContentType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:183</a></li> <li> viewfields(object::<b>PhysicalUnitsType001</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:198</a></li> <li> viewfields(object::<b>DataSetType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:215</a></li> </ul>
```julia
methods(namelist)
```
2 methods for generic function <b>namelist</b>:<ul><li> namelist(object::<b>InfoType</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:244</a></li> <li> namelist(object::<b>Dict{Any, Any}</b>) in Mera at <a href="file:///Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl" target="_blank">/Users/mabe/.julia/packages/Mera/tD6wJ/src/functions/viewfields.jl:262</a></li> </ul>
Get a detailed overview of all the fields from MERA composite types:
```julia
viewallfields(info)
```
output = 300
path = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10
fnames ==> subfields: (:output, :info, :amr, :hydro, :hydro_descriptor, :gravity, :particles, :part_descriptor, :rt, :rt_descriptor, :rt_descriptor_v0, :clumps, :timer, :header, :namelist, :compilation, :makefile, :patchfile)
simcode = RAMSES
mtime = 2023-04-09T05:34:09
ctime = 2023-04-10T08:08:14.488
ncpu = 640
ndim = 3
levelmin = 6
levelmax = 10
boxlen = 48.0
time = 29.9031937665063
aexp = 1.0
H0 = 1.0
omega_m = 1.0
omega_l = 0.0
omega_k = 0.0
omega_b = 0.045
unit_l = 3.085677581282e21
unit_d = 6.76838218451376e-23
unit_m = 1.9885499720830952e42
unit_v = 6.557528732282063e6
unit_t = 4.70554946422349e14
gamma = 1.6667
hydro = true
nvarh = 7
nvarp = 7
nvarrt = 0
variable_list = [:rho, :vx, :vy, :vz, :p, :var6, :var7]
gravity_variable_list = [:epot, :ax, :ay, :az]
particles_variable_list = [:vx, :vy, :vz, :mass, :family, :tag, :birth]
rt_variable_list = Symbol[]
clumps_variable_list = Symbol[]
sinks_variable_list = Symbol[]
descriptor ==> subfields: (:hversion, :hydro, :htypes, :usehydro, :hydrofile, :pversion, :particles, :ptypes, :useparticles, :particlesfile, :gravity, :usegravity, :gravityfile, :rtversion, :rt, :rtPhotonGroups, :usert, :rtfile, :clumps, :useclumps, :clumpsfile, :sinks, :usesinks, :sinksfile)
amr = true
gravity = true
particles = true
rt = false
clumps = false
sinks = false
namelist = true
namelist_content ==> dictionary: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
headerfile = true
makefile = true
files_content ==> subfields: (:makefile, :timerfile, :patchfile)
timerfile = true
compilationfile = false
patchfile = true
Narraysize = 0
scale ==> subfields: (:Mpc, :kpc, :pc, :mpc, :ly, :Au, :km, :m, :cm, :mm, :μm, :Mpc3, :kpc3, :pc3, :mpc3, :ly3, :Au3, :km3, :m3, :cm3, :mm3, :μm3, :Msol_pc3, :Msun_pc3, :g_cm3, :Msol_pc2, :Msun_pc2, :g_cm2, :Gyr, :Myr, :yr, :s, :ms, :Msol, :Msun, :Mearth, :Mjupiter, :g, :km_s, :m_s, :cm_s, :nH, :erg, :g_cms2, :T_mu, :K_mu, :T, :K, :Ba, :g_cm_s2, :p_kB, :K_cm3)
grid_info ==> subfields: (:ngridmax, :nstep_coarse, :nx, :ny, :nz, :nlevelmax, :nboundary, :ngrid_current, :bound_key, :cpu_read)
part_info ==> subfields: (:eta_sn, :age_sn, :f_w, :Npart, :Ndm, :Nstars, :Nsinks, :Ncloud, :Ndebris, :Nother, :Nundefined, :other_tracer1, :debris_tracer, :cloud_tracer, :star_tracer, :other_tracer2, :gas_tracer)
compilation ==> subfields: (:compile_date, :patch_dir, :remote_repo, :local_branch, :last_commit)
constants ==> subfields: (:Au, :Mpc, :kpc, :pc, :mpc, :ly, :Msol, :Msun, :Mearth, :Mjupiter, :Rsol, :Rsun, :me, :mp, :mn, :mH, :amu, :NA, :c, :G, :kB, :Gyr, :Myr, :yr)
[Mera]: Fields to scale from user/code units to selected units
=======================================================================
Mpc = 0.0010000000000006482
kpc = 1.0000000000006481
pc = 1000.0000000006482
mpc = 1.0000000000006482e6
ly = 3261.5637769461323
Au = 2.0626480623310105e23
km = 3.0856775812820004e16
m = 3.085677581282e19
cm = 3.085677581282e21
mm = 3.085677581282e22
μm = 3.085677581282e25
Mpc3 = 1.0000000000019446e-9
kpc3 = 1.0000000000019444
pc3 = 1.0000000000019448e9
mpc3 = 1.0000000000019446e18
ly3 = 3.469585750743794e10
Au3 = 8.775571306099254e69
km3 = 2.9379989454983075e49
m3 = 2.9379989454983063e58
cm3 = 2.9379989454983065e64
mm3 = 2.937998945498306e67
μm3 = 2.937998945498306e76
Msol_pc3 = 0.9997234790001649
Msun_pc3 = 0.9997234790001649
g_cm3 = 6.76838218451376e-23
Msol_pc2 = 999.7234790008131
Msun_pc2 = 999.7234790008131
g_cm2 = 0.20885045168302602
Gyr = 0.014910986463557083
Myr = 14.910986463557084
yr = 1.4910986463557083e7
s = 4.70554946422349e14
ms = 4.70554946422349e17
Msol = 9.99723479002109e8
Msun = 9.99723479002109e8
Mearth = 3.329677459032007e14
Mjupiter = 1.0476363431814971e12
g = 1.9885499720830952e42
km_s = 65.57528732282063
m_s = 65575.28732282063
cm_s = 6.557528732282063e6
nH = 30.987773856809987
erg = 8.551000140274429e55
g_cms2 = 2.9104844143584656e-9
T_mu = 517028.3199143136
K_mu = 517028.3199143136
T = 680300.4209398864
K = 680300.4209398864
Ba = 2.910484414358466e-9
g_cm_s2 = 2.910484414358466e-9
p_kB = 2.1080995598777838e7
K_cm3 = 2.1080995598777838e7
[Mera]: Constants given in cgs units
=========================================
Au = 0.01495978707
Mpc = 3.08567758128e24
kpc = 3.08567758128e21
pc = 3.08567758128e18
mpc = 3.08567758128e15
ly = 9.4607304725808e17
Msol = 1.9891e33
Msun = 1.9891e33
Mearth = 5.9722e27
Mjupiter = 1.89813e30
Rsol = 6.96e10
Rsun = 6.96e10
me = 9.1093897e-28
mp = 1.6726231e-24
mn = 1.6749286e-24
mH = 1.66e-24
amu = 1.6605402e-24
NA = 6.0221367e23
c = 2.99792458e10
G = 6.67259e-8
kB = 1.38062e-16
Gyr = 3.15576e16
Myr = 3.15576e13
yr = 3.15576e7
[Mera]: Paths and file-names
=================================
output = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300
info = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/info_00300.txt
amr = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/amr_00300.
hydro = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/hydro_00300.
hydro_descriptor = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/hydro_file_descriptor.txt
gravity = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/grav_00300.
particles = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/part_00300.
part_descriptor = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/part_file_descriptor.txt
rt = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/rt_00300.
rt_descriptor = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/rt_file_descriptor.txt
rt_descriptor_v0 = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/info_rt_00300.txt
clumps = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/clump_00300.
timer = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/timer_00300.txt
header = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/header_00300.txt
namelist = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/namelist.txt
compilation = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/compilation.txt
makefile = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/makefile.txt
patchfile = /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10/output_00300/patches.txt
[Mera]: Descriptor overview
=================================
hversion = 1
hydro = [:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01]
htypes = ["d", "d", "d", "d", "d", "d", "d"]
usehydro = false
hydrofile = true
pversion = 1
particles = [:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time]
ptypes = ["d", "d", "d", "d", "d", "d", "d", "i", "i", "b", "b", "d"]
useparticles = false
particlesfile = true
gravity = [:epot, :ax, :ay, :az]
usegravity = false
gravityfile = false
rtversion = 0
rt = Dict{Any, Any}()
rtPhotonGroups = Dict{Any, Any}()
usert = false
rtfile = false
clumps = Symbol[]
useclumps = false
clumpsfile = false
sinks = Symbol[]
usesinks = false
sinksfile = false
[Mera]: Namelist file content
=================================
&COOLING_PARAMS
cooling =.true.
z_ave =1.
&SF_PARAMS
m_star = 1
n_star = 10. !H/cc
T2_star = 0 !T/mu K
eps_star = 0.01 !1%
&AMR_PARAMS
levelmax =10
npartmax = 200000
ngridmax = 1000000 !1000000
boxlen =48.0 !kpc
levelmin =6
nexpand =1 !number of mesh expansions (mesh smoothing)
&BOUNDARY_PARAMS
jbound_min = 0, 0,-1,+1,-1,-1
kbound_max = 0, 0, 0, 0,-1,+1
no_inflow =.true.
bound_type = 2, 2, 2, 2, 2, 2 !2
nboundary = 6
ibound_max =-1,+1,+1,+1,+1,+1
ibound_min =-1,+1,-1,-1,-1,-1
jbound_max = 0, 0,-1,+1,+1,+1
kbound_min = 0, 0, 0, 0,-1,+1
&OUTPUT_PARAMS
tend =400
delta_tout =0.1 !Time increment between outputs
&POISSON_PARAMS
gravity_type =-3 !for 0 ->self gravitation ; 3 ->ext pot; -3 ->ext. pot. + sg
&RUN_PARAMS
pic =.true.
nsubcycle =20*2
ncontrol =100 !frequency of screen output
poisson =.true.
verbose =.false.
nremap =10 !10
nrestart =0
hydro =.true.
&FEEDBACK_PARAMS
eta_sn =0.2
delayed_cooling =.true.
t_diss = 1.5
&HYDRO_PARAMS
slope_type =1
smallr =1e-11
gamma =1.6667
courant_factor =0.6
!smallc =
riemann ='hllc'
&INIT_PARAMS
nregion =2
&REFINE_PARAMS
[Mera]: Grid overview
============================
ngridmax = 1000000
nstep_coarse = 6544
nx = 3
ny = 3
nz = 3
nlevelmax = 10
nboundary = 6
ngrid_current = 21305
bound_key ==> length(641)
cpu_read ==> length(641)
[Mera]: Particle overview
===============================
eta_sn = 0.0
age_sn = 0.6706464407596582
f_w = 0.0
Npart = 0
Ndm = 0
Nstars = 544515
Nsinks = 0
Ncloud = 0
Ndebris = 0
Nother = 0
Nundefined = 0
other_tracer1 = 0
debris_tracer = 0
cloud_tracer = 0
star_tracer = 0
other_tracer2 = 0
gas_tracer = 0
[Mera]: Compilation file overview
========================================
compile_date =
patch_dir =
remote_repo =
local_branch =
last_commit =
[Mera]: Makefile content
=================================
!content deleted on purpose
[Mera]: Timer-file content
=================================
--------------------------------------------------------------------
minimum average maximum standard dev std/av % rmn rmx TIMER
426.559 428.960 431.540 1.216 0.003 0.5 562 606 coarse levels
2086.863 2285.294 2620.028 109.814 0.048 2.9 639 1 refine
518.746 519.356 520.299 0.572 0.001 0.7 608 21 load balance
173.017 565.169 1799.729 385.862 0.683 0.7 602 1 particles
5897.562 5897.616 5897.791 0.018 0.000 7.5 244 1 io
5176.808 9619.415 26606.857 5416.924 0.563 12.3 568 1 feedback
25022.898 25410.890 25585.446 143.363 0.006 32.4 1 602 poisson
1131.397 2241.256 2547.320 322.916 0.144 2.9 1 345 rho
521.635 678.056 1076.044 151.775 0.224 0.9 601 1 courant
82.818 115.742 135.415 10.926 0.094 0.1 398 125 hydro - set unew
7009.921 9876.180 12208.171 1176.765 0.119 12.6 481 343 hydro - godunov
948.967 16679.099 23569.950 4760.658 0.285 21.3 640 340 hydro - rev ghostzones
189.513 208.576 229.883 7.902 0.038 0.3 398 581 hydro - set uold
1757.246 1795.542 1860.788 11.757 0.007 2.3 524 180 cooling
84.519 300.570 375.587 67.032 0.223 0.4 1 593 hydro - ghostzones
933.143 1662.855 1788.316 119.084 0.072 2.1 1 639 flag
78327.986 100.0 TOTAL
## Disc Space
Gives an overview of the used disc space for the different data types of the selected output:
```julia
storageoverview(info)
```
Overview of the used disc space for output: [300]
------------------------------------------------------
Folder: 5.68 GB <2.26 MB>/file
AMR-Files: 1.1 GB <1.75 MB>/file
Hydro-Files: 2.87 GB <4.58 MB>/file
Gravity-Files: 1.68 GB <2.69 MB>/file
Particle-Files: 38.56 MB <61.6 KB>/file
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
Dict{Any, Any} with 8 entries:
:folder => 6101105264
:sink => 0.0
:particle => 40430034
:hydro => 3079240490
:gravity => 1802094080
:amr => 1177085816
:clump => 0.0
:rt => 0.0
## Simulation outputs
Get an overview of existing output folders of a simulation
```julia
co = checkoutputs("../../testing/simulations/mw_L10")
```
Outputs - existing: 1 betw. 300:300 - missing: 1
Mera.CheckOutputNumberType([300], [301], "../../testing/simulations/mw_L10")
```julia
# It returns all output numbers of existing or missing (e.g. empty) folders:
propertynames(co)
```
(:outputs, :miss, :path)
```julia
co.outputs
```
1-element Vector{Int64}:
300
```julia
co.miss
```
1-element Vector{Int64}:
301
```julia
```
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 9743 | # 1. Clumps: First Data Inspection
## Simulation Overview
```julia
using Mera
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
```
[Mera]: 2020-02-12T20:41:16.814
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
A short overview of the loaded clumps properties is printed:
- existence of clumps files
- the variable names from the header of the clump files
## Load Clump Data
Read the Clumps data from all files of the full box with all existing variables. **MERA** checks the first line of a clump file to find the column names. The identified names give the number of existing columns.
```julia
clumps = getclumps(info);
```
[Mera]: Get clump data: 2020-02-12T20:41:23.656
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
The memory consumption of the data table is printed at the end. We provide a function which gives the possibility to print the used memory of any object:
```julia
usedmemory(clumps);
```
Memory used: 331.672 KB
The assigned object is now of type: `ClumpsDataType`:
```julia
typeof(clumps)
```
ClumpDataType
It is a sub-type of `ContainMassDataSetType`
```julia
supertype( ContainMassDataSetType )
```
DataSetType
`ContainMassDataSetType` is a sub-type of to the super-type `DataSetType`
```julia
supertype( ClumpDataType )
```
ContainMassDataSetType
The data is stored as a **JuliaDB** table and the selected clump variables and parameters are assigned to fields:
```julia
viewfields(clumps)
```
data ==> JuliaDB table: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
info ==> subfields: (:output, :path, :fnames, :simcode, :mtime, :ctime, :ncpu, :ndim, :levelmin, :levelmax, :boxlen, :time, :aexp, :H0, :omega_m, :omega_l, :omega_k, :omega_b, :unit_l, :unit_d, :unit_m, :unit_v, :unit_t, :gamma, :hydro, :nvarh, :nvarp, :variable_list, :gravity_variable_list, :particles_variable_list, :clumps_variable_list, :sinks_variable_list, :descriptor, :amr, :gravity, :particles, :clumps, :sinks, :rt, :namelist, :namelist_content, :headerfile, :makefile, :files_content, :timerfile, :compilationfile, :patchfile, :Narraysize, :scale, :grid_info, :part_info, :compilation, :constants)
boxlen = 48.0
ranges = [0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
selected_clumpvars = Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
scale ==> subfields: (:Mpc, :kpc, :pc, :mpc, :ly, :Au, :km, :m, :cm, :mm, :μm, :Msol_pc3, :g_cm3, :Msol_pc2, :g_cm2, :Gyr, :Myr, :yr, :s, :ms, :Msol, :Mearth, :Mjupiter, :g, :km_s, :m_s, :cm_s, :nH, :erg, :g_cms2, :T_mu, :Ba)
For convenience, all the fields from the info-object above (InfoType) are now also accessible from the object with "clumps.info" and the scaling relations from code to cgs units in "clumps.scale". The box length, the selected ranges and number of the clump variables are also retained.
Print the fields of an object (composite type) in a simple list:
```julia
propertynames(clumps)
```
(:data, :info, :boxlen, :ranges, :selected_clumpvars, :used_descriptors, :scale)
## Overview of Clump Data
Get some overview of the data associated with the object `clumps`. The calculated information can be accessed from the object `data_overview` (here) in code units for further calculations:
```julia
data_overview = dataoverview(clumps)
```
Table with 2 rows, 13 columns:
Columns:
# colname type
───────────────────
1 extrema Any
2 index Any
3 lev Any
4 parent Any
5 ncell Any
6 peak_x Any
7 peak_y Any
8 peak_z Any
9 rho- Any
10 rho+ Any
11 rho_av Any
12 mass_cl Any
13 relevance Any
If the number of columns is relatively long, the table is typically represented by an overview. To access certain columns, use the `select` function. The representation ":mass_cl" is called a quoted Symbol ([see in Julia documentation](https://docs.julialang.org/en/v1/manual/metaprogramming/#Symbols-1)):
```julia
using JuliaDB
```
```julia
select(data_overview, (:extrema, :index, :peak_x, :peak_y, :peak_z, :mass_cl) )
```
Table with 2 rows, 6 columns:
extrema index peak_x peak_y peak_z mass_cl
──────────────────────────────────────────────────────
"min" 4.0 10.292 9.93604 22.1294 0.00031216
"max" 2147.0 38.1738 35.7056 25.4634 0.860755
Get an array from the column ":mass_cl" in `data_overview` and scale it to the units `Msol`. The order of the calculated data is consistent with the table above:
```julia
select(data_overview, :mass_cl) * info.scale.Msol
```
2-element Array{Float64,1}:
312073.3187055649
8.605166312657958e8
Or simply convert the `:mass_cl` data in the table to `Msol` units by manipulating the column:
```julia
data_overview = transform(data_overview, :mass_cl => :mass_cl => value->value * info.scale.Msol);
```
```julia
select(data_overview, (:extrema, :index, :peak_x, :peak_y, :peak_z, :mass_cl) )
```
Table with 2 rows, 6 columns:
extrema index peak_x peak_y peak_z mass_cl
─────────────────────────────────────────────────────
"min" 4.0 10.292 9.93604 22.1294 3.12073e5
"max" 2147.0 38.1738 35.7056 25.4634 8.60517e8
## Data Inspection
The data is associated with the field `clumps.data` as a **JuliaDB** table (code units). Each row corresponds to a clump and each column to a property which makes it easy to find, filter, map, aggregate, group the data, etc.
More information can be found in the MERA tutorials or in: [JuliaDB API Reference](http://juliadb.org/latest/api/)
### Table View
The positions peak_x, peak_y,peak_z are the positions and should not be modified.
```julia
clumps.data
```
Table with 644 rows, 12 columns:
Columns:
# colname type
──────────────────────
1 index Float64
2 lev Float64
3 parent Float64
4 ncell Float64
5 peak_x Float64
6 peak_y Float64
7 peak_z Float64
8 rho- Float64
9 rho+ Float64
10 rho_av Float64
11 mass_cl Float64
12 relevance Float64
A more detailed view into the data:
```julia
select(clumps.data, (:index, :peak_x, :peak_y, :peak_z, :mass_cl) )
```
Table with 644 rows, 5 columns:
index peak_x peak_y peak_z mass_cl
─────────────────────────────────────────────
4.0 20.1094 11.5005 23.9604 0.0213767
5.0 20.1592 11.5122 23.9253 0.0131504
9.0 21.7852 17.855 23.814 0.00358253
12.0 21.8232 17.8608 23.855 0.00509792
13.0 21.8906 17.2837 23.5415 0.0319414
18.0 21.7822 16.8823 23.7817 0.00848828
19.0 21.75 16.8589 23.7993 0.00587003
20.0 21.6006 17.5679 23.7935 0.0324672
25.0 21.5801 17.6177 23.9341 0.0245806
26.0 21.5859 17.5796 23.9165 0.0183601
29.0 21.5625 17.5854 23.8726 0.0303356
46.0 21.5215 17.6235 23.9458 0.343594
⋮
2115.0 27.7705 13.2788 23.8081 0.0340939
2116.0 27.7617 13.3081 23.8081 0.0145199
2117.0 27.7793 13.2993 23.6851 0.00855992
2120.0 27.7559 13.1792 23.8638 0.00508007
2125.0 27.7939 13.0298 23.9194 0.00128829
2128.0 27.791 13.0649 23.9019 0.00183979
2131.0 28.3037 12.8188 23.9487 0.00128627
2132.0 28.626 12.8188 23.8755 0.00434
2137.0 29.9736 15.0571 23.7202 0.00195464
2140.0 27.1436 15.6401 23.9048 0.0160477
2147.0 25.1953 9.93604 23.9897 0.0294943
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 14092 | # 1. Hydro: First Data Inspection
## Simulation Overview
```julia
using Mera
info = getinfo(300, "../../testing/simulations/mw_L10");
```
[Mera]: 2023-04-10T10:48:46.483
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
A short overview of the loaded hydro properties is printed:
- existence of hydro files
- the number and predefined variables
- the variable names from the descriptor file
- adiabatic index
The functions in **Mera** "know" the predefined hydro variable names: :rho, :vx, :vy, :vz, :p, :var6, :var7,.... In a future version the variable names from the hydro descriptor can be used by setting the field info.descriptor.usehydro = true . Furthermore, the user has the opportunity to overwrite the variable names in the discriptor list by changing the entries in the array:
```julia
info.descriptor.hydro
```
7-element Vector{Symbol}:
:density
:velocity_x
:velocity_y
:velocity_z
:pressure
:scalar_00
:scalar_01
For example:
```julia
info.descriptor.hydro[2] = :vel_x;
```
```julia
info.descriptor.hydro
```
7-element Vector{Symbol}:
:density
:vel_x
:velocity_y
:velocity_z
:pressure
:scalar_00
:scalar_01
Get an overview of the loaded descriptor properties:
```julia
viewfields(info.descriptor)
```
[Mera]: Descriptor overview
=================================
hversion = 1
hydro = [:density, :vel_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01]
htypes = ["d", "d", "d", "d", "d", "d", "d"]
usehydro = false
hydrofile = true
pversion = 1
particles = [:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time]
ptypes = ["d", "d", "d", "d", "d", "d", "d", "i", "i", "b", "b", "d"]
useparticles = false
particlesfile = true
gravity = [:epot, :ax, :ay, :az]
usegravity = false
gravityfile = false
rtversion = 0
rt = Dict{Any, Any}()
rtPhotonGroups = Dict{Any, Any}()
usert = false
rtfile = false
clumps = Symbol[]
useclumps = false
clumpsfile = false
sinks = Symbol[]
usesinks = false
sinksfile = false
Get a simple list of the fields:
```julia
propertynames(info.descriptor)
```
(:hversion, :hydro, :htypes, :usehydro, :hydrofile, :pversion, :particles, :ptypes, :useparticles, :particlesfile, :gravity, :usegravity, :gravityfile, :rtversion, :rt, :rtPhotonGroups, :usert, :rtfile, :clumps, :useclumps, :clumpsfile, :sinks, :usesinks, :sinksfile)
## Load AMR/Hydro Data
```julia
info = getinfo(300, "../../testing/simulations/mw_L10", verbose=false); # used to overwrite the previous changes
```
Read the AMR and the Hydro data from all files of the full box with all existing variables and cell positions (only leaf cells of the AMR grid).
```julia
gas = gethydro(info);
```
[Mera]: Get hydro data: 2023-04-10T10:49:21.228
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:29
Memory used for data table :2.3210865957662463 GB
-------------------------------------------------------
The memory consumption of the data table is printed at the end. We provide a function which gives the possibility to print the used memory of any object:
```julia
usedmemory(gas);
```
Memory used: 2.321 GB
The assigned data object is now of type `HydroDataType`:
```julia
typeof(gas)
```
HydroDataType
It is a sub-type of `ContainMassDataSetType`
```julia
supertype( ContainMassDataSetType )
```
DataSetType
`ContainMassDataSetType` is a sub-type of to the super-type `DataSetType`
```julia
supertype( HydroDataType )
```
HydroPartType
The data is stored in a **JuliaDB** table and the user selected hydro variables and parameters are assigned to fields:
```julia
viewfields(gas)
```
data ==> JuliaDB table: (:level, :cx, :cy, :cz, :rho, :vx, :vy, :vz, :p, :var6, :var7)
info ==> subfields: (:output, :path, :fnames, :simcode, :mtime, :ctime, :ncpu, :ndim, :levelmin, :levelmax, :boxlen, :time, :aexp, :H0, :omega_m, :omega_l, :omega_k, :omega_b, :unit_l, :unit_d, :unit_m, :unit_v, :unit_t, :gamma, :hydro, :nvarh, :nvarp, :nvarrt, :variable_list, :gravity_variable_list, :particles_variable_list, :rt_variable_list, :clumps_variable_list, :sinks_variable_list, :descriptor, :amr, :gravity, :particles, :rt, :clumps, :sinks, :namelist, :namelist_content, :headerfile, :makefile, :files_content, :timerfile, :compilationfile, :patchfile, :Narraysize, :scale, :grid_info, :part_info, :compilation, :constants)
lmin = 6
lmax = 10
boxlen = 48.0
ranges = [0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
selected_hydrovars = [1, 2, 3, 4, 5, 6, 7]
smallr = 0.0
smallc = 0.0
scale ==> subfields: (:Mpc, :kpc, :pc, :mpc, :ly, :Au, :km, :m, :cm, :mm, :μm, :Mpc3, :kpc3, :pc3, :mpc3, :ly3, :Au3, :km3, :m3, :cm3, :mm3, :μm3, :Msol_pc3, :Msun_pc3, :g_cm3, :Msol_pc2, :Msun_pc2, :g_cm2, :Gyr, :Myr, :yr, :s, :ms, :Msol, :Msun, :Mearth, :Mjupiter, :g, :km_s, :m_s, :cm_s, :nH, :erg, :g_cms2, :T_mu, :K_mu, :T, :K, :Ba, :g_cm_s2, :p_kB, :K_cm3)
For convenience, all the fields from the info-object above (InfoType) are now also accessible from the object with "gas.info" and the scaling relations from code to cgs units in "gas.scale". The minimum and maximum level of the loaded data, the box length, the selected ranges and number of the hydro variables are retained.
A minimum density or sound speed can be set for the loaded data (e.g. to overwrite negative densities) and is then represented by the fields smallr and smallc of the object `gas` (here). An example:
```julia
gas = gethydro(info, smallr=1e-11);
```
[Mera]: Get hydro data: 2023-04-10T10:54:09.424
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:25
Memory used for data table :2.3210865957662463 GB
-------------------------------------------------------
Print the fields of an object (composite type) in a simple list:
```julia
propertynames(gas)
```
(:data, :info, :lmin, :lmax, :boxlen, :ranges, :selected_hydrovars, :used_descriptors, :smallr, :smallc, :scale)
## Overview of AMR/Hydro
Get an overview of the AMR structure associated with the object `gas` (HydroDataType).
The printed information is stored into the object `overview_amr` as a **JuliaDB** table (code units) and can be used for further calculations:
```julia
overview_amr = amroverview(gas)
```
Counting...
Table with 5 rows, 3 columns:
level cells cellsize
─────────────────────────
6 66568 0.75
7 374908 0.375
8 7806793 0.1875
9 12774134 0.09375
10 7298576 0.046875
Get some overview of the data that is associated with the object `gas`. The calculated information can be accessed from the object `data_overview` (here) in code units for further calculations:
```julia
data_overview = dataoverview(gas)
```
Calculating...
100%|███████████████████████████████████████████████████| Time: 0:00:06
Table with 5 rows, 16 columns:
Columns:
# colname type
──────────────────
1 level Any
2 mass Any
3 rho_min Any
4 rho_max Any
5 vx_min Any
6 vx_max Any
7 vy_min Any
8 vy_max Any
9 vz_min Any
10 vz_max Any
11 p_min Any
12 p_max Any
13 var6_min Any
14 var6_max Any
15 var7_min Any
16 var7_max Any
If the number of columns is relatively long, the table is typically represented by an overview. To access certain columns, use the `select` function. The representation ":mass" is called a quoted Symbol ([see in Julia documentation](https://docs.julialang.org/en/v1/manual/metaprogramming/#Symbols-1)):
```julia
using JuliaDB
```
```julia
select(data_overview, (:level,:mass, :rho_min, :rho_max ) )
```
Table with 5 rows, 4 columns:
level mass rho_min rho_max
───────────────────────────────────────────
6 0.000698165 2.61776e-9 1.16831e-7
7 0.00126374 1.15139e-8 2.21103e-7
8 0.0201245 2.44071e-8 0.000222309
9 0.204407 1.2142e-7 0.0141484
10 6.83618 4.49036e-7 3.32984
Get an array from the column ":mass" in `data_overview` and scale it to the units `Msol`. The order of the calculated data is consistent with the table above:
```julia
column(data_overview, :mass) * info.scale.Msol
```
5-element Vector{Float64}:
697971.5415380469
1.2633877595077453e6
2.01189316548175e7
2.0435047070331135e8
6.834288803451587e9
Or simply convert the `:mass` data in the table to `Msol` units by manipulating the column:
```julia
data_overview = transform(data_overview, :mass => :mass => value->value * info.scale.Msol);
```
```julia
select(data_overview, (:level, :mass, :rho_min, :rho_max ) )
```
Table with 5 rows, 4 columns:
level mass rho_min rho_max
─────────────────────────────────────────
6 6.97972e5 2.61776e-9 1.16831e-7
7 1.26339e6 1.15139e-8 2.21103e-7
8 2.01189e7 2.44071e-8 0.000222309
9 2.0435e8 1.2142e-7 0.0141484
10 6.83429e9 4.49036e-7 3.32984
## Data Inspection
The data is associated with the field `gas.data` as a **JuliaDB** table (code units).
Each row corresponds to a cell and each column to a property which makes it easy to find, filter, map, aggregate, group the data, etc.
More information can be found in the **Mera** tutorials or in: [JuliaDB API Reference](http://juliadb.org/latest/api/)
### Table View
The cell positions cx,cy,cz correspond to a uniform 3D array for each level. E.g., for level=8, the positions range from 1-256 for each dimension, for level=14, 1-16384 while not all positions within this range exist due to the complex AMR structure. The integers cx,cy,cz are used to reconstruct the grid in many functions of **MERA** and should not be modified.
```julia
gas.data
```
Table with 28320979 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
A more detailed view into the data:
```julia
select(gas.data, (:level,:cx, :cy, :cz, :rho) )
```
Table with 28320979 rows, 5 columns:
level cx cy cz rho
─────────────────────────────────
6 1 1 1 3.18647e-9
6 1 1 2 3.58591e-9
6 1 1 3 3.906e-9
6 1 1 4 4.27441e-9
6 1 1 5 4.61042e-9
6 1 1 6 4.83977e-9
6 1 1 7 4.974e-9
6 1 1 8 5.08112e-9
6 1 1 9 5.20596e-9
6 1 1 10 5.38372e-9
6 1 1 11 5.67209e-9
6 1 1 12 6.14423e-9
⋮
10 814 493 514 0.000321702
10 814 494 509 1.42963e-6
10 814 494 510 1.4351e-6
10 814 494 511 0.00029515
10 814 494 512 0.000395273
10 814 494 513 0.000321133
10 814 494 514 0.000319678
10 814 495 511 0.00024646
10 814 495 512 0.000269009
10 814 496 511 0.000235329
10 814 496 512 0.000242422
```julia
```
```julia
```
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 12150 | # 1. Particles: First Data Inspection
## Simulation Overview
```julia
using Mera
info = getinfo(300, "../../testing/simulations/mw_L10");
```
[Mera]: 2023-04-10T10:58:43.590
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
A short overview of the loaded particle properties is printed:
- existence of particle files
- the predefined variables
- the number of particles for each id/family (if exist)
- the variable names from the descriptor file (if exist)
The functions in **Mera** "know" the predefined particle variable names:
- From >= ramses-version-2018: :vx, :vy, :vz, :mass, :family, :tag, :birth, :metals :var9,....
- For =< ramses-version-2017: :vx, :vy, :vz, :mass, :birth, :var6, :var7,....
- Currently, the following variables are loaded by default (if exist): :level, :x, :y, :z, :id, :family, :tag.
- The cpu number associated with the particles can be loaded with the variable names: :cpu or :varn1
- In a future version the variable names from the particle descriptor can be used by setting the field info.descriptor.useparticles = true .
Get an overview of the loaded particle properties:
```julia
viewfields(info.part_info)
```
[Mera]: Particle overview
===============================
eta_sn = 0.0
age_sn = 0.6706464407596582
f_w = 0.0
Npart = 0
Ndm = 0
Nstars = 544515
Nsinks = 0
Ncloud = 0
Ndebris = 0
Nother = 0
Nundefined = 0
other_tracer1 = 0
debris_tracer = 0
cloud_tracer = 0
star_tracer = 0
other_tracer2 = 0
gas_tracer = 0
## Load AMR/Particle Data
Read the AMR and the Particle data from all files of the full box with all existing variables and particle positions:
```julia
particles = getparticles(info);
```
[Mera]: Get particle data: 2023-04-10T10:58:56.439
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
[32mProgress: 100%|█████████████████████████████████████████| Time: 0:00:02[39m
Found 5.445150e+05 particles
Memory used for data table :38.42913246154785 MB
-------------------------------------------------------
The memory consumption of the data table is printed at the end. We provide a function which gives the possibility to print the used memory of any object:
```julia
usedmemory(particles);
```
Memory used: 38.451 MB
The assigned object is now of type `PartDataType`:
```julia
typeof(particles)
```
PartDataType
It is a sub-type of ContainMassDataSetType
```julia
supertype( ContainMassDataSetType )
```
DataSetType
ContainMassDataSetType is a sub-type of to the super-type DataSetType
```julia
supertype( PartDataType )
```
HydroPartType
The data is stored in a **JuliaDB** table and the user selected particle variables and parameters are assigned to fields:
```julia
viewfields(particles)
```
data ==> JuliaDB table: (:level, :x, :y, :z, :id, :family, :tag, :vx, :vy, :vz, :mass, :birth)
info ==> subfields: (:output, :path, :fnames, :simcode, :mtime, :ctime, :ncpu, :ndim, :levelmin, :levelmax, :boxlen, :time, :aexp, :H0, :omega_m, :omega_l, :omega_k, :omega_b, :unit_l, :unit_d, :unit_m, :unit_v, :unit_t, :gamma, :hydro, :nvarh, :nvarp, :nvarrt, :variable_list, :gravity_variable_list, :particles_variable_list, :rt_variable_list, :clumps_variable_list, :sinks_variable_list, :descriptor, :amr, :gravity, :particles, :rt, :clumps, :sinks, :namelist, :namelist_content, :headerfile, :makefile, :files_content, :timerfile, :compilationfile, :patchfile, :Narraysize, :scale, :grid_info, :part_info, :compilation, :constants)
lmin = 6
lmax = 10
boxlen = 48.0
ranges = [0.0, 1.0, 0.0, 1.0, 0.0, 1.0]
selected_partvars = [:level, :x, :y, :z, :id, :family, :tag, :vx, :vy, :vz, :mass, :birth]
scale ==> subfields: (:Mpc, :kpc, :pc, :mpc, :ly, :Au, :km, :m, :cm, :mm, :μm, :Mpc3, :kpc3, :pc3, :mpc3, :ly3, :Au3, :km3, :m3, :cm3, :mm3, :μm3, :Msol_pc3, :Msun_pc3, :g_cm3, :Msol_pc2, :Msun_pc2, :g_cm2, :Gyr, :Myr, :yr, :s, :ms, :Msol, :Msun, :Mearth, :Mjupiter, :g, :km_s, :m_s, :cm_s, :nH, :erg, :g_cms2, :T_mu, :K_mu, :T, :K, :Ba, :g_cm_s2, :p_kB, :K_cm3)
For convenience, all the fields from the info-object above (InfoType) are now also accessible from the object with "particles.info" and the scaling relations from code to cgs units in "particles.scale".
Print the fields of an object (composite type) in a simple list:
```julia
propertynames(particles)
```
(:data, :info, :lmin, :lmax, :boxlen, :ranges, :selected_partvars, :used_descriptors, :scale)
## Overview of AMR/Particles
Get an overview of the AMR structure associated with the object `particles` (PartDataType). The printed information is stored into the object `overview_amr` as a **JuliaDB** table (code units) and can be used for further calculations:
```julia
amr_overview = amroverview(particles)
```
Counting...
Table with 5 rows, 2 columns:
level particles
────────────────
6 1389
7 543126
8 0
9 0
10 0
Get some overview of the data that is associated with the object `particles`. The calculated information can be accessed from the object `data_overview` (here) in code units for further calculations:
```julia
data_overview = dataoverview(particles)
```
Calculating...
Table with 5 rows, 23 columns:
Columns:
# colname type
────────────────────
1 level Any
2 x_min Any
3 x_max Any
4 y_min Any
5 y_max Any
6 z_min Any
7 z_max Any
8 id_min Any
9 id_max Any
10 family_min Any
11 family_max Any
12 tag_min Any
13 tag_max Any
14 vx_min Any
15 vx_max Any
16 vy_min Any
17 vy_max Any
18 vz_min Any
19 vz_max Any
20 mass_min Any
21 mass_max Any
22 birth_min Any
23 birth_max Any
If the number of columns is relatively long, the table is typically represented by an overview. To access certain columns, use the `select` function. The representation ":birth_max" is called a quoted Symbol ([see in Julia documentation](https://docs.julialang.org/en/v1/manual/metaprogramming/#Symbols-1)):
```julia
using JuliaDB
```
```julia
select(data_overview, (:level,:mass_min, :mass_max, :birth_min, :birth_max ) )
```
Table with 5 rows, 5 columns:
level mass_min mass_max birth_min birth_max
───────────────────────────────────────────────────
6 0.0 0.0 0.0 0.0
7 0.0 0.0 0.0 0.0
8 0.0 0.0 0.0 0.0
9 8.00221e-7 8.00221e-7 5.56525 22.126
10 8.00221e-7 2.00055e-6 0.0951753 29.9032
Get an array from the column ":birth" in `data_overview` and scale it to the units `Myr`. The order of the calculated data is consistent with the table above:
```julia
column(data_overview, :birth_min) * info.scale.Myr
```
5-element Vector{Float64}:
0.0
0.0
0.0
82.98342559299353
1.419158337486011
Or simply convert the `birth_max` data in the table to `Myr` units by manipulating the column:
```julia
data_overview = transform(data_overview, :birth_max => :birth_max => value->value * info.scale.Myr);
```
```julia
select(data_overview, (:level,:mass_min, :mass_max, :birth_min, :birth_max ) )
```
Table with 5 rows, 5 columns:
level mass_min mass_max birth_min birth_max
───────────────────────────────────────────────────
6 0.0 0.0 0.0 0.0
7 0.0 0.0 0.0 0.0
8 0.0 0.0 0.0 0.0
9 8.00221e-7 8.00221e-7 5.56525 329.92
10 8.00221e-7 2.00055e-6 0.0951753 445.886
## Data inspection
The data is associated with the field `particles.data` as a **JuliaDB** table (code units).
Each row corresponds to a particle and each column to a property which makes it easy to find, filter, map, aggregate, group the data, etc.
More information can be found in the **Mera** tutorials or in: [JuliaDB API Reference](http://juliadb.org/latest/api/)
### Table View
The particle positions x,y,z are given in code units and used in many functions of **MERA** and should not be modified.
```julia
particles.data
```
Table with 544515 rows, 12 columns:
Columns:
# colname type
────────────────────
1 level Int32
2 x Float64
3 y Float64
4 z Float64
5 id Int32
6 family Int8
7 tag Int8
8 vx Float64
9 vy Float64
10 vz Float64
11 mass Float64
12 birth Float64
A more detailed view into the data:
```julia
select(particles.data, (:level,:x, :y, :z, :birth) )
```
Table with 544515 rows, 5 columns:
level x y z birth
─────────────────────────────────────────
9 9.17918 22.4404 24.0107 8.86726
9 9.23642 21.5559 24.0144 8.71495
9 9.35638 20.7472 24.0475 7.91459
9 9.39529 21.1854 24.0155 7.85302
9 9.42686 20.9697 24.0162 8.2184
9 9.42691 22.2181 24.0137 8.6199
9 9.48834 22.0913 24.0137 8.70493
9 9.5262 20.652 24.0179 7.96008
9 9.60376 21.2814 24.0155 8.03346
9 9.6162 20.6243 24.0506 8.56482
9 9.62155 20.6248 24.0173 7.78062
9 9.62252 24.4396 24.0206 9.44825
⋮
10 37.7913 25.6793 24.018 9.78881
10 37.8255 22.6271 24.0279 9.89052
10 37.8451 22.7506 24.027 9.61716
10 37.8799 25.5668 24.0193 10.2294
10 37.969 23.2135 24.0273 9.85439
10 37.9754 22.6288 24.0265 9.4959
10 37.9811 23.2854 24.0283 9.9782
10 37.9919 22.873 24.0271 9.12003
10 37.9966 23.092 24.0281 9.45574
10 38.0328 22.8404 24.0265 9.77493
10 38.0953 22.8757 24.0231 9.20251
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 15552 | # 2. Clumps: Load Selected Variables and Data Ranges
## Simulation Overview
```julia
using Mera
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
```
[Mera]: 2020-02-08T13:43:44.724
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
## Select Variables
**MERA** reads the first line of a clump file to identify the number of columns and their names.
### Read all variables (default)
```julia
clumps = getclumps(info);
```
[Mera]: Get clump data: 2020-02-08T13:43:54.134
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
```julia
clumps.data
```
Table with 644 rows, 12 columns:
Columns:
# colname type
──────────────────────
1 index Float64
2 lev Float64
3 parent Float64
4 ncell Float64
5 peak_x Float64
6 peak_y Float64
7 peak_z Float64
8 rho- Float64
9 rho+ Float64
10 rho_av Float64
11 mass_cl Float64
12 relevance Float64
The colum names should not be changed, since they are assumed in some functions. The usage of individual descriptor variables will be implemented in the future.
### Select several variables w/o a keyword
Currently, the length of the loaded variable list can be modified. E.g. the list can be extended with more names if there are more columns in the data than given by the header in the files.
Load less than the found 12 columns from the header of the clump files; Pass an array with the variables to the keyword argument `vars`. The order of the variables has to be consistent with the header in the clump files:}
```julia
clumps = getclumps(info, vars=[ :index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z]);
```
[Mera]: Get clump data: 2020-02-08T13:44:01.434
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 7 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z]
Memory used for data table :36.1083984375 KB
-------------------------------------------------------
Pass an array that contains the variables without the keyword argument `vars`. The following order has to be preserved: InfoType-object, variables
```julia
clumps = getclumps(info, [ :index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z]);
```
[Mera]: Get clump data: 2020-02-08T13:44:03.36
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 7 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z]
Memory used for data table :36.1083984375 KB
-------------------------------------------------------
```julia
clumps.data
```
Table with 644 rows, 7 columns:
index lev parent ncell peak_x peak_y peak_z
──────────────────────────────────────────────────────
4.0 0.0 4.0 740.0 20.1094 11.5005 23.9604
5.0 0.0 5.0 1073.0 20.1592 11.5122 23.9253
9.0 0.0 9.0 551.0 21.7852 17.855 23.814
12.0 0.0 12.0 463.0 21.8232 17.8608 23.855
13.0 0.0 13.0 2141.0 21.8906 17.2837 23.5415
18.0 0.0 18.0 691.0 21.7822 16.8823 23.7817
19.0 0.0 19.0 608.0 21.75 16.8589 23.7993
20.0 0.0 20.0 1253.0 21.6006 17.5679 23.7935
25.0 0.0 25.0 1275.0 21.5801 17.6177 23.9341
26.0 0.0 26.0 1212.0 21.5859 17.5796 23.9165
29.0 0.0 29.0 1759.0 21.5625 17.5854 23.8726
46.0 0.0 46.0 4741.0 21.5215 17.6235 23.9458
⋮
2115.0 0.0 2115.0 1071.0 27.7705 13.2788 23.8081
2116.0 0.0 2116.0 839.0 27.7617 13.3081 23.8081
2117.0 0.0 2117.0 753.0 27.7793 13.2993 23.6851
2120.0 0.0 2120.0 866.0 27.7559 13.1792 23.8638
2125.0 0.0 2125.0 181.0 27.7939 13.0298 23.9194
2128.0 0.0 2128.0 296.0 27.791 13.0649 23.9019
2131.0 0.0 2131.0 323.0 28.3037 12.8188 23.9487
2132.0 0.0 2132.0 615.0 28.626 12.8188 23.8755
2137.0 0.0 2137.0 318.0 29.9736 15.0571 23.7202
2140.0 0.0 2140.0 1719.0 27.1436 15.6401 23.9048
2147.0 0.0 2147.0 1535.0 25.1953 9.93604 23.9897
Load more than the found 12 columns from the header of the clump files. The order of the variables has to be consistent with the header in the clump files:
```julia
clumps = getclumps(info, vars=[ :index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance, :vx, :vy, :vz]);
```
[Mera]: Get clump data: 2020-02-08T13:44:04.175
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 15 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance, :vx, :vy, :vz]
Memory used for data table :77.1787109375 KB
-------------------------------------------------------
```julia
clumps.data
```
Table with 644 rows, 15 columns:
Columns:
# colname type
──────────────────────
1 index Float64
2 lev Float64
3 parent Float64
4 ncell Float64
5 peak_x Float64
6 peak_y Float64
7 peak_z Float64
8 rho- Float64
9 rho+ Float64
10 rho_av Float64
11 mass_cl Float64
12 relevance Float64
13 vx Float64
14 vy Float64
15 vz Float64
## Select Spatial Ranges
### Use RAMSES Standard Notation
Ranges correspond to the domain [0:1]^3 and are related to the box corner at [0., 0., 0.] by default.
```julia
clumps = getclumps(info,
xrange=[0.2,0.8],
yrange=[0.2,0.8],
zrange=[0.4,0.6]);
```
[Mera]: Get clump data: 2020-02-08T13:44:06.579
domain:
xmin::xmax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
ymin::ymax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
zmin::zmax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
The loaded data ranges are assigned to the field `ranges` in an array in **RAMSES** standard notation (domain: [0:1]^3):
```julia
clumps.ranges
```
6-element Array{Float64,1}:
0.2
0.8
0.2
0.8
0.4
0.6
### Ranges relative to a given center:
```julia
clumps = getclumps(info,
xrange=[-0.3, 0.3],
yrange=[-0.3, 0.3],
zrange=[-0.1, 0.1],
center=[0.5, 0.5, 0.5]);
```
[Mera]: Get clump data: 2020-02-08T13:44:09.633
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
ymin::ymax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
zmin::zmax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
### Use notation in physical units
In the following example the ranges are given in units "kpc", relative to the box corner [0., 0., 0.] (default):
```julia
clumps = getclumps(info,
xrange=[2.,22.],
yrange=[2.,22.],
zrange=[22.,26.],
range_unit=:kpc);
```
[Mera]: Get clump data: 2020-02-08T13:44:09.96
domain:
xmin::xmax: 0.0416667 :: 0.4583333 ==> 2.0 [kpc] :: 22.0 [kpc]
ymin::ymax: 0.0416667 :: 0.4583333 ==> 2.0 [kpc] :: 22.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :12.83984375 KB
-------------------------------------------------------
The possible physical length units for the keyword `range_unit` are defined in the field `scale` :
```julia
viewfields(info.scale) # or e.g.: clumps.info.scale
```
[Mera]: Fields to scale from user/code units to selected units
=======================================================================
Mpc = 0.0010000000000006482
kpc = 1.0000000000006481
pc = 1000.0000000006482
mpc = 1.0000000000006482e6
ly = 3261.5637769461323
Au = 2.0626480623310105e23
km = 3.0856775812820004e16
m = 3.085677581282e19
cm = 3.085677581282e21
mm = 3.085677581282e22
μm = 3.085677581282e25
Msol_pc3 = 0.9997234790001649
g_cm3 = 6.76838218451376e-23
Msol_pc2 = 999.7234790008131
g_cm2 = 0.20885045168302602
Gyr = 0.014910986463557083
Myr = 14.910986463557084
yr = 1.4910986463557083e7
s = 4.70554946422349e14
ms = 4.70554946422349e17
Msol = 9.99723479002109e8
Mearth = 3.329677459032007e14
Mjupiter = 1.0476363431814971e12
g = 1.9885499720830952e42
km_s = 65.57528732282063
m_s = 65575.28732282063
cm_s = 6.557528732282063e6
nH = 30.987773856809987
erg = 8.551000140274429e55
g_cms2 = 2.9104844143584656e-9
T_mu = 517028.3199143136
Ba = 2.910484414358466e-9
### Ranges relative to a given center e.g. in units "kpc":
```julia
clumps = getclumps(info,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: Get clump data: 2020-02-08T13:44:10.318
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
Use the short notation for the box center :bc or :boxcenter for all dimensions (x,y,z):
```julia
clumps = getclumps(info,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[:boxcenter],
range_unit=:kpc);
```
[Mera]: Get clump data: 2020-02-08T13:44:11.159
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
```julia
clumps = getclumps(info,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[:bc],
range_unit=:kpc);
```
[Mera]: Get clump data: 2020-02-08T13:44:11.478
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
Use the box center notation for individual dimensions, here x,z:
```julia
clumps = getclumps(info,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[:bc, 24., :bc],
range_unit=:kpc);
```
[Mera]: Get clump data: 2020-02-08T13:44:12.344
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 17378 | # 2. Hydro: Load Selected Variables and Data Ranges
## Simulation Overview
```julia
using Mera
info = getinfo(300, "../../testing/simulations/mw_L10");
```
[Mera]: 2023-04-10T11:03:31.417
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
## Select Variables
Choose from the existing hydro variables listed in the simulation-info. Use the quoted Symbols: :varn1 or :cpu (=neg. one), :var1 or :rho, :var2 or :vx, :var3 or :vy, :var4 or :vz, :var5 or :p. Variables above 5 can be selected by :var6, :var7 etc. . No order is required. The selection of the variable's names from the descriptor files will be implemented in the future.
### Read all variables (default)
```julia
gas = gethydro(info);
```
[Mera]: Get hydro data: 2023-04-10T11:03:36.069
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:22
Memory used for data table :2.3210865957662463 GB
-------------------------------------------------------
```julia
gas.data
```
Table with 28320979 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### Select several variables w/o a keyword
```julia
gas_a = gethydro(info, vars=[:rho, :p]);
```
[Mera]: Get hydro data: 2023-04-10T11:04:07.311
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 5) = (:rho, :p)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:21
Memory used for data table :1.2660473119467497 GB
-------------------------------------------------------
The same variables can be read by using the var-number:
```julia
gas_a = gethydro(info, vars=[:var1, :var5]);
```
[Mera]: Get hydro data: 2023-04-10T11:04:31.757
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 5) = (:rho, :p)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:21
Memory used for data table :1.2660473119467497 GB
-------------------------------------------------------
A keyword argument for the variables is not needed if the following order is preserved: InfoType-object, variables:
```julia
gas_a = gethydro(info, [:rho, :p]);
```
[Mera]: Get hydro data: 2023-04-10T11:04:55.703
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 5) = (:rho, :p)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:21
Memory used for data table :1.2660473119467497 GB
-------------------------------------------------------
```julia
gas_a.data
```
Table with 28320979 rows, 6 columns:
level cx cy cz rho p
─────────────────────────────────────────────
6 1 1 1 3.18647e-9 1.06027e-9
6 1 1 2 3.58591e-9 1.33677e-9
6 1 1 3 3.906e-9 1.58181e-9
6 1 1 4 4.27441e-9 1.93168e-9
6 1 1 5 4.61042e-9 2.37842e-9
6 1 1 6 4.83977e-9 2.8197e-9
6 1 1 7 4.974e-9 3.20883e-9
6 1 1 8 5.08112e-9 3.56075e-9
6 1 1 9 5.20596e-9 3.89183e-9
6 1 1 10 5.38372e-9 4.20451e-9
6 1 1 11 5.67209e-9 4.50256e-9
6 1 1 12 6.14423e-9 4.78595e-9
⋮
10 814 493 514 0.000321702 2.18179e-6
10 814 494 509 1.42963e-6 3.35949e-6
10 814 494 510 1.4351e-6 3.38092e-6
10 814 494 511 0.00029515 2.55696e-6
10 814 494 512 0.000395273 2.5309e-6
10 814 494 513 0.000321133 2.16472e-6
10 814 494 514 0.000319678 2.17348e-6
10 814 495 511 0.00024646 2.19846e-6
10 814 495 512 0.000269009 2.20717e-6
10 814 496 511 0.000235329 2.10577e-6
10 814 496 512 0.000242422 2.09634e-6
### Select one variable
In this case, no array and keyword is necessary, but preserve the following order: InfoType-object, variable:
```julia
gas_c = gethydro(info, :vx );
```
[Mera]: Get hydro data: 2023-04-10T11:05:59.554
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(2,) = (:vx,)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:20
Memory used for data table :1.0550394551828504 GB
-------------------------------------------------------
```julia
gas_c.data
```
Table with 28320979 rows, 5 columns:
level cx cy cz vx
────────────────────────────────
6 1 1 1 -1.25532
6 1 1 2 -1.23262
6 1 1 3 -1.2075
6 1 1 4 -1.16462
6 1 1 5 -1.10493
6 1 1 6 -1.02686
6 1 1 7 -0.948004
6 1 1 8 -0.879731
6 1 1 9 -0.824484
6 1 1 10 -0.782768
6 1 1 11 -0.754141
6 1 1 12 -0.737723
⋮
10 814 493 514 0.268398
10 814 494 509 0.00398492
10 814 494 510 0.00496945
10 814 494 511 0.303842
10 814 494 512 0.305647
10 814 494 513 0.266079
10 814 494 514 0.26508
10 814 495 511 0.289612
10 814 495 512 0.290753
10 814 496 511 0.285209
10 814 496 512 0.285463
## Select Spatial Ranges
### Use RAMSES Standard Notation
Ranges correspond to the domain [0:1]^3 and are related to the box corner at [0., 0., 0.] by default. Here, we limit the loading of the data to a maximum level of 8:
```julia
gas = gethydro(info, lmax=8,
xrange=[0.2,0.8],
yrange=[0.2,0.8],
zrange=[0.4,0.6]);
```
[Mera]: Get hydro data: 2023-04-10T11:06:31.565
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
ymin::ymax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
zmin::zmax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:13
Memory used for data table :103.4984769821167 MB
-------------------------------------------------------
The loaded data ranges are assigned to the field `ranges` as an array in **RAMSES** standard notation (domain: [0:1]^3):
```julia
gas.ranges
```
6-element Vector{Float64}:
0.2
0.8
0.2
0.8
0.4
0.6
### Ranges relative to a given center:
```julia
gas = gethydro(info, lmax=8,
xrange=[-0.3, 0.3],
yrange=[-0.3, 0.3],
zrange=[-0.1, 0.1],
center=[0.5, 0.5, 0.5]);
```
[Mera]: Get hydro data: 2023-04-10T11:06:46.359
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
ymin::ymax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
zmin::zmax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:13
Memory used for data table :103.4984769821167 MB
-------------------------------------------------------
### Use notation in physical units
In the following example the ranges are given in unit "kpc", relative to the box corner [0., 0., 0.] (default):
```julia
gas = gethydro(info, lmax=8,
xrange=[2.,22.],
yrange=[2.,22.],
zrange=[22.,26.],
range_unit=:kpc);
```
[Mera]: Get hydro data: 2023-04-10T11:07:00.080
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0416667 :: 0.4583333 ==> 2.0 [kpc] :: 22.0 [kpc]
ymin::ymax: 0.0416667 :: 0.4583333 ==> 2.0 [kpc] :: 22.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:13
Memory used for data table :19.30322551727295 MB
-------------------------------------------------------
The possible physical length units for the keyword `range_unit` are defined in the field `scale` :
```julia
viewfields(info.scale) # or e.g.: gas.info.scale
```
[Mera]: Fields to scale from user/code units to selected units
=======================================================================
Mpc = 0.0010000000000006482
kpc = 1.0000000000006481
pc = 1000.0000000006482
mpc = 1.0000000000006482e6
ly = 3261.5637769461323
Au = 2.0626480623310105e23
km = 3.0856775812820004e16
m = 3.085677581282e19
cm = 3.085677581282e21
mm = 3.085677581282e22
μm = 3.085677581282e25
Mpc3 = 1.0000000000019446e-9
kpc3 = 1.0000000000019444
pc3 = 1.0000000000019448e9
mpc3 = 1.0000000000019446e18
ly3 = 3.469585750743794e10
Au3 = 8.775571306099254e69
km3 = 2.9379989454983075e49
m3 = 2.9379989454983063e58
cm3 = 2.9379989454983065e64
mm3 = 2.937998945498306e67
μm3 = 2.937998945498306e76
Msol_pc3 = 0.9997234790001649
Msun_pc3 = 0.9997234790001649
g_cm3 = 6.76838218451376e-23
Msol_pc2 = 999.7234790008131
Msun_pc2 = 999.7234790008131
g_cm2 = 0.20885045168302602
Gyr = 0.014910986463557083
Myr = 14.910986463557084
yr = 1.4910986463557083e7
s = 4.70554946422349e14
ms = 4.70554946422349e17
Msol = 9.99723479002109e8
Msun = 9.99723479002109e8
Mearth = 3.329677459032007e14
Mjupiter = 1.0476363431814971e12
g = 1.9885499720830952e42
km_s = 65.57528732282063
m_s = 65575.28732282063
cm_s = 6.557528732282063e6
nH = 30.987773856809987
erg = 8.551000140274429e55
g_cms2 = 2.9104844143584656e-9
T_mu = 517028.3199143136
K_mu = 517028.3199143136
T = 680300.4209398864
K = 680300.4209398864
Ba = 2.910484414358466e-9
g_cm_s2 = 2.910484414358466e-9
p_kB = 2.1080995598777838e7
K_cm3 = 2.1080995598777838e7
### Ranges relative to a given center e.g. in unit "kpc":
```julia
gas = gethydro(info, lmax=8,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: Get hydro data: 2023-04-10T11:07:13.344
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:13
Memory used for data table :54.6228666305542 MB
-------------------------------------------------------
Use the short notation for the box center :bc or :boxcenter for all dimensions (x,y,z):
```julia
gas = gethydro(info, lmax=8,
xrange=[-16., 16.],
yrange=[-16., 16.],
zrange=[-2., 2.],
center=[:boxcenter],
range_unit=:kpc);
```
[Mera]: Get hydro data: 2023-04-10T11:07:26.753
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:13
Memory used for data table :54.6228666305542 MB
-------------------------------------------------------
```julia
gas = gethydro(info, lmax=8,
xrange=[-16., 16.],
yrange=[-16., 16.],
zrange=[-2., 2.],
center=[:bc],
range_unit=:kpc);
```
[Mera]: Get hydro data: 2023-04-10T11:07:40.694
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:13
Memory used for data table :54.6228666305542 MB
-------------------------------------------------------
Use the box center notation for individual dimensions, here x,z:
```julia
gas = gethydro(info, lmax=8,
xrange=[-16., 16.],
yrange=[-16., 16.],
zrange=[-2., 2.],
center=[:bc, 24., :bc],
range_unit=:kpc);
```
[Mera]: Get hydro data: 2023-04-10T11:07:54.736
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:13
Memory used for data table :54.6228666305542 MB
-------------------------------------------------------
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 18994 | # 2. Particles: Load Selected Variables and Data Ranges
## Simulation Overview
```julia
using Mera
info = getinfo(300, "../../testing/simulations/mw_L10");
```
[Mera]: 2023-04-10T11:09:58.577
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
## Select Variables
Choose from the existing particle variables listed in the simulation-info.
The functions in **Mera** "know" the predefined particle variable names:
- From >= ramses-version-2018: :vx, :vy, :vz, :mass, :family, :tag, :birth, :metals :var9,....
- For =< ramses-version-2017: :vx, :vy, :vz, :mass, :birth, :var6, :var7,....
- Currently, the following variables are loaded by default (if exist): :level, :x, :y, :z, :id, :family, :tag.
- The cpu number associated with the particles can be loaded with the variable names: :cpu or :varn1
- In a future version the variable names from the particle descriptor can be used by setting the field info.descriptor.useparticles = true .
### Read all variables by default
```julia
particles = getparticles(info);
```
[Mera]: Get particle data: 2023-04-10T11:10:06.672
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Found 5.445150e+05 particles
Memory used for data table :38.42913246154785 MB
-------------------------------------------------------
```julia
particles.data
```
Table with 544515 rows, 12 columns:
Columns:
# colname type
────────────────────
1 level Int32
2 x Float64
3 y Float64
4 z Float64
5 id Int32
6 family Int8
7 tag Int8
8 vx Float64
9 vy Float64
10 vz Float64
11 mass Float64
12 birth Float64
### Select several variables w/o a keyword
```julia
particles_a = getparticles(info, vars=[:mass, :birth]);
```
[Mera]: Get particle data: 2023-04-10T11:10:09.828
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(4, 7) = (:mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Found 5.445150e+05 particles
Memory used for data table :25.96580410003662 MB
-------------------------------------------------------
The same variables can be read by using the var-number:
```julia
particles_a = getparticles(info, vars=[:var4, :var7]);
```
[Mera]: Get particle data: 2023-04-10T11:10:15.319
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(4, 7) = (:mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Found 5.445150e+05 particles
Memory used for data table :25.96580410003662 MB
-------------------------------------------------------
A keyword argument for the variables is not needed if the following order is preserved: InfoType-object, variables:
```julia
particles_a = getparticles(info, [:mass, :birth]);
```
[Mera]: Get particle data: 2023-04-10T11:10:17.681
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(4, 7) = (:mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Found 5.445150e+05 particles
Memory used for data table :25.96580410003662 MB
-------------------------------------------------------
```julia
particles_a.data
```
Table with 544515 rows, 9 columns:
level x y z id family tag mass birth
──────────────────────────────────────────────────────────────────────────
9 9.17918 22.4404 24.0107 128710 2 0 8.00221e-7 8.86726
9 9.23642 21.5559 24.0144 126838 2 0 8.00221e-7 8.71495
9 9.35638 20.7472 24.0475 114721 2 0 8.00221e-7 7.91459
9 9.39529 21.1854 24.0155 113513 2 0 8.00221e-7 7.85302
9 9.42686 20.9697 24.0162 120213 2 0 8.00221e-7 8.2184
9 9.42691 22.2181 24.0137 125689 2 0 8.00221e-7 8.6199
9 9.48834 22.0913 24.0137 126716 2 0 8.00221e-7 8.70493
9 9.5262 20.652 24.0179 115550 2 0 8.00221e-7 7.96008
9 9.60376 21.2814 24.0155 116996 2 0 8.00221e-7 8.03346
9 9.6162 20.6243 24.0506 125003 2 0 8.00221e-7 8.56482
9 9.62155 20.6248 24.0173 112096 2 0 8.00221e-7 7.78062
9 9.62252 24.4396 24.0206 136641 2 0 8.00221e-7 9.44825
⋮
10 37.7913 25.6793 24.018 141792 2 0 8.00221e-7 9.78881
10 37.8255 22.6271 24.0279 143663 2 0 8.00221e-7 9.89052
10 37.8451 22.7506 24.027 138989 2 0 8.00221e-7 9.61716
10 37.8799 25.5668 24.0193 150226 2 0 8.00221e-7 10.2294
10 37.969 23.2135 24.0273 142995 2 0 8.00221e-7 9.85439
10 37.9754 22.6288 24.0265 137301 2 0 8.00221e-7 9.4959
10 37.9811 23.2854 24.0283 145294 2 0 8.00221e-7 9.9782
10 37.9919 22.873 24.0271 132010 2 0 8.00221e-7 9.12003
10 37.9966 23.092 24.0281 136766 2 0 8.00221e-7 9.45574
10 38.0328 22.8404 24.0265 141557 2 0 8.00221e-7 9.77493
10 38.0953 22.8757 24.0231 133214 2 0 8.00221e-7 9.20251
### Select one variable
In this case, no array and keyword is necessary, but preserve the following order: InfoType-object, variable:
```julia
particles_c = getparticles(info, :vx );
```
[Mera]: Get particle data: 2023-04-10T11:10:22.160
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1,) = (:vx,)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Found 5.445150e+05 particles
Memory used for data table :21.81136131286621 MB
-------------------------------------------------------
```julia
particles_c.data
```
Table with 544515 rows, 8 columns:
level x y z id family tag vx
─────────────────────────────────────────────────────────────────
9 9.17918 22.4404 24.0107 128710 2 0 0.670852
9 9.23642 21.5559 24.0144 126838 2 0 0.810008
9 9.35638 20.7472 24.0475 114721 2 0 0.93776
9 9.39529 21.1854 24.0155 113513 2 0 0.870351
9 9.42686 20.9697 24.0162 120213 2 0 0.899373
9 9.42691 22.2181 24.0137 125689 2 0 0.717235
9 9.48834 22.0913 24.0137 126716 2 0 0.739564
9 9.5262 20.652 24.0179 115550 2 0 0.946747
9 9.60376 21.2814 24.0155 116996 2 0 0.893236
9 9.6162 20.6243 24.0506 125003 2 0 0.996445
9 9.62155 20.6248 24.0173 112096 2 0 0.960817
9 9.62252 24.4396 24.0206 136641 2 0 0.239579
⋮
10 37.7913 25.6793 24.018 141792 2 0 -0.466362
10 37.8255 22.6271 24.0279 143663 2 0 0.129315
10 37.8451 22.7506 24.027 138989 2 0 0.100542
10 37.8799 25.5668 24.0193 150226 2 0 -0.397774
10 37.969 23.2135 24.0273 142995 2 0 -0.0192855
10 37.9754 22.6288 24.0265 137301 2 0 0.10287
10 37.9811 23.2854 24.0283 145294 2 0 -0.0461542
10 37.9919 22.873 24.0271 132010 2 0 0.0570142
10 37.9966 23.092 24.0281 136766 2 0 -0.0185658
10 38.0328 22.8404 24.0265 141557 2 0 0.0391784
10 38.0953 22.8757 24.0231 133214 2 0 -0.0510545
## Selected Spatial Ranges
### Use RAMSES Standard Notation
Ranges correspond to the domain [0:1]^3 and are related to the box corner at [0., 0., 0.] by default.
```julia
particles = getparticles( info,
xrange=[0.2,0.8],
yrange=[0.2,0.8],
zrange=[0.4,0.6]);
```
[Mera]: Get particle data: 2023-04-10T11:10:29.091
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
domain:
xmin::xmax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
ymin::ymax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
zmin::zmax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
Found 5.444850e+05 particles
Memory used for data table :38.42701530456543 MB
-------------------------------------------------------
The loaded data ranges are assigned to the field `ranges` as an array in **RAMSES** standard notation (domain: [0:1]^3):
```julia
particles.ranges
```
6-element Vector{Float64}:
0.2
0.8
0.2
0.8
0.4
0.6
### Ranges relative to a given center:
```julia
particles = getparticles( info,
xrange=[-0.3, 0.3],
yrange=[-0.3, 0.3],
zrange=[-0.1, 0.1],
center=[0.5, 0.5, 0.5]);
```
[Mera]: Get particle data: 2023-04-10T11:10:33.971
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
ymin::ymax: 0.2 :: 0.8 ==> 9.6 [kpc] :: 38.4 [kpc]
zmin::zmax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
Found 5.444850e+05 particles
Memory used for data table :38.42701530456543 MB
-------------------------------------------------------
### Use notation in physical units
In the following example the ranges are given in unit "kpc", relative to the box corner [0., 0., 0.] (default):
```julia
particles = getparticles( info,
xrange=[2.,22.],
yrange=[2.,22.],
zrange=[22.,26.],
range_unit=:kpc);
```
[Mera]: Get particle data: 2023-04-10T11:10:40.217
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
domain:
xmin::xmax: 0.0416667 :: 0.4583333 ==> 2.0 [kpc] :: 22.0 [kpc]
ymin::ymax: 0.0416667 :: 0.4583333 ==> 2.0 [kpc] :: 22.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Found 3.091600e+04 particles
Memory used for data table :2.1834754943847656 MB
-------------------------------------------------------
The possible physical length units for the keyword `range_unit` are defined in the field `scale` :
```julia
viewfields(info.scale) # or e.g.: gas.info.scale
```
[Mera]: Fields to scale from user/code units to selected units
=======================================================================
Mpc = 0.0010000000000006482
kpc = 1.0000000000006481
pc = 1000.0000000006482
mpc = 1.0000000000006482e6
ly = 3261.5637769461323
Au = 2.0626480623310105e23
km = 3.0856775812820004e16
m = 3.085677581282e19
cm = 3.085677581282e21
mm = 3.085677581282e22
μm = 3.085677581282e25
Mpc3 = 1.0000000000019446e-9
kpc3 = 1.0000000000019444
pc3 = 1.0000000000019448e9
mpc3 = 1.0000000000019446e18
ly3 = 3.469585750743794e10
Au3 = 8.775571306099254e69
km3 = 2.9379989454983075e49
m3 = 2.9379989454983063e58
cm3 = 2.9379989454983065e64
mm3 = 2.937998945498306e67
μm3 = 2.937998945498306e76
Msol_pc3 = 0.9997234790001649
Msun_pc3 = 0.9997234790001649
g_cm3 = 6.76838218451376e-23
Msol_pc2 = 999.7234790008131
Msun_pc2 = 999.7234790008131
g_cm2 = 0.20885045168302602
Gyr = 0.014910986463557083
Myr = 14.910986463557084
yr = 1.4910986463557083e7
s = 4.70554946422349e14
ms = 4.70554946422349e17
Msol = 9.99723479002109e8
Msun = 9.99723479002109e8
Mearth = 3.329677459032007e14
Mjupiter = 1.0476363431814971e12
g = 1.9885499720830952e42
km_s = 65.57528732282063
m_s = 65575.28732282063
cm_s = 6.557528732282063e6
nH = 30.987773856809987
erg = 8.551000140274429e55
g_cms2 = 2.9104844143584656e-9
T_mu = 517028.3199143136
K_mu = 517028.3199143136
T = 680300.4209398864
K = 680300.4209398864
Ba = 2.910484414358466e-9
g_cm_s2 = 2.910484414358466e-9
p_kB = 2.1080995598777838e7
K_cm3 = 2.1080995598777838e7
### Ranges relative to the given center e.g. in unit "kpc":
```julia
particles = getparticles( info,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[50.,50.,50.],
range_unit=:kpc);
```
[Mera]: Get particle data: 2023-04-10T11:10:45.564
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
center: [1.0416667, 1.0416667, 1.0416667] ==> [50.0 [kpc] :: 50.0 [kpc] :: 50.0 [kpc]]
domain:
xmin::xmax: 0.7083333 :: 1.0 ==> 34.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.7083333 :: 1.0 ==> 34.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 1.0 :: 1.0 ==> 48.0 [kpc] :: 48.0 [kpc]
Found 0.000000e+00 particles
Memory used for data table :1.71484375 KB
-------------------------------------------------------
Use the short notation for the box center :bc or :boxcenter for all dimensions (x,y,z):
```julia
particles = getparticles( info,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[:boxcenter],
range_unit=:kpc);
```
[Mera]: Get particle data: 2023-04-10T11:10:48.345
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Found 5.445150e+05 particles
Memory used for data table :38.42913246154785 MB
-------------------------------------------------------
```julia
particles = getparticles( info,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[:bc],
range_unit=:kpc);
```
[Mera]: Get particle data: 2023-04-10T11:10:50.163
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Found 5.445150e+05 particles
Memory used for data table :38.42913246154785 MB
-------------------------------------------------------
Use the box center notation for individual dimensions, here x,z:
```julia
particles = getparticles( info,
xrange=[-16.,16.],
yrange=[-16.,16.],
zrange=[-2.,2.],
center=[:bc, 50., :bc],
range_unit=:kpc);
```
[Mera]: Get particle data: 2023-04-10T11:10:53.187
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
center: [0.5, 1.0416667, 0.5] ==> [24.0 [kpc] :: 50.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.1666667 :: 0.8333333 ==> 8.0 [kpc] :: 40.0 [kpc]
ymin::ymax: 0.7083333 :: 1.0 ==> 34.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Found 2.078000e+03 particles
Memory used for data table :151.8828125 KB
-------------------------------------------------------
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 31115 | # 3. Clumps: Get Sub-Regions of The Loaded Data
## Load the Data
```julia
using Mera, PyPlot
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14")
clumps = getclumps(info);
```
[Mera]: 2020-02-08T20:39:44.033
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get clump data: 2020-02-08T20:39:48.496
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
## Cuboid Region
### Create scatter plots of the full box:
Use the `getvar` function to extract the positions of the clumps relative to the box center. It returns a dictionary of arrays:
```julia
positions = getvar(clumps, [:x, :y, :z], :kpc, center=[:boxcenter], center_unit=:kpc) # units=[:kpc, :kpc, :kpc]
x, y, z = positions[:x], positions[:y], positions[:z]; # assign the three components of the dictionary to three arrays
```
Alternatively, use the `getposition` function to extract the positions of the clumps. It returns a tuple of the three components:
```julia
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter], center_unit=:kpc); # assign the three components of the tuple to three arrays
```
Get the extent of the processed domain with respect to a given center. The returned tuple is useful declare the specific range of the plots.
```julia
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
#### Cuboid Region: The red lines show the region that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
subplot(1,3,1)
scatter(x,y)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cuboid Region: Cutout the data assigned to the object `clumps`
Note: The selected regions can be given relative to a user given center or to the box corner [0., 0., 0.] by default. The user can choose between standard notation [0:1] (default) or physical length-units, defined in e.g. info.scale :
```julia
clumps_subregion = subregion( clumps, :cuboid,
xrange=[-4., 0.],
yrange=[-15. ,15.],
zrange=[-2. ,2.],
center=[:boxcenter],
range_unit=:kpc);
```
[Mera]: 2020-02-08T20:40:04.755
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :29.52734375 KB
-------------------------------------------------------
The function `subregion` creates a new object with the same type as the object created by the function `getclumps` :
```julia
typeof(clumps_subregion)
```
ClumpDataType
#### Cuboid Region: Scatter-Plots of the sub-region.
The coordinates center is the center of the box by default:
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # clump positions of the subregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter] ); # extent of the box
```
```julia
figure(figsize=(15.5, 3.5))
subplot(1,3,1)
scatter(x,y)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cuboid Region: Get the extent of the subregion data ranges
```julia
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc, center=[:boxcenter]); # extent of the subregion
```
```julia
figure(figsize=(15.5, 3.5))
subplot(1,3,1)
scatter(x,y)
xlim(rx_sub)
ylim(ry_sub)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
xlim(rx_sub)
ylim(rz_sub)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
xlim(ry_sub)
ylim(rz_sub)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cuboid Region: Get the data outside of the selected region (inverse selection):
```julia
clumps_subregion = subregion( clumps, :cuboid,
xrange=[-4., 0.],
yrange=[-15. ,15.],
zrange=[-2. ,2.],
center=[:boxcenter],
range_unit=:kpc,
inverse=true);
```
[Mera]: 2020-02-08T20:40:36.521
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :33.65234375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]);
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc, center=[:boxcenter]);
```
```julia
figure(figsize=(15.5, 3.5))
subplot(1,3,1)
scatter(x,y)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlim(rx_sub)
ylim(ry_sub)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx_sub)
ylim(rz_sub)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry_sub)
ylim(rz_sub)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

## Cylindrical Region
Extract the the clump positions and the extent of the full box:
```julia
clumps = getclumps(info);
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter]);
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
[Mera]: Get clump data: 2020-02-08T20:40:43.377
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
#### Cylindrical Region: The red lines show the region that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cylindrical Region: Cutout the data assigned to the object `clumps`
Select the ranges of the cylinder in the unit "kpc", relative to the given center [13., 24., 24.]. The height refers to both z-directions from the plane.
```julia
clumps_subregion = subregion( clumps, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[(24. -11.), :bc, :bc]); # direction=:z, by default
```
[Mera]: 2020-02-08T20:40:50.168
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :5.24609375 KB
-------------------------------------------------------
Extract the the clump positions of the subregion and the extent of the full box:
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter])
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cylindrical Region: Scatter-Plot of the selected data range with respect to the center of the sub-region:
```julia
x, y, z = getpositions(clumps_subregion, :kpc,
center=[ (24. -11.), :bc, :bc],
center_unit=:kpc);
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc,
center=[ (24. -11.), :bc, :bc],
center_unit=:kpc);
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 3. .* sin.(theta), 3 .* cos.(theta), color="red")
xlim(rx_sub)
ylim(ry_sub)
xlabel("kpc")
ylabel("kpc")
subplot(1,3,2)
scatter(x,z)
xlim(rx_sub)
ylim(rz_sub)
xlabel("kpc")
ylabel("kpc")
subplot(1,3,3)
scatter(y,z)
xlim(ry_sub)
ylim(rz_sub)
xlabel("kpc")
ylabel("kpc");
```

#### Cylindrical Region: Get the data outside of the selected region (inverse selection):
```julia
clumps_subregion = subregion( clumps, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[ (24. -11.),:bc,:bc],
inverse=true);
```
[Mera]: 2020-02-08T20:41:13.553
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :57.93359375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]);
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc, center=[:boxcenter]);
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

## Spherical Region
Extract the the clump positions and the extent of the full box:
```julia
clumps = getclumps(info);
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter]);
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
[Mera]: Get clump data: 2020-02-08T20:41:17.127
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
#### The red lines show the region that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]")
```

PyObject Text(871.9411764705884, 0.5, 'z [kpc]')
#### Spherical Region: Cutout the data assigned to the object `clumps`
Select the radius of the sphere in the unit "kpc", relative to the given center [13., 24., 24.]:
```julia
clumps_subregion = subregion( clumps, :sphere,
radius=10.,
range_unit=:kpc,
center=[ (24. -11.),:bc, :bc]);
```
[Mera]: 2020-02-08T20:41:21.728
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :28.68359375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # subregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Spherical Region: Scatter-Plot of the selected data range with respect to the center of the sub-region:
```julia
x, y, z = getpositions(clumps_subregion, :kpc,
center=[ (24. -11.), :bc, :bc],
center_unit=:kpc); # subregion
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc,
center=[(24. -11.), :bc, :bc],
center_unit=:kpc); # subregion
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta), 10 .* cos.(theta), color="red")
xlim(rx_sub)
ylim(ry_sub)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta), 10 .* cos.(theta), color="red")
xlim(rx_sub)
ylim(rz_sub)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta), 10 .* cos.(theta), color="red")
xlim(ry_sub)
ylim(rz_sub)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Spherical Region: Get the data outside of the selected region (inverse selection):
```julia
clumps_subregion = subregion( clumps, :sphere,
radius=10.,
range_unit=:kpc,
center=[ (24. -11.),:bc,:bc],
inverse=true);
```
[Mera]: 2020-02-08T20:41:43.641
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :34.49609375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]);
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc, center=[:boxcenter]);
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]")
```

PyObject Text(871.9411764705884, 0.5, 'z [kpc]')
## Combined/Nested/Shell Sub-Regions
#### The sub-region functions can be used in any combination with each other! (Combined with overlapping ranges or nested)
## Cylindrical Shell
Extract the the clump positions and the extent of the full box:
```julia
clumps = getclumps(info);
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter]);
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
[Mera]: Get clump data: 2020-02-08T20:41:52.553
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
#### The red lines show the shell that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red",ls = "--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cylindrical Shell:
Pass the height of the cylinder and the inner/outer radius of the shell in the unit "kpc", relative to the box center [24., 24., 24.]:
```julia
clumps_subregion = shellregion( clumps, :cylinder,
radius=[5.,10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter]);
```
[Mera]: 2020-02-08T20:42:00.413
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :18.55859375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # shellregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cylindrical Shell: Get the data outside of the selected shell-region (inverse selection):
```julia
clumps_subregion = shellregion( clumps, :cylinder,
radius=[5.,10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-08T20:42:10.055
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :44.62109375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # shellregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

## Spherical Shell
Extract the the clump positions and the extent of the full box:
```julia
clumps = getclumps(info);
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter]);
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
[Mera]: Get clump data: 2020-02-08T20:42:14.641
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
#### The red lines show the shell that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Spherical Shell:
Select the inner and outer radius of the spherical shell in unit "kpc", relative to the box center [24., 24., 24.]:
```julia
clumps_subregion = shellregion( clumps, :sphere,
radius=[5.,10.],
range_unit=:kpc,
center=[:boxcenter]);
```
[Mera]: 2020-02-08T20:42:19.499
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :18.55859375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # shellregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Spherical Shell: Get the data outside of the selected shell-region (inverse selection):
```julia
clumps_subregion = shellregion( clumps, :sphere,
radius=[5.,10.],
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-08T20:42:23.949
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :44.62109375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # shellregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter] ); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 39598 | # 3. Hydro: Get Sub-Regions of The Loaded Data
## Load the Data
```julia
using Mera, PyPlot
using ColorSchemes
cmap = ColorMap(ColorSchemes.lajolla.colors) # See http://www.fabiocrameri.ch/colourmaps.php
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14")
gas = gethydro(info, :rho, lmax=10, smallr=1e-5);
```
[Mera]: 2020-02-18T23:23:22.753
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get hydro data: 2020-02-18T23:23:32.417
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1,) = (:rho,)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:02:49
Memory used for data table :186.1558656692505 MB
-------------------------------------------------------
## Cuboid Region
### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:03
The generated objects include, e.g. the extent of the processed domain, that can be used to declare the specific range of the plots, while the field `cextent` gives the extent related to a given center (default: [0.,0.,0.]).
```julia
propertynames(proj_z)
```
(:maps, :maps_unit, :maps_lmax, :maps_mode, :lmax_projected, :lmin, :lmax, :ranges, :extent, :cextent, :ratio, :boxlen, :smallr, :smallc, :scale, :info)
#### Cuboid Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cuboid Region: Cutout the data assigned to the object `gas`
Note: The selected regions can be given relative to a user given center or to the box corner [0., 0., 0.] by default. The user can choose between standard notation [0:1] (default) or physical length-units, defined in e.g. info.scale :
```julia
gas_subregion = subregion( gas, :cuboid,
xrange=[-4., 0.],
yrange=[-15., 15.],
zrange=[-2., 2.],
center=[:boxcenter],
range_unit=:kpc);
```
[Mera]: 2020-02-18T23:27:06.861
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :47.87415790557861 MB
-------------------------------------------------------
The function `subregion` creates a new object with the same type as the object created by the function `gethydro` :
```julia
typeof(gas_subregion)
```
HydroDataType
#### Cuboid Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cuboid Region: Get the data outside of the selected region (inverse selection):
```julia
gas_subregion = subregion( gas, :cuboid,
xrange=[-4., 0.],
yrange=[-15., 15.],
zrange=[-2., 2.],
center=[:boxcenter],
range_unit=:kpc,
inverse=true);
```
[Mera]: 2020-02-18T23:27:09.597
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :138.2824068069458 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:01
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Cylindrical Region
#### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:01
100%|███████████████████████████████████████████████████| Time: 0:00:01
#### Cylindrical Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cylindrical Region: Cutout the data assigned to the object `gas`
Select the ranges of the cylinder in the unit "kpc", relative to the given center [13., 24., 24.]. The height refers to both z-directions from the plane.
```julia
gas_subregion = subregion( gas, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[13., :bc, :bc]); # direction=:z, by default
```
[Mera]: 2020-02-18T23:27:24.715
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :9.945767402648926 MB
-------------------------------------------------------
#### Cylindrical Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Region: Projections of the sub-region rekated ti a given data center:
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, direction=:z, center=[13., 24.,24.], range_unit=:kpc, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, direction=:y, center=[13., 24.,24.], range_unit=:kpc, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, direction=:x, center=[13., 24.,24.], range_unit=:kpc, verbose=false);
```
#### The ranges of the plots are now adapted to the given data center:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta), 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Region: Get the data outside of the selected region (inverse selection):
```julia
gas_subregion = subregion( gas, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[13.,:bc,:bc],
inverse=true); # direction=:z, by default
```
[Mera]: 2020-02-18T23:27:29.071
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :176.2107973098755 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Spherical Region
### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:01
#### Spherical Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Region: Cutout the data assigned to the object `gas`
Select the radius of the sphere in the unit "kpc", relative to the given center [13., 24., 24.]:
```julia
gas_subregion = subregion( gas, :sphere,
radius=10.,
range_unit=:kpc,
center=[13.,:bc,:bc]);
```
[Mera]: 2020-02-18T23:27:42.261
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :57.03980731964111 MB
-------------------------------------------------------
#### Spherical Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Region: Get the data outside of the selected region (inverse selection):
```julia
gas_subregion = subregion( gas, :sphere,
radius=10.,
range_unit=:kpc,
center=[13.,:bc,:bc],
inverse=true);
```
[Mera]: 2020-02-18T23:27:46.433
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :129.1167573928833 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Combined/Nested/Shell Sub-Regions
#### The sub-region functions can be used in any combination with each other! (Combined with overlapping or nested ranges)
One Example:
```julia
comb_region = subregion(gas, :cuboid, xrange=[-8.,8.], yrange=[-8.,8.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc, verbose=false)
comb_region2 = subregion(comb_region, :sphere, radius=12., center=[40.,24.,24.], range_unit=:kpc, inverse=true, verbose=false)
comb_region3 = subregion(comb_region2, :sphere, radius=12., center=[8.,24.,24.], range_unit=:kpc, inverse=true, verbose=false);
comb_region4 = subregion(comb_region3, :sphere, radius=12., center=[24.,5.,24.], range_unit=:kpc, inverse=true, verbose=false);
comb_region5 = subregion(comb_region4, :sphere, radius=12., center=[24.,43.,24.], range_unit=:kpc, inverse=true, verbose=false);
```
```julia
proj_z = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

## Cylindrical Shell
#### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:02
#### Cylindrical Shell: The red lines show the shell that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cylindrical Shell:
Pass the height of the cylinder and the inner/outer radius of the shell in the unit "kpc", relative to the box center [24., 24., 24.]:
```julia
gas_subregion = shellregion( gas, :cylinder,
radius=[5., 10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter]);
```
[Mera]: 2020-02-18T23:28:03.834
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :53.790066719055176 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Shell: Get the data outside of the selected shell (inverse selection):
```julia
gas_subregion = shellregion(gas, :cylinder,
radius=[5., 10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-18T23:28:06.945
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :132.36649799346924 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Spherical Shell
#### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:02
100%|███████████████████████████████████████████████████| Time: 0:00:02
100%|███████████████████████████████████████████████████| Time: 0:00:01
#### Spherical Shell: The red lines show the shell that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red",ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Shell:
Select the inner and outer radius of the spherical shell in unit "kpc", relative to the box center [24., 24., 24.]:
```julia
gas_subregion = shellregion(gas, :sphere,
radius=[5., 10.],
range_unit=:kpc,
center=[24.,24.,24.]);
```
[Mera]: 2020-02-18T23:28:21.357
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :56.55305194854736 MB
-------------------------------------------------------
#### Spherical Shell: Projections of the shell-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Shell: Get the data outside of the selected shell-region (inverse selection):
```julia
gas_subregion = shellregion(gas, :sphere,
radius=[5., 10.],
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-18T23:28:25.267
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :129.60351276397705 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 39918 | # 3. Particles: Get Sub-Regions of Loaded the Data
## Load the Data
```julia
using Mera, PyPlot
using ColorSchemes
cmap = ColorMap(ColorSchemes.lajolla.colors) # See http://www.fabiocrameri.ch/colourmaps.php
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
particles = getparticles(info, :mass);
```
[Mera]: 2020-02-18T23:29:31.468
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get particle data: 2020-02-18T23:29:46.476
Key vars=(:level, :x, :y, :z, :id)
Using var(s)=(4,) = (:mass,)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...100%|████████████████████████████████████| Time: 0:00:03
Found 5.089390e+05 particles
Memory used for data table :19.4152889251709 MB
-------------------------------------------------------
## Cuboid Region
### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
The generated objects include, e.g. the extent of the processed domain, that can be used to declare the specific range of the plots, while the field cextent gives the extent related to a given center (default: [0.,0.,0.]).
```julia
propertynames(proj_z)
```
(:maps, :maps_unit, :maps_lmax, :maps_mode, :lmax_projected, :lmin, :lmax, :ref_time, :ranges, :extent, :cextent, :ratio, :boxlen, :scale, :info)
#### Cuboid Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cuboid Region: Cutout the data assigned to the object `particles`
Note: The selected regions can be given relative to a user given center or to the box corner [0., 0., 0.] by default. The user can choose between standard notation [0:1] (default) or physical length-units, defined in e.g. info.scale :
```julia
part_subregion = subregion( particles, :cuboid,
xrange=[-4., 0.],
yrange=[-15. ,15.],
zrange=[-2. ,2.],
center=[:boxcenter],
range_unit=:kpc );
```
[Mera]: 2020-02-18T23:30:10.393
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :10.259977340698242 MB
-------------------------------------------------------
The function `subregion` creates a new object with the same type as the object created by the function `getparticles` :
```julia
typeof(part_subregion)
```
PartDataType
#### Cuboid Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=10, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=10, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=10, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cuboid Region: Get the data outside of the selected region (inverse selection):
```julia
part_subregion = subregion( particles, :cuboid,
xrange=[-4., 0.],
yrange=[-15. ,15.],
zrange=[-2. ,2.],
center=[24.,24.,24.],
range_unit=:kpc,
inverse=true);
```
[Mera]: 2020-02-18T23:30:12.491
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :9.156118392944336 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Cylindrical Region
#### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
#### Cylindrical Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cylindrical Region: Cutout the data assigned to the object `particles`
Select the ranges of the cylinder in the unit "kpc", relative to the given center [13., 24., 24.]. The height refers to both z-directions from the plane.
```julia
part_subregion = subregion(particles, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[13.,:bc,:bc],
direction=:z);
```
[Mera]: 2020-02-18T23:30:15.671
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :578.951171875 KB
-------------------------------------------------------
#### Cylindrical Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=10, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=10, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=10, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Region: Projections of the sub-region py passing a different center:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, direction=:z, center=[13., 24.,24.], range_unit=:kpc, lmax=10, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, direction=:y, center=[13., 24.,24.], range_unit=:kpc, lmax=10, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, direction=:x, center=[13., 24.,24.], range_unit=:kpc, lmax=10, verbose=false);
```
#### The ranges of the plots are now adapted to the given data center:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta), 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Region: Get the data outside of the selected region (inverse selection):
```julia
part_subregion = subregion(particles, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[ (24. -11.),:bc,:bc],
direction=:z,
inverse=true);
```
[Mera]: 2020-02-18T23:30:19.162
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :18.8507137298584 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Spherical Region
### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
#### Spherical Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Region: Cutout the data assigned to the object `particles`
Select the radius of the sphere in the unit "kpc", relative to the given center [13., 24., 24.]:
```julia
part_subregion = subregion( particles, :sphere,
radius=10.,
range_unit=:kpc,
center=[(24. -11.),24.,24.]);
```
[Mera]: 2020-02-18T23:30:22.122
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :8.807950973510742 MB
-------------------------------------------------------
#### Spherical Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Region: Get the data outside of the selected region (inverse selection):
```julia
part_subregion = subregion( particles, :sphere,
radius=10.,
range_unit=:kpc,
center=[(24. -11.),24.,24.],
inverse=true);
```
[Mera]: 2020-02-18T23:30:23.142
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :10.608144760131836 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Combined/Nested/Shell Sub-Regions
#### The sub-region and shell functions can be used in any combination with each other! (Combined with overlapping ranges or nested)
One Example:
```julia
comb_region = subregion(particles, :cuboid, xrange=[-8.,8.], yrange=[-8.,8.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc, verbose=false)
comb_region2 = subregion(comb_region, :sphere, radius=12., center=[40.,24.,24.], range_unit=:kpc, inverse=true, verbose=false)
comb_region3 = subregion(comb_region2, :sphere, radius=12., center=[8.,24.,24.], range_unit=:kpc, inverse=true, verbose=false);
comb_region4 = subregion(comb_region3, :sphere, radius=12., center=[24.,5.,24.], range_unit=:kpc, inverse=true, verbose=false);
comb_region5 = subregion(comb_region4, :sphere, radius=12., center=[24.,43.,24.], range_unit=:kpc, inverse=true, verbose=false);
```
```julia
proj_z = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter],direction=:y, verbose=false);
proj_x = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter],direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Cylindrical Shell
#### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
#### Cylindrical Shell: The red lines show the shell we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cylindrical Shell:
Pass the height of the cylinder and the inner/outer radius of the shell in the unit "kpc", relative to the box center [24., 24., 24.]:
```julia
part_subregion = shellregion( particles, :cylinder,
radius=[5.,10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter]);
```
[Mera]: 2020-02-18T23:30:28.41
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :7.282835006713867 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Shell: Get the data outside of the selected shell (inverse selection):
```julia
part_subregion = shellregion( particles, :cylinder,
radius=[5.,10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-18T23:30:30.228
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :12.133260726928711 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

<a id="ShellRegionSphere"></a>
## Spherical Shell
#### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
#### Spherical Shell: The red lines show the shell that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red",ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Shell:
Select the inner and outer radius of the spherical shell in unit "kpc", relative to the box center [24., 24., 24.]:
```julia
part_subregion = shellregion( particles, :sphere,
radius=[5.,10.],
range_unit=:kpc,
center=[24.,24.,24.]);
```
[Mera]: 2020-02-18T23:30:34.32
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :7.592016220092773 MB
-------------------------------------------------------
#### Spherical Shell: Projections of the shell-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red",ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red",ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Shell: Get the data outside of the selected shell-region (inverse selection):
```julia
part_subregion = shellregion( particles, :sphere,
radius=[5.,10.],
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-18T23:30:35.378
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :11.824079513549805 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 39319 | # 4. Basic Calculations
The following functions process different types of `DataSetType`:
- ContainMassDataSetType,
- HydroPartType,
- HydroDataType,
- PartDataType,
- ClumpDataType.
## Load The Data
```julia
using Mera
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
gas = gethydro(info, [:rho, :vx, :vy, :vz], lmax=8);
particles = getparticles(info, [:mass, :vx, :vy, :vz])
clumps = getclumps(info);
```
┌ Info: Precompiling Mera [02f895e8-fdb1-4346-8fe6-c721699f5126]
└ @ Base loading.jl:1273
*__ __ _______ ______ _______
| |_| | | _ | | _ |
| | ___| | || | |_| |
| | |___| |_||_| |
| | ___| __ | |
| ||_|| | |___| | | | _ |
|_| |_|_______|___| |_|__| |__|
[Mera]: 2020-02-15T21:12:42.671
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get hydro data: 2020-02-15T21:12:50.488
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4) = (:rho, :vx, :vy, :vz)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:02:13
Memory used for data table :51.840110778808594 MB
-------------------------------------------------------
[Mera]: Get particle data: 2020-02-15T21:15:06.908
Key vars=(:level, :x, :y, :z, :id)
Using var(s)=(1, 2, 3, 4) = (:vx, :vy, :vz, :mass)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...100%|████████████████████████████████████| Time: 0:00:02
Found 5.089390e+05 particles
Memory used for data table :31.064278602600098 MB
-------------------------------------------------------
[Mera]: Get clump data: 2020-02-15T21:15:11.574
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
### Note
Many functions can provide the results in selected units. The internal scaling from code to physical units makes use of the following defined relations:
```julia
viewfields(info.scale)
```
[Mera]: Fields to scale from user/code units to selected units
=======================================================================
Mpc = 0.0010000000000006482
kpc = 1.0000000000006481
pc = 1000.0000000006482
mpc = 1.0000000000006482e6
ly = 3261.5637769461323
Au = 2.0626480623310105e23
km = 3.0856775812820004e16
m = 3.085677581282e19
cm = 3.085677581282e21
mm = 3.085677581282e22
μm = 3.085677581282e25
Msol_pc3 = 0.9997234790001649
g_cm3 = 6.76838218451376e-23
Msol_pc2 = 999.7234790008131
g_cm2 = 0.20885045168302602
Gyr = 0.014910986463557083
Myr = 14.910986463557084
yr = 1.4910986463557083e7
s = 4.70554946422349e14
ms = 4.70554946422349e17
Msol = 9.99723479002109e8
Mearth = 3.329677459032007e14
Mjupiter = 1.0476363431814971e12
g = 1.9885499720830952e42
km_s = 65.57528732282063
m_s = 65575.28732282063
cm_s = 6.557528732282063e6
nH = 30.987773856809987
erg = 8.551000140274429e55
g_cms2 = 2.9104844143584656e-9
T_mu = 517028.3199143136
Ba = 2.910484414358466e-9
## Total Mass
The function `msum` calculates the total mass of the data that is assigned to the provided object. For the hydro-data, the mass is derived from the density and cell-size (level) of all elements. `info.scale.Msol` (or e.g.: gas.info.scale.Msol) scales the result from code units to solar masses:
```julia
println( "Gas Mtot: ", msum(gas) * info.scale.Msol, " Msol" )
println( "Particles Mtot: ", msum(particles) * info.scale.Msol, " Msol" )
println( "Clumps Mtot: ", msum(clumps) * info.scale.Msol, " Msol" )
```
Gas Mtot: 2.6703951073850353e10 Msol
Particles Mtot: 5.804426008528444e9 Msol
Clumps Mtot: 1.3743280681841675e10 Msol
The units for the results can be calculated by the function itself by providing an unit-argument:
```julia
println( "Gas Mtot: ", msum(gas, :Msol) , " Msol" )
println( "Particles Mtot: ", msum(particles, :Msol) , " Msol" )
println( "Clumps Mtot: ", msum(clumps, :Msol) , " Msol" )
```
Gas Mtot: 2.6703951073850353e10 Msol
Particles Mtot: 5.804426008528437e9 Msol
Clumps Mtot: 1.3743280681841677e10 Msol
The following methods are defined on the function `msum`:
```julia
methods(msum)
```
2 methods for generic function <b>msum</b>:<ul><li> msum(dataobject::<b>ContainMassDataSetType</b>; <i>unit, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L23" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:23</a></li> <li> msum(dataobject::<b>ContainMassDataSetType</b>, unit::<b>Symbol</b>; <i>mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L19" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:19</a></li> </ul>
## Center-Of-Mass
The function `center_of_mass` or `com` calculates the center-of-mass of the data that is assigned to the provided object.
```julia
println( "Gas COM: ", center_of_mass(gas) .* info.scale.kpc, " kpc" )
println( "Particles COM: ", center_of_mass(particles) .* info.scale.kpc, " kpc" )
println( "Clumps COM: ", center_of_mass(clumps) .* info.scale.kpc, " kpc" );
```
Gas COM: (23.327487354477643, 23.835419919525922, 24.041720148035843) kpc
Particles COM: (22.891354761211332, 24.174147282680273, 24.003205056545575) kpc
Clumps COM: (23.135765457064576, 23.741712325649264, 24.0050127185862) kpc
The units for the results can be calculated by the function itself by providing a unit-argument:
```julia
println( "Gas COM: ", center_of_mass(gas, :kpc) , " kpc" )
println( "Particles COM: ", center_of_mass(particles, :kpc) , " kpc" )
println( "Clumps COM: ", center_of_mass(clumps, :kpc) , " kpc" );
```
Gas COM: (23.327487354477643, 23.835419919525922, 24.041720148035843) kpc
Particles COM: (22.891354761211332, 24.174147282680273, 24.003205056545575) kpc
Clumps COM: (23.135765457064576, 23.741712325649264, 24.0050127185862) kpc
A shorter name for the function `center_of_mass` is defined as `com` :
```julia
println( "Gas COM: ", com(gas, :kpc) , " kpc" )
println( "Particles COM: ", com(particles, :kpc) , " kpc" )
println( "Clumps COM: ", com(clumps, :kpc) , " kpc" );
```
Gas COM: (23.327487354477643, 23.835419919525922, 24.041720148035843) kpc
Particles COM: (22.891354761211332, 24.174147282680273, 24.003205056545575) kpc
Clumps COM: (23.135765457064576, 23.741712325649264, 24.0050127185862) kpc
The result of the coordinates (x, y, z) can be assigned e.g. to a tuple or to three single variables:
```julia
# return coordinates in a tuple
com_gas = com(gas, :kpc)
println( "Tuple: ", com_gas, " kpc" )
# return coordinates into variables
x_pos, y_pos, z_pos = com(gas, :kpc); #create variables
println("Single vars: ", x_pos, " ", y_pos, " ", z_pos, " kpc")
```
Tuple: (23.327487354477643, 23.835419919525922, 24.041720148035843) kpc
Single vars: 23.327487354477643 23.835419919525922 24.041720148035843 kpc
Calculate the joint centre-of-mass from the hydro and particle data. Provide the hydro and particle data with an array (independent order):
```julia
println( "Joint COM (Gas + Particles): ", center_of_mass([gas,particles], :kpc) , " kpc" )
println( "Joint COM (Particles + Gas): ", center_of_mass([particles,gas], :kpc) , " kpc" )
```
Joint COM (Gas + Particles): (23.24961513830681, 23.895900266222746, 24.03484321295537) kpc
Joint COM (Particles + Gas): (23.24961513830681, 23.895900266222746, 24.03484321295537) kpc
Use the shorter name `com` that is defined as the function `center_of_mass` :
```julia
println( "Joint COM (Gas + Particles): ", com([gas,particles], :kpc) , " kpc" )
println( "Joint COM (Particles + Gas): ", com([particles,gas], :kpc) , " kpc" )
```
Joint COM (Gas + Particles): (23.24961513830681, 23.895900266222746, 24.03484321295537) kpc
Joint COM (Particles + Gas): (23.24961513830681, 23.895900266222746, 24.03484321295537) kpc
```julia
methods(center_of_mass)
```
4 methods for generic function <b>center_of_mass</b>:<ul><li> center_of_mass(dataobject::<b>Array{HydroPartType,1}</b>; <i>unit, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L108" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:108</a></li> <li> center_of_mass(dataobject::<b>Array{HydroPartType,1}</b>, unit::<b>Symbol</b>; <i>mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L103" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:103</a></li> <li> center_of_mass(dataobject::<b>ContainMassDataSetType</b>; <i>unit, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L51" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:51</a></li> <li> center_of_mass(dataobject::<b>ContainMassDataSetType</b>, unit::<b>Symbol</b>; <i>mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L47" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:47</a></li> </ul>
```julia
methods(com)
```
4 methods for generic function <b>com</b>:<ul><li> com(dataobject::<b>Array{HydroPartType,1}</b>; <i>unit, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L166" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:166</a></li> <li> com(dataobject::<b>Array{HydroPartType,1}</b>, unit::<b>Symbol</b>; <i>mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L162" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:162</a></li> <li> com(dataobject::<b>ContainMassDataSetType</b>; <i>unit, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L80" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:80</a></li> <li> com(dataobject::<b>ContainMassDataSetType</b>, unit::<b>Symbol</b>; <i>mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L76" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:76</a></li> </ul>
## Bulk Velocity
The function `bulk_velocity` or `average_velocity` calculates the average velocity (w/o mass-weight) of the data that is assigned to the provided object. It can also be used for the clump data if it has velocity components: vx, vy, vz. The default is with mass-weighting:
```julia
println( "Gas: ", bulk_velocity(gas, :km_s) , " km/s" )
println( "Particles: ", bulk_velocity(particles, :km_s) , " km/s" )
```
Gas: (-1.4418303105424648, -11.708719305767849, -0.5393243496862975) km/s
Particles: (-11.623422700314535, -18.440572802490234, -0.3291927731417528) km/s
```julia
println( "Gas: ", average_velocity(gas, :km_s) , " km/s" )
println( "Particles: ", average_velocity(particles, :km_s) , " km/s" )
```
Gas: (-1.4418303105424648, -11.708719305767849, -0.5393243496862975) km/s
Particles: (-11.623422700314535, -18.440572802490234, -0.3291927731417528) km/s
Without mass-weighting:
- gas: volume or :no weighting
- particles: no weighting
```julia
println( "Gas: ", bulk_velocity(gas, :km_s, weighting=:volume) , " km/s" )
println( "Particles: ", bulk_velocity(particles, :km_s, weighting=:no) , " km/s" )
```
Gas: (1.5248458901822857, -8.770913864354458, -0.5037635305158431) km/s
Particles: (-11.594477384589647, -18.38859118719373, -0.3097746295267971) km/s
```julia
println( "Gas: ", average_velocity(gas, :km_s, weighting=:volume) , " km/s" )
println( "Particles: ", average_velocity(particles, :km_s, weighting=:no) , " km/s" )
```
Gas: (1.5248458901822857, -8.770913864354458, -0.5037635305158431) km/s
Particles: (-11.594477384589647, -18.38859118719373, -0.3097746295267971) km/s
```julia
methods(bulk_velocity)
```
2 methods for generic function <b>bulk_velocity</b>:<ul><li> bulk_velocity(dataobject::<b>ContainMassDataSetType</b>; <i>unit, weighting, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L200" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:200</a></li> <li> bulk_velocity(dataobject::<b>ContainMassDataSetType</b>, unit::<b>Symbol</b>; <i>weighting, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L195" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:195</a></li> </ul>
```julia
methods(average_velocity)
```
2 methods for generic function <b>average_velocity</b>:<ul><li> average_velocity(dataobject::<b>ContainMassDataSetType</b>; <i>unit, weighting, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L241" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:241</a></li> <li> average_velocity(dataobject::<b>ContainMassDataSetType</b>, unit::<b>Symbol</b>; <i>weighting, mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L237" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:237</a></li> </ul>
## Mass Weighted Average
The functions `center_of_mass` and `bulk_velocity` use the function `average_mweighted` (average_mass-weighted) in the backend which can be feeded with any kind of variable that is pre-defined for the `getvar()` function or exists in the datatable. See the defined method and at getvar() below:
```julia
methods( average_mweighted )
```
1 method for generic function <b>average_mweighted</b>:<ul><li> average_mweighted(dataobject::<b>ContainMassDataSetType</b>, var::<b>Symbol</b>; <i>mask</i>) in Mera at <a href="https://github.com/ManuelBehrendt/Mera/tree/23691e0c306bee008c0474baa1e7d326f318cfa3//src/functions/basic_calc.jl#L172" target="_blank">/Users/mabe/Documents/Projects/dev/Mera/src/functions/basic_calc.jl:172</a></li> </ul>
<a id="Statistics"></a>
## Get Predefined Quantities
Here, we only show the examples with the hydro-data:
```julia
info = getinfo(1, "../../testing/simulations/manu_stable_2019", verbose=false);
gas = gethydro(info, [:rho, :vx, :vy, :vz], verbose=false);
```
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:00:56
Use `getvar` to extract variables or derive predefined quantities from the database, dependent on the data type.
See the possible variables:
```julia
getvar()
```
Predefined vars that can be calculated for each cell/particle:
----------------------------------------------------------------
=============================[gas]:=============================
-all the non derived hydro vars-
:cpu, :level, :rho, :cx, :cy, :cz, :vx, :vy, :vz, :p, var6,...
-derived hydro vars-
:x, :y, :z
:mass, :cellsize, :volume, :freefall_time
:cs, :mach, :jeanslength, :jeansnumber
==========================[particles]:==========================
all the non derived vars:
:cpu, :level, :id, :family, :tag
:x, :y, :z, :vx, :vy, :vz, :mass, :birth, :metal....
-derived particle vars-
:age
===========================[clumps]:===========================
:peak_x or :x, :peak_y or :y, :peak_z or :z
:v, :ekin,...
=====================[gas or particles]:=======================
:v, :ekin
related to a given center:
---------------------------
:r_cylinder, :r_sphere (radial components)
:vr_cylinder
:vϕ
----------------------------------------------------------------
### Get a Single Quantity
In the following example, we calculate the mass for each cell of the hydro data.
- The output is a 1dim array in code units by default (mass1).
- Each element/cell can be scaled to Msol units by the elementwise multiplikation **gas.scale.Msol** (mass2).
- The `getvar` function supports intrinsic scaling to a selected unit (mass3).
- The selected unit does not need a keyword argument if the following order is maintained: dataobject, variable, unit
```julia
mass1 = getvar(gas, :mass) # [code units]
mass2 = getvar(gas, :mass) * gas.scale.Msol # scale the result (1dim array) from code units to solar masses
mass3 = getvar(gas, :mass, unit=:Msol) # unit calculation, provided by a keyword argument [Msol]
mass4 = getvar(gas, :mass, :Msol) # unit calculation provided by an argument [Msol]
# construct a three dimensional array to compare the three created arrays column wise:
mass_overview = [mass1 mass2 mass3 mass4]
```
37898393×4 Array{Float64,2}:
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
8.9407e-7 894.07 894.07 894.07
⋮
1.02889e-7 102.889 102.889 102.889
1.02889e-7 102.889 102.889 102.889
1.94423e-7 194.423 194.423 194.423
1.94423e-7 194.423 194.423 194.423
8.90454e-8 89.0454 89.0454 89.0454
8.90454e-8 89.0454 89.0454 89.0454
2.27641e-8 22.7641 22.7641 22.7641
2.27641e-8 22.7641 22.7641 22.7641
8.42157e-9 8.42157 8.42157 8.42157
8.42157e-9 8.42157 8.42157 8.42157
3.65085e-8 36.5085 36.5085 36.5085
3.65085e-8 36.5085 36.5085 36.5085
Furthermore, we provide a simple function to get the mass of each cell in code units:
```julia
getmass(gas)
```
37898393-element Array{Float64,1}:
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
8.940696716308594e-7
⋮
1.0288910576564388e-7
1.0288910576564388e-7
1.9442336261293343e-7
1.9442336261293343e-7
8.90453891574347e-8
8.90453891574347e-8
2.276412192306883e-8
2.276412192306883e-8
8.421571563820485e-9
8.421571563820485e-9
3.650851622718898e-8
3.650851622718898e-8
### Get Multiple Quantities
Get several quantities with one function call by passing an array containing the selected variables.
`getvar` returns a dictionary containing 1dim arrays for each quantity in code units:
```julia
quantities = getvar(gas, [:mass, :ekin])
```
Dict{Any,Any} with 2 entries:
:mass => [8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407e-7, 8…
:ekin => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 2.28274e-7, 2.…
The units for each quantity can by passed as an array to the keyword argument "units" (plural, compare with single quantitiy call above) by preserving the order of the vars argument:
```julia
quantities = getvar(gas, [:mass, :ekin], units=[:Msol, :erg])
```
Dict{Any,Any} with 2 entries:
:mass => [894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894…
:ekin => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 1.95354e49, 1.…
The function can be called without any keywords by preserving the following order: dataobject, variables, units
```julia
quantities = getvar(gas, [:mass, :ekin], [:Msol, :erg])
```
Dict{Any,Any} with 2 entries:
:mass => [894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894…
:ekin => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 1.95354e49, 1.…
The arrays of the single quantities can be accessed from the dictionary:
```julia
quantities[:mass]
```
37898393-element Array{Float64,1}:
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
894.0696716308591
⋮
102.88910576564386
102.88910576564386
194.42336261293337
194.42336261293337
89.04538915743468
89.04538915743468
22.764121923068824
22.764121923068824
8.421571563820482
8.421571563820482
36.50851622718897
36.50851622718897
If all selected variables should be of the same unit use the following arguments: dataobject, array of quantities, unit (no array needed):
```julia
quantities = getvar(gas, [:vx, :vy, :vz], :km_s)
```
Dict{Any,Any} with 3 entries:
:vy => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … -97.5301, -97.53…
:vz => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0…
:vx => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … -24.307, -24.307…
### Get Quantities related to a center
Some quantities are related to a given center, e.g. radius in cylindrical coordinates, see the overview :
```julia
getvar()
```
Predefined vars that can be calculated for each cell/particle:
----------------------------------------------------------------
=============================[gas]:=============================
-all the non derived hydro vars-
:cpu, :level, :rho, :cx, :cy, :cz, :vx, :vy, :vz, :p, var6,...
-derived hydro vars-
:x, :y, :z
:mass, :cellsize, :volume, :freefall_time
:cs, :mach, :jeanslength, :jeansnumber
:T, :Temp, :Temperature with p/rho
:h, :hx, :hy, :hz (specific angular momentum)
==========================[particles]:==========================
-all the non derived particle vars-
:cpu, :level, :id, :family, :tag
:x, :y, :z, :vx, :vy, :vz, :mass, :birth, :metal....
-derived particle vars-
:age
===========================[gravity]:===========================
-all the non derived gravity vars-
:cpu, :level, cx, cy, cz, :epot, :ax, :ay, :az
-derived gravity vars-
:x, :y, :z
:cellsize, :volume
===========================[clumps]:===========================
:peak_x or :x, :peak_y or :y, :peak_z or :z
:v, :ekin,...
=====================[gas or particles]:=======================
:v, :ekin
related to a given center:
---------------------------
:r_cylinder, :r_sphere (radial components)
:vr_cylinder
:vϕ
----------------------------------------------------------------
The unit of the provided center-array (in cartesian coordinates: x,y.z) is given by the keyword argument `center_unit` (default: code units).
The function returns the quantitites in code units:
```julia
cv = (gas.boxlen / 2.) * gas.scale.kpc # provide the box-center in kpc
# e.g. for :mass the center keyword is ignored
quantities = getvar(gas, [:mass, :r_cylinder], center=[cv, cv, cv], center_unit=:kpc)
```
Dict{Any,Any} with 2 entries:
:r_cylinder => [70.1583, 70.1583, 70.1583, 70.1583, 70.1583, 70.1583, 70.1583…
:mass => [8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407e-7, 8.9407…
Here, the function returns the result in the units that are provided. Note: E.g. the quantities :mass and :v (velocity) are not affected by the given center.
```julia
quantities = getvar(gas, [:mass, :r_cylinder, :v], units=[:Msol, :kpc, :km_s], center=[cv, cv, cv], center_unit=:kpc)
```
Dict{Any,Any} with 3 entries:
:r_cylinder => [70.1583, 70.1583, 70.1583, 70.1583, 70.1583, 70.1583, 70.1583…
:v => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 100.513,…
:mass => [894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.0…
Use the short notation for the box center :bc or :boxcenter for all dimensions (x,y,z). In this case the keyword `center_unit` is ignored:
```julia
quantities = getvar(gas, [:mass, :r_cylinder, :v], units=[:Msol, :kpc, :km_s], center=[:boxcenter])
```
Dict{Any,Any} with 3 entries:
:r_cylinder => [70.1583, 70.1583, 70.1583, 70.1583, 70.1583, 70.1583, 70.1583…
:v => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 100.513,…
:mass => [894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.0…
```julia
quantities = getvar(gas, [:mass, :r_cylinder, :v], units=[:Msol, :kpc, :km_s], center=[:bc])
```
Dict{Any,Any} with 3 entries:
:r_cylinder => [70.1583, 70.1583, 70.1583, 70.1583, 70.1583, 70.1583, 70.1583…
:v => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 100.513,…
:mass => [894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.0…
Use the box center notation for individual dimensions, here x,z. The keyword `center_unit` is needed for the y-coordinates:
```julia
quantities = getvar(gas, [:mass, :r_cylinder, :v], units=[:Msol, :kpc, :km_s], center=[:bc, 24., :bc], center_unit=:kpc)
```
Dict{Any,Any} with 3 entries:
:r_cylinder => [54.9408, 54.9408, 54.9408, 54.9408, 54.9408, 54.9408, 54.9408…
:v => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 100.513,…
:mass => [894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.07, 894.0…
## Create Costum Quantities
**Example1:** Represent the positions of the data as the radius for a disk, centred in the simulation box (cylindrical coordinates):
```julia
boxlen = info.boxlen
cv = boxlen / 2. # box-center
levels = getvar(gas, :level) # get the level of each cell
cellsize = boxlen ./ 2 .^levels # calculate the cellsize for each cell (code units)
# or use the predefined quantity
cellsize = getvar(gas, :cellsize)
# convert the cell-number (related to the levels) into positions (code units), relative to the box center
x = getvar(gas, :cx) .* cellsize .- cv # (code units)
y = getvar(gas, :cy) .* cellsize .- cv # (code units)
# or use the predefined quantity
x = getvar(gas, :x, center=[:bc])
y = getvar(gas, :y, center=[:bc])
# calculate the cylindrical radius and scale from code units to kpc
radius = sqrt.(x.^2 .+ y.^2) .* info.scale.kpc
```
37898393-element Array{Float64,1}:
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
70.15825094589823
⋮
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
20.08587520654808
### Use JuliaDB Functions
see <https://juliadb.org>
```julia
using JuliaDB
```
Example: Get the mass for each gas cell:
m_i = ρ_i * cell_volume_i = ρ_i * (boxlen / 2^level)^3
#### Version 1
Use the `select` function and calculate the mass for each cell:
```julia
boxlen = gas.boxlen
level = select(gas.data, :level ) # get level information from each cell
cellvol = (boxlen ./ 2 .^level).^3 # calculate volume for each cell
mass1 = select(gas.data, :rho) .* cellvol .* info.scale.Msol; # calculate the mass for each cell in Msol units
```
#### Version 2
Use a single time the `select` function to do the calculations from above :
```julia
mass2 = select( gas.data, (:rho, :level)=>p->p.rho * (boxlen / 2^p.level)^3 ) .* info.scale.Msol;
```
#### Version 3
Use the `map` function to do the calculations from above :
```julia
mass3 = map(p->p.rho * (boxlen / 2^p.level)^3, gas.data) .* info.scale.Msol;
```
Comparison of the results:
```julia
[mass1 mass2 mass3]
```
37898393×3 Array{Float64,2}:
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
894.07 894.07 894.07
⋮
102.889 102.889 102.889
102.889 102.889 102.889
194.423 194.423 194.423
194.423 194.423 194.423
89.0454 89.0454 89.0454
89.0454 89.0454 89.0454
22.7641 22.7641 22.7641
22.7641 22.7641 22.7641
8.42157 8.42157 8.42157
8.42157 8.42157 8.42157
36.5085 36.5085 36.5085
36.5085 36.5085 36.5085
## Statistical Quantities
```julia
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14", verbose=false);
gas = gethydro(info, [:rho, :vx, :vy, :vz], lmax=8, smallr=1e-5, verbose=false);
particles = getparticles(info, [:mass, :vx, :vy, :vz], verbose=false)
clumps = getclumps(info, verbose=false);
```
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:02:22
Reading data...100%|████████████████████████████████████| Time: 0:00:03
Pass any kind of Array{<:Real,1} (Float, Integer,...) to the `wstat` function to get several unweighted statistical quantities at once:
```julia
stats_gas = wstat( getvar(gas, :vx, :km_s) )
stats_particles = wstat( getvar(particles, :vx, :km_s) )
stats_clumps = wstat( getvar(clumps, :rho_av, :Msol_pc3) );
```
The result is an object that contains several fields with the statistical quantities:
```julia
println( typeof(stats_gas) )
println( typeof(stats_particles) )
println( typeof(stats_clumps) )
propertynames(stats_gas)
```
Mera.WStatType
Mera.WStatType
Mera.WStatType
(:mean, :median, :std, :skewness, :kurtosis, :min, :max)
```julia
println( "Gas <vx>_allcells : ", stats_gas.mean, " km/s" )
println( "Particles <vx>_allparticles : ", stats_particles.mean, " km/s" )
println( "Clumps <rho_av>_allclumps : ", stats_clumps.mean, " Msol/pc^3" )
```
Gas <vx>_allcells : -2.9318774650713726 km/s
Particles <vx>_allparticles : -11.594477384589647 km/s
Clumps <rho_av>_allclumps : 594.7315900915924 Msol/pc^3
```julia
println( "Gas min/max_allcells : ", stats_gas.min, "/", stats_gas.max, " km/s" )
println( "Particles min/max_allparticles : ", stats_particles.min,"/", stats_particles.max, " km/s" )
println( "Clumps min/max_allclumps : ", stats_clumps.min, "/", stats_clumps.max, " Msol/pc^3" )
```
Gas min/max_allcells : -676.5464963488397/894.9181733956399 km/s
Particles min/max_allparticles : -874.6440509326601/670.7956741234592 km/s
Clumps min/max_allclumps : 125.4809686796669/5357.370234867635 Msol/pc^3
## Weighted Statistics
Pass any kind of Array{<:Real,1} (Float, Integer,...) for the given variables and one for the weighting with the same length. The weighting goes cell by cell, particle by particle, clump by clump, etc...:
```julia
stats_gas = wstat( getvar(gas, :vx, :km_s), weight=getvar(gas, :mass ));
stats_particles = wstat( getvar(particles, :vx, :km_s), weight=getvar(particles, :mass ));
stats_clumps = wstat( getvar(clumps, :peak_x, :kpc ), weight=getvar(clumps, :mass_cl)) ;
```
Without the keyword `weight` the following order for the given arrays has to be maintained: values, weight
```julia
stats_gas = wstat( getvar(gas, :vx, :km_s), getvar(gas, :mass ));
stats_particles = wstat( getvar(particles, :vx, :km_s), getvar(particles, :mass ));
stats_clumps = wstat( getvar(clumps, :peak_x, :kpc ), getvar(clumps, :mass_cl)) ;
```
```julia
propertynames(stats_gas)
```
(:mean, :median, :std, :skewness, :kurtosis, :min, :max)
```julia
println( "Gas <vx>_allcells : ", stats_gas.mean, " km/s (mass weighted)" )
println( "Particles <vx>_allparticles : ", stats_particles.mean, " km/s (mass weighted)" )
println( "Clumps <peak_x>_allclumps : ", stats_clumps.mean, " kpc (mass weighted)" )
```
Gas <vx>_allcells : -1.199925358479736 km/s (mass weighted)
Particles <vx>_allparticles : -11.623422700314544 km/s (mass weighted)
Clumps <peak_x>_allclumps : 23.13576545706458 kpc (mass weighted)
```julia
println( "Gas min/max_allcells : ", stats_gas.min, "/", stats_gas.max, " km/s" )
println( "Particles min/max_allparticles : ", stats_particles.min,"/", stats_particles.max, " km/s" )
println( "Clumps min/max_allclumps : ", stats_clumps.min, "/", stats_clumps.max, " Msol/pc^3" )
```
Gas min/max_allcells : -676.5464963488397/894.9181733956399 km/s
Particles min/max_allparticles : -874.6440509326601/670.7956741234592 km/s
Clumps min/max_allclumps : 10.29199219000667/38.17382813002474 Msol/pc^3
For the average of the gas-density use volume weighting:
```julia
stats_gas = wstat( getvar(gas, :rho, :g_cm3), weight=getvar(gas, :volume) );
```
```julia
println( "Gas <rho>_allcells : ", stats_gas.mean, " g/cm^3 (volume weighted)" )
```
Gas <rho>_allcells : 0.008679815788762611 g/cm^3 (volume weighted)
## Helpful Functions
Get the x,y,z positions of every cell relative to a given center:
```julia
x,y,z = getpositions(gas, :kpc, center=[24.,24.,24.], center_unit=:kpc); # returns a Tuple of 3 arrays
```
The box-center can be calculated automatically:
```julia
x,y,z = getpositions(gas, :kpc, center=[:boxcenter]);
```
```julia
[x y z] # preview of the output
```
849332×3 Array{Float64,2}:
-23.25 -23.25 -23.25
-23.25 -23.25 -22.5
-23.25 -23.25 -21.75
-23.25 -23.25 -21.0
-23.25 -23.25 -20.25
-23.25 -23.25 -19.5
-23.25 -23.25 -18.75
-23.25 -23.25 -18.0
-23.25 -23.25 -17.25
-23.25 -23.25 -16.5
-23.25 -23.25 -15.75
-23.25 -23.25 -15.0
-23.25 -23.25 -14.25
⋮
16.125 3.9375 0.1875
16.125 3.9375 0.375
16.125 3.9375 0.5625
16.125 3.9375 0.75
16.125 4.125 -0.5625
16.125 4.125 -0.375
16.125 4.125 -0.1875
16.125 4.125 0.0
16.125 4.125 0.1875
16.125 4.125 0.375
16.125 4.125 0.5625
16.125 4.125 0.75
Get the extent of the dataset-domain:
```julia
getextent(gas) # returns Tuple of (xmin, xmax), (ymin ,ymax ), (zmin ,zmax )
```
((0.0, 48.0), (0.0, 48.0), (0.0, 48.0))
Get the extent relative to a given center:
```julia
getextent(gas, center=[:boxcenter])
```
((-24.0, 24.0), (-24.0, 24.0), (-24.0, 24.0))
Get simulation time in code unit oder physical unit
```julia
gettime(info)
```
29.9031937665063
```julia
gettime(info, :Myr)
```
445.8861174695
```julia
gettime(gas, :Myr)
```
445.8861174695
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 26561 | # 5. Mask/Select/Map/Filter/Metaprogramming...
- Learn how to extract data from the data table with JuliaDB and Mera functions
- Filter the data table according to one or several conditions
- Extract data from a filtered data table and use it for further calculations
- Extend the data table with new columns/variables
- Mask data with different methods and apply it to some functions
## Load The Data
```julia
using Mera
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
gas = gethydro(info, lmax=8, smallr=1e-5);
particles = getparticles(info)
clumps = getclumps(info);
```
[Mera]: 2020-02-08T20:56:19.834
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get hydro data: 2020-02-08T20:56:27.064
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:02:07
Memory used for data table :71.28007793426514 MB
-------------------------------------------------------
[Mera]: Get particle data: 2020-02-08T20:58:39.435
Key vars=(:level, :x, :y, :z, :id)
Using var(s)=(1, 2, 3, 4, 5) = (:vx, :vy, :vz, :mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Found 5.089390e+05 particles
Memory used for data table :34.947275161743164 MB
-------------------------------------------------------
[Mera]: Get clump data: 2020-02-08T20:58:41.769
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
## Select From Data Table
### Select a single column/variable
##### By using JuliaDB or Mera functions
```julia
using JuliaDB
```
The JuliaDB data table is stored in the `data`-field of any `DataSetType`. Extract an existing column (variable):
```julia
select(gas.data, :rho) # JuliaDB
```
849332-element Array{Float64,1}:
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
⋮
0.00010967104288285959
0.0001088040126114162
0.00010915603617815434
0.00010917096551347797
0.00012465438542871006
0.00011934527871880502
0.00011294656300014925
0.00011110068692986109
0.00010901341218606515
0.00010849404903183988
0.00010900588395976569
0.00010910219163333514
Pass the entire `DataSetType` (here `gas`) to the Mera function `getvar` to extract the selected variable or derived quantity from the data table.
Call `getvar()` to get a list of the predefined quantities.
```julia
getvar(gas, :rho) # MERA
```
849332-element Array{Float64,1}:
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
⋮
0.00010967104288285959
0.0001088040126114162
0.00010915603617815434
0.00010917096551347797
0.00012465438542871006
0.00011934527871880502
0.00011294656300014925
0.00011110068692986109
0.00010901341218606515
0.00010849404903183988
0.00010900588395976569
0.00010910219163333514
### Select several columns
By selecting several columns a new JuliaDB databse is returned:
```julia
select(gas.data, (:rho, :level)) #JuliaDB
```
Table with 849332 rows, 2 columns:
rho level
──────────────────
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
⋮
0.000108804 8
0.000109156 8
0.000109171 8
0.000124654 8
0.000119345 8
0.000112947 8
0.000111101 8
0.000109013 8
0.000108494 8
0.000109006 8
0.000109102 8
The getvar function returns a dictionary containing the extracted arrays:
```julia
getvar(gas, [:rho, :level]) # MERA
```
Dict{Any,Any} with 2 entries:
:level => [6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0 … 8.0, 8.0, 8.0…
:rho => [1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.…
Select one or more columns and get a tuple of vectors:
```julia
vtuple = columns(gas.data, (:rho, :level)) # JuliaDB
```
(rho = [1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5 … 0.00010915603617815434, 0.00010917096551347797, 0.00012465438542871006, 0.00011934527871880502, 0.00011294656300014925, 0.00011110068692986109, 0.00010901341218606515, 0.00010849404903183988, 0.00010900588395976569, 0.00010910219163333514], level = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6 … 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
```julia
propertynames(vtuple)
```
(:rho, :level)
```julia
vtuple.rho
```
849332-element Array{Float64,1}:
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
⋮
0.00010967104288285959
0.0001088040126114162
0.00010915603617815434
0.00010917096551347797
0.00012465438542871006
0.00011934527871880502
0.00011294656300014925
0.00011110068692986109
0.00010901341218606515
0.00010849404903183988
0.00010900588395976569
0.00010910219163333514
## Filter by Condition
### With JuliaDB (example A)
Get all the data corresponding to cells/rows with level=6. Here, the variable `p` is used as placeholder for rows. A new JuliaDB data table is returend:
```julia
filtered_db = filter(p->p.level==6, gas.data ) # JuliaDB
# see the reduced row number
```
Table with 240956 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### With Macro Expression (example A)
(see the documentation at: <https://piever.github.io/JuliaDBMeta.jl/stable/> )
```julia
using JuliaDBMeta
```
┌ Info: Precompiling JuliaDBMeta [2c06ca41-a429-545c-b8f0-5ca7dd64ba19]
└ @ Base loading.jl:1273
```julia
filtered_db = @filter gas.data :level==6 # JuliaDBMeta
```
Table with 240956 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### With JuliaDB (example B)
Get all cells/rows with densities >= 3 Msol/pc^3. Since the data is given in code units, we need to convert from the given physical units:
```julia
density = 3. / gas.scale.Msol_pc3
filtered_db = filter(p->p.rho>= density, gas.data ) # JuliaDB
```
Table with 210 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### With Macro Expression (example B)
```julia
density = 3. /gas.scale.Msol_pc3
filtered_db = @filter gas.data :rho>= density # JuliaDBMeta
```
Table with 210 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### Get a Quantity/Variable from The Filtered Data Table
Calculate the mass for each cell and the sum:
```julia
mass_tot = getvar(gas, :mass, :Msol) # the full data table
sum(mass_tot)
```
3.0968754148332745e10
The same calculation is possible for the filtered data base which has to be passed together with the original object, here: `gas`
```julia
mass_filtered_tot = getvar(gas, :mass, :Msol, filtered_db=filtered_db) # the filtered data table
sum(mass_filtered_tot)
```
1.4862767967535206e10
### Create a New DataSetType from a Filtered Data Table
A new `DataSetType` can be constructed for the filtered data table that can be passed to the functions.
```julia
density = 3. /gas.scale.Msol_pc3
filtered_db = @filter gas.data :rho >= density
gas_new = construct_datatype(filtered_db, gas);
```
```julia
# Both are now of HydroDataType and include the same information about the simulation properties (besides the canged data table)
println( typeof(gas) )
println( typeof(gas_new) )
```
HydroDataType
HydroDataType
```julia
mass_filtered_tot = getvar(gas_new, :mass, :Msol)
sum(mass_filtered_tot)
```
1.4862767967535206e10
## Filter by Multiple Conditions
### With JuliaDB
Get the mass of all cells/rows with densities >= 3 Msol/pc^3 that is within the disk radius of 3 kpc and 2 kpc from the plane:
```julia
boxlen = info.boxlen
cv = boxlen/2. # box-center
density = 3. /gas.scale.Msol_pc3
radius = 3. /gas.scale.kpc
height = 2. /gas.scale.kpc
# filter cells/rows that contain rho greater equal density
filtered_db = filter(p->p.rho >= density, gas.data )
# filter cells/rows lower equal the defined radius and height
# (convert the cell number to a position according to its cellsize and relative to the box center)
filtered_db = filter(row-> sqrt( (row.cx * boxlen /2^row.level - cv)^2 + (row.cy * boxlen /2^row.level - cv)^2) <= radius &&
abs(row.cz * boxlen /2^row.level - cv) <= height, filtered_db)
var_filtered = getvar(gas, :mass, filtered_db=filtered_db, unit=:Msol)
sum(var_filtered) # [Msol]
```
2.750632450062189e9
### Use Pipeline Macros
```julia
boxlen = info.boxlen
cv = boxlen/2.
density = 3. /gas.scale.Msol_pc3
radius = 3. /gas.scale.kpc
height = 2. /gas.scale.kpc
filtered_db = @apply gas.data begin
@where :rho >= density
@where sqrt( (:cx * boxlen/2^:level - cv)^2 + (:cy * boxlen/2^:level - cv)^2 ) <= radius
@where abs(:cz * boxlen/2^:level -cv) <= height
end
var_filtered = getvar(gas, :mass, filtered_db=filtered_db, unit=:Msol)
sum(var_filtered) # [Msol]
```
2.750632450062189e9
### External Functions With JuliaDB
```julia
boxlen = info.boxlen
function r(x,y,level,boxlen)
return sqrt((x * boxlen /2^level - boxlen/2.)^2 + (y * boxlen /2^level - boxlen/2.)^2)
end
function h(z,level,boxlen)
return abs(z * boxlen /2^level - boxlen/2.)
end
density = 3. /gas.scale.Msol_pc3
radius = 3. /gas.scale.kpc
height = 2. /gas.scale.kpc
filtered_db = filter(row-> row.rho >= density &&
r(row.cx,row.cy, row.level, boxlen) <= radius &&
h(row.cz,row.level, boxlen) <= height, gas.data)
var_filtered = getvar(gas, :mass, filtered_db=filtered_db, unit=:Msol)
sum(var_filtered) # [Msol]
```
2.750632450062189e9
### External Functions With Macro Expression
```julia
boxlen = info.boxlen
cv = boxlen/2.
density = 3. /gas.scale.Msol_pc3
radius = 3. /gas.scale.kpc
height = 2. /gas.scale.kpc
function p(val, level, boxlen)
cv = boxlen/2
return val * boxlen /2^level - cv
end
filtered_db = @apply gas.data begin
@where :rho >= density
@where sqrt( p(:cx, :level, boxlen)^2 + p(:cy, :level, boxlen)^2 ) <= radius
@where abs( p(:cz, :level, boxlen) ) <= height
end
var_filtered = getvar(gas, :mass, filtered_db=filtered_db, unit=:Msol)
sum(var_filtered) # [Msol]
```
2.750632450062189e9
### Compare With Predefined Functions
Compare the previous calculations with the predefined `subregion` function:
The `subregion` function takes the intersected cells of the range borders into account (default):
```julia
density = 3. /gas.scale.Msol_pc3 # in code units
sub_region = subregion(gas, :cylinder, radius=3., height=2., center=[:boxcenter], range_unit=:kpc, verbose=false ) # default: cell=true
filtered_db = @filter sub_region.data :rho >= density
var_filtered = getvar(gas, :mass, :Msol, filtered_db=filtered_db)
sum(var_filtered) # [Msol]
```
2.9388306102361355e9
By setting the keyword `cell=false`, only the cell-centres within the defined region are taken into account (as in the calculations in the previous section).
```julia
density = 3. /gas.scale.Msol_pc3 # in code units
sub_region = subregion(gas, :cylinder, radius=3., height=2., center=[:boxcenter], range_unit=:kpc, cell=false, verbose=false )
filtered_db = @filter sub_region.data :rho >= density
var_filtered = getvar(gas, :mass, :Msol, filtered_db=filtered_db)
sum(var_filtered)
```
2.750632450062189e9
## Extend the Data Table
Add costum columns/variables to the data that can be automatically processed in some functions:
(note: to take advantage of the Mera unit management, store new data in code-units)
```julia
# calculate the Mach number in each cell
mach = getvar(gas, :mach);
```
```julia
# add the extracted Mach number (1dim-array) to the data in the object "gas"
# the array has the same length and order (rows/cells) as in the data table
# push a column at the end of the table:
# transform(data-table, key => new-data)
gas.data = transform(gas.data, :mach => mach) # JuliaDB
```
Table with 849332 rows, 12 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
12 mach Float64
```julia
proj_z = projection(gas, :mach, xrange=[-8.,8.], yrange=[-8.,8.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc);
```
[Mera]: 2020-02-08T20:59:42.246
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.3333333 :: 0.6666667 ==> 16.0 [kpc] :: 32.0 [kpc]
ymin::ymax: 0.3333333 :: 0.6666667 ==> 16.0 [kpc] :: 32.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:mach, :sd)
100%|███████████████████████████████████████████████████| Time: 0:00:07
```julia
using PyPlot
imshow( ( permutedims(proj_z.maps[:mach]) ), origin="lower", extent=proj_z.cextent)
colorbar();
```

Remove the column :mach from the table:
```julia
gas.data = select(gas.data, Not(:mach)) # select all columns, not :mach
```
Table with 849332 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
## Masking
Many functions in **MERA** provide the opportunity to use a mask on selected data without changing the content in the data table. Here we present several methods to prepare a mask and apply it to some functions. A created mask is an array of type: `MaskType`, which can be Array{Bool,1} or BitArray{1}. A masked cell/row corresponds to a **false**.
#### Version 1: External Function
Create an array which represents the cells with the selected condition by true.
The function checks if the following requirement is true or false for each row/cell in the data table:
```julia
function ftest(value)
density = (4. / gas.scale.Msol_pc3)
if value < density
return true
else
return false
end
end
mask_v1 = map(row->ftest(row.rho), gas.data);
println( length(mask_v1) )
println( typeof(mask_v1) )
```
849332
Array{Bool,1}
#### Version 2: Short Syntax
##### Example 1
```julia
mask_v2 = map(row->row.rho < 4. / gas.scale.Msol_pc3, gas.data);
println( length(mask_v2) )
println( typeof(mask_v2) )
```
849332
Array{Bool,1}
##### Example 2
```julia
mask_v2b = getvar(gas, :rho, :Msol_pc3) .> 1. ;
println( length(mask_v2b) )
println( typeof(mask_v2b) )
```
849332
BitArray{1}
#### Version 3: Longer Syntax
```julia
rho_array = select(gas.data, :rho);
mask_v3 = rho_array .< 1. / gas.scale.Msol_pc3;
println( length(mask_v3) )
println( typeof(mask_v3) )
```
849332
BitArray{1}
### Some Functions With Masking Functionality
The masked rows are not considered in the calculations (mask-element = false ).
### Examples
### Total Mass
```julia
mask = map(row->row.rho < 1. / gas.scale.Msol_pc3, gas.data);
mtot_masked = msum(gas, :Msol, mask=mask)
mtot = msum(gas, :Msol)
println()
println( "Gas Mtot masked: ", mtot_masked , " Msol" )
println( "Gas Mtot: ", mtot , " Msol" )
println()
```
Gas Mtot masked: 1.336918953133308e10 Msol
Gas Mtot: 3.0968754148332745e10 Msol
```julia
mask = map(row->row.birth < 100. / particles.scale.Myr, particles.data);
mtot_masked = msum(particles, :Msol, mask=mask)
mtot = msum(particles, :Msol)
println()
println( "Particles Mtot masked: ", mtot_masked , " Msol" )
println( "Particles Mtot: ", mtot , " Msol" )
println()
```
Particles Mtot masked: 1.4537556611888414e7 Msol
Particles Mtot: 5.804426008528437e9 Msol
```julia
mask = map(row->row.mass_cl < 1e6 / clumps.scale.Msol, clumps.data);
mtot_masked = msum(clumps, :Msol, mask=mask)
mtot = msum(clumps, :Msol)
println()
println( "Clumps Mtot masked: ", mtot_masked , " Msol" )
println( "Clumps Mtot: ", mtot , " Msol" )
println()
```
Clumps Mtot masked: 2.926390055686605e7 Msol
Clumps Mtot: 1.3743280681841677e10 Msol
### Center-Of-Mass
```julia
mask = map(row->row.rho < 100. / gas.scale.nH, gas.data);
com_gas_masked = center_of_mass(gas, :kpc, mask=mask)
com_gas = center_of_mass(gas, :kpc)
println()
println( "Gas COM masked: ", com_gas_masked , " kpc" )
println( "Gas COM: ", com_gas , " kpc" )
println()
```
Gas COM masked: (23.632781376611646, 24.017935187730938, 24.078280687627124) kpc
Gas COM: (23.47221401632259, 23.93931869865653, 24.08483637116779) kpc
```julia
mask = map(row->row.birth < 100. / particles.scale.Myr, particles.data);
com_particles_masked = center_of_mass(particles, :kpc, mask=mask)
com_particles = center_of_mass(particles, :kpc)
println()
println( "Particles COM masked: ", com_particles_masked , " kpc" )
println( "Particles COM: ", com_particles , " kpc" )
println()
```
Particles COM masked: (22.766374936557934, 24.817294529838456, 24.020065595650212) kpc
Particles COM: (22.891354761211332, 24.174147282680273, 24.003205056545575) kpc
```julia
# calculate joint center-of-mass from gas and particles
mask1 = map(row->row.rho < 100. / gas.scale.nH, gas.data); # mask for the hydro data
mask2 = map(row->row.birth < 100. / particles.scale.Myr, particles.data); # mask for the particle data
println( "Joint COM (Gas + Particles) masked: ", center_of_mass([gas,particles], :kpc, mask=[mask1, mask2]) , " kpc" )
println( "Joint COM (Gas + Particles): ", center_of_mass([gas,particles], :kpc) , " kpc" )
```
Joint COM (Gas + Particles) masked: (23.632014753139174, 24.01864248583754, 24.078229177095928) kpc
Joint COM (Gas + Particles): (23.380528865533876, 23.976384982693947, 24.07195135758772) kpc
```julia
mask = map(row->row.mass_cl < 1e6 / clumps.scale.Msol, clumps.data);
com_clumps_masked = center_of_mass(clumps, mask=mask)
com_clumps = center_of_mass(clumps)
println()
println( "Clumps COM masked:", com_clumps_masked .* clumps.scale.kpc, " kpc" )
println( "Clumps COM: ", com_clumps .* clumps.scale.kpc, " kpc" )
println()
```
Clumps COM masked:(22.979676622296815, 23.22447986984898, 24.11056806473746) kpc
Clumps COM: (23.135765457064576, 23.741712325649264, 24.0050127185862) kpc
### Bulk-Velocity
```julia
mask = map(row->row.rho < 100. / gas.scale.nH, gas.data);
bv_gas_masked = bulk_velocity(gas, :km_s, mask=mask)
bv_gas = bulk_velocity(gas, :km_s)
println()
println( "Gas bulk velocity masked: ", bv_gas_masked , " km/s" )
println( "Gas bulk velocity: ", bv_gas , " km/s" )
println()
```
Gas bulk velocity masked: (-0.046336703401138456, -6.60993479840688, -1.000280146674773) km/s
Gas bulk velocity: (-1.1999253584798182, -10.678485153330122, -0.44038538452508785) km/s
```julia
mask = map(row->row.birth < 100. / particles.scale.Myr, particles.data);
bv_particles_masked = bulk_velocity(particles, :km_s, mask=mask)
bv_particles = bulk_velocity(particles, :km_s)
println()
println( "Particles bulk velocity masked: ", bv_particles_masked , " km/s" )
println( "Particles bulk velocity: ", bv_particles , " km/s" )
println()
```
Particles bulk velocity masked: (-27.702254113836513, -7.532075727552787, -1.3273993940211153) km/s
Particles bulk velocity: (-11.623422700314535, -18.440572802490234, -0.3291927731417528) km/s
### Weighted Statistics
(It is also possible to use the mask within the `getvar` function)
```julia
maskgas = map(row->row.rho < 100. / gas.scale.nH, gas.data);
maskpart = map(row->row.birth < 100. / particles.scale.Myr, particles.data);
maskclump = map(row->row.mass_cl < 1e7 / clumps.scale.Msol, clumps.data);
stats_gas_masked = wstat( getvar(gas, :vx, :km_s), weight=getvar(gas, :mass ), mask=maskgas);
stats_particles_masked = wstat( getvar(particles, :vx, :km_s), weight=getvar(particles, :mass ), mask=maskpart);
stats_clumps_masked = wstat( getvar(clumps, :peak_x, :kpc ), weight=getvar(clumps, :mass_cl), mask=maskclump) ;
println( "Gas <vx>_cells masked : ", stats_gas_masked.mean, " km/s (mass weighted)" )
println( "Particles <vx>_particles masked : ", stats_particles_masked.mean, " km/s (mass weighted)" )
println( "Clumps <peak_x>_clumps masked : ", stats_clumps_masked.mean, " kpc (mass weighted)" )
println()
```
Gas <vx>_cells masked : -0.04633670340114798 km/s (mass weighted)
Particles <vx>_particles masked : -27.702254113836517 km/s (mass weighted)
Clumps <peak_x>_clumps masked : 22.907689025275953 kpc (mass weighted)
```julia
stats_gas = wstat( getvar(gas, :vx, :km_s), weight=getvar(gas, :mass ));
stats_particles = wstat( getvar(particles, :vx, :km_s), weight=getvar(particles, :mass ));
stats_clumps = wstat( getvar(clumps, :peak_x, :kpc ), weight=getvar(clumps, :mass_cl)) ;
println( "Gas <vx>_allcells : ", stats_gas.mean, " km/s (mass weighted)" )
println( "Particles <vx>_allparticles : ", stats_particles.mean, " km/s (mass weighted)" )
println( "Clumps <peak_x>_allclumps : ", stats_clumps.mean, " kpc (mass weighted)" )
println()
```
Gas <vx>_allcells : -1.199925358479736 km/s (mass weighted)
Particles <vx>_allparticles : -11.623422700314544 km/s (mass weighted)
Clumps <peak_x>_allclumps : 23.13576545706458 kpc (mass weighted)
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 42772 | # 6. Hydro: Projections
## Load The Data
```julia
using Mera
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
gas = gethydro(info, lmax=10, smallr=1e-5);
```
┌ Info: Precompiling Mera [02f895e8-fdb1-4346-8fe6-c721699f5126]
└ @ Base loading.jl:1273
*__ __ _______ ______ _______
| |_| | | _ | | _ |
| | ___| | || | |_| |
| | |___| |_||_| |
| | ___| __ | |
| ||_|| | |___| | | | _ |
|_| |_|_______|___| |_|__| |__|
[Mera]: 2020-02-18T22:27:12.257
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get hydro data: 2020-02-18T22:27:49.16
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:03:04
Memory used for data table :409.5426664352417 MB
-------------------------------------------------------
```julia
gas.data
```
Table with 4879946 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
## Projection of Predefined Quantities
See the possible variables:
```julia
projection()
```
Predefined vars for projections:
------------------------------------------------
=====================[gas]:=====================
-all the non derived hydro vars-
:cpu, :level, :rho, :cx, :cy, :cz, :vx, :vy, :vz, :p, var6,...
further possibilities: :rho, :density, :ρ
-derived hydro vars-
:x, :y, :z
:sd or :Σ or :surfacedensity
:mass, :cellsize, :freefall_time
:cs, :mach, :jeanslength, :jeansnumber
==================[particles]:==================
all the non derived vars:
:cpu, :level, :id, :family, :tag
:x, :y, :z, :vx, :vy, :vz, :mass, :birth, :metal....
-derived particle vars-
:age
==============[gas or particles]:===============
:v, :ekin
squared => :vx2, :vy2, :vz2
velocity dispersion => σx, σy, σz, σ
related to a given center:
---------------------------
:vr_cylinder, vr_sphere (radial components)
:vϕ_cylinder, :vθ
squared => :vr_cylinder2, :vϕ_cylinder2
velocity dispersion => σr_cylinder, σϕ_cylinder
2d maps (not projected):
:r_cylinder
:ϕ
------------------------------------------------
## Projection of a Single Quantity in Different Directions (z,y,x)
Here we project the surface density in the z-direction of the data within a particular vertical range (domain=[0:1]) onto a grid corresponding to the maximum loaded level.
Pass any object of `HydroDataType` (here: "gas") to the `projection`-function and select a variable by a Symbol (here: :sd = :surfacedensity = :Σ in Msol/pc^3)
```julia
proj_z = projection(gas, :sd, unit=:Msol_pc2, zrange=[0.45,0.55])
proj_z = projection(gas, :Σ, unit=:Msol_pc2, zrange=[0.45,0.55], verbose=false)
proj_z = projection(gas, :surfacedensity, unit=:Msol_pc2, zrange=[0.45,0.55], verbose=false)
proj_z = projection(gas, :sd, :Msol_pc2, zrange=[0.45,0.55], verbose=false) # The keyword "unit" (singular) can be omit if the following order is preserved: data-object, quantity, unit.
proj_x = projection(gas, :sd, :Msol_pc2, direction = :x, zrange=[0.45,0.55], verbose=false); # Project the surface density in x-direction
```
[Mera]: 2020-02-12T12:18:14.842
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:sd,)
100%|███████████████████████████████████████████████████| Time: 0:01:07
100%|███████████████████████████████████████████████████| Time: 0:01:02
100%|███████████████████████████████████████████████████| Time: 0:00:57
100%|███████████████████████████████████████████████████| Time: 0:00:57
100%|███████████████████████████████████████████████████| Time: 0:00:56
### Select a Range Related to a Center
See also in the documentation for: load data by selection
```julia
cv = (gas.boxlen / 2.) * gas.scale.kpc # provide the box-center in kpc
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[cv,cv,cv], range_unit=:kpc);
```
[Mera]: 2020-02-12T12:23:18.582
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
100%|███████████████████████████████████████████████████| Time: 0:00:55
Use the short notation for the box center :bc or :boxcenter for all dimensions (x,y,z):
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc);
```
[Mera]: 2020-02-12T12:24:15.893
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
100%|███████████████████████████████████████████████████| Time: 0:00:53
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:bc], range_unit=:kpc);
```
[Mera]: 2020-02-12T12:25:09.001
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
100%|███████████████████████████████████████████████████| Time: 0:00:52
Use the box center notation for individual dimensions, here x,z:
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:bc, 24., :bc], range_unit=:kpc);
```
[Mera]: 2020-02-12T12:26:03.671
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
100%|███████████████████████████████████████████████████| Time: 0:00:53
### Get Multiple Quantities
Get several quantities with one function call by passing an array containing the selected variables (at least one entry). The keyword name for the units is now in plural.
```julia
proj1_x = projection(gas, [:sd], units=[:Msol_pc2],
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2020-02-12T12:26:57.186
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
100%|███████████████████████████████████████████████████| Time: 0:00:53
Pass an array containing several quantities to process and their corresponding units:
```julia
proj1_z = projection(gas, [:sd, :vx], units=[:Msol_pc2, :km_s],
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2020-02-12T12:27:50.658
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd, :vx)
100%|███████████████████████████████████████████████████| Time: 0:00:59
The function can be called without any keywords by preserving the following order: dataobject, variables, units
```julia
proj1_z = projection(gas, [:sd , :vx], [:Msol_pc2, :km_s],
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2020-02-12T12:28:49.928
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd, :vx)
100%|███████████████████████████████████████████████████| Time: 0:00:56
If all selected variables should be of the same unit use the following arguments: dataobject, array of quantities, unit (no array needed)
```julia
projvel_z = projection(gas, [:vx, :vy, :vz], :km_s,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2020-02-12T12:29:46.23
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:vx, :vy, :vz, :sd)
100%|███████████████████████████████████████████████████| Time: 0:00:55
## Function Output
List the fields of the assigned object:
```julia
propertynames(proj1_z)
```
(:maps, :maps_unit, :maps_lmax, :maps_mode, :lmax_projected, :lmin, :lmax, :ranges, :extent, :cextent, :ratio, :boxlen, :smallr, :smallc, :scale, :info)
The projected 2D maps are stored in a dictionary:
```julia
proj1_z.maps
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 2 entries:
:sd => [2.42108 2.42108 … 3.06809 3.06809; 2.42108 2.42108 … 3.06809 3.06809;…
:vx => [48.3311 48.3311 … 35.0161 35.0161; 48.3311 48.3311 … 35.0161 35.0161;…
The maps can be accessed by giving the name of the dictionary:
```julia
proj1_z.maps[:sd]
```
428×86 Array{Float64,2}:
2.42108 2.42108 2.42108 2.76423 … 3.80613 3.06809 3.06809 3.06809
2.42108 2.42108 2.42108 2.76423 3.80613 3.06809 3.06809 3.06809
2.43323 2.43323 2.43323 2.83905 3.77978 3.04769 3.04769 3.04769
2.43323 2.43323 2.43323 2.83905 3.77978 3.04769 3.04769 3.04769
2.43323 2.43323 2.43323 2.83612 3.77978 3.04769 3.04769 3.04769
2.43323 2.43323 2.43323 2.83612 … 3.77978 3.04769 3.04769 3.04769
2.61724 2.61724 2.61724 2.78421 3.38093 2.59978 2.59978 2.59978
2.61724 2.61724 2.61724 2.78421 3.38093 2.59978 2.59978 2.59978
2.61724 2.61724 2.61724 2.78048 3.38093 2.59978 2.59978 2.59978
2.61724 2.61724 2.61724 2.78048 3.38093 2.59978 2.59978 2.59978
2.65948 2.65948 2.65948 2.92033 … 3.26695 2.56391 2.56391 2.56391
2.65948 2.65948 2.65948 2.92033 3.26695 2.56391 2.56391 2.56391
2.65948 2.65948 2.65948 2.9154 3.26695 2.56391 2.56391 2.56391
⋮ ⋱ ⋮
3.64783 3.62431 3.62431 3.69296 2.64986 2.58555 2.58555 2.58555
3.64783 3.62431 3.62431 3.69296 2.64986 2.58555 2.58555 2.58555
4.06584 4.06584 4.06584 4.25253 2.5403 2.54319 2.54319 2.54319
4.06584 4.06584 4.06584 4.25253 2.5403 2.54319 2.54319 2.54319
4.06584 4.06584 4.06584 4.36169 … 2.5403 2.54319 2.54319 2.54319
4.06584 4.06584 4.06584 4.36169 2.5403 2.54319 2.54319 2.54319
5.43946 5.43946 5.43946 5.56363 2.45995 2.45782 2.45782 2.45782
5.43946 5.43946 5.43946 5.56363 2.45995 2.45782 2.45782 2.45782
5.43946 5.43946 5.43946 5.39163 2.45995 2.45782 2.45782 2.45782
5.43946 5.43946 5.43946 5.39163 … 2.45995 2.45782 2.45782 2.45782
5.68876 5.68876 5.68876 5.8404 2.41942 2.43411 2.43411 2.43411
5.68876 5.68876 5.68876 2.62535 2.41942 2.43411 2.43411 2.43411
The units of the maps are stored in:
```julia
proj1_z.maps_unit
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 2 entries:
:sd => :Msol_pc2
:vx => :km_s
Projections on a different grid size (see subject below):
```julia
proj1_z.maps_lmax
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 0 entries
The following fields are helpful for further calculations or plots.
```julia
proj1_z.ranges # normalized to the domain=[0:1]
```
6-element Array{Float64,1}:
0.29166666666647767
0.7083333333328743
0.29166666666647767
0.7083333333328743
0.4583333333330363
0.5416666666663156
```julia
proj1_z.extent # ranges in code units
```
4-element Array{Float64,1}:
13.96875
34.03125
21.984375
26.015625
```julia
proj1_z.cextent # ranges in code units relative to a given center (by default: box center)
```
4-element Array{Float64,1}:
-10.03125
10.03125
-2.015625
2.015625
```julia
proj1_z.ratio # the ratio between the two ranges
```
4.976744186046512
## Plot Maps with Python
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false)
proj_x = projection(gas, :sd, :Msol_pc2,
zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
direction = :x);
```
100%|███████████████████████████████████████████████████| Time: 0:01:02
100%|███████████████████████████████████████████████████| Time: 0:01:00
Python functions can be directly called in Julia, which gives the opportunity, e.g. to use the Matplotlib library.
```julia
using PyPlot
using ColorSchemes
cmap = ColorMap(ColorSchemes.lajolla.colors) # See http://www.fabiocrameri.ch/colourmaps.php
cmap2 = ColorMap(ColorSchemes.roma.colors)
```

```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

Project a specific spatial range and plot the axes of the map relative to the box-center (given by keyword: data_center):
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[24.,24.,24.], data_center_unit=:kpc)
proj_x = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[24.,24.,24.], data_center_unit=:kpc,
direction = :x);
```
100%|███████████████████████████████████████████████████| Time: 0:00:54
100%|███████████████████████████████████████████████████| Time: 0:00:51
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

Plot the axes of the map relative to the map-center (given by keyword: data_center):
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[19.,19.,24.], data_center_unit=:kpc)
proj_x = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[19.,19.,24.], data_center_unit=:kpc,
direction = :x);
```
100%|███████████████████████████████████████████████████| Time: 0:01:10
100%|███████████████████████████████████████████████████| Time: 0:01:00
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

## Projections of Derived Kinematic Data
#### Use quantities in cartesian coordinates:
Project the following derived data
(mass weighted by default): The absolute value of the velocity :v, the velocity dispersion :σ in different directions. The Julia language supports Unicode characters and can be inserted by e.g. "\sigma + tab-key" leading to: **σ**.
```julia
proj_z = projection(gas, [:v, :σ, :σx, :σy, :σz], :km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[24.,24.,24.], range_unit=:kpc);
```
[Mera]: 2020-02-18T22:49:54.49
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:v, :σ, :σx, :σy, :σz, :vx, :vx2, :vy, :vy2, :vz, :vz2, :v2, :sd)
100%|███████████████████████████████████████████████████| Time: 0:01:03
For the velocity dispersion additional maps are created to created the mass-weighted quantity:
E. g.: σx = sqrt( <vx^2> - < vx >^2 )
```julia
proj_z.maps
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 13 entries:
:sd => [0.000525384 0.000525384 … 0.000463458 0.000334485; 0.000525384 0.000…
:v => [10.9033 10.9033 … 9.28165 8.34605; 10.9033 10.9033 … 9.28165 8.34605…
:v2 => [0.245404 0.245404 … 0.193833 0.163449; 0.245404 0.245404 … 0.193833 …
:vx => [0.11951 0.11951 … -0.0700017 -0.0384127; 0.11951 0.11951 … -0.070001…
:vx2 => [0.122347 0.122347 … 0.111339 0.0775909; 0.122347 0.122347 … 0.111339…
:vy => [0.0445661 0.0445661 … -0.00514768 -0.00554146; 0.0445661 0.0445661 ……
:vy2 => [0.0331066 0.0331066 … 0.019046 0.018845; 0.0331066 0.0331066 … 0.019…
:vz => [-0.0999134 -0.0999134 … -0.0370643 -0.024236; -0.0999134 -0.0999134 …
:vz2 => [0.0899502 0.0899502 … 0.0634475 0.0670127; 0.0899502 0.0899502 … 0.0…
:σ => [30.6004 30.6004 … 27.3378 25.1633; 30.6004 30.6004 … 27.3378 25.1633…
:σx => [21.5567 21.5567 … 21.3939 18.0916; 21.5567 21.5567 … 21.3939 18.0916…
:σy => [11.5681 11.5681 … 9.04357 8.99465; 11.5681 11.5681 … 9.04357 8.99465…
:σz => [18.5437 18.5437 … 16.3378 16.9008; 18.5437 18.5437 … 16.3378 16.9008…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 13 entries:
:sd => :standard
:v => :km_s
:v2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vz => :standard
:vz2 => :standard
:σ => :km_s
:σx => :km_s
:σy => :km_s
:σz => :km_s
```julia
usedmemory(proj_z);
```
Memory used: 18.436 MB
```julia
figure(figsize=(10, 5.5))
subplot(2, 3, 1)
title("v [km/s]")
imshow( (permutedims(proj_z.maps[:v]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 2)
title("σ [km/s]")
imshow( (permutedims(proj_z.maps[:σ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 4)
title("σx [km/s]")
imshow( (permutedims(proj_z.maps[:σx]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 5)
title("σy [km/s]")
imshow( permutedims(proj_z.maps[:σy]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 6)
title("σz [km/s]")
imshow( permutedims(proj_z.maps[:σz]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

#### Use quantities in cylindrical coordinates:
#### Face-on disc (z-direction)
For the cylindrical or spherical components of a quantity, the center of the coordinate system is used (keywords: data_center = center default) and can be given with the keyword "data_center" and its units with "data_center_unit". Additionally, the quantities that are based on cartesian coordinates can be given.
```julia
proj_z = projection(gas, [:v, :σ, :σx, :σy, :ϕ, :r_cylinder, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
units=[:km_s,:km_s,:km_s, :km_s, :standard, :kpc, :km_s, :km_s, :km_s, :km_s],
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
data_center=[24.,24.,24.],
data_center_unit=:kpc);
```
[Mera]: 2020-02-18T23:17:14.519
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:v, :σ, :σx, :σy, :ϕ, :r_cylinder, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder, :vx, :vx2, :vy, :vy2, :v2, :vr_cylinder2, :vϕ_cylinder2, :sd)
100%|███████████████████████████████████████████████████| Time: 0:01:08
```julia
proj_z.maps
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 18 entries:
:r_cylinder => [14.0758 14.0427 … 14.1201 14.1534; 14.0427 14.0096 … 14.087…
:sd => [0.000525384 0.000525384 … 0.000463458 0.000334485; 0.000525…
:v => [8.72263 8.72263 … 7.42532 6.67684; 8.72263 8.72263 … 7.4253…
:v2 => [0.196323 0.196323 … 0.155066 0.130759; 0.196323 0.196323 … …
:vr_cylinder => [-6.0864 -6.0864 … 2.38666 1.2034; -6.0864 -6.0864 … 2.38666…
:vr_cylinder2 => [0.105049 0.105049 … 0.0620751 0.0537682; 0.105049 0.105049 …
:vx => [0.0956079 0.0956079 … -0.0560013 -0.0307302; 0.0956079 0.09…
:vx2 => [0.097878 0.097878 … 0.0890713 0.0620727; 0.097878 0.097878 …
:vy => [0.0356529 0.0356529 … -0.00411814 -0.00443317; 0.0356529 0.…
:vy2 => [0.0264853 0.0264853 … 0.0152368 0.015076; 0.0264853 0.02648…
:vϕ_cylinder => [2.78004 2.78004 … 3.22947 2.23274; 2.78004 2.78004 … 3.2294…
:vϕ_cylinder2 => [0.0193141 0.0193141 … 0.042233 0.0233806; 0.0193141 0.01931…
:σ => [27.7151 27.7151 … 24.7319 22.753; 27.7151 27.7151 … 24.7319…
:σr_cylinder => [20.3637 20.3637 … 16.1627 15.1579; 20.3637 20.3637 … 16.162…
:σx => [19.5341 19.5341 … 19.2232 16.2129; 19.5341 19.5341 … 19.223…
:σy => [10.4127 10.4127 … 8.08995 8.04638; 10.4127 10.4127 … 8.0899…
:σϕ_cylinder => [8.67895 8.67895 … 13.0835 9.77518; 8.67895 8.67895 … 13.083…
:ϕ => [3.92699 3.92463 … 2.35306 2.35073; 3.92935 3.92699 … 2.3507…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 18 entries:
:r_cylinder => :kpc
:sd => :standard
:v => :km_s
:v2 => :standard
:vr_cylinder => :km_s
:vr_cylinder2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vϕ_cylinder => :km_s
:vϕ_cylinder2 => :standard
:σ => :km_s
:σr_cylinder => :km_s
:σx => :km_s
:σy => :km_s
:σϕ_cylinder => :km_s
:ϕ => :radian
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("Radius [kpc]")
imshow( permutedims(proj_z.maps[:r_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_z.maps[:vr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmin=-20.,vmax=20.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_z.maps[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 4)
title("ϕ-angle ")
imshow( permutedims(proj_z.maps[:ϕ]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( permutedims(proj_z.maps[:σr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( permutedims(proj_z.maps[:σϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( permutedims(proj_z.maps[:σ]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( permutedims(proj_z.maps[:σx] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( permutedims(proj_z.maps[:σy] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

## Project on a Coarser Grid
The default is the projection on the maximum loaded grid level (always provided in the output). Choose a smaller level with the keyword `lmax` to project on a coarser grid in addition. Higher-resolution data is averaged within each coarser grid-cell (default: mass-weighted). By default, the data is assumed to be in the center of the simulation box.
```julia
proj_z = projection(gas, [:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
:km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
lmax=8);
```
[Mera]: 2020-02-18T23:18:44.018
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder, :vx, :vx2, :vy, :vy2, :vz, :vz2, :v2, :vr_cylinder2, :vϕ_cylinder2, :sd)
100%|███████████████████████████████████████████████████| Time: 0:01:08
remap from:
level 10 => 8
cellsize 46.88 [pc] => 187.5 [pc]
pixels (428, 428) => (107, 107)
The projection onto the maximum loaded grid is always provided:
```julia
proj_z.maps_lmax
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 19 entries:
:sd => [0.000525384 0.000545269 … 0.000475553 0.000334485; 0.000532…
:v => [7.26886 7.32994 … 7.73366 5.56403; 7.30578 7.37137 … 8.9885…
:v2 => [0.163603 0.166415 … 0.210983 0.108966; 0.166587 0.168972 … …
:vr_cylinder => [-5.072 -4.65663 … 2.60367 1.00283; -5.02593 -4.4874 … 2.140…
:vr_cylinder2 => [0.0875409 0.0826628 … 0.0646939 0.0448068; 0.0884293 0.0811…
:vx => [0.0796732 0.0788819 … -0.0691436 -0.0256085; 0.0809557 0.07…
:vx2 => [0.081565 0.0804544 … 0.136752 0.0517273; 0.0845953 0.082583…
:vy => [0.0297108 0.0211165 … -0.0132175 -0.0036943; 0.0278214 0.01…
:vy2 => [0.022071 0.0251372 … 0.0168816 0.0125634; 0.0229327 0.02711…
:vz => [-0.0666089 -0.0671458 … -0.0188721 -0.0161574; -0.0657326 -…
:vz2 => [0.0599668 0.0608235 … 0.0573498 0.0446751; 0.0590593 0.0592…
:vϕ_cylinder => [2.3167 2.65081 … 3.9351 1.86062; 2.49477 2.91954 … 5.93535 …
:vϕ_cylinder2 => [0.0160951 0.0229288 … 0.0889397 0.0194838; 0.0190986 0.0284…
:σ => [25.5083 25.727 … 29.1109 20.9191; 25.7482 25.928 … 33.7281 …
:σr_cylinder => [18.7273 18.2695 … 16.4746 13.8445; 18.8414 18.1389 … 13.727…
:σx => [17.9845 17.8664 … 23.8221 14.8194; 18.319 18.1022 … 25.8056…
:σy => [9.54527 10.3042 … 8.47594 7.3461; 9.7614 10.7401 … 15.0491 …
:σz => [15.4527 15.5615 … 15.655 13.8198; 15.3422 15.3681 … 16.8782…
:σϕ_cylinder => [7.99022 9.56921 … 19.1564 8.96219; 8.7122 10.678 … 26.5011 …
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 19 entries:
:sd => :standard
:v => :km_s
:v2 => :standard
:vr_cylinder => :km_s
:vr_cylinder2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vz => :standard
:vz2 => :standard
:vϕ_cylinder => :km_s
:vϕ_cylinder2 => :standard
:σ => :km_s
:σr_cylinder => :km_s
:σx => :km_s
:σy => :km_s
:σz => :km_s
:σϕ_cylinder => :km_s
The projection onto a coarser grid (fieldname: `maps_lmax`) is stored in a dictionary into the field `maps_lmax`:
```julia
proj_z.lmax_projected
```
8
```julia
proj_z.maps_lmax
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 19 entries:
:sd => [0.000525384 0.000545269 … 0.000475553 0.000334485; 0.000532…
:v => [7.26886 7.32994 … 7.73366 5.56403; 7.30578 7.37137 … 8.9885…
:v2 => [0.163603 0.166415 … 0.210983 0.108966; 0.166587 0.168972 … …
:vr_cylinder => [-5.072 -4.65663 … 2.60367 1.00283; -5.02593 -4.4874 … 2.140…
:vr_cylinder2 => [0.0875409 0.0826628 … 0.0646939 0.0448068; 0.0884293 0.0811…
:vx => [0.0796732 0.0788819 … -0.0691436 -0.0256085; 0.0809557 0.07…
:vx2 => [0.081565 0.0804544 … 0.136752 0.0517273; 0.0845953 0.082583…
:vy => [0.0297108 0.0211165 … -0.0132175 -0.0036943; 0.0278214 0.01…
:vy2 => [0.022071 0.0251372 … 0.0168816 0.0125634; 0.0229327 0.02711…
:vz => [-0.0666089 -0.0671458 … -0.0188721 -0.0161574; -0.0657326 -…
:vz2 => [0.0599668 0.0608235 … 0.0573498 0.0446751; 0.0590593 0.0592…
:vϕ_cylinder => [2.3167 2.65081 … 3.9351 1.86062; 2.49477 2.91954 … 5.93535 …
:vϕ_cylinder2 => [0.0160951 0.0229288 … 0.0889397 0.0194838; 0.0190986 0.0284…
:σ => [25.5083 25.727 … 29.1109 20.9191; 25.7482 25.928 … 33.7281 …
:σr_cylinder => [18.7273 18.2695 … 16.4746 13.8445; 18.8414 18.1389 … 13.727…
:σx => [17.9845 17.8664 … 23.8221 14.8194; 18.319 18.1022 … 25.8056…
:σy => [9.54527 10.3042 … 8.47594 7.3461; 9.7614 10.7401 … 15.0491 …
:σz => [15.4527 15.5615 … 15.655 13.8198; 15.3422 15.3681 … 16.8782…
:σϕ_cylinder => [7.99022 9.56921 … 19.1564 8.96219; 8.7122 10.678 … 26.5011 …
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("v [km/s]")
imshow( permutedims(proj_z.maps_lmax[:v] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_z.maps_lmax[:vr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmin=-20.,vmax=20.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_z.maps_lmax[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 4)
title("σz [km/s]")
imshow( permutedims(proj_z.maps_lmax[:σz] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( permutedims(proj_z.maps_lmax[:σr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( permutedims(proj_z.maps_lmax[:σϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( permutedims(proj_z.maps_lmax[:σ]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( permutedims(proj_z.maps_lmax[:σx] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( permutedims(proj_z.maps_lmax[:σy] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

## Remap a Projected Data onto a Coarser Grid
Pass the object with the projected data to the function `remap` and the level of the coarser grid:
```julia
proj_zlmax = remap(proj_z, 6, weighting=:mass);
```
remap from:
level 10 => 6
cellsize 46.88 [pc] => 750.0 [pc]
pixels (428, 428) => (27, 27)
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("v [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:v] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:vr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent, vmin=-20.,vmax=20.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 4)
title("log10(σz) [km/s]")
imshow( log10.(permutedims(proj_zlmax.maps_lmax[:σz]) ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 5)
title("log10(σr) [km/s]")
imshow( log10.(permutedims(proj_zlmax.maps_lmax[:σr_cylinder] )), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 6)
title("log10(σϕ) [km/s]")
imshow( log10.(permutedims(proj_zlmax.maps_lmax[:σϕ_cylinder] )), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 7)
title("log10(σ) [km/s]")
imshow( log10.(permutedims(proj_zlmax.maps_lmax[:σ]) ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 8)
title("log10(σx) [km/s]")
imshow( log10.(permutedims(proj_zlmax.maps_lmax[:σx] )), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 9)
title("log10(σy) [km/s]")
imshow( log10.(permutedims(proj_zlmax.maps_lmax[:σy] )), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar();
```

## Projection of Thermal Data
The the sound speed is calculated from the loaded adiabatic index (from the hydro files):
```julia
proj_z = projection(gas, :cs, :km_s, zrange=[0.45,0.55], xrange=[0.3, 0.6], yrange=[0.3, 0.6])
proj_x = projection(gas, :cs, :km_s, zrange=[0.45,0.55], xrange=[0.3, 0.6], yrange=[0.3, 0.6], direction=:x);
```
[Mera]: 2020-02-18T22:54:00.33
domain:
xmin::xmax: 0.3 :: 0.6 ==> 14.4 [kpc] :: 28.8 [kpc]
ymin::ymax: 0.3 :: 0.6 ==> 14.4 [kpc] :: 28.8 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:cs, :sd)
100%|███████████████████████████████████████████████████| Time: 0:00:58
[Mera]: 2020-02-18T22:54:58.629
domain:
xmin::xmax: 0.3 :: 0.6 ==> 14.4 [kpc] :: 28.8 [kpc]
ymin::ymax: 0.3 :: 0.6 ==> 14.4 [kpc] :: 28.8 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:cs, :sd)
100%|███████████████████████████████████████████████████| Time: 0:00:55
```julia
figure(figsize=(10, 3.5))
subplot(1, 2, 1)
im = imshow( log10.(permutedims(proj_z.maps[:cs]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(c_s) \ [km \ s^{-1}]}")
subplot(1, 2, 2)
im = imshow( log10.(permutedims(proj_x.maps[:cs]) ), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(c_s) \ [km \ s^{-1}]}",orientation="horizontal", pad=0.2);
```

Change the adiabatic index in the field `gas.info.gamma` to use a different value in the projection calculation.
## Projection of Masked Data
Mask higher densities by creating a Bool-array where the lower density cells correspond to false entries:
```julia
density = 4e-3 / gas.scale.Msol_pc3
mask = map(row->row.rho < density, gas.data);
```
Pass the mask to the projection function:
```julia
proj_z = projection(gas, :sd, :Msol_pc2, zrange=[0.45,0.55], mask=mask)
proj_x = projection(gas, :sd, :Msol_pc2, zrange=[0.45,0.55], mask=mask, direction=:x);
```
[Mera]: 2020-02-18T23:04:58.755
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:sd,)
:mask provided by function
100%|███████████████████████████████████████████████████| Time: 0:01:35
[Mera]: 2020-02-18T23:06:34.69
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:sd,)
:mask provided by function
100%|███████████████████████████████████████████████████| Time: 0:01:34
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 43224 | # 6. Particles: Projections
## Load The Data
```julia
using Mera
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
particles = getparticles(info);
```
[Mera]: 2020-02-18T23:09:51.793
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get particle data: 2020-02-18T23:10:01.886
Key vars=(:level, :x, :y, :z, :id)
Using var(s)=(1, 2, 3, 4, 5) = (:vx, :vy, :vz, :mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...100%|████████████████████████████████████| Time: 0:00:04
Found 5.089390e+05 particles
Memory used for data table :34.947275161743164 MB
-------------------------------------------------------
```julia
particles.data
```
Table with 508939 rows, 10 columns:
Columns:
# colname type
────────────────────
1 level Int32
2 x Float64
3 y Float64
4 z Float64
5 id Int32
6 vx Float64
7 vy Float64
8 vz Float64
9 mass Float64
10 birth Float64
## Projection of Predefined Quantities
See the possible variables:
```julia
projection()
```
Predefined vars for projections:
------------------------------------------------
=====================[gas]:=====================
-all the non derived hydro vars-
:cpu, :level, :rho, :cx, :cy, :cz, :vx, :vy, :vz, :p, var6,...
further possibilities: :rho, :density, :ρ
-derived hydro vars-
:x, :y, :z
:sd or :Σ or :surfacedensity
:mass, :cellsize, :freefall_time
:cs, :mach, :jeanslength, :jeansnumber
==================[particles]:==================
all the non derived vars:
:cpu, :level, :id, :family, :tag
:x, :y, :z, :vx, :vy, :vz, :mass, :birth, :metal....
-derived particle vars-
:age
==============[gas or particles]:===============
:v, :ekin
squared => :vx2, :vy2, :vz2
velocity dispersion => σx, σy, σz, σ
related to a given center:
---------------------------
:vr_cylinder, vr_sphere (radial components)
:vϕ_cylinder, :vθ
squared => :vr_cylinder2, :vϕ_cylinder2
velocity dispersion => σr_cylinder, σϕ_cylinder
2d maps (not projected):
:r_cylinder
:ϕ
------------------------------------------------
## Projection of a Single Quantity in Different Directions (z,y,x)
Here we project the surface density in the z-direction of the data within a particular vertical range (domain=[0:1]) on a grid corresponding to level=9.
Pass any object of *PartDataType* (here: "particles") to the *projection*-function and select a variable by a Symbol (here: :sd = :surfacedensity = :Σ in Msol/pc^3)
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, lmax=9, zrange=[0.45,0.55])
proj_z = projection(particles, :Σ, unit=:Msol_pc2, lmax=9, zrange=[0.45,0.55], verbose=false)
proj_z = projection(particles, :surfacedensity, unit=:Msol_pc2, lmax=9,zrange=[0.45,0.55], verbose=false)
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9, zrange=[0.45,0.55], verbose=false) # The keyword "unit" (singular) can be omit if the following order is preserved: data-object, quantity, unit.
proj_x = projection(particles, :sd, :Msol_pc2, lmax=9, direction = :x, zrange=[0.45,0.55], verbose=false); # Project the surface density in x-direction
```
[Mera]: 2020-02-12T20:07:42.33
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.95 :: 1.0 ==> 45.6 [kpc] :: 48.0 [kpc]
Map data on given lmax: 9
xrange: 1 513
yrange: 1 513
zrange: 487 513
pixel-size: 93.75 [pc]
### Select a Range Related to a Center
See also in the documentation for: load data by selection
```julia
cv = (particles.boxlen / 2.) * particles.scale.kpc # provide the box-center in kpc
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[cv,cv,cv], range_unit=:kpc);
```
[Mera]: 2020-02-12T20:07:45.187
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
Use the short notation for the box center :bc or :boxcenter for all dimensions (x,y,z):
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc);
```
[Mera]: 2020-02-12T20:07:46.718
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:bc], range_unit=:kpc);
```
[Mera]: 2020-02-12T20:07:46.818
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
Use the box center notation for individual dimensions, here x,z:
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:bc, 24., :bc], range_unit=:kpc);
```
[Mera]: 2020-02-12T20:07:48.695
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
### Get Multiple Quantities
Get several quantities with one function call by passing an array containing the selected variables (at least one entry). The keyword name for the units is now in plural.
```julia
proj1_x = projection(particles, [:sd], units=[:Msol_pc2], lmax=9,
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2020-02-12T20:07:49.018
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
Pass an array containing several quantities to process and their corresponding units:
```julia
proj1_z = projection(particles, [:sd, :vx], units=[:Msol_pc2, :km_s], lmax=9,
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2020-02-12T20:07:49.132
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
The function can be called without any keywords by preserving the following order: dataobject, variables, units
```julia
proj1_z = projection(particles, [:sd , :vx], [:Msol_pc2, :km_s], lmax=9,
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2020-02-12T20:07:50.02
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
If all selected variables should be of the same unit use the following arguments: dataobject, array of quantities, unit (no array needed)
```julia
projvel_z = projection(particles, [:vx, :vy, :vz], :km_s, lmax=9,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2020-02-12T20:07:50.259
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
## Function Output
List the fields of the assigned object:
```julia
propertynames(proj1_z)
```
(:maps, :maps_unit, :maps_lmax, :maps_mode, :lmax_projected, :lmin, :lmax, :ref_time, :ranges, :extent, :cextent, :ratio, :boxlen, :scale, :info)
The projected 2D maps are stored in a dictionary:
```julia
proj1_z.maps
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 2 entries:
:sd => [1.29223 1.29223 … 1.29223 0.0; 2.58445 1.29223 … 0.0 0.0; … ; 3.87668…
:vx => [178.738 143.611 … 131.468 NaN; 96.6932 154.086 … NaN NaN; … ; -189.97…
The maps can be accessed by giving the name of the dictionary:
```julia
proj1_z.maps[:sd]
```
214×44 Array{Float64,2}:
1.29223 1.29223 1.29223 1.29223 … 0.0 1.29223 1.29223 0.0
2.58445 1.29223 2.58445 2.58445 1.29223 1.29223 0.0 0.0
0.0 1.29223 3.87668 2.58445 1.29223 0.0 0.0 0.0
1.29223 1.29223 2.58445 1.29223 0.0 1.29223 0.0 0.0
0.0 0.0 1.29223 2.58445 1.29223 0.0 1.29223 0.0
2.58445 2.58445 3.87668 1.29223 … 0.0 0.0 0.0 0.0
0.0 2.58445 0.0 2.58445 2.58445 0.0 0.0 0.0
1.29223 1.29223 6.46114 3.87668 3.87668 0.0 0.0 0.0
0.0 1.29223 1.29223 1.29223 0.0 2.58445 0.0 0.0
1.29223 2.58445 1.29223 3.87668 5.16891 2.58445 0.0 0.0
1.29223 0.0 1.29223 7.75336 … 0.0 2.58445 0.0 0.0
2.58445 2.58445 2.58445 3.87668 6.46114 0.0 1.29223 0.0
2.58445 2.58445 5.16891 0.0 0.0 2.58445 0.0 0.0
⋮ ⋱ ⋮
3.87668 3.87668 5.16891 2.58445 5.16891 3.87668 0.0 0.0
1.29223 6.46114 2.58445 5.16891 3.87668 2.58445 2.58445 0.0
5.16891 7.75336 3.87668 6.46114 3.87668 2.58445 3.87668 0.0
11.63 7.75336 5.16891 5.16891 … 7.75336 5.16891 1.29223 0.0
1.29223 3.87668 3.87668 2.58445 2.58445 1.29223 0.0 0.0
5.16891 3.87668 3.87668 11.63 2.58445 3.87668 0.0 0.0
2.58445 6.46114 6.46114 6.46114 5.16891 2.58445 1.29223 0.0
2.58445 3.87668 3.87668 10.3378 9.04559 2.58445 0.0 0.0
5.16891 6.46114 7.75336 9.04559 … 3.87668 2.58445 0.0 0.0
3.87668 3.87668 0.0 6.46114 9.04559 6.46114 0.0 0.0
3.87668 5.16891 5.16891 1.29223 2.58445 3.87668 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
The units of the maps are stored in:
```julia
proj1_z.maps_unit
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 2 entries:
:sd => :Msol_pc2
:vx => :km_s
The following fields are helpful for further calculations or plots.
```julia
proj1_z.ranges # normalized to the domain=[0:1]
```
6-element Array{Float64,1}:
0.29166666666647767
0.7083333333328743
0.29166666666647767
0.7083333333328743
0.4583333333330363
0.5416666666663156
```julia
proj1_z.extent # ranges in code units
```
4-element Array{Float64,1}:
13.96875
34.03125
21.9375
26.0625
```julia
proj1_z.cextent # ranges in code units relative to a given center (by default: box center)
```
4-element Array{Float64,1}:
-10.031250000015554
10.031249999984446
-2.062500000015554
2.062499999984446
```julia
proj1_z.ratio # the ratio between the two ranges
```
4.863636363636363
## Plot Maps with Python
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false)
proj_x = projection(particles, :sd, :Msol_pc2, lmax=9,
zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
direction = :x);
```
Python functions can be directly called in Julia, which gives the opportunity, e.g. to use the Matplotlib library.
```julia
using PyPlot
using ColorSchemes
cmap = ColorMap(ColorSchemes.lajolla.colors) # See http://www.fabiocrameri.ch/colourmaps.php
cmap2 = ColorMap(ColorSchemes.roma.colors)
```

```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

Project a specific spatial range and plot the axes of the map relative to the box-center (given by keyword: data_center):
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[24.,24.,24.], data_center_unit=:kpc)
proj_x = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[24.,24.,24.], data_center_unit=:kpc,
direction = :x);
```
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

Plot the axes of the map relative to the map-center (given by keyword: data_center):
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[19.,19.,24.], data_center_unit=:kpc)
proj_x = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[19.,19.,24.], data_center_unit=:kpc,
direction = :x);
```
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

## Projections of Derived Kinematic Data
#### Use quantities in cartesian coordinates:
Project the following derived data
(mass weighted by default): The absolute value of the velocity :v, the velocity dispersion :σ in different directions and the kinetic energy :ekin. The Julia language supports Unicode characters and can be inserted by e.g. "\sigma + tab-key" leading to: **σ**.
```julia
proj_z = projection(particles, [:v, :σ, :σx, :σy, :σz, :ekin],
units=[:km_s,:km_s,:km_s,:km_s,:km_s,:erg],
lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[24.,24.,24.], range_unit=:kpc);
```
[Mera]: 2020-02-18T23:11:45.881
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
100%|███████████████████████████████████████████████████| Time: 0:00:03
For the velocity dispersion additional maps are created to created the mass-weighted quantity:
E. g.: σx = sqrt( <vx^2> - < vx >^2 )
```julia
proj_z.maps
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 14 entries:
:ekin => [2.4169e51 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; …
:sd => [0.00129258 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … 0.0 0.0;…
:v => [146.277 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; Na…
:v2 => [4.97588 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; Na…
:vx => [1.22376 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; Na…
:vx2 => [1.49758 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; Na…
:vy => [-1.84928 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; N…
:vy2 => [3.41984 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; Na…
:vz => [-0.241781 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; …
:vz2 => [0.058458 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; N…
:σ => [1.90735e-6 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN;…
:σx => [0.0 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:σy => [0.0 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:σz => [1.72737e-7 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN;…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 14 entries:
:ekin => :erg
:sd => :standard
:v => :km_s
:v2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vz => :standard
:vz2 => :standard
:σ => :km_s
:σx => :km_s
:σy => :km_s
:σz => :km_s
```julia
usedmemory(proj_z);
```
Memory used: 5.16 MB
```julia
figure(figsize=(10, 5.5))
subplot(2, 3, 1)
title("v [km/s]")
imshow( (permutedims(proj_z.maps[:v]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmax=300.)
colorbar()
subplot(2, 3, 2)
title("σ [km/s]")
imshow( (permutedims(proj_z.maps[:σ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 3)
title("Ekin [erg]")
imshow( log10.(permutedims(proj_z.maps[:ekin]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 4)
title("σx [km/s]")
imshow( (permutedims(proj_z.maps[:σx]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 5)
title("σy [km/s]")
imshow( (permutedims(proj_z.maps[:σy]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 6)
title("σz [km/s]")
imshow( (permutedims(proj_z.maps[:σz]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

#### Use quantities in cylindrical coordinates:
#### Face-on disc (z-direction)
For the cylindrical or spherical components of a quantity, the center of the coordinate system is used (keywords: data_center = center default) and can be given with the keyword "data_center" and its units with "data_center_unit". Additionally, the quantities that are based on cartesian coordinates can be given.
```julia
proj_z = projection(particles, [:v, :σ, :σx, :σy, :ϕ, :r_cylinder, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
units=[:km_s,:km_s,:km_s, :km_s, :standard, :kpc, :km_s, :km_s, :km_s, :km_s],
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
data_center=[24.,24.,24.], data_center_unit=:kpc);
```
[Mera]: 2020-02-18T23:14:53.029
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 9
xrange: 150 364
yrange: 150 364
zrange: 235 279
pixel-size: 93.75 [pc]
100%|███████████████████████████████████████████████████| Time: 0:00:01
```julia
proj_z.maps
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 18 entries:
:r_cylinder => [14.0096 13.9434 … 14.1205 14.1874; 13.9434 13.877 … 14.0549…
:sd => [0.00129258 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … …
:v => [146.277 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN…
:v2 => [4.97588 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN…
:vr_cylinder => [29.3132 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN…
:vr_cylinder2 => [0.199823 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … Na…
:vx => [1.22376 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN…
:vx2 => [1.49758 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN…
:vy => [-1.84928 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … Na…
:vy2 => [3.41984 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN…
:vϕ_cylinder => [142.43 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN …
:vϕ_cylinder2 => [4.7176 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN …
:σ => [1.90735e-6 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … …
:σr_cylinder => [0.0 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:σx => [0.0 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:σy => [0.0 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:σϕ_cylinder => [0.0 NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:ϕ => [3.92699 3.92224 … 2.34837 2.34373; 3.93175 3.92699 … 2.3436…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 18 entries:
:r_cylinder => :kpc
:sd => :standard
:v => :km_s
:v2 => :standard
:vr_cylinder => :km_s
:vr_cylinder2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vϕ_cylinder => :km_s
:vϕ_cylinder2 => :standard
:σ => :km_s
:σr_cylinder => :km_s
:σx => :km_s
:σy => :km_s
:σϕ_cylinder => :km_s
:ϕ => :radian
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("Radius [kpc]")
imshow( permutedims(proj_z.maps[:r_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_z.maps[:vr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmin=-200.,vmax=200.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_z.maps[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 4)
title("ϕ-angle")
imshow( (permutedims(proj_z.maps[:ϕ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( permutedims(proj_z.maps[:σr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( permutedims(proj_z.maps[:σϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( (permutedims(proj_z.maps[:σ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( permutedims(proj_z.maps[:σx] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( permutedims(proj_z.maps[:σy] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

## Project on a Coarser Grid
The default is the projection on the maximum loaded grid level (always provided in the output). Choose a smaller level with the keyword *lmax* to project on a coarser grid in addition. Higher-resolution data is averaged within each coarser grid-cell (default: mass-weighted). By default, the data is assumed to be in the center of the simulation box.
```julia
proj_z = projection(particles,
[:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
:km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
lmax=8);
```
[Mera]: 2020-02-18T23:15:37.232
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Map data on given lmax: 8
xrange: 75 183
yrange: 75 183
zrange: 118 140
pixel-size: 187.5 [pc]
100%|███████████████████████████████████████████████████| Time: 0:00:01
The projection onto the maximum loaded grid is always provided:
```julia
proj_z.maps
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 19 entries:
:sd => [0.000323146 0.000323146 … 0.0 0.0; 0.000969439 0.000323146 …
:v => [146.277 156.41 … NaN NaN; 168.992 166.428 … NaN NaN; … ; Na…
:v2 => [4.97588 5.6892 … NaN NaN; 6.6621 6.4413 … NaN NaN; … ; NaN …
:vr_cylinder => [29.3132 76.3408 … NaN NaN; 26.5929 6.80341 … NaN NaN; … ; N…
:vr_cylinder2 => [0.199823 1.35529 … NaN NaN; 0.25831 0.010764 … NaN NaN; … ;…
:vx => [1.22376 0.610176 … NaN NaN; 1.49846 1.69991 … NaN NaN; … ; …
:vx2 => [1.49758 0.372314 … NaN NaN; 2.33418 2.88971 … NaN NaN; … ; …
:vy => [-1.84928 -2.29076 … NaN NaN; -2.04837 -1.86716 … NaN NaN; ……
:vy2 => [3.41984 5.24756 … NaN NaN; 4.22525 3.48629 … NaN NaN; … ; N…
:vz => [-0.241781 -0.263284 … NaN NaN; -0.187282 0.25555 … NaN NaN;…
:vz2 => [0.058458 0.0693187 … NaN NaN; 0.102671 0.0653057 … NaN NaN;…
:vϕ_cylinder => [142.43 135.419 … NaN NaN; 164.297 165.443 … NaN NaN; … ; Na…
:vϕ_cylinder2 => [4.7176 4.26459 … NaN NaN; 6.30112 6.36523 … NaN NaN; … ; Na…
:σ => [1.90735e-6 0.0 … NaN NaN; 9.45804 1.90735e-6 … NaN NaN; … ;…
:σr_cylinder => [0.0 0.0 … NaN NaN; 20.0894 8.42937e-8 … NaN NaN; … ; NaN Na…
:σx => [0.0 0.0 … NaN NaN; 19.5408 0.0 … NaN NaN; … ; NaN NaN … NaN…
:σy => [0.0 0.0 … NaN NaN; 11.246 1.9543e-6 … NaN NaN; … ; NaN NaN …
:σz => [1.72737e-7 0.0 … NaN NaN; 17.0492 0.0 … NaN NaN; … ; NaN Na…
:σϕ_cylinder => [0.0 0.0 … NaN NaN; 10.1009 0.0 … NaN NaN; … ; NaN NaN … NaN…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 19 entries:
:sd => :standard
:v => :km_s
:v2 => :standard
:vr_cylinder => :km_s
:vr_cylinder2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vz => :standard
:vz2 => :standard
:vϕ_cylinder => :km_s
:vϕ_cylinder2 => :standard
:σ => :km_s
:σr_cylinder => :km_s
:σx => :km_s
:σy => :km_s
:σz => :km_s
:σϕ_cylinder => :km_s
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("|v| [km/s]")
imshow( permutedims(proj_z.maps[:v] ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmax=300.)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_z.maps[:vr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmin=-200.,vmax=200.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_z.maps[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 4)
title("σz [km/s]")
imshow( (permutedims(proj_z.maps[:σz]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( (permutedims(proj_z.maps[:σr_cylinder] )), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( (permutedims(proj_z.maps[:σϕ_cylinder] )), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( (permutedims(proj_z.maps[:σ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( (permutedims(proj_z.maps[:σx] )), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( (permutedims(proj_z.maps[:σy] )), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

## Remap a Projected Data onto a Coarser Grid
Pass the object with the projected data to the function *remap* and the level of the coarser grid:
```julia
proj_zlmax = remap(proj_z, 6, weighting=:mass);
```
remap from:
level 8 => 6
cellsize 187.5 [pc] => 750.0 [pc]
pixels (108, 108) => (27, 27)
```julia
proj_zlmax.maps_lmax
```
DataStructures.SortedDict{Any,Any,Base.Order.ForwardOrdering} with 19 entries:
:sd => [0.000323146 0.000646292 … 0.000969439 0.0; 0.000323146 0.00…
:v => [146.277 168.298 … 156.122 NaN; 139.301 147.989 … 163.056 Na…
:v2 => [4.97588 6.59448 … 5.72437 NaN; 4.51262 5.41716 … 6.34405 Na…
:vr_cylinder => [29.3132 84.1136 … 12.6568 NaN; -65.7457 1.40056 … -13.4105 …
:vr_cylinder2 => [0.199823 1.66491 … 1.15359 NaN; 1.0052 0.0947446 … 0.295219…
:vx => [1.22376 0.492592 … -1.53257 NaN; 2.0553 1.52317 … -1.57894 …
:vx2 => [1.49758 0.249049 … 2.51795 NaN; 4.22424 2.55826 … 2.92281 N…
:vy => [-1.84928 -2.42313 … -1.35159 NaN; -0.536675 -1.55209 … -1.8…
:vy2 => [3.41984 5.88813 … 3.07412 NaN; 0.28802 2.57923 … 3.41524 Na…
:vz => [-0.241781 -0.672377 … -0.170057 NaN; -0.0189591 -0.412132 ……
:vz2 => [0.058458 0.457301 … 0.132298 NaN; 0.000359447 0.279663 … 0.…
:vϕ_cylinder => [142.43 138.647 … 133.136 NaN; 122.804 142.63 … 158.394 NaN;…
:vϕ_cylinder2 => [4.7176 4.47227 … 4.43848 NaN; 3.50705 5.04275 … 6.04282 NaN…
:σ => [1.90735e-6 5.72296 … 15.5331 0.0; 0.0 37.3334 … 26.3214 0.0…
:σr_cylinder => [0.0 9.17629 … 69.2848 0.0; 0.0 20.1358 … 33.0096 0.0; … ; 0…
:σx => [0.0 5.24676 … 26.9716 0.0; 0.0 32.0052 … 42.9889 0.0; … ; 0…
:σy => [0.0 8.44153 … 73.2366 0.0; 0.0 27.0583 … 11.713 0.0; … ; 0.…
:σz => [1.72737e-7 4.73321 … 21.0841 0.0; 0.0 21.7301 … 4.72985 0.0…
:σϕ_cylinder => [0.0 2.88507 … 36.8894 0.0; 0.0 36.6195 … 29.9383 0.0; … ; 0…
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("Radius [kpc]")
imshow( permutedims(proj_zlmax.maps_lmax[:v] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:vr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent, vmin=-150.,vmax=150.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 4)
title("σz [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:σz]) , cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:σr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:σϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:σ]) , cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:σx]), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( permutedims(proj_zlmax.maps_lmax[:σy] ), cmap=cmap2, origin="lower", extent=proj_zlmax.cextent)
colorbar();
```

## Projection of the Birth/Age-Time
Project the average birth-time of the particles to the grid:
```julia
proj_z = projection(particles, :birth, :Myr,
lmax=6, zrange=[0.45,0.55], center=[0.,0.,0.], verbose=false);
proj_x = projection(particles, :birth, :Myr,
lmax=6, zrange=[0.45,0.55], center=[0.,0.,0.], direction=:x, verbose=false);
```
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:birth])), cmap=cmap2, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Birth) \ [Myr]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:birth])), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Birth) \ [Myr]}",orientation="horizontal", pad=0.2);
```

Project the average age of the particles to the grid. The age is taken relative to the loaded snapshot time by default.
```julia
proj_z = projection(particles, :age, :Myr,
lmax=6, zrange=[0.45,0.55], center=[0.,0.,0.], verbose=false);
proj_x = projection(particles, :age, :Myr,
lmax=6, zrange=[0.45,0.55], direction=:x, center=[0.,0.,0.], verbose=false);
```
The reference time (code units) for the age calculation:
```julia
proj_z.ref_time
```
39.9019537349027
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:age])), cmap=cmap2, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:age])), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}",orientation="horizontal", pad=0.2);
```

Project the average age of the particles relative to a given reference time:
```julia
proj_z = projection(particles, :age, :Myr, ref_time=0.,
lmax=6, zrange=[0.45,0.55], center=[0.,0.,0.], verbose=false);
proj_x = projection(particles, :age, :Myr, ref_time = 0.,
lmax=6, zrange=[0.45,0.55], center=[0.,0.,0.], direction=:x, verbose=false);
```
The reference time (code units) for the age calculation:
```julia
proj_z.ref_time
```
0.0
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( ( permutedims(proj_z.maps[:age])), cmap=cmap2, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}")
subplot(1,2,2)
im = imshow( ( permutedims(proj_x.maps[:age])), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}",orientation="horizontal", pad=0.2);
```

## Projection of Masked Data
Mask particles with ages higher than 500 Myr by creating a Bool-array where the smaller ages correspond to false entries:
```julia
mask = getvar(particles, :age, :Myr) .> 500. ;
```
```julia
proj_z = projection(particles, :age, :Myr, mask=mask,
lmax=6, zrange=[0.45,0.55], center=[0.,0.,0.]);
proj_x = projection(particles, :age, :Myr, mask=mask,
lmax=6, zrange=[0.45,0.55], center=[0.,0.,0.], direction=:x);
```
[Mera]: 2020-02-18T23:14:17.09
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Map data on given lmax: 6
xrange: 1 65
yrange: 1 65
zrange: 29 37
pixel-size: 750.0 [pc]
:mask provided by function
[Mera]: 2020-02-18T23:14:24.262
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Map data on given lmax: 6
xrange: 1 65
yrange: 1 65
zrange: 29 37
pixel-size: 750.0 [pc]
:mask provided by function
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:age])), cmap=cmap2, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:age])), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}",orientation="horizontal", pad=0.2);
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 36071 | # Save/Convert/Load MERA-Files
The RAMSES simulation data can be stored and accessed from files in the JLD2 file format.
```julia
using Mera
```
## Load the Data From Ramses
```julia
info = getinfo(300, "../../testing/simulations/mw_L10");
gas = gethydro(info, verbose=false, show_progress=false);
part = getparticles(info, verbose=false, show_progress=false);
grav = getgravity(info, verbose=false, show_progress=false);
# the same applies for clump-data...
```
[Mera]: 2023-04-10T14:48:37.021
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
## Store the Data Into JLD2 Files
The running number is taken from the original RAMSES outputs.
```julia
savedata(gas, "../../testing/simulations/JLD2_files/");
```
[Mera]: 2023-04-10T14:50:14.702
Not existing file: output_00300.jld2
Directory: /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10
-----------------------------------
merafile_version: 1.0 - Simulation code: RAMSES
-----------------------------------
DataType: hydro - Data variables: (:level, :cx, :cy, :cz, :rho, :vx, :vy, :vz, :p, :var6, :var7)
-----------------------------------
I/O mode: nothing - Compression: nothing
-----------------------------------
-----------------------------------
Memory size: 2.321 GB (uncompressed)
-----------------------------------
<div class="alert alert-block alert-info"> <b>NOTE</b> The hydro data was not written into the file to prevent overwriting existing files.
The following argument is mandatory: **fmode=:write** </div>
```julia
savedata(gas, "../../testing/simulations/JLD2_files/", fmode=:write);
```
[Mera]: 2023-04-10T14:53:39.878
Create file: output_00300.jld2
Directory: /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10
-----------------------------------
merafile_version: 1.0 - Simulation code: RAMSES
-----------------------------------
DataType: hydro - Data variables: (:level, :cx, :cy, :cz, :rho, :vx, :vy, :vz, :p, :var6, :var7)
-----------------------------------
I/O mode: write - Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x000000011f192040, 0x0000000000000013), false)
-----------------------------------
CodecZlib 0.6.0
Mera 1.2.0 https://github.com/ManuelBehrendt/Mera.jl
CodecBzip2 0.7.2
JLD2 0.4.31
CodecLz4 0.4.0
-----------------------------------
Memory size: 2.321 GB (uncompressed)
Total file size: 1.276 GB
-----------------------------------
Add/Append further datatypes:
```julia
savedata(part, "../../testing/simulations/JLD2_files/", fmode=:append);
savedata(grav, "../../testing/simulations/JLD2_files/", fmode=:append);
```
[Mera]: 2023-04-10T14:53:41.387
Create file: output_00300.jld2
Directory: /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10
-----------------------------------
merafile_version: 1.0 - Simulation code: RAMSES
-----------------------------------
DataType: particles - Data variables: (:level, :x, :y, :z, :id, :family, :tag, :vx, :vy, :vz, :mass, :birth)
-----------------------------------
I/O mode: append - Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x00000001198ff9a0, 0x0000000000000013), false)
-----------------------------------
CodecZlib 0.6.0
Mera 1.2.0 https://github.com/ManuelBehrendt/Mera.jl
CodecBzip2 0.7.2
JLD2 0.4.31
CodecLz4 0.4.0
-----------------------------------
Memory size: 38.451 MB (uncompressed)
Total file size: 1.306 GB
-----------------------------------
[Mera]: 2023-04-10T14:53:43.590
Create file: output_00300.jld2
Directory: /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10
-----------------------------------
merafile_version: 1.0 - Simulation code: RAMSES
-----------------------------------
DataType: gravity - Data variables: (:level, :cx, :cy, :cz, :epot, :ax, :ay, :az)
-----------------------------------
I/O mode: append - Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x000000011a600ec0, 0x0000000000000013), false)
-----------------------------------
CodecZlib 0.6.0
Mera 1.2.0 https://github.com/ManuelBehrendt/Mera.jl
CodecBzip2 0.7.2
JLD2 0.4.31
CodecLz4 0.4.0
-----------------------------------
Memory size: 1.688 GB (uncompressed)
Total file size: 2.159 GB
-----------------------------------
<div class="alert alert-block alert-info"> <b>NOTE</b> It is not possible to exchange stored data; only writing into a new file or appending is supported. </div>
## Overview of Stored Data
```julia
vd = viewdata(300, "../../testing/simulations/JLD2_files/")
```
[Mera]: 2023-04-10T17:53:19.650
Mera-file output_00300.jld2 contains:
Datatype: particles
merafile_version: 1.0
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x0000000000000000, 0x0000000000000013), false)
CodecZlib: VersionNumber[v"0.6.0"]
merafile_version: 1.0
JLD2: VersionNumber[v"0.4.31"]
CodecBzip2: VersionNumber[v"0.7.2"]
JLD2compatible_versions: 0.1
CodecLz4: VersionNumber[v"0.4.0"]
Mera: Any[v"1.2.0", "https://github.com/ManuelBehrendt/Mera.jl"]
-------------------------
Memory: 38.4513635635376 MB (uncompressed)
Datatype: gravity
merafile_version: 1.0
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x0000000000000000, 0x0000000000000013), false)
CodecZlib: VersionNumber[v"0.6.0"]
merafile_version: 1.0
JLD2: VersionNumber[v"0.4.31"]
CodecBzip2: VersionNumber[v"0.7.2"]
JLD2compatible_versions: 0.1
CodecLz4: VersionNumber[v"0.4.0"]
Mera: Any[v"1.2.0", "https://github.com/ManuelBehrendt/Mera.jl"]
-------------------------
Memory: 1.6880846759304404 GB (uncompressed)
Datatype: hydro
merafile_version: 1.0
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x0000000000000000, 0x0000000000000013), false)
CodecZlib: VersionNumber[v"0.6.0"]
merafile_version: 1.0
JLD2: VersionNumber[v"0.4.31"]
CodecBzip2: VersionNumber[v"0.7.2"]
JLD2compatible_versions: 0.1
CodecLz4: VersionNumber[v"0.4.0"]
Mera: Any[v"1.2.0", "https://github.com/ManuelBehrendt/Mera.jl"]
-------------------------
Memory: 2.3211082834750414 GB (uncompressed)
-----------------------------------
convert stat: false
-----------------------------------
Total file size: 2.159 GB
-----------------------------------
Dict{Any, Any} with 4 entries:
"particles" => Dict{Any, Any}("versions"=>Dict{Any, Any}("CodecZlib"=>Version…
"FileSize" => (2.159, "GB")
"gravity" => Dict{Any, Any}("versions"=>Dict{Any, Any}("CodecZlib"=>Version…
"hydro" => Dict{Any, Any}("versions"=>Dict{Any, Any}("CodecZlib"=>Version…
Information about the content, etc. is returned in a dictionary.
```julia
```
Get a detailed tree-view of the data-file:
```julia
vd = viewdata(300, "../../testing/simulations/JLD2_files/", showfull=true)
```
[Mera]: 2023-04-10T17:54:10.300
Mera-file output_00300.jld2 contains:
├─📂 hydro
│ ├─🔢 data
│ ├─🔢 info
│ └─📂 information
│ ├─🔢 compression
│ ├─🔢 comments
│ ├─🔢 storage
│ ├─🔢 memory
│ └─📂 versions
│ ├─🔢 merafile_version
│ ├─🔢 JLD2compatible_versions
│ ├─🔢 CodecZlib
│ ├─🔢 Mera
│ ├─🔢 CodecBzip2
│ ├─🔢 JLD2
│ └─🔢 CodecLz4
├─📂 particles
│ ├─🔢 data
│ ├─🔢 info
│ └─📂 information
│ ├─🔢 compression
│ ├─🔢 comments
│ ├─🔢 storage
│ ├─🔢 memory
│ └─📂 versions
│ ├─🔢 merafile_version
│ ├─🔢 JLD2compatible_versions
│ ├─🔢 CodecZlib
│ ├─🔢 Mera
│ ├─🔢 CodecBzip2
│ ├─🔢 JLD2
│ └─🔢 CodecLz4
└─📂 gravity
├─🔢 data
├─🔢 info
└─📂 information
├─🔢 compression
├─🔢 comments
├─🔢 storage
├─🔢 memory
└─📂 versions
├─🔢 merafile_version
├─🔢 JLD2compatible_versions
├─🔢 CodecZlib
├─🔢 Mera
├─🔢 CodecBzip2
├─🔢 JLD2
└─🔢 CodecLz4
Datatype: particles
merafile_version: 1.0
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x0000000000000000, 0x0000000000000013), false)
CodecZlib: VersionNumber[v"0.6.0"]
merafile_version: 1.0
JLD2: VersionNumber[v"0.4.31"]
CodecBzip2: VersionNumber[v"0.7.2"]
JLD2compatible_versions: 0.1
CodecLz4: VersionNumber[v"0.4.0"]
Mera: Any[v"1.2.0", "https://github.com/ManuelBehrendt/Mera.jl"]
-------------------------
Memory: 38.4513635635376 MB (uncompressed)
Datatype: gravity
merafile_version: 1.0
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x0000000000000000, 0x0000000000000013), false)
CodecZlib: VersionNumber[v"0.6.0"]
merafile_version: 1.0
JLD2: VersionNumber[v"0.4.31"]
CodecBzip2: VersionNumber[v"0.7.2"]
JLD2compatible_versions: 0.1
CodecLz4: VersionNumber[v"0.4.0"]
Mera: Any[v"1.2.0", "https://github.com/ManuelBehrendt/Mera.jl"]
-------------------------
Memory: 1.6880846759304404 GB (uncompressed)
Datatype: hydro
merafile_version: 1.0
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x0000000000000000, 0x0000000000000013), false)
CodecZlib: VersionNumber[v"0.6.0"]
merafile_version: 1.0
JLD2: VersionNumber[v"0.4.31"]
CodecBzip2: VersionNumber[v"0.7.2"]
JLD2compatible_versions: 0.1
CodecLz4: VersionNumber[v"0.4.0"]
Mera: Any[v"1.2.0", "https://github.com/ManuelBehrendt/Mera.jl"]
-------------------------
Memory: 2.3211082834750414 GB (uncompressed)
-----------------------------------
convert stat: false
-----------------------------------
Total file size: 2.159 GB
-----------------------------------
Dict{Any, Any} with 4 entries:
"particles" => Dict{Any, Any}("versions"=>Dict{Any, Any}("CodecZlib"=>Version…
"FileSize" => (2.159, "GB")
"gravity" => Dict{Any, Any}("versions"=>Dict{Any, Any}("CodecZlib"=>Version…
"hydro" => Dict{Any, Any}("versions"=>Dict{Any, Any}("CodecZlib"=>Version…
## Get Info
The following function **infodata** is comparable to **getinfo()** used for the RAMSES files and loads detailed information about the simulation output:
```julia
info = infodata(300, "../../testing/simulations/JLD2_files/");
```
[Mera]: 2023-04-10T17:56:08.095
Use datatype: hydro
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&HYDRO_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&INIT_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
In this case, it loaded the **InfoDataType** from the **hydro** data. Choose a different stored **datatype** to get the info from:
```julia
info = infodata(300, "../../testing/simulations/JLD2_files/", :particles);
```
[Mera]: 2023-04-10T17:58:12.353
Use datatype: particles
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&HYDRO_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&INIT_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
## Load The Data from JLD2
### Full Data
```julia
gas = loaddata(300, "../../testing/simulations/JLD2_files/", :hydro);
```
[Mera]: 2023-04-10T17:59:17.292
Open Mera-file output_00300.jld2:
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Memory used for data table :2.321107776835561 GB
-------------------------------------------------------
```julia
typeof(gas)
```
HydroDataType
```julia
part = loaddata(300, "../../testing/simulations/JLD2_files/", :particles);
```
[Mera]: 2023-04-10T17:59:53.847
Open Mera-file output_00300.jld2:
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Memory used for data table :38.45084476470947 MB
-------------------------------------------------------
```julia
typeof(part)
```
PartDataType
### Data Range
Complete data is loaded, and the selected subregion is returned:
```julia
gas = loaddata(300, "../../testing/simulations/JLD2_files/", :hydro,
xrange=[-10,10],
yrange=[-10,10], zrange=[-2,2],
center=[:boxcenter],
range_unit=:kpc);
```
[Mera]: 2023-04-10T18:02:11.639
Open Mera-file output_00300.jld2:
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :587.3237018585205 MB
-------------------------------------------------------
## Convert RAMSES Output Into JLD2
Existing AMR, hydro, gravity, particle, and clump data is sequentially stored in a JLD2 file. The individual loading/writing processes are timed, and the memory usage is returned in a dictionary:
### Full Data
```julia
cvd = convertdata(300, path="../../testing/simulations/mw_L10",
fpath="../../testing/simulations/JLD2_files/");
```
[Mera]: 2023-04-10T18:06:14.413
Requested datatypes: [:hydro, :gravity, :particles, :clumps]
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
reading/writing lmax: 10 of 10
-----------------------------------
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x000000011f291c50, 0x0000000000000013), false)
-----------------------------------
- hydro
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:24
- gravity
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:19
- particles
Total datasize:
- total folder: 5.682 GB
- selected: 5.68 GB
- used: 4.047 GB
- new on disc: 2.159 GB
#### Timer
Get a view of the timers:
```julia
using TimerOutputs
```
```julia
cvd
```
Dict{Any, Any} with 3 entries:
"viewdata" => Dict{Any, Any}("particles"=>Dict{Any, Any}("versions"=>Dict…
"size" => Dict{Any, Any}("folder"=>Any[6101105264, "Bytes"], "selecte…
"TimerOutputs" => Dict{Any, Any}("writing"=> ──────────────────────────…
```julia
cvd["TimerOutputs"]["reading"]
```
──────────────────────────────────────────────────────────────────────
Time Allocations
─────────────────────── ────────────────────────
Tot / % measured: 324s / 16.9% 45.4GiB / 72.9%
Section ncalls time %tot avg alloc %tot avg
──────────────────────────────────────────────────────────────────────
hydro 1 30.4s 55.4% 30.4s 18.7GiB 56.5% 18.7GiB
gravity 1 24.0s 43.7% 24.0s 14.1GiB 42.6% 14.1GiB
particles 1 503ms 0.9% 503ms 309MiB 0.9% 309MiB
──────────────────────────────────────────────────────────────────────
```julia
cvd["TimerOutputs"]["writing"]
```
──────────────────────────────────────────────────────────────────────
Time Allocations
─────────────────────── ────────────────────────
Tot / % measured: 327s / 1.0% 45.4GiB / 22.6%
Section ncalls time %tot avg alloc %tot avg
──────────────────────────────────────────────────────────────────────
hydro 1 1.89s 55.4% 1.89s 5.92GiB 57.6% 5.92GiB
gravity 1 1.34s 39.3% 1.34s 4.23GiB 41.2% 4.23GiB
particles 1 181ms 5.3% 181ms 129MiB 1.2% 129MiB
──────────────────────────────────────────────────────────────────────
```julia
```
```julia
# prep timer
to = TimerOutput();
```
```julia
@timeit to "MERA" begin
@timeit to "hydro" gas = loaddata(300, "../../testing/simulations/JLD2_files/", :hydro, )
@timeit to "particles" part= loaddata(300, "../../testing/simulations/JLD2_files/", :particles)
end;
```
[Mera]: 2023-04-10T18:13:05.133
Open Mera-file output_00300.jld2:
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Memory used for data table :2.321107776835561 GB
-------------------------------------------------------
[Mera]: 2023-04-10T18:13:11.371
Open Mera-file output_00300.jld2:
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Memory used for data table :38.45084476470947 MB
-------------------------------------------------------
```julia
to
```
────────────────────────────────────────────────────────────────────────
Time Allocations
─────────────────────── ────────────────────────
Tot / % measured: 80.3s / 8.1% 7.23GiB / 99.8%
Section ncalls time %tot avg alloc %tot avg
────────────────────────────────────────────────────────────────────────
MERA 3 6.50s 100.0% 2.17s 7.22GiB 100.0% 2.41GiB
hydro 3 6.36s 97.8% 2.12s 7.10GiB 98.4% 2.37GiB
particles 1 140ms 2.1% 140ms 121MiB 1.6% 121MiB
────────────────────────────────────────────────────────────────────────
<div class="alert alert-block alert-info"> <b>NOTE</b> The reading from JLD2 files is multiple times faster than from the original RAMSES files. </div>
#### Used Memory
```julia
cvd["size"]
```
Dict{Any, Any} with 4 entries:
"folder" => Any[6101105264, "Bytes"]
"selected" => Any[4.29676e9, "Bytes"]
"ondisc" => Any[1402573523, "Bytes"]
"used" => Any[2.53259e9, "Bytes"]
<div class="alert alert-block alert-info"> <b>NOTE</b> The compressed JLD2 file takes a significantly smaller disk space than the original RAMSES folder.</div>
```julia
factor = cvd["size"]["folder"][1] / cvd["size"]["ondisc"][1]
println("==============================================================================")
println("In this example, the disk space is reduced by a factor of $factor !!")
println("==============================================================================")
```
==============================================================================
In this example, the disk space is reduced by a factor of 4.349936145201281 !!
==============================================================================
```julia
```
### Selected Datatypes
```julia
cvd = convertdata(300, [:hydro, :particles],
path="../../testing/simulations/mw_L10",
fpath="../../testing/simulations/JLD2_files/");
```
[Mera]: 2023-04-10T18:17:17.373
Requested datatypes: [:hydro, :particles]
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
reading/writing lmax: 10 of 10
-----------------------------------
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x000000011dbea7b0, 0x0000000000000013), false)
-----------------------------------
- hydro
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:24
- particles
Total datasize:
- total folder: 5.682 GB
- selected: 4.002 GB
- used: 2.359 GB
- new on disc: 1.306 GB
```julia
```
## Compression
By default, the data is compressed by a standard compressor. Therefore, if you want to use a different compression algorithm better suited to your needs, you can also directly pass a compressor. https://juliaio.github.io/JLD2.jl/stable/compression/
|Library | Compressor| |
|---|---|---|
|CodecZlib.jl | ZlibCompressor | The default as it is very widely used. |
|CodecBzip2.jl | Bzip2Compressor | Can often times be faster |
|CodecLz4.jl | LZ4FrameCompressor | Fast, but not compatible to the LZ4 shipped by HDF5 |
To use any of these, replace the compress = true argument with an instance of the compressor, e.g.
```julia
using CodecZlib
cvd = convertdata(300, [:hydro, :particles], compress=ZlibCompressor(),
path="../../testing/simulations/mw_L10",
fpath="../../testing/simulations/JLD2_files/");
```
[Mera]: 2023-04-10T18:25:31.061
Requested datatypes: [:hydro, :particles]
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
reading/writing lmax: 10 of 10
-----------------------------------
Compression: ZlibCompressor(level=-1, windowbits=15)
-----------------------------------
- hydro
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:23
- particles
Total datasize:
- total folder: 5.682 GB
- selected: 4.002 GB
- used: 2.359 GB
- new on disc: 1.24 GB
```julia
savedata(gas, "../../testing/simulations/JLD2_files/",
fmode=:write, compress=ZlibCompressor());
```
[Mera]: 2023-04-10T19:38:12.259
Create file: output_00300.jld2
Directory: /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10
-----------------------------------
merafile_version: 1.0 - Simulation code: RAMSES
-----------------------------------
DataType: hydro - Data variables: (:level, :cx, :cy, :cz, :rho, :vx, :vy, :vz, :p, :var6, :var7)
-----------------------------------
I/O mode: write - Compression: ZlibCompressor(level=-1, windowbits=15)
-----------------------------------
CodecZlib 0.6.0
Mera 1.2.0 https://github.com/ManuelBehrendt/Mera.jl
CodecBzip2 0.7.2
JLD2 0.4.31
CodecLz4 0.4.0
-----------------------------------
Memory size: 2.321 GB (uncompressed)
Total file size: 1.213 GB
-----------------------------------
Get more information about the parameters of the compressor:
```julia
?ZlibCompressor
```
search: ZlibCompressor ZlibCompressorStream ZlibDecompressor
```
ZlibCompressor(;level=-1, windowbits=15)
```
Create a zlib compression codec.
## Arguments
* `level`: compression level (-1..9)
* `windowbits`: size of history buffer (8..15)
```julia
```
## Comments
Add a description to the files:
```julia
comment = "The simulation is...."
cvd = convertdata(300, [:hydro, :particles], comments=comment,
path="../../testing/simulations/mw_L10",
fpath="../../testing/simulations/JLD2_files/");
```
[Mera]: 2023-04-10T19:40:13.068
Requested datatypes: [:hydro, :particles]
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
reading/writing lmax: 10 of 10
-----------------------------------
Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x000000011d36bcb0, 0x0000000000000013), false)
-----------------------------------
- hydro
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:29
- particles
Progress: 100%|█████████████████████████████████████████| Time: 0:00:02
Total datasize:
- total folder: 5.682 GB
- selected: 4.002 GB
- used: 2.359 GB
- new on disc: 1.306 GB
```julia
```
```julia
comment = "The simulation is...."
savedata(gas, "../../testing/simulations/JLD2_files/", comments=comment, fmode=:write);
```
[Mera]: 2023-04-10T19:42:11.007
Create file: output_00300.jld2
Directory: /Users/mabe/Documents/codes/github/Mera.jl/tutorials/version_1/../../testing/simulations/mw_L10
-----------------------------------
merafile_version: 1.0 - Simulation code: RAMSES
-----------------------------------
DataType: hydro - Data variables: (:level, :cx, :cy, :cz, :rho, :vx, :vy, :vz, :p, :var6, :var7)
-----------------------------------
I/O mode: write - Compression: CodecLz4.LZ4FrameCompressor(Base.RefValue{Ptr{CodecLz4.LZ4F_cctx}}(Ptr{CodecLz4.LZ4F_cctx} @0x0000000000000000), Base.RefValue{CodecLz4.LZ4F_preferences_t}(CodecLz4.LZ4F_preferences_t(CodecLz4.LZ4F_frameInfo_t(0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000, 0x00000000, 0x00000000), 0, 0x00000000, (0x00000000, 0x00000000, 0x00000000, 0x00000000))), TranscodingStreams.Memory(Ptr{UInt8} @0x000000011a279cc0, 0x0000000000000013), false)
-----------------------------------
CodecZlib 0.6.0
Mera 1.2.0 https://github.com/ManuelBehrendt/Mera.jl
CodecBzip2 0.7.2
JLD2 0.4.31
CodecLz4 0.4.0
-----------------------------------
Memory size: 2.321 GB (uncompressed)
Total file size: 1.276 GB
-----------------------------------
Load the comment (hydro) from JLD2 file:
```julia
vd = viewdata(300, "../../testing/simulations/JLD2_files/", verbose=false);
```
```julia
vd["hydro"]["comments"]
```
"The simulation is...."
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 7067 | # Miscellaneous
```julia
using Mera
info=getinfo(300, "../../../testing/simulations/mw_L10/", verbose=false);
```
## MyArguments
Pass several arguments at once to a function for better readability!
```julia
# create an empty struct for arguments:
myargs = ArgumentsType()
```
ArgumentsType(missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
```julia
viewfields(myargs)
```
[Mera]: Fields to use as arguments in functions
=======================================================================
pxsize = missing
res = missing
lmax = missing
xrange = missing
yrange = missing
zrange = missing
radius = missing
height = missing
direction = missing
plane = missing
plane_ranges = missing
thickness = missing
position = missing
center = missing
range_unit = missing
data_center = missing
data_center_unit = missing
verbose = missing
show_progress = missing
```julia
# assign necessary fields:
myargs.pxsize = [100., :pc]
myargs.xrange=[-10.,10.]
myargs.yrange=[-10.,10.]
myargs.zrange=[-2.,2.]
myargs.center=[:boxcenter]
myargs.range_unit=:kpc;
```
<div class="alert alert-block alert-info"> <b>NOTE</b> All functions that hold the upper listed arguments can handle the ArgumentsType struct! </div>
```julia
gas = gethydro(info, myargs=myargs);
```
[Mera]: Get hydro data: 2023-04-10T21:15:35.249
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:17
Memory used for data table :580.2776288986206 MB
-------------------------------------------------------
```julia
part = getparticles(info, myargs=myargs);
```
[Mera]: Get particle data: 2023-04-10T21:15:57.394
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Found 5.368130e+05 particles
Memory used for data table :37.88558769226074 MB
-------------------------------------------------------
```julia
p = projection(gas, :sd, :Msun_pc2, myargs=myargs);
```
[Mera]: 2023-04-10T21:16:08.050
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 481^2
Map size: 201 x 201
Pixel size: 99.792 [pc]
Simulation min.: 46.875 [pc]
```julia
# add more args for silent screen:
myargs.verbose=false
myargs.show_progress=false;
```
```julia
gas = gethydro(info, myargs=myargs);
```
```julia
part = getparticles(info, myargs=myargs);
```
```julia
p = projection(gas, :sd, :Msun_pc2, myargs=myargs);
```
```julia
```
## Verbose & Progressbar Switch
Master switch to toggle the verbose mode and progress bar for all functions:
```julia
# current status
# "nothing" allows the functions to use the passed argument:
# verbose=false/true
verbose()
```
verbose_mode: nothing
```julia
# switch off verbose mode globally:
verbose(false)
```
false
```julia
# check
gas = gethydro(info);
```
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:22
```julia
# switch on verbose mode globally:
# the passed argument verbose=false/true to the individual
# functions is ignored.
verbose(true)
```
```julia
gas = gethydro(info);
```
[Mera]: Get hydro data: 2023-04-10T21:21:09.500
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:24
Memory used for data table :2.3210865957662463 GB
-------------------------------------------------------
```julia
```
```julia
# current status
# "nothing" allows the functions to use the passed argument:
# show_progress=false/true
showprogress()
```
showprogress_mode: nothing
```julia
# switch off the progressbar globally:
showprogress(false)
```
false
```julia
# check
showprogress()
```
showprogress_mode: false
```julia
gas = gethydro(info);
```
[Mera]: Get hydro data: 2023-04-10T21:25:05.493
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Memory used for data table :2.3210865957662463 GB
-------------------------------------------------------
```julia
```
```julia
# switch on the progressbar globally:
# the passed argument show_progress=false/true to the individual
# functions is ignored.
showprogress(true)
```
true
```julia
# check
showprogress()
```
showprogress_mode: true
```julia
# return to neutral mode
showprogress(nothing)
```
```julia
# check
showprogress()
```
showprogress_mode: nothing
```julia
```
## Notification Bell
```julia
?bell
```
search: bell bytesavailable @label bulk_velocity baremodule AbstractChannel
### Get a notification sound, e.g., when your calculations are finished.
This may not apply when working remotely on a server:
```julia
julia> bell()
```
## Notification E-Mail
```julia
?notifyme
```
search: notifyme notify
### Get an email notification, e.g., when your calculations are finished.
Mandatory:
* the email client "mail" needs to be installed
* put a file with the name "email.txt" in your home folder that contains your email address in the first line
```julia
julia> notifyme()
```
or:
```julia
julia> notifyme("Calculation 1 finished!")
```
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 469 | ## Types
#### Abstract type hierarchies

- HydroMapsType <: DataMapsType
- PartMapsType <: DataMapsType
#### List of types
```@index
Modules = [Mera]
Order = [:type]
```
## Functions
```@index
Modules = [Mera]
Private = false
Order = [:function]
```
## Documentation Types
```@autodocs
Modules = [Mera]
Order = [:type]
```
## Documentation Functions
```@autodocs
Modules = [Mera]
Order = [:function]
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 444 |
# Short Tutorials
- [Hands-On Session RUM2023 (included: density PDFs, radial profiles, phase diagram...)](https://github.com/ManuelBehrendt/RUM2023)
- [Load from a sequence of existing simulations in a folder](examples/LoadFromExistingOutputs.md)
- [Export/Import data - ASCII/binary files](examples/ExportImportData.md)
- [The documentation as Jupyter Notebooks for download](https://github.com/ManuelBehrendt/Mera.jl/tree/master/tutorials) | Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 12231 | # Home
[](https://zenodo.org/badge/latestdoi/229728152)
MERA is a package for working with large 3D AMR/uniform-grid and N-body particle data sets from astrophysical simulations.
It is entirely written in the language [Julia](https://julialang.org) and currently supports the hydrodynamic code [RAMSES](https://bitbucket.org/rteyssie/ramses/overview). With this package, I intend to provide essential functions to load and prepare the simulation data for calculations but try to avoid too high-level abstraction (black boxes).
!!! note "Note"
To get a first impression, look at the `Hands-On Session RUM2023` with downloadable simulation examples:
https://github.com/ManuelBehrendt/RUM2023
## Package Features
- Easy to install and update
- Fast and memory lightweight data reading/saving and handling
- The data is loaded and processed in a database framework [JuliaDB.jl](https://juliadb.org)
- Efficient workflow
- Many functionalities for advanced analysis
- Easy to extend
- Interactive and script functionality
- Many examples and tutorials
- Mera-files, a significant faster way to read/store the RAMSES data for time sequence analysis
## Dependencies
Find the main dependencies on [JuliaHub](https://juliahub.com/ui/Packages/Mera/7jlnw/1.4.2?page=1) or of the development version listed in the file [Project.toml](https://github.com/ManuelBehrendt/Mera.jl/blob/master/Project.toml).
## Tests
We are developing **unit-test** and **end-to-end** testing strategies to encounter bugs like general errors, incorrect data returns, and functionality issues. After new commits are pushed to GitHub, **different operating system environments** and **Julia versions** run **automated tests**, e. g. on outputs from various RAMSES simulations, to ensure important functionalities of MERA. The *test* folder contains all tests with the main function in the **runtest.jl** file. Find the current test status of the development version at: https://github.com/ManuelBehrendt/Mera.jl/blob/master/README.md
## Julia Installation
- Binary download + installation instructions: https://julialang.org/downloads/
- Juliaup, an installer and version manager: https://github.com/JuliaLang/juliaup
- Apple Silicon: M1/M2 Chips: Julia 1.6.x can be installed without any trouble. But to use PyPlot, it is recommended to install/pin the package [email protected] ! https://pkgdocs.julialang.org/v1.6/managing-packages/#Pinning-a-package . If you encounter any problems with Julia 1.9, try the binary *macOS x86 (Intel or Rosetta)* instead of *macOS (Apple Silicon)*.
## Package Installation
The package is tested against the long-term supported Julia 1.6.x (recommended), 1.7.x, 1.8.x, 1.9.x and can be installed with the Julia package manager: https://pkgdocs.julialang.org/v1/
### Julia REPL
From the Julia REPL, type ] to enter the Pkg REPL mode and run:
```julia
pkg> add Mera
```
### Jupyter Notebook
Or, equivalently, via the Pkg API in the Jupyter notebook use
```julia
using Pkg
Pkg.add("Mera")
```
## Updates
Watch on [GitHub](https://github.com/ManuelBehrendt/Mera.jl).
Note: Before updating, always read the release notes. In Pkg REPL mode run:
```julia
pkg> update Mera
```
Or, equivalently,
```julia
using Pkg
Pkg.update("Mera")
```
## Reproducibility
Reproducibility is an essential requirement of the scientific process. Therefore, I recommend working with environments.
Create independent projects that contain their list of used package dependencies and their versions.
The possibility of creating projects ensures reproducibility of your programs on your or other platforms if, e.g. the code is shared (toml-files are added to the project folder). For more information see [Julia environments](https://julialang.github.io/Pkg.jl/v1.6/environments/).
In order to create a new project "activate" your working directory:
```julia
shell> cd MyProject
/Users/you/MyProject
(v1.6) pkg> activate .
```
Now add packages like Mera and PyPlot in the favored version:
```julia
(MyProject) pkg> add Package
```
## Help and Documentation
The exported functions and types in MERA are listed in the API documentation, but can also be accessed in the REPL or Jupyter notebook.
In the REPL use e.g. for the function *getinfo*:
```julia
julia> ? # upon typing ?, the prompt changes (in place) to: help?>
help?> getinfo
search: getinfo SegmentationFault getindex getpositions MissingException
Get the simulation overview from RAMSES info, descriptor and output header files
----------------------------------------------------------------------------------
getinfo(; output::Real=1, path::String="", namelist::String="", verbose::Bool=verbose_mode)
return InfoType
Keyword Arguments
-------------------
• output: timestep number (default=1)
• path: the path to the output folder relative to the current folder or absolute path
• namelist: give the path to a namelist file (by default the namelist.txt-file in the output-folder is read)
• verbose:: informations are printed on the screen by default: gloval variable verbose_mode=true
Examples
----------
...........
```
In the Jupyter notebook use e.g.:
```julia
?getinfo
search: getinfo SegmentationFault getindex getpositions MissingException
Get the simulation overview from RAMSES info, descriptor and output header files
----------------------------------------------------------------------------------
getinfo(; output::Real=1, path::String="", namelist::String="", verbose::Bool=verbose_mode)
return InfoType
Keyword Arguments
-------------------
• output: timestep number (default=1)
• path: the path to the output folder relative to the current folder or absolute path
• namelist: give the path to a namelist file (by default the namelist.txt-file in the output-folder is read)
• verbose:: informations are printed on the screen by default: gloval variable verbose_mode=true
Examples
----------
...........
```
Get a list of the defined methods of a function:
```julia
julia> methods(viewfields)
# 10 methods for generic function "viewfields":
[1] viewfields(object::PhysicalUnitsType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:181
[2] viewfields(object::Mera.FilesContentType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:166
[3] viewfields(object::DescriptorType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:150
[4] viewfields(object::FileNamesType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:134
[5] viewfields(object::CompilationInfoType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:116
[6] viewfields(object::GridInfoType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:90
[7] viewfields(object::PartInfoType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:73
[8] viewfields(object::ScalesType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:57
[9] viewfields(object::InfoType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:12
[10] viewfields(object::DataSetType) in Mera at /Users/mabe/Documents/Projects/dev/Mera/src/functions/viewfields.jl:197
```
## Further Notes
- To use the **Jupyter** interactive environment, please install IJulia (see [IJulia](https://github.com/JuliaLang/IJulia.jl)) and/or the standalone "JupyterLab Desktop" app: https://github.com/jupyterlab/jupyterlab-desktop
- The **tutorials** in the documentation can be downloaded from [GitHub](https://github.com/ManuelBehrendt/Mera.jl/tree/master/tutorials) as Jupyter notebooks
- To get a first impression, look at the **Hands-On Session** RUM2023` with downloadable simulation examples:
https://github.com/ManuelBehrendt/RUM2023
- Mera is tested against the **RAMSES versions**: =< stable-17.09, stable-18-09, stable-19-10
- The variables from the **descriptor-files** are currently only read and can be used in a future Mera version
- For simulations with a **uniform grid**, the column **:level** is not created to reduce memory usage
## Why Julia?
In scientific computing, we are dealing with a steadily increasing amount of data. Highest performance is required, and therefore, most science-related libraries are written in low-level languages like C or Fortran with relatively long development times. The reduced data is often processed in a high-level language like Python.
Julia is a relatively new and modern language, and it combines high-level programming with high-performance numerical computing. The syntax is simple and great for math. The just-in-time compilation allows for interactive coding and to achieve an optimized machine code on the fly. Both enhance prototyping and code readability. Therefore, complex projects can be realized in relatively short development times.
Further features:
- Package manager
- Runs on multiple platform
- Multiple dispatch
- Build-in parallelism
- Metaprogramming
- Directly call C, Fortran, Python (e.g. Matplotlib), R libraries, ...
….
## Useful Links
- [Official Julia website](https://julialang.org)
- Alternatively use the Julia version manager and make Julia 1.6.* the default: https://github.com/JuliaLang/juliaup
- [Learning Julia](https://julialang.org/learning/)
- [Wikibooks](https://en.wikibooks.org/wiki/Introducing_Julia)
- [Julia Cheatsheet](https://juliadocs.github.io/Julia-Cheat-Sheet/)
- [Free book ThinkJulia](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html)
- [Synthax comparison: MATLAB–Python–Julia](https://cheatsheets.quantecon.org)
- [Julia forum JuliaDiscourse](https://discourse.julialang.org)
- [Courses on YouTube](https://www.youtube.com/user/JuliaLanguage)
- Database framework used in Mera: [JuliaDB.jl](https://juliadb.org)
- Interesting Packages: [JuliaAstro.jl](http://juliaastro.github.io), [JuliaObserver.com](https://juliaobserver.com)
- Use Matplotlib in Julia: [PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl)
- Call Python packages/functions from Julia: [PyCall.jl](https://github.com/JuliaPy/PyCall.jl)
- Visual Studio Code based Julia IDE [julia-vscode](https://github.com/julia-vscode/julia-vscode)
## Contact for Questions and Contributing
- If you have any questions about the package, please feel free to write an email to: mera[>]manuelbehrendt.com
- For bug reports, etc., please submit an issue on [GitHub](https://github.com/ManuelBehrendt/Mera.jl)
New ideas, feature requests are very welcome! MERA can be easily extended for other grid-based or N-body based data. Write an email to: mera[>]manuelbehrendt.com
## Supporting and Citing
To credit the Mera software, please star the repository on GitHub. If you use the Mera software as part of your research, teaching, or other activities, I would be grateful if you could cite my work. To give proper academic credit, follow the link for BibTeX export:
[](https://zenodo.org/badge/latestdoi/229728152)
## License
MIT License
Copyright (c) 2019 Manuel Behrendt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 30622 | # 3. Clumps: Get Sub-Regions of The Loaded Data
## Load the Data
```julia
using Mera, PyPlot
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14")
clumps = getclumps(info);
```
[Mera]: 2020-02-08T20:39:44.033
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get clump data: 2020-02-08T20:39:48.496
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
## Cuboid Region
### Create scatter plots of the full box:
Use the `getvar` function to extract the positions of the clumps relative to the box center. It returns a dictionary of arrays:
```julia
positions = getvar(clumps, [:x, :y, :z], :kpc, center=[:boxcenter], center_unit=:kpc) # units=[:kpc, :kpc, :kpc]
x, y, z = positions[:x], positions[:y], positions[:z]; # assign the three components of the dictionary to three arrays
```
Alternatively, use the `getposition` function to extract the positions of the clumps. It returns a tuple of the three components:
```julia
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter], center_unit=:kpc); # assign the three components of the tuple to three arrays
```
Get the extent of the processed domain with respect to a given center. The returned tuple is useful declare the specific range of the plots.
```julia
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
#### Cuboid Region: The red lines show the region that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
subplot(1,3,1)
scatter(x,y)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cuboid Region: Cutout the data assigned to the object `clumps`
Note: The selected regions can be given relative to a user given center or to the box corner [0., 0., 0.] by default. The user can choose between standard notation [0:1] (default) or physical length-units, defined in e.g. info.scale :
```julia
clumps_subregion = subregion( clumps, :cuboid,
xrange=[-4., 0.],
yrange=[-15. ,15.],
zrange=[-2. ,2.],
center=[:boxcenter],
range_unit=:kpc);
```
[Mera]: 2020-02-08T20:40:04.755
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :29.52734375 KB
-------------------------------------------------------
The function `subregion` creates a new object with the same type as the object created by the function `getclumps` :
```julia
typeof(clumps_subregion)
```
ClumpDataType
#### Cuboid Region: Scatter-Plots of the sub-region.
The coordinates center is the center of the box by default:
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # clump positions of the subregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter] ); # extent of the box
```
```julia
figure(figsize=(15.5, 3.5))
subplot(1,3,1)
scatter(x,y)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cuboid Region: Get the extent of the subregion data ranges
```julia
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc, center=[:boxcenter]); # extent of the subregion
```
```julia
figure(figsize=(15.5, 3.5))
subplot(1,3,1)
scatter(x,y)
xlim(rx_sub)
ylim(ry_sub)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
xlim(rx_sub)
ylim(rz_sub)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
xlim(ry_sub)
ylim(rz_sub)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cuboid Region: Get the data outside of the selected region (inverse selection):
```julia
clumps_subregion = subregion( clumps, :cuboid,
xrange=[-4., 0.],
yrange=[-15. ,15.],
zrange=[-2. ,2.],
center=[:boxcenter],
range_unit=:kpc,
inverse=true);
```
[Mera]: 2020-02-08T20:40:36.521
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :33.65234375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]);
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc, center=[:boxcenter]);
```
```julia
figure(figsize=(15.5, 3.5))
subplot(1,3,1)
scatter(x,y)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlim(rx_sub)
ylim(ry_sub)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx_sub)
ylim(rz_sub)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry_sub)
ylim(rz_sub)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

## Cylindrical Region
Extract the the clump positions and the extent of the full box:
```julia
clumps = getclumps(info);
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter]);
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
[Mera]: Get clump data: 2020-02-08T20:40:43.377
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
#### Cylindrical Region: The red lines show the region that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cylindrical Region: Cutout the data assigned to the object `clumps`
Select the ranges of the cylinder in the unit "kpc", relative to the given center [13., 24., 24.]. The height refers to both z-directions from the plane.
```julia
clumps_subregion = subregion( clumps, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[(24. -11.), :bc, :bc]); # direction=:z, by default
```
[Mera]: 2020-02-08T20:40:50.168
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :5.24609375 KB
-------------------------------------------------------
Extract the the clump positions of the subregion and the extent of the full box:
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter])
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cylindrical Region: Scatter-Plot of the selected data range with respect to the center of the sub-region:
```julia
x, y, z = getpositions(clumps_subregion, :kpc,
center=[ (24. -11.), :bc, :bc],
center_unit=:kpc);
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc,
center=[ (24. -11.), :bc, :bc],
center_unit=:kpc);
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 3. .* sin.(theta), 3 .* cos.(theta), color="red")
xlim(rx_sub)
ylim(ry_sub)
xlabel("kpc")
ylabel("kpc")
subplot(1,3,2)
scatter(x,z)
xlim(rx_sub)
ylim(rz_sub)
xlabel("kpc")
ylabel("kpc")
subplot(1,3,3)
scatter(y,z)
xlim(ry_sub)
ylim(rz_sub)
xlabel("kpc")
ylabel("kpc");
```

#### Cylindrical Region: Get the data outside of the selected region (inverse selection):
```julia
clumps_subregion = subregion( clumps, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[ (24. -11.),:bc,:bc],
inverse=true);
```
[Mera]: 2020-02-08T20:41:13.553
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :57.93359375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]);
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc, center=[:boxcenter]);
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

## Spherical Region
Extract the the clump positions and the extent of the full box:
```julia
clumps = getclumps(info);
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter]);
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
[Mera]: Get clump data: 2020-02-08T20:41:17.127
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
#### The red lines show the region that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]")
```

PyObject Text(871.9411764705884, 0.5, 'z [kpc]')
#### Spherical Region: Cutout the data assigned to the object `clumps`
Select the radius of the sphere in the unit "kpc", relative to the given center [13., 24., 24.]:
```julia
clumps_subregion = subregion( clumps, :sphere,
radius=10.,
range_unit=:kpc,
center=[ (24. -11.),:bc, :bc]);
```
[Mera]: 2020-02-08T20:41:21.728
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :28.68359375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # subregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Spherical Region: Scatter-Plot of the selected data range with respect to the center of the sub-region:
```julia
x, y, z = getpositions(clumps_subregion, :kpc,
center=[ (24. -11.), :bc, :bc],
center_unit=:kpc); # subregion
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc,
center=[(24. -11.), :bc, :bc],
center_unit=:kpc); # subregion
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta), 10 .* cos.(theta), color="red")
xlim(rx_sub)
ylim(ry_sub)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta), 10 .* cos.(theta), color="red")
xlim(rx_sub)
ylim(rz_sub)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta), 10 .* cos.(theta), color="red")
xlim(ry_sub)
ylim(rz_sub)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Spherical Region: Get the data outside of the selected region (inverse selection):
```julia
clumps_subregion = subregion( clumps, :sphere,
radius=10.,
range_unit=:kpc,
center=[ (24. -11.),:bc,:bc],
inverse=true);
```
[Mera]: 2020-02-08T20:41:43.641
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :34.49609375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]);
rx_sub, ry_sub, rz_sub = getextent(clumps_subregion, :kpc, center=[:boxcenter]);
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(ry)
xlabel("x [kpc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]")
```

PyObject Text(871.9411764705884, 0.5, 'z [kpc]')
## Combined/Nested/Shell Sub-Regions
#### The sub-region functions can be used in any combination with each other! (Combined with overlapping ranges or nested)
## Cylindrical Shell
Extract the the clump positions and the extent of the full box:
```julia
clumps = getclumps(info);
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter]);
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
[Mera]: Get clump data: 2020-02-08T20:41:52.553
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
#### The red lines show the shell that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red",ls = "--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cylindrical Shell:
Pass the height of the cylinder and the inner/outer radius of the shell in the unit "kpc", relative to the box center [24., 24., 24.]:
```julia
clumps_subregion = shellregion( clumps, :cylinder,
radius=[5.,10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter]);
```
[Mera]: 2020-02-08T20:42:00.413
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :18.55859375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # shellregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Cylindrical Shell: Get the data outside of the selected shell-region (inverse selection):
```julia
clumps_subregion = shellregion( clumps, :cylinder,
radius=[5.,10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-08T20:42:10.055
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :44.62109375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # shellregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

## Spherical Shell
Extract the the clump positions and the extent of the full box:
```julia
clumps = getclumps(info);
x, y, z = getpositions(clumps, :kpc, center=[:boxcenter]);
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]);
```
[Mera]: Get clump data: 2020-02-08T20:42:14.641
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
#### The red lines show the shell that we want to cut-out as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Spherical Shell:
Select the inner and outer radius of the spherical shell in unit "kpc", relative to the box center [24., 24., 24.]:
```julia
clumps_subregion = shellregion( clumps, :sphere,
radius=[5.,10.],
range_unit=:kpc,
center=[:boxcenter]);
```
[Mera]: 2020-02-08T20:42:19.499
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :18.55859375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # shellregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter]); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

#### Spherical Shell: Get the data outside of the selected shell-region (inverse selection):
```julia
clumps_subregion = shellregion( clumps, :sphere,
radius=[5.,10.],
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-08T20:42:23.949
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :44.62109375 KB
-------------------------------------------------------
```julia
x, y, z = getpositions(clumps_subregion, :kpc, center=[:boxcenter]); # shellregion
rx, ry, rz = getextent(clumps, :kpc, center=[:boxcenter] ); # full box
```
```julia
figure(figsize=(15.5, 3.5))
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
scatter(x,y)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(ry)
xlabel("x k[pc]")
ylabel("y [kpc]")
subplot(1,3,2)
scatter(x,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(rx)
ylim(rz)
xlabel("x [kpc]")
ylabel("z [kpc]")
subplot(1,3,3)
scatter(y,z)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlim(ry)
ylim(rz)
xlabel("y [kpc]")
ylabel("z [kpc]");
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 39131 | # 3. Hydro: Get Sub-Regions of The Loaded Data
## Load the Data
```julia
using Mera, PyPlot
using ColorSchemes
cmap = ColorMap(ColorSchemes.lajolla.colors) # See http://www.fabiocrameri.ch/colourmaps.php
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14")
gas = gethydro(info, :rho, lmax=10, smallr=1e-5);
```
[Mera]: 2020-02-18T23:23:22.753
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get hydro data: 2020-02-18T23:23:32.417
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1,) = (:rho,)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:02:49
Memory used for data table :186.1558656692505 MB
-------------------------------------------------------
## Cuboid Region
### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:03
The generated objects include, e.g. the extent of the processed domain, that can be used to declare the specific range of the plots, while the field `cextent` gives the extent related to a given center (default: [0.,0.,0.]).
```julia
propertynames(proj_z)
```
(:maps, :maps_unit, :maps_lmax, :maps_mode, :lmax_projected, :lmin, :lmax, :ranges, :extent, :cextent, :ratio, :boxlen, :smallr, :smallc, :scale, :info)
#### Cuboid Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cuboid Region: Cutout the data assigned to the object `gas`
Note: The selected regions can be given relative to a user given center or to the box corner [0., 0., 0.] by default. The user can choose between standard notation [0:1] (default) or physical length-units, defined in e.g. info.scale :
```julia
gas_subregion = subregion( gas, :cuboid,
xrange=[-4., 0.],
yrange=[-15., 15.],
zrange=[-2., 2.],
center=[:boxcenter],
range_unit=:kpc);
```
[Mera]: 2020-02-18T23:27:06.861
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :47.87415790557861 MB
-------------------------------------------------------
The function `subregion` creates a new object with the same type as the object created by the function `gethydro` :
```julia
typeof(gas_subregion)
```
HydroDataType
#### Cuboid Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cuboid Region: Get the data outside of the selected region (inverse selection):
```julia
gas_subregion = subregion( gas, :cuboid,
xrange=[-4., 0.],
yrange=[-15., 15.],
zrange=[-2., 2.],
center=[:boxcenter],
range_unit=:kpc,
inverse=true);
```
[Mera]: 2020-02-18T23:27:09.597
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :138.2824068069458 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:01
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Cylindrical Region
#### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:01
100%|███████████████████████████████████████████████████| Time: 0:00:01
#### Cylindrical Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cylindrical Region: Cutout the data assigned to the object `gas`
Select the ranges of the cylinder in the unit "kpc", relative to the given center [13., 24., 24.]. The height refers to both z-directions from the plane.
```julia
gas_subregion = subregion( gas, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[13., :bc, :bc]); # direction=:z, by default
```
[Mera]: 2020-02-18T23:27:24.715
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :9.945767402648926 MB
-------------------------------------------------------
#### Cylindrical Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Region: Projections of the sub-region rekated ti a given data center:
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, direction=:z, center=[13., 24.,24.], range_unit=:kpc, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, direction=:y, center=[13., 24.,24.], range_unit=:kpc, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, direction=:x, center=[13., 24.,24.], range_unit=:kpc, verbose=false);
```
#### The ranges of the plots are now adapted to the given data center:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta), 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Region: Get the data outside of the selected region (inverse selection):
```julia
gas_subregion = subregion( gas, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[13.,:bc,:bc],
inverse=true); # direction=:z, by default
```
[Mera]: 2020-02-18T23:27:29.071
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :176.2107973098755 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, :Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Spherical Region
### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:01
#### Spherical Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Region: Cutout the data assigned to the object `gas`
Select the radius of the sphere in the unit "kpc", relative to the given center [13., 24., 24.]:
```julia
gas_subregion = subregion( gas, :sphere,
radius=10.,
range_unit=:kpc,
center=[13.,:bc,:bc]);
```
[Mera]: 2020-02-18T23:27:42.261
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :57.03980731964111 MB
-------------------------------------------------------
#### Spherical Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Region: Get the data outside of the selected region (inverse selection):
```julia
gas_subregion = subregion( gas, :sphere,
radius=10.,
range_unit=:kpc,
center=[13.,:bc,:bc],
inverse=true);
```
[Mera]: 2020-02-18T23:27:46.433
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :129.1167573928833 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Combined/Nested/Shell Sub-Regions
#### The sub-region functions can be used in any combination with each other! (Combined with overlapping or nested ranges)
One Example:
```julia
comb_region = subregion(gas, :cuboid, xrange=[-8.,8.], yrange=[-8.,8.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc, verbose=false)
comb_region2 = subregion(comb_region, :sphere, radius=12., center=[40.,24.,24.], range_unit=:kpc, inverse=true, verbose=false)
comb_region3 = subregion(comb_region2, :sphere, radius=12., center=[8.,24.,24.], range_unit=:kpc, inverse=true, verbose=false);
comb_region4 = subregion(comb_region3, :sphere, radius=12., center=[24.,5.,24.], range_unit=:kpc, inverse=true, verbose=false);
comb_region5 = subregion(comb_region4, :sphere, radius=12., center=[24.,43.,24.], range_unit=:kpc, inverse=true, verbose=false);
```
```julia
proj_z = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

## Cylindrical Shell
#### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:02
#### Cylindrical Shell: The red lines show the shell that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cylindrical Shell:
Pass the height of the cylinder and the inner/outer radius of the shell in the unit "kpc", relative to the box center [24., 24., 24.]:
```julia
gas_subregion = shellregion( gas, :cylinder,
radius=[5., 10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter]);
```
[Mera]: 2020-02-18T23:28:03.834
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :53.790066719055176 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Shell: Get the data outside of the selected shell (inverse selection):
```julia
gas_subregion = shellregion(gas, :cylinder,
radius=[5., 10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-18T23:28:06.945
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :132.36649799346924 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Spherical Shell
#### Create projections of the full box:
```julia
proj_z = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
100%|███████████████████████████████████████████████████| Time: 0:00:02
100%|███████████████████████████████████████████████████| Time: 0:00:02
100%|███████████████████████████████████████████████████| Time: 0:00:01
#### Spherical Shell: The red lines show the shell that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red",ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Shell:
Select the inner and outer radius of the spherical shell in unit "kpc", relative to the box center [24., 24., 24.]:
```julia
gas_subregion = shellregion(gas, :sphere,
radius=[5., 10.],
range_unit=:kpc,
center=[24.,24.,24.]);
```
[Mera]: 2020-02-18T23:28:21.357
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :56.55305194854736 MB
-------------------------------------------------------
#### Spherical Shell: Projections of the shell-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Shell: Get the data outside of the selected shell-region (inverse selection):
```julia
gas_subregion = shellregion(gas, :sphere,
radius=[5., 10.],
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-18T23:28:25.267
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :129.60351276397705 MB
-------------------------------------------------------
```julia
proj_z = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, verbose=false);
proj_x = projection(gas_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 39330 | # 3. Particles: Get Sub-Regions of Loaded the Data
## Load the Data
```julia
using Mera, PyPlot
using ColorSchemes
cmap = ColorMap(ColorSchemes.lajolla.colors) # See http://www.fabiocrameri.ch/colourmaps.php
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
particles = getparticles(info, :mass);
```
[Mera]: 2020-02-18T23:29:31.468
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get particle data: 2020-02-18T23:29:46.476
Key vars=(:level, :x, :y, :z, :id)
Using var(s)=(4,) = (:mass,)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...100%|████████████████████████████████████| Time: 0:00:03
Found 5.089390e+05 particles
Memory used for data table :19.4152889251709 MB
-------------------------------------------------------
## Cuboid Region
### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
The generated objects include, e.g. the extent of the processed domain, that can be used to declare the specific range of the plots, while the field cextent gives the extent related to a given center (default: [0.,0.,0.]).
```julia
propertynames(proj_z)
```
(:maps, :maps_unit, :maps_lmax, :maps_mode, :lmax_projected, :lmin, :lmax, :ref_time, :ranges, :extent, :cextent, :ratio, :boxlen, :scale, :info)
#### Cuboid Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cuboid Region: Cutout the data assigned to the object `particles`
Note: The selected regions can be given relative to a user given center or to the box corner [0., 0., 0.] by default. The user can choose between standard notation [0:1] (default) or physical length-units, defined in e.g. info.scale :
```julia
part_subregion = subregion( particles, :cuboid,
xrange=[-4., 0.],
yrange=[-15. ,15.],
zrange=[-2. ,2.],
center=[:boxcenter],
range_unit=:kpc );
```
[Mera]: 2020-02-18T23:30:10.393
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :10.259977340698242 MB
-------------------------------------------------------
The function `subregion` creates a new object with the same type as the object created by the function `getparticles` :
```julia
typeof(part_subregion)
```
PartDataType
#### Cuboid Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=10, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=10, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=10, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cuboid Region: Get the data outside of the selected region (inverse selection):
```julia
part_subregion = subregion( particles, :cuboid,
xrange=[-4., 0.],
yrange=[-15. ,15.],
zrange=[-2. ,2.],
center=[24.,24.,24.],
range_unit=:kpc,
inverse=true);
```
[Mera]: 2020-02-18T23:30:12.491
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.4166667 :: 0.5 ==> 20.0 [kpc] :: 24.0 [kpc]
ymin::ymax: 0.1875 :: 0.8125 ==> 9.0 [kpc] :: 39.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Memory used for data table :9.156118392944336 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-15.,-15.,15.,15.,-15.], color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-4.,0.,0.,-4.,-4.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-15.,15.,15.,-15.,-15.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Cylindrical Region
#### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
#### Cylindrical Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cylindrical Region: Cutout the data assigned to the object `particles`
Select the ranges of the cylinder in the unit "kpc", relative to the given center [13., 24., 24.]. The height refers to both z-directions from the plane.
```julia
part_subregion = subregion(particles, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[13.,:bc,:bc],
direction=:z);
```
[Mera]: 2020-02-18T23:30:15.671
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :578.951171875 KB
-------------------------------------------------------
#### Cylindrical Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=10, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=10, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=10, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext = L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Region: Projections of the sub-region py passing a different center:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, direction=:z, center=[13., 24.,24.], range_unit=:kpc, lmax=10, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, direction=:y, center=[13., 24.,24.], range_unit=:kpc, lmax=10, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, direction=:x, center=[13., 24.,24.], range_unit=:kpc, lmax=10, verbose=false);
```
#### The ranges of the plots are now adapted to the given data center:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta), 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Region: Get the data outside of the selected region (inverse selection):
```julia
part_subregion = subregion(particles, :cylinder,
radius=3.,
height=2.,
range_unit=:kpc,
center=[ (24. -11.),:bc,:bc],
direction=:z,
inverse=true);
```
[Mera]: 2020-02-18T23:30:19.162
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2083333 :: 0.3333333 ==> 10.0 [kpc] :: 16.0 [kpc]
ymin::ymax: 0.4375 :: 0.5625 ==> 21.0 [kpc] :: 27.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Radius: 3.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :18.8507137298584 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 3. .* sin.(theta) .-11, 3 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.] .-11.,[-2.,-2.,2.,2.,-2.], color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-3.,3.,3.,-3.,-3.],[-2.,-2.,2.,2.,-2.], color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Spherical Region
### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
#### Spherical Region: The red lines show the region that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Region: Cutout the data assigned to the object `particles`
Select the radius of the sphere in the unit "kpc", relative to the given center [13., 24., 24.]:
```julia
part_subregion = subregion( particles, :sphere,
radius=10.,
range_unit=:kpc,
center=[(24. -11.),24.,24.]);
```
[Mera]: 2020-02-18T23:30:22.122
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :8.807950973510742 MB
-------------------------------------------------------
#### Spherical Region: Projections of the sub-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Region: Get the data outside of the selected region (inverse selection):
```julia
part_subregion = subregion( particles, :sphere,
radius=10.,
range_unit=:kpc,
center=[(24. -11.),24.,24.],
inverse=true);
```
[Mera]: 2020-02-18T23:30:23.142
center: [0.2708333, 0.5, 0.5] ==> [13.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.0625 :: 0.4791667 ==> 3.0 [kpc] :: 23.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Radius: 10.0 [kpc]
Memory used for data table :10.608144760131836 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) .-11., 10 .* cos.(theta), color="red")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Combined/Nested/Shell Sub-Regions
#### The sub-region and shell functions can be used in any combination with each other! (Combined with overlapping ranges or nested)
One Example:
```julia
comb_region = subregion(particles, :cuboid, xrange=[-8.,8.], yrange=[-8.,8.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc, verbose=false)
comb_region2 = subregion(comb_region, :sphere, radius=12., center=[40.,24.,24.], range_unit=:kpc, inverse=true, verbose=false)
comb_region3 = subregion(comb_region2, :sphere, radius=12., center=[8.,24.,24.], range_unit=:kpc, inverse=true, verbose=false);
comb_region4 = subregion(comb_region3, :sphere, radius=12., center=[24.,5.,24.], range_unit=:kpc, inverse=true, verbose=false);
comb_region5 = subregion(comb_region4, :sphere, radius=12., center=[24.,43.,24.], range_unit=:kpc, inverse=true, verbose=false);
```
```julia
proj_z = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, verbose=false);
proj_y = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter],direction=:y, verbose=false);
proj_x = projection(comb_region5, :sd, unit=:Msol_pc2, center=[:boxcenter],direction=:x, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = LinRange(-pi, pi, 100)
subplot(1,3,1)
im = imshow( log10.(permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.(permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

## Cylindrical Shell
#### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
#### Cylindrical Shell: The red lines show the shell we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.(permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Cylindrical Shell:
Pass the height of the cylinder and the inner/outer radius of the shell in the unit "kpc", relative to the box center [24., 24., 24.]:
```julia
part_subregion = shellregion( particles, :cylinder,
radius=[5.,10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter]);
```
[Mera]: 2020-02-18T23:30:28.41
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :7.282835006713867 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, orientation="horizontal", label=labeltext, pad=0.2);
```

#### Cylindrical Shell: Get the data outside of the selected shell (inverse selection):
```julia
part_subregion = shellregion( particles, :cylinder,
radius=[5.,10.],
height=2.,
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-18T23:30:30.228
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Height: 2.0 [kpc]
Memory used for data table :12.133260726928711 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot([-10.,-10.,10.,10.,-10.], [-2.,2.,2.,-2.,-2.], color="red")
plot([-5.,-5,5.,5.,-5.], [-2.,2.,2.,-2.,-2.], color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

<a id="ShellRegionSphere"></a>
## Spherical Shell
#### Create projections of the full box:
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(particles, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
#### Spherical Shell: The red lines show the shell that we want to cutout as a sub-region from the full data:
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red",ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Shell:
Select the inner and outer radius of the spherical shell in unit "kpc", relative to the box center [24., 24., 24.]:
```julia
part_subregion = shellregion( particles, :sphere,
radius=[5.,10.],
range_unit=:kpc,
center=[24.,24.,24.]);
```
[Mera]: 2020-02-18T23:30:34.32
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :7.592016220092773 MB
-------------------------------------------------------
#### Spherical Shell: Projections of the shell-region.
The coordinates center is the center of the box:
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red",ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red",ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

#### Spherical Shell: Get the data outside of the selected shell-region (inverse selection):
```julia
part_subregion = shellregion( particles, :sphere,
radius=[5.,10.],
range_unit=:kpc,
center=[:boxcenter],
inverse=true);
```
[Mera]: 2020-02-18T23:30:35.378
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
Inner radius: 5.0 [kpc]
Outer radius: 10.0 [kpc]
Radius diff: 5.0 [kpc]
Memory used for data table :11.824079513549805 MB
-------------------------------------------------------
```julia
proj_z = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:z, lmax=8, verbose=false);
proj_y = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:y, lmax=8, verbose=false);
proj_x = projection(part_subregion, :sd, unit=:Msol_pc2, center=[:boxcenter], direction=:x, lmax=8, verbose=false);
```
```julia
figure(figsize=(15.5, 3.5))
labeltext=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}"
theta = range(-pi, stop=pi, length=100)
subplot(1,3,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd]) ), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,2)
im = imshow( log10.( permutedims(proj_y.maps[:sd]) ), cmap=cmap, aspect=proj_y.ratio, origin="lower", extent=proj_y.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext)
subplot(1,3,3)
im = imshow( log10.( permutedims(proj_x.maps[:sd]) ), cmap=cmap, aspect=proj_x.ratio, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
plot( 10. .* sin.(theta) , 10 .* cos.(theta), color="red")
plot( 5. .* sin.(theta) , 5. .* cos.(theta), color="red", ls="--")
xlabel("y [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=labeltext);
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 27093 | # 5. Mask/Select/Map/Filter/Metaprogramming...
- Learn how to extract data from the data table with JuliaDB and Mera functions
- Filter the data table according to one or several conditions
- Extract data from a filtered data table and use it for further calculations
- Extend the data table with new columns/variables
- Mask data with different methods and apply it to some functions
## Load The Data
```julia
using Mera
info = getinfo(400, "../../testing/simulations/manu_sim_sf_L14");
gas = gethydro(info, lmax=8, smallr=1e-5);
particles = getparticles(info)
clumps = getclumps(info);
```
[Mera]: 2020-02-08T20:56:19.834
Code: RAMSES
output [400] summary:
mtime: 2018-09-05T09:51:55.041
ctime: 2019-11-01T17:35:21.051
=======================================================
simulation time: 594.98 [Myr]
boxlen: 48.0 [kpc]
ncpu: 2048
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 14 --> cellsize(s): 750.0 [pc] - 2.93 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :thermal_pressure, :passive_scalar_1, :passive_scalar_2)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Npart: 5.091500e+05
- Nstars: 5.066030e+05
- Ndm: 2.547000e+03
particle variables: (:vx, :vy, :vz, :mass, :birth)
-------------------------------------------------------
clumps: true
clump-variables: (:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance)
-------------------------------------------------------
namelist-file: false
timer-file: false
compilation-file: true
makefile: true
patchfile: true
=======================================================
[Mera]: Get hydro data: 2020-02-08T20:56:27.064
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:02:07
Memory used for data table :71.28007793426514 MB
-------------------------------------------------------
[Mera]: Get particle data: 2020-02-08T20:58:39.435
Key vars=(:level, :x, :y, :z, :id)
Using var(s)=(1, 2, 3, 4, 5) = (:vx, :vy, :vz, :mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Found 5.089390e+05 particles
Memory used for data table :34.947275161743164 MB
-------------------------------------------------------
[Mera]: Get clump data: 2020-02-08T20:58:41.769
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Read 12 colums:
Symbol[:index, :lev, :parent, :ncell, :peak_x, :peak_y, :peak_z, Symbol("rho-"), Symbol("rho+"), :rho_av, :mass_cl, :relevance]
Memory used for data table :61.77734375 KB
-------------------------------------------------------
## Select From Data Table
### Select a single column/variable
##### By using JuliaDB or Mera functions
```julia
using JuliaDB
```
The JuliaDB data table is stored in the `data`-field of any `DataSetType`. Extract an existing column (variable):
```julia
select(gas.data, :rho) # JuliaDB
```
849332-element Array{Float64,1}:
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
⋮
0.00010967104288285959
0.0001088040126114162
0.00010915603617815434
0.00010917096551347797
0.00012465438542871006
0.00011934527871880502
0.00011294656300014925
0.00011110068692986109
0.00010901341218606515
0.00010849404903183988
0.00010900588395976569
0.00010910219163333514
Pass the entire `DataSetType` (here `gas`) to the Mera function `getvar` to extract the selected variable or derived quantity from the data table.
Call `getvar()` to get a list of the predefined quantities.
```julia
getvar(gas, :rho) # MERA
```
849332-element Array{Float64,1}:
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
⋮
0.00010967104288285959
0.0001088040126114162
0.00010915603617815434
0.00010917096551347797
0.00012465438542871006
0.00011934527871880502
0.00011294656300014925
0.00011110068692986109
0.00010901341218606515
0.00010849404903183988
0.00010900588395976569
0.00010910219163333514
### Select several columns
By selecting several columns a new JuliaDB databse is returned:
```julia
select(gas.data, (:rho, :level)) #JuliaDB
```
Table with 849332 rows, 2 columns:
rho level
──────────────────
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
1.0e-5 6
⋮
0.000108804 8
0.000109156 8
0.000109171 8
0.000124654 8
0.000119345 8
0.000112947 8
0.000111101 8
0.000109013 8
0.000108494 8
0.000109006 8
0.000109102 8
The getvar function returns a dictionary containing the extracted arrays:
```julia
getvar(gas, [:rho, :level]) # MERA
```
Dict{Any,Any} with 2 entries:
:level => [6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0, 6.0 … 8.0, 8.0, 8.0…
:rho => [1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.…
Select one or more columns and get a tuple of vectors:
```julia
vtuple = columns(gas.data, (:rho, :level)) # JuliaDB
```
(rho = [1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5, 1.0e-5 … 0.00010915603617815434, 0.00010917096551347797, 0.00012465438542871006, 0.00011934527871880502, 0.00011294656300014925, 0.00011110068692986109, 0.00010901341218606515, 0.00010849404903183988, 0.00010900588395976569, 0.00010910219163333514], level = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6 … 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
```julia
propertynames(vtuple)
```
(:rho, :level)
```julia
vtuple.rho
```
849332-element Array{Float64,1}:
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
1.0e-5
⋮
0.00010967104288285959
0.0001088040126114162
0.00010915603617815434
0.00010917096551347797
0.00012465438542871006
0.00011934527871880502
0.00011294656300014925
0.00011110068692986109
0.00010901341218606515
0.00010849404903183988
0.00010900588395976569
0.00010910219163333514
## Filter by Condition
### With JuliaDB (example A)
Get all the data corresponding to cells/rows with level=6. Here, the variable `p` is used as placeholder for rows. A new JuliaDB data table is returend:
```julia
filtered_db = filter(p->p.level==6, gas.data ) # JuliaDB
# see the reduced row number
```
Table with 240956 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### With Macro Expression (example A)
(see the documentation at: <https://piever.github.io/JuliaDBMeta.jl/stable/> )
```julia
using JuliaDBMeta
```
┌ Info: Precompiling JuliaDBMeta [2c06ca41-a429-545c-b8f0-5ca7dd64ba19]
└ @ Base loading.jl:1273
```julia
filtered_db = @filter gas.data :level==6 # JuliaDBMeta
```
Table with 240956 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### With JuliaDB (example B)
Get all cells/rows with densities >= 3 Msol/pc^3. Since the data is given in code units, we need to convert from the given physical units:
```julia
density = 3. / gas.scale.Msol_pc3
filtered_db = filter(p->p.rho>= density, gas.data ) # JuliaDB
```
Table with 210 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### With Macro Expression (example B)
```julia
density = 3. /gas.scale.Msol_pc3
filtered_db = @filter gas.data :rho>= density # JuliaDBMeta
```
Table with 210 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
### Get a Quantity/Variable from The Filtered Data Table
Calculate the mass for each cell and the sum:
```julia
mass_tot = getvar(gas, :mass, :Msol) # the full data table
sum(mass_tot)
```
3.0968754148332745e10
The same calculation is possible for the filtered data base which has to be passed together with the original object, here: `gas`
```julia
mass_filtered_tot = getvar(gas, :mass, :Msol, filtered_db=filtered_db) # the filtered data table
sum(mass_filtered_tot)
```
1.4862767967535206e10
### Create a New DataSetType from a Filtered Data Table
A new `DataSetType` can be constructed for the filtered data table that can be passed to the functions.
```julia
density = 3. /gas.scale.Msol_pc3
filtered_db = @filter gas.data :rho >= density
gas_new = construct_datatype(filtered_db, gas);
```
```julia
# Both are now of HydroDataType and include the same information about the simulation properties (besides the canged data table)
println( typeof(gas) )
println( typeof(gas_new) )
```
HydroDataType
HydroDataType
```julia
mass_filtered_tot = getvar(gas_new, :mass, :Msol)
sum(mass_filtered_tot)
```
1.4862767967535206e10
## Filter by Multiple Conditions
### With JuliaDB
Get the mass of all cells/rows with densities >= 3 Msol/pc^3 that is within the disk radius of 3 kpc and 2 kpc from the plane:
```julia
boxlen = info.boxlen
cv = boxlen/2. # box-center
density = 3. /gas.scale.Msol_pc3
radius = 3. /gas.scale.kpc
height = 2. /gas.scale.kpc
# filter cells/rows that contain rho greater equal density
filtered_db = filter(p->p.rho >= density, gas.data )
# filter cells/rows lower equal the defined radius and height
# (convert the cell number to a position according to its cellsize and relative to the box center)
filtered_db = filter(row-> sqrt( (row.cx * boxlen /2^row.level - cv)^2 + (row.cy * boxlen /2^row.level - cv)^2) <= radius &&
abs(row.cz * boxlen /2^row.level - cv) <= height, filtered_db)
var_filtered = getvar(gas, :mass, filtered_db=filtered_db, unit=:Msol)
sum(var_filtered) # [Msol]
```
2.750632450062189e9
### Use Pipeline Macros
```julia
boxlen = info.boxlen
cv = boxlen/2.
density = 3. /gas.scale.Msol_pc3
radius = 3. /gas.scale.kpc
height = 2. /gas.scale.kpc
filtered_db = @apply gas.data begin
@where :rho >= density
@where sqrt( (:cx * boxlen/2^:level - cv)^2 + (:cy * boxlen/2^:level - cv)^2 ) <= radius
@where abs(:cz * boxlen/2^:level -cv) <= height
end
var_filtered = getvar(gas, :mass, filtered_db=filtered_db, unit=:Msol)
sum(var_filtered) # [Msol]
```
2.750632450062189e9
### External Functions With JuliaDB
```julia
boxlen = info.boxlen
function r(x,y,level,boxlen)
return sqrt((x * boxlen /2^level - boxlen/2.)^2 + (y * boxlen /2^level - boxlen/2.)^2)
end
function h(z,level,boxlen)
return abs(z * boxlen /2^level - boxlen/2.)
end
density = 3. /gas.scale.Msol_pc3
radius = 3. /gas.scale.kpc
height = 2. /gas.scale.kpc
filtered_db = filter(row-> row.rho >= density &&
r(row.cx,row.cy, row.level, boxlen) <= radius &&
h(row.cz,row.level, boxlen) <= height, gas.data)
var_filtered = getvar(gas, :mass, filtered_db=filtered_db, unit=:Msol)
sum(var_filtered) # [Msol]
```
2.750632450062189e9
### External Functions With Macro Expression
```julia
boxlen = info.boxlen
cv = boxlen/2.
density = 3. /gas.scale.Msol_pc3
radius = 3. /gas.scale.kpc
height = 2. /gas.scale.kpc
function p(val, level, boxlen)
cv = boxlen/2
return val * boxlen /2^level - cv
end
filtered_db = @apply gas.data begin
@where :rho >= density
@where sqrt( p(:cx, :level, boxlen)^2 + p(:cy, :level, boxlen)^2 ) <= radius
@where abs( p(:cz, :level, boxlen) ) <= height
end
var_filtered = getvar(gas, :mass, filtered_db=filtered_db, unit=:Msol)
sum(var_filtered) # [Msol]
```
2.750632450062189e9
### Compare With Predefined Functions
Compare the previous calculations with the predefined `subregion` function:
The `subregion` function takes the intersected cells of the range borders into account (default):
```julia
density = 3. /gas.scale.Msol_pc3 # in code units
sub_region = subregion(gas, :cylinder, radius=3., height=2., center=[:boxcenter], range_unit=:kpc, verbose=false ) # default: cell=true
filtered_db = @filter sub_region.data :rho >= density
var_filtered = getvar(gas, :mass, :Msol, filtered_db=filtered_db)
sum(var_filtered) # [Msol]
```
2.9388306102361355e9
By setting the keyword `cell=false`, only the cell-centres within the defined region are taken into account (as in the calculations in the previous section).
```julia
density = 3. /gas.scale.Msol_pc3 # in code units
sub_region = subregion(gas, :cylinder, radius=3., height=2., center=[:boxcenter], range_unit=:kpc, cell=false, verbose=false )
filtered_db = @filter sub_region.data :rho >= density
var_filtered = getvar(gas, :mass, :Msol, filtered_db=filtered_db)
sum(var_filtered)
```
2.750632450062189e9
## Extend the Data Table
Add costum columns/variables to the data that can be automatically processed in some functions:
(note: to take advantage of the Mera unit management, store new data in code-units)
```julia
# calculate the Mach number in each cell
mach = getvar(gas, :mach);
```
```julia
# add the extracted Mach number (1dim-array) to the data in the object "gas"
# the array has the same length and order (rows/cells) as in the data table
# push a column at the end of the table:
# transform(data-table, key => new-data)
gas.data = transform(gas.data, :mach => mach) # JuliaDB
```
Table with 849332 rows, 12 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
12 mach Float64
```julia
proj_z = projection(gas, :mach, xrange=[-8.,8.], yrange=[-8.,8.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc);
```
[Mera]: 2020-02-08T20:59:42.246
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.3333333 :: 0.6666667 ==> 16.0 [kpc] :: 32.0 [kpc]
ymin::ymax: 0.3333333 :: 0.6666667 ==> 16.0 [kpc] :: 32.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:mach, :sd)
100%|███████████████████████████████████████████████████| Time: 0:00:07
```julia
using PyPlot
imshow( ( permutedims(proj_z.maps[:mach]) ), origin="lower", extent=proj_z.cextent)
colorbar();
```

Remove the column :mach from the table:
```julia
gas.data = select(gas.data, Not(:mach)) # select all columns, not :mach
```
Table with 849332 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
## Masking
Many functions in **MERA** provide the opportunity to use a mask on selected data without changing the content in the data table. Here we present several methods to prepare a mask and apply it to some functions. A created mask is an array of type: `MaskType`, which can be Array{Bool,1} or BitArray{1}. A masked cell/row corresponds to a **false**.
#### Version 1: External Function
Create an array which represents the cells with the selected condition by true.
The function checks if the following requirement is true or false for each row/cell in the data table:
```julia
function ftest(value)
density = (4. / gas.scale.Msol_pc3)
if value < density
return true
else
return false
end
end
mask_v1 = map(row->ftest(row.rho), gas.data);
println( length(mask_v1) )
println( typeof(mask_v1) )
```
849332
Array{Bool,1}
#### Version 2: Short Syntax
##### Example 1
```julia
mask_v2 = map(row->row.rho < 4. / gas.scale.Msol_pc3, gas.data);
println( length(mask_v2) )
println( typeof(mask_v2) )
```
849332
Array{Bool,1}
##### Example 2
```julia
mask_v2b = getvar(gas, :rho, :Msol_pc3) .> 1. ;
println( length(mask_v2b) )
println( typeof(mask_v2b) )
```
849332
BitArray{1}
#### Version 3: Longer Syntax
```julia
rho_array = select(gas.data, :rho);
mask_v3 = rho_array .< 1. / gas.scale.Msol_pc3;
println( length(mask_v3) )
println( typeof(mask_v3) )
```
849332
BitArray{1}
#### Combine Multiple Masks
```julia
# create individual masks for different density and temperature regions
mask_h = getvar(gas, :rho, :nH) .< 10. # cm-3
mask_l = getvar(gas, :rho, :nH) .> 1e-2 # cm-3
mask_T1 = getvar(gas, :Temperature, :K) .< 1e4 # K
mask_T2 = getvar(gas, :Temperature, :K) .> 1e3 # K
# combine several masks to one
mask_tot = mask_h .* mask_l .* mask_T1 .* mask_T2
println( length(mask_tot) )
println( typeof(mask_tot) )
```
28320979
BitVector
### Some Functions With Masking Functionality
The masked rows are not considered in the calculations (mask-element = false ).
### Examples
### Total Mass
```julia
mask = map(row->row.rho < 1. / gas.scale.Msol_pc3, gas.data);
mtot_masked = msum(gas, :Msol, mask=mask)
mtot = msum(gas, :Msol)
println()
println( "Gas Mtot masked: ", mtot_masked , " Msol" )
println( "Gas Mtot: ", mtot , " Msol" )
println()
```
Gas Mtot masked: 1.336918953133308e10 Msol
Gas Mtot: 3.0968754148332745e10 Msol
```julia
mask = map(row->row.birth < 100. / particles.scale.Myr, particles.data);
mtot_masked = msum(particles, :Msol, mask=mask)
mtot = msum(particles, :Msol)
println()
println( "Particles Mtot masked: ", mtot_masked , " Msol" )
println( "Particles Mtot: ", mtot , " Msol" )
println()
```
Particles Mtot masked: 1.4537556611888414e7 Msol
Particles Mtot: 5.804426008528437e9 Msol
```julia
mask = map(row->row.mass_cl < 1e6 / clumps.scale.Msol, clumps.data);
mtot_masked = msum(clumps, :Msol, mask=mask)
mtot = msum(clumps, :Msol)
println()
println( "Clumps Mtot masked: ", mtot_masked , " Msol" )
println( "Clumps Mtot: ", mtot , " Msol" )
println()
```
Clumps Mtot masked: 2.926390055686605e7 Msol
Clumps Mtot: 1.3743280681841677e10 Msol
### Center-Of-Mass
```julia
mask = map(row->row.rho < 100. / gas.scale.nH, gas.data);
com_gas_masked = center_of_mass(gas, :kpc, mask=mask)
com_gas = center_of_mass(gas, :kpc)
println()
println( "Gas COM masked: ", com_gas_masked , " kpc" )
println( "Gas COM: ", com_gas , " kpc" )
println()
```
Gas COM masked: (23.632781376611646, 24.017935187730938, 24.078280687627124) kpc
Gas COM: (23.47221401632259, 23.93931869865653, 24.08483637116779) kpc
```julia
mask = map(row->row.birth < 100. / particles.scale.Myr, particles.data);
com_particles_masked = center_of_mass(particles, :kpc, mask=mask)
com_particles = center_of_mass(particles, :kpc)
println()
println( "Particles COM masked: ", com_particles_masked , " kpc" )
println( "Particles COM: ", com_particles , " kpc" )
println()
```
Particles COM masked: (22.766374936557934, 24.817294529838456, 24.020065595650212) kpc
Particles COM: (22.891354761211332, 24.174147282680273, 24.003205056545575) kpc
```julia
# calculate joint center-of-mass from gas and particles
mask1 = map(row->row.rho < 100. / gas.scale.nH, gas.data); # mask for the hydro data
mask2 = map(row->row.birth < 100. / particles.scale.Myr, particles.data); # mask for the particle data
println( "Joint COM (Gas + Particles) masked: ", center_of_mass([gas,particles], :kpc, mask=[mask1, mask2]) , " kpc" )
println( "Joint COM (Gas + Particles): ", center_of_mass([gas,particles], :kpc) , " kpc" )
```
Joint COM (Gas + Particles) masked: (23.632014753139174, 24.01864248583754, 24.078229177095928) kpc
Joint COM (Gas + Particles): (23.380528865533876, 23.976384982693947, 24.07195135758772) kpc
```julia
mask = map(row->row.mass_cl < 1e6 / clumps.scale.Msol, clumps.data);
com_clumps_masked = center_of_mass(clumps, mask=mask)
com_clumps = center_of_mass(clumps)
println()
println( "Clumps COM masked:", com_clumps_masked .* clumps.scale.kpc, " kpc" )
println( "Clumps COM: ", com_clumps .* clumps.scale.kpc, " kpc" )
println()
```
Clumps COM masked:(22.979676622296815, 23.22447986984898, 24.11056806473746) kpc
Clumps COM: (23.135765457064576, 23.741712325649264, 24.0050127185862) kpc
### Bulk-Velocity
```julia
mask = map(row->row.rho < 100. / gas.scale.nH, gas.data);
bv_gas_masked = bulk_velocity(gas, :km_s, mask=mask)
bv_gas = bulk_velocity(gas, :km_s)
println()
println( "Gas bulk velocity masked: ", bv_gas_masked , " km/s" )
println( "Gas bulk velocity: ", bv_gas , " km/s" )
println()
```
Gas bulk velocity masked: (-0.046336703401138456, -6.60993479840688, -1.000280146674773) km/s
Gas bulk velocity: (-1.1999253584798182, -10.678485153330122, -0.44038538452508785) km/s
```julia
mask = map(row->row.birth < 100. / particles.scale.Myr, particles.data);
bv_particles_masked = bulk_velocity(particles, :km_s, mask=mask)
bv_particles = bulk_velocity(particles, :km_s)
println()
println( "Particles bulk velocity masked: ", bv_particles_masked , " km/s" )
println( "Particles bulk velocity: ", bv_particles , " km/s" )
println()
```
Particles bulk velocity masked: (-27.702254113836513, -7.532075727552787, -1.3273993940211153) km/s
Particles bulk velocity: (-11.623422700314535, -18.440572802490234, -0.3291927731417528) km/s
### Weighted Statistics
(It is also possible to use the mask within the `getvar` function)
```julia
maskgas = map(row->row.rho < 100. / gas.scale.nH, gas.data);
maskpart = map(row->row.birth < 100. / particles.scale.Myr, particles.data);
maskclump = map(row->row.mass_cl < 1e7 / clumps.scale.Msol, clumps.data);
stats_gas_masked = wstat( getvar(gas, :vx, :km_s), weight=getvar(gas, :mass ), mask=maskgas);
stats_particles_masked = wstat( getvar(particles, :vx, :km_s), weight=getvar(particles, :mass ), mask=maskpart);
stats_clumps_masked = wstat( getvar(clumps, :peak_x, :kpc ), weight=getvar(clumps, :mass_cl), mask=maskclump) ;
println( "Gas <vx>_cells masked : ", stats_gas_masked.mean, " km/s (mass weighted)" )
println( "Particles <vx>_particles masked : ", stats_particles_masked.mean, " km/s (mass weighted)" )
println( "Clumps <peak_x>_clumps masked : ", stats_clumps_masked.mean, " kpc (mass weighted)" )
println()
```
Gas <vx>_cells masked : -0.04633670340114798 km/s (mass weighted)
Particles <vx>_particles masked : -27.702254113836517 km/s (mass weighted)
Clumps <peak_x>_clumps masked : 22.907689025275953 kpc (mass weighted)
```julia
stats_gas = wstat( getvar(gas, :vx, :km_s), weight=getvar(gas, :mass ));
stats_particles = wstat( getvar(particles, :vx, :km_s), weight=getvar(particles, :mass ));
stats_clumps = wstat( getvar(clumps, :peak_x, :kpc ), weight=getvar(clumps, :mass_cl)) ;
println( "Gas <vx>_allcells : ", stats_gas.mean, " km/s (mass weighted)" )
println( "Particles <vx>_allparticles : ", stats_particles.mean, " km/s (mass weighted)" )
println( "Clumps <peak_x>_allclumps : ", stats_clumps.mean, " kpc (mass weighted)" )
println()
```
Gas <vx>_allcells : -1.199925358479736 km/s (mass weighted)
Particles <vx>_allparticles : -11.623422700314544 km/s (mass weighted)
Clumps <peak_x>_allclumps : 23.13576545706458 kpc (mass weighted)
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 41376 | # 6. Hydro: Projections
## Load The Data
```julia
using Mera
info = getinfo(300, "../../testing/simulations/mw_L10");
gas = gethydro(info, lmax=10);
```
[Mera]: 2023-04-10T12:05:52.163
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
[Mera]: Get hydro data: 2023-04-10T12:05:52.197
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1, 2, 3, 4, 5, 6, 7) = (:rho, :vx, :vy, :vz, :p, :var6, :var7)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
Progress: 100%|█████████████████████████████████████████| Time: 0:00:23
Memory used for data table :2.3210865957662463 GB
-------------------------------------------------------
```julia
gas.data
```
Table with 28320979 rows, 11 columns:
Columns:
# colname type
────────────────────
1 level Int64
2 cx Int64
3 cy Int64
4 cz Int64
5 rho Float64
6 vx Float64
7 vy Float64
8 vz Float64
9 p Float64
10 var6 Float64
11 var7 Float64
## Projection of Predefined Quantities
See the possible variables:
```julia
projection()
```
Predefined vars for projections:
------------------------------------------------
=====================[gas]:=====================
-all the non derived hydro vars-
:cpu, :level, :rho, :cx, :cy, :cz, :vx, :vy, :vz, :p, var6,...
further possibilities: :rho, :density, :ρ
-derived hydro vars-
:x, :y, :z
:sd or :Σ or :surfacedensity
:mass, :cellsize, :freefall_time
:cs, :mach, :jeanslength, :jeansnumber
:t, :Temp, :Temperature with p/rho
==================[particles]:==================
all the non derived vars:
:cpu, :level, :id, :family, :tag
:x, :y, :z, :vx, :vy, :vz, :mass, :birth, :metal....
-derived particle vars-
:age
==============[gas or particles]:===============
:v, :ekin
squared => :vx2, :vy2, :vz2
velocity dispersion => σx, σy, σz, σ
related to a given center:
---------------------------
:vr_cylinder, vr_sphere (radial components)
:vϕ_cylinder, :vθ
squared => :vr_cylinder2, :vϕ_cylinder2
velocity dispersion => σr_cylinder, σϕ_cylinder
2d maps (not projected) => :r_cylinder, :ϕ
------------------------------------------------
## Projection of a Single Quantity in Different Directions (z,y,x)
Here we project the surface density in the z-direction of the data within a particular vertical range (domain=[0:1]) onto a grid corresponding to the maximum loaded level.
Pass any object of `HydroDataType` (here: "gas") to the `projection`-function and select a variable by a Symbol (here: :sd = :surfacedensity = :Σ in Msol/pc^3)
```julia
proj_z = projection(gas, :sd, unit=:Msol_pc2, zrange=[0.45,0.55])
proj_z = projection(gas, :sd, :Msol_pc2, zrange=[0.45,0.55], verbose=false) # The keyword "unit" (singular) can be omit if the following order is preserved: data-object, quantity, unit.
proj_x = projection(gas, :sd, :Msol_pc2, direction = :x, zrange=[0.45,0.55], verbose=false); # Project the surface density in x-direction
```
[Mera]: 2023-04-10T12:06:22.093
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 1024^2
Map size: 1024 x 1024
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:02
### Select a Range Related to a Center
See also in the documentation for: load data by selection
```julia
cv = (gas.boxlen / 2.) * gas.scale.kpc # provide the box-center in kpc
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[cv,cv,cv], range_unit=:kpc);
```
[Mera]: 2023-04-10T12:06:30.071
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 428
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Use the short notation for the box center :bc or :boxcenter for all dimensions (x,y,z):
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc);
```
[Mera]: 2023-04-10T12:06:32.245
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 428
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:bc], range_unit=:kpc);
```
[Mera]: 2023-04-10T12:06:34.277
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 428
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Use the box center notation for individual dimensions, here x,z:
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:bc, 24., :bc], range_unit=:kpc);
```
[Mera]: 2023-04-10T12:06:36.462
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 428
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
### Get Multiple Quantities
Get several quantities with one function call by passing an array containing the selected variables (at least one entry). The keyword name for the units is now in plural.
```julia
proj1_x = projection(gas, [:sd], units=[:Msol_pc2],
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2023-04-10T12:06:43.824
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 86
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:01
Pass an array containing several quantities to process and their corresponding units:
```julia
proj1_z = projection(gas, [:sd, :vx], units=[:Msol_pc2, :km_s],
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2023-04-10T12:06:48.228
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd, :vx)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 86
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:03
The function can be called without any keywords by preserving the following order: dataobject, variables, units
```julia
proj1_z = projection(gas, [:sd , :vx], [:Msol_pc2, :km_s],
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2023-04-10T12:06:52.513
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:sd, :vx)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 86
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:03
If all selected variables should be of the same unit use the following arguments: dataobject, array of quantities, unit (no array needed)
```julia
projvel_z = projection(gas, [:vx, :vy, :vz], :km_s,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2023-04-10T12:06:56.640
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:vx, :vy, :vz, :sd)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 428
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
## Function Output
List the fields of the assigned object:
```julia
propertynames(proj1_z)
```
(:maps, :maps_unit, :maps_lmax, :maps_weight, :maps_mode, :lmax_projected, :lmin, :lmax, :ranges, :extent, :cextent, :ratio, :effres, :pixsize, :boxlen, :smallr, :smallc, :scale, :info)
The projected 2D maps are stored in a dictionary:
```julia
proj1_z.maps
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 2 entries:
:sd => [0.139938 0.137134 … 0.0559771 0.039597; 0.139217 0.137082 … 0.0542157…
:vx => [77.2952 76.0304 … 81.0816 35.6391; 77.0928 75.8627 … 76.2712 35.0263;…
The maps can be accessed by giving the name of the dictionary:
```julia
proj1_z.maps[:sd]
```
428×86 Matrix{Float64}:
0.139938 0.137134 0.131767 … 0.0872412 0.0559771 0.039597
0.139217 0.137082 0.132994 0.0816654 0.0542157 0.0398295
0.137721 0.136923 0.135395 0.0704139 0.0505852 0.0401868
0.130652 0.132227 0.135241 0.060856 0.0473774 0.0403063
0.118059 0.123044 0.132582 0.0530844 0.0446923 0.0402881
0.10163 0.110067 0.126214 … 0.0476658 0.0429264 0.0404395
0.0813691 0.0933035 0.116143 0.044649 0.0421367 0.0408176
0.0669271 0.07945 0.103416 0.0428914 0.0417599 0.041163
0.0582977 0.0685004 0.0880284 0.0423535 0.0417506 0.0414303
0.0535281 0.06126 0.0760619 0.0423028 0.0420018 0.0418397
0.0526318 0.0577423 0.0675286 … 0.0427375 0.0425119 0.0423895
0.052837 0.0560511 0.0622078 0.0431381 0.0429604 0.0428636
0.0541345 0.0561769 0.0600908 0.0435055 0.0433486 0.0432631
⋮ ⋱ ⋮
0.345865 0.369255 0.413998 0.629721 0.626234 0.624502
0.331128 0.356762 0.405799 0.633807 0.626743 0.623164
0.301443 0.329698 0.38375 0.635831 0.62586 0.620785
0.264759 0.29386 0.349533 0.636119 0.623004 0.616308
0.221068 0.249242 0.303144 … 0.634589 0.618091 0.609649
0.18151 0.207886 0.25835 0.626543 0.606447 0.596148
0.146155 0.169863 0.215215 0.611892 0.588007 0.575739
0.116928 0.137085 0.175624 0.589726 0.562302 0.548179
0.0937383 0.109461 0.139499 0.560153 0.529411 0.513549
0.0759276 0.087617 0.109919 … 0.527518 0.495959 0.479666
0.063372 0.0714275 0.0867677 0.49155 0.461674 0.446257
0.0570274 0.063266 0.0751304 0.473422 0.444384 0.429406
The units of the maps are stored in:
```julia
proj1_z.maps_unit
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 2 entries:
:sd => :Msol_pc2
:vx => :km_s
Projections on a different grid size (see subject below):
```julia
proj1_z.maps_lmax
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering}()
The following fields are helpful for further calculations or plots.
```julia
proj1_z.ranges # normalized to the domain=[0:1]
```
6-element Vector{Float64}:
0.29166666666647767
0.7083333333328743
0.29166666666647767
0.7083333333328743
0.4583333333330363
0.5416666666663156
```julia
proj1_z.extent # ranges in code units
```
4-element Vector{Float64}:
13.96875
34.03125
21.984375
26.015625
```julia
proj1_z.cextent # ranges in code units relative to a given center (by default: box center)
```
4-element Vector{Float64}:
-10.031250000015556
10.031249999984444
-2.0156250000155556
2.0156249999844444
```julia
proj1_z.ratio # the ratio between the two ranges
```
4.976744186046512
## Plot Maps with Python
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false)
proj_x = projection(gas, :sd, :Msol_pc2,
zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
direction = :x);
```
Progress: 100%|█████████████████████████████████████████| Time: 0:00:02
Python functions can be directly called in Julia, which gives the opportunity, e.g. to use the Matplotlib library.
```julia
using PyPlot
using ColorSchemes
cmap3 = ColorMap(ColorSchemes.Blues.colors)
cmap = ColorMap(ColorSchemes.lajolla.colors) # See http://www.fabiocrameri.ch/colourmaps.php
cmap2 = ColorMap(reverse(ColorSchemes.roma.colors))
```

```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

Project a specific spatial range and plot the axes of the map relative to the box-center (given by keyword: data_center):
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[24.,24.,24.], data_center_unit=:kpc)
proj_x = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[24.,24.,24.], data_center_unit=:kpc,
direction = :x);
```
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

Plot the axes of the map relative to the map-center (given by keyword: data_center):
```julia
proj_z = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[19.,19.,24.], data_center_unit=:kpc)
proj_x = projection(gas, :sd, :Msol_pc2,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[19.,19.,24.], data_center_unit=:kpc,
direction = :x);
```
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

## Projections of Derived Kinematic Data
#### Use quantities in cartesian coordinates:
Project the following derived data
(mass weighted by default): The absolute value of the velocity :v, the velocity dispersion :σ in different directions. The Julia language supports Unicode characters and can be inserted by e.g. "\sigma + tab-key" leading to: **σ**.
```julia
proj_z = projection(gas, [:v, :σ, :σx, :σy, :σz], :km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[24.,24.,24.], range_unit=:kpc);
```
[Mera]: 2023-04-10T13:07:59.030
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:v, :σ, :σx, :σy, :σz, :vx, :vx2, :vy, :vy2, :vz, :vz2, :v2, :sd)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 428
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:05
For the velocity dispersion additional maps are created to created the mass-weighted quantity:
E. g.: σx = sqrt( <vx^2> - < vx >^2 )
```julia
proj_z.maps
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 13 entries:
:sd => [6.6833e-5 6.80617e-5 … 0.000177126 0.000163977; 7.28461e-5 7.45496e-…
:v => [200.553 200.475 … 206.694 206.58; 201.081 201.027 … 206.638 206.51; …
:v2 => [9.55132 9.53998 … 9.97416 9.96594; 9.58466 9.57475 … 9.96848 9.95871…
:vx => [2.20801 2.21133 … -2.44779 -2.44328; 2.2193 2.22319 … -2.44946 -2.44…
:vx2 => [4.99404 5.00648 … 6.07258 6.05673; 5.03519 5.04973 … 6.07857 6.06466…
:vy => [-2.1024 -2.09689 … -1.95211 -1.9531; -2.10305 -2.09739 … -1.94946 -1…
:vy2 => [4.53656 4.51184 … 3.85382 3.86121; 4.52933 4.50363 … 3.84079 3.8444;…
:vz => [-0.00975545 -0.0138632 … 0.145365 0.144179; -0.0151512 -0.0196064 … …
:vz2 => [0.0207161 0.0216515 … 0.0477525 0.048001; 0.0201404 0.0213888 … 0.04…
:σ => [29.1564 28.8564 … 12.9517 13.3988; 27.9589 27.5801 … 12.8922 13.3103…
:σx => [22.5962 22.3827 … 18.6511 19.3549; 21.74 21.4671 … 18.3996 19.0645; …
:σy => [22.3791 22.2288 … 13.6137 14.1599; 21.4007 21.2053 … 13.1819 13.719;…
:σz => [9.41661 9.60612 … 10.6993 10.8176; 9.25306 9.50375 … 10.6957 10.8257…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 13 entries:
:sd => :standard
:v => :km_s
:v2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vz => :standard
:vz2 => :standard
:σ => :km_s
:σx => :km_s
:σy => :km_s
:σz => :km_s
```julia
usedmemory(proj_z);
```
Memory used: 19.595 MB
```julia
figure(figsize=(10, 5.5))
subplot(2, 3, 1)
title("v [km/s]")
imshow( (permutedims(proj_z.maps[:v]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 2)
title("σ [km/s]")
imshow( (permutedims(proj_z.maps[:σ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 4)
title("σx [km/s]")
imshow( (permutedims(proj_z.maps[:σx]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 5)
title("σy [km/s]")
imshow( permutedims(proj_z.maps[:σy]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 6)
title("σz [km/s]")
imshow( permutedims(proj_z.maps[:σz]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

#### Use quantities in cylindrical coordinates:
#### Face-on disc (z-direction)
For the cylindrical or spherical components of a quantity, the center of the coordinate system is used (keywords: data_center = center default) and can be given with the keyword "data_center" and its units with "data_center_unit". Additionally, the quantities that are based on cartesian coordinates can be given.
```julia
proj_z = projection(gas, [:v, :σ, :σx, :σy, :ϕ, :r_cylinder, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
units=[:km_s,:km_s,:km_s, :km_s, :standard, :kpc, :km_s, :km_s, :km_s, :km_s],
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
data_center=[24.,24.,24.],
data_center_unit=:kpc);
```
[Mera]: 2023-04-10T13:08:23.110
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:v, :σ, :σx, :σy, :ϕ, :r_cylinder, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder, :vx, :vx2, :vy, :vy2, :v2, :vr_cylinder2, :vϕ_cylinder2, :sd)
Weighting = :mass
Effective resolution: 1024^2
Map size: 428 x 428
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:07
```julia
proj_z.maps
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 18 entries:
:r_cylinder => [14.0758 14.0427 … 14.1201 14.1534; 14.0427 14.0096 … 14.087…
:sd => [6.6833e-5 6.80617e-5 … 0.000177126 0.000163977; 7.28461e-5 …
:v => [200.553 200.475 … 206.694 206.58; 201.081 201.027 … 206.638…
:v2 => [9.55132 9.53998 … 9.97416 9.96594; 9.58466 9.57475 … 9.9684…
:vr_cylinder => [-4.89687 -5.55316 … 22.2491 21.7111; -5.09439 -5.78506 … 22…
:vr_cylinder2 => [0.013517 0.0160811 … 0.166383 0.16509; 0.0139447 0.0166047 …
:vx => [2.20801 2.21133 … -2.44779 -2.44328; 2.2193 2.22319 … -2.44…
:vx2 => [4.99404 5.00648 … 6.07258 6.05673; 5.03519 5.04973 … 6.0785…
:vy => [-2.1024 -2.09689 … -1.95211 -1.9531; -2.10305 -2.09739 … -1…
:vy2 => [4.53656 4.51184 … 3.85382 3.86121; 4.52933 4.50363 … 3.8407…
:vϕ_cylinder => [199.868 199.758 … 204.153 204.024; 200.431 200.34 … 204.133…
:vϕ_cylinder2 => [9.51708 9.50225 … 9.76002 9.75285; 9.55058 9.53676 … 9.7569…
:σ => [29.1564 28.8564 … 12.9517 13.3988; 27.9589 27.5801 … 12.892…
:σr_cylinder => [5.84342 6.18975 … 14.8473 15.4446; 5.83191 6.15915 … 14.326…
:σx => [22.5962 22.3827 … 18.6511 19.3549; 21.74 21.4671 … 18.3996 …
:σy => [22.3791 22.2288 … 13.6137 14.1599; 21.4007 21.2053 … 13.181…
:σϕ_cylinder => [31.2613 30.9453 … 17.0522 17.6776; 29.935 29.5447 … 16.903 …
:ϕ => [3.92699 3.92463 … 2.35306 2.35073; 3.92935 3.92699 … 2.3507…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 18 entries:
:r_cylinder => :kpc
:sd => :standard
:v => :km_s
:v2 => :standard
:vr_cylinder => :km_s
:vr_cylinder2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vϕ_cylinder => :km_s
:vϕ_cylinder2 => :standard
:σ => :km_s
:σr_cylinder => :km_s
:σx => :km_s
:σy => :km_s
:σϕ_cylinder => :km_s
:ϕ => :radian
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("Radius [kpc]")
imshow( permutedims(proj_z.maps[:r_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_z.maps[:vr_cylinder] ), cmap="seismic", origin="lower", extent=proj_z.cextent, vmin=-20.,vmax=20.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_z.maps[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 4)
title("ϕ-angle ")
imshow( permutedims(proj_z.maps[:ϕ]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( permutedims(proj_z.maps[:σr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( permutedims(proj_z.maps[:σϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( permutedims(proj_z.maps[:σ]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( permutedims(proj_z.maps[:σx] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( permutedims(proj_z.maps[:σy] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

## Project on a Coarser Grid
### lmax
The default is the projection on the maximum loaded grid level (always provided in the output). Choose a smaller/larger level with the keyword `lmax` (independend on the maximum level of the simulation) to project on a coarser/finer grid. By default, the data is assumed to be in the center of the simulation box.
```julia
proj_z = projection(gas, [:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
:km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
lmax=6);
```
[Mera]: 2023-04-10T13:12:01.879
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder, :vx, :vx2, :vy, :vy2, :vz, :vz2, :v2, :vr_cylinder2, :vϕ_cylinder2, :sd)
Weighting = :mass
Effective resolution: 64^2
Map size: 28 x 28
Pixel size: 750.0 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:08
```julia
# this corresponds to an effective resolution of:
proj_z.effres
```
64
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("v [km/s]")
imshow( permutedims(proj_z.maps[:v] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_z.maps[:vr_cylinder] ), cmap="seismic", origin="lower", extent=proj_z.cextent, vmin=-20.,vmax=20.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_z.maps[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 4)
title("σz [km/s]")
imshow( permutedims(proj_z.maps[:σz] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( permutedims(proj_z.maps[:σr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( permutedims(proj_z.maps[:σϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( permutedims(proj_z.maps[:σ]) , cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( permutedims(proj_z.maps[:σx] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( permutedims(proj_z.maps[:σy] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

### res
Choose the effective resolution (related to the full box) of the projected grid:
```julia
proj_z = projection(gas, [:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
:km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
res=100);
```
[Mera]: 2023-04-10T13:16:07.047
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder, :vx, :vx2, :vy, :vy2, :vz, :vz2, :v2, :vr_cylinder2, :vϕ_cylinder2, :sd)
Weighting = :mass
Effective resolution: 100^2
Map size: 42 x 42
Pixel size: 480.0 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:08
### pxsize
Choose the pixel size in a physical unit, e.g. pixel-size=100 pc. The data is projected to a grid with a pixel-size that is closest to the given number, but not larger:
```julia
proj_z = projection(gas, [:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
:km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
pxsize=[100., :pc]);
```
[Mera]: 2023-04-10T13:20:23.556
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Selected var(s)=(:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder, :vx, :vx2, :vy, :vy2, :vz, :vz2, :v2, :vr_cylinder2, :vϕ_cylinder2, :sd)
Weighting = :mass
Effective resolution: 481^2
Map size: 201 x 201
Pixel size: 99.792 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:08
```julia
```
## Projection of Thermal Data
The the sound speed is calculated from the loaded adiabatic index (from the hydro files):
```julia
proj_z = projection(gas, :cs, :km_s, zrange=[0.45,0.55], xrange=[0.4, 0.6], yrange=[0.4, 0.6])
proj_x = projection(gas, :cs, :km_s, zrange=[0.45,0.55], xrange=[0.4, 0.6], yrange=[0.4, 0.6], direction=:x);
```
[Mera]: 2023-04-10T13:38:42.414
domain:
xmin::xmax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
ymin::ymax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:cs, :sd)
Weighting = :mass
Effective resolution: 1024^2
Map size: 206 x 206
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
[Mera]: 2023-04-10T13:38:45.005
domain:
xmin::xmax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
ymin::ymax: 0.4 :: 0.6 ==> 19.2 [kpc] :: 28.8 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:cs, :sd)
Weighting = :mass
Effective resolution: 1024^2
Map size: 206 x 104
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:01
```julia
figure(figsize=(10, 3.5))
subplot(1, 2, 1)
im = imshow( log10.(permutedims(proj_z.maps[:cs]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(c_s) \ [km \ s^{-1}]}")
subplot(1, 2, 2)
im = imshow( log10.(permutedims(proj_x.maps[:cs]) ), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(c_s) \ [km \ s^{-1}]}",orientation="horizontal", pad=0.2);
```

Change the adiabatic index in the field `gas.info.gamma` to use a different value in the projection calculation.
## Projection of Masked Data
Mask higher densities by creating a Bool-array where the lower density cells correspond to false entries:
```julia
#density = 4e-3 / gas.scale.Msol_pc3
#mask = map(row->row.rho < density, gas.data);
mask_nH = getvar(gas, :rho, :nH) .< 1. # cm-3
mask_T = getvar(gas, :Temperature, :K) .< 1e4 # K
mask_tot = mask_nH .* mask_T;
```
Pass the mask to the projection function:
```julia
proj_z = projection(gas, :sd, :Msol_pc2, zrange=[0.45,0.55], mask=mask_tot)
proj_x = projection(gas, :sd, :Msol_pc2, zrange=[0.45,0.55], mask=mask_tot, direction=:x);
```
[Mera]: 2023-04-10T13:25:01.398
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 1024^2
Map size: 1024 x 1024
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
:mask provided by function
[Mera]: 2023-04-10T13:25:02.534
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Selected var(s)=(:sd,)
Weighting = :mass
Effective resolution: 1024^2
Map size: 1024 x 104
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
:mask provided by function
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=0, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
tight_layout()
```

```julia
```
## Weighting - Integration
By default, the data is weighted by mass, except for the surface density. Choose different weightings, e.g., volume:
```julia
proj_z = projection(gas, :cs, :km_s, weighting=[:volume]);
```
[Mera]: 2023-04-10T13:31:41.084
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Selected var(s)=(:cs,)
Weighting = :volume
Effective resolution: 1024^2
Map size: 1024 x 1024
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:03
Any quantity that is predefined (see: projection(), getvar()) or is part of the data-table can be selected. Furthermore, a unit can be given, e.g., for volume with cm3:
```julia
proj_z = projection(gas, :cs, :km_s, weighting=[:volume, :cm3]);
```
[Mera]: 2023-04-10T13:34:04.680
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Selected var(s)=(:cs,)
Weighting = :volume
Effective resolution: 1024^2
Map size: 1024 x 1024
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:03
This can be useful if you want to make an integrated projection for local emissivities that are given e.g., emissivity/cm3. For such integration, choose the summation mode (examples will be given soon):
```julia
proj_z = projection(gas, :emissivity, weighting=[:volume, :cm3], mode=:sum);
```
```julia
```
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 41261 | # 6. Particles: Projections
## Load The Data
```julia
using Mera
info = getinfo(300, "../../testing/simulations/mw_L10");
particles = getparticles(info);
```
[Mera]: 2023-04-10T13:44:15.828
Code: RAMSES
output [300] summary:
mtime: 2023-04-09T05:34:09
ctime: 2023-04-10T08:08:14.488
=======================================================
simulation time: 445.89 [Myr]
boxlen: 48.0 [kpc]
ncpu: 640
ndim: 3
-------------------------------------------------------
amr: true
level(s): 6 - 10 --> cellsize(s): 750.0 [pc] - 46.88 [pc]
-------------------------------------------------------
hydro: true
hydro-variables: 7 --> (:rho, :vx, :vy, :vz, :p, :var6, :var7)
hydro-descriptor: (:density, :velocity_x, :velocity_y, :velocity_z, :pressure, :scalar_00, :scalar_01)
γ: 1.6667
-------------------------------------------------------
gravity: true
gravity-variables: (:epot, :ax, :ay, :az)
-------------------------------------------------------
particles: true
- Nstars: 5.445150e+05
particle-variables: 7 --> (:vx, :vy, :vz, :mass, :family, :tag, :birth)
particle-descriptor: (:position_x, :position_y, :position_z, :velocity_x, :velocity_y, :velocity_z, :mass, :identity, :levelp, :family, :tag, :birth_time)
-------------------------------------------------------
rt: false
clumps: false
-------------------------------------------------------
namelist-file: ("&COOLING_PARAMS", "&SF_PARAMS", "&AMR_PARAMS", "&BOUNDARY_PARAMS", "&OUTPUT_PARAMS", "&POISSON_PARAMS", "&RUN_PARAMS", "&FEEDBACK_PARAMS", "&HYDRO_PARAMS", "&INIT_PARAMS", "&REFINE_PARAMS")
-------------------------------------------------------
timer-file: true
compilation-file: false
makefile: true
patchfile: true
=======================================================
[Mera]: Get particle data: 2023-04-10T13:44:20.554
Key vars=(:level, :x, :y, :z, :id, :family, :tag)
Using var(s)=(1, 2, 3, 4, 7) = (:vx, :vy, :vz, :mass, :birth)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Found 5.445150e+05 particles
Memory used for data table :38.42913246154785 MB
-------------------------------------------------------
```julia
particles.data
```
Table with 544515 rows, 12 columns:
Columns:
# colname type
────────────────────
1 level Int32
2 x Float64
3 y Float64
4 z Float64
5 id Int32
6 family Int8
7 tag Int8
8 vx Float64
9 vy Float64
10 vz Float64
11 mass Float64
12 birth Float64
## Projection of Predefined Quantities
See the possible variables:
```julia
projection()
```
Predefined vars for projections:
------------------------------------------------
=====================[gas]:=====================
-all the non derived hydro vars-
:cpu, :level, :rho, :cx, :cy, :cz, :vx, :vy, :vz, :p, var6,...
further possibilities: :rho, :density, :ρ
-derived hydro vars-
:x, :y, :z
:sd or :Σ or :surfacedensity
:mass, :cellsize, :freefall_time
:cs, :mach, :jeanslength, :jeansnumber
:t, :Temp, :Temperature with p/rho
==================[particles]:==================
all the non derived vars:
:cpu, :level, :id, :family, :tag
:x, :y, :z, :vx, :vy, :vz, :mass, :birth, :metal....
-derived particle vars-
:age
==============[gas or particles]:===============
:v, :ekin
squared => :vx2, :vy2, :vz2
velocity dispersion => σx, σy, σz, σ
related to a given center:
---------------------------
:vr_cylinder, vr_sphere (radial components)
:vϕ_cylinder, :vθ
squared => :vr_cylinder2, :vϕ_cylinder2
velocity dispersion => σr_cylinder, σϕ_cylinder
2d maps (not projected) => :r_cylinder, :ϕ
------------------------------------------------
## Projection of a Single Quantity in Different Directions (z,y,x)
Here we project the surface density in the z-direction of the data within a particular vertical range (domain=[0:1]) on a grid corresponding to level=9.
Pass any object of *PartDataType* (here: "particles") to the *projection*-function and select a variable by a Symbol (here: :sd = :surfacedensity = :Σ in Msol/pc^3)
```julia
proj_z = projection(particles, :sd, unit=:Msol_pc2, lmax=9, zrange=[0.45,0.55])
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9, zrange=[0.45,0.55], verbose=false) # The keyword "unit" (singular) can be omit if the following order is preserved: data-object, quantity, unit.
proj_x = projection(particles, :sd, :Msol_pc2, lmax=9, direction = :x, zrange=[0.45,0.55], verbose=false); # Project the surface density in x-direction
```
[Mera]: 2023-04-10T13:44:30.854
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
### Select a Range Related to a Center
See also in the documentation for: load data by selection
```julia
cv = (particles.boxlen / 2.) * particles.scale.kpc # provide the box-center in kpc
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[cv,cv,cv], range_unit=:kpc);
```
[Mera]: 2023-04-10T13:44:38.556
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
Use the short notation for the box center :bc or :boxcenter for all dimensions (x,y,z):
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc);
```
[Mera]: 2023-04-10T13:44:42.484
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:bc], range_unit=:kpc);
```
[Mera]: 2023-04-10T13:44:43.180
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
Use the box center notation for individual dimensions, here x,z:
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:bc, 24., :bc], range_unit=:kpc);
```
[Mera]: 2023-04-10T13:44:46.717
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
### Get Multiple Quantities
Get several quantities with one function call by passing an array containing the selected variables (at least one entry). The keyword name for the units is now in plural.
```julia
proj1_x = projection(particles, [:sd], units=[:Msol_pc2], lmax=9,
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2023-04-10T13:44:54.060
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
Pass an array containing several quantities to process and their corresponding units:
```julia
proj1_z = projection(particles, [:sd, :vx], units=[:Msol_pc2, :km_s], lmax=9,
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2023-04-10T13:44:56.764
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
The function can be called without any keywords by preserving the following order: dataobject, variables, units
```julia
proj1_z = projection(particles, [:sd , :vx], [:Msol_pc2, :km_s], lmax=9,
direction = :x,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2023-04-10T13:45:02.692
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
If all selected variables should be of the same unit use the following arguments: dataobject, array of quantities, unit (no array needed)
```julia
projvel_z = projection(particles, [:vx, :vy, :vz], :km_s, lmax=9,
xrange=[-10.,10.],
yrange=[-10.,10.],
zrange=[-2.,2.],
center=[24.,24.,24.],
range_unit=:kpc);
```
[Mera]: 2023-04-10T13:45:05.474
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
## Function Output
List the fields of the assigned object:
```julia
propertynames(projvel_z)
```
(:maps, :maps_unit, :maps_lmax, :maps_mode, :lmax_projected, :lmin, :lmax, :ref_time, :ranges, :extent, :cextent, :ratio, :effres, :pixsize, :boxlen, :scale, :info)
The projected 2D maps are stored in a dictionary:
```julia
projvel_z.maps # NaN for empty regions
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 4 entries:
:sd => [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … 0.0 0.0; 0.0 0.0 …
:vx => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN NaN …
:vy => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN NaN …
:vz => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN NaN …
The maps can be accessed by giving the name of the dictionary:
```julia
proj1_z.maps[:sd]
```
214×44 Matrix{Float64}:
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
⋮ ⋮ ⋱ ⋮
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 … 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
The units of the maps are stored in:
```julia
projvel_z.maps_unit
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 4 entries:
:sd => :standard
:vx => :km_s
:vy => :km_s
:vz => :km_s
The following fields are helpful for further calculations or plots.
```julia
projvel_z.ranges # normalized to the domain=[0:1]
```
6-element Vector{Float64}:
0.29166666666647767
0.7083333333328743
0.29166666666647767
0.7083333333328743
0.4583333333330363
0.5416666666663156
```julia
projvel_z.extent # ranges in code units
```
4-element Vector{Float64}:
13.96875
34.03125
13.96875
34.03125
```julia
projvel_z.cextent # ranges in code units relative to a given center (by default: box center)
```
4-element Vector{Float64}:
-10.031250000015554
10.031249999984446
-10.031250000015554
10.031249999984446
```julia
proj1_z.ratio # the ratio between the two ranges
```
4.863636363636363
## Plot Maps with Python
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false)
proj_x = projection(particles, :sd, :Msol_pc2, lmax=9,
zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
direction = :x);
```
Python functions can be directly called in Julia, which gives the opportunity, e.g. to use the Matplotlib library.
```julia
using PyPlot
using ColorSchemes
cmap = ColorMap(ColorSchemes.lajolla.colors) # See http://www.fabiocrameri.ch/colourmaps.php
cmap2 = ColorMap(reverse(ColorSchemes.roma.colors))
```

```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=-0.5, vmax=1.5)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=-0.5, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
tight_layout()
```

Project a specific spatial range and plot the axes of the map relative to the box-center (given by keyword: data_center):
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[24.,24.,24.], data_center_unit=:kpc)
proj_x = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[24.,24.,24.], data_center_unit=:kpc,
direction = :x);
```
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=-0.5, vmax=2.)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=-0.5, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

Plot the axes of the map relative to the map-center (given by keyword: data_center):
```julia
proj_z = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[19.,19.,24.], data_center_unit=:kpc)
proj_x = projection(particles, :sd, :Msol_pc2, lmax=9,
xrange=[-10.,0.], yrange=[-10.,0.], zrange=[-2.,2.], center=[:boxcenter], range_unit=:kpc,
verbose=false,
data_center=[19.,19.,24.], data_center_unit=:kpc,
direction = :x);
```
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:sd])), cmap=cmap, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent, vmin=-0.5, vmax=2.)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:sd])), cmap=cmap, origin="lower", extent=proj_x.cextent, vmin=-0.5, vmax=3)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(\Sigma) \ [M_{\odot} pc^{-2}]}",orientation="horizontal", pad=0.2);
```

## Projections of Derived Kinematic Data
#### Use quantities in cartesian coordinates:
Project the following derived data
(mass weighted by default): The absolute value of the velocity :v, the velocity dispersion :σ in different directions and the kinetic energy :ekin. The Julia language supports Unicode characters and can be inserted by e.g. "\sigma + tab-key" leading to: **σ**.
```julia
proj_z = projection(particles, [:v, :σ, :σx, :σy, :σz, :ekin],
units=[:km_s,:km_s,:km_s,:km_s,:km_s,:erg],
lmax=9,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[24.,24.,24.], range_unit=:kpc);
```
[Mera]: 2023-04-10T13:49:11.587
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 512^2
Pixel size: 93.75 [pc]
Simulation min.: 46.875 [pc]
For the velocity dispersion additional maps are created to created the mass-weighted quantity:
E. g.: σx = sqrt( <vx^2> - < vx >^2 )
```julia
proj_z.maps
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 14 entries:
:ekin => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:sd => [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … 0.0 0.0; 0.0 0.…
:v => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:v2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:vx => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:vx2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:vy => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:vy2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:vz => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:vz2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:σ => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:σx => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:σy => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
:σz => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN; NaN Na…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 14 entries:
:ekin => :erg
:sd => :standard
:v => :km_s
:v2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vz => :standard
:vz2 => :standard
:σ => :km_s
:σx => :km_s
:σy => :km_s
:σz => :km_s
```julia
usedmemory(proj_z);
```
Memory used: 4.919 MB
```julia
figure(figsize=(10, 5.5))
subplot(2, 3, 1)
title("v [km/s]")
imshow( (permutedims(proj_z.maps[:v]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmax=300.)
colorbar()
subplot(2, 3, 2)
title("σ [km/s]")
imshow( (permutedims(proj_z.maps[:σ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 3)
title("Ekin [erg]")
imshow( log10.(permutedims(proj_z.maps[:ekin]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 4)
title("σx [km/s]")
imshow( (permutedims(proj_z.maps[:σx]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 5)
title("σy [km/s]")
imshow( (permutedims(proj_z.maps[:σy]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(2, 3, 6)
title("σz [km/s]")
imshow( (permutedims(proj_z.maps[:σz]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

#### Use quantities in cylindrical coordinates:
#### Face-on disc (z-direction)
For the cylindrical or spherical components of a quantity, the center of the coordinate system is used (keywords: data_center = center default) and can be given with the keyword "data_center" and its units with "data_center_unit". Additionally, the quantities that are based on cartesian coordinates can be given.
```julia
proj_z = projection(particles, [:v, :σ, :σx, :σy, :ϕ, :r_cylinder, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
units=[:km_s,:km_s,:km_s, :km_s, :standard, :kpc, :km_s, :km_s, :km_s, :km_s],
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
data_center=[24.,24.,24.], data_center_unit=:kpc);
```
[Mera]: 2023-04-10T13:50:46.517
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 1024^2
Pixel size: 46.875 [pc]
Simulation min.: 46.875 [pc]
Progress: 100%|█████████████████████████████████████████| Time: 0:00:01
```julia
proj_z.maps
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 18 entries:
:r_cylinder => [14.0758 14.0427 … 14.1201 14.1534; 14.0427 14.0096 … 14.087…
:sd => [0.0 0.0 … 0.0 0.0; 0.0 0.0 … 0.0 0.0; … ; 0.0 0.0 … 0.0 0.0…
:v => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:v2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:vr_cylinder => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:vr_cylinder2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:vx => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:vx2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:vy => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:vy2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:vϕ_cylinder => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:vϕ_cylinder2 => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:σ => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:σr_cylinder => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:σx => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:σy => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:σϕ_cylinder => [NaN NaN … NaN NaN; NaN NaN … NaN NaN; … ; NaN NaN … NaN NaN…
:ϕ => [3.92699 3.92463 … 2.35306 2.35073; 3.92935 3.92699 … 2.3507…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 18 entries:
:r_cylinder => :kpc
:sd => :standard
:v => :km_s
:v2 => :standard
:vr_cylinder => :km_s
:vr_cylinder2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vϕ_cylinder => :km_s
:vϕ_cylinder2 => :standard
:σ => :km_s
:σr_cylinder => :km_s
:σx => :km_s
:σy => :km_s
:σϕ_cylinder => :km_s
:ϕ => :radian
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("Radius [kpc]")
imshow( permutedims(proj_z.maps[:r_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_z.maps[:vr_cylinder] ), cmap="seismic", origin="lower", extent=proj_z.cextent, vmin=-50.,vmax=50.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_z.maps[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 4)
title("ϕ-angle")
imshow( (permutedims(proj_z.maps[:ϕ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( permutedims(proj_z.maps[:σr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( permutedims(proj_z.maps[:σϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( (permutedims(proj_z.maps[:σ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( permutedims(proj_z.maps[:σx] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( permutedims(proj_z.maps[:σy] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

## Project on a Coarser Grid
### lmax
The default is the projection on the maximum loaded grid level (always provided in the output). Choose a smaller/larger level with the keyword `lmax` (independend on the maximum level of the simulation) to project on a coarser/finer grid. By default, the data is assumed to be in the center of the simulation box.
```julia
proj_z = projection(particles,
[:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
:km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
lmax=6);
```
[Mera]: 2023-04-10T14:35:46.954
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 64^2
Pixel size: 750.0 [pc]
Simulation min.: 46.875 [pc]
The projection onto the maximum loaded grid is always provided:
```julia
proj_z.maps
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 19 entries:
:sd => [3.6988e-5 6.11725e-5 … 2.84523e-5 4.26785e-6; 0.000146885 8…
:v => [215.727 217.893 … 213.689 211.398; 211.909 214.371 … 215.29…
:v2 => [10.8327 11.0472 … 10.6218 10.3945; 10.4511 10.6909 … 10.782…
:vr_cylinder => [-4.97035 9.83744 … 0.326624 -5.23378; -8.36334 3.71396 … 7.…
:vr_cylinder2 => [0.0231364 0.0346302 … 0.0196151 0.0344127; 0.0339309 0.0312…
:vx => [2.38824 2.13472 … -2.30736 -2.28246; 2.4166 2.28742 … -2.49…
:vx2 => [5.71099 4.56492 … 5.33794 5.23511; 5.844 5.24859 … 6.2532 6…
:vy => [-2.25778 -2.54366 … -2.29652 -2.26901; -2.14059 -2.32778 … …
:vy2 => [5.12035 6.48209 … 5.28291 5.15929; 4.60593 5.44099 … 4.5285…
:vz => [-0.032174 0.00624848 … -0.0229633 0.00636579; -0.0269481 -0…
:vz2 => [0.00140393 0.000219812 … 0.000962049 0.000127987; 0.0011519…
:vϕ_cylinder => [215.479 217.553 … 213.481 211.046; 211.546 214.042 … 214.91…
:vϕ_cylinder2 => [10.8082 11.0124 … 10.6012 10.36; 10.416 10.6583 … 10.7443 1…
:σ => [6.62266 5.19183 … 3.45808 2.9201; 5.96424 4.11213 … 3.61926…
:σr_cylinder => [8.64782 7.22072 … 9.17826 10.9812; 8.71558 10.9816 … 10.005…
:σx => [5.59831 5.83217 … 7.77318 10.4683; 4.16244 8.36784 … 6.5268…
:σy => [9.89835 7.14297 … 6.19364 6.84324; 10.118 9.82426 … 9.42142…
:σz => [1.25926 0.88166 … 1.36727 0.613275; 1.35303 2.02241 … 1.188…
:σϕ_cylinder => [6.7421 5.02267 … 3.52611 2.97303; 6.19423 4.23835 … 3.69795…
```julia
proj_z.maps_unit
```
DataStructures.SortedDict{Any, Any, Base.Order.ForwardOrdering} with 19 entries:
:sd => :standard
:v => :km_s
:v2 => :standard
:vr_cylinder => :km_s
:vr_cylinder2 => :standard
:vx => :standard
:vx2 => :standard
:vy => :standard
:vy2 => :standard
:vz => :standard
:vz2 => :standard
:vϕ_cylinder => :km_s
:vϕ_cylinder2 => :standard
:σ => :km_s
:σr_cylinder => :km_s
:σx => :km_s
:σy => :km_s
:σz => :km_s
:σϕ_cylinder => :km_s
```julia
figure(figsize=(10, 8.5))
subplot(3, 3, 1)
title("|v| [km/s]")
imshow( permutedims(proj_z.maps[:v] ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmax=300.)
colorbar()
subplot(3, 3, 2)
title("vr [km/s]")
imshow( permutedims(proj_z.maps[:vr_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent, vmin=-200.,vmax=200.)
colorbar()
subplot(3, 3, 3)
title("vϕ [km/s]")
imshow( permutedims(proj_z.maps[:vϕ_cylinder] ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 4)
title("σz [km/s]")
imshow( (permutedims(proj_z.maps[:σz]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 5)
title("σr [km/s]")
imshow( (permutedims(proj_z.maps[:σr_cylinder] )), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 6)
title("σϕ [km/s]")
imshow( (permutedims(proj_z.maps[:σϕ_cylinder] )), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 7)
title("σ [km/s]")
imshow( (permutedims(proj_z.maps[:σ]) ), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 8)
title("σx [km/s]")
imshow( (permutedims(proj_z.maps[:σx] )), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar()
subplot(3, 3, 9)
title("σy [km/s]")
imshow( (permutedims(proj_z.maps[:σy] )), cmap=cmap2, origin="lower", extent=proj_z.cextent)
colorbar();
```

### res
Choose the effective resolution (related to the full box) of the projected grid:
```julia
proj_z = projection(particles,
[:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
:km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
res=100);
```
[Mera]: 2023-04-10T14:36:28.832
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 100^2
Pixel size: 480.0 [pc]
Simulation min.: 46.875 [pc]
### pxsize
Choose the pixel size in a physical unit, e.g. pixel-size=100 pc. The data is projected to a grid with a pixel-size that is closest to the given number, but not larger:
```julia
proj_z = projection(particles,
[:v, :σ, :σx, :σy, :σz, :vr_cylinder, :vϕ_cylinder, :σr_cylinder, :σϕ_cylinder],
:km_s,
xrange=[-10.,10.], yrange=[-10.,10.], zrange=[-2.,2.],
center=[:boxcenter], range_unit=:kpc,
pxsize=[100., :pc]);
```
[Mera]: 2023-04-10T14:36:55.300
center: [0.5, 0.5, 0.5] ==> [24.0 [kpc] :: 24.0 [kpc] :: 24.0 [kpc]]
domain:
xmin::xmax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
ymin::ymax: 0.2916667 :: 0.7083333 ==> 14.0 [kpc] :: 34.0 [kpc]
zmin::zmax: 0.4583333 :: 0.5416667 ==> 22.0 [kpc] :: 26.0 [kpc]
Effective resolution: 481^2
Pixel size: 99.792 [pc]
Simulation min.: 46.875 [pc]
## Projection of the Birth/Age-Time
Project the average birth-time of the particles to the grid:
```julia
proj_z = projection(particles, :birth, :Myr,
lmax=8, zrange=[0.45,0.55], center=[0.,0.,0.], verbose=false);
proj_x = projection(particles, :birth, :Myr,
lmax=8, zrange=[0.45,0.55], center=[0.,0.,0.], direction=:x, verbose=false);
```
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:birth])), cmap=cmap2, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Birth) \ [Myr]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:birth])), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Birth) \ [Myr]}",orientation="horizontal", pad=0.2);
tight_layout()
```

Project the average age of the particles to the grid. The age is taken relative to the loaded snapshot time by default.
```julia
proj_z = projection(particles, :age, :Myr,
lmax=8, zrange=[0.45,0.55], center=[0.,0.,0.], verbose=false);
proj_x = projection(particles, :age, :Myr,
lmax=8, zrange=[0.45,0.55], direction=:x, center=[0.,0.,0.], verbose=false);
```
The reference time (code units) for the age calculation:
```julia
proj_z.ref_time
```
29.9031937665063
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:age])), cmap=cmap2, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:age])), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}",orientation="horizontal", pad=0.2);
tight_layout()
```

Project the average age of the particles relative to a given reference time:
```julia
proj_z = projection(particles, :age, :Myr, ref_time=0.,
lmax=8, zrange=[0.45,0.55], center=[0.,0.,0.], verbose=false);
proj_x = projection(particles, :age, :Myr, ref_time = 0.,
lmax=8, zrange=[0.45,0.55], center=[0.,0.,0.], direction=:x, verbose=false);
```
The reference time (code units) for the age calculation:
```julia
proj_z.ref_time
```
0.0
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( ( permutedims(proj_z.maps[:age])), cmap=cmap2, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{Age \ [Myr]}")
subplot(1,2,2)
im = imshow( ( permutedims(proj_x.maps[:age])), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{Age \ [Myr]}",orientation="horizontal", pad=0.2);
tight_layout()
```

## Projection of Masked Data
Mask particles with ages higher than 400 Myr by creating a Bool-array where the smaller ages correspond to false entries:
```julia
mask = getvar(particles, :age, :Myr) .> 400. ;
```
```julia
proj_z = projection(particles, :age, :Myr, mask=mask,
lmax=8, zrange=[0.45,0.55], center=[0.,0.,0.]);
proj_x = projection(particles, :age, :Myr, mask=mask,
lmax=8, zrange=[0.45,0.55], center=[0.,0.,0.], direction=:x);
```
[Mera]: 2023-04-10T14:40:56.942
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Effective resolution: 256^2
Pixel size: 187.5 [pc]
Simulation min.: 46.875 [pc]
:mask provided by function
[Mera]: 2023-04-10T14:40:57.144
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.45 :: 0.55 ==> 21.6 [kpc] :: 26.4 [kpc]
Effective resolution: 256^2
Pixel size: 187.5 [pc]
Simulation min.: 46.875 [pc]
:mask provided by function
```julia
figure(figsize=(10, 3.5))
subplot(1,2,1)
im = imshow( log10.( permutedims(proj_z.maps[:age])), cmap=cmap2, aspect=proj_z.ratio, origin="lower", extent=proj_z.cextent)
xlabel("x [kpc]")
ylabel("y [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}")
subplot(1,2,2)
im = imshow( log10.( permutedims(proj_x.maps[:age])), cmap=cmap2, origin="lower", extent=proj_x.cextent)
xlabel("x [kpc]")
ylabel("z [kpc]")
cb = colorbar(im, label=L"\mathrm{log10(Age) \ [Myr]}",orientation="horizontal", pad=0.2);
tight_layout()
```

```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
|
[
"MIT"
] | 1.4.4 | ccd0226f62ff59b9b1f5231646e2afa7b8002586 | docs | 19381 | # Export/Import Data (ASCII/Binary)
This notebook presents several ways to export your data.
Used libraries in this tutorial:
- DelimitedFiles, Serialization (comes with Julia)
- JuliaDB, FileIO, CSVFiles, JLD, CodecZlib, HDF5, Numpy, FITS, Matlap, GZip (needs to be installed)
## Load The Data
```julia
using Mera
```
```julia
info = getinfo(400, "../../../testing/simulations/manu_sim_sf_L14", verbose=false)
hydro = gethydro(info, :rho, smallr=1e-5, lmax=10)
particles = getparticles(info, :mass);
```
[0m [Mera]: Get hydro data: 2020-02-29T17:54:15.397
Key vars=(:level, :cx, :cy, :cz)
Using var(s)=(1,) = (:rho,)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...
100%|███████████████████████████████████████████████████| Time: 0:02:55
Memory used for data table :186.1558656692505 MB
-------------------------------------------------------
[0m [Mera]: Get particle data: 2020-02-29T17:57:14.49
Key vars=(:level, :x, :y, :z, :id)
Using var(s)=(4,) = (:mass,)
domain:
xmin::xmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
ymin::ymax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
zmin::zmax: 0.0 :: 1.0 ==> 0.0 [kpc] :: 48.0 [kpc]
Reading data...100%|████████████████████████████████████| Time: 0:00:03
Found 5.089390e+05 particles
Memory used for data table :19.4152889251709 MB
-------------------------------------------------------
```julia
println("Cells: ", length(hydro.data))
println("Particles: ", length(particles.data))
```
Cells: 4879946
Particles: 508939
Define a function to preview the first lines of the created ASCII files:
```julia
function viewheader(filename, lines)
open(filename) do f
line = 1
while line<=lines
x = readline(f)
println(x)
line += 1
end
end
end
```
viewheader (generic function with 1 method)
## Collect The Data For Export
```julia
# Get the cell and particle positions relative to the box-center
# Choose the relevant units
# The function getvar returns a dictionary containing a 1d-array for each quantity
hvals = getvar(hydro, [:x,:y,:z,:cellsize,:rho], [:kpc,:kpc,:kpc,:kpc,:g_cm3], center=[:boxcenter]);
pvals = getvar(hydro, [:x,:y,:z,:mass], [:kpc,:kpc,:kpc,:Msol], center=[:boxcenter]);
```
```julia
hvals
```
Dict{Any,Any} with 5 entries:
:cellsize => [0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75 … …
:y => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25,…
:rho => [6.76838e-28, 6.76838e-28, 6.76838e-28, 6.76838e-28, 6.76838e-28…
:z => [-23.25, -22.5, -21.75, -21.0, -20.25, -19.5, -18.75, -18.0, -17…
:x => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25,…
```julia
pvals
```
Dict{Any,Any} with 4 entries:
:y => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23…
:z => [-23.25, -22.5, -21.75, -21.0, -20.25, -19.5, -18.75, -18.0, -17.25,…
:mass => [4217.58, 4217.58, 4217.58, 4217.58, 4217.58, 4217.58, 4217.58, 4217…
:x => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23…
## ASCII: DelimitedFiles Library
```julia
using DelimitedFiles
```
Save into an ASCII file with no header, comma separated:
```julia
open("simulation_hydro.csv", "w") do io
writedlm(io, [hvals[:x] hvals[:y] hvals[:z] hvals[:cellsize] hvals[:rho]], ",")
end
```
Check the first lines in the file:
```julia
viewheader("simulation_hydro.csv", 5)
```
-23.25000000001507,-23.25000000001507,-23.25000000001507,0.7500000000004861,6.768382184513761e-28
-23.25000000001507,-23.25000000001507,-22.500000000014584,0.7500000000004861,6.768382184513761e-28
-23.25000000001507,-23.25000000001507,-21.750000000014097,0.7500000000004861,6.768382184513761e-28
-23.25000000001507,-23.25000000001507,-21.00000000001361,0.7500000000004861,6.768382184513761e-28
-23.25000000001507,-23.25000000001507,-20.250000000013124,0.7500000000004861,6.768382184513761e-28
Use a different syntax; save into file with header and tab-separated values:
```julia
header = ["x/kpc" "y/kpc" "z/kpc" "cellsize/kpc" "rho/g_cm3"]
valsrray = [hvals[:x] hvals[:y] hvals[:z] hvals[:cellsize] hvals[:rho]] # Array with the columns
writedlm("simulation_hydro.dat", [header ; valsrray], "\t")
```
```julia
viewheader("simulation_hydro.dat", 5)
```
x/kpc y/kpc z/kpc cellsize/kpc rho/g_cm3
-23.25000000001507 -23.25000000001507 -23.25000000001507 0.7500000000004861 6.768382184513761e-28
-23.25000000001507 -23.25000000001507 -22.500000000014584 0.7500000000004861 6.768382184513761e-28
-23.25000000001507 -23.25000000001507 -21.750000000014097 0.7500000000004861 6.768382184513761e-28
-23.25000000001507 -23.25000000001507 -21.00000000001361 0.7500000000004861 6.768382184513761e-28
Write the particles data into an ASCII file with header:
```julia
header = ["x/kpc" "y/kpc" "z/kpc" "mass/Msol"]
valsrray = [pvals[:x] pvals[:y] pvals[:z] pvals[:mass]]
writedlm("simulation_particles.dat", [header ; valsrray], "\t")
```
```julia
viewheader("simulation_particles.dat", 5)
```
x/kpc y/kpc z/kpc mass/Msol
-23.25000000001507 -23.25000000001507 -23.25000000001507 4217.583427040147
-23.25000000001507 -23.25000000001507 -22.500000000014584 4217.583427040147
-23.25000000001507 -23.25000000001507 -21.750000000014097 4217.583427040147
-23.25000000001507 -23.25000000001507 -21.00000000001361 4217.583427040147
## ASCII: Save JuliaDB Database into a CSV-File with FileIO
```julia
using FileIO
```
See for documentation https://github.com/JuliaIO/FileIO.jl/tree/master/docs
The simulation data is stored in a JuliadB database:
```julia
particles.data
```
Table with 508939 rows, 6 columns:
level x y z id mass
───────────────────────────────────────────────────────
6 0.00462947 22.3885 24.571 327957 1.13606e-5
6 0.109066 22.3782 21.5844 116193 1.13606e-5
6 0.238211 28.7537 24.8191 194252 1.13606e-5
6 0.271366 22.7512 31.5681 130805 1.13606e-5
6 0.312574 16.2385 23.7591 162174 1.13606e-5
6 0.314957 28.2084 30.966 320052 1.13606e-5
6 0.328337 4.59858 23.5001 292889 1.13606e-5
6 0.420712 27.6688 26.5735 102940 1.13606e-5
6 0.509144 33.1737 23.9789 183902 1.13606e-5
6 0.565516 25.9409 26.0579 342278 1.13606e-5
6 0.587289 9.60231 23.8477 280020 1.13606e-5
6 0.592878 25.5519 21.3079 64182 1.13606e-5
⋮
14 37.6271 25.857 23.8833 437164 1.13606e-5
14 37.6299 25.8403 23.9383 421177 1.13606e-5
14 37.6301 25.8502 23.9361 478941 1.13606e-5
14 37.6326 25.8544 23.9383 428429 1.13606e-5
14 37.6528 25.8898 23.9928 467148 1.13606e-5
14 37.6643 25.9061 23.9945 496129 1.13606e-5
14 37.6813 25.8743 23.9789 435636 1.13606e-5
14 37.7207 25.8623 23.8775 476398 1.13606e-5
14 38.173 25.8862 23.7978 347919 1.13606e-5
14 38.1738 25.8914 23.7979 403094 1.13606e-5
14 38.1739 25.8905 23.7992 381503 1.13606e-5
```julia
FileIO.save("database_partilces.csv", particles.data)
```
┌ Info: Precompiling CSVFiles [5d742f6a-9f54-50ce-8119-2520741973ca]
└ @ Base loading.jl:1273
```julia
viewheader("database_partilces.csv", 5)
```
"level","x","y","z","id","mass"
6,0.004629472789625229,22.388543919075275,24.571021484979347,327957,1.1360607549574087e-5
6,0.1090659052277639,22.3782196217294,21.58442789512976,116193,1.1360607549574087e-5
6,0.2382109772356709,28.753723953405462,24.81911909925676,194252,1.1360607549574087e-5
6,0.271365638325332,22.751224267806695,31.568145104287826,130805,1.1360607549574087e-5
Export selected variables from the datatable:
```julia
using JuliaDB
```
See for documentation https://juliacomputing.github.io/JuliaDB.jl/latest/
```julia
FileIO.save("database_partilces.csv", select(particles.data, (:x,:y,:mass)) )
```
```julia
viewheader("database_partilces.csv", 5)
```
"x","y","mass"
0.004629472789625229,22.388543919075275,1.1360607549574087e-5
0.1090659052277639,22.3782196217294,1.1360607549574087e-5
0.2382109772356709,28.753723953405462,1.1360607549574087e-5
0.271365638325332,22.751224267806695,1.1360607549574087e-5
## Binary: Save JuliaDB Database into a Binary Format
```julia
JuliaDB.save(hydro.data, "database_hydro.jdb")
```
Table with 4879946 rows, 5 columns:
level cx cy cz rho
─────────────────────────────────
6 1 1 1 1.0e-5
6 1 1 2 1.0e-5
6 1 1 3 1.0e-5
6 1 1 4 1.0e-5
6 1 1 5 1.0e-5
6 1 1 6 1.0e-5
6 1 1 7 1.0e-5
6 1 1 8 1.0e-5
6 1 1 9 1.0e-5
6 1 1 10 1.0e-5
6 1 1 11 1.0e-5
6 1 1 12 1.0e-5
⋮
10 826 554 512 0.000561671
10 826 554 513 0.000634561
10 826 554 514 0.000585903
10 826 555 509 0.000368259
10 826 555 510 0.000381535
10 826 555 511 0.000401867
10 826 555 512 0.000413433
10 826 556 509 0.000353701
10 826 556 510 0.000360669
10 826 556 511 0.000380094
10 826 556 512 0.000386327
```julia
hdata = JuliaDB.load("database_hydro.jdb")
```
Table with 4879946 rows, 5 columns:
level cx cy cz rho
─────────────────────────────────
6 1 1 1 1.0e-5
6 1 1 2 1.0e-5
6 1 1 3 1.0e-5
6 1 1 4 1.0e-5
6 1 1 5 1.0e-5
6 1 1 6 1.0e-5
6 1 1 7 1.0e-5
6 1 1 8 1.0e-5
6 1 1 9 1.0e-5
6 1 1 10 1.0e-5
6 1 1 11 1.0e-5
6 1 1 12 1.0e-5
⋮
10 826 554 512 0.000561671
10 826 554 513 0.000634561
10 826 554 514 0.000585903
10 826 555 509 0.000368259
10 826 555 510 0.000381535
10 826 555 511 0.000401867
10 826 555 512 0.000413433
10 826 556 509 0.000353701
10 826 556 510 0.000360669
10 826 556 511 0.000380094
10 826 556 512 0.000386327
## Binary: Save Multiple Data into a JLD File
See for documentation: https://github.com/JuliaIO/JLD.jl
```julia
using JLD
```
```julia
jldopen("mydata.jld", "w") do file
write(file, "hydro", hvals )
write(file, "particles", pvals )
end
```
Open file for read and get an overview of the stored dataset:
```julia
file = jldopen("mydata.jld","r")
```
Julia data file version 0.1.3: mydata.jld
```julia
names(file)
```
2-element Array{String,1}:
"hydro"
"particles"
```julia
hydrodata = read(file, "hydro")
```
Dict{Any,Any} with 5 entries:
:x => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25,…
:y => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25,…
:rho => [6.76838e-28, 6.76838e-28, 6.76838e-28, 6.76838e-28, 6.76838e-28…
:z => [-23.25, -22.5, -21.75, -21.0, -20.25, -19.5, -18.75, -18.0, -17…
:cellsize => [0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75 … …
```julia
particledata = read(file, "particles")
```
Dict{Any,Any} with 4 entries:
:y => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23…
:z => [-23.25, -22.5, -21.75, -21.0, -20.25, -19.5, -18.75, -18.0, -17.25,…
:mass => [4217.58, 4217.58, 4217.58, 4217.58, 4217.58, 4217.58, 4217.58, 4217…
:x => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23…
Compare stored with original data:
```julia
hydrodata == hvals
```
true
```julia
particledata == pvals
```
true
## Binary: Compress Data into a gz-File
```julia
using CodecZlib, Serialization
```
See for documentation: https://github.com/JuliaIO/CodecZlib.jl
```julia
fo= GzipCompressorStream( open("sample-data.jls.gz", "w") ); serialize(fo, hvals); close(fo)
```
```julia
hydrodata1 = deserialize( GzipDecompressorStream( open("sample-data.jls.gz", "r") ) )
```
Dict{Any,Any} with 5 entries:
:x => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25,…
:y => [-23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25, -23.25,…
:rho => [6.76838e-28, 6.76838e-28, 6.76838e-28, 6.76838e-28, 6.76838e-28…
:z => [-23.25, -22.5, -21.75, -21.0, -20.25, -19.5, -18.75, -18.0, -17…
:cellsize => [0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75 … …
```julia
hydrodata1 == hvals
```
true
Prepare variable-array:
```julia
varsarray = [hvals[:x] hvals[:y] hvals[:z] hvals[:cellsize] hvals[:rho]]
```
4879946×5 Array{Float64,2}:
-23.25 -23.25 -23.25 0.75 6.76838e-28
-23.25 -23.25 -22.5 0.75 6.76838e-28
-23.25 -23.25 -21.75 0.75 6.76838e-28
-23.25 -23.25 -21.0 0.75 6.76838e-28
-23.25 -23.25 -20.25 0.75 6.76838e-28
-23.25 -23.25 -19.5 0.75 6.76838e-28
-23.25 -23.25 -18.75 0.75 6.76838e-28
-23.25 -23.25 -18.0 0.75 6.76838e-28
-23.25 -23.25 -17.25 0.75 6.76838e-28
-23.25 -23.25 -16.5 0.75 6.76838e-28
-23.25 -23.25 -15.75 0.75 6.76838e-28
-23.25 -23.25 -15.0 0.75 6.76838e-28
-23.25 -23.25 -14.25 0.75 6.76838e-28
⋮
14.7188 1.96875 -0.046875 0.046875 3.59298e-26
14.7188 1.96875 0.0 0.046875 3.80161e-26
14.7188 1.96875 0.046875 0.046875 4.29495e-26
14.7188 1.96875 0.09375 0.046875 3.96562e-26
14.7188 2.01563 -0.140625 0.046875 2.49252e-26
14.7188 2.01563 -0.09375 0.046875 2.58237e-26
14.7188 2.01563 -0.046875 0.046875 2.71999e-26
14.7188 2.01563 0.0 0.046875 2.79827e-26
14.7188 2.0625 -0.140625 0.046875 2.39398e-26
14.7188 2.0625 -0.09375 0.046875 2.44115e-26
14.7188 2.0625 -0.046875 0.046875 2.57262e-26
14.7188 2.0625 0.0 0.046875 2.61481e-26
```julia
fo= GzipCompressorStream( open("sample-data2.jls.gz", "w") ); serialize(fo, varsarray); close(fo)
```
Read the data again:
```julia
hydrodata2 = deserialize( GzipDecompressorStream( open("sample-data2.jls.gz", "r") ) )
```
4879946×5 Array{Float64,2}:
-23.25 -23.25 -23.25 0.75 6.76838e-28
-23.25 -23.25 -22.5 0.75 6.76838e-28
-23.25 -23.25 -21.75 0.75 6.76838e-28
-23.25 -23.25 -21.0 0.75 6.76838e-28
-23.25 -23.25 -20.25 0.75 6.76838e-28
-23.25 -23.25 -19.5 0.75 6.76838e-28
-23.25 -23.25 -18.75 0.75 6.76838e-28
-23.25 -23.25 -18.0 0.75 6.76838e-28
-23.25 -23.25 -17.25 0.75 6.76838e-28
-23.25 -23.25 -16.5 0.75 6.76838e-28
-23.25 -23.25 -15.75 0.75 6.76838e-28
-23.25 -23.25 -15.0 0.75 6.76838e-28
-23.25 -23.25 -14.25 0.75 6.76838e-28
⋮
14.7188 1.96875 -0.046875 0.046875 3.59298e-26
14.7188 1.96875 0.0 0.046875 3.80161e-26
14.7188 1.96875 0.046875 0.046875 4.29495e-26
14.7188 1.96875 0.09375 0.046875 3.96562e-26
14.7188 2.01563 -0.140625 0.046875 2.49252e-26
14.7188 2.01563 -0.09375 0.046875 2.58237e-26
14.7188 2.01563 -0.046875 0.046875 2.71999e-26
14.7188 2.01563 0.0 0.046875 2.79827e-26
14.7188 2.0625 -0.140625 0.046875 2.39398e-26
14.7188 2.0625 -0.09375 0.046875 2.44115e-26
14.7188 2.0625 -0.046875 0.046875 2.57262e-26
14.7188 2.0625 0.0 0.046875 2.61481e-26
Compare original with loaded data:
```julia
hydrodata2 == varsarray
```
true
Store array with header:
```julia
header = ["x/kpc" "y/kpc" "z/kpc" "cellsize/kpc" "rho/g_cm3"]
fo= GzipCompressorStream( open("sample-data3.jls.gz", "w") ); serialize(fo, [header ; varsarray]); close(fo)
```
```julia
hydrodata3 = deserialize( GzipDecompressorStream( open("sample-data3.jls.gz", "r") ) )
```
4879947×5 Array{Any,2}:
"x/kpc" "y/kpc" "z/kpc" "cellsize/kpc" "rho/g_cm3"
-23.25 -23.25 -23.25 0.75 6.76838e-28
-23.25 -23.25 -22.5 0.75 6.76838e-28
-23.25 -23.25 -21.75 0.75 6.76838e-28
-23.25 -23.25 -21.0 0.75 6.76838e-28
-23.25 -23.25 -20.25 0.75 6.76838e-28
-23.25 -23.25 -19.5 0.75 6.76838e-28
-23.25 -23.25 -18.75 0.75 6.76838e-28
-23.25 -23.25 -18.0 0.75 6.76838e-28
-23.25 -23.25 -17.25 0.75 6.76838e-28
-23.25 -23.25 -16.5 0.75 6.76838e-28
-23.25 -23.25 -15.75 0.75 6.76838e-28
-23.25 -23.25 -15.0 0.75 6.76838e-28
⋮
14.7188 1.96875 -0.046875 0.046875 3.59298e-26
14.7188 1.96875 0.0 0.046875 3.80161e-26
14.7188 1.96875 0.046875 0.046875 4.29495e-26
14.7188 1.96875 0.09375 0.046875 3.96562e-26
14.7188 2.01563 -0.140625 0.046875 2.49252e-26
14.7188 2.01563 -0.09375 0.046875 2.58237e-26
14.7188 2.01563 -0.046875 0.046875 2.71999e-26
14.7188 2.01563 0.0 0.046875 2.79827e-26
14.7188 2.0625 -0.140625 0.046875 2.39398e-26
14.7188 2.0625 -0.09375 0.046875 2.44115e-26
14.7188 2.0625 -0.046875 0.046875 2.57262e-26
14.7188 2.0625 0.0 0.046875 2.61481e-26
## Other File Formats
- HDF5 https://github.com/JuliaIO/HDF5.jl
- Numpy https://github.com/fhs/NPZ.jl
- FITS https://github.com/JuliaAstro/FITSIO.jl
- FITS https://github.com/emmt/EasyFITS.jl
- Matlab https://github.com/JuliaIO/MAT.jl
- GZip https://github.com/JuliaIO/GZip.jl
```julia
```
| Mera | https://github.com/ManuelBehrendt/Mera.jl.git |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.