-
Notifications
You must be signed in to change notification settings - Fork 18
/
plot_swath_profile.py
114 lines (90 loc) · 3.42 KB
/
plot_swath_profile.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
## plot_swath_profile.py
##=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## Plots a simple swath profile generated by LSDTopoTools swath profiler
##=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
## DTM 16/06/2014
## Update SMM 18/06/2014 Change to handle nodata
##=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#import modules
import numpy as np, matplotlib.pyplot as plt
from matplotlib import rcParams
import matplotlib.colors as colors
import matplotlib.cm as cmx
def plot_swath_profile(full_file_path, ax):
# Set up fonts for plots
rcParams['font.family'] = 'sans-serif'
rcParams['font.sans-serif'] = ['Liberation Sans']
rcParams['font.size'] = 16
rcParams['legend.numpoints'] = 1
axis_size = 16
# FileList = dir +
f = open(full_file_path, 'r')
lines = f.readlines()
N_Segments = len(lines)-1
# Initialise a bunch of vectors
distance = np.zeros(N_Segments)
mean = np.zeros(N_Segments)
sd = np.zeros(N_Segments)
minimum = np.zeros(N_Segments)
LQ = np.zeros(N_Segments)
median = np.zeros(N_Segments)
UQ = np.zeros(N_Segments)
maximum = np.zeros(N_Segments)
for i in range (0, N_Segments):
line = lines[i+1].strip().split(" ")
distance[i] = float(line[0])
mean[i] = float(line[1])
sd[i] = float(line[2])
minimum[i] = float(line[3])
LQ[i] = float(line[4])
median[i] = float(line[5])
UQ[i] = float(line[6])
maximum[i] = float(line[7])
# if there is nodata (-9999) replace with the numpy nodata entry
if (mean[i] == -9999):
mean[i] = np.nan
sd[i] = np.nan
minimum[i] = np.nan
LQ[i] = np.nan
median[i] = np.nan
UQ[i] = np.nan
maximum[i] = np.nan
f.close()
#######################
# #
# Plot data #
# #
#######################
OutputFigureFormat = 'pdf'
# SET UP COLOURMAPS
# PLOT 1 -> transverse profile
#plt.figure(1, facecolor='White',figsize=[10,6])
#plt.plot(distance,median,'-')
ax.plot(distance,LQ,'--')
ax.plot(distance,UQ,'--')
#plt.plot(distance,minimum,'-.',color='black')
#plt.plot(distance,maximum,'-.',color='black')
ax.plot(distance,mean,'-')
# Configure final plot
ax.spines['top'].set_linewidth(1)
ax.spines['left'].set_linewidth(1)
ax.spines['right'].set_linewidth(1)
ax.spines['bottom'].set_linewidth(1)
ax.tick_params(axis='both', width=1)
plt.ylabel('Average elevation difference (m)', fontsize = axis_size)
plt.xlabel('Distance along channel longitudinal profile (m)', fontsize = axis_size)
plt.subplots_adjust(bottom=0.15,left=0.18)
#plt.show()
def multiSwathPlot(data_dir, wildcard_fname):
import glob
fig, ax = plt.subplots()
for f in glob.glob(data_dir + wildcard_fname):
print(f)
full_file_path = data_dir + wildcard_fname
plot_swath_profile(f, ax)
fig.canvas.draw()
data_dir = "/mnt/SCRATCH/Analyses/HydrogeomorphPaper/SwathProfile/Swath_secondVisit/Ryedale/"
file_single = "RyedaleElevDiff_GRIDDED_TLIM_long_profile.txt"
file_wildcard = "*ElevDiff_*_TLIM_long_profile.txt"
#plot_swath_profile(file_single + data_dir)
multiSwathPlot(data_dir, file_wildcard)