Skip to content

Commit

Permalink
Modified hostingCap to use the Path library and new inputs for tradit…
Browse files Browse the repository at this point in the history
…ional HC
  • Loading branch information
jenny-nyx committed Dec 13, 2023
1 parent 062dcee commit b96dd01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
22 changes: 7 additions & 15 deletions omf/models/hostingCapacity.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
</div>
{% endif %}
<div class="wideInput">
<p class="inputSectionHeader">AMI-Based Hosting Capacity</p>
<p class="inputSectionHeader">AMI-Based or "MoHCa" Hosting Capacity</p>
</div>
<hr>
<div class="shortInput">
<label class="tooltip">Apply AMI-Based hosting capacity</label>
<label class="tooltip">Apply AMI-Based Hosting Capacity</label>
<select id="runAmiAlgorithm" name="runAmiAlgorithm" value="{{allInputDataDict.runAmiAlgorithm}}" required>
<option value="off" {% if allInputDataDict.runAmiAlgorithm == 'off' %}selected{% endif %}>Off</option>
<option value="on" {% if allInputDataDict.runAmiAlgorithm == 'on' %}selected{% endif %}>On</option>
Expand All @@ -62,11 +62,11 @@
</select>
</div>
<div class="wideInput">
<p class="inputSectionHeader">Traditional Hosting Capacity</p>
<p class="inputSectionHeader">Model-Based or "Traditional" Hosting Capacity</p>
</div>
<hr>
<div class="shortInput">
<label class="tooltip">Apply traditional hosting capacity</label>
<label class="tooltip">Apply Model-Based Hosting Capacity</label>
<select id="optionalCircuitFile" name="optionalCircuitFile" value="{{allInputDataDict.optionalCircuitFile}}" required>
<option value="off" {% if allInputDataDict.optionalCircuitFile == 'off' %}selected{% endif %}>Off</option>
<option value="on" {% if allInputDataDict.optionalCircuitFile == 'on' %}selected{% endif %}>On</option>
Expand All @@ -80,19 +80,11 @@
<input type="text" id="feederName1" name="feederName1" value="{{allInputDataDict.feederName1}}" style="display:none">
</div>
<div class="shortInput">
<label class="tooltip">Traditional Hosting Capacity Steps
<span class="classic">How many times the specified kW is added to determine max hosting capacity</span>
<label class="tooltip">Maximum kW Tested
<span class="classic">The maximum threshhold of KW added to determine max hosting capacity</span>
</label>
<input type="text" id="traditionalHCSteps" name="traditionalHCSteps" value="{{allInputDataDict.traditionalHCSteps}}" pattern="^[0-9]*$"/>
<input type="text" id="traditionalHCMaxTestkw" name="traditionalHCMaxTestkw" value="{{allInputDataDict.traditionalHCMaxTestkw}}" pattern="^[0-9]*$"/>
</div>

<div class="shortInput">
<label class="tooltip">Traditional Hosting Capacity kW
<span class="classic">How much kW is added to each step to determine hostingCapacity</span>
</label>
<input type="text" id="traditionalHCkW" name="traditionalHCkW" value="{{allInputDataDict.traditionalHCkW}}">
</div>
<input type="hidden" name="runAmiAlgorithm" value="{{allInputDataDict.runAmiAlgorithm}}"/>
{{ omfModelButtons }}
</form>
</div>
Expand Down
23 changes: 12 additions & 11 deletions omf/models/hostingCapacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def bar_chart_coloring( row ):

def createColorCSV(modelDir, df):
new_df = df[['bus','max_kw']]
new_df.to_csv(pJoin(modelDir, 'color_by.csv'), index=False)
new_df.to_csv(Path(modelDir, 'color_by.csv'), index=False)

def work(modelDir, inputDict):
outData = {}
Expand All @@ -48,15 +48,15 @@ def work(modelDir, inputDict):

def run_ami_algorithm(modelDir, inputDict, outData):
# mohca data-driven hosting capacity
with open(pJoin(modelDir,inputDict['inputDataFileName']),'w', newline='') as pv_stream:
with open(Path(modelDir,inputDict['inputDataFileName']),'w', newline='') as pv_stream:
pv_stream.write(inputDict['inputDataFileContent'])
inputPath = pJoin(modelDir, inputDict['inputDataFileName'])
inputPath = Path(modelDir, inputDict['inputDataFileName'])
try:
csvValidateAndLoad(inputDict['inputDataFileContent'], modelDir=modelDir, header=0, nrows=None, ncols=5, dtypes=[str, pd.to_datetime, float, float, float], return_type='df', ignore_nans=False, save_file=None, ignore_errors=False )
except:
errorMessage = "AMI-Data CSV file is incorrect format. Please see valid format definition at <a target='_blank' href='https://github.com/dpinney/omf/wiki/Models-~-hostingCapacity#meter-data-input-csv-file-format'>OMF Wiki hostingCapacity</a>"
raise Exception(errorMessage)
outputPath = pJoin(modelDir, 'mohcaOutput.csv')
outputPath = Path(modelDir, 'mohcaOutput.csv')
mohcaOutput = []
if inputDict[ "mohcaAlgorithm" ] == "sandia1":
mohcaOutput = mohca_cl.sandia1( inputPath, outputPath )
Expand All @@ -68,6 +68,7 @@ def run_ami_algorithm(modelDir, inputDict, outData):
mohcaResults = mohcaOutput[0].rename(columns={'kW_hostable': 'voltage_cap_kW'})
mohcaHistogramFigure = px.histogram( mohcaResults, x='voltage_cap_kW', template="simple_white", color_discrete_sequence=["MediumPurple"] )
mohcaHistogramFigure.update_layout(bargap=0.5)
# TBD - Needs to be modified when the MoHCA algorithm supports calculating thermal hosting capacity
mohcaResults['thermal_cap_kW'] = [7.23, 7.34, 7.45, 7.53, 7.24, 6.24, 7.424, 7.23 ]
mohcaResults['max_cap_allowed_kW'] = np.minimum( mohcaResults['voltage_cap_kW'], mohcaResults['thermal_cap_kW'])
mohcaBarChartFigure = px.bar(mohcaResults, x='busname', y=['voltage_cap_kW', 'thermal_cap_kW', 'max_cap_allowed_kW'], barmode='group', color_discrete_sequence=["green", "lightblue", "MediumPurple"], template="simple_white" )
Expand All @@ -81,11 +82,11 @@ def run_traditional_algorithm(modelDir, inputDict, outData):
# traditional hosting capacity if they uploaded an omd circuit file and chose to use it.
feederName = [x for x in os.listdir(modelDir) if x.endswith('.omd') and x[:-4] == inputDict['feederName1'] ][0]
inputDict['feederName1'] = feederName[:-4]
path_to_omd = pJoin(modelDir, feederName)
path_to_omd = Path(modelDir, feederName)
tree = opendss.dssConvert.omdToTree(path_to_omd)
opendss.dssConvert.treeToDss(tree, pJoin(modelDir, 'circuit.dss'))
opendss.dssConvert.treeToDss(tree, Path(modelDir, 'circuit.dss'))
curr_dir = os.getcwd()
traditionalHCResults = opendss.hosting_capacity_all(pJoin(modelDir, 'circuit.dss'), int(inputDict["traditionalHCMaxTestkw"]))
traditionalHCResults = opendss.hosting_capacity_all(Path(modelDir, 'circuit.dss'), int(inputDict["traditionalHCMaxTestkw"]))
# - opendss.hosting_capacity_all() changes the cwd, so change it back so other code isn't affected
os.chdir(curr_dir)
tradHCDF = pd.DataFrame(traditionalHCResults)
Expand Down Expand Up @@ -122,7 +123,7 @@ def run_traditional_algorithm(modelDir, inputDict, outData):
with open(new_path, 'w+') as out_file:
json.dump(omd, out_file, indent=4)
omf.geo.map_omd(new_path, modelDir, open_browser=False )
outData['traditionalHCMap'] = open(pJoin(modelDir, "geoJson_offline.html"), 'r' ).read()
outData['traditionalHCMap'] = open(Path(modelDir, "geoJson_offline.html"), 'r' ).read()
outData['traditionalGraphData'] = json.dumps(traditionalHCFigure, cls=py.utils.PlotlyJSONEncoder )
outData['traditionalHCTableHeadings'] = tradHCDF.columns.values.tolist()
outData['traditionalHCTableValues'] = (list(tradHCDF.itertuples(index=False, name=None)))
Expand All @@ -149,16 +150,16 @@ def new(modelDir):
creationCode = __neoMetaModel__.new(modelDir, defaultInputs)
try:
shutil.copyfile(
pJoin(__neoMetaModel__._omfDir, "static", "publicFeeders", defaultInputs["feederName1"]+'.omd'),
pJoin(modelDir, defaultInputs["feederName1"]+'.omd'))
Path(__neoMetaModel__._omfDir, "static", "publicFeeders", defaultInputs["feederName1"]+'.omd'),
Path(modelDir, defaultInputs["feederName1"]+'.omd'))
except:
return False
return creationCode

@neoMetaModel_test_setup
def _disabled_tests():
# Location
modelLoc = pJoin(__neoMetaModel__._omfDir,"data","Model","admin","Automated Testing of " + modelName)
modelLoc = Path(__neoMetaModel__._omfDir,"data","Model","admin","Automated Testing of " + modelName)
# Blow away old test results if necessary.
try:
shutil.rmtree(modelLoc)
Expand Down

0 comments on commit b96dd01

Please sign in to comment.