Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Jupyter notebook 2016-11-15-200330/lab1.ipynb

27 views
Kernel: Python 3

Earth's Atmospheric Composition: Computer Laboratory #1

Paul Palmer, University of Edinburgh ([email protected])

Contents:

The learning objectives of this lab are:

  1. Understand what is an e-folding lifetime.

  2. Understand what determines the lifetime of a gas that is subject to different loss processes.

  3. Understand the relevance of an e-folding lifetime is to atmospheric composition.

This is a Jupyter notebook, which allows you to use the power of Python without much knowledge of the language.

To run the code below:

  1. Click on the cell to select it.

  2. Press SHIFT+ENTER on your keyboard or press the play button () in the toolbar above.

Exercise #1: Box model describing time-dependent mass of gas X

The following equation is a simple mass balance model that describes the change in mass of gas XX as a function of time tt: dXdt=SXτ,\begin{equation} \frac{dX}{dt} = S - \frac{X}{\tau}, \end{equation} where mass is determined by a source SS (mass/time) and a loss that is described by an e-folding lifetime τ\tau (time).

Rearranging and integrating this equation: X(t)=X0exptτ,\begin{equation} X(t)=X_0\exp^{-\frac{t}{\tau}}, \end{equation} where X0X_0 is the carbon mass at time t=0t=0.

The following piece of code describes this equation. In this example, we have ignored SS (SS=0), used τ=20\tau=20 seconds and X0_0=10 units. Below we explore the role of SS in the model.

%matplotlib inline from ipywidgets import widgets, interact, interactive from IPython.display import clear_output, display, HTML import numpy as np import pylab as plt import math tau = 20. # 1/seconds c_0 = 10. c = [] t = np.arange(100) for ii in np.arange(len(t)): c.append(c_0*np.exp(-t[ii]/tau)) plt.figure(figsize=(10,7)) plt.plot(t,c) plt.xlabel('Time [unit]') plt.ylabel('Atmospheric mass of carbon [unit]') plt.title('$C(t)=C_0\exp^{-t/tau}$')
<matplotlib.text.Text at 0x10713cba8>
Image in a Jupyter notebook

We can explore a few key concepts with this simple model: 1) e-folding lifetime and 2) mass balance.

From the figure above we can see that in the absence of a source the carbon mass progressively gets smaller, which is determined by τ\tau. Every time tt increases by a factor of τ\tau the carbon mass is reduced by a factor of ee, which has a value of approximately 2.72. At tt=τ\tau, C(τ)=C0exp1C(\tau)=C_0\exp^{-1} and when t=2τt=2\tau, C(2τ)=C0exp2C(2\tau) = C_0\exp^{-2}. For the example above (using C0=10C_0 = 10 units) C(τ)=10exp1=3.68C(\tau) = 10\exp^{-1} = 3.68, C(2τ)=10exp2=1.35C(2\tau) = 10\exp^{-2} = 1.35, ...

Below is an interactive version of the static figure above. The vertical and horizontal lines are giving you the corresponding values for tt and C(t)C(t) for tt=τ\tau and 2τ2\tau.

Activities

  1. Use the slider to explore how the lifetime affects C(t)C(t)

  2. Make sure you understand why in this model C(t)C(t) reduces in a way that can be described by multiples of ee.

  3. What is the value of C(3τ)C(3\tau)? Double check by adjusting the code.

%matplotlib inline from ipywidgets import widgets, interact, interactive from IPython.display import clear_output, display, HTML import numpy as np import pylab as plt import math def lifetime(tau): c_0 = 10. c = [] t = np.arange(100) for ii in np.arange(len(t)): c.append(c_0*np.exp(-t[ii]/tau)) plt.figure(figsize=(10,7)) plt.plot(t,c) # one e-folding lifetime cefold = np.exp(-1)*c_0 # two e-folding lifetimes twocefold = np.exp(-2)*c_0 print('C(t) at one e-folding lifetime: '+'{:5.2f}'.format(cefold)) print('C(t) at two e-folding lifetimes: '+'{:5.2f}'.format(twocefold)) plt.plot([tau,tau],[0,10],'--') plt.plot([2*tau,2*tau],[0,10],'--') plt.plot([tau],[cefold],'*') plt.plot([0,tau],[cefold,cefold]) plt.plot([2*tau],[twocefold],'*') plt.plot([0,2*tau],[twocefold,twocefold]) plt.xlabel('Time [unit]') plt.ylabel('Atmospheric mass of carbon [unit]') plt.title('$c(t)=c_0\exp^{-t/tau}$'+'; tau = '+str(tau)) interactive(lifetime,tau=(5,50,5))
C(t) at one e-folding lifetime: 3.68 C(t) at two e-folding lifetimes: 1.35
Image in a Jupyter notebook

Exercise #2: Mass balance box model of gas X

Let's return to the original mass balance equation as defined above: dXdt=SXτ,\begin{equation} \frac{dX}{dt} = S - \frac{X}{\tau}, \end{equation} where all variables are defined as above.

Activities

  1. In this activity we retain the source term SS.

  • Fix X0X_0 = 300 units and τ\tau = 120 units. Adjust the source term from the minimum value of 1 to the maximum value of 5. What do you find?

  • Return all the sliders back to their middle position. This time adjust the τ\tau slider from the smallest to the largest value. What do you find?

  • Now freely adjust the X0X_0 and τ\tau sliders. What do you find?

  1. For some pairs of model parameters (e.g., X0X_0 and τ\tau) you should have found a situation when X(t)X(t) remains fixed in time for the entire period. What does mean? Given the value for SS and τ\tau can you predict the fixed value?

  2. For other model parameter values you will have found that X(t)X(t) reached a steady value later in the run. What does that mean? Given the value for SS and τ\tau can you predict the final steady value?

  3. Do long-lived or short-lived gases respond quicker to changes in sources?

  4. How do you think an atmospheric gas would respond to a rapidly varying source and a source that has a slower mode of varibility?

%matplotlib inline from ipywidgets import widgets, interact, interactive from IPython.display import clear_output, display, HTML import numpy as np import pylab as plt import math def boxmodel(S,X0,tau): nyears = 1000 #2016-1957+1 X = [] years = [] # Initial conditions X.append(X0) years.append(1957) for ii in np.arange(nyears)+1: dX = S - (1./tau)*X[ii-1] X.append(X[ii-1]+dX) years.append(ii+1957) #print(S,(1./tau)*C[ii-1],C[ii]) plt.figure(figsize=(10,7)) plt.plot(years,X) plt.xlabel('Time [unit]') plt.xlim([1960,2600]) plt.ylabel('Atmospheric mass of gas X [unit]') interactive(boxmodel,S=(1,5,0.5),X0=(299,301,1),tau=(20,220,20))
Image in a Jupyter notebook