swiftsimio.masks module

Provide functions and objects that use mask information from SWIFT snapshots.

class swiftsimio.masks.SWIFTMask(filename: Path, metadata: SWIFTMetadata, *, safe_padding: bool | float = 0.1, handle: File | None = None, spatial_only: bool | None = None)[source]

Bases: HandleProvider

Main masking object. This can have masks for any present particle type in it.

For catalogues (e.g. SOAP) where all arrays are the same size there can be a “shared” mask that is stored once and used for all of them.

Takes the SWIFT metadata and enables individual property-by-property masking when reading from snapshots. When masking like this order-in-file is not preserved, i.e. the 7th particle may not be the 7th particle in the file.

Parameters:
  • filename (Path) – File to read cell metadata from.

  • metadata (SWIFTMetadata) – Metadata loaded from snapshot.

  • safe_padding (bool or float, optional) – If snapshot does not specify bounding box of cell particles (MinPositions, MaxPositions), pad the mask to gurantee that all particles in requested spatial region(s) are selected. If the bounding box metadata is present, this argument is ignored. The default (0.1) is to pad by 0.1 times the cell length. Padding can be disabled (False) or set to a different fraction of the cell length (e.g. 0.5). Only entire cells are loaded, but if the region boundary is more than safe_padding from a cell boundary the neighbouring cell is not read. Switching off can reduce I/O load by up to a factor of 30 in some cases (but a few particles in region could be missing). See https://swiftsimio.readthedocs.io/en/latest/masking/index.html for further details.

  • handle (h5py.File, optional) – The file handle to read metadata from.

  • spatial_only (bool, optional) – Deprecated, any necessary conversions handled automatically.

filename: Path
constrained: str | None
property group_mapping: dict[str, str]

Create mapping between “group names” and their underlying cell metadata names.

Allows for aliases to be used instead of re-creating masks.

Returns:

The dictionary of corresponding names.

Return type:

dict[str, str]

property group_size_mapping: dict[str, str]

Create mapping between “group names” and their underlying cell metadata names.

Allows for aliases to be used instead of re-creating masks.

Returns:

The dictionary of corresponding names.

Return type:

dict[str, str]

property update_list: list[str]

Get list of internal mask variables that need updating when changing spatial mask.

Returns:

List of the variable names that need updating.

Return type:

list[str]

constrain_mask(group_name: str, quantity: str, lower: cosmo_quantity, upper: cosmo_quantity) None[source]

Use constrain_property() instead.

This name is deprecated and will be removed in the future.

Parameters:
  • group_name (str) – Particle type (e.g. "gas").

  • quantity (str) – Quantity being constrained (e.g. "temperatures").

  • lower (cosmo_quantity) – Constraint lower bound.

  • upper (cosmo_quantity) – Constraint upper bound.

constrain_property(*args: tuple, **kwargs: dict) None[source]
constrain_spatial(*args: tuple, **kwargs: dict) None[source]
convert_masks_to_ranges() None[source]

Convert the masks to range masks.

These are more compact than boolean masks so they can help save space on highly constrained machines.

convert_masks_to_bool() None[source]

Convert the masks to boolean masks.

These are sometimes easier to work with than range masks but usually use more memory.

constrain_index(*args: tuple, **kwargs: dict) None[source]
constrain_indices(*args: tuple, **kwargs: dict) None[source]