Random

class sf3dmodels.grid.fillgrid.Random(grid, smart=True)[source] [edit on github]

Bases: sf3dmodels.grid.Build_r, sf3dmodels.grid.fillgrid.SmartRejectionDummies

Methods for filling in the grid randomly with (non-physical) dummy points.

Parameters:
GRID : Struct

Grid structure to compute.

Attributes:
r : numpy.ndarray, shape (GRID.NPoints,)

Array of \(r\) coordinate values in input units.

Methods Summary

by_density(self, density[, mass_fraction, …]) Under development.
by_mass(self, mass, prop[, prop_fill, …]) Fills up the grid with uniformly-distributed random dummy points in a spherical section based on a mass threshold.
spherical(self, prop[, prop_fill, r_min, …]) Fills up the grid with uniformly-distributed random dummy points in a spherical section.

Methods Documentation

by_density(self, density, mass_fraction=0.5, r_max=None, n_dummy=None, r_steps=100)[source] [edit on github]

Under development.

Fills up the grid with uniformly-distributed random points according to a mass criterion, given a density field.

Useful when the model does provide the density but not the mass. However the aim is identical to the method by_mass.

The mass is calculated via the mean density enclosed in a sphere growing on each iteration until the mass_fraction is reached, which sets the inner radius of the spherical section where the dummy points will be generated.

Parameters:
density : array_like

list or numpy.ndarray with the density of each cell, where the i-th density corresponds to the i-th cell of the GRID.

mass_fraction : float

The mass fraction to be enclosed by the inner radius of the spherical section. Sets the inner radius r_min at spherical.

Defaults to 0.5, i.e, by default the computed inner radius will enclose (approx.) the 50% of the total mass.

r_max : float

Outer radius of the spherical section enclosing the random dummy points.

Defaults to None. In that case it takes the distance of the farthest point in the grid.

n_dummy : int

Number of dummy points to be generated.

Defaults to None. In that case n_dummy = GRID.NPoints / 100

r_steps : int

Number of divisions along the radial coordinate to compute the enclosed mass.

Defaults to 100.

Returns:
In prep.

See also

by_mass, spherical
by_mass(self, mass, prop, prop_fill={}, mass_fraction=0.5, r_max=None, n_dummy=None, r_steps=100)[source] [edit on github]

Fills up the grid with uniformly-distributed random dummy points in a spherical section based on a mass threshold.

The inner radius of the spherical section will be equal to the radius of a sphere enclosing the input mass_fraction.

The function iterates over the radial coordinate until it finds an r=r0 where the enclosed mass fraction exceeds the input mass_fraction. Afterwards, it invokes spherical(r_min = r0, r_max = r_max, n_dummy = n_dummy), see spherical.

Parameters:
mass : array_like

list or numpy.ndarray with the mass of each cell, where the i-th mass corresponds to the i-th cell of the GRID.

prop : dict

Dictionary of arrays of physical properties to be filled up by dummy values.

prop_fill : dict, optional

Dictionary specifying the dummy value (scalar) with which each physical property will be filled up.

Defaults to {}. In that case, the filling dummy value is zero for all the properties.

mass_fraction : float, optional

The mass fraction enclosed by the inner radius of the spherical section. n - Note that this sets the inner radius r_min at spherical.

Defaults to 0.5, i.e, by default the computed inner radius will enclose (approx.) the 50% of the total mass.

r_max : float, optional

Outer radius of the spherical section enclosing the random dummy points.

Defaults to None. In that case it takes the distance of the farthest point in the grid.

n_dummy : int, optional

Number of dummy points to be generated.

Defaults to None. In that case n_dummy = GRID.NPoints / 100

r_steps : int, optional

Number of divisions along the radial coordinate to compute the enclosed mass.

Defaults to 100.

Returns:
out : dict
Returns a dictionary with the following keys:
r_rand : numpy.ndarray

Radial coordinate of the computed random points.

r_min : float

Computed inner radius of the spherical section which encloses (approximately) the input mass fraction and above which the random`dummy points are generated.

r_max : float

Outer radius of the spherical section enclosing the random dummy points.

comp_fraction : float

Computed mass fraction enclosed by r_min. The higher r_steps the closer this value will be to the input mass fraction.

n_dummy : int

Number of dummy points generated.

See also

by_density, spherical
spherical(self, prop, prop_fill={}, r_min=0.0, r_max=None, n_dummy=None)[source] [edit on github]

Fills up the grid with uniformly-distributed random dummy points in a spherical section.

Parameters:
prop : dict

Dictionary of arrays of physical properties to be filled up by dummy values.

prop_fill : dict, optional

Dictionary specifying the dummy value (scalar) with which each physical property will be filled up.

Defaults to {}. In that case, the filling dummy value is zero for all the properties.

r_min : float, optional

Inner radius of the spherical section enclosing the random dummy points.

Defaults to zero.

r_max : float, optional

Outer radius of the spherical section enclosing the random dummy points.

Defaults to None. In that case, the maximum radius takes the distance of the farthest point in the grid from the coordinates centre.

n_dummy : int, optional

Number of dummy points to be generated.

Defaults to None. In that case, n_dummy = GRID.NPoints / 100

Returns:
out : dict
Returns a dictionary with the following keys:
r_rand : numpy.ndarray

Radial coordinate of the computed random points.

n_dummy : int

Number of dummy points generated.

See also

box