synthesizer.utils.ascii_table¶
A module for formatting objects into ASCII tables.
Contains the TableFormatter class for formatting objects into ASCII tables.
- Example usage:
- class Example:
- def __init__(self):
self.coordinates = np.random.rand(10, 3) self.velocities = np.random.rand(10, 3) self.masses = np.random.rand(10) self.redshift = 0.5 self.softening_length = 0.1 self.nparticles = 10 self.centre = np.array([0.5, 0.5, 0.5])
# Example usage example = Example() formatter = TableFormatter(example) print(formatter.get_table())
Classes
- class synthesizer.utils.ascii_table.TableFormatter(obj)[source]¶
A class to format an arbitrary object’s attributes into a table.
- obj¶
The object whose attributes are to be formatted into a table.
- Type:
object
- attributes¶
A dictionary of the object’s attributes.
- Type:
dict
- format_array(array)[source]¶
Format numpy arrays to show their mean value.
- Parameters:
array (numpy.ndarray) – The array to be formatted.
- Returns:
The formatted string showing the mean value of the array.
- Return type:
str
- format_dict(dictionary)[source]¶
Format dictionaries to show their keys and the types of their values.
- Parameters:
dictionary (dict) – The dictionary to be formatted.
- Returns:
A list of tuples where each tuple contains the dictionary key and the type of its value.
- Return type:
list of tuple
- format_list(lst)[source]¶
Format lists content to spead out the values over multiple lines.
- Parameters:
lst (list) – The list to be formatted.
- Returns:
The formatted string containing the list content.
- Return type:
str
- get_array_rows()[source]¶
Collect the object’s attributes and formats them into rows.
- Returns:
A list of tuples where each tuple contains the attribute name and its formatted value.
- Return type:
list of tuple
- get_dict_rows()[source]¶
Collect the object’s attributes and formats them into rows.
- Returns:
A list of tuples where each tuple contains the attribute name and its formatted value.
- Return type:
list of tuple
- get_list_rows()[source]¶
Collect the object’s attributes and formats them into rows.
- Returns:
A list of tuples where each tuple contains the attribute name and its formatted value.
- Return type:
list of tuple