<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Since the current concentrations $N$ of $CO_2$ in the atmosphere is so high, the direct
dependence of the surface temperature $T$ on $N$ should be given approximately by
$$
T = T_0 + \Delta T {\log{N \over N_0} \over \log 2}\quad\quad\quad\text{(1)}
$$
Here $T_0$ is a reference temperature, say the temperature in 1980 and $N_0$ is the corresponding
atmospheric concentration of $CO_2$, say 340 ppm at Mauna Loa in 1980. From (1) we see
that doubling the CO2 concentration (letting $N = 2N_0$) will increase T by the temperature
sensitivity $\Delta T$.
Let's express $\Delta T$
Step1:  Let's fetch the raw data of $CO_2$ measurements at Mauna Loa from the noaa.gov website
Step2:  As explained in the file co2_mm_mlo.txt, the average column are the raw data of $CO_2$ values averaged over a month, and some months are missing. The trend then subtracts "seasonal cycle" computed over a 7 year window. The missing values in trend are then linearly interpolated. Finally, the average column then contains the trend value plus average seasonal cycle (i.e. average and interpolated contain the same values except for missing months, which are "intelligently" interpolated). We should do this analysis ourselves in the notebook directly from the average data only, but for now let's reuse this analysis.
Step3:  Let's get numbers for $N$ (year 2010) and $N_0$ (year 1980) by reading it off the $y$-axis
Step4:  Temperature changes
Warming from Berkeley Earth in the last 30 years (see a separate notebook for this calculation)
Step5:  Warming over the past 30 years using satellite measuremenets (see a separate notebook for this calculation)
Step6:  We'll use the satellite measurements, as arguably they have less systematic errors.
Temperature difference
Step7:  Calculation of temperature sensitivity
From equation (2) we then directly calculate
<ASSISTANT_TASK:>
Python Code:
%pylab inline
import urllib
Explanation: Since the current concentrations $N$ of $CO_2$ in the atmosphere is so high, the direct
dependence of the surface temperature $T$ on $N$ should be given approximately by
$$
T = T_0 + \Delta T {\log{N \over N_0} \over \log 2}\quad\quad\quad\text{(1)}
$$
Here $T_0$ is a reference temperature, say the temperature in 1980 and $N_0$ is the corresponding
atmospheric concentration of $CO_2$, say 340 ppm at Mauna Loa in 1980. From (1) we see
that doubling the CO2 concentration (letting $N = 2N_0$) will increase T by the temperature
sensitivity $\Delta T$.
Let's express $\Delta T$:
$$
\Delta T = (T - T_0) {\log 2 \over \log (N/N_0)}\quad\quad\quad\text{(2)}
$$
$CO_2$ Data
End of explanation
# Only execute this if you want to regenerate the downloaded file
open("data/co2_mm_mlo.txt", "wb").write(urllib.request.urlopen("ftp://ftp.cmdl.noaa.gov/ccg/co2/trends/co2_mm_mlo.txt").read())
D = loadtxt("data/co2_mm_mlo.txt")
years = D[:, 2]
average = D[:, 3]
interpolated = D[:, 4]
trend = D[:, 5]
Explanation: Let's fetch the raw data of $CO_2$ measurements at Mauna Loa from the noaa.gov website:
End of explanation
plot(years, interpolated, "r-", lw=1.5, label="monthly average")
plot(years, trend, "k-", label="trend")
xlabel("Year")
ylabel("$CO_2$ concentration [ppm]")
title("Atmospheric $CO_2$ concentrations at Mauna Loa")
legend(loc="upper left");
Explanation: As explained in the file co2_mm_mlo.txt, the average column are the raw data of $CO_2$ values averaged over a month, and some months are missing. The trend then subtracts "seasonal cycle" computed over a 7 year window. The missing values in trend are then linearly interpolated. Finally, the average column then contains the trend value plus average seasonal cycle (i.e. average and interpolated contain the same values except for missing months, which are "intelligently" interpolated). We should do this analysis ourselves in the notebook directly from the average data only, but for now let's reuse this analysis.
End of explanation
idx1980 = sum(years < 1980)
idx2010 = sum(years < 2010)
N0 = trend[idx1980]
N  = trend[idx2010]
print("N0 = %.2f ppm  (year %.3f)" % (N0, years[idx1980]))
print("N  = %.2f ppm  (year %.3f)" % (N,  years[idx2010]))
Explanation: Let's get numbers for $N$ (year 2010) and $N_0$ (year 1980) by reading it off the $y$-axis:
End of explanation
dTdt = 0.24995728742972512 # C / decade
Explanation: Temperature changes
Warming from Berkeley Earth in the last 30 years (see a separate notebook for this calculation):
End of explanation
dTdt = 0.13764588789937693 # C / decade
Explanation: Warming over the past 30 years using satellite measuremenets (see a separate notebook for this calculation):
End of explanation
dT = dTdt * 3 # 3 decades
dT
Explanation: We'll use the satellite measurements, as arguably they have less systematic errors.
Temperature difference:
End of explanation
from math import log
deltaT = dT * log(2) / log(1.0*N/N0)
print("∆T = ", deltaT, "C")
Explanation: Calculation of temperature sensitivity
From equation (2) we then directly calculate:
End of explanation
<END_TASK>