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

Event grid updates #366

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
7 changes: 6 additions & 1 deletion modules/Workflow/rWHALE.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ def main( # noqa: C901, D103

# now for each asset, do regional mapping
for asset_type, assetIt in asset_files.items(): # noqa: N806
WF.perform_regional_mapping(assetIt, asset_type)
if not isinstance(WF.shared_data['RegionalEvent']['eventFile'], list):
WF.shared_data['RegionalEvent']['eventFile'] = [
WF.shared_data['RegionalEvent']['eventFile']
]
for event_grid in WF.shared_data['RegionalEvent']['eventFile']:
WF.perform_regional_mapping(assetIt, asset_type, event_grid)

if parallelType == 'parSETUP':
return
Expand Down
4 changes: 2 additions & 2 deletions modules/Workflow/whale/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ def perform_regional_recovery(self, asset_keys): # noqa: ARG002
)
log_div()

def perform_regional_mapping(self, AIM_file_path, assetType, doParallel=True): # noqa: FBT002, N803
def perform_regional_mapping(self, AIM_file_path, assetType, event_grid, doParallel=True): # noqa: FBT002, N803
"""Performs the regional mapping between the asset and a hazard event.

Parameters
Expand All @@ -1787,7 +1787,7 @@ def perform_regional_mapping(self, AIM_file_path, assetType, doParallel=True):
'id': 'filenameEVENTgrid',
'type': 'path',
'default': resolve_path(
self.shared_data['RegionalEvent']['eventFile'],
event_grid,
self.reference_dir,
),
}
Expand Down
132 changes: 131 additions & 1 deletion modules/createEVENT/SimCenterEvent/SimCenterEvent.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,138 @@ def write_RV(AIM_file, EVENT_file): # noqa: N802, N803, D103
# get the location of the event input files
# TODO: assuming a single event for now # noqa: TD002
aim_event_input = aim_file['Events'][0]
data_dir = Path(aim_event_input['EventFolderPath'])

if 'SimCenterEvent' in aim_event_input:
simcenter_event = aim_event_input['SimCenterEvent']
data_dir = Path(simcenter_event['EventFolderPath'])

event_file = {'randomVariables': [], 'Events': []}
# the event should be sampled during hazard to asset mapping, so not random
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: not -> no

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected

# variables are needed
event_file['Events'].append({
"data_dir": str(data_dir),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using 'dataDir' instead of 'data_dir' in the event_file to be consistent with our camelCase convention in JSON files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also consider making dataDir optional since it is only needed for timeHistory events

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to dataDir.

I think in the future, by default, the format should support both IM and timHistory. As a result, by default, the dataDir should be needed. I intended to avoid too many "if" conditions when different types of event formats are used.

"unitScaleFactor": f_scale_units,
'units': input_unit_bases,
})

################Below are for future multiple event_type use############
# # Get the number of realizations
# if 'intensityMeasure' in simcenter_event:
# num_of_realizations = len(simcenter_event['intensityMeasure']['Events'][0])
# if 'timeHistory' in simcenter_event:
# if num_of_realizations != len(simcenter_event['timeHistory']['Events'][0]):
# msg = 'Number of realizations in intensityMeasure and timeHistory do not match'
# raise ValueError(msg)
# elif 'timeHistory' in simcenter_event:
# num_of_realizations = len(simcenter_event['timeHistory']['Events'][0])
# else:
# msg = 'No intensityMeasure or timeHistory in SimCenterEvent'
# raise ValueError(msg)

# # currently assume only intensityMeasure or timeHistory
# if 'intensityMeasure' in simcenter_event:
# event_type = 'intensityMeasure'
# elif 'timeHistory' in simcenter_event:
# event_type = 'timeHistory'
# else:
# msg = 'No intensityMeasure or timeHistory in SimCenterEvent'
# raise ValueError(msg)

# if num_of_realizations > 1:
# # if there is more than one event then we need random variables

# # initialize the randomVariables part of the EVENT file
# if event_type == 'intensityMeasure':
# event_file['randomVariables'].append(
# {
# 'distribution': 'discrete_design_set_string',
# 'name': 'eventID',
# 'value': 'RV.eventID',
# 'elements': ['event_' + str(i) for i in range(num_of_realizations)],
# }
# )

# # initialize the Events part of the EVENT file
# event_file['Events'].append(
# {
# 'type': event_type,
# 'event_id': 'RV.eventID',
# 'unitScaleFactor': f_scale_units,
# 'units': input_unit_bases,
# 'values': simcenter_event[event_type]['Events'],
# 'labels': simcenter_event[event_type]['Labels'],
# }
# )
# elif event_type == 'timeHistory':
# event_file['randomVariables'].append(
# {
# 'distribution': 'discrete_design_set_string',
# 'name': 'eventID',
# 'value': 'RV.eventID',
# 'elements': [],
# }
# )

# # initialize the Events part of the EVENT file
# event_file['Events'].append(
# {
# # 'type': 'Seismic', I am pretty sure we are not using this now
# # or we are using it incorrectly, so I removed it for the time being
# # and replaced it with the information that is actually used
# 'type': aim_event_input['type'],
# 'event_id': 'RV.eventID',
# 'unitScaleFactor': f_scale_units,
# 'units': input_unit_bases,
# 'data_dir': str(data_dir),
# }
# )

# # collect the filenames
# RV_elements = simcenter_event[event_type]['Events'][0] # noqa: N806
# # for event in events:
# # #if event['EventClassification'] in ['Earthquake', 'Hurricane',
# # # 'Flood']:
# # #RV_elements.append(event['fileName'])
# # RV_elements.append(event[0])

# # and add them to the list of randomVariables
# event_file['randomVariables'][0]['elements'] = RV_elements

# # if time histories are used, then load the first event
# # TODO: this is needed by some other code that should be fixed and this # noqa: TD002
# # part should be removed.
# event_file['Events'][0].update({'scale_factors': simcenter_event[event_type]['ScaleFactors']})
# event_file['Events'][0].update(
# load_record(simcenter_event[event_type]['Events'][0][0], data_dir, empty=num_of_realizations > 1)
# )
# # , event_class = event_class))

# else:
# # if there is only one event, then we do not need random variables

# # initialize the Events part of the EVENT file
# # The events are now two dimensiontal list. The first dimension is sequence of events
# # The second dimension is different grid in the same event

# event_file['Events'].append(
# {
# # 'type': 'Seismic',
# 'type': event_type,
# 'event_id': simcenter_event[event_type]['Events'][0][0],
# 'unitScaleFactor': f_scale_units,
# 'units': input_unit_bases,
# 'data_dir': str(data_dir),
# }
# )
########################################################################

# save the EVENT dictionary to a json file
with open(EVENT_file, 'w', encoding='utf-8') as f: # noqa: PTH123
json.dump(event_file, f, indent=2)

return
# Below are for backward compatibility
data_dir = Path(aim_event_input['EventFolderPath'])
# get the list of events assigned to this asset
events = aim_event_input['Events']

Expand Down
Loading
Loading