-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcamsizer_grain_size_analysis.py
168 lines (148 loc) · 6.47 KB
/
camsizer_grain_size_analysis.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
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 3 15:04:45 2021
@author: rdchlntc
"""
import numpy as np
import os
import xlsxwriter
#Put the Directory here with all the files you want to load
directory = '/home/elizabeth/Documents/Research/Data/CAMSIZERdata/BSV01'
#first loop through to determine how many xle files are present
os.chdir(directory)
count = -1
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
if os.path.isfile(f) and filename.endswith('.xle'):
count = count+1
#set up corresponding variables for storage + output
d2 = np.zeros([count+1])
d5 = np.zeros([count+1])
d10 = np.zeros([count+1])
d16 = np.zeros([count+1])
d25 = np.zeros([count+1])
d50 = np.zeros([count+1])
d75 = np.zeros([count+1])
d90 = np.zeros([count+1])
d95 = np.zeros([count+1])
d98 = np.zeros([count+1])
bl_avg = np.zeros([count+1])
spht_avg = np.zeros([count+1])
symm_avg = np.zeros([count+1])
perc_very_coarse_sand = np.zeros([count+1])
perc_coarse_sand = np.zeros([count+1])
perc_medium_sand = np.zeros([count+1])
perc_fine_sand = np.zeros([count+1])
perc_very_fine_sand = np.zeros([count+1])
perc_silt = np.zeros([count+1])
perc_granule = np.zeros([count+1])
perc_pebble = np.zeros([count+1])
#set up excel spreadsheet
workbook = xlsxwriter.Workbook('camsizer_outputs.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write(0,0, 'Filename')
worksheet.write(0,1, 'Site')
worksheet.write(0,2, 'CoreNumber')
worksheet.write(0,3, 'SampleNumber')
worksheet.write(0,4, 'D2(mm)')
worksheet.write(0,5, 'D5(mm)')
worksheet.write(0,6, 'D10(mm)')
worksheet.write(0,7, 'D16(mm)')
worksheet.write(0,8, 'D25(mm)')
worksheet.write(0,9, 'D50(mm)')
worksheet.write(0,10, 'D75(mm)')
worksheet.write(0,11, 'D90(mm)')
worksheet.write(0,12, 'D95(mm)')
worksheet.write(0,13, 'D98(mm)')
worksheet.write(0,14, 'Symmetry_Avg')
worksheet.write(0,15, 'Sphericity_Avg')
worksheet.write(0,16, 'B/L_Avg')
worksheet.write(0,17, 'Perc_VeryCoarseSand')
worksheet.write(0,18, 'Perc_CoarseSand')
worksheet.write(0,19, 'Perc_MediumSand')
worksheet.write(0,20, 'Perc_FineSand')
worksheet.write(0,21, 'Perc_VeryFineSand')
worksheet.write(0,22, 'Perc_Silt')
worksheet.write(0,23, 'Perc_Granule')
worksheet.write(0,24, 'Perc_Pebble')
#loop through again to actually calculate data
count = -1
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
if os.path.isfile(f) and filename.endswith('.xle'):
data = np.loadtxt(filename, delimiter='\t', skiprows=31, encoding = "utf-16")
count = count + 1
#determine grain size bounds
lower_bound_size_mm = np.array(data[:,0])
upper_bound_size_mm = np.array(data[:,1])
upper_bound_size_mm[-1] = 10
grain_size_mm = lower_bound_size_mm/2 + upper_bound_size_mm/2
#store other shape data
p= data[:,2]
q=data[:,3]
spht = data[:,4]
symm = data[:,5]
bl = data[:,6]
pdn = data[:,7]
#calc relevant stats
d2[count] = np.interp(2, q, grain_size_mm)
d5[count] = np.interp(5, q, grain_size_mm)
d10[count] = np.interp(10, q, grain_size_mm)
d16[count] = np.interp(16, q, grain_size_mm)
d25[count] = np.interp(25, q, grain_size_mm)
d50[count] = np.interp(50, q, grain_size_mm)
d75[count] = np.interp(75, q, grain_size_mm)
d90[count] = np.interp(90, q, grain_size_mm)
d95[count] = np.interp(95, q, grain_size_mm)
d98[count] = np.interp(98, q, grain_size_mm)
ifind = np.where((d25[count] <= grain_size_mm) & (grain_size_mm <= d75[count]))
symm_avg[count] = np.nanmean(symm[ifind])
spht_avg[count] = np.nanmean(spht[ifind])
bl_avg[count] = np.nanmean(bl[ifind])
#ifind = np.where((grain_size_mm >= 1) & (grain_size_mm < 2))
perc_very_coarse_sand[count] = np.sum(p[np.where((grain_size_mm >= 1) & (grain_size_mm < 2))])
perc_coarse_sand[count] = np.sum(p[np.where((grain_size_mm >= 0.5) & (grain_size_mm < 1))])
perc_medium_sand[count] = np.sum(p[np.where((grain_size_mm >= 0.25) & (grain_size_mm < 0.5))])
perc_fine_sand[count] = np.sum(p[np.where((grain_size_mm >= 0.125) & (grain_size_mm < 0.25))])
perc_very_fine_sand[count] = np.sum(p[np.where((grain_size_mm >= 0.0625) & (grain_size_mm < 0.125))])
perc_silt[count] = np.sum(p[np.where((grain_size_mm >= 0.004) & (grain_size_mm < 0.0625))])
perc_granule[count] = np.sum(p[np.where((grain_size_mm >= 2) & (grain_size_mm < 4))])
perc_pebble[count] = np.sum(p[np.where(grain_size_mm >= 4)])
#write out data
ifindSite = filename.find('V')
ifindCoreStart = ifindSite+1
ifindCoreEnd = ifindSite+3
site = filename[0:ifindCoreStart]
core = filename[ifindCoreStart:ifindCoreEnd]
ifindSampleNum = filename.find('SS')
ifindSampleStart = ifindSampleNum+2
ifindSampleEnd = ifindSampleNum+4
samplenum = filename[ifindSampleStart:ifindSampleEnd]
worksheet.write(count+1,0, filename)
worksheet.write(count+1,1, site)
worksheet.write(count+1,2, core)
worksheet.write(count+1,3, samplenum)
worksheet.write(count+1,4, d2[count])
worksheet.write(count+1,5, d5[count])
worksheet.write(count+1,6, d10[count])
worksheet.write(count+1,7, d16[count])
worksheet.write(count+1,8, d25[count])
worksheet.write(count+1,9, d50[count])
worksheet.write(count+1,10, d75[count])
worksheet.write(count+1,11, d90[count])
worksheet.write(count+1,12, d95[count])
worksheet.write(count+1,13, d98[count])
worksheet.write(count+1,14, symm_avg[count])
worksheet.write(count+1,15, spht_avg[count])
worksheet.write(count+1,16, bl_avg[count])
worksheet.write(count+1,17, perc_very_coarse_sand[count])
worksheet.write(count+1,18, perc_coarse_sand[count])
worksheet.write(count+1,19, perc_medium_sand[count])
worksheet.write(count+1,20, perc_fine_sand[count])
worksheet.write(count+1,21, perc_very_fine_sand[count])
worksheet.write(count+1,22, perc_silt[count])
worksheet.write(count+1,23, perc_granule[count])
worksheet.write(count+1,24, perc_pebble[count])
#close and save excel spreadsheet
workbook.close()