|
|
Logger reader
|
|
|
=============
|
|
|
|
|
|
Here we will describe quickly the API that we wish to provide for the logger.
|
|
|
Before thinking about the reader implementation, lets start by imagining the kind of API we would like to provide to users.
|
|
|
|
|
|
```python
|
|
|
|
|
|
with logger.Reader(basename, use_cache=False) as f:
|
|
|
# Activate the cache
|
|
|
f.use_cache = True
|
|
|
with logger.Reader(basename) as f:
|
|
|
|
|
|
# At the end of each function, we store in f an array of (k?) offset / time in order
|
|
|
# to quickly access the records next time.
|
|
|
# Create a logger.ParticleSet of the particles we want to track.
|
|
|
particle_set = f.get_particles(type="Gas")
|
|
|
particle_set -= f.get_particles(ids=[...])
|
|
|
|
|
|
# Read some fields for some particles.
|
|
|
positions, velocities = f.get_particle_data(
|
|
|
fields=["Coordinates", "Velocities"], time=time, ids=particle_ids)
|
|
|
|
|
|
# Same as before, but we use all the ids from the index file.
|
|
|
positions, velocities = logger.get_particle_data(
|
|
|
fields=["Coordinates", "Velocities"], time=time, ids=None)
|
|
|
|
|
|
# Same as before, but we read all the fields.
|
|
|
# here we should be fast thanks to the cache.
|
|
|
parts = logger.load_snapshot_at_time(time)
|
|
|
|
|
|
# Easy solution
|
|
|
print(parts["Coordinates"])
|
|
|
# Josh's solution
|
|
|
print(parts.gas.coordinates)
|
|
|
particles=particle_set,
|
|
|
fields=["Coordinates", "Velocities"],
|
|
|
time=time,
|
|
|
interpolation="linear")
|
|
|
|
|
|
# Move a set of particles forward in time.
|
|
|
# here we should be fast thanks to the cache.
|
|
|
positions = f.get_particle_data(fields=["Coordinates"],
|
|
|
time=time + 1, ids=None)
|
|
|
positions = f.get_particle_data(
|
|
|
particles=particle_set,
|
|
|
fields=["Coordinates"],
|
|
|
time=time + 1)
|
|
|
|
|
|
# here we close the logfile and cleanup everything
|
|
|
``` |
|
|
\ No newline at end of file |