yt.frontends.ramses.particle_handlers module

class yt.frontends.ramses.particle_handlers.DefaultParticleFileHandler(domain)[source]

Bases: ParticleFileHandler

classmethod any_exist(ds)

This function should return True if the kind of particle represented by the class exists in the dataset. It takes as argument the class itself -not an instance- and a dataset.

Parameters:

ds (a Ramses Dataset)

Note

This function is usually called once at the initialization of the RAMSES Dataset structure to determine if the particle type (e.g. regular particles) exists.

attrs: tuple[tuple[str, int, str], ...] = (('ncpu', 1, 'i'), ('ndim', 1, 'i'), ('npart', 1, 'i'), ('localseed', -1, 'i'), ('nstar_tot', 1, 'i'), ('mstar_tot', 1, 'd'), ('mstar_lost', 1, 'd'), ('nsink', 1, 'i'))
property birth_file_fname
config_field: str | None = 'ramses-particles'
property exists

This function should return True if the file the instance exists. It is called for each file of the type found on the disk.

By default, it just returns whether the file exists. Override it for more complex cases.

property field_offsets: dict[tuple[str, str], int]
property field_types: dict[tuple[str, str], str]
file_descriptor: str | None = 'part_file_descriptor.txt'
fname: str = 'part_{iout:05d}.out{icpu:05d}'
handle_field(field: tuple[str, str], data_dict: dict[tuple[str, str], ndarray])[source]

This function allows custom code to be called to handle special cases, such as the particle birth time.

It updates the data_dict dictionary with the new data.

Parameters:
  • field (tuple[str, str]) – The field name.

  • data_dict (dict[tuple[str, str], np.ndarray]) – A dictionary containing the data.

  • default (By)

  • nothing. (this function does)

property has_birth_file
property has_descriptor

This function should return True if a file descriptor exists.

By default, it just returns whether the file exists. Override it for more complex cases.

property header: dict[str, Any]
known_fields: list[FieldKey] = [('particle_position_x', 'd'), ('particle_position_y', 'd'), ('particle_position_z', 'd'), ('particle_velocity_x', 'd'), ('particle_velocity_y', 'd'), ('particle_velocity_z', 'd'), ('particle_mass', 'd'), ('particle_identity', 'i'), ('particle_refinement_level', 'i')]
property local_particle_count: int
ptype: str = 'io'
read_header()[source]

This function is called once per file. It should:

  • read the header of the file and store any relevant information

  • detect the fields in the file

  • compute the offsets (location in the file) of each field

It is in charge of setting self.field_offsets and self.field_types.

  • _field_offsets: dictionary: tuple -> integer

    A dictionary that maps (type, field_name) to their location in the file (integer)

  • _field_types: dictionary: tuple -> character

    A dictionary that maps (type, field_name) to their type (character), following Python’s struct convention.

reader(subset, fields, count)

General file handler for binary file, called by _read_particle_subset

Parameters:
  • particle (ParticleFileHandler) – the particle class we want to read

  • subset (RAMSESDomainSubset) – A RAMSES domain subset object

  • fields (list of tuple) – The fields to read

  • count (integer) – The number of elements to count

setup_handler(domain)

Initialize an instance of the class. This automatically sets the full path to the file. This is not intended to be overridden in most cases.

If you need more flexibility, rewrite this function to your need in the inherited class.

class yt.frontends.ramses.particle_handlers.ParticleFileHandler(domain)[source]

Bases: ABC, HandlerMixin

Abstract class to handle particles in RAMSES. Each instance represents a single file (one domain).

To add support to a new particle file, inherit from this class and implement all functions containing a NotImplementedError.

See SinkParticleFileHandler for an example implementation.

classmethod any_exist(ds)

This function should return True if the kind of particle represented by the class exists in the dataset. It takes as argument the class itself -not an instance- and a dataset.

Parameters:

ds (a Ramses Dataset)

Note

This function is usually called once at the initialization of the RAMSES Dataset structure to determine if the particle type (e.g. regular particles) exists.

attrs: tuple[tuple[str, int, str], ...]
config_field: str | None = None
property exists

This function should return True if the file the instance exists. It is called for each file of the type found on the disk.

By default, it just returns whether the file exists. Override it for more complex cases.

property field_offsets: dict[tuple[str, str], int]
property field_types: dict[tuple[str, str], str]
file_descriptor: str | None = None
fname: str
handle_field(field: tuple[str, str], data_dict: dict[tuple[str, str], ndarray])[source]

This function allows custom code to be called to handle special cases, such as the particle birth time.

It updates the data_dict dictionary with the new data.

Parameters:
  • field (tuple[str, str]) – The field name.

  • data_dict (dict[tuple[str, str], np.ndarray]) – A dictionary containing the data.

  • default (By)

  • nothing. (this function does)

property has_descriptor

This function should return True if a file descriptor exists.

By default, it just returns whether the file exists. Override it for more complex cases.

property header: dict[str, Any]
known_fields: list[tuple[str, str]]
property local_particle_count: int
ptype: str
abstract read_header()[source]

This function is called once per file. It should:

  • read the header of the file and store any relevant information

  • detect the fields in the file

  • compute the offsets (location in the file) of each field

It is in charge of setting self.field_offsets and self.field_types.

  • _field_offsets: dictionary: tuple -> integer

    A dictionary that maps (type, field_name) to their location in the file (integer)

  • _field_types: dictionary: tuple -> character

    A dictionary that maps (type, field_name) to their type (character), following Python’s struct convention.

reader: Callable[[ParticleFileHandler, RAMSESDomainSubset, list[tuple[str, str]], int], dict[tuple[str, str], ndarray]]
setup_handler(domain)

Initialize an instance of the class. This automatically sets the full path to the file. This is not intended to be overridden in most cases.

If you need more flexibility, rewrite this function to your need in the inherited class.

class yt.frontends.ramses.particle_handlers.SinkParticleFileHandler(domain)[source]

Bases: ParticleFileHandler

Handle sink files

classmethod any_exist(ds)

This function should return True if the kind of particle represented by the class exists in the dataset. It takes as argument the class itself -not an instance- and a dataset.

Parameters:

ds (a Ramses Dataset)

Note

This function is usually called once at the initialization of the RAMSES Dataset structure to determine if the particle type (e.g. regular particles) exists.

attrs: tuple[tuple[str, int, str], ...] = (('nsink', 1, 'i'), ('nindsink', 1, 'i'))
config_field: str | None = 'ramses-sink-particles'
property exists

This function should return True if the file the instance exists. It is called for each file of the type found on the disk.

By default, it just returns whether the file exists. Override it for more complex cases.

property field_offsets: dict[tuple[str, str], int]
property field_types: dict[tuple[str, str], str]
file_descriptor: str | None = 'sink_file_descriptor.txt'
fname: str = 'sink_{iout:05d}.out{icpu:05d}'
handle_field(field: tuple[str, str], data_dict: dict[tuple[str, str], ndarray])

This function allows custom code to be called to handle special cases, such as the particle birth time.

It updates the data_dict dictionary with the new data.

Parameters:
  • field (tuple[str, str]) – The field name.

  • data_dict (dict[tuple[str, str], np.ndarray]) – A dictionary containing the data.

  • default (By)

  • nothing. (this function does)

property has_descriptor

This function should return True if a file descriptor exists.

By default, it just returns whether the file exists. Override it for more complex cases.

property header: dict[str, Any]
known_fields: list[FieldKey] = [('particle_identifier', 'i'), ('particle_mass', 'd'), ('particle_position_x', 'd'), ('particle_position_y', 'd'), ('particle_position_z', 'd'), ('particle_velocity_x', 'd'), ('particle_velocity_y', 'd'), ('particle_velocity_z', 'd'), ('particle_birth_time', 'd'), ('BH_real_accretion', 'd'), ('BH_bondi_accretion', 'd'), ('BH_eddington_accretion', 'd'), ('BH_esave', 'd'), ('gas_spin_x', 'd'), ('gas_spin_y', 'd'), ('gas_spin_z', 'd'), ('BH_spin_x', 'd'), ('BH_spin_y', 'd'), ('BH_spin_z', 'd'), ('BH_spin', 'd'), ('BH_efficiency', 'd')]
property local_particle_count: int
ptype: str = 'sink'
read_header()[source]

This function is called once per file. It should:

  • read the header of the file and store any relevant information

  • detect the fields in the file

  • compute the offsets (location in the file) of each field

It is in charge of setting self.field_offsets and self.field_types.

  • _field_offsets: dictionary: tuple -> integer

    A dictionary that maps (type, field_name) to their location in the file (integer)

  • _field_types: dictionary: tuple -> character

    A dictionary that maps (type, field_name) to their type (character), following Python’s struct convention.

reader(subset, fields, count)

General file handler for binary file, called by _read_particle_subset

Parameters:
  • particle (ParticleFileHandler) – the particle class we want to read

  • subset (RAMSESDomainSubset) – A RAMSES domain subset object

  • fields (list of tuple) – The fields to read

  • count (integer) – The number of elements to count

setup_handler(domain)

Initialize an instance of the class. This automatically sets the full path to the file. This is not intended to be overridden in most cases.

If you need more flexibility, rewrite this function to your need in the inherited class.

class yt.frontends.ramses.particle_handlers.SinkParticleFileHandlerCsv(domain)[source]

Bases: ParticleFileHandler

Handle sink files from a csv file, the format from the sink particle in ramses

classmethod any_exist(ds)

This function should return True if the kind of particle represented by the class exists in the dataset. It takes as argument the class itself -not an instance- and a dataset.

Parameters:

ds (a Ramses Dataset)

Note

This function is usually called once at the initialization of the RAMSES Dataset structure to determine if the particle type (e.g. regular particles) exists.

attrs: tuple[tuple[str, int, str], ...] = (('nsink', 1, 'i'), ('nindsink', 1, 'i'))
config_field: str | None = 'ramses-sink-particles'
property exists

This function should return True if the file the instance exists. It is called for each file of the type found on the disk.

By default, it just returns whether the file exists. Override it for more complex cases.

property field_offsets: dict[tuple[str, str], int]
property field_types: dict[tuple[str, str], str]
file_descriptor: str | None = None
fname: str = 'sink_{iout:05d}.csv'
handle_field(field: tuple[str, str], data_dict: dict[tuple[str, str], ndarray])[source]

This function allows custom code to be called to handle special cases, such as the particle birth time.

It updates the data_dict dictionary with the new data.

Parameters:
  • field (tuple[str, str]) – The field name.

  • data_dict (dict[tuple[str, str], np.ndarray]) – A dictionary containing the data.

  • default (By)

  • nothing. (this function does)

property has_descriptor

This function should return True if a file descriptor exists.

By default, it just returns whether the file exists. Override it for more complex cases.

property header: dict[str, Any]
known_fields: list[FieldKey]
property local_particle_count: int
ptype: str = 'sink_csv'
read_header()[source]

This function is called once per file. It should:

  • read the header of the file and store any relevant information

  • detect the fields in the file

  • compute the offsets (location in the file) of each field

It is in charge of setting self.field_offsets and self.field_types.

  • _field_offsets: dictionary: tuple -> integer

    A dictionary that maps (type, field_name) to their location in the file (integer)

  • _field_types: dictionary: tuple -> character

    A dictionary that maps (type, field_name) to their type (character), following Python’s struct convention.

reader(subset, fields, count)

General file handler for csv file, called by _read_particle_subset

Parameters:
  • particle (ParticleFileHandler) – the particle class we want to read

  • subset (RAMSESDomainSubset) – A RAMSES domain subset object

  • fields (list of tuple) – The fields to read

  • count (integer) – The number of elements to count

setup_handler(domain)

Initialize an instance of the class. This automatically sets the full path to the file. This is not intended to be overridden in most cases.

If you need more flexibility, rewrite this function to your need in the inherited class.

yt.frontends.ramses.particle_handlers.get_particle_handlers()[source]
yt.frontends.ramses.particle_handlers.register_particle_handler(ph)[source]