Skip to content

Commit

Permalink
Merge pull request #345 from jinyan1214/barbaros_transport
Browse files Browse the repository at this point in the history
Add residual demand simulation and some ruff check
  • Loading branch information
fmckenna authored Oct 30, 2024
2 parents 7d5a330 + 11ba5ef commit e4dcc51
Show file tree
Hide file tree
Showing 35 changed files with 6,850 additions and 1,083 deletions.
430 changes: 222 additions & 208 deletions modules/Workflow/WorkflowApplications.json

Large diffs are not rendered by default.

51 changes: 30 additions & 21 deletions modules/Workflow/whale/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def create_command(command_list, enforced_python=None):
return command # noqa: DOC201, RUF100


def run_command(command, app_category=""): # noqa: C901
def run_command(command, app_category=''):
"""Short description
Long description
Expand Down Expand Up @@ -380,27 +380,26 @@ def run_command(command, app_category=""): # noqa: C901
#

try:

if (platform.system() == 'Windows') and ('python.exe' in str(command)):
if returncode != 0:
raise WorkFlowInputError('Analysis Failed at ' + app_category) # noqa: TRY301
# if (platform.system() == 'Windows') and ('python.exe' in str(command)):
if returncode != 0:
raise WorkFlowInputError('Analysis Failed at ' + app_category) # noqa: TRY301

# sy - safe apps should be added below
elif ('OpenSeesInput' in str(command)):
elif 'OpenSeesInput' in str(command): # noqa: RET506
if returncode != 0:
raise WorkFlowInputError('Analysis Failed at ' + app_category) # noqa: TRY301

return str(result), returncode

except WorkFlowInputError as e:
# this will catch the error
print(str(e).replace('\'','')) # noqa: T201
print(" =====================================") # noqa: T201
print(str(e).replace("'", '')) # noqa: T201
print(' =====================================') # noqa: T201
print(str(result)) # noqa: T201
sys.exit(-20)

except: # noqa: E722
# if for whatever reason the function inside "try" failes, move on without checking error
# if for whatever reason the function inside "try" fails, move on without checking error
return str(result), 0

return result, returncode
Expand Down Expand Up @@ -1307,7 +1306,7 @@ def create_asset_files(self):
prepend_blank_space=False,
)

result, returncode = run_command(command,"Asset Creater")
result, returncode = run_command(command, 'Asset Creater')

# Check if the command was completed successfully
if returncode != 0:
Expand Down Expand Up @@ -1546,7 +1545,15 @@ def perform_system_performance_assessment(self, asset_type):

# Check if system performance is requested
if 'SystemPerformance' in self.workflow_apps:
performance_app = self.workflow_apps['SystemPerformance'][asset_type]
if asset_type in self.workflow_apps['SystemPerformance']:
performance_app = self.workflow_apps['SystemPerformance'][asset_type]
else:
log_msg(
f'No Performance application to run for asset type: {asset_type}.',
prepend_timestamp=False,
)
log_div()
return False
else:
log_msg(
f'No Performance application to run for asset type: {asset_type}.',
Expand Down Expand Up @@ -1597,7 +1604,7 @@ def perform_system_performance_assessment(self, asset_type):
prepend_blank_space=False,
)

result, returncode = run_command(command,"Performance Assessment")
result, returncode = run_command(command, 'Performance Assessment')
log_msg(
f'\n{result}\n',
prepend_timestamp=False,
Expand Down Expand Up @@ -1661,7 +1668,7 @@ def perform_regional_event(self):
prepend_blank_space=False,
)

result, returncode = run_command(command,"Hazard Event")
result, returncode = run_command(command, 'Hazard Event')

log_msg('Output: ', prepend_timestamp=False, prepend_blank_space=False)
log_msg(
Expand Down Expand Up @@ -1724,7 +1731,7 @@ def perform_regional_recovery(self, asset_keys): # noqa: ARG002
prepend_blank_space=False,
)

result, returncode = run_command(command, "Recovery")
result, returncode = run_command(command, 'Recovery')

log_msg('Output: ', prepend_timestamp=False, prepend_blank_space=False)
log_msg(
Expand Down Expand Up @@ -1807,7 +1814,7 @@ def perform_regional_mapping(self, AIM_file_path, assetType, doParallel=True):
)

else:
result, returncode = run_command(command,"Hazard-Asset Mapping (HTA)")
result, returncode = run_command(command, 'Hazard-Asset Mapping (HTA)')

log_msg(
'Output: ' + str(returncode),
Expand Down Expand Up @@ -2047,7 +2054,9 @@ def preprocess_inputs( # noqa: C901
prepend_blank_space=False,
)

result, returncode = run_command(command,f'{app_type} - at the initial setup (getRV)')
result, returncode = run_command(
command, f'{app_type} - at the initial setup (getRV)'
)

log_msg(
'Output: ' + str(returncode),
Expand Down Expand Up @@ -2457,7 +2466,7 @@ def simulate_response(self, AIM_file_path='AIM.json', asst_id=None): # noqa: C9
prepend_blank_space=False,
)

result, returncode = run_command(command, "Response Simulator")
result, returncode = run_command(command, 'Response Simulator')

if self.run_type in ['run', 'runningLocal']:
log_msg(
Expand Down Expand Up @@ -2534,7 +2543,7 @@ def perform_asset_performance(asset_type): # noqa: N805, D102
app_path=self.app_dir_local # noqa: F821
)
command = create_command(app_command_list)
result, returncode = run_command(command,"Performance assessment")
result, returncode = run_command(command, 'Performance assessment')

def estimate_losses( # noqa: C901
self,
Expand Down Expand Up @@ -2627,7 +2636,7 @@ def estimate_losses( # noqa: C901
prepend_blank_space=False,
)

result, returncode = run_command(command,"Damage and loss")
result, returncode = run_command(command, 'Damage and loss')

log_msg(result, prepend_timestamp=False)

Expand Down Expand Up @@ -2678,7 +2687,7 @@ def estimate_losses( # noqa: C901
prepend_blank_space=False,
)

result, returncode = run_command(command,"Damage and loss")
result, returncode = run_command(command, 'Damage and loss')

log_msg(result, prepend_timestamp=False)

Expand Down Expand Up @@ -2821,7 +2830,7 @@ def estimate_performance( # noqa: D102
prepend_blank_space=False,
)

result, returncode = run_command(command,"Performance Assessment")
result, returncode = run_command(command, 'Performance Assessment')

log_msg(result, prepend_timestamp=False)

Expand Down
3 changes: 2 additions & 1 deletion modules/createEDP/surrogateEDP/surrogateEDP.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import argparse
import json

errPath = os.path.join(os.getcwd(),'workflow.err') # noqa: N816
errPath = os.path.join(os.getcwd(), 'workflow.err') # noqa: N816, PTH109, PTH118


def write_RV(AIM_input_path, EDP_input_path, EDP_type): # noqa: ARG001, N802, N803, D103
# load the AIM file
Expand Down
Loading

0 comments on commit e4dcc51

Please sign in to comment.