SWIFTSIM / swiftsimio

Python library for reading SWIFT data. Uses unyt and h5py.
GNU Lesser General Public License v3.0
18 stars 13 forks source link

More useful `__repr__` for interactive use #202

Open kyleaoman opened 2 months ago

kyleaoman commented 2 months ago

Currently printing a swift dataset gives something like this:

>>> sd = SWIFTDataset(snapfile)
>>> sd
SWIFT dataset at /cosma8/data/dp004/colibre/Runs/L0012N0376/Fiducial_test/SOAP/colibre_with_SOAP_membership_0123.hdf5.

And similarly for a particle dataset:

>>> sd.gas
<swiftsimio.reader.GasDataset object at 0x7f2c0d79b980>

It would be nice if instead these printed the available fields, like:

>>> sd
SWIFT dataset at <location>
Available fields:
gas    dark_matter    stars    black_holes

and

>>> sd.gas
GasDataset, available fields:
masses                coordinates          velocities
element_abundances    smoothing_lengths    temperatures
densities             <and so on>

Should check that it works similarly for SOAP catalogues.

I noticed recently that tab completion seems to work on recent pythons (3.12 on cosma, for instance). Could also look at that at the same time to see if it's already useful as-is or could be improved.