Converters

There are 4 types of converters present as of now. Here, we shall discuss their basic structure and guidelines for building a custom converter.

Use the examples notebooks to understand how to convert data from the respective formats.

Refer to converters in API documentation for more details

Structure

The VisonExcelConverter extends the tabular converters for Excel exports of Vision. All converters are derived from the base power_grid_model_io.converters.base_converter. The usable functions for loading, saving and converting the data are located in the base class. The private functions (_load_data, _parse_data and _serialize_data) are overloaded based on the specific type of converter (ie. excel, json or pandapower). It is recommended to create any custom converter in a similar way.

Instantiation

A converter object can be instantiated in the following way. For eg, for a PgmJsonConverter,

from power_grid_model_io.converters.pgm_json_converter import PgmJsonConverter

converter = PgmJsonConverter(source_file=source, destination_file=destination)

The usable methods of converters for loading and saving the data are described below.

Loading data

Use the methods load_input_data(), load_update_data(), load_sym_output_data() or load_asym_output_data() to load the relevant data to the converter. The Converter can be initialised with source_file containing path to source data. Or alternatively, the data can be provided as an argument to the load function.

In addition to the power-grid-model input data, other miscellaneous information in the source file not used in calculations by power-grid-model gets stored under extra_info

input_data, extra_info = converter.load_input_data(data=example_data)

Saving Data

It is possible to save the data in the format of the converter. The Converter can be instantiated with a path given to destination_file. Alternatively, the destination path can be provided in the save function. You can also add additional information about each component in the form of extra_info generated by Load data to be saved along with it.

converter.save(example_data, extra_info=example_extra_info, destination=destination_path)

Configuring The Log Output

We have provided an interface to configure the log level of the converter. Notice that this log level only belongs to the logger within the converter. Users need to set their basic configuration of the logging module to a level that is below what is configuired for the converters.

# Examplary usage in your script
import logging
from power_grid_model_io.converters import VisionExcelConverter
 
logging.basicConfig(level=logging.INFO) # Only levels INFO and above will be logged
 
converter_warning = VisionExcelConverter(input_file, log_level=logging.WARNING) # If there is any logs above WARNING, they will be logged
converter_info = VisionExcelConverter(input_file) # Uses default INFO level

logging.basicConfig(level=logging.WARNING) # Only levels WARNING and above will be logged
assert converter_info.get_log_level() == logging.INFO # Previously created converters will retain their original log level, regardless of system wide configuration 

converter_debug = VisionExcelConverter(input_file, log_level=logging.DEBUG) # Any logs on DEBUG and INFO level will not be logged