Skip to content

Commit

Permalink
HostingCapacity: Added warnings to cases if buses don't match or no q…
Browse files Browse the repository at this point in the history
… is present.
  • Loading branch information
jenny-nyx committed Jan 30, 2025
1 parent 1947bff commit 948a822
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 14 deletions.
38 changes: 27 additions & 11 deletions omf/models/hostingCapacity.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,33 @@
<!--
We want the map to be displayed at the top, but it'll only display if model-based is there since its created there
-->
<p class="reportTitle" style="page-break-before:always">Hosting Capacity Map</p>
<div id="hostingCapacityMap" class="tightContent"></div>
<script>
var mapContent = allOutputData["hostingCapacityMap"]
var iframe = document.createElement('iframe');
iframe.style = 'width:1000px; height:800px; border-radius:8px;'
document.getElementById('hostingCapacityMap').appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(mapContent);
iframe.contentWindow.document.close();
</script>
{% if allOutputDataDict['modelFreeWarningFlag'] == True %}
<p class="reportTitle" style="page-break-before:always"><b>Model-Free Hosting Capacity Analysis Warning</b></p>
<div id="warningInformation" class="tightContent">
<p style="font-size: 20px; padding: 8px;"><span style="color: red; font-weight: bold;">WARNING: </span> {{ allOutputDataDict['modelFreeWarningInfo'] }} </p>
</div>
</p>
{% endif %}
{% if allOutputDataDict['mapWarningFlag'] == True %}
<p class="reportTitle" style="page-break-before:always"><b>Map Display Warning</b></p>
<div id="warningInformation" class="tightContent">
<p style="font-size: 20px; padding: 8px;"><span style="color: red; font-weight: bold;">WARNING: </span> {{ allOutputDataDict['mapWarningInfo'] }} </p>
</div>
</p>
{% endif %}
{% if allOutputDataDict['hideMap'] == False %}
<p class="reportTitle" style="page-break-before:always">Hosting Capacity Map</p>
<div id="hostingCapacityMap" class="tightContent"></div>
<script>
var mapContent = allOutputData["hostingCapacityMap"]
var iframe = document.createElement('iframe');
iframe.style = 'width:1000px; height:800px; border-radius:8px;'
document.getElementById('hostingCapacityMap').appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(mapContent);
iframe.contentWindow.document.close();
</script>
{% endif %}
{% if allInputDataDict['runAmiAlgorithm'] == 'on' %}
<p class="reportTitle">AMI-Based Hosting Capacity Runtime ( H:M:S:MS ) </p>
<div id="AMI_runtime" class="tightContent">
Expand Down
38 changes: 35 additions & 3 deletions omf/models/hostingCapacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,30 @@ def convert_seconds_to_hms_ms( seconds ):
seconds, milliseconds = divmod(remainder, 1000)
return "{:02d}:{:02d}:{:02d}.{:03d}".format(int(hours), int(minutes), int(seconds), int(milliseconds))

def sandia_algo_post_check(modelDir):
retVal = False
mohcaLog = [x for x in os.listdir(modelDir) if x.endswith('.log')][0]
try:
with open( Path(modelDir, mohcaLog), 'r', encoding="utf-8") as file:
for line in file:
splitLine = line.split(" - ")
if len(splitLine) > 3:
splitWords = splitLine[3].split(" ")
if splitWords[4].lower() == "q":
retVal = True
except FileNotFoundError as e:
print("HostingCapacity - ModelFree Sandia Algorithm - mohca_sandia.log file not found: ", {e})
return retVal


def hosting_capacity_map( modelDir, inputDict, outData ):
feederName = [x for x in os.listdir(modelDir) if x.endswith('.omd')][0]
path_to_omd = Path(modelDir, feederName)
starting_omd = json.load(open(path_to_omd))
starting_omd = json.load(open(path_to_omd))

# Starting there are no warnings
outData['mapWarningFlag'] = False
outData['hideMap'] = False

if inputDict['runAmiAlgorithm'] == 'on':
model_free_data = Path(modelDir, 'output_mohca.csv')
Expand All @@ -45,7 +65,7 @@ def hosting_capacity_map( modelDir, inputDict, outData ):
model_free_buses = model_free_data_df['busname'].unique()
# Finding the buses from mohca thats in the circuit. this is what we will color
model_free_buses_in_omd_file = list(set(model_free_buses).intersection(buses_from_omd_tree))
if model_free_buses_in_omd_file != 0:
if len(model_free_buses_in_omd_file) != 0:
# Great, there are some buses in the mohca file that are in the omd file. That means we can have some color!
# Note: If buses are in the omd and not in the Model-Free results, nothing is done.
# If buses are in the Model-Free results and not in the omd, nothing is done.
Expand All @@ -69,12 +89,16 @@ def hosting_capacity_map( modelDir, inputDict, outData ):
json.dump(starting_omd, out_file, indent=4)
omf.geo.map_omd(new_omd_path, modelDir, open_browser=False)
outData['hostingCapacityMap'] = open(Path(modelDir, "geoJson_offline.html"), 'r').read()
else:
# Warning there are no buses
outData['mapWarningFlag'] = True
outData['mapWarningInfo'] = f"There are no buses in the .csv file that was provided for the model-free algorithm that are present in the circuit file. Map display may be affected."

if inputDict['runModelBasedAlgorithm'] == 'on':
# This code is copied from what previously existed in run_model_based_algorithm
# Except now, we are gonna check if color.omd is created.
# If it is, then we just need to add the results to the already existing stuff
# If its not, that means we need to create the map fresh. This would also mean that model_free_flag is false.
# If its not, that means we need to create the map fresh.
colorPath = Path(modelDir, 'color.omd')
if colorPath.exists():
# Just add model-based coloring
Expand Down Expand Up @@ -146,6 +170,10 @@ def hosting_capacity_map( modelDir, inputDict, outData ):
omf.geo.map_omd(new_omd_path, modelDir, open_browser=False )
outData['hostingCapacityMap'] = open(Path(modelDir, "geoJson_offline.html"), 'r' ).read()

if outData["mapWarningFlag"] == True and inputDict['runModelBasedAlgorithm'] == 'off' and inputDict['runDownlineAlgorithm'] == 'off':
# If there are no buses in the .csv that match the circuit, and model based and downline load both are not running, we don't need the map
outData["hideMap"] = True

def run_downline_load_algorithm( modelDir, inputDict, outData ):
feederName = [x for x in os.listdir(modelDir) if x.endswith('.omd')][0]
path_to_omd = Path(modelDir, feederName)
Expand Down Expand Up @@ -219,6 +247,10 @@ def run_ami_algorithm( modelDir, inputDict, outData ):
else:
errorMessage = "DG Error - Should not happen. dgInverterSetting is not either of the 2 options it is supposed to be."
raise Exception(errorMessage)
present_q_warning = sandia_algo_post_check(modelDir=modelDir)
if present_q_warning == True:
outData["modelFreeWarningFlag"] = present_q_warning
outData["modelFreeWarningInfo"] = f"Reactive power missing from data set. Estimating hosting capacity through power factor from given input 'Load Power Factor'"
elif inputDict[ "algorithm" ] == "iastate":
mohca_cl.iastate( inputPath, outputPath )
else:
Expand Down
1 change: 1 addition & 0 deletions omf/solvers/mohca_cl/sandia.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def hosting_cap(

logger.info(f"HC calculated for: {n_hc_est}")
logger.info("Skipped: {n_skipped}")
logging.shutdown()

return hc_results

Expand Down

0 comments on commit 948a822

Please sign in to comment.