Skip to content

upload_scenario

NexusePlugin

NexusePlugin(parameters: dict, scenario: Scenario)

Bases: Plugin

Source code in src/plugins/upload_scenario/nexus_e_plugin.py
def __init__(self, parameters: dict, scenario: Scenario):
    self.settings = Config(**parameters)
    self.__data_context = scenario.get_data_context()
    if self.__data_context.type != "mysql":
        raise ValueError("upload_scenario only works with a MySQL database")

settings instance-attribute

settings = Config(**parameters)

get_default_parameters classmethod

get_default_parameters() -> dict
Source code in src/plugins/upload_scenario/nexus_e_plugin.py
@classmethod
def get_default_parameters(cls) -> dict:
    return asdict(Config())

run

run() -> dict[str, Any]
Source code in src/plugins/upload_scenario/nexus_e_plugin.py
def run(self) -> dict[str, Any]:
    output = {}
    # Load the data
    self.data_loader = DataLoader(
        excel_file_path=self.settings.excel_file_path
    )
    logging.info(f"Using Excel file: {self.settings.excel_file_path}")
    logging.info("Load data from Excel file...")
    inputDB = self.data_loader.load_data()
    logging.info("Done")

    # add TYNDP24 data if include_tyndp24 is True
    if self.settings.include_tyndp24:
        self.data_merger = DataMerger(
            inputDB_excel=inputDB,
            tyndp24_data_path=self.settings.tyndp24_data_path,
            tyndp24_policy=self.settings.tyndp24_policy,
            tyndp24_climate_year=self.settings.tyndp24_climate_year,
            include_branch_sheet=self.settings.include_branch_sheet,
            preset_line_types=self.settings.preset_line_types,
            new_line_types=self.settings.new_line_types,
            update_only_specific_columns=self.settings.update_only_specific_columns,
            columns_to_update=self.settings.columns_to_update,
            ntc_type=self.settings.ntc_type,
            tyndp24_scope=self.settings.tyndp24_scope
        )
        logging.info(f"Using TYNDP24 data from {self.settings.tyndp24_data_path}")
        logging.info("Inject TYNDP24 data...")
        inputDB = self.data_merger.upsert_tyndp24_data()
        logging.info("Done")

    # create excel file if create_excel is True
    if self.settings.create_excel:
        logging.info(f"Using Excel file: {self.settings.excel_file_target_path}")
        logging.info("Create Excel file...")
        self.__create_excel(self.settings.excel_file_target_path, inputDB)
        logging.info("Done")

    # prepare data
    schema_version = self.settings.dump_file_path.strip(".sql").split("_")[-1]
    version_number = float(schema_version.replace("v", ""))
    self.data_preparer = DataPreparer(
        inputDB=inputDB,
        excel_file_path=self.settings.excel_file_path,
        database_author=self.settings.database_author,
        use_new_line_types=self.settings.use_new_line_types,
        demand_profiles_path=self.settings.demand_profiles_path,
        include_flex_params=self.settings.include_flex_params,
        schema_version=version_number,
        config_years_int=self.settings.config_years_int,
        config_years=self.settings.config_years
    )
    logging.info("Prepare data for MySQL...")
    inputDB = self.data_preparer.prepare_data()
    logging.info("Done")

    # load data to MySQL
    self.my_sql_connector = MysqlConnector(
        push_to_mysql=self.settings.push_to_mysql,
        inputDB=inputDB,
        host=self.__data_context.host,
        user=self.__data_context.user,
        password=self.__data_context.password,
        database_name=self.settings.database_name,
        dump_file_path=self.settings.dump_file_path,
        include_flex_params=self.settings.include_flex_params
    )
    logging.info(f"Using MySQL database: {self.settings.database_name}")
    logging.info("Push data to database...")
    self.my_sql_connector.push_DB_to_mysql()
    logging.info("Done")
    output["data_context"] = {"name": self.settings.database_name}
    return output

Config dataclass

Config(
    excel_file_path: str = "src/plugins/data/source_excel/input.xlsx",
    push_to_mysql: bool = True,
    database_name: str = "project_date_version",
    database_author: str = "FirstName LastName",
    dump_file_path: str = "src/plugins/upload_scenario/schemas/Dump_STRUC_clean_v9.sql",
    include_flex_params: bool = False,
    demand_profiles_path: str = "src/data/source_excel/Nexuse_DB-Input_v47_TYNDP22-GA08_CentIvPV_base_DemandProfiles",
    include_tyndp24: bool = False,
    tyndp24_data_path: str = "src/data/TYNDP24_datasets/TYNDP24_nbc",
    tyndp24_scope: Literal["nbc", "EU"] = "nbc",
    tyndp24_policy: str = "DE",
    tyndp24_climate_year: int = 2009,
    ntc_type: str | NtcType = "modelResults",
    use_new_line_types: bool = True,
    preset_line_types: bool = True,
    new_line_types: str = "NTC",
    config_years: list[str] = (
        lambda: ["2018", "2020", "2030", "2040", "2050"]
    )(),
    config_years_int: list[int] = (lambda: [2018, 2020, 2030, 2040, 2050])(),
    create_excel: bool = False,
    excel_file_target_path: str = "output.xlsx",
    include_branch_sheet: bool = True,
    update_only_specific_columns: bool = False,
    columns_to_update: dict[str, list[str]] = (
        lambda: {"branch": ["line_id", "start_year", "S_max_win (MVA)"]}
    )(),
)

columns_to_update class-attribute instance-attribute

columns_to_update: dict[str, list[str]] = field(
    default_factory=lambda: {
        "branch": ["line_id", "start_year", "S_max_win (MVA)"]
    }
)

config_years class-attribute instance-attribute

config_years: list[str] = field(
    default_factory=lambda: ["2018", "2020", "2030", "2040", "2050"]
)

config_years_int class-attribute instance-attribute

config_years_int: list[int] = field(
    default_factory=lambda: [2018, 2020, 2030, 2040, 2050]
)

create_excel class-attribute instance-attribute

create_excel: bool = False

database_author class-attribute instance-attribute

database_author: str = 'FirstName LastName'

database_name class-attribute instance-attribute

database_name: str = 'project_date_version'

demand_profiles_path class-attribute instance-attribute

demand_profiles_path: str = "src/data/source_excel/Nexuse_DB-Input_v47_TYNDP22-GA08_CentIvPV_base_DemandProfiles"

dump_file_path class-attribute instance-attribute

dump_file_path: str = (
    "src/plugins/upload_scenario/schemas/Dump_STRUC_clean_v9.sql"
)

excel_file_path class-attribute instance-attribute

excel_file_path: str = 'src/plugins/data/source_excel/input.xlsx'

excel_file_target_path class-attribute instance-attribute

excel_file_target_path: str = 'output.xlsx'

include_branch_sheet class-attribute instance-attribute

include_branch_sheet: bool = True

include_flex_params class-attribute instance-attribute

include_flex_params: bool = False

include_tyndp24 class-attribute instance-attribute

include_tyndp24: bool = False

new_line_types class-attribute instance-attribute

new_line_types: str = 'NTC'

ntc_type class-attribute instance-attribute

ntc_type: str | NtcType = 'modelResults'

preset_line_types class-attribute instance-attribute

preset_line_types: bool = True

push_to_mysql class-attribute instance-attribute

push_to_mysql: bool = True

tyndp24_climate_year class-attribute instance-attribute

tyndp24_climate_year: int = 2009

tyndp24_data_path class-attribute instance-attribute

tyndp24_data_path: str = 'src/data/TYNDP24_datasets/TYNDP24_nbc'

tyndp24_policy class-attribute instance-attribute

tyndp24_policy: str = 'DE'

tyndp24_scope class-attribute instance-attribute

tyndp24_scope: Literal['nbc', 'EU'] = 'nbc'

update_only_specific_columns class-attribute instance-attribute

update_only_specific_columns: bool = False

use_new_line_types class-attribute instance-attribute

use_new_line_types: bool = True

NtcType

Bases: Enum

ref_grid: NTCs are based on the reference grid, fixed values, do not change for 2040 and 2050 (no upgrades)

Expansion1: NTCs are based on the reference grid + real investment candidates

Expansion2: NTCs are based on the reference grid + real investment candidates + concept investment candidates

modelResults: NTCs are based on the modelling results from TYNDP24 (depend on scenario)

Expansion1 class-attribute instance-attribute

Expansion1 = 'Expansion1'

Expansion2 class-attribute instance-attribute

Expansion2 = 'Expansion2'

modelResults class-attribute instance-attribute

modelResults = 'modelResults'

ref_grid class-attribute instance-attribute

ref_grid = 'ref_grid'