-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckstartdepth.py
More file actions
141 lines (117 loc) · 5.31 KB
/
checkstartdepth.py
File metadata and controls
141 lines (117 loc) · 5.31 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
# -*- coding: utf-8 -*-
"""
=============================================================
Measured Vs Expansion Start Depth Calculation Script
-------------------------------------------------------------
Purpose:
This script calculates the expanded starting depth (d_new)
for Measured Vs profiles, using the median of the depth
differences (Δd), ensuring d_new >= 0.
The results are saved to a single CSV file.
Usage:
Run the script from the command line with the folder path
containing the Measured Vs CSV files as an argument.
python vs_expansion_analysis.py <Measured_Vs_Folder>
Example:
python vs_expansion_analysis.py ./vsmo
=============================================================
"""
import os
import pandas as pd
import numpy as np
import sys
from datetime import datetime
# -----------------------------------------------------------
# 1. Check command-line arguments and Setup
# -----------------------------------------------------------
if len(sys.argv) != 2:
print("Usage: python vs_expansion_analysis.py <Measured_Vs_Folder>")
print("Example: python vs_expansion_analysis.py ./vsmo")
sys.exit(1)
measured_vs_folder = sys.argv[1]
if not os.path.exists(measured_vs_folder):
print(f"Error: Folder not found at path: {measured_vs_folder}")
sys.exit(1)
# Output folder setup
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
output_folder = f'./vs_expansion_output_{timestamp}'
os.makedirs(output_folder, exist_ok=True)
output_csv_filename = 'measured_vs_expansion_start_depths.csv'
output_csv_path = os.path.join(output_folder, output_csv_filename)
print(f"Processing Measured Vs files in: {measured_vs_folder}")
print(f"Results will be saved to: {output_csv_path}")
# -----------------------------------------------------------
# 2. Helper function to extract file key (code)
# -----------------------------------------------------------
def extract_file_key(filename):
"""Extract consistent key (code) from filename"""
base = os.path.basename(filename)
parts = base.split('_')
# 파일명이 'vsmo_CODE.csv' 형태라고 가정하고 CODE를 추출
if len(parts) >= 2:
# .csv 확장자 제거
return parts[1].replace('.csv', '')
return None
# -----------------------------------------------------------
# 3. Main Calculation Loop
# -----------------------------------------------------------
vs_expansion_data = []
# 폴더 내의 모든 .csv 파일을 순회
for filename in os.listdir(measured_vs_folder):
if not filename.endswith('.csv'):
continue
file_path = os.path.join(measured_vs_folder, filename)
code = extract_file_key(filename)
if not code:
print(f"Warning: Could not extract code from file: {filename}. Skipping.")
continue
# Measured Vs 파일 로드
try:
df_measured = pd.read_csv(file_path)
except Exception as e:
print(f"Skipping file '{filename}' due to load error: {e}")
continue
# 필수 컬럼 ('d': 깊이, 'vs': Vs) 확인 및 처리
if 'd' not in df_measured.columns or 'vs' not in df_measured.columns:
print(f"Warning: File '{filename}' is missing 'd' or 'vs' column. Skipping.")
continue
df_measured = df_measured.sort_values('d').reset_index(drop=True)
# 첫 번째 깊이가 0보다 클 경우에만 확장 시작 깊이 계산
if not df_measured.empty and df_measured.iloc[0]['d'] > 0:
first_depth = df_measured.iloc[0]['d']
# 깊이 차이 계산: Δd = d[i] - d[i-1]
depth_diffs = np.diff(df_measured['d'].values)
# 깊이 차이가 없으면 (단일 데이터 포인트) 첫 깊이를 미디안으로 사용
median_diff = np.median(depth_diffs) if len(depth_diffs) > 0 else first_depth
# 새로운 시작 깊이 계산 (최솟값은 0)
# new_depth = max(df_measured.iloc[0]['d'] - median_diff, 0.0)
new_depth = max(first_depth - median_diff, 0.0)
# 결과를 리스트에 추가
vs_expansion_data.append({
'File Code': code,
'Original Filename': filename,
'First Measured Depth (m)': first_depth,
'Depth Difference Median (m)': median_diff,
'Expanded Start Depth (d_new, m)': new_depth
})
print(f"Processed {code}: d_new = {new_depth:.3f} m")
else:
# 첫 깊이가 이미 0이거나 데이터가 비어있는 경우
vs_expansion_data.append({
'File Code': code,
'Original Filename': filename,
'First Measured Depth (m)': df_measured.iloc[0]['d'] if not df_measured.empty else np.nan,
'Depth Difference Median (m)': 0.0,
'Expanded Start Depth (d_new, m)': 0.0
})
# print(f"Skipping expansion for {code}: First depth is 0 or data is empty.")
# -----------------------------------------------------------
# 4. Save Results
# -----------------------------------------------------------
if vs_expansion_data:
df_vs_expansion = pd.DataFrame(vs_expansion_data)
# CSV 파일로 저장
df_vs_expansion.to_csv(output_csv_path, index=False, encoding='utf-8-sig')
print(f"\n✅ 분석이 완료되었습니다. 결과가 저장되었습니다: {output_csv_path}")
else:
print("\n⚠️ 처리할 Measured Vs CSV 파일이 Measured Vs 폴더 내에 없습니다.")