Miscellaneous¶
Datatype enum¶
-
class
astrophysix.simdm.utils.
DataType
(value)¶ Value data type enum
Example
>>> dt = DataType.INTEGER >>> dt.name "Integer number"
-
BOOLEAN
= ('bool', 'Boolean')¶
-
COMPLEX
= ('comp', 'Complex number')¶
-
DATETIME
= ('time', 'Datetime')¶
-
INTEGER
= ('int', 'Integer number')¶
-
RATIONAL
= ('rat', 'Rational number')¶
-
REAL
= ('real', 'Real number')¶
-
STRING
= ('str', 'String')¶
-
classmethod
from_key
(k)¶ - Parameters
key (
string
) – data type key- Returns
t – Physics matching the requested key.
- Return type
- Raises
ValueError – if requested key does not match any physics.
Example
>>> dt = DataType.from_key("rat") >>> dt.name "Rational number" >>> dt2 = DataType.from_key("MY_UNKNOWN_DTYPE") ValuerError: No DataType defined with the key 'MY_UNKNOWN_DTYPE'.
-
property
key
¶ Data type index key
-
Object lists¶
-
class
astrophysix.simdm.utils.
ObjectList
(obj_class, index_prop_name, validity_check=None)¶ Generic object list container class
- Parameters
obj_class (
type
) – base class of the objects that can be added to the listindex_prop_name (
string
) – object property name used as a list indexvalidity_check (
callable
) – method called upon object addition into the list. Default None.
Examples
>>> run1 = Simulation(simu_code=arepo, name="Pure-hydro run (isolated galaxy)") >>> run2 = Simulation(simu_code=arepo, name="MHD run") >>> run3 = project.simulation.add(Simulation(simu_code=arepo, name="Hydro run with BH feedback") >>> run4 = Simulation(simu_code=arepo, name="MHD run with BH feedback") >>> project.simulation.add(run1) >>> project.simulation.add(run2) >>> project.simulation.add(run3) >>> project.simulation.add(run4, insert_pos=2) # Insert at position 2, not appendend at the end of the list >>> len(project.simulations) 4 >>> print(str(project.simulations)) Simulation list : +---+-----------------------------------+-----------------------------------------------+ | # | Index | Item | +---+-----------------------------------+-----------------------------------------------+ | 0 | Pure-hydro run (isolated galaxy) | 'Pure-hydro run (isolated galaxy)' simulation | +---+-----------------------------------+-----------------------------------------------+ | 1 | MHD run | 'MHD run' simulation | +---+-----------------------------------+-----------------------------------------------+ | 2 | MHD run with BH feedback | 'MHD run with BH feedback' simulation | +---+-----------------------------------+-----------------------------------------------+ | 3 | Hydro run with BH feedback | 'Hydro run with BH feedback' simulation | +---+-----------------------------------+-----------------------------------------------+ >>> run3 is project.simulations[3] # Search by item position True >>> project.simulations["MHD run"] # Search by item index value 'MHD run' simulation >>> del project.simulations[0] >>> del project.simulations["MHD run"] >>> del project.simulations[run4] >>> print(str(project.simulations)) Simulation list : +---+-----------------------------------+-----------------------------------------------+ | # | Index | Item | +---+-----------------------------------+-----------------------------------------------+ | 0 | Hydro run with BH feedback | 'Hydro run with BH feedback' simulation | +---+-----------------------------------+-----------------------------------------------+
-
__delitem__
(item)¶ Delete an object from the list.
- Parameters
item (
object
orint
orstring
) – instance to delete, object position in the list (int
) or index property value (string
) of the object to remove from the list.
-
__eq__
(other)¶ Object list comparison method
- Parameters
other (
ObjectList
) – other object list to compare to
-
__getitem__
(index)¶ Get an object from the list.
- Parameters
item (
int
orstring
) – object position in the list (int
) or index property value (string
) of the object to fetch from the list.- Returns
o – Found object in the list. None if none were found.
- Return type
object
of type self.object_class- Raises
AttributeError – if the search index type is neither an
int
nor astring
.IndexError – if the
int
search index value is lower than 0 or larger than the length of the list - 1.
-
__iter__
()¶ Basic object list iterator
-
__len__
()¶ Size of the object list
-
__unicode__
()¶ String representation of the instance
-
add
(obj, insert_pos=- 1)¶ Adds a instance to the list at a given position
- Parameters
obj (
object
) – instance to insert in the listinsert_pos (
int
) – insertion position in the simulation list. Default -1 (last).
-
find_by_uid
(uid)¶ Find an object in the list with a matching UUID
- Parameters
uid (
UUID
orstring
) – UUID or UUID string representation of the object to search for.- Returns
o
- Return type
Matching object with corresponding UUID,if any. Otherwise returns None
-
galactica_validity_check
(**kwargs)¶ Perform validity checks on this instance and eventually log warning messages.
- Parameters
kwargs (
dict
) – keyword arguments (optional)
-
property
index_attribute_name
¶ Name of the object property used as an index in this object list
-
property
object_class
¶ Type of object that can be added into the list