gizio.core module

Core interface.

gizio.core.load(prefix, suffix='.hdf5', spec='gizmo')[source]

Load snapshot.

Parameters
  • prefix (str or pathlib.Path) – Snapshot file(s) prefix.

  • suffix (str, optional) – Snapshot file(s) suffix. (default: “.hdf5”)

  • spec (str or SpecBase, optional) – Snapshot format specification. If given as str, will use a built-in one. (default: “gizmo”)

Returns

The loaded snapshot.

Return type

Snapshot

class gizio.core.Snapshot(paths, spec)[source]

Bases: object

Simulation snapshot.

snap[key]
snap[ptype, field]

Load the field from file and cache in memory.

del snap[key]
del snap[ptype, field]

Delete the cache.

Parameters
  • paths (typing.Iterable) – Snapshot file paths in correct order.

  • spec (SpecBase) – Snapshot format specification.

paths

Snapshot file paths.

Type

list

prefix

Common prefix of paths without trailing dot.

Type

str

spec

Snapshot format specification.

Type

SpecBase

header

Snapshot header.

Type

dict

shape

Data shape composed of {ptype_name: n_part} entries, in the specification ptypes order.

Type

collections.OrderedDict

cosmology

An astropy cosmology calculator.

Type

astropy.cosmology.LambdaCDM

unit_registry

Simulation unit registry.

Type

unyt.unit_registry.UnitRegistry

pt

Dictionary of particle type selectors.

Type

dict

keys()[source]

A list of available keys.

cached_keys()[source]

A list of cached keys.

clear_cache()[source]

Clear field cache.

array(value, unit)[source]

Helper method to create unyt array with snapshot unit registry.

Parameters
Returns

A unyt array.

Return type

unyt.array.unyt_array

quantity(value, unit)[source]

Helper method to create unyt quantity with snapshot unit registry.

Parameters
  • value (float) – The value.

  • unit (str) – The unit.

Returns

A unyt quantity.

Return type

unyt.array.unyt_quantity

class gizio.core.ParticleSelector(snap, masks)[source]

Bases: object

High level snapshot field access for selected particles.

len(ps)

Return the number of selected particles.

ps[key]

Retrieve the field. Compute and create cache if not existing already.

del ps[key]

Delete the cache.

Parameters

snap (Snapshot) – The snapshot to access.

snap

The snapshot to access.

Type

Snapshot

pmask

Particle mask.

Type

collections.OrderedDict

shape

Shape.

Type

collections.OrderedDict

classmethod from_ptypes(snap, ptypes)[source]

Create particle selector for specified particle types.

Parameters
  • snap (Snapshot) – The snapshot to access.

  • ptypes (list) – A list of particle types to select.

Returns

The corresponding particle selector.

Return type

ParticleSelector

keys()[source]

All registered fields.

Returns

A view on keys.

Return type

dict_keys

direct_fields()[source]

Known direct fields.

Returns

A dictionary mapping shorhand keys to raw field names.

Return type

dict

register_field(key, func)[source]

Register a field.

Parameters
  • key (str) – The key to retrieve the field.

  • func (typing.Callable) – The function to compute the field.

register_direct_field(key, field)[source]

Register a direct field.

Parameters
  • key (str) – The key to retrieve the field.

  • field (str) – The raw field name.

unregister_field(key)[source]

Unregister a field.

Parameters

key (str) – The key of the field.

clear_cache()[source]

Clear all field caches.

normalize_mask()[source]

Normalize mask arrays.