-
Notifications
You must be signed in to change notification settings - Fork 8
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 #396 from GEMScienceTools/update_sub_plotting
Update subduction plotting tools
- Loading branch information
Showing
19 changed files
with
338 additions
and
67 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
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,30 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
|
||
from openquake.baselib import sap | ||
from openquake.sub.make_cs_coords import make_cs_coords | ||
|
||
def main(cs_dir, outfi, ini_fname, cs_length=300., cs_depth=300.): | ||
""" | ||
Creates file with parameters needed to plot cross sections. | ||
Output file is a list for each cross section with the format: | ||
lon lat length depth azimuth id <config>.ini | ||
Example use: | ||
oqm sub make_cs_coords openquake/sub/tests/data/cs_cam cs_profiles.csv | ||
example.ini 300 300 | ||
""" | ||
|
||
make_cs_coords(cs_dir, outfi, ini_fname, cs_length, cs_depth) | ||
|
||
|
||
make_cs_coords.cs_dir = 'directory with cross section coordinates' | ||
make_cs_coords.outfi = 'output filename' | ||
make_cs_coords.ini_fname = 'name of ini file specifying data paths' | ||
make_cs_coords.cs_length = 'length of cross sections (default 300)' | ||
make_cs_coords.cs_depth = 'depth extent of cross sections (default 300 km)' | ||
|
||
if __name__ == '__main__': | ||
sap.run(main) |
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,25 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
|
||
from openquake.baselib import sap | ||
from openquake.sub.plotting.plot_multiple_cross_sections_map import plot | ||
|
||
|
||
def main(config_fname, cs_file=None): | ||
""" | ||
Plots map of cross sections with earthquake data | ||
Example: | ||
oqm sub plot_cross_sections_map config.ini cs_profiles.cs | ||
Note: paths in config.ini are relative to cwd | ||
""" | ||
|
||
plot(config_fname, cs_file) | ||
|
||
|
||
main.config_fname = 'config file to datasets' | ||
main.cs_file = 'existing cross sections details' | ||
|
||
if __name__ == "__main__": | ||
sap.run(main) |
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,26 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
|
||
from openquake.baselib import sap | ||
from openquake.sub.plotting.plot_multiple_cross_sections import pcs | ||
|
||
|
||
def main(cs_file, output_folder=None): | ||
""" | ||
Plots cross section of data for each cross section in | ||
cs_file including the data in the ini file referenced | ||
in the cs_file lines. Saves pdfs to output_folder | ||
Example: | ||
oqm sub plot_multiple_cross_sections cs_profiles.cs pdf | ||
""" | ||
|
||
pcs(cs_file, output_folder) | ||
|
||
|
||
main.cs_file = 'file with cross sections details' | ||
main.output_folder = 'place to store the pdfs' | ||
|
||
if __name__ == "__main__": | ||
sap.run(main) |
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,44 @@ | ||
import pandas as pd | ||
import geopandas as gpd | ||
from shapely.geometry import Point | ||
|
||
from openquake.baselib import sap | ||
|
||
|
||
def main(fippath):#, eventid): | ||
""" | ||
Converts an event from the sourcemod database of the format | ||
.fsp to a geojson file | ||
Note: first download events from http://equake-rc.info/srcmod/ | ||
Example: | ||
oqm sub srcmod_to_json srcmod_events/s2013SCOTIA01HAYE.fsp | ||
""" | ||
fin = f'{fippath}' | ||
root = fin.split('/')[-1].replace('.fsp','') | ||
outfi = f'{root}.geojson' | ||
|
||
file1 = open(fin, 'r') | ||
Lines = file1.readlines() | ||
|
||
lons, lats, depths, slips = [],[],[],[] | ||
for line in Lines: | ||
if (line[0] != '%') & (line != ' \n'): | ||
parts = line.strip().split() | ||
lons.append(parts[1]); lats.append(parts[0]) | ||
depths.append(float(parts[4])); slips.append(float(parts[5])) | ||
df = pd.DataFrame({'lon': lons, 'lat': lats, | ||
'depth': depths, 'slip': slips}) | ||
|
||
gdf = gpd.GeoDataFrame(df, geometry=[Point(xy) for xy in \ | ||
zip(df['lon'], df['lat'])], crs="epsg:4326") | ||
gdf.to_file(outfi, driver="GeoJSON") | ||
print(f'Written to {outfi}') | ||
|
||
main.fippath = 'path to .fsp file' | ||
|
||
if __name__ == "__main__": | ||
sap.run(main) |
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
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
Oops, something went wrong.