py_champ.utility package
Submodules
py_champ.utility.util module
- class py_champ.utility.util.BaseSchedulerByTypeFiltered(model: Model)
Bases:
BaseSchedulerA scheduler that overrides the step method to allow for filtering of agents by .agt_type.
Example:
>>> scheduler = BaseSchedulerByTypeFiltered(model) >>> scheduler.step(agt_type="Behavior")
- do_each(method, agent_keys=None, shuffle=False, agt_type=None)
- py_champ.utility.util.get_nested_attr(obj, attr_str)
A patch to collect a nested attribute using MESA’s datacollector.
This function is used to get a nested attribute from an object. For example, if we have an object with an attribute “a” that is a dictionary with a key “b”, we can get the value of “b” by calling get_nested_attr(obj, “a.b”). This is useful when collecting data from agents in a model.
- py_champ.utility.util.get_agt_attr(attr_str)
Get a nested attribute from an agent object.
This replaces, e.g., lambda a: getattr(a, “satisfaction”, None) We have to do this to return None if the attribute is not exist in the given agent type. def func(agent):
return getattr(agent, attr, None).
- Parameters:
attr_str (str) – A string of nested attributes separated by a period.
- Returns:
A function that returns the nested attribute.
- Return type:
function
- py_champ.utility.util.dict_to_string(dictionary, prefix='', indentor=' ', level=2)
Ture a dictionary into a printable string.
- class py_champ.utility.util.TimeRecorder
Bases:
objectA class for recording time.
- get_elapsed_time(event=None, strf=True)
Get elapsed time since the start of the recorder.
- class py_champ.utility.util.Indicator
Bases:
objectA class for calculating indicators.
- static remove_na(x_obv, y_sim)
Remove nan in x_obv and y_sim.
This function makes sure there is no nan involves in the indicator calculation. If nan is detected, data points will be remove from x_obv and y_sim simultaneously.
- Parameters:
x_obv (array) – Observation data.
y_sim (array) – Simulation data.
- Returns:
Updated (x_obv, y_sim)
- Return type:
- static cal_indicator_df(x_obv, y_sim, index_name='value', indicators_list=None, r_na=True)
Calculate indicators and return as a DataFrame.
- Parameters:
- Returns:
A DataFrame of indicators.
- Return type:
DataFrame
- static get_r(x_obv, y_sim, r_na=True)
Correlation.
- static get_r2(x_obv, y_sim, r_na=True)
Coefficient of determination.
- static get_rmse(x_obv, y_sim, r_na=False)
Root mean square error.
- static get_nse(x_obv, y_sim, r_na=False)
Nash-Sutcliffe efficiency.
- static get_inse(x_obv, y_sim, r_na=False)
Inverse Nash-Sutcliffe efficiency.
- static get_cp(x_obv, y_sim, r_na=False)
Correlation of persistence.
- static get_rsr(x_obv, y_sim, r_na=False)
RMSE-observations standard deviation ratio.
- static get_kge(x_obv, y_sim, r_na=True)
Kling-Gupta efficiency.
Module contents
Provides utility functions and classes for the PyCHAMP package.