-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from NHERI-SimCenter/R2D_CI
SG: Move logic from R2D frontend into backend
- Loading branch information
Showing
9 changed files
with
592 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
simcenter_add_python_script(SCRIPT shakeMapEvent.py) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(NearestNeighborEvents) | ||
add_subdirectory(SiteSpecifiedEvents) | ||
add_subdirectory(GISSpecifiedEvents) |
2 changes: 2 additions & 0 deletions
2
modules/performRegionalMapping/GISSpecifiedEvents/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
89 changes: 89 additions & 0 deletions
89
modules/performRegionalMapping/GISSpecifiedEvents/GISSpecifiedEvent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.