Challenge

Project 2

Early warning system:

Early warning system is an adaptive measure for climate change, using integrated communication systems to help communities prepare for hazardous climate-related events. A successful EWS saves lives and jobs, land and infrastructures and supports long-term sustainability.

# -*- coding: utf-8 -*-
"""
Created on Mon Mar  7 16:28:04 2022

@author: DELL
"""

# import libraries
import numpy as np
import pandas as pd
from scipy import integrate
import matplotlib.pyplot as plt
# show plots in notebook

#parameters
df = pd.read_csv('NSE-TATAGLOBAL11.csv')

# looking at the first five rows of the data
print(df.head())
print('\n Shape of the data:')
print(df.shape)
a = 0.7
b = 1.
r = 0.2
h = 1.  # half-saturation value
# take high p for steep Hill-function
p = 12

# determine strength of noise
sigma = 0.1

# define the system in a function
def Sys(X, t=0):
    # X[0] = x and x[1] = y    
    return np.array([a - b * X[0] + r *(X[0]**p / (X[0]**p + h**p))])

# generate 1000 linearly spaced numbers for x-axes
t = np.linspace(1, 10,  1000)
# initial value for X: 1
Sys0 = np.array([1])

# prepare plots
fig = plt.figure(figsize=(15,5))
ax1 = fig.add_subplot(1,1,1)

# loop through various r values
while r <= 1:
    # integrate system
    X, infodict = integrate.odeint(Sys, Sys0, t, full_output=True)
    #generate noise, sigma * x * dW
    noise = sigma * np.random.normal(0, 0.1, 1000)
    # transform x and y, and add noise
    x = X.T + noise*X.T
    # plot
    ax1.plot(x[0], label = 'r = %0.1f' % r)
    # increment r
    r += 0.2

# determine plotting specifics
ax1.grid()
ax1.legend(loc='best')
ax1.set_xlabel('time')
ax1.set_ylabel('Nutrient load')
ax1.set_title('Dynamics in time (parameter r)')
#critical slowing down (parameter r)
fig = plt.figure(figsize=(15,5))
ax2 = fig.add_subplot(1,1,1)

# reduce strength of noise to make differences more distinct
sigma = 0.01

x = np.linspace(400, 2000, 1600)
dt = 0.01
r = 0.2
# loop through various r values
while r < 0.6:
    P = []
    P.append(1)
    i = 0
    while (i < 2000):
        # perturb only when equilibrium is reached, here after 500 timesteps
        if i == 500:
            P[i] = P[i - 1] + 0.5
        # the difference equation with noise added
        P.append(P[i] + (a - b * P[i] + r * (P[i]**p / (P[i]**p + h**p))) * dt + sigma * P[i] * np.random.normal(0, 0.1))
        i += 1
    ax2.plot(x, P[400:2000], label = 'r = ' + str(r) + ', distance to tipping point = %0.1f' % (0.6 - r))
    r += 0.1

ax2.grid()
ax2.legend(loc='best')
ax2.set_xlabel('time')
ax2.set_title('Critical slowing down (parameter r)')

To start with, the following Python code generates a plot which shows that this model too has alternative stable states, depending on the parameter rr (for the nutrient recycling rate). Other than in the analyzing chapter, we add a small amount of noise to the development to let the behavior become a bit more realistic. The amplitude of this noise is determined by a parameter σσ.

The most prominent indicator in the conception of EWS is critical slowing down suggesting that a decreasing rate of recovery from small perturbations predicts the approachment of a tipping point (i.e. a critical transition). The next piece of Python-code generates a plot showing the above development with a small perturbation applied after reaching equilibrium (at timetime = 500). Testing different rr-values, the plot shows that recovery time increases with decreasing distance to the tipping point. In this case, in order to be able to intervene, the system is modeled in the form of a difference equation.

Another noticable Early Warning Signal is a system's back and forth oscillation between two stable states close to a critical transition. This oscillation has been called flickering and was observed among others on the model of lake eutrophication (Wang et al. 2012). In the following calculation we increase rr slowly and plot the system at timetime = 800. in order to show that flickering is noise-induced, we add a second curve (red) to the plot showing the same dynamics without added noise.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.