Skip to content

Commit 282ae1e

Browse files
committed
add adjoint station convert script
1 parent 2ab1007 commit 282ae1e

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
#PBS -A GEO111
4+
#PBS -N weighting
5+
#PBS -j oe
6+
#PBS -l walltime=6:00:00
7+
#PBS -l nodes=1
8+
9+
#cd $PBS_O_WORKDIR
10+
echo "pwd: `pwd`"
11+
echo "start at `date`"
12+
13+
eventfile="../eventlist.wenjie"
14+
15+
idx=0
16+
for event in `cat $eventfile`
17+
do
18+
idx=$(( $idx + 1 ))
19+
echo "========================"
20+
echo "[$idx]$event"
21+
path=paths/$event.adjoint_stations.path.json
22+
if [ ! -f $path ]; then
23+
echo "Path not exists: $path"
24+
exit
25+
fi
26+
pypaw-generate_adjoint_stations -f $path
27+
echo "Time: `date`"
28+
29+
done
30+
31+
echo
32+
echo "job done at `date`"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Introduction
2+
3+
This is the script used to generate the STATIONS_ADJOINT for adjoint simulation in specfem3d_Globe.
4+
5+
There are two things it needs:
6+
1. the measurements files generated by pyadjoint, including multiple period bands, which includes those stations with measurements for one event.
7+
2. the stations.json file which contains stations location information.
8+
9+
If you have multiple period bands, be sure to include all the measurement files inside the path json file.
10+
11+
#### Usage
12+
1. Generate the path json file by running:
13+
```
14+
python generate_path_adjoint_stations.py
15+
```
16+
Be sure to modify the path information and eventlist in the script.
17+
18+
2. Run the converting using:
19+
```
20+
pypaw-generate_adjoint_stations -f event1.path.json
21+
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import json
3+
4+
5+
def load_txt(fn):
6+
with open(fn) as fh:
7+
return [line.rstrip() for line in fh]
8+
9+
10+
def dump_json(content, fn):
11+
with open(fn, 'w') as fh:
12+
json.dump(content, fh, indent=2, sort_keys=True)
13+
14+
15+
def file_exists(fn):
16+
if not os.path.exists(fn):
17+
raise ValueError("File not exists: %s" % fn)
18+
19+
20+
def generate_adjoint_station_paths(
21+
eventname, period_bands, basedir, path_dir):
22+
measure_dir = os.path.join(basedir, "measure")
23+
station_dir = os.path.join(basedir, "stations")
24+
output_dir = os.path.join(basedir, "stations_adjoint")
25+
26+
measure_files = {}
27+
for pb in period_bands:
28+
fn = os.path.join(
29+
measure_dir, "%s.%s.measure_adj.json" % (eventname, pb))
30+
file_exists(fn)
31+
measure_files[pb] = fn
32+
33+
station_file = os.path.join(station_dir, "%s.stations.json" % eventname)
34+
output_file = os.path.join(output_dir, "STATIONS_ADJOINT.%s" % eventname)
35+
36+
content = {"measure_files": measure_files, "station_file": station_file,
37+
"output_file": output_file}
38+
39+
path_json = os.path.join(path_dir, "%s.adjoint_stations.path.json" %
40+
eventname)
41+
dump_json(content, path_json)
42+
43+
44+
def main():
45+
period_bands = ["17_40", "40_100", "90_250"]
46+
basedir = "/lustre/atlas/proj-shared/geo111/Wenjie/DATA_M16"
47+
pathdir = "paths"
48+
49+
print("Output path dir: %s" % pathdir)
50+
if not os.path.exists(pathdir):
51+
os.makedirs(pathdir)
52+
53+
eventlist = load_txt("../eventlist.wenjie")
54+
print("Number of events: %d" % len(eventlist))
55+
for event in eventlist:
56+
generate_adjoint_station_paths(event, period_bands, basedir, pathdir)
57+
58+
59+
60+
if __name__ == "__main__":
61+
main()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"measure_files": {
3+
"17_40": "/lustre/atlas/proj-shared/geo111/Wenjie/DATA_M16/measure/C201411021717A.17_40.measure_adj.json",
4+
"40_100": "/lustre/atlas/proj-shared/geo111/Wenjie/DATA_M16/measure/C201411021717A.40_100.measure_adj.json",
5+
"90_250": "/lustre/atlas/proj-shared/geo111/Wenjie/DATA_M16/measure/C201411021717A.90_250.measure_adj.json"
6+
},
7+
"output_file": "/lustre/atlas/proj-shared/geo111/Wenjie/DATA_M16/stations_adjoint/STATIONS_ADJOINT.C201411021717A",
8+
"station_file": "/lustre/atlas/proj-shared/geo111/Wenjie/DATA_M16/stations/C201411021717A.stations.json"
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
#PBS -A GEO111
4+
#PBS -N convert_adjoint_sta
5+
#PBS -j oe
6+
#PBS -l walltime=1:00:00
7+
#PBS -l nodes=1
8+
9+
cd $PBS_O_WORKDIR
10+
echo "pwd: `pwd`"
11+
echo "start at `date`"
12+
13+
eventfile="../eventlist.wenjie"
14+
15+
idx=0
16+
for event in `cat $eventfile`
17+
do
18+
idx=$(( $idx + 1 ))
19+
echo "======================================"
20+
echo "[$idx]$event"
21+
path=paths/$event.adjoint_stations.path.json
22+
if [ ! -f $path ]; then
23+
echo "Path not exists: $path"
24+
exit
25+
fi
26+
pypaw-generate_adjoint_stations -f $path
27+
echo "Time: `date`"
28+
29+
done
30+
31+
echo
32+
echo "job done at `date`"

0 commit comments

Comments
 (0)