-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathres2dinv_converter.py
More file actions
96 lines (68 loc) · 2.53 KB
/
Copy pathres2dinv_converter.py
File metadata and controls
96 lines (68 loc) · 2.53 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
import pandas as pd
def read_data_gimli(df):
# Define column names
column_names = ['a', 'b', 'm', 'n', 'err', 'i', 'ip', 'iperr', 'k', 'r', 'rhoa', 'u', 'valid']
# Read the file starting from line 76
data = pd.read_csv(df, delimiter='\t', skiprows=76, skipfooter=1, names=column_names)
# Print the data
print(data)
return data
def read_geom_gimli(df):
# Define column names
column_names = ['x', 'y', 'z']
# Read the file starting from line 76
data = pd.read_csv(df, delimiter='\t', skiprows=2, nrows=72, names=column_names)
print(data)
def convert_2_res2dinv(df, filename='data_res2dinv/ert_WIL_01.dat'):
# Create a new dataframe
new_df = pd.DataFrame(columns=['id', 'a', 'type_a', 'b', 'type_b', 'm', 'type_m', 'n', 'type_n', 'rhoa'])
new_df['a'] = (df['a']-1) * 2.5
new_df['b'] = (df['b']-1) * 2.5
new_df['m'] = (df['m']-1) * 2.5
new_df['n'] = (df['n']-1) * 2.5
new_df['rhoa'] = df['rhoa']
new_df['type_a'] = 0.0
new_df['type_b'] = 0.0
new_df['type_m'] = 0.0
new_df['type_n'] = 0.0
new_df['id'] = int(4)
header = """P01_O-E_clean-topo.bin
2.50
11
7
Type of measurement (0=app. resistivity,1=resistance)
0
1316
2
0
"""
footer = """0
0
0
0
"""
# Open the file in write mode
with open(filename, 'w') as f:
# Write the header
f.write(header)
# Write each row to the file with the desired spacing
for _, row in new_df.iterrows():
line = f"{int(row['id']):1} {row['a']:2.2f} {row['type_a']:.2f} {row['b']:2.2f} {row['type_b']:.2f} {row['m']:2.2f} {row['type_m']:.2f} {row['n']:2.2f} {row['type_n']:.2f} {row['rhoa']:2.5f}\n"
f.write(line)
f.write(footer)
print(new_df)
return new_df
# def read_res2Dinv_processed(path):
# import matplotlib.pyplot as plt
# # Read the data, skipping the first 5 rows and using whitespace as the delimiter
# df = pd.read_csv(path, skiprows=2473, delim_whitespace=True, nrows=1136, names=['X', 'Depth', 'Resistivity', 'Relative sensitivity', 'Smoothed sensitivity', 'Uncertainty'])
# # Pivot the DataFrame to create a grid of resistivity values
# pivot_df = df.pivot(index='Depth', columns='X', values='Resistivity')
# # Plot the colormap using the 'jet' cmap
# plt.figure(figsize=(10, 8))
# plt.imshow(pivot_df, cmap='jet', origin='lower')
# plt.colorbar(label='Resistivity')
# plt.title('Resistivity Colormap')
# plt.xlabel('X')
# plt.ylabel('Depth')
# plt.show()