XYZFile1

class cometsuite.xyzfile.XYZFile1(filename, mode, *args, **keywords)

Bases: XYZFileBase

Open a CometSuite data file for I/O.

inf = XYZFile1(filename, ‘w’, sim) inf = XYZFile1(filename, ‘r’)

Parameters:
filenamestring

The file name.

modestring

‘r’ for read mode, ‘w’ for write mode.

simSimulation

Initialize XYZFile1 with this simulation’s parameter set.

verbosebool, optional

When False, feedback to the user will generally be supressed.

Methods Summary

read_simulation([n])

Read particles from the file.

write_particles(particles)

Write a particle or list of particles to the file.

Methods Documentation

read_simulation(n=None)

Read particles from the file.

Parameters:
nint or long, optional

Read n particles. If n is None, read as many particles as are expected, based on the data header.

Returns:
pnumpy record array

The array of particle data.

write_particles(particles)

Write a particle or list of particles to the file.

Parameters:
particlesdictionary-like

A dictionary-like (e.g., dict or numpy record array) set of parameters for each particle.

Examples

>>> import numpy as np
>>> import cometsuite as cs
>>>
>>> p = dict(radius=np.random.rand(10), age=np.random.rand(10) * 100)
>>> sim = cs.Simulation()
>>> sim.params.update(comet='encke', kernel='encke.bsp', date=2450000.5,
...                   nparticles=len(p['radius']), save=['radius', 'age'])
>>> outf = cs.XYZFile1('test.xyz', 'w', sim)
>>> outf.write_particles(p)
>>> outf.close()