-
Notifications
You must be signed in to change notification settings - Fork 0
/
old_funcs
47 lines (38 loc) · 2.47 KB
/
old_funcs
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
def plot_lambda(data_dict, max_gamma=1000, max_superelevation=30, frac=.2, ci=90):
# Determine the number of rows needed based on the number of names and a max of 4 columns
num_plots = len(data_dict)
num_columns = min(num_plots, 4)
num_rows = (num_plots + num_columns - 1) // num_columns # Ceiling division to get number of rows needed
fig, axs = plt.subplots(num_rows, num_columns, figsize=(3*num_columns, 3*num_rows), squeeze=False)
for name, details in data_dict.items():
ax = axs.flatten()[list(data_dict.keys()).index(name)]
print(f'Processing {name}...')
df = process_data(f'data/{name}_output.csv', max_gamma=max_gamma, max_superelevation=max_superelevation)
if name == 'V7':
df = df[df['dist_out'] > 2080699]
df = df[df['lambda'] > .1]
df = df[df['lambda'] < 300]
# Convert 'dist_out' from meters to kilometers
df['dist_out'] = df['dist_out'] / 1000
# Compute the LOWESS smoothed curve for lambda
smoothed_lambda = lowess(df['lambda'], df['dist_out'], frac=frac)
#ax.hlines(y=2, xmin=df['dist_out'].min(), xmax=df['dist_out'].max(), color='black', linestyle='--', lw=1.5, zorder=1)
ax.set_xlabel('Distance along reach (km)')
ax.set_ylabel('Lambda')
ax.set_yscale('log')
ax.invert_xaxis() # Reverse the x-axis
ax.set_title(name) # Set the title of the plot to the name
# Fill the area between the start and end of the avulsion belt across the entire y-axis
ax.fill_betweenx(y=[0, 1], x1=details['avulsion_belt'][0], x2=details['avulsion_belt'][1], color='gray', alpha=0.3, transform=ax.get_xaxis_transform())
# Plot the avulsion_dist_out as vertical black dashed lines behind the data
for dist_out in details.get('avulsion_lines', []):
ax.axvline(x=dist_out, color='k', linestyle='--', zorder=1)
# Plot the crevasse_splay_dist_out as vertical dark blue dotted lines behind the data
for dist_out in details.get('crevasse_splay_lines', []):
ax.axvline(x=dist_out, color='blue', linestyle=':', zorder=1)
# Ensure scatter plot and LOWESS curve are plotted above the vertical lines
sns.scatterplot(data=df, x='dist_out', y='lambda', color='#26C6DA', marker='^', edgecolor='k', s=65, ax=ax, zorder=2)
ax.plot(smoothed_lambda[:, 0], smoothed_lambda[:, 1], 'r-', zorder=2)
# Adjust layout to prevent overlap
plt.tight_layout()
plt.show()