swiftsimio.masks module

Loading functions and objects that use masked information from the SWIFT snapshots.

class swiftsimio.masks.SWIFTMask(metadata: SWIFTMetadata, spatial_only=True)[source]

Bases: object

Main masking object. This can have masks for any present particle field in it. Pass in the SWIFTMetadata.

constrain_mask(ptype: str, quantity: str, lower: unyt_quantity, upper: unyt_quantity)[source]

Constrains the mask further for a given particle type, and bounds a quantity between lower and upper values.

We update the mask such that

lower < ptype.quantity <= upper

The quantities must have units attached.

Parameters:
  • ptype (str) – particle type

  • quantity (str) – quantity being constrained

  • lower (unyt.array.unyt_quantity) – constraint lower bound

  • upper (unyt.array.unyt_quantity) – constraint upper bound

See also

constrain_spatial

method to generate spatially constrained cell mask

constrain_spatial(restrict)[source]

Uses the cell metadata to create a spatial mask.

This mask is necessarily approximate and is coarse-grained to the cell size.

Parameters:

restrict (list) –

length 3 list of length two arrays giving the lower and upper bounds for that axis, e.g.

restrict = [

[0.5, 0.7], [0.1, 0.9], [0.0, 0.1]

]

These values must have units associated with them. It is also acceptable to have a row as None to not restrict in this direction.

See also

constrain_mask

method to further refine mask

convert_masks_to_ranges()[source]

Converts the masks to range masks so that they take up less space.

This is non-reversible. It is also not required, but can help save space on highly constrained machines before you start reading in the data.

If you don’t know what you are doing please don’t use this.

get_masked_counts_offsets() -> (typing.Dict[str, <built-in function array>], typing.Dict[str, <built-in function array>])[source]

Returns the particle counts and offsets in cells selected by the mask

Returns:

Dictionaries containing the particle offets and counts for each particle type. For example, the particle counts dictionary would be of the form

{"gas": [g_0, g_1, ...],
 "dark matter": [bh_0, bh_1, ...], ...}

where the keys would be each of the particle types and values are arrays of the number of corresponding particles in each cell (in this case there would be g_0 gas particles in the first cell, g_1 in the second, etc.). The structure of the dictionaries is the same for the offsets, with the arrays now storing the offset of the first particle in the cell.

Return type:

Dict[str, np.array], Dict[str, np.array]