Ejemplo n.º 1
0
import sys
sys.path.append('../../code/')
from data.utils import load_milanko
from scipy.signal import correlate, correlation_lags
from scipy.signal import butter, sosfiltfilt
from scipy.interpolate import interp1d
from fig_defaults import *

def norm(x):
    y = x - np.mean(x,0)
    return y/np.std(y,0)

mil_t, ecc, obliq, prec = load_milanko(direction='backward')
mil_t = mil_t[-10001:]
ecc = ecc[-10001:]

#benthic = np.load('../data/benthic.npy')
benthic = np.load('../../code/data/bin_isolated_ice_vol')
benf = interp1d(benthic[:,0],-benthic[:,1])
# --------- Fig for deciding band range ------------
fig, ax = plt.subplots(figsize=WIDE)
ax.set_xlim(0,0.08)
ax.set_ylim(0,100)
ax2 = ax.twinx()
ax2.set_ylim(0,1000)
epow = np.fft.fft(ecc)
ipow = np.fft.fft(benf(mil_t))
freq = np.fft.fftfreq(len(mil_t),mil_t[1]-mil_t[0])
ax.plot(freq[1:len(mil_t)//2],abs(epow[1:len(mil_t)//2]),label='Eccentricity')
ax2.plot(freq[1:len(mil_t)//2],abs(ipow[1:len(mil_t)//2]),'C1',label='Ice Volume')
ax.set_ylabel('Power')
Ejemplo n.º 2
0
""" Section taken from D-65, focussing just on fitting the orbital parameters
to the benthic data"""
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
from data.utils import load_milanko
from scipy.optimize import minimize
from scipy.signal import sosfiltfilt, butter, welch

param_names = ['c', 'b', 'e', 'r', 'B', 'E', 'R', 'tau', 'sqrt_l']
var_names = ['c', 'bet', 'eps', 'rho', 'seaB', 'seaE', 'seaR']

ben_t, benthic = np.load('data/band_benthic.npy').T

mil_t, ecc, obliq, prec = load_milanko()
prec = np.cos(prec)


def variance_explained(fit, data):
    band_fit = sosfiltfilt(
        butter(4, [1 / 150, 1 / 10], 'bandpass', output='sos', fs=t_n / win),
        fit)
    band_data = sosfiltfilt(
        butter(4, [1 / 150, 1 / 10], 'bandpass', output='sos', fs=t_n / win),
        data)
    tot_vari = np.var(band_data)
    resid_vari = np.var(band_data - band_fit)
    expl_vari = tot_vari - resid_vari
    return expl_vari / tot_vari

Ejemplo n.º 3
0
import numpy as np
import matplotlib.pyplot as plt
import sys
sys.path.append('../../code/')
from data.utils import load_milanko
from scipy.interpolate import interp1d
from matplotlib import rc
rc('text', usetex=True)
rc('font', family='serif', size=16)
rc('text.latex', preamble=r'\usepackage{wasysym}')

Q65 = np.loadtxt('../data/N65_insol.csv', delimiter=',')
t, ecc, obliq, rho = load_milanko()
ecc_fun = interp1d(t, ecc)
obliq_fun = interp1d(t, obliq)
benth = np.loadtxt('../data/benthic.csv', delimiter=',')
ben_fun = interp1d(benth[:, 0], benth[:, 1])

fig, ax = plt.subplots(4, 1, tight_layout=True, figsize=(10, 7))
t = np.linspace(-1000, 0, 3333)
ax[1].plot(t, Q65[-3333:], linewidth=2)
ax[0].plot(t, ecc_fun(t), 'C1', linewidth=2)
ax[2].plot(t, 180 / np.pi * obliq_fun(t), 'C2', linewidth=2)
ax[3].plot(t[::-1], ben_fun(t[::-1]), 'C3', linewidth=2)
ax[3].invert_yaxis()
ax[0].set_xticks([])
ax[2].set_xticks([])
ax[1].set_xticks([])
ax[3].set_xticks(-np.arange(1000, -1, -200))
ax[3].set_xticklabels(np.arange(1000, -1, -200))
ax[0].set_yticks([0, 0.05])
Ejemplo n.º 4
0
from data.utils import load_milanko
from scipy.interpolate import interp1d
from scipy.integrate import solve_ivp
from scipy.optimize import minimize
import matplotlib.pyplot as plt
import numpy as np
from benth_fit_sweep_odes import solve_I, fit_lstsqrs

mil_t, ecc, obliq, prec = load_milanko('backward')
eps = interp1d(mil_t, ecc)
bet = interp1d(mil_t, obliq)
rho = interp1d(mil_t, prec)

benthic = np.load('data/benthic.npy')
ben_fun = interp1d(benthic[:, 0], benthic[:, 1])


def variance_explained(fit, data, band=False):
    if band:
        fit = sosfiltfilt(
            butter(4, [1 / 150, 1 / 10],
                   'bandpass',
                   output='sos',
                   fs=t_n / (tmax - tmin)), fit)
        data = sosfiltfilt(
            butter(4, [1 / 150, 1 / 10],
                   'bandpass',
                   output='sos',
                   fs=t_n / (tmax - tmin)), data)
    tot_vari = np.var(data)
    resid_vari = np.var(data - fit)
Ejemplo n.º 5
0
from scipy.optimize import minimize
from matplotlib import rc
rc('text', usetex=True)
rc('font', family='serif', size=16)
rc('text.latex', preamble=r'\usepackage{wasysym}')

t_n = 10001
tmin = -1000
tmax = 0
t_span = np.linspace(tmin, tmax, t_n)
benthic = np.loadtxt('../data/benthic.csv', delimiter=',')
ben_fun = interp1d(benthic[:, 0], benthic[:, 1])
#benth = ben_fun(t_span)
benth = sosfiltfilt(butter(4, 1 / 19, 'low', output='sos', fs=10),
                    ben_fun(t_span))
mil_t, mil_ecc, mil_obliq, mil_l_peri = load_milanko()
eps_func = interp1d(mil_t, mil_ecc, 'cubic')
beta_func = interp1d(mil_t, mil_obliq, 'cubic')
rho_func = interp1d(mil_t, mil_l_peri, 'cubic')
fig, ax = plt.subplots(4, 1, figsize=(10, 11), tight_layout=True)
[a.plot(t_span, benth, 'k', linewidth=3) for a in ax]

########------ Quadratic Complex Analytical function of benthic from Q65, and orbital params  -------#######
av_eps = sosfiltfilt(butter(2, 1 / 60, 'low', output='sos'),
                     eps_func(np.linspace(-2000, 0, 2001)))
h = hilbert(eps_func(np.linspace(-2000, 0, 2001)) - av_eps)
f_eps = (eps_func(np.linspace(-2000, 0, 2001)) - av_eps) / np.abs(h)
filt_eps_func = interp1d(np.linspace(-2000, 0, 2001), f_eps)


def analytical_func(C, rm_var):
Ejemplo n.º 6
0
def norm(x):
    y = x - np.mean(x)
    return y / np.std(y)


""" 
https://www.ncdc.noaa.gov/abrupt-climate-change/Glacial-Interglacial%20Cycles

This shows how the Q65 insolation, which has period 23k (as precession),
correlates with the jump in co2/benthic when it coincides with increasing
eccentricity. This might mean the budyko model requires sub-year resolution as
the temperature in summer is relating to the initiation of the inter-glacial."""

N_insol = np.loadtxt('data/NQ65.csv', delimiter=',')
S_insol = np.loadtxt('data/SQ65.csv', delimiter=',')
t, ecc, obliq, l_peri = load_milanko(direction='backward')
rho = (3 / 2 * np.pi - l_peri) % (2 * np.pi)
benth = np.loadtxt(
    'data/benthic.csv',
    delimiter=',')  #https://lorraine-lisiecki.com/LisieckiRaymo2005.pdf
temp = np.loadtxt(
    'data/delta_temp.csv',
    delimiter=',')  #https://www.nature.com/articles/nature06015#rightslink
carbon = np.loadtxt(
    'data/co2.csv',
    delimiter=',')  #https://www.nature.com/articles/nature06949
ecc_fun = interp1d(t, ecc)
rho_fun = interp1d(t, rho)
obliq_fun = interp1d(t, obliq)
ben_fun = interp1d(benth[:, 0], benth[:, 1])
carbon_func = interp1d(carbon[:, 0], carbon[:, 1])
Ejemplo n.º 7
0
# Range over 25kyr = 46e6 Gt
ben_range = np.ptp(ice_cont[-51:, 1])
ice_vol = (ice_cont[:, 1] - np.mean(ice_cont[:, 1])) / ben_range * 46e6
ice_vol = ice_vol - ice_vol[-1] + 27.685e6
ice_vol_fun = interp1d(ice_cont[:, 0], ice_vol)
# Use https://bit.ly/3rvXMfB which gives antarctic temp as having range
# 15C, with average temp (at dome C) of -54C
# https://en.wikipedia.org/wiki/Dome_C#Climate
ALPHA_S = -54
# c given as rough scale between eps and ocean [0,0.06] > [-1,2]
# Although https://bit.ly/3uav5G5 says this range is [-2,3] so maybe use instead
C = 50
# Alpha_O is -1 to shift from max eps of 0.06 to 50*0.06 - 1 = 2
ALPHA_O = -1
ALPHA_O_ = ALPHA_O / C
mil_t, ecc, obliq, prec = load_milanko(interp=False)
eps = interp1d(mil_t, ecc)
bet = interp1d(mil_t, obliq)
rho = interp1d(mil_t, prec)


def variance_explained(fit, data, band=False):
    if band:
        fit = sosfiltfilt(
            butter(4, [1 / 150, 1 / 10],
                   'bandpass',
                   output='sos',
                   fs=t_n / (tmax - tmin)), fit)
        data = sosfiltfilt(
            butter(4, [1 / 150, 1 / 10],
                   'bandpass',
Ejemplo n.º 8
0
from matplotlib import rc
rc('text', usetex=True)
rc('font', family='serif',size=16)
rc('text.latex', preamble=r'\usepackage{wasysym}')

tmin = -1000
tmax = 0
t_n = 10001
t_span = np.linspace(tmin, tmax, t_n)
benthic = np.loadtxt('../data/benthic.csv',delimiter=',')
ben_fun = interp1d(benthic[:,0],benthic[:,1])
#smooth_benth = savgol_filter(ben_fun(t_span), 101, 3)
smooth_benth = sosfiltfilt(butter(4, 1/19, 'low', output='sos', fs=10),ben_fun(t_span))
#smooth_benth = ben_fun(t_span)

mil_t, mil_ecc, mil_obliq, mil_rho = load_milanko()
eps_func = interp1d(mil_t, mil_ecc, 'cubic')
beta_func = interp1d(mil_t, mil_obliq, 'cubic')
rho_func = interp1d(mil_t, mil_rho, 'cubic')
########------ Simple Analytical function of benthic from and orbital params  -------#######
av_eps = sosfiltfilt(butter(2, 1/60, 'low', output='sos'), eps_func(np.linspace(-2000,0,2001)))
h = hilbert(eps_func(np.linspace(-2000,0,2001))-av_eps)
f_eps = (eps_func(np.linspace(-2000,0,2001))-av_eps)/np.abs(h)
filt_eps_func = interp1d(np.linspace(-2000,0,2001),f_eps)

#Shouldnt need the three offset terms as they would be absorbed into c, but
#seems to produce a higher prop vari explained so will leave them in
def analytical_func(C):
    c,b,e,r,l,o_e = C
    l = abs(l)+0.1
    bet = beta_func(t_span-l)