pynbody.snapshot.namemapper.AdaptiveNameMapper

pynbody.snapshot.namemapper.AdaptiveNameMapper#

class pynbody.snapshot.namemapper.AdaptiveNameMapper(config_name, gadget_blocks=False, return_all_format_names=False)[source]#

Bases: object

A class to map between the names of arrays in different simulation codes.

This class is designed to be used in a context where the names of arrays in a simulation code (a ‘format name’) may not be fully known in advance. For example, we might be unsure whether pynbody’s pos array corresponds to the format name Coordinates or Position in a given simulation snapshot. This class allows us possible different mappings to be given in the configuration, and then once one of the mappings is used, it is locked in for the duration of the object’s lifetime.

One may wish to set return_all_format_names to True to just get all possible format names for a given pynbody name.

Methods

__call__(name[, reverse])

Map a pynbody name to a format name.

__init__(config_name, gadget_blocks=False, return_all_format_names=False)[source]#

Create a new AdaptiveNameMapper object.

Parameters:
  • config_name (str) – The name of the section in the configuration file to use for the mapping.

  • gadget_blocks (bool) – If True, the mapping is case-insensitive and pads the names to 4 characters, as is the convention for GADGET block names.

  • return_all_format_names (bool) – If True, return all the possible format-specific names for a pynbody name, rather than only the most recently accessed (which is the default behaviour).

Notes

Generally, return_all_format_names = False is the obvious choice, where we don’t know in advance the name of the array in the simulation snapshot, but we know there will be only one such name. However, swift uses a different name for the masses of its black holes (SubgridMasses) than for the masses of its other particles (Masses), so in this case we need to set allow_ambiguous = True. There may be other cases where this is necessary.