-
Notifications
You must be signed in to change notification settings - Fork 1
/
reformat_synthetic_file.py
54 lines (43 loc) · 1.6 KB
/
reformat_synthetic_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File Name: reformat_synthetic_file
# Author: Khang Vo
# Date Created: 3/13/2023
# Date Last Modified: 3/13/2023
# Python Version: 3.10
import os
import glob
import time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def obs(input_file, output_path):
df_res = pd.read_csv(input_file, delim_whitespace=True)
df_res.columns = ["ievt", "sta", "ttime", "wgt", "phasej"]
c_res = df_res[["ievt", "sta", "ttime", "wgt", "phasej"]]
c_res.to_csv(output_path + "/temp_abs.txt", sep="\t", index=False)
ievt_seen = set()
with open(output_path + "/temp_abs.txt", "r") as infile:
with open(output_path + "/syn_obs.txt", "w") as outfile:
# outfile.write("sta" + "\t")
# outfile.write("ttime" + "\t")
# outfile.write("wgt" + "\t")
# outfile.write("phasej" + "\n")
next(infile)
for line in infile:
fields = line.split()
ievt = fields[0]
sta = fields[1]
ttime = fields[2]
wgt = fields[3]
phasej = fields[4]
if ievt not in ievt_seen:
outfile.write("# " + ievt + "\n")
ievt_seen.add(ievt)
outfile.write(sta + "\t")
outfile.write(ttime + "\t")
outfile.write(wgt + "\t")
outfile.write(phasej + "\n")
os.remove(output_path + "/temp_abs.txt")
if __name__ == "__main__":
input_file = "/Users/khangvo/Downloads/absolute.syn"
output_path = "/Users/khangvo/Downloads"
obs(input_file, output_path)