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

Changes for E16 to be ran on DesignSafe Part1 #355

Merged
merged 6 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions modules/Workflow/WorkflowApplications.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
"Name": "INP_FILE",
"ExecutablePath": "applications/createAIM/INP_FILE/INP_FILE.py",
"ApplicationSpecificInputs": [
{
"id": "assetSourceFile",
"type": "path",
"description": "path to asset database file"
},
{
"id": "assetFile",
"type": "path",
Expand Down Expand Up @@ -1255,6 +1260,32 @@
}
]
},
"SystemPerformanceApplications":{
"API": {
"Inputs": [
],
"Outputs": [
]
},
"Applications": [
{
"Name": "REWETRecovery",
"ExecutablePath": "applications/systemPerformance/REWET/REWET_Wrapper.py",
"ApplicationSpecificInputs": [
{
"id": "assetSourceFile",
"type": "path",
"description": "path to asset database file"
},
{
"id": "inputDir",
"type": "path",
"description": "path to input directory"
}
]
}
]
},
"PerformanceApplications": {
"API": {
"Inputs": [],
Expand Down
24 changes: 14 additions & 10 deletions modules/createAIM/INP_FILE/INP_FILE.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparse # noqa: D100, INP001
import argparse # noqa: INP001, D100
import importlib
import json
import os
Expand All @@ -8,8 +8,7 @@
import warnings

import geopandas as gpd

# import momepy
import momepy
import numpy as np
import pandas as pd
import shapely
Expand Down Expand Up @@ -180,10 +179,10 @@ def defineConnectivities( # noqa: N802, D102
# Convert find connectivity and add start_node, end_node attributes
edges = self.gdf
datacrs = edges.crs
graph = momepy.gdf_to_nx(edges.to_crs('epsg:6500'), approach='primal') # noqa: F821
graph = momepy.gdf_to_nx(edges.to_crs('epsg:6500'), approach='primal')
with warnings.catch_warnings(): # Suppress the warning of disconnected components in the graph
warnings.simplefilter('ignore')
nodes, edges, sw = momepy.nx_to_gdf( # noqa: F821
nodes, edges, sw = momepy.nx_to_gdf(
graph, points=True, lines=True, spatial_weights=True
)
# edges = edges.set_index('ind')
Expand Down Expand Up @@ -241,9 +240,9 @@ def defineConnectivities( # noqa: N802, D102
self.gdf = edges


def split_and_select_components(input_config): # noqa: C901, D103
def split_and_select_components(input_config, asset_source_file): # noqa: C901, D103
component_dict = dict() # noqa: C408
asset_source_file = input_config['assetSourceFile']
# asset_source_file = input_config['assetSourceFile']
with open(asset_source_file, encoding='utf-8') as f: # noqa: PTH123
source_data = json.load(f)
crs = source_data['crs']
Expand Down Expand Up @@ -304,7 +303,7 @@ def init_workdir(component_dict, outDir): # noqa: N803, D103
return component_dir


def create_asset_files(output_file, asset_type, input_file, doParallel): # noqa: C901, N803, D103
def create_asset_files(output_file, asset_source_file, asset_type, input_file, doParallel): # noqa: C901, N803, D103
# check if running parallel
numP = 1 # noqa: N806
procID = 0 # noqa: N806
Expand Down Expand Up @@ -334,7 +333,7 @@ def create_asset_files(output_file, asset_type, input_file, doParallel): # noqa
]
# if input_config.get("Roadway", None):
# roadSegLength = float(input_config['Roadway'].get('maxRoadLength_m', "100000"))
component_dict = split_and_select_components(input_config)
component_dict = split_and_select_components(input_config, asset_source_file)
component_dir = init_workdir(component_dict, outDir) # noqa: F841
assets_array = []
for component_type, component_data in component_dict.items():
Expand Down Expand Up @@ -400,6 +399,7 @@ def create_asset_files(output_file, asset_type, input_file, doParallel): # noqa
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--assetFile')
parser.add_argument('--assetSourceFile')
parser.add_argument('--assetType')
parser.add_argument('--inputJsonFile')
parser.add_argument('--doParallel', default='False')
Expand All @@ -411,7 +411,11 @@ def create_asset_files(output_file, asset_type, input_file, doParallel): # noqa
if args.getRV:
sys.exit(
create_asset_files(
args.assetFile, args.assetType, args.inputJsonFile, args.doParallel
args.assetFile,
args.assetSourceFile,
args.assetType,
args.inputJsonFile,
args.doParallel
)
)
else:
Expand Down
45 changes: 33 additions & 12 deletions modules/systemPerformance/REWET/REWET_Wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def get_dl_file_name(run_dir, dl_file_path, scn_number):
return file_path, file_dir


def set_settings_data(input_json, rewet_input_data):
def set_settings_data(input_json, rewet_input_data, input_dir):
"""
Set REWET-style input settings data.

Expand All @@ -192,6 +192,9 @@ def set_settings_data(input_json, rewet_input_data):
rewet_input_data : TYPE
DESCRIPTION.

input_dir: Path
Input directory path.

Returns
-------
None.
Expand All @@ -200,11 +203,11 @@ def set_settings_data(input_json, rewet_input_data):
policy_file_name = input_json['SystemPerformance']['WaterDistributionNetwork'][
'Policy Definition'
]
policy_file_path = input_json['SystemPerformance']['WaterDistributionNetwork'][
'Policy DefinitionPath'
]
#policy_file_path = input_json['SystemPerformance']['WaterDistributionNetwork'][
#'Policy DefinitionPath'
#]

policy_config_file = Path(policy_file_path) / Path(policy_file_name)
policy_config_file = Path(input_dir) / Path(policy_file_name)

rewet_input_data['settings']['RUN_TIME'] = input_json['SystemPerformance'][
'WaterDistributionNetwork'
Expand Down Expand Up @@ -453,8 +456,24 @@ def create_path(path):
help='if specified, uses all CPUS. 2 or more CPUs are not available, it will revert back to serial run.',
)

arg_parser.add_argument(
'--assetSourceFile',
help='Asset GeoJSOn File Path.',
)

arg_parser.add_argument(
'--inputDir',
help='Input Directory Path.',
)

parser_data = arg_parser.parse_args()

sc_geojson = parser_data.assetSourceFile
sc_geojson = Path(sc_geojson)

input_dir = parser_data.inputDir
input_dir = Path(input_dir)

# Setting parallel or serial settings

proc_size = 1
Expand Down Expand Up @@ -489,7 +508,7 @@ def create_path(path):
rewet_input_data['settings'] = {}

rwhale_input_data = preprocessorIO.read_json_file(parser_data.input)
set_settings_data(rwhale_input_data, rewet_input_data)
set_settings_data(rwhale_input_data, rewet_input_data, input_dir)
event_time = rwhale_input_data['SystemPerformance']['WaterDistributionNetwork'][
'eventTime'
]
Expand All @@ -498,12 +517,14 @@ def create_path(path):
water_asset_data = rwhale_input_data['Applications']['Assets'][
'WaterDistributionNetwork'
]
inp_file_addr = water_asset_data['ApplicationData']['inpFile']
if '{Current_Dir}' in inp_file_addr:
inp_file_addr = inp_file_addr.replace('{Current_Dir}', '.')
sc_geojson = rwhale_input_data['Applications']['Assets'][
'WaterDistributionNetwork'
]['ApplicationData']['assetSourceFile']
inp_file_name = water_asset_data['ApplicationData']['inpFile']
inp_file_addr = input_dir / inp_file_name

#if '{Current_Dir}' in inp_file_addr:
#inp_file_addr = inp_file_addr.replace('{Current_Dir}', '.')
#sc_geojson = rwhale_input_data['Applications']['Assets'][
#'WaterDistributionNetwork'
#]['ApplicationData']['assetSourceFile']

run_dir = cur_dir
number_of_realization = rwhale_input_data['Applications']['DL'][
Expand Down
2 changes: 1 addition & 1 deletion modules/systemPerformance/REWET/preprocessorIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def read_json_file(file_addr):
"""
file_addr = Path(file_addr).resolve()
if not file_addr.exists():
raise ValueError('INPUT WHALE FILE is not found.', file_addr) # noqa: EM101, TRY003
raise ValueError('INPUT FILE is not found.', file_addr) # noqa: EM101, TRY003

with file_addr.open('rt') as f:
data = json.load(f)
Expand Down
Loading