<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 ATM 623
Step1:  Homework questions
Step2:  The temperature data is called air. Take a look at the details
<ASSISTANT_TASK:>
Python Code:
#  Ensure compatibility with Python 2 and 3
from __future__ import print_function, division
Explanation: ATM 623: Climate Modeling
Brian E. J. Rose, University at Albany
Climate sensivity and the energy budget in CESM
Warning: content out of date and not maintained
You really should be looking at The Climate Laboratory book by Brian Rose, where all the same content (and more!) is kept up to date.
Here you are likely to find broken links and broken code.
In this assignment you will investigate how the CESM slab ocean model responds to a doubling of atmospheric CO2.
Refer to Assignment 2 for detailed instructions on how to access the CESM output.
Your assigment
Answer all questions listed in this notebook.
As before, write up your answers (including text, code and figures) in a new IPython notebook. Try to make sure that your notebook runs cleanly from start to finish, and explicitly imports every package that it uses.
Save your notebook as [your last name].ipynb, e.g. my notebook should be called Rose.ipynb.  
Submit your answers by email before class on Tuesday February 21.
End of explanation
import xarray as xr
url = "http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis.derived/surface_gauss/air.2m.mon.1981-2010.ltm.nc"
ncep_air2m = xr.open_dataset(url, decode_times=False)
## The NOAA ESRL server is shutdown! January 2019
#url = 'http://apdrc.soest.hawaii.edu:80/dods/public_data/Reanalysis_Data/NCEP/NCEP/clima/'
#ncep_air2m = xr.open_dataset(url + 'surface_gauss/air')
print( ncep_air2m)
Explanation: Homework questions: part A
Here we investigate differences between the control simulation and the 2xCO2 simulation (after it has reached its new, warmer equilibrium).
The two model output files you need are the control run:
som_1850_f19.cam.h0.clim.nc
and the doubled CO2 run:
som_1850_2xCO2.cam.h0.clim.nc
Calculate Equilibrium Climate Sensitivity (ECS) for the CESM slab ocean model.
Calculate the net TOA energy flux in the control run and in the equilibrated 2xCO2 run (time and global averages). Are they both close to zero?
What is the change in ASR and the change in OLR after doubling CO2?
What are the clear-sky and cloudy-sky components of those changes?
Make well-labeled maps of the change in the annual mean of these five quantities:
Surface temperature
ASR (total)
ASR (clear sky)
ASR (cloudy sky)
OLR (total)
OLR (clear sky)
OLR (cloud sky)
Comment on what you found in your maps.
Which regions warm more than others?
Are there any discernible spatial patterns in ASR and OLR changes?
What about the clear and cloudy sky components?
Comment on anything you find striking, interesting, or unexpected in these results.
Homework questions: part B
Here we investigate the transient adjustment to equilibrium.
For this, we will use the file
som_1850_2xCO2.cam.h0.global.nc
This file contains a monthly timeseries of the CESM model output from the 2xCO2 model run, which was initialized from the control run. Every variable in this file has already been averaged globally. We can use the timeseries to look at the adjustment of the global average temperature and energy budget to the new equilibrium.
Make a well-labeled graph of the timeseries of global mean surface temperature.
You will find that there is a well-defined annual cycle in this temperature. Offer a reasonable hypothesis to explain why such a cycle exists in the simulation.
Implement some kind of running average filter to smooth out the data. (There are many ways to do this... do whatever makes sense to you, but make sure your code is self-explanatory).
Make another graph of the smooth timeseries. Does it look anything like the exponential relaxation curves we found in the zero-dimensional EBM?
In another graph, plot smoothed verions of the timeseries of ASR and OLR.
Comment on anything interesting you learned from these figures.
Verifying the annual cycle in global mean surface temperature against observations
Here we still study the annual cycle in global mean surface temperature and verify it against observations. For observations, we will use the NCEP Reanalysis data.
Reanalysis data is really a blend of observations and output from numerical weather prediction models. It represents our “best guess” at conditions over the whole globe, including regions where observations are very sparse.
The necessary data are all served up over the internet. We will look at monthly climatologies averaged over the 30 year period 1981 - 2010.
The data catalog is here, please feel free to browse: http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis.derived/catalog.html
Surface air temperature is contained in a file called air.2m.mon.1981-2010.ltm.nc, which is found in the directory surface_gauss. 
Here's a link directly to the catalog page for this data file:
http://www.esrl.noaa.gov/psd/thredds/dodsC/Datasets/ncep.reanalysis.derived/surface_gauss/catalog.html?dataset=Datasets/ncep.reanalysis.derived/surface_gauss/air.2m.mon.1981-2010.ltm.nc
Now click on the OPeNDAP link. A page opens up with lots of information about the contents of the file. The Data URL is what we need to read the data into our Python session. For example, this code opens the file and displays a list of the variables it contains:
End of explanation
print( ncep_air2m.air)
Explanation: The temperature data is called air. Take a look at the details:
End of explanation
<END_TASK>