pressomancy.analysis package

Submodules

pressomancy.analysis.data_analysis module

class pressomancy.analysis.data_analysis.H5DataSelector(h5_file, particle_group, ts_slice=None, pt_slice=None)[source]

Bases: object

A simplified interface to access simulation data stored in an HDF5 file. The H5DataSelector maintains internal slice information for timesteps (axis 0) and particles (axis 1) and supports chaining via its accessor properties:

  • .timestep: Provides an interface for slicing/iterating over timesteps.

  • .particles: Provides an interface for slicing/iterating over particles.

Usage Examples:

# Slice timesteps 10 to 20 (inclusive of the start, exclusive of the stop) time_subset = data.timestep[10:20]

# Slice particles 0 to 100 particle_subset = data.particles[:100]

# Chain slicing: sub = data.timestep[:5].particles[0:10]

# Retrieve property data (e.g., positions): pos = data.pos # This calls get_property(“pos”)

# Connectivity-based particle selection: filament_particles = data.select_particles_by_object(“Filament”, connectivity_value=0) monomer_subset = filament_particles.particles[10:20].timestep[5]

Notes:
  • Direct indexing on a top-level H5DataSelector is disallowed to ensure explicit axis selection. Use the accessor properties (.timestep or .particles) for slicing.

  • Iteration and len() are only defined on the accessor objects.

Raises:
  • ValueError if the dimensions of the stored property datasets are inconsistent.

get_child_ids(parent_key, child_key, parent_id)[source]

Retrieve a sorted list of child object IDs connected to a given parent_id.

This method first attempts to obtain the connectivity map relating the parent and child objects. If the connectivity map is not found (i.e., None), a warning is issued and None is returned. Otherwise, it filters the connectivity entries to select rows with the matching parent_id, extracts the corresponding child IDs, converts them to integers, sorts them, and returns the resulting list.

Parameters:
  • parent_key (str) – Name of the parent object type.

  • child_key (str) – Name of the child object type.

  • parent_id (int) – The identifier for the parent object.

Returns:

A sorted list of child object IDs connected to the given parent_id. Returns None if the connectivity map is missing.

Return type:

List[int] or None

get_connectivity_map(parent_key, child_key)[source]

Retrieve the connectivity map between parent and child objects from the HDF5 file.

This method constructs a dataset path based on the particle group and the specified parent and child keys, then attempts to retrieve an array of [parent_id, child_id] pairs from the HDF5 connectivity group. If the dataset is not found, a warning is issued and None is returned.

Parameters:
  • parent_key (str) – Name of the parent object type (e.g. “Filament”).

  • child_key (str) – Name of the child object type (e.g. “Quadriplex”).

Returns:

An array containing [parent_id, child_id] pairs if the connectivity map exists; otherwise, None.

Return type:

ndarray of shape (N, 2) or None

get_connectivity_values(object_name)[source]

Return the raw connectivity pairs for a given object, using the ParticleHandle_to_<object_name> dataset.

Parameters:

object_name (str) – Name of the connected object type (e.g. “Filament”).

Returns:

Array of [particle_id, object_index] pairs.

Return type:

ndarray of shape (N, 2)

get_parent_ids(parent_key, child_key, child_id)[source]

Return a sorted list of parent object IDs connected to a given child_id.

Parameters:
  • parent_key (str) – Name of the parent object type.

  • child_key (str) – Name of the child object type.

  • child_id (int) – The who_am_i identifier of the child object.

Returns:

Sorted list of parent who_am_i IDs that link to the child.

Return type:

List[int]

get_property(prop)[source]

Retrieve data for a given property from the HDF5 dataset applying the current slices.

Parameters:

prop (str) – The property name (e.g., ‘pos’, ‘f’).

Returns:

The dataset with the applied timestep and particle slices.

Return type:

ndarray

property particles

Accessor for slicing/iterating over the particle axis.

Returns:

An accessor object for particle operations.

Return type:

ParticleAccessor

Usage:

# Slicing particles 0 to 100: data.particles[0:100]

# Iterating over each particle in a slice: for p in data.particles[20:30]:

process(p)

sanity_check(metadata, particle_group)[source]

Ensures that all properties in a given particle group have consistent timestep and particle dimensions.

Parameters:
  • metadata (dict) – The hierarchical dictionary of the HDF5 structure.

  • particle_group (str) – The name of the particle group.

Returns:

(timesteps, particles) common to all valid ‘value’ datasets.

Return type:

tuple

Raises:

ValueError – If the particle group is not found or dimensions are inconsistent.

select_particles_by_object(object_name, connectivity_value=0)[source]

Select a subset of particles based on a connectivity dataset. The indices are sorted and stored as a list (for correct slicing behavior).

Parameters:
  • object_name (str) – Name of the connectivity object (e.g., “Filament”).

  • connectivity_value (int, optional) – The value to match in the connectivity map. Defaults to 0.

Returns:

A new selector with the particle slice set to the selected indices.

Return type:

H5DataSelector

property timestep

Accessor for slicing/iterating over the timestep axis.

Returns:

An accessor object for timestep operations.

Return type:

TimestepAccessor

Usage:

# Slicing timesteps 10 to 20: data.timestep[10:20]

# Iterating over each timestep in a slice: for t in data.timestep[5:10]:

process(t)

class pressomancy.analysis.data_analysis.ParticleAccessor(sim_data)[source]

Bases: object

An accessor for slicing and iterating over particles of a H5DataSelector.

It composes new particle indices with any existing slice and enables iteration where each iteration yields a H5DataSelector corresponding to a single particle index.

class pressomancy.analysis.data_analysis.TimestepAccessor(sim_data)[source]

Bases: object

An accessor for slicing and iterating over timesteps of a H5DataSelector.

It composes new timestep slices with any existing slice and enables iteration where each iteration yields a H5DataSelector corresponding to a single timestep.

Module contents