:py:mod:`metacast.event_handling.events` ======================================== .. py:module:: metacast.event_handling.events .. autoapi-nested-parse:: Creation: Author: Martin Grunnill Date: 2024/03/08 Description: Events for use in class EventQueue. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: metacast.event_handling.events.BaseEvent metacast.event_handling.events.ValueFactorProportionChangeEvent metacast.event_handling.events.TransferEvent metacast.event_handling.events.ChangeParametersEvent metacast.event_handling.events.ParametersEqualSubPopEvent .. py:class:: BaseEvent(name, times) Base parent event. Parameters & Attributes ----------------------- name : str Name given to event. times : floats/ints, ranges or list/tuple/set of floats/ints Times at which event occurs. .. method:: process() Method for carrying out event. .. method:: make_event_a_nullevent() Changes method into a do null event (do nothing event). Child classes process method should start with 'if self._do_nothing: super().process() else:' or 'if self._do_nothing: pass else:' .. method:: undo_make_event_a_nullevent() Changes method from a do null event (do nothing event). Child classes process method should start with 'if self._do_nothing: super().process() else:' or 'if self._do_nothing: pass else:' .. py:method:: process() Method for carrying out event. :rtype: Nothing .. py:class:: ValueFactorProportionChangeEvent(name, times, value=None, factor=None, proportion=None) Bases: :py:obj:`BaseEvent` Parent event for events that involve changing a value or values. Parameters & Attributes ----------------------- name : str Name given to event. times : floats/ints, ranges or list/tuple/set of floats/ints Times at which event occurs. value : foat/int, mutually exclusive with factor and proportion. Value that overrides original value(s). proportion : foat/int, mutually exclusive with value and factor. Proportion the multiplies original value(s). Must be between 0 and 1. factor : foat/int, mutually exclusive with value and proportion. Factor the multiplies original value(s). .. method:: process() Method for carrying out event. .. method:: make_event_a_nullevent() Changes method into a do null event (do nothing event). .. method:: undo_make_event_a_nullevent() Changes method from a do null event (do nothing event). .. py:property:: proportion .. py:property:: factor .. py:property:: value .. py:class:: TransferEvent(name, times, value=None, factor=None, proportion=None, from_index=None, to_index=None) Bases: :py:obj:`ValueFactorProportionChangeEvent` Transfers values between state variables. Note if value, factor and proportion are all None event is a null event (do nothing event). Parameters & Attributes ----------------------- name : str Name given to event. times : floats/ints, ranges or list/tuple/set of floats/ints Times at which event occurs. value : foat/int, optional but mutually exclusive with factor and proportion. Value that overrides original parameter value(s). proportion : foat/int, optional but mutually exclusive with value and factor. Proportion the multiplies original parameter value(s). Must be between 0 and 1. factor : foat/int, optional but mutually exclusive with value and proportion. Factor the multiplies original parameter value(s). from_index: list-like of ints Indexes of stat variables from which transfers take place. to_index: list-like of ints Indexes of stat variables to which transfers take place. .. method:: process() Process event by transferring amount between state variables .. method:: make_event_a_nullevent() Changes method into a do null event (do nothing event). .. py:method:: process(solution_at_t, time, return_total_effected=True) Process event by transferring amount between state variables. Note if value, factor and proportion are all None event is a null event (do nothing event). :param solution_at_t: State variable values at time t. :type solution_at_t: numpy.array :param time: Time at t. :type time: float :param return_total_effected: If true total number transferred is returned. :type return_total_effected: bool, default is True :rtype: If return_total_effected is True, total number transferred is returned. .. py:class:: ChangeParametersEvent(name, times, changing_parameters, value=None, factor=None, proportion=None) Bases: :py:obj:`ValueFactorProportionChangeEvent` Event for changing parameter values. Note if value, factor and proportion are all None event is a null event (do nothing event). Parameters & Attributes ----------------------- name : str Name given to event. times : floats/ints, ranges or list/tuple/set of floats/ints Times at which event occurs. changing_parameters : list-like of strings Parameters whose values will be changed. value : foat/int, optional but mutually exclusive with factor and proportion. Value that overrides original parameter value(s). proportion : foat/int, optional but mutually exclusive with value and factor. Proportion the multiplies original parameter value(s). Must be between 0 and 1. factor : foat/int, optional but mutually exclusive with value and proportion. Factor the multiplies original parameter value(s). .. method:: process() Process event by change parameter values for parameters listed in self.changing_parameters. .. method:: make_event_a_nullevent() Changes method into a do null event (do nothing event). .. py:method:: process(model_object, parameters_attribute, parameters) Process event by change parameter values for parameters listed in self.changing_parameters. Note if value, factor and proportion are all None event is a null event (do nothing event). :param model_object: Object used to define and simulate model. :type model_object: object :param parameters_attribute: Attribute of model_object that sets parameters (must accept dictionary where keys are strings and values are floats/ints). :type parameters_attribute: string :param parameters: Parameters being used by model. :type parameters: dict {str : floats/ints} :returns: **parameters** -- Parameters being used by model after the values of those is list self.changing_parameters is changed. :rtype: dict {str : floats/ints} .. py:class:: ParametersEqualSubPopEvent(name, times, changing_parameters, subpopulation_index) Bases: :py:obj:`BaseEvent` Change parameters to be equal to the sum of a subpopulation. Parameters & Attributes ----------------------- name : str Name given to event. times : floats/ints, ranges or list/tuple/set of floats/ints Times at which event occurs. changing_parameters : list-like of strings Parameters whose values will be changed. subpopulation_index : list-like of ints Index of subpopulation the sum of which will change self.changing_parameters to. .. method:: process() Process event by changing parameters to be equal to the sum of a subpopulation. .. method:: make_event_a_nullevent() Changes method into a do null event (do nothing event). .. py:method:: process(model_object, parameters_attribute, parameters, solution_at_t) Process event by changing parameters to be equal to the sum of a subpopulation. :param model_object: Object used to define and simulate model. :type model_object: object :param parameters_attribute: Attribute of model_object that sets parameters (must accept dictionary where keys are strings and values are floats/ints). :type parameters_attribute: string :param parameters: Parameters being used by model. :type parameters: dict {str : floats/ints} :param solution_at_t: State variable values at time t. :type solution_at_t: numpy.array :rtype: Nothing