VeraGridEngine.IO.veragrid package

Submodules

VeraGridEngine.IO.veragrid.catalogue module

VeraGridEngine.IO.veragrid.catalogue.get_cables_catalogue_df(grid: MultiCircuit)[source]
Parameters:

grid

Returns:

VeraGridEngine.IO.veragrid.catalogue.get_sequence_lines_catalogue_df(grid: MultiCircuit)[source]
Parameters:

grid

Returns:

VeraGridEngine.IO.veragrid.catalogue.get_transformers_catalogue_df(grid: MultiCircuit)[source]
Parameters:

grid

Returns:

VeraGridEngine.IO.veragrid.catalogue.get_wires_catalogue_df(grid: MultiCircuit)[source]
Parameters:

grid

Returns:

VeraGridEngine.IO.veragrid.catalogue.load_catalogue(fname: str) Tuple[Assets, Logger][source]
Parameters:

fname

Returns:

VeraGridEngine.IO.veragrid.catalogue.parse_cable_types(df: DataFrame) List[UndergroundLineType][source]
Parameters:

df

Returns:

VeraGridEngine.IO.veragrid.catalogue.parse_sequence_line_types(df: DataFrame) List[SequenceLineType][source]
Parameters:

df

Returns:

VeraGridEngine.IO.veragrid.catalogue.parse_transformer_types(df: DataFrame) List[TransformerType][source]
Parameters:

df

Returns:

VeraGridEngine.IO.veragrid.catalogue.parse_wire_types(df: DataFrame) List[Wire][source]
Parameters:

df

Returns:

VeraGridEngine.IO.veragrid.catalogue.save_catalogue(fname: str, grid: MultiCircuit)[source]
Parameters:
  • fname

  • grid

Returns:

VeraGridEngine.IO.veragrid.contingency_parser module

VeraGridEngine.IO.veragrid.contingency_parser.export_contingencies_json_file(circuit: MultiCircuit, file_path)[source]
VeraGridEngine.IO.veragrid.contingency_parser.get_contingencies_dict(circuit: MultiCircuit)[source]
Parameters:

circuit

Returns:

VeraGridEngine.IO.veragrid.contingency_parser.import_contingencies_from_json(file_name: str)[source]
Parameters:

file_name

Returns:

VeraGridEngine.IO.veragrid.contingency_parser.parse_contingencies(data)[source]
Parameters:

data

Returns:

VeraGridEngine.IO.veragrid.excel_interface module

VeraGridEngine.IO.veragrid.excel_interface.check_names(names: List[str], logger: Logger) None[source]

Check that the names are allowed :param names: :param logger: :return:

VeraGridEngine.IO.veragrid.excel_interface.get_allowed_sheets() Dict[str, Any][source]

Get the allowed sheets in the excel file :return:

VeraGridEngine.IO.veragrid.excel_interface.interpret_excel_v3(data: ~typing.Dict[str, ~pandas.DataFrame], logger: ~VeraGridEngine.basic_structures.Logger = <VeraGridEngine.basic_structures.Logger object>) MultiCircuit[source]

Interpret the file version 3 In this file version there are no complex numbers saved :param circuit: :param data: Dictionary with the excel file sheet labels and the corresponding DataFrame :param logger: Loger object :return: Nothing, just applies the loaded data to this MultiCircuit instance

VeraGridEngine.IO.veragrid.excel_interface.interprete_excel_v2(data, logger: Logger = <VeraGridEngine.basic_structures.Logger object>) MultiCircuit[source]

Interpret the file version 2 :param data: Dictionary with the excel file sheet labels and the corresponding DataFrame :return: Nothing, just applies the loaded data to this MultiCircuit instance

VeraGridEngine.IO.veragrid.excel_interface.load_from_xls(filename: str, logger: Logger) Dict[str, DataFrame][source]

Loads the excel file content to a dictionary for parsing the data

VeraGridEngine.IO.veragrid.excel_interface.save_excel_v4(circuit: MultiCircuit, file_path)[source]

Save the circuit information in excel format :param circuit: MultiCircuit instance :param file_path: path to the excel file :return: logger with information

VeraGridEngine.IO.veragrid.excel_interface.shorten_dict_keys(d: Dict[str, Any], max_size=30)[source]

Change dict keys to match the Excel 30 char limit :param d: :param max_size: :return:

VeraGridEngine.IO.veragrid.generic_io_functions module

class VeraGridEngine.IO.veragrid.generic_io_functions.CustomJSONizer(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
VeraGridEngine.IO.veragrid.generic_io_functions.parse_config_df(df, data=None)[source]

VeraGridEngine.IO.veragrid.h5_interface module

VeraGridEngine.IO.veragrid.h5_interface.open_h5(file_path, text_func=None, prog_func=None, logger: Logger = <VeraGridEngine.basic_structures.Logger object>)[source]
Parameters:
  • file_path

  • text_func

  • prog_func

  • logger

Returns:

VeraGridEngine.IO.veragrid.h5_interface.save_h5(circuit: MultiCircuit, file_path, compression_opts=5, text_func=None, prog_func=None)[source]

Save the circuit information in excel format :param circuit: MultiCircuit instance :param file_path: path to the excel file :param compression_opts: compression [0, 9] :param text_func: :param prog_func: :return: logger with information

VeraGridEngine.IO.veragrid.json_parser module

VeraGridEngine.IO.veragrid.json_parser.add_to_dict(main_dict: Dict[str, List[Any]], data_to_append: Dict[Any, Any], key: str)[source]

Append d2 into a list of d at the key :param main_dict: Dictionary to append to :param data_to_append: Secondary dictionary to append :param key: key where to append the dictionary

VeraGridEngine.IO.veragrid.json_parser.add_to_dict2(main_dict: Dict[str, Any], data: Dict[Any, Any], key: str)[source]

Add data to the main dictionary at the given key if it does not exists already :param main_dict:Dictionary to append to :param data: Some dictionary :param key: key to store

VeraGridEngine.IO.veragrid.json_parser.get_obj_ref(elm)[source]

get the idtag and if none return an empty str :param elm: :return:

VeraGridEngine.IO.veragrid.json_parser.get_profiles_dict(elm: EditableDevice) Dict[str, Any][source]
Returns:

VeraGridEngine.IO.veragrid.json_parser.json_to_profile(profile: ProfileFloat | ProfileInt | ProfileBool | ProfileDevice | ProfileEnum, d: Dict[str, Any]) None[source]

Assign a json profile to a Profile object :param profile: Profile to modify :param d: json parsed dictionary

VeraGridEngine.IO.veragrid.json_parser.parse_json(file_name) MultiCircuit[source]

Parse JSON file into Circuit :param file_name: :return: VeraGrid MultiCircuit

VeraGridEngine.IO.veragrid.json_parser.parse_json_data(data) MultiCircuit[source]

Parse JSON structure into VeraGrid MultiCircuit :param data: JSON structure (list of dictionaries) :return: VeraGrid MultiCircuit

VeraGridEngine.IO.veragrid.json_parser.parse_json_data_v2(data: dict, logger: Logger)[source]

New Json parser :param data: :param logger: :return:

VeraGridEngine.IO.veragrid.json_parser.parse_json_data_v3(data: dict, logger: Logger)[source]

Json parser for V3 :param data: :param logger: :return:

VeraGridEngine.IO.veragrid.json_parser.profile_to_json(profile: ProfileFloat | ProfileInt | ProfileBool | ProfileDevice | ProfileEnum) Dict[str, Any][source]

Convert a Profile to a json dictionary :param profile: :return:

VeraGridEngine.IO.veragrid.json_parser.save_json_file_v3(file_path: str, circuit: MultiCircuit, simulation_drivers: List[DriverToSave] | None = None)[source]

Save JSON file :param file_path: file path :param circuit: VeraGrid MultiCircuit element :param simulation_drivers: List of Simulation Drivers (optional)

VeraGridEngine.IO.veragrid.json_parser.set_object_properties(elm, prop: List[str], entry: Dict[str, Any])[source]

Set the properties of an object :param elm: object to be set :param prop: list of properties :param entry: :return:

VeraGridEngine.IO.veragrid.pack_unpack module

class VeraGridEngine.IO.veragrid.pack_unpack.CreatedOnTheFly[source]

Bases: object

This class is to pack all those devices that are created β€œon the fly” to support legacy formats

create_contingency(elm: Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement)[source]
Parameters:

elm

Returns:

create_technology(elm: Generator, tech_name: str)[source]
Parameters:
  • elm

  • tech_name

Returns:

get_create_area(property_value)[source]
Parameters:

property_value

Returns:

get_create_substation(property_value)[source]
Parameters:

property_value

Returns:

get_create_zone(property_value)[source]
Parameters:

property_value

Returns:

VeraGridEngine.IO.veragrid.pack_unpack.cast_profile_value(profile: ProfileFloat | ProfileInt | ProfileBool | ProfileDevice | ProfileEnum, value: Any, collection: None | Dict[str, Any] = None) Any[source]

Convert serialized profile payloads into the concrete type required by profile.

Parameters:
  • profile – Typed profile that will receive the value.

  • value – Serialized raw value.

  • collection – Optional idtag-to-object dictionary for device references.

Returns:

Converted value.

VeraGridEngine.IO.veragrid.pack_unpack.gather_model_as_data_frames(circuit: MultiCircuit, logger: Logger = <VeraGridEngine.basic_structures.Logger object>, legacy: bool = False) Dict[str, DataFrame][source]

Pack the circuit information into tables (DataFrames) :param circuit: MultiCircuit instance :param logger: Logger instance :param legacy: Generate the legacy object DataFrames :return: dictionary of DataFrames

VeraGridEngine.IO.veragrid.pack_unpack.gather_model_as_jsons(circuit: MultiCircuit, project_directory: Path | None = None) dict[str, dict[str, dict[str, str] | list[dict[str, str]]] | dict[str, list[dict[str, Any]] | dict[int, list[Any]] | dict[int, dict[str, Any]] | list[int]]][source]

Transform a MultiCircuit into a collection of Json files :param circuit: :return:

VeraGridEngine.IO.veragrid.pack_unpack.get_multiverse_node_metadata(metadata: Dict[str, Any]) Dict[str, Dict[str, Any]][source]

Extract the per-node metadata dictionary from a multiverse metadata payload.

Newer files wrap node records under nodes and may include top-level metadata such as active_node_id. Older files store the node records directly at the top level.

VeraGridEngine.IO.veragrid.pack_unpack.get_objects_dictionary() Dict[str, Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement][source]

creates a dictionary with the types and the circuit objects :return: Dictionary instance

VeraGridEngine.IO.veragrid.pack_unpack.get_profile_from_dict(profile: ProfileFloat | ProfileInt | ProfileBool | ProfileDevice | ProfileEnum, data: Dict[str, Any | Dict[str, Any]], collection: None | Dict[str, Any] = None)[source]

Create a profile from json dict data :param profile: Profile object to fill in :param data: Json dict data :param collection: if the collection is provided, it will be used to convert idtags into objects :return: None

VeraGridEngine.IO.veragrid.pack_unpack.handle_legacy_jsons(model_data: Dict[str, List], elements_dict_by_type: Dict[DeviceType, Dict], logger: Logger) None[source]

Handle those legacy structures that were deprecated and removed from VeraGrid’s structure :param model_data: :param elements_dict_by_type: :param logger: :return:

VeraGridEngine.IO.veragrid.pack_unpack.look_for_property(elm: Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement, property_name) GCProp | None[source]
Parameters:
  • elm

  • property_name

Returns:

VeraGridEngine.IO.veragrid.pack_unpack.look_in_collection_by_name(key: str, collection: Dict[str, Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement]) Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement | None[source]

Look in a collection for an element by its name instead of by Idtag :param key: name of the element :param collection: Collection to look into :return: Device or None if not found

VeraGridEngine.IO.veragrid.pack_unpack.order_multiverse_records(metadata: Dict[str, Dict[str | int | float]] | Dict[str, Any]) List[Dict[str, Any]][source]

Return multiverse metadata records in a parent-before-child order.

The multiverse payloads must be parsed in dependency order because child delta payloads may reference objects inherited from their parent composed scenario.

VeraGridEngine.IO.veragrid.pack_unpack.parse_multiverse_data(data: dict[str, VERAGRID_FILE_TYPE], metadata: Dict[str, Dict[str | int | float] | int | None], text_func: Union[Callable, None] = None, progress_func: Union[Callable, None] = None, logger: Logger = <VeraGridEngine.basic_structures.Logger object>) dev.MultiVerse[source]
Parameters:
  • data

  • metadata

  • text_func

  • progress_func

  • logger

Returns:

VeraGridEngine.IO.veragrid.pack_unpack.parse_object_type_from_dataframe(main_df: DataFrame, template_elm: Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement, elements_dict_by_type: Dict[DeviceType, Dict[str, Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement]], time_profile: DatetimeIndex, object_type_key: str, data: Dict[str, float | str | DataFrame], logger: Logger) Tuple[List[Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement], Dict[str, Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement], CreatedOnTheFly][source]

Convert a DataFrame to a list of VeraGrid devices :param main_df: DataFrame to convert :param template_elm: Element to use as template for conversion :param elements_dict_by_type: Dictionary of devices grouped by type used to look for referenced objects

elements_dict_by_type[DeviceType][idtag] -> device

Parameters:
  • time_profile – Master time profile

  • object_type_key – Object type naming to find the profile

  • data – Complete data collection to find the profiles

  • logger – Logger instance

Returns:

devices, devices_dict

VeraGridEngine.IO.veragrid.pack_unpack.parse_object_type_from_json(template_elm: Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement, data_list: List[Dict[str, Dict[str, str]]], elements_dict_by_type: Dict[DeviceType, Dict[str, Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement]], time_profile: DatetimeIndex, block_parser: BlockParser, logger: Logger)[source]
Parameters:
  • template_elm

  • data_list

  • elements_dict_by_type

  • time_profile

  • block_parser

  • logger

Returns:

VeraGridEngine.IO.veragrid.pack_unpack.parse_veragrid_data(data: ~typing.Dict[str, str | float | ~pandas.DataFrame | ~typing.Dict[str, ~typing.Any] | ~typing.List[~typing.Dict[str, ~typing.Any]]], previous_circuit: ~VeraGridEngine.Devices.multi_circuit.MultiCircuit | None = None, project_directory: str | ~pathlib.Path | None = None, refine_pointers: bool = True, text_func: ~typing.Callable | None = None, progress_func: ~typing.Callable | None = None, logger: ~VeraGridEngine.basic_structures.Logger = <VeraGridEngine.basic_structures.Logger object>) MultiCircuit[source]

Interpret data :param project_directory: file project directory :param refine_pointers: Refine (and possibly delete) the pointer objects such as investments and contingencies? :param data: dictionary of data frames and other information :param previous_circuit: Optional previous VeraGrid circuit. This is relevant in case of loading grid increments :param text_func: text callback function :param progress_func: progress callback function :param logger: Logger to register events :return: MultiCircuit instance

VeraGridEngine.IO.veragrid.pack_unpack.profile_todict(profile: ProfileFloat | ProfileInt | ProfileBool | ProfileDevice | ProfileEnum) Dict[str, str | bool][source]

Get a dictionary representation of the profile :return:

VeraGridEngine.IO.veragrid.pack_unpack.profile_todict_idtag(profile: ProfileFloat | ProfileInt | ProfileBool | ProfileDevice | ProfileEnum) Dict[str, str][source]

Get a dictionary representation of the profile :return:

VeraGridEngine.IO.veragrid.pack_unpack.profile_todict_str(profile: ProfileFloat | ProfileInt | ProfileBool | ProfileDevice | ProfileEnum) Dict[str, str][source]

Get a dictionary representation of the profile :return:

VeraGridEngine.IO.veragrid.pack_unpack.search_and_apply_json_profile(json_entry: Dict[str, Dict[str, str | Any | Dict[str, Any]]], gc_prop: GCProp, elm: Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement, property_value: Any, collection: None | Dict[str, Any] = None) None[source]

Search from the property profiles into the json and apply it :param json_entry: Json entry of an object :param gc_prop: GCProp :param elm: THe device to set the profile into :param property_value: The snapshot value :param collection: if the collection is provided, it will be used to convert idtags into objects :return: None

VeraGridEngine.IO.veragrid.pack_unpack.search_property(template_elm: Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement, old_props_dict: Dict[str, str], property_to_search: str, logger: Logger) GCProp | None[source]

Search for a property name in the template object registered properties and their old names :param template_elm: Device to loo into :param old_props_dict: Dictionary matching the old names with their current counterpart :param property_to_search: property name to search :param logger: Logger :return: GCProp or None if not found

VeraGridEngine.IO.veragrid.pack_unpack.search_property_into_json(json_entry: dict, prop: GCProp)[source]

Find property in Json entry :param json_entry: json of an object :param prop: GCProp :return: value or None if not found

VeraGridEngine.IO.veragrid.pack_unpack.valid_value(val) bool[source]
Parameters:

val

Returns:

VeraGridEngine.IO.veragrid.pack_unpack.veragrid_object_to_json(elm: Generator | Battery | Load | ExternalGrid | StaticGenerator | Shunt | ControllableShunt | CurrentInjection | Line | DcLine | Transformer2W | HvdcLine | VSC | UPFC | Winding | Switch | SeriesReactance | FluidNode | FluidPath | FluidP2x | FluidTurbine | FluidPump | Substation | Bus | BusBar | VoltageLevel | Country | Region | Community | Municipality | Area | Zone | Transformer3W | TransformerNW | OverheadLineType | Wire | TransformerType | EmissionGas | BranchGroup | LineLocations | LineLocation | ModellingAuthority | Facility | Fuel | Investment | InvestmentsGroup | Contingency | ContingencyGroup | RemedialAction | RemedialActionGroup | Technology | Owner | UndergroundLineType | SequenceLineType | RmsModelTemplate | EmtModelTemplate | FmuTemplate | RmsEvent | RmsEventsGroup | ShortCircuitEvent | IfMeasurement | ItMeasurement | QfMeasurement | PfMeasurement | QtMeasurement | PtMeasurement | QiMeasurement | PiMeasurement | VmMeasurement | VaMeasurement | PgMeasurement | QgMeasurement, block_saver: BlockSaver, project_directory: Path | None = None) Dict[str, str][source]
Parameters:
  • elm

  • block_saver

Returns:

VeraGridEngine.IO.veragrid.remote module

class VeraGridEngine.IO.veragrid.remote.RemoteInstruction(operation: None | SimulationTypes = None, data: None | Dict[str, Dict[str, str]] = None)[source]

Bases: object

Remote instruction class

get_data() Dict[str, str][source]
Returns:

parse_data(data: Dict[str, Dict[str, str]])[source]
Parameters:

data

Returns:

class VeraGridEngine.IO.veragrid.remote.RemoteJob(grid: None | MultiCircuit = None, instruction: None | RemoteInstruction = None, data: None | Dict[str, Any] = None)[source]

Bases: object

Remote job class

cancel()[source]
Returns:

get_data() dict[source]
Returns:

parse_data(data: Dict[str, Any])[source]
Parameters:

data

Returns:

VeraGridEngine.IO.veragrid.remote.gather_model_as_jsons_for_communication(circuit: MultiCircuit, instruction: RemoteInstruction) dict[str, str | float | int | dict[str, str] | dict[str, dict[str, dict[str, str] | list[dict[str, str]]] | dict[str, list[dict[str, Any]] | dict[int, dict[str, Any]] | list[int]]] | list[Any]][source]

Create a Json with the same information expected for loading with parse_veragrid_data :param circuit: MultiCircuit :param instruction: RemoteInstruction :return: JSON like data

VeraGridEngine.IO.veragrid.remote.get_certificate(base_url: str, certificate_path: str, pwd: str, logger: Logger = <VeraGridEngine.basic_structures.Logger object>) bool[source]

Try connecting to the server :return: ok?

VeraGridEngine.IO.veragrid.remote.get_certificate_path() str[source]

Get a path to the certificates :return:

VeraGridEngine.IO.veragrid.remote.run_job(grid: MultiCircuit, job: RemoteJob) AvailableTransferCapacityDriver | AvailableTransferCapacityTimeSeriesDriver | ContingencyAnalysisDriver | ContingencyAnalysisTimeSeriesDriver | ContinuationPowerFlowDriver | LinearAnalysisDriver | LinearAnalysisTimeSeriesDriver | OptimalPowerFlowDriver | OptimalPowerFlowTimeSeriesDriver | PowerFlowDriver | PowerFlowDriver3Ph | PowerFlowTimeSeriesDriver | StateEstimationDriver | ShortCircuitDriver | StochasticPowerFlowDriver | ClusteringDriver | CascadingDriver | SigmaAnalysisDriver | OptimalNetTransferCapacityDriver | OptimalNetTransferCapacityTimeSeriesDriver | NodeGroupsDriver | InputsAnalysisDriver | InvestmentsEvaluationDriver | CatalogueOptimizationDriver | NodalCapacityTimeSeriesDriver | ReliabilityStudyDriver | RmsSimulationDriver | SmallSignalStabilityRmsDriver | SmallSignalStabilityEmtDriver | EmtSimulationDriver | None[source]

Function to run a job, this is a simple function :param grid: MultiCircuit :param job: RemoteJob :return: DRIVER_OBJECTS or None

VeraGridEngine.IO.veragrid.remote.send_json_data(json_data: Dict[str, str | Dict[str, Dict[str, str]]], endpoint_url: str, certificate: str) Any[source]

Send a file along with instructions about the file :param json_data: Json with te model :param endpoint_url: Web socket URL to connect to :param certificate: SSL certificate path :return service response

VeraGridEngine.IO.veragrid.results_export module

VeraGridEngine.IO.veragrid.results_export.export_drivers(drivers_list: List[DRIVER_OBJECTS], file_name: str, text_func: Union[Callable[[str], None], None] = None, progress_func: Union[Callable[[float], None], None] = None, logger: Logger = <VeraGridEngine.basic_structures.Logger object>)[source]

Constructor :param drivers_list: list of VeraGrid simulation drivers :param file_name: name of the file where to save (.zip) :param text_func: text function :param progress_func: progress function :param logger: logging object

VeraGridEngine.IO.veragrid.results_export.export_results(results_list: List[RESULTS_OBJECTS], file_name: str, text_func: Union[Callable[[str], None], None] = None, progress_func: Union[Callable[[float], None], None] = None, logger: Logger = <VeraGridEngine.basic_structures.Logger object>)[source]

Constructor :param results_list: list of VeraGrid simulation results :param file_name: name of the file where to save (.zip) :param text_func: text function :param progress_func: progress function :param logger: logging object

VeraGridEngine.IO.veragrid.sqlite_interface module

VeraGridEngine.IO.veragrid.sqlite_interface.open_data_frames_from_sqlite(file_path, text_func=None, progress_func=None)[source]
VeraGridEngine.IO.veragrid.sqlite_interface.save_data_frames_to_sqlite(dfs, file_path, text_func=None, progress_func=None)[source]

Save the circuit information in excel format :param dfs: list of DataFrames :param file_path: path to the excel file :return: logger with information

VeraGridEngine.IO.veragrid.zip_interface module

VeraGridEngine.IO.veragrid.zip_interface.get_frames_from_zip(file_name_zip: str, text_func: None | ~typing.Callable[[str], None] = None, progress_func: None | ~typing.Callable[[float], None] = None, logger=<VeraGridEngine.basic_structures.Logger object>) Tuple[Dict[str, str | float | DataFrame | Dict[str, Any] | List[Dict[str, Any]]], Dict[str, Any], bool][source]

Open the csv files from a zip file :param file_name_zip: name of the zip file :param text_func: pointer to function that prints the names :param progress_func: pointer to function that prints the progress 0~100 :param logger: :return: list of DataFrames

VeraGridEngine.IO.veragrid.zip_interface.get_session_tree(file_name_zip: str)[source]

Get the sessions structure :param file_name_zip: :return:

VeraGridEngine.IO.veragrid.zip_interface.get_xml_content(file_ptr: ZipExtFile | BufferedReader) List[str][source]

Reads the content of a file :param file_ptr: File pointer (from file or zip file) :return: list of text lines

VeraGridEngine.IO.veragrid.zip_interface.get_xml_from_zip(file_name_zip: str, text_func: None | Callable[[str], None] = None, progress_func: None | Callable[[float], None] = None)[source]

Get the .xml files from a zip file :param file_name_zip: name of the zip file :param text_func: pointer to function that prints the names :param progress_func: pointer to function that prints the progress 0~100 :return: list of xml file contents

VeraGridEngine.IO.veragrid.zip_interface.load_json_from_file_pointer(file_pointer) dict[source]

Load JSON from a file pointer using orjson if available, falling back to json. :param file_pointer: File pointer (from zip file or regular file) :return: Parsed JSON as dict

VeraGridEngine.IO.veragrid.zip_interface.load_session_driver_objects(file_name_zip: str, session_name: str, study_name: str) Dict[str, None | DataFrame][source]

Get the sessions structure :param file_name_zip: :param session_name: :param study_name: :return: Dict[str, Union[None, pd.DataFrame]]

VeraGridEngine.IO.veragrid.zip_interface.read_data_frame_from_zip(file_pointer, extension: str, index_col=None, logger=<VeraGridEngine.basic_structures.Logger object>) None | DataFrame[source]

read DataFrame :param file_pointer: Pointer to the file within the zip file :param extension: Extension, just to determine the reader method :param index_col: Index col (only for config file) :param logger: :return: Data

VeraGridEngine.IO.veragrid.zip_interface.save_multiverse_data_to_zip(f_zip_ptr: ~zipfile.ZipFile, multiverse: ~VeraGridEngine.Devices.multiverse.MultiVerse, filename_zip: str, active_grid_idtag: str | None = None, active_sessions_data: ~typing.List[~VeraGridEngine.Simulations.driver_template.DriverToSave] | None = None, text_func: None | ~typing.Callable[[str], None] = None, progress_func: None | ~typing.Callable[[float], None] = None, logger=<VeraGridEngine.basic_structures.Logger object>) None[source]

Save only the multiverse-specific payload into an already opened VeraGrid archive.

VeraGridEngine.IO.veragrid.zip_interface.save_results_in_zip(f_zip_ptr: ZipFile, filename_zip: str, sessions_data: List[DriverToSave], folder: str, text_func: None | Callable[[str], None] = None, progress_func: None | Callable[[float], None] = None)[source]
Parameters:
  • f_zip_ptr

  • filename_zip

  • sessions_data

  • folder

  • text_func

  • progress_func

Returns:

VeraGridEngine.IO.veragrid.zip_interface.save_results_only(filename_zip: str, sessions_data: List[DriverToSave], text_func: None | Callable[[str], None] = None, progress_func: None | Callable[[float], None] = None)[source]

Save the results into a new file :param filename_zip: name of the zip file :param sessions_data: Sessions to save :param text_func: Text progress function :param progress_func: Numerical progress function

VeraGridEngine.IO.veragrid.zip_interface.save_single_circuit_data_to_zip(f_zip_ptr: ~zipfile.ZipFile, circuit: ~VeraGridEngine.Devices.multi_circuit.MultiCircuit, sessions_data: ~typing.List[~VeraGridEngine.Simulations.driver_template.DriverToSave], filename_zip: str, text_func: None | ~typing.Callable[[str], None] = None, progress_func: None | ~typing.Callable[[float], None] = None, logger=<VeraGridEngine.basic_structures.Logger object>) None[source]

Save the non-multiverse circuit payload into an already opened VeraGrid archive.

VeraGridEngine.IO.veragrid.zip_interface.save_veragrid_data_to_zip(filename_zip: str, circuit: ~VeraGridEngine.Devices.multi_circuit.MultiCircuit, sessions_data: ~typing.List[~VeraGridEngine.Simulations.driver_template.DriverToSave], json_files: ~typing.Dict[str, dict], text_func: None | ~typing.Callable[[str], None] = None, progress_func: None | ~typing.Callable[[float], None] = None, logger=<VeraGridEngine.basic_structures.Logger object>)[source]

Save a list of DataFrames to a zip file without saving to disk the csv files :param filename_zip: file name where to save all :param circuit: MultiCircuit object :param sessions_data: List of DriverToSave instances, representing the results drivers data :param json_files: List of configuration json files to save such as gui_config Dict[file_name, dictionary to save] :param text_func: pointer to function that prints the names :param progress_func: pointer to function that prints the progress 0~100 :param logger: Logger object

VeraGridEngine.IO.veragrid.zip_interface.save_veragrid_multiverse_data_to_zip(filename_zip: str, json_files: ~typing.Dict[str, dict], multiverse: ~VeraGridEngine.Devices.multiverse.MultiVerse, active_grid_idtag: str | None = None, active_sessions_data: ~typing.List[~VeraGridEngine.Simulations.driver_template.DriverToSave] | None = None, text_func: None | ~typing.Callable[[str], None] = None, progress_func: None | ~typing.Callable[[float], None] = None, logger=<VeraGridEngine.basic_structures.Logger object>)[source]

Save a list of DataFrames to a zip file without saving to disk the csv files :param filename_zip: file name where to save all :param json_files: List of configuration json files to save such as gui_config Dict[file_name, dictionary to save] :param multiverse: MultiVerse object :param text_func: pointer to function that prints the names :param progress_func: pointer to function that prints the progress 0~100 :param logger: Logger object

Module contents