Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pypsse/cli/explore.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path

import os
from loguru import logger
import pandas as pd
import click
Expand Down Expand Up @@ -107,6 +107,10 @@ def explore(project_path, simulations_file, export_file_path, load_filter, load,
}
results = x.sim.read_subsystems(quantities, buses)

# print(results.keys())
# print(results["LOAD_P"])
# quit()

had_comp_models = False
if "Loads_FmA" in results:
had_comp_models = True
Expand All @@ -129,7 +133,7 @@ def explore(project_path, simulations_file, export_file_path, load_filter, load,

is_comp_load[bus] = is_comp
load_dict[bus].append(ld_id)
key = f"{ld_id} _{bus}" if len(ld_id) == 1 else f"{ld_id}_{bus}"
key = f"{bus}_{ld_id}"
key2 = f"{bus}_{ld_id}".replace(" ", "")
load_p = max(
results["Loads_MVA"][key].real + results["Loads_IL"][key].real + results["Loads_YL"][key].real,
Expand All @@ -149,7 +153,7 @@ def explore(project_path, simulations_file, export_file_path, load_filter, load,
if bus not in generator_dict:
generator_dict[bus] = []
bus_gen[bus] = 0
key = f"{gen_id} _{bus}" if len(gen_id) == 1 else f"{gen_id}_{bus}"
key = f"{bus}_{gen_id}"
generator_dict[bus].append(gen_id)
bus_gen[bus] += results["Machines_MVA"][key]

Expand All @@ -168,7 +172,7 @@ def explore(project_path, simulations_file, export_file_path, load_filter, load,
results["is load comp"].append(is_comp_load[bus] if bus in is_comp_load else False)
results["total P load [MW]"].append(bus_load_real[bus] if bus in bus_load_real else 0)
results["total Q load [MVar]"].append(bus_load_imag[bus] if bus in bus_load_imag else 0)
results["has generation"].append(True if bus in generator_dict else False)
results["has generation"].append(True if (bus in generator_dict and bus_gen[bus] > 0)else False)
results["total generation [MVA]"].append(bus_gen[bus] if bus in bus_gen else 0)


Expand Down Expand Up @@ -200,7 +204,7 @@ def explore(project_path, simulations_file, export_file_path, load_filter, load,
results=results[(results["total P load [MW]"] >= load_lower) & (results["total P load [MW]"] <= load_upper)]
results=results[(results["total generation [MVA]"] >= gen_lower) & (results["total generation [MVA]"] <= gen_upper)]

print(results)
# print(results)
results.to_csv(export_file_path)
logger.info(f"Results exported to {export_file_path.absolute()}")

Expand Down
11 changes: 5 additions & 6 deletions pypsse/cli/profiles.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""
CLI to run a PyDSS project
"""
CLI to run a PyDSS project
"""

from pathlib import Path

from loguru import logger
import click
import toml

from pypsse.models import SimulationSettings
from pypsse.common import SIMULATION_SETTINGS_FILENAME
from pypsse.profile_manager_interface import ProfileManagerInterface

@click.argument(
"project-path",
)
Expand Down Expand Up @@ -41,4 +41,3 @@ def get_profiles(project_path, simulations_file=None):

profile_interface = ProfileManagerInterface.from_setting_files(file_path)
profile_interface.get_profiles()

7 changes: 6 additions & 1 deletion pypsse/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from loguru import logger
import click
import toml
import os

from pypsse.models import SimulationSettings
from pypsse.common import SIMULATION_SETTINGS_FILENAME
Expand Down Expand Up @@ -34,11 +35,15 @@ def run(project_path, simulations_file=None):

simulation_settiings = toml.load(file_path)
simulation_settiings = SimulationSettings(**simulation_settiings)

if simulation_settiings.log.clear_old_log_file:
log_path = Path(project_path) / "Logs" / "pypsse.log"
if os.path.exists(log_path):
os.remove(log_path)
logger.level(simulation_settiings.log.logging_level.value)
if simulation_settiings.log.log_to_external_file:
log_path = Path(project_path) / "Logs" / "pypsse.log"
logger.add(log_path)


x = Simulator.from_setting_files(file_path)

Expand Down
36 changes: 20 additions & 16 deletions pypsse/contingencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ def __init__(self, psse, settings, contingency_type):
self.psse = psse
self.enabled = False
self.tripped = False

logger.debug(
f"contingency_type : {contingency_type}"
)
logger.debug(
f"settings : {settings}"
)
# os.system("PAUSE")

def update(self, t: float):
"""updates a fault event

Expand All @@ -55,30 +62,27 @@ def update(self, t: float):
"""
self.t = t
if hasattr(self.settings, "duration"):
if (
self.settings.time + self.settings.duration
> t
>= self.settings.time
and not self.enabled
):
if (self.settings.time + self.settings.duration > t >= self.settings.time and not self.enabled):
self.enabled = True
self.enable_fault()
if (
t >= self.settings.time + self.settings.duration
and self.enabled
):
if (t >= self.settings.time + self.settings.duration and self.enabled):
self.enabled = False
self.disable_fault()
elif (
not hasattr(self.settings, "duration")
and t >= self.settings.time
and not self.tripped
):
elif (not hasattr(self.settings, "duration") and t >= self.settings.time and not self.tripped):
self.enable_fault()
self.tripped = True

def enable_fault(self):
"""enables a fault event"""
data_check = getattr(self.psse, self.fault_method)
logger.debug(
f"data_check : {data_check}"
)
logger.debug(
f"data_check : {self.fault_method}"
)
# os.system("PAUSE")

err = getattr(self.psse, self.fault_method)(**self.fault_settings)
if err:
logger.warning(
Expand Down
2 changes: 1 addition & 1 deletion pypsse/data_writers/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def write(
if self.step >= len(self.Timestamp):
self.Timestamp.resize((len(self.Timestamp) + 1,))
self.convergence.resize((len(self.convergence) + 1,))
self.Timestamp[self.step - 1] = np.string_(currenttime.strftime("%Y-%m-%d %H:%M:%S.%f"))
self.Timestamp[self.step - 1] = np.bytes_(currenttime.strftime("%Y-%m-%d %H:%M:%S.%f"))
self.convergence[self.step - 1] = convergence
# Add object status data to a DataFrame
self.store.flush()
Expand Down
10 changes: 9 additions & 1 deletion pypsse/enumerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ class SimulationModes(str, Enum):
STATIC = "Steady-state"
DYNAMIC = "Dynamic"

class GenerationLevel(str, Enum):
"Valid generation level setting modes"
TRANSMISSION = "transmission"
DISTRIBUTION = "distribution"

class HelicsCoreTypes(str, Enum):
"HELICS core types"
ZMQ = "zmq"
TCP_SS="tcp_ss"
TCP="tcp"


class WritableModelTypes(str, Enum):
Expand All @@ -40,7 +46,9 @@ class WritableModelTypes(str, Enum):
PLANT = "Plant"
MACHINE = "Machine"
GENERATOR = "Induction_machine"

LOAD_STATUS = "Load_status"
LINE_STATUS = "Line_status"
MACHINE_STATUS = "Machine_status"

class ModelTypes(str, Enum):
"Supported asset tpyes in PyPSSE"
Expand Down
Loading