paicos.writers package

Submodules

paicos.writers.arepo_image module

This defines a class for saving images as hdf5 files in a systematic way.

class paicos.writers.arepo_image.ArepoImage(image_creator, basedir, basename='projection', mode='w')

Bases: PaicosWriter

A derived data format for Arepo snapshots.

A common task is to reduce Arepo snapshots to 2D arrays (either slices or projections) which can plotted as images. The computation of the 2D arrays can be time-consuming for high-resolution simulations with large snapshots. The purpose of this class is to define a derived data format which can be used to store images for later plotting with matplotlib.

__init__(image_creator, basedir, basename='projection', mode='w')

Initialize an HDF5 file for storing an image.

This class is intended to be used with images created using a Paicos Projector or Slicer object, which can be passed as the image_creator input argument.

The image data, including ‘center’, ‘widths’, ‘extent’, and ‘direction’, will be extracted from the image_creator object and stored in the HDF5 file. The HDF5 file is created in the basedir folder, with the name basename_{:03d}.

The mode argument controls whether the file is opened in write mode (‘w’) or amend mode (‘a’). If mode is ‘w’, the file will be created at self.tmp_filename and the image information will be written to the file. Setting the mode to amend mode, ‘a’, allows to add new images to an already existing file.

Parameters:
  • image_creator (object) – A Paicos Projector or Slicer object used to create the image.

  • (file (basedir) – The folder where the image file should be saved.

  • basename (string) – The base name for the image file, which will be in the format basename_{:03d}. (default: “projection”).

  • mode (string) – The mode to open the file in, either ‘w’ for write mode or ‘a’ for append mode. (default: ‘w’).

finalize :

Changes the filename from a temporary one to the final one, e.g., from self.tmp_filename to self.filename.

save_image(name, data)

This method saves a 2D image to the hdf5 file.

paicos.writers.arepo_image.ImageWriter

alias of ArepoImage

paicos.writers.paicos_writer module

Defines hdf5 file writers that can be read with a PaicosReader instance.

class paicos.writers.paicos_writer.PaicosTimeSeriesWriter(reader_object, basedir, basename='paicos_time_series', add_snapnum=False, mode='w')

Bases: PaicosWriter

Similar to the standard PaicosWriter but here we ensure that the snapnum is not part of the resulting filename for the hdf5 file.

class paicos.writers.paicos_writer.PaicosWriter(reader_object, basedir, basename='paicos_file', add_snapnum=True, mode='w')

Bases: object

This class can be used for writing data to self-documenting hdf5 files.

It is the base class for the ArepoImage writer.

__init__(reader_object, basedir, basename='paicos_file', add_snapnum=True, mode='w')

The constructor for the PaicosWriter class.

Parameters:
  • reader_object (obj) – A PaicosReader object (or Snaphot or Catalog object).

  • basedir (file path) – The folder where the HDF5 file will be saved.

  • basename (str, optional) – Base name of the HDF5 file. Defaults to “paicos_file”.

  • add_snapnum (bool) –

    Whether to add the snapnum to the HDF5 filename.

    When True, the filename will be “basename_{:03d}.hdf5”, when False it will simply be “basename.hdf5” Defaults to True.

  • mode (string) – The mode to open the file in, either ‘w’ for write mode or ‘a’ for append mode. (default: ‘w’).

finalize()

Move from a temporary filename to the final filename.

write_data(name, data, data_attrs={}, group=None, group_attrs={})

Write a data set to the hdf5 file.

Parameters:
  • name (str) – Name of the data to be written.

  • data (obj) – The data to be written (e.g. PaicosQuantity, PaicosTimeSeries, Astropy Quantity, numpy array).

  • data_attrs (dict) –

    Dictionary of attributes for the data. E.g.:

    {'info': 'Here I have written some extra information about the data set'}
    

    Defaults to an empty dictionary.

  • group (str, optional) – Group in the HDF5 file where the data should be saved. Defaults to None in which case the data set is saved at the top level of the hdf5 file).

  • group_attrs (dict, optional) – Dictionary of attributes for the group. Defaults to an empty dictionary.

Module contents