|
6 | 6 | """
|
7 | 7 |
|
8 | 8 | import pandas as pd
|
| 9 | +import numpy as np |
9 | 10 | import matplotlib.pyplot as plt
|
| 11 | +import statsmodels.formula.api as sm |
10 | 12 |
|
11 | 13 | # Read in data
|
12 | 14 | data = pd.read_csv("opal_ct.csv")
|
|
18 | 20 | ax1.set_ylabel('Depth below seafloor')
|
19 | 21 | # Make the y-axis label, ticks and tick labels match the line color.
|
20 | 22 | ax1.set_xlabel('Count', color='b')
|
| 23 | +plt.xlim(0,20) |
21 | 24 | ax1.tick_params('x', colors='b')
|
22 | 25 | ax2 = ax1.twiny()
|
23 | 26 | ax2.hist(data2['Depth_below_seafloor'], normed=1, histtype='step',cumulative=True, color='r', orientation='horizontal')
|
|
31 | 34 | data2['burial_rate'] = data2['Depth_below_seafloor'] / data2['Age_host_seds']
|
32 | 35 |
|
33 | 36 | # Plot data on a semilog plot
|
34 |
| -plt.scatter(data2['burial_rate'][data2['burial_rate'] < 3], data2['Depth_below_seafloor'][data2['burial_rate'] < 3], color='b') |
35 |
| -plt.scatter(data2['burial_rate'][data2['burial_rate'] > 3], data2['Depth_below_seafloor'][data2['burial_rate'] > 3], color='c') |
36 |
| -plt.scatter(data2['burial_rate'][data2['burial_rate']> 30], data2['Depth_below_seafloor'][data2['burial_rate'] > 30], color='r') |
| 37 | +plt.scatter(data2['burial_rate'][data2['burial_rate'] < 4], data2['Depth_below_seafloor'][data2['burial_rate'] < 4], color='b') |
| 38 | +plt.scatter(data2['burial_rate'][data2['burial_rate'] > 4], data2['Depth_below_seafloor'][data2['burial_rate'] > 4], color='c') |
| 39 | +plt.scatter(data2['burial_rate'][data2['burial_rate']> 40], data2['Depth_below_seafloor'][data2['burial_rate'] > 40], color='r') |
37 | 40 | plt.xlabel('Burial rate (m/Ma)')
|
38 | 41 | plt.ylabel('Depth (m)')
|
| 42 | +plt.ylim(0,1000) |
39 | 43 | ax = plt.gca()
|
40 | 44 | ax.invert_yaxis()
|
41 | 45 | ax.set_xscale('log')
|
42 | 46 | plt.show()
|
43 | 47 |
|
| 48 | +# Make cumulative hist for subsets of data |
| 49 | +fig, ax1 = plt.subplots(figsize=(4,5)) |
| 50 | +ax1.hist(data2['Depth_below_seafloor'][data2['burial_rate'] < 4], color='b', orientation='horizontal', bins=range(0,1000,100)) |
| 51 | +ax1.set_ylabel('Depth below seafloor') |
| 52 | +# Make the y-axis label, ticks and tick labels match the line color. |
| 53 | +ax1.set_xlabel('Count', color='b') |
| 54 | +ax1.set_xlim(0,15) |
| 55 | +ax1.set_ylim([0,1000]) |
| 56 | +ax1.tick_params('x', colors='b') |
| 57 | +ax2 = ax1.twiny() |
| 58 | +ax2.hist(data2['Depth_below_seafloor'][data2['burial_rate'] < 4], normed=1, histtype='step',cumulative=True, color='r', orientation='horizontal') |
| 59 | +ax2.set_xlabel('Cumulative frequency', color='r') |
| 60 | +ax2.tick_params('x', colors='r') |
| 61 | +ax2.set_ylim([0,1000]) |
| 62 | +plt.gca().invert_yaxis() |
| 63 | +fig.tight_layout() |
| 64 | +plt.show() |
| 65 | + |
| 66 | +fig, ax1 = plt.subplots(figsize=(4,5)) |
| 67 | +ax1.hist(data2.loc[(data2["burial_rate"] > 4) & (data2["burial_rate"] < 40), "Depth_below_seafloor"], color='c', orientation='horizontal', bins=range(0,1000,100)) |
| 68 | +ax1.set_ylabel('Depth below seafloor') |
| 69 | +# Make the y-axis label, ticks and tick labels match the line color. |
| 70 | +ax1.set_xlabel('Count', color='c') |
| 71 | +ax1.set_xlim(0,15) |
| 72 | +ax1.set_ylim([0,1000]) |
| 73 | +ax1.tick_params('x', colors='c') |
| 74 | +ax2 = ax1.twiny() |
| 75 | +ax2.hist(data2.loc[(data2["burial_rate"] > 4) & (data2["burial_rate"] < 40), "Depth_below_seafloor"], normed=1, histtype='step',cumulative=True, color='r', orientation='horizontal') |
| 76 | +ax2.set_xlabel('Cumulative frequency', color='r') |
| 77 | +ax2.tick_params('x', colors='r') |
| 78 | +ax2.set_ylim([0,1000]) |
| 79 | +plt.gca().invert_yaxis() |
| 80 | +fig.tight_layout() |
| 81 | +plt.show() |
| 82 | + |
| 83 | +fig, ax1 = plt.subplots(figsize=(4,5)) |
| 84 | +ax1.hist(data2['Depth_below_seafloor'][data2['burial_rate'] >40], color='r', orientation='horizontal', bins=range(0,1000,100)) |
| 85 | +ax1.set_ylabel('Depth below seafloor') |
| 86 | +# Make the y-axis label, ticks and tick labels match the line color. |
| 87 | +ax1.set_xlabel('Count', color='r') |
| 88 | +ax1.set_xlim(0,15) |
| 89 | +ax1.set_ylim([0,1000]) |
| 90 | +ax1.tick_params('x', colors='r') |
| 91 | +ax2 = ax1.twiny() |
| 92 | +ax2.hist(data2['Depth_below_seafloor'][data2['burial_rate'] >40], normed=1, histtype='step',cumulative=True, color='r', orientation='horizontal') |
| 93 | +ax2.set_xlabel('Cumulative frequency', color='r') |
| 94 | +ax2.tick_params('x', colors='r') |
| 95 | +ax2.set_ylim([0,1000]) |
| 96 | +plt.gca().invert_yaxis() |
| 97 | +fig.tight_layout() |
| 98 | +plt.show() |
| 99 | + |
| 100 | +# 0th order |
| 101 | +## plot cumulative freq against time |
| 102 | +# time = depth / burial rate |
| 103 | +# fit regression line, slope is reaction rate k. |
| 104 | + |
| 105 | +# For inversion, vector of A and vector of E (to make grid search). |
| 106 | +A = np.linspace(start=10e-2, stop=10e4, num=10) |
| 107 | +E = np.linspace(start=70, stop=110, num=10) |
| 108 | +misfit_grid = np.zeros((10,10)) |
| 109 | +# find temp at each point with a geothermal gradient of 30 degrees c and a surface temp of 0. |
| 110 | +data2['temp'] = data2['Depth_below_seafloor']/1000 * 30 |
| 111 | +# Find misfit as abs(predicted - real). Fill it into grid search. |
| 112 | +# Sort by depth |
| 113 | +data3 = data2.sort_values(by='Depth_below_seafloor') |
| 114 | +# Make column of cumulative percentage |
| 115 | +data3['cum_perc'] = np.cumsum(data3['Depth_below_seafloor'].values)/np.max(np.cumsum(data3['Depth_below_seafloor'].values)) * 100 |
| 116 | +result = sm.ols(formula="cum_perc ~ Depth_below_seafloor", data=data3).fit() |
| 117 | +k = result.params['Depth_below_seafloor'] |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | +# 1st order |
| 124 | +## plot ln(cumulative freq) against time |
| 125 | +# time = depth / burial rate |
| 126 | +# fit regression line, slope is -ve reaction rate k. |
| 127 | + |
| 128 | +# For inversion, vector of A and vector of E (to make grid search). |
| 129 | +# find temp at each point with a geothermal gradient of 30 degrees c and a surface temp of 0. |
| 130 | +# Find misfit as abs(predicted - real). Fill it into grid search. |
| 131 | + |
| 132 | + |
| 133 | +# Nucleation and growth reaction |
| 134 | +## plot ln(cumulative freq) against time |
| 135 | +# time = depth / burial rate |
| 136 | +# fit regression line, slope is -ve reaction rate k. |
| 137 | + |
| 138 | +# For inversion, vector of A and vector of E (to make grid search). |
| 139 | +# find temp at each point with a geothermal gradient of 30 degrees c and a surface temp of 0. |
| 140 | +# Find misfit as abs(predicted - real). Fill it into grid search. |
| 141 | + |
44 | 142 |
|
45 | 143 |
|
0 commit comments