Operations
Transformations
CosmoParticles.rotate
— Functionrotate(p::AbstractParticles, rotmat::AbstractMatrix{<:Real}, prop)
rotate(p::AbstractParticles, rotmat::AbstractMatrix{<:Real}, props=[:pos, :vel])
Rotates the specified properties props
of the particles p
by the rotation matrix rotmat
.
Creates a copy of the particles with only new pointers to the rotated properties (by default position and velocity). This means that mutations to other properties will affect both the original particles as well as the rotated copied particles. The properties should be given as a single Symbol
, or a vector of Symbol
s. Only the existing quantities will be rotated (e.g., this method does not throw an error if velocities are not given for the particles).
rotate(pc::AbstractParticleCollection, rotmat::AbstractMatrix{<:Real}, prop)
rotate(pc::AbstractParticleCollection, rotmat::AbstractMatrix{<:Real}, props=[:pos, :vel])
Rotates the specified properties props
of the particles in the collection by the rotation matrix rotmat
.
Creates a copy of the particle collection with only new pointers to the rotated particles (by default position and velocity). The properties should be given as a single Symbol
, or a vector of Symbol
s.
LinearAlgebra.rotate!
— FunctionLinearAlgebra.rotate!(p::AbstractParticles, rotmat::AbstractMatrix{<:Real}, props=[:pos, :vel])
LinearAlgebra.rotate!(p::AbstractParticles, rotmat::AbstractMatrix{<:Real}, prop)
LinearAlgebra.rotate!(pc::AbstractParticleCollection, rotmat::AbstractMatrix{<:Real}, props=[:pos, :vel])
LinearAlgebra.rotate!(pc::AbstractParticleCollection, rotmat::AbstractMatrix{<:Real}, prop)
In-place version of rotate
.
This function is reexported.
CosmoParticles.translate
— Functiontranslate(p::AbstractParticles, Δx, prop::Symbol=:pos)
Translates the specified property of the particles p
by Δx
.
Creates a copy of the particles with only new pointers to the translated property. Typically, Δx
will be an AbstractVector
, e.g., for positions or velocities.
translate(pc::AbstractParticleCollection, Δx::AbstractVector{<:Number}, prop::Symbol=:pos)
Translates the specified property of the particles in the collection pc
by Δx
.
Creates a copy of the particle collection with only new pointers to the translated properties for the particles. Typically, Δx
will be an AbstractVector
, e.g., for positions or velocities.
CosmoParticles.translate!
— Functiontranslate!(p::AbstractParticles, Δx, prop::Symbol=:pos)
translate!(pc::AbstractParticleCollection, Δx, prop::Symbol=:pos)
In-place version of translate
.
CosmoParticles.translate_periodic
— Functiontranslate_periodic(p::AbstractParticles, centerpos, period, prop::Symbol=:pos)
translate_periodic(pc::AbstractParticleCollection, centerpos, period, prop::Symbol=:pos)
Translates the specified property of the particles or collection by the period
such that all particles are the closest to centerpos
as possible.
Creates a copy of the particles or the collection with only new pointers to the translated property. Typically, centerpos
will be an AbstractVector
, e.g., for positions, and period
can be a Number
or AbstractVector
, depending on if the period is the same for all dimensions or if they are different.
CosmoParticles.translate_periodic!
— Functiontranslate_periodic!(p::AbstractParticles, centerpos, period, prop::Symbol=:pos)
translate_periodic!(pc::AbstractParticleCollection, centerpos, period, prop::Symbol=:pos)
In-place version of translate_periodic
.
CosmoParticles.translate_periodic_to_center
— Functiontranslate_periodic_to_center(p::AbstractParticles, centerpos, period, prop::Symbol=:pos)
translate_periodic_to_center(pc::AbstractParticleCollection, centerpos, period, prop::Symbol=:pos)
Translates the specified property of the particles or collection to place centerpos
at the origin.
The particles are translated periodically to place them closest to centerpos
.
Creates a copy of the particles or the collection with only new pointers to the translated property. Typically, centerpos
will be an AbstractVector
, e.g., for positions, and period
can be a Number
or AbstractVector
, depending on if the period is the same for all dimensions or if they are different.
Also see translate_periodic
.
CosmoParticles.translate_periodic_to_center!
— Functiontranslate_periodic_to_center!(p::AbstractParticles, centerpos, period, prop::Symbol=:pos)
translate_periodic_to_center!(pc::AbstractParticleCollection, centerpos, period, prop::Symbol=:pos)
In-place version of translate_periodic_to_center
.
CosmoParticles.to_comoving
— Functionto_comoving(p::AbstractParticles, z::Real; propexp=[(:pos, 1), (:vel, 1)])
to_comoving(pc::AbstractParticleCollection; propexp=[(:pos, 1), (:vel, 1)])
Create new particles or collection with particle properties converted from physical to comoving.
The properties and the positional exponent of their units (e.g., 1 for positions, 3 for volumes, and -3 for densities) are passed as the keyword argument propexp
as a vector of tuples. The redshift z
is obtained from redshift
for the particle collection.
The properties are multiplied by $(1 + z)^n$ where $n$ is the positional exponent.
CosmoParticles.to_comoving!
— Functionto_comoving!(p::AbstractParticles, z::Real; propexp=[(:pos, 1), (:vel, 1)])
to_comoving!(pc::AbstractParticleCollection; propexp=[(:pos, 1), (:vel, 1)])
Convert particle properties from physical to comoving in-place.
In-place version of to_comoving
.
CosmoParticles.to_physical
— Functionto_physical(p::AbstractParticles, z::Real; propexp=[(:pos, 1), (:vel, 1)])
to_physical(pc::AbstractParticleCollection; propexp=[(:pos, 1), (:vel, 1)])
Create new particles or collection with particle properties converted from comoving to physical.
The properties and the positional exponent of their units (e.g., 1 for positions, 3 for volumes, and -3 for densities) are passed as the keyword argument propexp
as a vector of tuples. The redshift z
is obtained from redshift
for the particle collection.
The properties are multiplied by $(1 + z)^{-n}$ where $n$ is the positional exponent.
CosmoParticles.to_physical!
— Functionto_physical!(p::AbstractParticles, z::Real; propexp=[(:pos, 1), (:vel, 1)])
to_physical!(pc::AbstractParticleCollection; propexp=[(:pos, 1), (:vel, 1)])
Convert particle properties from comoving to physical in-place.
In-place version of to_physical
.
Further Operations
Base.sort
— FunctionBase.sort(p::AbstractParticles, prop::Symbol; affect=keys(p), kwargs...)
Create new particles with the particles sorted according to the specified property.
All property arrays of the particles are rearranged according to the property being sorted. If the keyword argument affect
is a non-empty vector of Symbol
s, only those properties are rearranged and added to the newly created particles object. The other keyword arguments are passed on to Base.sortperm
.
The sorting algorithm for unitful properties may also be RadixSort
from SortingAlgorithms.jl.
Base.sort(pc::AbstractParticleCollection, prop::Symbol; [affect,] kwargs...)
Create new particle collection with the particles in the collection sorted by calling Base.sort
on each of the particles objects.
If the keyword argument affect
is a non-empty vector of Symbol
s, only the affected properties are kept for the particles. The specified affected properties do not have to be available for all particles. For collections of Particles
, affect
can alternatively be a vector of tuples in the following form: [(:dm, [:id, :pos, :mass]), (:gas, [:id, :pos, :mass, :temp])]
.
Base.sort!
— FunctionBase.sort!(p::AbstractParticles, prop::Symbol; kwargs...)
Sort the particles in-place according to the specified property.
All property arrays of the particles are rearranged in-place according to the property being sorted. The keyword arguments are passed on to Base.sortperm
.
The sorting algorithm for unitful properties may also be RadixSort
from SortingAlgorithms.jl.
Base.sort!(pc::AbstractParticleCollection, prop::Symbol; kwargs...)
Sort the particles in the collection in-place by calling Base.sort!
on each of the Particles
objects.
Base.filter
— FunctionBase.filter(f, p::AbstractParticles; affect=keys(p))
Base.filter(f, pc::AbstractParticleCollection[; affect])
Create new particles or collection with the particles filtered by a mask returned by the function f
.
The function f
takes the particles as argument and has to either return a BitArray
mask with a length of the number of particles or an array of indices. If the keyword argument affect
is a non-empty vector of Symbol
s, only those properties are filtered and added to the newly created particles object.
For collections of Particles
, affect
can alternatively be a vector of tuples in the following form: [(:dm, [:id, :pos, :mass]), (:gas, [:id, :pos, :mass, :temp])]
.
Base.filter(p::AbstractParticles, ids; affect=keys(p))
Base.filter(pc::AbstractParticleCollection; ids[, affect])
Create new particles or collection with them filtered by keeping only the particles with the given IDs.
If the keyword argument affect
is a non-empty vector of Symbol
s, only those properties are filtered and added to the newly created particles object.
For collections of Particles
, affect
can alternatively be a vector of tuples in the following form: [(:dm, [:id, :pos, :mass]), (:gas, [:id, :pos, :mass, :temp])]
.
Base.filter(p::AbstractParticles, geo::AbstractCosmoGeometry, prop::Symbol=:pos; affect=keys(p))
Base.filter(pc::AbstractParticleCollection, geo::AbstractCosmoGeometry, prop::Symbol=:pos[; affect])
Create new particles or collection with them filtered by keeping only the particles inside the given AbstractCosmoGeometry
.
The geometry filter is applied to the property specified. If the keyword argument affect
is a non-empty vector of Symbol
s, only those properties are filtered and added to the newly created particles object.
For collections of Particles
, affect
can alternatively be a vector of tuples in the following form: [(:dm, [:id, :pos, :mass]), (:gas, [:id, :pos, :mass, :temp])]
.
Base.filter!
— FunctionBase.filter!(f, p::AbstractParticles)
Base.filter!(f, pc::AbstractParticleCollection)
Filter the particles or collection in-place by masks returned by the function f
.
The function f
takes a particles object as argument and has to either return a BitArray
mask with a length of the number of particles or an array of indices.
Base.filter!(p::AbstractParticles; ids)
Base.filter!(pc::AbstractParticleCollection; ids)
Filter the particles or collection in-place by keeping only the particles with the given IDs.
Base.filter!(p::AbstractParticles, geo::AbstractCosmoGeometry, prop::Symbol=:pos)
Base.filter!(pc::AbstractParticleCollection, geo::AbstractCosmoGeometry, prop::Symbol=:pos)
Filter the particles or collection in-place by keeping only the particles inside the given AbstractCosmoGeometry
.
The geometry filter is applied to the property specified.
Missing docstring for Base.delete
. Check Documenter's build log for details.
Base.delete!
— FunctionBase.delete!(p::AbstractParticles; ids)
Base.delete!(pc::AbstractParticleCollection; ids)
Filter the particles or collection in-place by removing all particles with the given IDs.
Base.delete!(p::AbstractParticles, geo::AbstractCosmoGeometry, prop::Symbol=:pos)
Base.delete!(pc::AbstractParticleCollection, geo::AbstractCosmoGeometry, prop::Symbol=:pos)
Filter the particles or collection in-place by keeping only the particles outside the given AbstractCosmoGeometry
.
The geometry filter is applied to the property specified.
CosmoParticles.applyind
— FunctionCosmoParticles.applyind(p::AbstractParticles, ind::Union{AbstractVector,Colon}; affect=keys(p))
Create new particles with the given indices or mask applied to all particle properties.
This can also be called by the simple syntax p[ind]
. If the keyword argument affect
is a vector of Symbol
s, only those properties are indexed into and added to the newly created particles object.
This is not exported.
CosmoParticles.applyind!
— FunctionCosmoParticles.applyind!(p::AbstractParticles, ind::Union{AbstractVector,Colon})
In-place application of indices or mask to all particle properties.
This is not exported.
CosmoParticles.removeind
— FunctionCosmoParticles.removeind(p::AbstractParticles, ind::AbstractVector; affect=keys(p))
Create new particles without the given indices or mask applied to all particle properties.
This can also be called by the simple syntax p[ind]
. If the keyword argument affect
is a vector of Symbol
s, only those properties are indexed into and added to the newly created particles object.
This is not exported.
CosmoParticles.removeind!
— FunctionCosmoParticles.removeind!(p::AbstractParticles, ind::AbstractVector)
In-place removal of indices to all particle properties.
This is not exported.
CosmoParticles.findall_in
— FunctionCosmoParticles.findall_in(a::AbstractVector, set)
Return all indices of a
that are in set
.
If both a
and set
are sorted AbstractVector
s, then the optimized findall_in_sorted
is called. Otherwise, a Set
is constructed from the Vector
to perform the checks with in
.
This is not exported.
CosmoParticles.findall_in_sorted
— FunctionCosmoParticles.findall_in_sorted(a::AbstractVector, set::AbstractVector)
Return all indices of a
that are in set
, where both a
and set
are assumed to be sorted.
This uses an optimized algorithm that is faster than creating a Set
from set
and performing checks with in
.
This is not exported.
Internals
CosmoParticles.matrix_rotate
— FunctionCosmoParticles.matrix_rotate(vals::AbstractMatrix{<:Number}, rotmat::AbstractMatrix{<:Real})
Returns vals
rotated by the rotation matrix rotmat
by regular matrix multiplication. Works for any dimensions and is optimized for unitful arrays.
This is not exported.
CosmoParticles.matrix_rotate!
— FunctionCosmoParticles.matrix_rotate!(vals::AbstractMatrix{<:Number}, rotmat::AbstractMatrix{<:Real})
In-place version of CosmoParticles.matrix_rotate
, overwriting vals
.
This is not exported.
CosmoParticles.matrix_rotate!(dst::AbstractMatrix{<:Number}, vals::AbstractMatrix{<:Number}, rotmat::AbstractMatrix{<:Real})
In-place version of CosmoParticles.matrix_rotate
, overwriting dst
.
This is not exported.
CosmoParticles._applyind
— FunctionCosmoParticles._applyind(a, ind::Union{AbstractVector,Colon})
Apply indices or mask to a Number
, Vector
, or Matrix
.
Other possible types: Nothing
The following indexing is applied:
a::Number
:a
is returned directly.a::Vector
:a[ind]
is returned.a::Matrix
:a[:, ind]
is returned.
This is not exported.
CosmoParticles._removeind
— FunctionCosmoParticles._removeind(a, ind::AbstractVector)
Remove indices of a Number
, Vector
, or Matrix
.
The vector ind
has to contain sorted and unique indices: sort!(unique!(ind))
. Additionally, all elements in ind
have to be valid indices in a
.
Other possible types: Nothing
The following indexing is applied:
a::Number
:a
is returned directly.a::Vector
:a[Not(ind)]
is returned.a::Matrix
:a[:, Not(ind)]
is returned.
This is not exported.
CosmoParticles._translate_periodic
— Function_translate_periodic(x::Number, x₀::Number, period::Number, period_half::Number=1//2*period)
Returns the coordinate x
shifted by the period
if reference coordinate x₀
is on the other side.
For periodic simulation boxes, the period corresponds to the boxlength.
This is not exported.