Element

Overview

Element is the base abstraction for carriers and technologies in ZEN-creator.

Use Cases

  • Define shared behavior for all model elements.

  • Implement project-specific subclasses with custom attribute logic.

Examples

from zen_creator import Element

# Typically extended in project-specific implementations.
class MyElement(Element):
    pass

Summary

zen_creator.Element.__init__

Initialize an Element instance.

Constructors

Element.__init__(model: Model, power_unit: str = 'MW')

Initialize an Element instance.

Parameters:
  • model (Model) – The model this element belongs to.

  • power_unit (str) – The unit for power values. Defaults to “MW”.

Member Reference

class zen_creator.Element(model: Model, power_unit: str = 'MW')

Bases: Registry[Element], ABC

Base class for all elements in the ZEN model.

This class provides the foundation for carriers, technologies, and other model components. It handles attribute management, path resolution, and serialization.

name

The name of the element.

Type:

str

subpath

Subpath for organizing element files.

Type:

ClassVar[str]

_element_registry

Registry of all element classes.

Type:

dict[str, Type[Element]]

property attributes: dict[str, Attribute]

Dictionary of all attributes for this element.

Returns:

Mapping of attribute names to Attribute

objects.

Return type:

dict[str, Attribute]

attributes_to_dict() dict

Convert element attributes to a dictionary for serialization.

Returns:

Dictionary representation of the element’s attributes.

Return type:

dict

build()

Build the element by setting attributes from their setters.

This method calls the _set_<attribute_name> methods whenever these exist. The attributes are set to the output of these methods.

get_output_path() Path

Get the path to the element output directory and create it.

Returns:

The absolute path to the element’s output directory.

Return type:

Path

name: str = 'element'
property output_path: Path

Get the absolute output path and ensure the directory exists.

Side Effects:

Creates the output path if it does not exist.

Returns:

The absolute path to the output directory for this element.

Return type:

Path

overwrite_from_existing_model(existing_model_path: Path)

Overwrite attributes with values from an existing model.

Parameters:

existing_model_path (Path) – Path to the existing model directory.

property relative_output_path: Path

Get the relative output path for this element.

The path is constructed by combining the element name with subpaths from the class hierarchy.

Returns:

The relative path for output files.

Return type:

Path

save_attributes()

Save the element’s attributes to attributes.json.

save_data()

Save the element’s data files.

property source_path: Path

Get the source path of the model where the raw data is located.

Returns:

The source path to the raw data.

Return type:

Path

sources_to_str() str

Convert the sources of all attributes to a markdown page.

Returns:

A markdown-formatted string of all sources for this element.

Return type:

str

subpath: ClassVar[str] = ''
write()

Write the element to disk.

This method saves the attributes.json file and any associated data files.