Commit 3c9ca876 authored by Domanski, Marian M.'s avatar Domanski, Marian M.

Merge branch '37-add-split-method-to-full-results' into 'master'

Resolve "Add split method to full results"

Closes #37

See merge request mdomanski/fluegg!31
parents ce3523a2 72bde13f
......@@ -275,6 +275,49 @@ class FullResults(Results):
return positions
def in_domain(self, time):
"""Returns a results instance containing particles that are
in the simulation domain at a given time
Parameters
----------
time : float
Simulation time, in seconds. `time` must be finite.
Returns
-------
Full Results or None
Returns None if no particles are in the domain at `time`
"""
if not np.isfinite(time):
raise ValueError("time must be a finite value")
positions_at_time = np.apply_along_axis(
lambda p: np.interp(
time,
self._time,
p),
0,
self._positions)
particles_in_domain = positions_at_time[:, 0] <= self._domain_length
if np.any(particles_in_domain):
cls = self.__class__
res = cls.__new__(cls)
res._positions = self._positions[:, particles_in_domain, :]
res._depth = self._depth[:, particles_in_domain]
res._width = self._width[:, particles_in_domain]
res._domain_length = self._domain_length
res._configuration = self.configuration()
res._time = self._time.copy()
else:
res = None
return res
def positions(self, normalize=()):
"""Returns particle position array
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment