XML File Format ==================== The `opgee` package includes two built-in XML files: * `opgee/etc/opgee.xml` describes the default model, and * `opgee/etc/attributes.xml` describes attributes of various model components. Users can provide their own XML files which can be merged with or used in place of, the built-in definitions. The elements of the two files are described below, followed by the contents of the built-in files. XML file merging ----------------- The user can specify multiple XML filenames to the `opg run` sub-command. The purpose of this feature is to allow users to use the built-in model specification as much as possible, by specifying only modifications changes to that model. The built-in files etc/opgee.xml and etc/attributes.xml are first loaded unless the user specifies `--no-default-model` on the command-line to the `opg run` sub-command. Files are merged in the order they are given on the command-line. How merging works ^^^^^^^^^^^^^^^^^^^^^ The first loaded XML is considered the "base" file into which subsequent files are merged. Each subsequent file contain the complete XML structure, from the `` element down, but it needs to specify only * new elements not present in the base or previously merged files * modifications to existing elements, or * elements to delete For an elements to "match" a previously defined one, it must be in the position in the XML hierarchy where each element in the hierarchy of the new and old models have the same tag and attributes (attribute order is irrelevant). An element is inserted into the XML in the position where a non-matching element first appears in the structure. **Give example** If a match is found and the attribute ``delete=true`` is specified in the new XML, that element and everything below it in original XML is deleted, and any XML below this element is inserted in its place. **Give example** If a match is found and the attribute ``delete=true`` is *not* specified in the new XML, the matching process proceeds recursively to the next lower level of the XML structure. If a final XML element (i.e., one with no children) matches, its text is copied in place of any that appeared in the currently merged XML. **Give example.** --------------------------------------------------------------------------------------------------------- opgee.xml ------------ The elements that comprise the ``opgee.xml`` file are described below. ^^^^^^^^^^ The top-most element, ````, encloses one or more ````, ````, and ```` elements. The ```` element takes no attributes. .. [Saved for later] The ``delete`` attribute is used only by user-defined files. If the value of the attribute is "1", "yes", or "true" (case insensitive), and a corresponding value exists in the built-in XML structure, the built-in element and all elements below it in the hierarchy are deleted before the new element is added. ^^^^^^^^^^^^^^^ The ```` element is used to set values for attributes in a ````, ````, ```` or ```` element. The XML schema allows model elements to have zero or more attributes. The XML schema ensures that the ```` elements are syntactically correct. The semantics of these elements is defined by a corresponding ```` element (see attributes.xml) in the named class. For example, .. code-block:: xml 124 2342 provides values for two attributes, `weight` and `distance`, for the `SurveyShip` class. These have a corresponding (**required**) ```` definition in attributes.xml that provides the units, description, type, and default value: .. code-block:: xml 10000 100 The ```` element contains no further elements, but it contains an optional value for the attribute, which if absent is assigned the default for this attribute. The `name` attribute must refer to the name of an ```` defined in the built-in `attributes.xml` or a file loaded by the user. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text ^^^^^^^^^^^^^ This element contains one or more ```` or ```` elements and accepts one required attribute, `name`. The ```` elements identify fields to include in the analysis by field name, whereas ```` elements allow matching of group names indicated in ```` definitions, by direct string match or by regular expression match. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text ^^^^^^^^^ The ```` element provides a system of keyword matching by which ```` elements can declare themselves members of a group, and ```` elements can reference members of the group. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - regex - no - "false" - boolean The ```` element allows one attribute, `regex` and contains no subelements. It must contain a string that is either a regular expression (if `regex` has a "true" value, i.e., "true", "yes", "1") or the name of a field group (if `regex` has a "false" value, i.e., "false", "no", "0", or is absent.) The identification of the ```` elements to include in the ```` matches ```` elements declared within ```` elements. The match uses direct string matching (if `regex` is false) or regular expression matching (if `regex` is true). ^^^^^^^^^^ This element describes an oil or gas field and its processes. ```` can contain more or more ````, ````, ````, ````, or ```` elements. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text * - enabled - no - "1" - boolean * - extend - no - "0" - boolean ^^^^^^^^^^^^^^^ This element contains one or more ````, ````, or ```` elements. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text * - enabled - no - "1" - boolean ^^^^^^^^^^^^^^^ The ```` element defines the characteristics of a physical process. It must include a `class` attribute which identifies the Python class that implements the process. The identified class must be a subclass of `Process`. ``>`` elements may contain one or more ```` elements. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - class - yes - (none) - text * - name - no - (class name) - text * - desc - no - (none) - str * - enabled - no - "1" - boolean * - extend - no - "0" - boolean * - impute-start - no - "0" - boolean * - cycle-start - no - "0" - boolean * - boundary - no - (none) - text * - delete - no - "0" - boolean * - after - no - "0" - boolean The ```` element is also used to define boundary processes. In this case, the ``class`` attribute must have the value "Boundary", and the ``boundary`` attribute must have the name of a defined system boundary. By default, these include `Production`, `Transportation`, and `Distribution`, but boundaries can be added or removed by setting the configuration variable ``OPGEE.Boundaries``. See :doc:`config` for more information. Example: .. code-block:: xml ^^^^^^^^^^^^^^^ This element contains one or more ````, ```` or ```` elements. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text * - number - no - (none) - int * - src - yes - (none) - str * - dst - yes - (none) - str * - impute - no - 1 - bool The `src` and `dst` attributes must be set to the names of Process subclasses that are the source and destination, respectively, for the `Stream`. If no `name` is provided, the name becomes "{src} => {dst}", with the names of the source and destination processes substituted for `{src}` and `{dst}`. The `impute` attribute defaults to "1" (true); if set to "0" (or "false" or "no") the `Stream` will not be traversed during the `impute()` processing phase, which works backwards (upstream) from the `Streams` with exogenously-defined flow rates. ^^^^^^^^^^^^^^^^ This element must occur within a ```` definition. Component encloses a numerical value defining an exogenous component flow rate, expressed in mmbtu/day for all components other than electricity, expressed in kWh/day. (See :obj:`opgee.stream.Stream` for a list of component names.) .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text * - phase - yes - "solid", "liquid" or "gas" - str ^^^^^^^^^^^^^^^^ This element must occur within a ```` definition. The ```` element holds a string indicating a generic name for the substance found in the stream. This allows processes to find different input streams without reference to any specific process name. The ```` element takes no XML attributes. ^^^^^^^^^^^^^^^^^^^ This element can contain multiple ```` elements. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text * - default - no - (none) - text ^^^^^^^^^^^^^^^^^^^ This element can contain multiple ````, ````, and ```` elements. That is, ```` elements can nest recursively, so there can be choices within choices. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text ^^^^^^^^^^^^^^^^^^^ This element identifies a ``Process`` by name for inclusion in a ````. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text ^^^^^^^^^^^^^^^^^^^ This element identifies a ``Stream`` by name for inclusion in a ````. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text ^^^^^^^^^^^^^^^^^^^ This element defines one or more updates to a built-in CSV data file. The ``name`` attribute must be the basename of a built-in table. A ``TableUpdate`` element must contain one or more ```` elements. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text ^^^^^^^^^^^^^^^^^^^ This element defines a single replacement value for a value in a built-in CSV data file. The ``row`` and ``col`` attributes (both required) define the cell whose value is replaced by the content .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - row - yes - (none) - text * - col - yes - (none) - text Example: .. code-block:: xml 1234.5 12345.67 --------------------------------------------------------------------------------------------------------- attributes.xml ---------------- ^^^^^^^^^^^^^ .. saved for reference link format only .. This element identifies a :doc:`rewrite set ` by name. .. The rewrite set must be defined in a file identified as an argument .. to the :py:func:`pygcam.query.runBatchQuery`, on the command-line to .. the :ref:`query sub-command `, or by setting a value for .. the config variable ``GCAM.RewriteSetsFile``. This is the top-level element in the `attributes.xml` file. It accepts no attributes and contains only ```` elements. ^^^^^^^^^^^^^^^^^ This element describes attributes associated with an OPGEE class, whose name is provide by the `name` attribute. ```` elements contain any number of ```` and ```` elements. .. list-table:: Attributes :widths: 10 10 10 10 :header-rows: 1 * - Attribute - Required - Default - Values * - name - yes - (none) - text ^^^^^^^^^^^^ This element defines a named set of legal values. Both the `name` and `default` attributes are required. The ```` element contains one or more (more usefully, two or more) ``