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.

__init__(*args, **kwds)[source]

Constructor

__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:
  • filename (str) – A filename that specifies the data source. Default is None.

  • server (str) – The name of the remote server that hosts the data. Default is None.

  • using (str) – The name of the resource used to load the data. Default is None.

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:
  • name (str) – The name of the symbol that is returned. Default is None, which indicates that the entire data in the namespace is returned.

  • namespace (str) – The name of the namespace that is accessed. Default is None.

Returns:

If name is None, then the dictionary for the namespace is returned. Otherwise, the data associated with name in given namespace is returned. The return value is a constant if None if there is a single value in the symbol dictionary, and otherwise the symbol dictionary is returned.

disconnect()[source]

Close the data manager object that is associated with the input source.

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.

store(**kwds)[source]

Export data to 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.

values(namespace=None)[source]

Return an iterator of the data values in the specified namespace.

Yields:

The data value for the next symbol in the specified namespace. This may be a simple value, or a dictionary of values.

class pyomo.dataportal.TableData.TableData[source]

A class used to read/write data from/to a table in an external data source.

__init__()[source]

Constructor

__weakref__

list of weak references to the object (if defined)

add_options(**kwds)[source]

Add the keyword options to the Options object in this object.

available()[source]
Returns:

Return True if the data manager is available.

clear()[source]

Clear the data that was extracted from this table

close()[source]

Close the data manager.

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.

open()[source]

Open the data manager.

process(model, data, default)[source]

Process the data that was extracted from this data manager and return it.

read()[source]

Read data from the data manager.

write(data)[source]

Write data to the data manager.