-
Notifications
You must be signed in to change notification settings - Fork 9
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 #240 from PrincetonUniversity/issue-213
Issue 213
- Loading branch information
Showing
16 changed files
with
1,087 additions
and
3,460 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,2 +1,4 @@ | ||
specfem_config.yaml | ||
Par_File | ||
line_sources.yaml | ||
__pycache__ |
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,39 @@ | ||
# Wave propagration through fluid-solid interface | ||
|
||
This example simulates a tele-seismic plane wave within a fluid-solid domain. This example is contributed by Sirawich Pipatprathanporn and is part of the publication [Pipatprathanporn et al. (2024)](https://doi.org/10.1093/gji/ggae238) | ||
|
||
## Running the examples | ||
|
||
To run the examples, you first need to install poetry following these [instructions](https://python-poetry.org/docs/#installation). Once you've done so, you can install the dependencies for the examples by running the following command in the current directory: | ||
|
||
```bash | ||
# verify poetry is installed | ||
poetry --version | ||
|
||
# install dependencies | ||
poetry install | ||
|
||
``` | ||
|
||
After installing the dependencies, you can run the examples by running the following command within the example directory you want to run: | ||
|
||
```bash | ||
|
||
# run the example | ||
poetry run snakemake -j 1 | ||
|
||
# or to run the example on a slurm cluster | ||
poetry run snakemake --executor slurm -j 1 | ||
|
||
``` | ||
|
||
## Cleaning up | ||
|
||
To clean up the example directory, you can run the following command in the directory of the example you want to clean up: | ||
|
||
```bash | ||
|
||
# clean up the example | ||
poetry run snakemake clean | ||
|
||
``` |
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,134 @@ | ||
SPECFEM_BIN = "specfem2d" | ||
MESHFEM_BIN = "xmeshfem2D" | ||
|
||
|
||
rule all: | ||
input: | ||
plot="OUTPUT_FILES/results/plot.png", | ||
localrule: True | ||
|
||
rule generate_mesh: | ||
input: | ||
"Par_File", | ||
output: | ||
database="OUTPUT_FILES/database.bin", | ||
stations="OUTPUT_FILES/STATIONS", | ||
localrule: True | ||
shell: | ||
""" | ||
mkdir -p OUTPUT_FILES | ||
{MESHFEM_BIN} -p {input} | ||
""" | ||
|
||
rule generate_line_sources: | ||
input: | ||
jinja_file = "line_sources.yaml.j2", | ||
jinja_variables = "jinja_variables.yaml", | ||
output: | ||
source_file = "line_sources.yaml", | ||
localrule: True | ||
run: | ||
import jinja2 | ||
import yaml | ||
|
||
def generate_sources(): | ||
# read jinja2 variables yaml file | ||
with open(input.jinja_variables, 'r') as f: | ||
jinja_vars = yaml.safe_load(f) | ||
|
||
with open(input.jinja_file, 'r') as f: | ||
template = jinja2.Template(f.read()) | ||
|
||
variables = jinja_vars['variables'] | ||
with open(output.source_file, 'w') as f: | ||
f.write(template.render(variables)) | ||
|
||
generate_sources() | ||
|
||
rule run_simulation: | ||
input: | ||
database="OUTPUT_FILES/database.bin", | ||
stations="OUTPUT_FILES/STATIONS", | ||
line_sources="line_sources.yaml", | ||
specfem_config="specfem_config.yaml", | ||
output: | ||
pressure_siesmograms=expand( | ||
"OUTPUT_FILES/results/{station_name}{network_name}{component}.semp", | ||
station_name=[ | ||
"S0001", | ||
"S0002", | ||
], | ||
network_name=["AA"], | ||
component=["PRE"], | ||
), | ||
resources: | ||
nodes=1, | ||
tasks=1, | ||
cpus_per_task=1, | ||
runtime=40, | ||
shell: | ||
""" | ||
module purge | ||
module load boost/1.73.0 | ||
mkdir -p OUTPUT_FILES/results | ||
mkdir -p OUTPUT_FILES/display | ||
echo "Hostname: $(hostname)" > output.log | ||
{SPECFEM_BIN} -p {input.specfem_config} >> output.log | ||
""" | ||
|
||
rule plot_seismogram: | ||
input: | ||
pressure_siesmograms=expand( | ||
"OUTPUT_FILES/results/{station_name}{network_name}{component}.semp", | ||
station_name=[ | ||
"S0001", | ||
"S0002", | ||
], | ||
network_name=["AA"], | ||
component=["PRE"], | ||
), | ||
output: | ||
traces="OUTPUT_FILES/results/plot.png", | ||
localrule: True | ||
run: | ||
import glob | ||
import os | ||
import numpy as np | ||
import obspy | ||
|
||
# Set matplotlib gui off | ||
import matplotlib | ||
matplotlib.use("Agg") | ||
|
||
def get_traces(directory): | ||
traces = [] | ||
files = glob.glob(directory + "/*.sem*") | ||
## iterate over all seismograms | ||
for filename in files: | ||
station_name = os.path.splitext(filename)[0] | ||
station_name = station_name.split("/")[-1] | ||
trace = np.loadtxt(filename, delimiter=" ") | ||
starttime = trace[0, 0] | ||
dt = trace[1, 0] - trace[0, 0] | ||
traces.append( | ||
obspy.Trace( | ||
trace[:, 1], | ||
{"network": station_name, "starttime": starttime, "delta": dt}, | ||
) | ||
) | ||
|
||
stream = obspy.Stream(traces) | ||
|
||
return stream | ||
|
||
|
||
stream = get_traces("OUTPUT_FILES/results") | ||
stream.plot(size=(800, 1000)).savefig(output.traces) | ||
|
||
rule clean: | ||
localrule: True | ||
shell: | ||
""" | ||
rm -rf OUTPUT_FILES | ||
rm -f line_sources.yaml | ||
""" |
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,4 @@ | ||
|
||
variables: | ||
number_of_sources_x: 197 | ||
number_of_sources_z: 37 |
Oops, something went wrong.