The Data
class is an interface for all the data to be collected during a model’s run. The object is subscriptable: data[key]
will return the column of the data labelled key
.
This class should not be instantiated by user code; it is initialized during model setup and stored as model.data
.
Initialization Parameters
model — Helipad, required
The model object.
Methods
Click a method name for more detailed documentation.
addReporter( key, func, smooth )
Registers a column in the data to be collected each period. Typically used in conjunction with the various reporter methods of
Data
, but user functions can also be used with the@reporter
decorator.agentReporter( key, prim, breed, … )
Generates a reporter function that takes the model object and returns a summary statistic over all the values of an agent property.
getLast( key, n )
Returns the latest recorded value or values from the model's data.
modelReporter( key )
Generates a reporter function that takes the model object and returns the named attribute of the model.
removeReporter( key )
Removes a column and its subsidiaries (e.g. percentiles) from the data collection, stops its reporter, and removes any associated series. This function should not be used while a model is active.
reset( )
Clears all model data. Generally used to clean up between model runs. This function takes no arguments.
saveCSV( filename )
Outputs the model's data to a CSV file in the same directory as the running program. CSV output can be modified immediately prior to saving using the
saveCSV
hook.collect( model )
Iterates over all the registered reporters and collects model data each period.
This function is called from
model.step()
and should not be called from user code.
Object Properties
all — dict
A
dict
of all model data, with keys corresponding to registered reporters. Seedata.addReporter()
.Initial value: {}
dataframe — Pandas.DataFrame
A Pandas dataframe with the model run data. Useful for statistical functions.
Initial value: Pandas.DataFrame({})
reporters — dict{str:Reporter}
Contains the registered data reporters. See
data.addReporter()
.Initial value: {}
columns — dict{str:Reporter}
A dict of columns and the Reporter object associated with it. Calling
Data.columns.keys()
is less computationally expensive than callingData.all.keys()
. It also does not correspond toData.reporters.keys()
, because multiple columns may be associated with the same reporter (e.g. with percentile bars, smoothing, or ± standard deviations).
Hooks
Click a hook name for more detailed documentation.
saveCSV( data, model )
Allows CSV output to be filtered immediately before saving.
dataCollect( data, t )
Runs at the end of each model step immediately before the period's data is collected.
If you need a hook immediately after data is collected, use
modelPostStep
and access theData
object withmodel.data
.
Notes and Examples