Skip to content

Add option to dump iidm in the same format/version as the loaded one #1234

Description

@FredericSabot

Describe the current behavior

Currently, network.dump(file) dumps the network using the latest supported iidm version, and force the extension of fileto be .xiidm.

Describe the expected behavior

Add an option to dump using the loaded version (from n = pp.network.load(iidm)) and don't overwrite the file extension.

Describe the motivation

Some external tools might not support the latest version of powsybl, which requires workaround like

def get_iidm_version(iidm_path: Path) -> str:
    tree = etree.parse(iidm_path)
    ns = tree.getroot().nsmap.get(None) or next(iter(tree.getroot().nsmap.values()))
    # e.g. "http://www.itesla/_project.eu/schema/iidm/1_0" -> "1.0"
    version = ns.rstrip("/").rsplit("/", 1)[-1].replace("_", ".")
    return version

n = pp.network.load(iidm)
version = get_iidm_version(iidm)  # Keep original version in dump
n.dump(output, 'XIIDM', {"iidm.export.xml.version": version})
# Keep the original extension instead of forcing xiidm
[file, ext] = output_name.rsplit('.', 1)
if ext != 'xiidm':
    os.rename(file + '.xiidm', iidm)

Extra Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions