Skip to content

Commit

Permalink
updated scenario generation package to allow for multiple sizes of DE…
Browse files Browse the repository at this point in the history
…Rs with probabilities
  • Loading branch information
EC2 Default User committed Sep 24, 2023
1 parent 88425d1 commit 8837b14
Show file tree
Hide file tree
Showing 22 changed files with 337 additions and 254 deletions.
8 changes: 4 additions & 4 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@
heading_level: 4


### <p style="color:teal;border-bottom:1px solid teal;width:max-content;">emerge.scenarios.pv_scenario </p>
### <p style="color:teal;border-bottom:1px solid teal;width:max-content;">emerge.scenarios.scenario </p>

::: emerge.scenarios.pv_scenario
::: emerge.scenarios.scenario
options:
show_source: true
heading_level: 4

### <p style="color:teal;border-bottom:1px solid teal;width:max-content;">emerge.scenarios.strategy </p>
### <p style="color:teal;border-bottom:1px solid teal;width:max-content;">emerge.scenarios.sizing_strategy </p>

::: emerge.scenarios.strategy
::: emerge.scenarios.sizing_strategy
options:
show_source: true
heading_level: 4
Expand Down
4 changes: 3 additions & 1 deletion emerge/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
compute_multiscenario_time_series_metrics,
)
from emerge.cli.custom_metrics import compute_custom_metrics
from emerge.cli.schema_generator import create_schemas


@click.command()
Expand Down Expand Up @@ -193,4 +194,5 @@ def cli():
cli.add_command(create_geojsons)
cli.add_command(generate_pv_scenarios_for_feeder)
cli.add_command(compute_multiscenario_time_series_metrics)
cli.add_command(compute_custom_metrics)
cli.add_command(compute_custom_metrics)
cli.add_command(create_schemas)
33 changes: 0 additions & 33 deletions emerge/cli/interface.py

This file was deleted.

44 changes: 0 additions & 44 deletions emerge/cli/pv_scenario_config.json

This file was deleted.

18 changes: 9 additions & 9 deletions emerge/cli/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@
import click
import json

import pydantic

from emerge.scenarios import (
data_model,
scenario,
sizing_strategy,
selection_strategy,
opendss_writer,
)
from emerge.utils import dss_util
from emerge.simulator import opendss
from emerge.cli.interface import PVSceanarioCliInputModel


@click.command()
Expand All @@ -35,8 +30,9 @@ def generate_pv_scenarios_for_feeder(config, customer_type):
# pylint: disable=no-member
with open(config, "r", encoding="utf-8") as file:
config_dict = json.load(file)
config_data = pydantic.parse_obj_as(
PVSceanarioCliInputModel, config_dict)

config_data = data_model.DERScenarioConfigModel.model_validate(
config_dict)

for der_scen in config_data.der_scenario:

Expand All @@ -45,12 +41,16 @@ def generate_pv_scenarios_for_feeder(config, customer_type):
mapper_object = dss_util.get_load_mapper_objects(simulator.dss_instance)

derscenarios = scenario.create_der_scenarios(
list_of_customers, config_data.basic_config,
list_of_customers,
data_model.ScenarioBaseConfig(
**config_data.model_dump(include=['pct_resolution',
'num_of_penetration', 'max_num_of_samples'])
),
der_config=der_scen
)
writer_object = opendss_writer.OpenDSSPVScenarioWriter(
derscenarios, config_data.output_folder
)
writer_object.write(mapper_object,
file_name=der_scen.file_name, tag_name=der_scen.tag_name
file_name=der_scen.file_name
)
88 changes: 88 additions & 0 deletions emerge/cli/schema_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
""" This module implements commad line interface for exporting
schemas and handling opt in vscode update."""

# standard imports
from pathlib import Path
from typing import List

# third-party imports
import click
from pydantic import BaseModel
import pydantic

# internal imports
from emerge.scenarios import data_model
from emerge.utils import util

class SchemaItemModel(BaseModel):
name: str
model: pydantic._internal._model_construction.ModelMetaclass

class Config:
arbitrary_types_allowed=True

class SchemaManager:
def __init__(self, schema_folder: str =".vscode"):
self.schema_folder = Path(schema_folder)
self.schemas: List[SchemaItemModel] = []

def add_schema(self, name: str, model: BaseModel):
self.schemas.append(SchemaItemModel(name=name, model=model))

def generate_and_save_schemas(self):

if not self.schema_folder.exists():
self.schema_folder.mkdir()

for schema in self.schemas:
json_schema = schema.model.model_json_schema()
schema_file = self.schema_folder / f"{schema.name}.json"
util.write_file(json_schema, schema_file)

def configure_vscode_settings(self):
vscode_settings_file = self.schema_folder / "settings.json"

if not vscode_settings_file.exists():
util.write_file({}, vscode_settings_file)

settings = util.read_file(vscode_settings_file, use_json5=True)
vscode_key = "json.schemas"

if vscode_key not in settings:
settings[vscode_key] = []

for schema in self.schemas:
updated_in_place = False
schema_file = self.schema_folder / f"{schema.name}.json"

for item in settings[vscode_key]:
if schema.name in item.get("url", ''):
item["url"] = str(schema_file)
updated_in_place = True

if not updated_in_place:
settings[vscode_key].append({
"fileMatch": ["*.json"],
"url": str(vscode_settings_file)
})

util.write_file(settings, vscode_settings_file)

@click.command()
@click.option(
"-vc",
"--vscode",
default=False,
show_default=True,
help="""Update JSON schemas in vscode settings. Note will create .vscode folder
if not present in the current directory."""
)
def create_schemas(vscode: bool):
""" Function to handle the JSON schemas for emerge package."""

schema_manager = SchemaManager()
schema_manager.add_schema("emerge_scenario_schema",
data_model.DERScenarioConfigModel)
schema_manager.generate_and_save_schemas()
if vscode:
schema_manager.configure_vscode_settings()
5 changes: 0 additions & 5 deletions emerge/metrics/compute_snapshot_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,3 @@ def compute_snapshot_metrics(
"label": "peak_load",
"data": xfmr_loading_df.to_dict()['loading(pu)']})

if __name__ == '__main__':

compute_snapshot_metrics(
r'C:\Users\KDUWADI\Desktop\NREL_Projects\ciff_track_2\exports\opendss_new\master.dss'
)
9 changes: 5 additions & 4 deletions emerge/metrics/data_model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
""" Module for managing pydantic data models."""

from pydantic import BaseModel, confloat
from pydantic import Field, BaseModel
from typing_extensions import Annotated


class ThermalLoadingLimit(BaseModel):
""" Model representing thermal loading limit. """

threshold: confloat(ge = 0.0, le=2.0) = 1.0
threshold: Annotated[float, Field(ge = 0.0, le=2.0)] = 1.0

class VoltageViolationLimit(BaseModel):
""" Model representing voltage violation limit. """

overvoltage_threshold: confloat(ge = 1.01, le=2.0) = 1.05
undervoltage_threshold: confloat(ge = 0, le=1.0) = 0.95
overvoltage_threshold: Annotated[float, Field(ge = 1.01, le=2.0)] = 1.05
undervoltage_threshold: Annotated[float, Field(ge = 0, le=1.0)] = 0.95
1 change: 0 additions & 1 deletion emerge/metrics/feeder_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# internal imports
from emerge.utils.util import validate_path, write_file
from emerge.simulator.opendss import OpenDSSSimulator

def create_feeder_geojson(
dss_instance,
Expand Down
65 changes: 30 additions & 35 deletions emerge/metrics/feeder_metrics_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,51 @@
Extract base level metrics
"""
# standard imports
from enum import Enum
from typing import Optional, Union

# third-party imports
from pydantic import (
BaseModel,
validator,
conint,
confloat,
)
Field, BaseModel)
from typing_extensions import Annotated

class LoadAssetMetrics(BaseModel):
total_count: conint(ge=0) = 0
max_kw_capacity: confloat(ge=0.0) = 0.0
min_kw_capacity: confloat(ge=0.0) = 0.0
min_kvar_capacity: confloat(ge=0.0) = 0.0
max_kvar_capacity: confloat(ge=0.0) = 0.0
total_kw_capacity: confloat(ge=0.0) = 0.0
total_kvar_capacity: confloat(ge=0.0) = 0.0
total_count: Annotated[int, Field(ge=0)] = 0
max_kw_capacity: Annotated[float, Field(ge=0.0)] = 0.0
min_kw_capacity: Annotated[float, Field(ge=0.0)] = 0.0
min_kvar_capacity: Annotated[float, Field(ge=0.0)] = 0.0
max_kvar_capacity: Annotated[float, Field(ge=0.0)] = 0.0
total_kw_capacity: Annotated[float, Field(ge=0.0)] = 0.0
total_kvar_capacity: Annotated[float, Field(ge=0.0)] = 0.0

class PVAssetMetrics(BaseModel):
total_count: conint(ge=0) = 0
max_kw_capacity: confloat(ge=0.0) = 0.0
min_kw_capacity: confloat(ge=0.0) = 0.0
total_kw_capacity: confloat(ge=0.0) = 0.0
total_count: Annotated[int, Field(ge=0)] = 0
max_kw_capacity: Annotated[float, Field(ge=0.0)] = 0.0
min_kw_capacity: Annotated[float, Field(ge=0.0)] = 0.0
total_kw_capacity: Annotated[float, Field(ge=0.0)] = 0.0

class CapacitorAssetMetrics(BaseModel):
total_count: conint(ge=0) = 0
max_kvar_capacity: confloat(ge=0.0) = 0.0
min_kvar_capacity: confloat(ge=0.0) = 0.0
total_kvar_capacity: confloat(ge=0.0) = 0.0
total_count: Annotated[int, Field(ge=0)] = 0
max_kvar_capacity: Annotated[float, Field(ge=0.0)] = 0.0
min_kvar_capacity: Annotated[float, Field(ge=0.0)] = 0.0
total_kvar_capacity: Annotated[float, Field(ge=0.0)] = 0.0

class RegulatorsAssetMetrics(BaseModel):
total_count: conint(ge=0) = 0
total_count: Annotated[int, Field(ge=0)] = 0

class TransformersAssetMetrics(BaseModel):
total_count: conint(ge=0) = 0
max_kva_capacity: confloat(ge=0.0) = 0.0
min_kva_capacity: confloat(ge=0.0) = 0.0
total_kva_capacity: confloat(ge=0.0) = 0.0
total_count: Annotated[int, Field(ge=0)] = 0
max_kva_capacity: Annotated[float, Field(ge=0.0)] = 0.0
min_kva_capacity: Annotated[float, Field(ge=0.0)] = 0.0
total_kva_capacity: Annotated[float, Field(ge=0.0)] = 0.0

class FeederMetrics(BaseModel):
total_feeder_length_km: confloat(ge=0.0) = 0.0
max_primary_feeder_length_km: confloat(ge=0.0) = 0.0
max_secondary_feeder_length_km: confloat(ge=0.0) = 0.0
min_secondary_feeder_length_km: confloat(ge=0.0) = 0.0
primary_kv_level: confloat(ge=0.0) = 0.0
secondary_kv_level: confloat(ge=0.0) = 0.0
total_buses: conint(ge=0) = 0
total_line_sections: conint(ge=0) = 0
total_feeder_length_km: Annotated[float, Field(ge=0.0)] = 0.0
max_primary_feeder_length_km: Annotated[float, Field(ge=0.0)] = 0.0
max_secondary_feeder_length_km: Annotated[float, Field(ge=0.0)] = 0.0
min_secondary_feeder_length_km: Annotated[float, Field(ge=0.0)] = 0.0
primary_kv_level: Annotated[float, Field(ge=0.0)] = 0.0
secondary_kv_level: Annotated[float, Field(ge=0.0)] = 0.0
total_buses: Annotated[int, Field(ge=0)] = 0
total_line_sections: Annotated[int, Field(ge=0)] = 0


class AssetMetrics(BaseModel):
Expand Down
Loading

0 comments on commit 8837b14

Please sign in to comment.