Data acquisition functions
These functions are used internally and none are exported.
These functions depend on the particulars of the simulation code (e.g. units).
These function read the different output files from the simulation (snapshots, FoF catalogs, sfr.txt, etc.), and load the data into memory as dictionaries.
GalaxyInspector.addRequest
— MethodaddRequest(
request::Dict{Symbol,Vector{String}},
addition::Dict{Symbol,Vector{String}},
)::Dict{Symbol,Vector{String}}
Add the blocks in addition
to request
, only for the types already present in request
.
Arguments
request::Dict{Symbol,Vector{String}}
: The request dictionary forreadSnapshot
.addition::Dict{Symbol,Vector{String}}
: Request dictionary with the blocks to be added, only for the types already present inrequest
.
Returns
- A new dictionary with all the requests.
GalaxyInspector.countSnapshot
— MethodcountSnapshot(simulation_path::String)::Int
Count the number of snapshots in simulation_path
.
This function count the number of snapshots, no the number of snapshot files. So if each snapshot is made of more than one files, the count will not change.
Arguments
simulation_path::String
: Path to the simulation directory, set in the code variableOutputDir
.
Returns
- The number of snapshots.
GalaxyInspector.countStars
— MethodcountStars(path::String)::Int
Count the number of stars in a snapshot, excluding wind particles.
Arguments
path::String
: Path to the snapshot file or folder.
Returns
- The number of stars.
GalaxyInspector.findQtyExtrema
— MethodfindQtyExtrema(
simulation_path::String,
slice_n::Int,
component::Symbol,
block::String;
<keyword arguments>
)::NTuple{2,<:Number}
Compute the minimum and maximum values of block
.
Arguments
simulation_path::String
: Path to the simulation directory, set in the code variableOutputDir
.slice_n::Int
: Selects which snapshot to plot, starts at 1 and is independent of the number in the file name. If every snapshot is present, the relation isslice_n
= (number in filename) + 1. If set to a negative number, the values in the whole simulation will be compared.component::Symbol
: Cell/particle type. The possibilities are the keys ofPARTICLE_INDEX
.block::String
: Target block. The possibilities are the keys ofQUANTITIES
.f::Function=identity
: A function with the signature:f(data) -> values
where
data::VecOrMat{<:Number}
: Data returned bygetBlock
.values::Vector{<:Number}
: A vector with the values to be compared.
Returns
- Tuple with the minimum and maximum values.
GalaxyInspector.findRealStars
— MethodfindRealStars(path::String)::Vector{Bool}
Find which stellar particles are real stars and not wind particles.
Arguments
path::String
: Path to the snapshot file or folder.
Returns
- A boolean vector with true for stars and false for wind particles.
GalaxyInspector.getBlock
— MethodgetBlock(path::String, component::Symbol, block::String)::VecOrMat{<:Number}
Convenience function to directly get the data associated with one block.
Arguments
path::String
: Path to the snapshot file or folder.component::Symbol
: Type of cell/particle. The possibilities are the keys ofPARTICLE_INDEX
.block::String
: Target block. The possibilities are the keys ofQUANTITIES
.
Returns
- The data for
block
.
GalaxyInspector.getGroupCatPaths
— MethodgetGroupCatPaths(simulation_path::String)::Dict{Symbol,Vector{String}}
Find the path and number of every group catalog in simulation_path
.
If each group catalog is made of multiple files, the :paths
field will have paths to folders, each one containing the sub-files of the corresponding group catalog.
Arguments
simulation_path::String
: Path to the simulation directory, set in the code variableOutputDir
.
Returns
A dictionary with the following shape:
:numbers
-> The number that characterize each group catalog.:paths
-> The full path to each group catalog.
GalaxyInspector.getSnapshotPaths
— MethodgetSnapshotPaths(simulation_path::String)::Dict{Symbol,Vector{String}}
Find the path and number of every snapshot in simulation_path
.
If each snapshot is made of multiple files, the :paths
field will have paths to folders, each one containing the sub-files of the corresponding snapshot.
Arguments
simulation_path::String
: Path to the simulation directory, set in the code variableOutputDir
.
Returns
A dictionary with the following shape:
:numbers
-> The number that characterize each snapshot.:paths
-> The full path to each snapshot.
GalaxyInspector.groupcatTypes
— MethodgroupcatTypes(data_dict::Dict)::Vector{Symbol}
Find which group catalog data types are part of the keys of data_dict
.
Arguments
data_dict::Dict
: A dictionary.
Returns
- A vector with the group catalog data types.
GalaxyInspector.groupcatTypes
— MethodgroupcatTypes(path::String)::Vector{Symbol}
Find which group catalog data types are part of the snapshot in path
.
Arguments
path::String
: Path to the snapshot file or folder.
Returns
- A vector with the group catalog data types.
GalaxyInspector.internalUnits
— MethodinternalUnits(quantity::String, path::String)::Union{Unitful.Quantity,Unitful.Units}
Get the factor to convert a plain number into a Unitful quantity, using the correct internal code units.
Arguments
quantity::String
: Target quantity. The options are the keys ofQUANTITIES
.path::String
: Path to the snapshot file or folder.
Returns
- A Unitful quantity or unit.
GalaxyInspector.isBlockPresent
— MethodisBlockPresent(block::String, group::HDF5.Group)::Bool
Checks if a given data block exists in a HDF5 group.
Arguments
block::String
: Target block. The possibilities are the keys ofQUANTITIES
.group::HDF5.Group
: HDF5 group.
Returns
- If
block
exists ingroup
.
GalaxyInspector.isBlockPresent
— MethodisBlockPresent(component::Symbol, block::String, path::String)::Bool
Checks if a given block exists in a snapshot.
Arguments
component::Symbol
: The cell/particle type of the target block. The possibilities are the keys ofPARTICLE_INDEX
.block::String
: Target block. The possibilities are the keys ofQUANTITIES
.path::String
: Path to the snapshot file or folder.
Returns
- If
block
exists in the snapshot.
GalaxyInspector.isCosmological
— MethodisCosmological(path::String)::Bool
Check if the snapshot in path
comes from a cosmological simulation.
If each snapshot is made of multiple files, the function will read the first chunk to check if the simulation is cosmological.
Arguments
path::String
: Path to the snapshot file or folder.
Returns
If the simulation is cosmological
false
-> Newtonian simulation (ComovingIntegrationOn
= 0,Redshift
= 0.0).true
-> Cosmological simulation (ComovingIntegrationOn
= 1,Redshift
!= 0.0).
GalaxyInspector.isSubfindActive
— MethodisSubfindActive(path::String)::Bool
Check if there is information about the halos and subhalos in the group catalog file.
Arguments
path::String
: Path to the group catalog file or folder.
Returns
- If there are halo and subhalo information in the group catalog file.
GalaxyInspector.makeDataDict
— MethodmakeDataDict(
simulation_path::String,
slice_n::Int,
request::Dict{Symbol,Vector{String}},
simulation_table::DataFrame,
)::Dict
Construct a data dictionary for a single snapshot.
Arguments
simulation_path::String
: Path to the simulation directory, set in the code variableOutputDir
.slice_n::Int
: Selects the target snapshot. Starts at 1 and is independent of the number in the file name. If every snapshot is present, the relation isslice_n
= (number in filename) + 1.request::Dict{Symbol,Vector{String}}
: Dictionary with the shapecell/particle type
-> [block
,block
, ...], where the possible types are the keys ofPARTICLE_INDEX
, and the possible quantities are the keys ofQUANTITIES
.simulation_table::DataFrame
: Dataframe with the path, time stamps, and number of each snapshot and group catalog file insimulation_path
. It must have the same shape as the one returned bymakeSimulationTable
.
Returns
A dictionary with the following shape:
:sim_data
-> ::Simulation (seeSimulation
).:snap_data
-> ::Snapshot (seeSnapshot
).:gc_data
-> ::GroupCatalog (seeGroupCatalog
).cell/particle type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).cell/particle type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).cell/particle type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).- ...
groupcat type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).groupcat type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).groupcat type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).- ...
GalaxyInspector.makeDataDict
— MethodmakeDataDict(
simulation_path::String,
slice_n::Int,
request::Dict{Symbol,Vector{String}},
)::Dict
Construct a data dictionary for a single snapshot.
Arguments
simulation_path::String
: Path to the simulation directory, set in the code variableOutputDir
.slice_n::Int
: Selects the target snapshot. Starts at 1 and is independent of the number in the file name. If every snapshot is present, the relation isslice_n
= (number in filename) + 1.request::Dict{Symbol,Vector{String}}
: Dictionary with the shapecell/particle type
-> [block
,block
, ...], where the possible types are the keys ofPARTICLE_INDEX
, and the possible quantities are the keys ofQUANTITIES
.
Returns
A dictionary with the following shape:
:sim_data
-> ::Simulation (seeSimulation
).:snap_data
-> ::Snapshot (seeSnapshot
).:gc_data
-> ::GroupCatalog (seeGroupCatalog
).cell/particle type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).cell/particle type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).cell/particle type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).- ...
groupcat type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).groupcat type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).groupcat type
-> (block
-> data ofblock
,block
-> data ofblock
, ...).- ...
GalaxyInspector.makeSimulationTable
— MethodmakeSimulationTable(simulation_path::String)::DataFrame
Construct a dataframe with the path, time stamps and number of each snapshot and group catalog file in simulation_path
.
Arguments
simulation_path::String
: Path to the simulation directory, set in the code variableOutputDir
.
Returns
A dataframe with 8 columns:
:ids
-> Dataframe index of each snapshot, i.e. if there are 10 snapshots in total it runs from 1 to 10.:numbers
-> Number in the file name of each snapshot.:scale_factors
-> Scale factor of each snapshot.:redshifts
-> Redshift of each snapshot.:physical_times
-> Physical time since the Big Bang of each snapshot.:lookback_times
-> Physical time left to reach the last snapshot.:snapshot_paths
-> Full path to the snapshots.:groupcat_paths
-> Full path to the group catalog files.
GalaxyInspector.mergeRequests
— MethodmergeRequests(requests::Dict{Symbol,Vector{String}}...)::Dict{Symbol,Vector{String}}
Merge several request dictionaries, ignoring duplicates.
Arguments
requests
: The request dictionaries forreadSnapshot
.
Returns
- A new dictionary with all the requests.
GalaxyInspector.readCpuFile
— MethodreadCpuFile(
file_path::String,
targets::Vector{String};
<keyword arguments>
)::Dict{String,Matrix{Float64}}
Read the cpu.txt
file.
For each process in targets
a matrix with all the CPU usage data is returned.
Arguments
file_path::String
: Path to thecpu.txt
file.targets::Vector{String}
: Target processes.step::Int=1
: Step used to traverse the rows.
Returns
A dictionary with the following shape:
target process
-> matrix with columns:- Time step.
- Simulation time (scale factor for cosmological simulations and physical time for non-cosmological simulations).
- Clock time in seconds.
- Clock time as a percentage.
- Total clock time in seconds.
- Total clock time as a percentage.
GalaxyInspector.readGoupCatBlocks
— MethodreadGoupCatBlocks(
file_path::String,
snapshot_path::String,
request::Dict{Symbol,Vector{String}},
)::Dict{Symbol,Dict{String,VecOrMat{<:Number}}}
Read the specified blocks from a group catalog file.
Arguments
file_path::String
: Path to the group catalog file.snapshot_path::String
: Path to the corresponding snapshot file or folder. This is needed for unit conversion.request::Dict{Symbol,Vector{String}}
: The blocks to be read. It must have the shapegroup type
-> [block
,block
,block
].
Returns
- A dictionary with the following shape:
group type
-> (block
-> data ofblock
).
GalaxyInspector.readGroupCatHeader
— MethodreadGroupCatHeader(path::Union{String,Missing})::GroupCatHeader
Read the header of a group catalog in the HDF5 format.
If each group catalog is made of multiple files, the function will read the header of the first one.
Arguments
path::Union{String,Missing}
: Path to the group catalog file or folder.
Returns
GalaxyInspector.readGroupCatalog
— MethodreadGroupCatalog(
path::Union{String,Missing},
snapshot_path::String,
request::Dict{Symbol,Vector{String}},
)::Dict{Symbol,Dict{String,VecOrMat{<:Number}}}
Read the specified blocks from a group catalog file or folder.
Arguments
path::Union{String,Missing}
: Path to the group catalog file or folder.snapshot_path::String
: Path to the corresponding snapshot file or folder. This is needed for unit conversion.request::Dict{Symbol,Vector{String}}
: Which blocks will be read. It must have the shapegroup type
-> [block
,block
,block
].
Returns
- A dictionary with the following shape:
group type
-> (block
-> data ofblock
).
GalaxyInspector.readSfrFile
— MethodreadSfrFile(
file_path::String,
snap_path::String,
)::Dict{Int32,VecOrMat{<:Number}}
Read the sfr.txt
file.
Arguments
file_path::String
: Path to thesfr.txt
file.snapshot_path::String
: Path to one snapshot file or folder of the simulation. This is needed for unit conversion.
Returns
A dictionary with the following shape:
1
-> Time or scale factor (internal units).2
-> Total stellar mass to be formed prior to stochastic sampling (internal units).3
-> Instantaneous star formation rate of all cells ($\mathrm{M_\odot \, yr^{-1}}$).4
-> Instantaneous star formation rate of active cells ($\mathrm{M_\odot \, yr^{-1}}$).5
-> Total mass in stars formed after stochastic sampling (internal units).6
-> Cumulative stellar mass formed (internal units).
GalaxyInspector.readSnapBlocks
— MethodreadSnapBlocks(
file_path::String,
request::Dict{Symbol,Vector{String}},
)::Dict{Symbol,Dict{String,VecOrMat{<:Number}}}
Read the specified blocks from a snapshot file.
Arguments
file_path::String
: Path to the snapshot file.request::Dict{Symbol,Vector{String}}
: The blocks to be read. It must have the shapecell/particle type
-> [block
,block
,block
].
Returns
- A dictionary with the following shape:
cell/particle type
-> (block
-> data ofblock
).
GalaxyInspector.readSnapHeader
— MethodreadSnapHeader(path::String)::SnapshotHeader
Read the header of a snapshot in the HDF5 format.
If each snapshot is made of multiple files, the function will read the header of the first chunk.
Arguments
path::String
: Path to the snapshot file or folder.
Returns
- A
SnapshotHeader
structure.
GalaxyInspector.readSnapshot
— MethodreadSnapshot(
path::Union{String,Missing},
request::Dict{Symbol,Vector{String}},
)::Dict{Symbol,Dict{String,VecOrMat{<:Number}}}
Read the specified blocks from a snapshot file or folder.
Arguments
path::Union{String,Missing}
: Path to the snapshot file or folder.request::Dict{Symbol,Vector{String}}
: Which blocks will be read. It must have the shapecell/particle type
-> [block
,block
,block
].
Returns
- A dictionary with the following shape:
cell/particle type
-> (block
-> data ofblock
).
GalaxyInspector.readTemperature
— MethodreadTemperature(file_path::String)::Vector{<:Unitful.Temperature}
Compute the temperature of the gas cells in a snapshot.
Arguments
file_path::String
: Path to the snapshot file.
Returns
- The temperature of the gas cells.
GalaxyInspector.readTime
— MethodreadTime(path::String)::Float64
Read the "Time" field in the header of a snapshot file.
If each snapshot is made of multiple files, the function will read the header of the first chunk.
Arguments
path::String
: Path to the snapshot file or folder.
Returns
- The "Time" field in the header (for cosmological simulations it is the scale factor).
GalaxyInspector.snapshotTypes
— MethodsnapshotTypes(data_dict::Dict)::Vector{Symbol}
Find which cell/particle types are part of the keys of data_dict
.
Arguments
data_dict::Dict
: A dictionary.
Returns
- A vector with the cell/particle types.
GalaxyInspector.snapshotTypes
— MethodsnapshotTypes(path::String)::Vector{Symbol}
Find which cell/particle types are part of the snapshot in path
.
Arguments
path::String
: Path to the snapshot file or folder.
Returns
- A vector with the cell/particle types.