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

SG: Move logic from R2D frontend into backend #317

Merged
merged 2 commits into from
Sep 30, 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
29 changes: 28 additions & 1 deletion modules/Workflow/WorkflowApplications.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,23 @@
},
{
"Name": "UserInputShakeMap",
"ExecutablePath": null,
"ExecutablePath": "applications/createEVENT/shakeMapEvent/shakeMapEvent.py",
"ApplicationSpecificInputs": [
{
"id": "Directory",
"type": "path",
"description": "Path to file containing folder of shake maps"
},
{
"id": "EventPath",
"type": "string",
"description": "Path to the shake map event"
},
{
"id": "IntensityMeasureType",
"type": "list",
"description": "List of intensity measures"
}
]
},
{
Expand Down Expand Up @@ -360,6 +375,18 @@
{
"Name": "SiteSpecifiedEvents",
"ExecutablePath": "applications/performRegionalMapping/SiteSpecifiedEvents/SSE.py",
"RunsParallel": true,
"ApplicationSpecificInputs": [
{
"id": "filenameEVENTgrid",
"type": "path",
"description": "Path to file containing location information on each event file"
}
]
},
{
"Name": "GISSpecifiedEvents",
"ExecutablePath": "applications/performRegionalMapping/GISSpecifiedEvents/GISSpecifiedEvent.py",
"RunsParallel": true,
"ApplicationSpecificInputs": [
{
Expand Down
67 changes: 33 additions & 34 deletions modules/createEVENT/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
add_subdirectory(common)
add_subdirectory(CFDEvent)
add_subdirectory(GeoClawOpenFOAM)
add_subdirectory(DEDM_HRP)
add_subdirectory(hazardBasedEvent)
add_subdirectory(multiplePEER)
add_subdirectory(multipleSimCenter)
add_subdirectory(siteResponse)
add_subdirectory(windTunnelExperiment)
add_subdirectory(LowRiseTPU)
add_subdirectory(HighRiseTPU)
add_subdirectory(pointWindSpeed)
add_subdirectory(LLNL_SW4)
add_subdirectory(SimCenterEvent)
add_subdirectory(ASCE7_WindSpeed)
add_subdirectory(stochasticGroundMotion)
add_subdirectory(stochasticWind)
add_subdirectory(groundMotionIM)
add_subdirectory(uniformPEER)
add_subdirectory(experimentalWindForces)
add_subdirectory(experimentalWindPressures)
add_subdirectory(EmptyDomainCFD)
add_subdirectory(IsolatedBuildingCFD)
add_subdirectory(SurroundedBuildingCFD)
add_subdirectory(coupledDigitalTwin)
add_subdirectory(physicsBasedMotion)
add_subdirectory(M9)
add_subdirectory(Istanbul)
add_subdirectory(MPM)
add_subdirectory(stochasticWave)
add_subdirectory(TaichiEvent)
add_subdirectory(CelerisTaichiEvent)


add_subdirectory(common)
add_subdirectory(CFDEvent)
add_subdirectory(GeoClawOpenFOAM)
add_subdirectory(DEDM_HRP)
add_subdirectory(hazardBasedEvent)
add_subdirectory(multiplePEER)
add_subdirectory(multipleSimCenter)
add_subdirectory(siteResponse)
add_subdirectory(windTunnelExperiment)
add_subdirectory(LowRiseTPU)
add_subdirectory(HighRiseTPU)
add_subdirectory(pointWindSpeed)
add_subdirectory(LLNL_SW4)
add_subdirectory(SimCenterEvent)
add_subdirectory(ASCE7_WindSpeed)
add_subdirectory(stochasticGroundMotion)
add_subdirectory(stochasticWind)
add_subdirectory(groundMotionIM)
add_subdirectory(uniformPEER)
add_subdirectory(experimentalWindForces)
add_subdirectory(experimentalWindPressures)
add_subdirectory(EmptyDomainCFD)
add_subdirectory(IsolatedBuildingCFD)
add_subdirectory(SurroundedBuildingCFD)
add_subdirectory(coupledDigitalTwin)
add_subdirectory(physicsBasedMotion)
add_subdirectory(M9)
add_subdirectory(Istanbul)
add_subdirectory(MPM)
add_subdirectory(stochasticWave)
add_subdirectory(TaichiEvent)
add_subdirectory(CelerisTaichiEvent)

1 change: 1 addition & 0 deletions modules/createEVENT/shakeMapEvent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
simcenter_add_python_script(SCRIPT shakeMapEvent.py)
114 changes: 114 additions & 0 deletions modules/createEVENT/shakeMapEvent/shakeMapEvent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# # noqa: INP001, D100
# Copyright (c) 2018 Leland Stanford Junior University
# Copyright (c) 2018 The Regents of the University of California
#
# This file is part of the SimCenter Backend Applications
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# You should have received a copy of the BSD 3-Clause License along with
# this file. If not, see <http://www.opensource.org/licenses/>.
#
# Contributors:
# Stevan Gavrilovic
#

import argparse
import xml.etree.ElementTree as ET
import geopandas as gpd
from shapely.geometry import Point
from pathlib import Path


def create_shakemap_event(eventDirectory, eventPath, IMTypes): # noqa: D103

IMTypesList = eval(IMTypes)

print("Creating shakemap event")

xml_file_path = Path(eventDirectory) / eventPath / 'grid.xml'

# Parse the XML file
tree = ET.parse(xml_file_path)
root = tree.getroot()

# Find the grid_data element
grid_data = root.find('{http://earthquake.usgs.gov/eqcenter/shakemap}grid_data')

# Prepare lists to store data
points = []
attributes = []

# Parse the grid data
for line in grid_data.text.strip().split('\n'):
values = line.split()
lon, lat = float(values[0]), float(values[1])
point = Point(lon, lat)
points.append(point)

# Store only the specified attributes
attr = {}
attribute_mapping = {
'PGA': 2,
'PGV': 3,
'MMI': 4,
'PSA03': 5,
'PSA10': 6,
'PSA30': 7
}

for im_type in IMTypesList:
if im_type in attribute_mapping:
attr[im_type] = float(values[attribute_mapping[im_type]])

attributes.append(attr)

# Create GeoDataFrame
gdf = gpd.GeoDataFrame(attributes, geometry=points, crs="EPSG:4326")

# Display the first few rows
print("Saving shakemap to gpkg")

# Save as a GeoPackage file
gdf_path = Path(eventDirectory) / 'EventGrid.gpkg'
gdf.to_file(gdf_path, driver="GPKG")

return


if __name__ == '__main__':

parser = argparse.ArgumentParser()
parser.add_argument('--input', help='Input file')
parser.add_argument('--Directory', help='Directory path')
parser.add_argument('--EventPath', help='Event path')
parser.add_argument('--IntensityMeasureType', help='types of intensity measures')


args = parser.parse_args()

create_shakemap_event(args.Directory, args.EventPath, args.IntensityMeasureType)
1 change: 1 addition & 0 deletions modules/performRegionalMapping/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(NearestNeighborEvents)
add_subdirectory(SiteSpecifiedEvents)
add_subdirectory(GISSpecifiedEvents)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
simcenter_add_python_script(SCRIPT GISSpecifiedEvent.py)
simcenter_add_python_script(SCRIPT RasterEvent.py)
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# # noqa: INP001, D100
# Copyright (c) 2018 Leland Stanford Junior University
# Copyright (c) 2018 The Regents of the University of California
#
# This file is part of the SimCenter Backend Applications
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# You should have received a copy of the BSD 3-Clause License along with
# this file. If not, see <http://www.opensource.org/licenses/>.
#
# Contributors:
# Stevan Gavrilovic
#

import argparse
from pathlib import Path
import xml.etree.ElementTree as ET

from RasterEvent import create_event as create_raster_event

def is_raster_file(filename):
# Define a set of common raster file extensions
raster_extensions = {'.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.tif'}

# Create a Path object from the filename
file_path = Path(filename)

# Extract the file extension and check if it is in the set of raster extensions
return file_path.suffix.lower() in raster_extensions

def is_xml_file(filename):
# Check if the file has an .xml extension
if not filename.lower().endswith('.xml'):
return False

# Try to parse the file as XML
try:
ET.parse(filename)
return True
except ET.ParseError:
return False

def create_event(asset_file : str, event_grid_file: str): # noqa: C901, N803, D103

if is_raster_file(event_grid_file):
return create_raster_event(asset_file, event_grid_file)
elif is_xml_file(event_grid_file):
# Here you would call a function to handle XML files
# For now, we'll just raise a NotImplementedError
raise NotImplementedError("XML file handling is not yet implemented.")
else:
raise ValueError(f"{event_grid_file} is not a raster. Only rasters are currently supported.")



if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--assetFile')
parser.add_argument('--filenameEVENTgrid')
args = parser.parse_args()

create_event(
args.assetFile, args.filenameEVENTgrid
)
Loading
Loading