-
Notifications
You must be signed in to change notification settings - Fork 0
/
elevation_ksn_scatter.py
132 lines (90 loc) · 4.37 KB
/
elevation_ksn_scatter.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
#Ksn by elevation
import matplotlib
matplotlib.use("Agg")
from matplotlib import pyplot as plt
import pandas as pd
import sys
import numpy as np
from numpy import median
import matplotlib.cm as cm
import matplotlib.patches as mpatches
from mpl_toolkits.axes_grid.inset_locator import inset_axes
target = '/exports/csce/datastore/geos/users/s1134744/LSDTopoTools/Topographic_projects/full_himalaya_5000/'
source= '0_4_ex_MChiSegmented_burned_outlier_removed.csv'
def getAxis(column):
with open(target+source,'r') as csvfile:
df = pd.read_csv(csvfile,delimiter=',')
distance = []
full_data = []
for lower,upper in zip(range(350,5000,50),range(400,5050,50)):
selectedDF_c = df[df[column] >= lower]
selectedDF_c = selectedDF_c[selectedDF_c[column] < upper]
series = selectedDF_c["m_chi"].tolist()
value = median(series)
full_data.append(value)
distance.append(full_data)
for x,y in zip(range(0,2000,500),range(500,2500,500)):
selectedDF = df[df["distance_a"] >= x]
selectedDF = selectedDF[selectedDF["distance_a"] < y]
elevation = []
for lower,upper in zip(range(350,5000,50),range(400,5050,50)):
selectedDF_b = selectedDF[selectedDF[column] >= lower]
selectedDF_b = selectedDF_b[selectedDF_b[column] < upper]
series = selectedDF_b["m_chi"].tolist()
value = median(series)
#print value
elevation.append(value)
distance.append(elevation)
return distance
def getAxisHist(column):
with open(target+source,'r') as csvfile:
df = pd.read_csv(csvfile,delimiter=',')
distance = []
full_data = []
#for lower,upper in zip(range(350,5000,50),range(400,5050,50)):
# selectedDF_c = df[df[column] >= lower]
# selectedDF_c = selectedDF_c[selectedDF_c[column] < upper]
series = df[column].tolist()
#value = median(series)
distance.append(series)
#distance.append(full_data)
for x,y in zip(range(0,2000,500),range(500,2500,500)):
selectedDF = df[df["distance_a"] >= x]
selectedDF = selectedDF[selectedDF["distance_a"] < y]
series = selectedDF[column].tolist()
distance.append(series)
return distance
data = getAxis("segmented_")
x_series = range(375,5025,50)
fig = plt.figure(1, figsize=(18,9))
legends = []
x = np.arange(len(range(0,2000,500)))
ys = [i+x+(i*x)**2 for i in range(len(range(0,2500,500)))]
colours = cm.rainbow(np.linspace(0, 1, len(ys)))
bins = [str(y)+'-'+str(z) for y,z in zip(range(0,2000,500),range(500,2500,500))]
ax = fig.add_subplot(111)
for item,colour,name in zip(data[1:],colours,bins):
ax.scatter(x_series,item,marker=',',s=5,c=colour)
legend = mpatches.Patch(color=colour, label=name)
legends.append(legend)
ax.scatter(x_series,data[0],marker='o',c='k')
legend = mpatches.Patch(color='k', label='Full Dataset')
#legend = mpatches.Circle((0.5, 0.5), 1, facecolor='k', linewidth=3)
legends.append(legend)
leg = plt.legend(handles=legends, title='Distance along mountain front (500km bins)',ncol=6,loc='upper center', bbox_to_anchor=(0.5, 1.05))
plt.ylabel(r"Median $K_{sn}$")
plt.xlabel("Elevation (50m bins)")
leg.get_frame().set_alpha(1)
#adding inset histogram
new_axes = inset_axes(ax, width="40%",height="40%",bbox_to_anchor=(0.5,0.5,1200,300))
data_2 = getAxisHist("segmented_")
new_colour = []
new_colour.append('k')
for x in colours:
new_colour.append(x)
plt.hist(data_2,bins=x_series,stacked=True,color=new_colour[:5])
plt.title("Histogram of Data Points in Elevation Bins")
plt.ylabel("Frequency")
plt.xlabel("Elevation (50m bins)")
leg.get_frame().set_alpha(1)
fig.savefig('../elevation_scatter_500.png', bbox_inches='tight')