Skip to content

Instantly share code, notes, and snippets.

@j08lue
Created June 25, 2015 09:03
Show Gist options
  • Save j08lue/c4a6b4bd504c0a7598b2 to your computer and use it in GitHub Desktop.
Save j08lue/c4a6b4bd504c0a7598b2 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import xray"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"url = 'http://data.nodc.noaa.gov/thredds/dodsC/cortad/Version5/cortadv5_FilledSST.nc'"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" <xray.DataArray 'FilledSST' (time: 15)>\n",
"array([ 299.42, 300.24, 301.07, 300.84, 299.36, 298.07, 299.2 ,\n",
" 299.13, 299.66, 300.2 , 299.72, 299.76, 299.32, 301.57,\n",
" 299.77])\n",
"Coordinates:\n",
" * time (time) datetime64[ns] 2012-09-18 2012-09-25 2012-10-02 ...\n",
" lat float32 ...\n",
" lon float32 ...\n",
"Attributes:\n",
" standard_name: sea_surface_skin_temperature\n",
" long_name: Gap-Filled weekly SST time series for 1982-01-02 to 2012-12-28\n",
" units: Kelvin\n",
" grid_mapping: crs\n",
" valid_min: -180\n",
" valid_max: 4500\n",
" land_value: -1100\n",
" missing_pixel_value: -1100\n",
" source: The weekly sea surface temperature is derived from Pathfinder 5.2 SST. \n",
"\n",
"raw: Gap-Filled weekly SST time series for 1982-01-02 to 2012-12-28 \n",
"\n",
"after load: Gap-Filled weekly SST time series for 1982-01-02 to 2012-12-28 \n",
"\n",
"after mean: "
]
},
{
"ename": "AttributeError",
"evalue": "'DataArray' object has no attribute 'long_name'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-28-6290fa2aaa73>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[1;34m'after load: '\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mload\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlong_name\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'\\n'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[1;34m'after mean: '\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdim\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'time'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlong_name\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m/climgeo/bluthgen/Software/anaconda/lib/python2.7/site-packages/xray/core/common.pyc\u001b[0m in \u001b[0;36m__getattr__\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m 133\u001b[0m \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 134\u001b[0m raise AttributeError(\"%r object has no attribute %r\" %\n\u001b[1;32m--> 135\u001b[1;33m (type(self).__name__, name))\n\u001b[0m\u001b[0;32m 136\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 137\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m__dir__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mAttributeError\u001b[0m: 'DataArray' object has no attribute 'long_name'"
]
}
],
"source": [
"with xray.open_dataset(url) as ds:\n",
" \n",
" data = ds['FilledSST'][-15:,2000,2000]\n",
"\n",
" print data, '\\n'\n",
" \n",
" print 'raw: ', data.long_name, '\\n'\n",
" \n",
" print 'after load: ', data.load().long_name, '\\n'\n",
" \n",
" print 'after mean: ', data.mean(dim='time').long_name\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment