:py:mod:`gnome.array_types` =========================== .. py:module:: gnome.array_types .. autoapi-nested-parse:: Module contains array types that a mover may need based on the data movers needs ** NOTE: ** These are global declarations For instance: If the PointWindMover that uses array_types.PointWindMover updates the properties of 'windages' ArrayType, it will change it universally. The user/mover should not need to change dtype or shape internally. If these need to change, it should be done here. The initial_value can be changed by movers since that's only used when elements are released. For most arrays, that is currently 0. As a convention, when a dict defines these array_types, best to use the name of the array_type as the 'key'. When other modules, primarily element_type, look for numpy array in data_arrays with associated array_types, it will assume the 'key' is the name of the array_types. todo: For array_types like mass_components and other array_types used by weathering objects, the shape is set at runtime. Since this changes depending on each type of spill that is modeled, need to rethink this global definition for these array_types. Currently, these ArrayTypes are defined with 'shape'=None. Add optional shape argument to ArrayTypes().initialize() to handle the case where shape attribute is None Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: gnome.array_types.ArrayType gnome.array_types.IdArrayType gnome.array_types.ArrayTypeDivideOnSplit Functions ~~~~~~~~~ .. autoapisummary:: gnome.array_types.get_array_type gnome.array_types.reset_to_defaults Attributes ~~~~~~~~~~ .. autoapisummary:: gnome.array_types._default_values gnome.array_types.gat gnome.array_types.DEFAULT_ARRAY_TYPES gnome.array_types.default_array_types .. py:class:: ArrayType(shape, dtype, name, initial_value=0) Bases: :py:obj:`gnome.AddLogger` Object used to capture attributes of numpy data array for elements An ArrayType specifies how data arrays associated with elements are defined. constructor for ArrayType :param shape: shape of the numpy array :type shape: tuple of integers :param dtype: numpy datatype contained in array :type dtype: numpy dtype .. py:method:: __repr__() Return repr(self). .. py:method:: initialize_null(shape=None) initialize array with 0 elements. Used so SpillContainer can initializes all arrays with 0 elements. Used when the model is rewound. The purpose is to show all data_arrays even if model is not yet running or no particles have been released .. py:method:: initialize(num_elements, shape=None, initial_value=None) Initialize a numpy array with the dtype and shape specified. The length of the array is given by num_elements and spill is given as input if the initialize function needs information about the spill to initialize :param num_elements: number of elements so size of array to initialize Optional parameter :param shape=None: If this is None then use self.shape to determine size of array to create, else use this parameter. This is primarily used for ArrayTypes where either object's shape attribute is None or we want to override the object's predefined 'shape' during initialization .. py:method:: _num_gt_2(num) .. py:method:: split_element(num, value, *args) define how an LE gets split for specified ArrayType :param num: number of elements that current value should get split into :type num: int :param value: the current value that is replicated :type value: this must have shape and dtype equal to self.shape and self.dtype :param *args: accept more arguments as derived class may divide LE on split and in this case, user can specify a list of fractions for this division. .. py:method:: __eq__(other) Return self==value. .. py:method:: __ne__(other) Return self!=value. .. py:class:: IdArrayType(shape, dtype, name, initial_value=0) Bases: :py:obj:`ArrayType` The 'id' array assigns a unique int for every particle released. constructor for ArrayType :param shape: shape of the numpy array :type shape: tuple of integers :param dtype: numpy datatype contained in array :type dtype: numpy dtype .. py:method:: initialize(num_elements, *args) overrides base initialize functionality to output a range of values self.initial_value to num_elements + self.initial_value This is only used for 'id' of particle. shape attribute and initial_value are ignored since you always get an array of shape (num_elements,) Define *args to keep method signature the same .. py:method:: split_element(num, value, *args) split elements into num and assign 'value' to all of them .. py:class:: ArrayTypeDivideOnSplit(shape, dtype, name, initial_value=0) Bases: :py:obj:`ArrayType` Object used to capture attributes of numpy data array for elements An ArrayType specifies how data arrays associated with elements are defined. constructor for ArrayType :param shape: shape of the numpy array :type shape: tuple of integers :param dtype: numpy datatype contained in array :type dtype: numpy dtype .. py:method:: split_element(num, value, l_frac=None) define how an LE gets split for specified ArrayType. l_frac if given should sum to 1.0 :param num: number of elements that current value should get split into :type num: int :param value: the current value that is replicated :type value: this must have shape and dtype equal to self.shape and self.dtype :param l_frac: user can specify a list of fractions for this division - if None, then evenly divide 'value' into 'num'. sum(l_frac) = 1.0 .. py:data:: _default_values .. py:function:: get_array_type(name) Returns and instance of an array type appropriate for name, or None if one does not exist .. py:data:: gat .. py:function:: reset_to_defaults(at) .. py:data:: DEFAULT_ARRAY_TYPES :value: ['positions', 'next_positions', 'last_water_positions', 'status_codes', 'mass', 'init_mass',... .. py:data:: default_array_types