Skip to content

Commit

Permalink
add branch, bus, and gen key layers
Browse files Browse the repository at this point in the history
  • Loading branch information
jaelynlitz committed Nov 8, 2023
1 parent 98f0d5b commit 119ddb7
Showing 1 changed file with 130 additions and 1 deletion.
131 changes: 130 additions & 1 deletion docs/devcontainer/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,136 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'nbus': [9.0], 'ngen': [3.0], 'nbranch': [9.0], 'baseMVA': [100.0], 'Bus': {'Bus': [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], 'Pd': [0.0, 0.0, 0.0, 0.0, 75.0, 90.0, 0.0, 100.0, 0.0], 'Qd': [0.0, 0.0, 0.0, 0.0, 50.0, 30.0, 0.0, 35.0, 0.0], 'Vm': [1.04, 1.02, 1.02, 1.03, 1.01, 1.02, 1.03, 1.02, 1.03], 'Va': [0.0, 4.54, 2.9, -2.19, -3.38, -4.26, 0.75, -1.72, 0.21], 'mult_Pmis': [2064.25, 2013.83, 2018.37, 2064.55, 2076.02, 2093.63, 2014.5, 2035.99, 2018.82], 'mult_Qmis': [0.0, -0.0, -0.0, 0.78, 11.05, 5.44, 3.54, 7.25, 2.49]}, 'Branch': {'From': [1.0, 2.0, 3.0, 4.0, 4.0, 5.0, 6.0, 7.0, 8.0], 'To': [4.0, 7.0, 9.0, 5.0, 6.0, 7.0, 9.0, 8.0, 9.0], 'Status': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], 'Sft': [73.27, 111.43, 86.05, 32.2, 42.77, 49.98, 50.0, 63.9, 42.3], 'Stf': [72.63, 111.84, 86.79, 43.0, 44.87, 48.69, 51.77, 64.98, 36.62], 'Slim': [380.0, 250.0, 300.0, 250.0, 250.0, 250.0, 150.0, 250.0, 150.0], 'mult_Sf': [-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0], 'mult_St': [-0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0]}, 'Gen': {'Gen bus': [1.0, 2.0, 3.0], 'Status': [1.0, 1.0, 1.0], 'Fuel': ['NG', 'NG', 'WIND'], 'Pg': [71.1, 111.4, 85.0], 'Qg': [17.7, -2.61, -13.42], 'Pmin': [10.0, 10.0, 0.0], 'Pmax': [350.0, 300.0, 85.0], 'Qmin': [-300.0, -300.0, -300.0], 'Qmax': [300.0, 300.0, 300.0]}}\n",
"data converted from ./tmp.output to ./data.json\n"
]
}
],
"source": [
"import csv \n",
"import json\n",
"import time\n",
"import numbers\n",
"\n",
"def opflow_csv_to_json(csvFilePath, jsonFilePath):\n",
" jsonArray = []\n",
"\n",
" #count the number of lines in the csv file\n",
" lines = 0\n",
" with open(csvFilePath, encoding='utf-8') as csvf: \n",
" lines = sum(1 for _ in csvf)\n",
" csvf.close()\n",
"\n",
" #read csv file\n",
" with open(csvFilePath, encoding='utf-8') as csvf: \n",
" #load csv file data using csv library's reader\n",
" csvReader = csv.reader(csvf) \n",
"\n",
" current_row = 0\n",
" temp = {}\n",
" keys = True\n",
" row = next(csvReader)\n",
" current_row += 1\n",
"\n",
" for key in row:\n",
" temp[key] = []\n",
" current_keys = row\n",
" #check if there's another row\n",
" if current_row < lines:\n",
" row = next(csvReader)\n",
" current_row += 1\n",
"\n",
" #add values to corresponding keys\n",
" for x in range(0, len(current_keys)):\n",
" temp[current_keys[x]].append(float(row[x]))\n",
"\n",
" #check if there's another row\n",
" if current_row < lines:\n",
" row = next(csvReader)\n",
" current_row += 1\n",
" temp[\"Bus\"] = {}\n",
" for key in row:\n",
" temp[\"Bus\"][key] = []\n",
" current_keys = row\n",
" \n",
" for k in range(0, 9): #rows under the Bus category \n",
" #check if there's another row\n",
" if current_row < lines:\n",
" row = next(csvReader)\n",
" current_row += 1\n",
" #add values to corresponding keys\n",
" for x in range(0, len(current_keys)):\n",
" temp[\"Bus\"][current_keys[x]].append(float(row[x])) \n",
"\n",
" #check if there's another row\n",
" if current_row < lines:\n",
" row = next(csvReader)\n",
" current_row += 1\n",
" temp[\"Branch\"] = {}\n",
" for key in row:\n",
" temp[\"Branch\"][key] = []\n",
" current_keys = row\n",
" \n",
" for k in range(0, 9): #rows under the Branch category \n",
" #check if there's another row\n",
" if current_row < lines:\n",
" row = next(csvReader)\n",
" current_row += 1\n",
" #add values to corresponding keys\n",
" for x in range(0, len(current_keys)):\n",
" temp[\"Branch\"][current_keys[x]].append(float(row[x])) \n",
" \n",
" #check if there's another row\n",
" if current_row < lines:\n",
" row = next(csvReader)\n",
" current_row += 1\n",
" \n",
" temp[\"Gen\"] = {}\n",
" for key in row:\n",
" temp[\"Gen\"][key] = []\n",
" current_keys = row\n",
" \n",
" for k in range(0, 3): #rows under the Gen category \n",
" #check if there's another row\n",
" if current_row < lines:\n",
" row = next(csvReader)\n",
" current_row += 1\n",
" #add values to corresponding keys\n",
" for x in range(0, len(current_keys)):\n",
" for j in range(0, len(row)):\n",
" if j != 2:\n",
" row[j] = float(row[j])\n",
" else:\n",
" row[j] = row[2].strip()\n",
" temp[\"Gen\"][current_keys[x]].append(row[x]) \n",
"\n",
" print(temp)\n",
" jsonArray = temp\n",
" #convert python jsonArray to JSON String and write to file\n",
" with open(jsonFilePath, 'w', encoding='utf-8') as jsonf: \n",
" jsonString = json.dumps(jsonArray, indent=4)\n",
" jsonf.write(jsonString)\n",
" return\n",
"\n",
"#if cell 2 is run, then ./ is the top level of the ExaGO dir\n",
"csvFilePath = r'./tmp.output'\n",
"jsonFilePath = r'./data.json'\n",
"\n",
"opflow_csv_to_json(csvFilePath, jsonFilePath)\n",
"\n",
"print(f\"data converted from {csvFilePath} to {jsonFilePath}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down

0 comments on commit 119ddb7

Please sign in to comment.