Model Data Management
- class pyomo.dataportal.DataPortal.DataPortal(*args, **kwds)[source]
An object that manages loading and storing data from external data sources. This object interfaces to plugins that manipulate the data in a manner that is dependent on the data format.
Internally, the data in a DataPortal object is organized as follows:
data[namespace][symbol][index] -> value
All data is associated with a symbol name, which may be indexed, and which may belong to a namespace. The default namespace is
None
.- Parameters:
model – The model for which this data is associated. This is used for error checking (e.g. object names must exist in the model, set dimensions must match, etc.). Default is
None
.filename (str) – A file from which data is loaded. Default is
None
.data_dict (dict) – A dictionary used to initialize the data in this object. Default is
None
.
- __getitem__(*args)[source]
Return the specified data value.
If a single argument is given, then this is the symbol name:
dp = DataPortal() dp[name]
If a two arguments are given, then the first is the namespace and the second is the symbol name:
dp = DataPortal() dp[namespace, name]
- Parameters:
*args (str) – A tuple of arguments.
- Returns:
If a single argument is given, then the data associated with that symbol in the namespace
None
is returned. If two arguments are given, then the data associated with symbol in the given namespace is returned.
- __setitem__(name, value)[source]
Set the value of
name
with the given value.- Parameters:
name (str) – The name of the symbol that is set.
value – The value of the symbol.
- __weakref__
list of weak references to the object (if defined)
- connect(**kwds)[source]
Construct a data manager object that is associated with the input source. This data manager is used to process future data imports and exports.
- Parameters:
Other keyword arguments are passed to the data manager object.
- data(name=None, namespace=None)[source]
Return the data associated with a symbol and namespace
- Parameters:
- Returns:
If
name
isNone
, then the dictionary for the namespace is returned. Otherwise, the data associated withname
in given namespace is returned. The return value is a constant ifNone
if there is a single value in the symbol dictionary, and otherwise the symbol dictionary is returned.
- items(namespace=None)[source]
Return an iterator of (name, value) tuples from the data in the specified namespace.
- Yields:
The next (name, value) tuple in the namespace. If the symbol has a simple data value, then that is included in the tuple. Otherwise, the tuple includes a dictionary mapping symbol indices to values.
- keys(namespace=None)[source]
Return an iterator of the data keys in the specified namespace.
- Yields:
A string name for the next symbol in the specified namespace.
- load(**kwds)[source]
Import data from an external data source.
- Parameters:
model – The model object for which this data is associated. Default is
None
.
Other keyword arguments are passed to the
connect()
method.
- namespaces()[source]
Return an iterator for the namespaces in the data portal.
- Yields:
A string name for the next namespace.
- class pyomo.dataportal.TableData.TableData[source]
A class used to read/write data from/to a table in an external data source.
- __weakref__
list of weak references to the object (if defined)
- initialize(**kwds)[source]
Initialize the data manager with keyword arguments.
The filename argument is recognized here, and other arguments are passed to the
add_options()
method.