-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerger and Trim Passive Seismic Data
More file actions
178 lines (145 loc) · 7.99 KB
/
Merger and Trim Passive Seismic Data
File metadata and controls
178 lines (145 loc) · 7.99 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import tkinter as tk
from tkinter import filedialog, messagebox
from obspy import read, Stream, UTCDateTime
import matplotlib.pyplot as plt
import os
from PIL import Image, ImageTk
class SeismicApp:
def __init__(self, root):
self.root = root
self.root.title("Passive Seismic Data PreProcessing")
self.stream_gabungan = Stream()
self.stream_potongan = Stream()
self.temp_dir = "temp_images"
os.makedirs(self.temp_dir, exist_ok=True)
# Setup menubar
self.menubar = tk.Menu(root)
root.config(menu=self.menubar)
file_menu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="FILE", menu=file_menu)
HVSR_menu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="HVSR", menu=HVSR_menu)
LFPS_menu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="LFPS", menu=LFPS_menu)
exit_menu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label ="EXIT", menu=exit_menu)
# Menambahkan semua tools ke dalam menu FILE
file_menu.add_command(label="Pilih File Seismik", command=self.pilih_dan_baca_files)
file_menu.add_command(label="Potong & Plot Data", command=self.potong_dan_plot)
file_menu.add_separator()
file_menu.add_command(label="Simpan Data Gabungan", command=self.simpan_data_gabungan)
file_menu.add_command(label="Simpan Data Potongan", command=self.simpan_data_potongan)
# Menambahkan semua tools kedalam menu EXIT
exit_menu.add_command(label="Keluar dari Program", command=root.quit)
# Frame utama untuk info dan gambar
main_frame = tk.Frame(root, padx=15, pady=15)
main_frame.pack(fill='both', expand=True)
# Judul
title = tk.Label(main_frame, text="Software Preprocessing Data Pasif Seismik", font=("Arial", 16, "bold"))
title.grid(row=0, column=0, columnspan=2, pady=(0, 10))
# Keterangan tentang seismik pasif
desc_text = (
"Seismik pasif adalah metode pengamatan getaran bumi yang tidak menggunakan sumber getaran buatan. Metode ini mengandalkan gelombang seismik alami untuk menganalisis struktur bawah permukaan.Tools pada menu FILE memungkinkan pengolahan data seismik pasif dalam format MiniSEED. Pengguna dapat memilih file, memotong data berdasarkan waktu, memplot, dan menyimpan hasil."
)
desc_label = tk.Label(main_frame, text=desc_text, justify='left', font=("Arial", 10), wraplength=600)
desc_label.grid(row=1, column=0, columnspan=2, sticky='w', pady=(0, 20))
# Frame untuk gambar hasil
frame_gambar = tk.Frame(main_frame)
frame_gambar.grid(row=2, column=0, columnspan=2, sticky='ew')
tk.Label(frame_gambar, text="Gambar Hasil Penggabungan", font=("Arial", 12, "underline")).grid(row=0, column=0, padx=20)
tk.Label(frame_gambar, text="Gambar Hasil Pemotongan", font=("Arial", 12, "underline")).grid(row=0, column=1, padx=20)
self.label_img_gabung = tk.Label(frame_gambar, borderwidth=2, relief="groove")
self.label_img_gabung.grid(row=1, column=0, padx=20, pady=10)
self.label_img_potong = tk.Label(frame_gambar, borderwidth=2, relief="groove")
self.label_img_potong.grid(row=1, column=1, padx=20, pady=10)
main_frame.grid_columnconfigure(0, weight=1)
main_frame.grid_columnconfigure(1, weight=1)
frame_gambar.grid_columnconfigure(0, weight=1)
frame_gambar.grid_columnconfigure(1, weight=1)
def pilih_dan_baca_files(self):
file_paths = filedialog.askopenfilenames(title="Pilih file seismik",
filetypes=(("MiniSEED files", "*.mseed"), ("All files", "*.*")))
if not file_paths:
messagebox.showinfo("Info", "Tidak ada file yang dipilih.")
return
self.stream_gabungan = Stream()
for file in file_paths:
try:
st = read(file)
self.stream_gabungan += st
except Exception as e:
messagebox.showerror("Error", f"Gagal membaca file '{file}': {e}")
messagebox.showinfo("Sukses", f"{len(file_paths)} file dibaca, total {len(self.stream_gabungan)} trace tergabung.")
if len(self.stream_gabungan) > 0:
fig = self.stream_gabungan.plot(show=False)
path_gabung = os.path.join(self.temp_dir, "gambar_gabungan.png")
fig.savefig(path_gabung)
plt.close(fig)
self.tampilkan_gambar(path_gabung, self.label_img_gabung)
def potong_dan_plot(self):
if len(self.stream_gabungan) == 0:
messagebox.showwarning("Peringatan", "Belum ada data yang dimuat.")
return
# Ambil input waktu dari dialog askstring karena input tidak ada di GUI utama
import tkinter.simpledialog as sd
mulai_str = sd.askstring("Input Waktu Mulai", "Masukkan waktu mulai (YYYY-MM-DD HH:MM):")
if not mulai_str:
return
selesai_str = sd.askstring("Input Waktu Selesai", "Masukkan waktu selesai (YYYY-MM-DD HH:MM):")
if not selesai_str:
return
try:
mulai_waktu = UTCDateTime(mulai_str + ":00")
selesai_waktu = UTCDateTime(selesai_str + ":00")
except Exception as e:
messagebox.showerror("Error", f"Format waktu salah: {e}")
return
if mulai_waktu >= selesai_waktu:
messagebox.showwarning("Peringatan", "Waktu mulai harus lebih kecil dari waktu selesai.")
return
self.stream_potongan = self.stream_gabungan.slice(starttime=mulai_waktu, endtime=selesai_waktu)
if len(self.stream_potongan) == 0:
messagebox.showinfo("Info", "Data pada interval waktu tersebut kosong.")
return
fig = self.stream_potongan.plot(show=False)
path_potong = os.path.join(self.temp_dir, "gambar_potongan.png")
fig.savefig(path_potong)
plt.close(fig)
self.tampilkan_gambar(path_potong, self.label_img_potong)
messagebox.showinfo("Sukses", "Hasil plot pemotongan disimpan dan ditampilkan.")
def simpan_data_gabungan(self):
if len(self.stream_gabungan) == 0:
messagebox.showwarning("Peringatan", "Belum ada data untuk disimpan.")
return
path = filedialog.asksaveasfilename(defaultextension=".mseed",
filetypes=[("MiniSEED files", "*.mseed"), ("All files", "*.*")],
title="Simpan Data Gabungan Sebagai")
if path:
try:
self.stream_gabungan.write(path, format="MSEED")
messagebox.showinfo("Sukses", f"Data gabungan berhasil disimpan ke\n{path}")
except Exception as e:
messagebox.showerror("Error", f"Gagal menyimpan data: {e}")
def simpan_data_potongan(self):
if not hasattr(self, 'stream_potongan') or len(self.stream_potongan) == 0:
messagebox.showwarning("Peringatan", "Belum ada data potongan yang tersedia untuk disimpan.")
return
path = filedialog.asksaveasfilename(defaultextension=".mseed",
filetypes=[("MiniSEED files", "*.mseed"), ("All files", "*.*")],
title="Simpan Data Potongan Sebagai")
if path:
try:
self.stream_potongan.write(path, format="MSEED")
messagebox.showinfo("Sukses", f"Data potongan berhasil disimpan ke\n{path}")
except Exception as e:
messagebox.showerror("Error", f"Gagal menyimpan data: {e}")
def tampilkan_gambar(self, path, label):
image = Image.open(path)
image = image.resize((600, 400), Image.Resampling.LANCZOS)
photo = ImageTk.PhotoImage(image)
label.config(image=photo)
label.image = photo
if __name__ == "__main__":
root = tk.Tk()
app = SeismicApp(root)
root.mainloop()