Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing poor implementation of phase integration for AMI #163

Merged
merged 12 commits into from
Feb 3, 2024
23 changes: 15 additions & 8 deletions converters/csv-ami2glm-player.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def string_clean(input_str):
network = False
ami_key = False

def write_player(file, obj, node_ID, phase) :
file.write('object player {\n')
file.write('\tparent "' + obj + '";\n')
file.write('\tfile "' + os.path.join(folder_name,str(node_ID)) + '.csv";\n')
file.write(f'\tproperty constant_power_{phase};\n')
file.write('}\n')

def convert(input_files, output_file, options={}):

if type(input_files) is dict:
Expand Down Expand Up @@ -98,22 +105,20 @@ def convert(input_files, output_file, options={}):
if os.path.splitext(output_file)[1]=='.csv' :
df.to_csv(os.path.join(folder_name,os.path.basename(output_file)), index=False)
elif os.path.splitext(output_file)[1]=='.glm' :
phase_dict = {}
with open(output_file, mode='w') as file :
file.write('module tape;\n')

for node_ID in node_ID_set :
if isinstance(node_ID, float) and math.isnan(node_ID) :
continue
file.write('object player {\n')
for obj,val in network["objects"].items() :
if "load" in val["class"] and node_ID in obj:
node_phase = val["phases"]
node_phase = val["phases"].replace("N", '').replace("S",'')
parent = val["parent"]
file.write('\tparent "' + str(parent) + '";\n')
file.write('\tfile "' + os.path.join(folder_name,str(node_ID)) + '.csv";\n')
file.write('\tphases "' + node_phase + '";\n')
file.write('}\n')

phase_dict[node_ID]=node_phase
for p in node_phase :
write_player(file, obj, node_ID, p)

new_column_names = {
'reading_dttm': 'timestamp',
Expand All @@ -123,12 +128,14 @@ def convert(input_files, output_file, options={}):
df_ami.rename(columns=new_column_names,inplace=True)
df_ami.drop(['interval_pcfc_date','interval_pcfc_hour'],axis=1,inplace=True)
df_ami.sort_index(inplace=True)

# Iterate over unique customer IDs
for customer_id in df_ami['customer_id'].unique():
# Create a new DataFrame for each customer ID
if isinstance(customer_id, float) and math.isnan(customer_id) :
continue
customer_df = df_ami[df_ami['customer_id'] == customer_id].drop(columns='customer_id')
customer_df = customer_df.sort_values(by='timestamp')
customer_df['power[kW]'] = customer_df['power[kW]']/len(phase_dict[customer_id])*1000
# Save the DataFrame to a CSV file
output_file = f"{folder_name}/{customer_id}.csv"
customer_df.to_csv(output_file, index=False, header=False)
Loading