andes.core.model.ModelData#
- class andes.core.model.ModelData(*args, three_params=True, **kwargs)[source]#
Class for holding parameter data for a model.
This class is designed to hold the parameter data separately from model equations. Models should inherit this class to define the parameters from input files.
Inherit this class to create the specific class for holding input parameters for a new model. The recommended name for the derived class is the model name with
Data
. For example, data for GENROU should be named GENROUData.Parameters should be defined in the
__init__
function of the derived class.Refer to
andes.core.param
for available parameter types.- Attributes:
- cache
A cache instance for different views of the internal data.
- flagsdict
Flags to control the routine and functions that get called. If the model is using user-defined numerical calls, set f_num, g_num and j_num properly.
Notes
Three default parameters are pre-defined in
ModelData
and will be inherited by all models. They areidx
, unique device idx of typeandes.core.param.DataParam
u
, connection status of typeandes.core.param.NumParam
name
, (device name of typeandes.core.param.DataParam
In rare cases one does not want to define these three parameters, one can pass three_params=True to the constructor of
ModelData
.Examples
If we want to build a class
PQData
(for static PQ load) with three parameters, Vn, p0 and q0, we can use the followingfrom andes.core.model import ModelData, Model from andes.core.param import IdxParam, NumParam class PQData(ModelData): super().__init__() self.Vn = NumParam(default=110, info="AC voltage rating", unit='kV', non_zero=True, tex_name=r'V_n') self.p0 = NumParam(default=0, info='active power load in system base', tex_name=r'p_0', unit='p.u.') self.q0 = NumParam(default=0, info='reactive power load in system base', tex_name=r'q_0', unit='p.u.')
In this example, all the three parameters are defined as
andes.core.param.NumParam
. In the full PQData class, other types of parameters also exist. For example, to store the idx of owner, PQData usesself.owner = IdxParam(model='Owner', info="owner idx")
Methods
add
(**kwargs)Add a device (an instance) to this model.
as_df
([vin])Export all parameters as a pandas.DataFrame object.
Export local variable values and services to a DataFrame.
as_dict
([vin])Export all parameters as a dict.
find_idx
(keys, values[, allow_none, ...])Find idx of devices whose values match the given pattern.
find_param
(prop)Find params with the given property and return in an OrderedDict.
update_from_df
(df[, vin])Update parameter values from a DataFrame.