EnergySystemHandler
- class esdl.esdl_handler.EnergySystemHandler(energy_system=None)
- __init__(energy_system=None)
- load_file(uri_or_filename: str) EnergySystem
Loads a file in a new resource set
- load_uri(uri) EnergySystem
Loads a new resource in a new resourceSet
- add_uri(uri) EnergySystem
Adds the specified URI to the resource set, i.e. load extra resources that the resource can refer to.
- load_from_string(esdl_string) EnergySystem
- to_string() str
To serialize an energy system in a resource, we use a StringURI to save it to a string instead of a file :return: XML string of the current resource/ESDL file that is loaded.
- to_bytesio() BytesIO
Returns a BytesIO stream for the energy system
- get_external_reference(url: str, object_id: str | None = None)
Support function to create a reference to an external ESDL/EDD file.
- Parameters:
url – web address e.g. a URL from the EDR, https://drive.esdl.hesi.energy/store/resource/edr/Public/Key figures/Emissiefactoren energiedragers 2017.edd
object_id – Optional, the id of the object in the file to refer to, if not specified, it will return the root of the file.
- Returns:
EObject returning the root of the document, or the object that is specified by the id found in that file
Be aware that when assigning an external reference to a containment relation, the content from the external reference will be moved (not copied) to the resource that it is assigned to. If you want the reference to be external, only use this for references (no diamond), not containment relations (a diamond in the ESDL UML diagram)
- save(filename=None)
Add the resource to the resourceSet when saving
- save_as(filename)
Saves the resource under a different filename
- get_energy_system() EnergySystem
- get_by_id(object_id) EObject
- get_by_id_slow(object_id) EObject
- update_uuid_dict(es: EnergySystem | None = None) None
Update the Resource’s uuid_dict of a specific energy system This might be necessary when e.g. deepcopying an object in an resource that has references to other parts of that resource that are not being deepcopied. :param es: energy system that needs a uuid_dict update, if None, the current self.energy_system is used
- add_object(obj)
- remove_object(obj)
- remove_obj_by_id(obj_id)
- get_all_instances_of_type(esdl_type)
- static instantiate_esdltype(className: str) EObject
Instantiates a new instance of an ESDL class className and returns it. E.g. ip:InPort = instantiate_esdltype(“InPort”)
- static resolve_fragment(resource: Resource, fragment: str)
Resolves a URI fragment (e.g. ‘//@instance.0/@area/@asset.0/@port.0’) to the associated object and returns the object. This is used for objects that have no ID attribute
- static attr_to_dict(esdl_object) Dict[str, Any]
Creates a dict of all the attributes of an ESDL object, useful for printing/debugging
- static generate_uuid() str
Creates a uuid: useful for generating unique IDs
- create_empty_energy_system(name, es_description=None, inst_title='Instance0', area_title='Main Area') EnergySystem
Creates a new empty Energy System (EnergySystem + Instance + Area) and adds it to the resource set :param name: :param es_description: Optional :param inst_title: optional, default “Instance0” :param area_title: :return: the created empty Energy System
- static version()
Returns the version of pyESDL
- class esdl.esdl_handler.StringURI(uri, text=None)
- __init__(uri, text=None)
Creates a new StringURI to be used for a resource. By setting text it can convert that XML text to a python class model, when doing a resource.load(uri). If text is empty and the associated resource is not, resource.save(uri) will convert the resource to XML. Use uri.getvalue() to return the string representation of this resource. :param uri: the file name of this ESDL, should be unique in this resource set. :param text: XML string to convert to a resource (pyEcore classes)
- getvalue()
- Returns:
the XML as a string of this ESDL resource
- create_instream()
- create_outstream()
- get_stream()