From f92238fbdc0c87f86d04a525c391d627a574a3fb Mon Sep 17 00:00:00 2001 From: jenny Date: Fri, 15 Mar 2024 00:50:58 -0400 Subject: [PATCH] Minor organizing to make code look better --- omf/models/hostingCapacity.py | 10 ++++++++-- omf/models/transformerPairing.py | 7 +++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/omf/models/hostingCapacity.py b/omf/models/hostingCapacity.py index 0af4a3258..90d364187 100644 --- a/omf/models/hostingCapacity.py +++ b/omf/models/hostingCapacity.py @@ -49,6 +49,7 @@ def createColorCSV(modelDir, df): def work(modelDir, inputDict): outData = {} + if inputDict['runAmiAlgorithm'] == 'on': run_ami_algorithm(modelDir, inputDict, outData) if inputDict.get('optionalCircuitFile', outData) == 'on': @@ -61,13 +62,16 @@ def run_ami_algorithm(modelDir, inputDict, outData): # mohca data-driven hosting capacity inputPath = Path(modelDir, inputDict['AMIDataFileName']) inputAsString = inputPath.read_text() + + outputPath = Path(modelDir, 'AMI_output.csv') + AMI_output = [] + try: csvValidateAndLoad(inputAsString, 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 OMF Wiki hostingCapacity" raise Exception(errorMessage) - outputPath = Path(modelDir, 'AMI_output.csv') - AMI_output = [] + AMI_start_time = time.time() if inputDict[ "algorithm" ] == "sandia1": AMI_output = mohca_cl.sandia1( inputPath, outputPath ) @@ -77,6 +81,7 @@ def run_ami_algorithm(modelDir, inputDict, outData): errorMessage = "Algorithm name error" raise Exception(errorMessage) AMI_end_time = time.time() + AMI_results = AMI_output[0].rename(columns={'kW_hostable': 'voltage_cap_kW'}) histogramFigure = px.histogram( AMI_results, x='voltage_cap_kW', template="simple_white", color_discrete_sequence=["MediumPurple"] ) histogramFigure.update_layout(bargap=0.5) @@ -84,6 +89,7 @@ def run_ami_algorithm(modelDir, inputDict, outData): min_value = 5 max_value = 8 AMI_results['thermal_cap_kW'] = np.random.randint(min_value, max_value + 1, size=len(AMI_results)) + AMI_results['max_cap_allowed_kW'] = np.minimum( AMI_results['voltage_cap_kW'], AMI_results['thermal_cap_kW']) barChartFigure = px.bar(AMI_results, x='busname', y=['voltage_cap_kW', 'thermal_cap_kW', 'max_cap_allowed_kW'], barmode='group', color_discrete_sequence=["green", "lightblue", "MediumPurple"], template="simple_white" ) barChartFigure.add_traces( list(px.line(AMI_results, x='busname', y='max_cap_allowed_kW', markers=True).select_traces()) ) diff --git a/omf/models/transformerPairing.py b/omf/models/transformerPairing.py index 9a3c6fc64..0b2a6a444 100644 --- a/omf/models/transformerPairing.py +++ b/omf/models/transformerPairing.py @@ -26,10 +26,11 @@ def work(modelDir, inputDict): outData = {} useTrueLabels = True - outData["useTrueLabels"] = useTrueLabels - + saveResultsPath = modelDir test_data_file_path = Path(omf.omfDir,'static','testFiles', 'transformerPairing') + outData["useTrueLabels"] = useTrueLabels + voltageInputPathCSV = Path( modelDir, inputDict['voltageDataFileName']) realPowerInputPathCSV = Path( modelDir, inputDict['realPowerDataFileName']) custIDInputPathCSV = Path( modelDir, inputDict['customerIDDataFileName']) @@ -44,8 +45,6 @@ def work(modelDir, inputDict): shutil.copyfile( Path( test_data_file_path, transformer_labels_true_file_name ), Path(modelDir, transformer_labels_true_file_name) ) transformerLabelsTruePath = Path(modelDir, transformer_labels_true_file_name) - saveResultsPath = modelDir - if inputDict['algorithm'] == 'reactivePower': sdsmc.MeterTransformerPairing.TransformerPairing.run( voltageInputPathCSV, realPowerInputPathCSV, reactivePowerInputPathCSV, custIDInputPathCSV, transformerLabelsErrorsPathCSV, transformerLabelsTruePath, saveResultsPath, useTrueLabels )