diff --git a/.gitignore b/.gitignore index 740c0841..e081b5b0 100755 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,5 @@ Anaconda-2.0.1-Linux-*.sh # notebook generated temp dirs # ################################ tmp_img/ +data/new.nc +data/new2.nc diff --git a/data/new.nc b/data/new.nc deleted file mode 100644 index 3cdcd241..00000000 Binary files a/data/new.nc and /dev/null differ diff --git a/data/new2.nc b/data/new2.nc deleted file mode 100644 index fc08533c..00000000 Binary files a/data/new2.nc and /dev/null differ diff --git a/notebooks/writing_netCDF.ipynb b/notebooks/writing_netCDF.ipynb index 6b33592f..6d908ccf 100644 --- a/notebooks/writing_netCDF.ipynb +++ b/notebooks/writing_netCDF.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 1, "metadata": { "collapsed": false, "internals": { @@ -62,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 2, "metadata": { "collapsed": false, "internals": { @@ -80,7 +80,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", + "\n", "root group (NETCDF4_CLASSIC data model, file format HDF5):\n", " dimensions(sizes): \n", " variables(dimensions): \n", @@ -124,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 3, "metadata": { "collapsed": false, "internals": { @@ -142,11 +142,11 @@ "name": "stdout", "output_type": "stream", "text": [ - "('lat', : name = 'lat', size = 73\n", + "('lat', : name = 'lat', size = 73\n", ")\n", - "('lon', : name = 'lon', size = 144\n", + "('lon', : name = 'lon', size = 144\n", ")\n", - "('time', (unlimited): name = 'time', size = 0\n", + "('time', (unlimited): name = 'time', size = 0\n", ")\n" ] } @@ -182,7 +182,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 4, "metadata": { "collapsed": false, "internals": { @@ -255,7 +255,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 5, "metadata": { "collapsed": false, "internals": { @@ -273,13 +273,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", + "\n", "float64 temp(time, lat, lon)\n", " units: K\n", " standard_name: air_temperature\n", "unlimited dimensions: time\n", "current shape = (0, 73, 144)\n", - "filling on, default _FillValue of 9.96920996839e+36 used\n", + "filling on, default _FillValue of 9.969209968386869e+36 used\n", "\n" ] } @@ -325,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 6, "metadata": { "collapsed": false, "internals": { @@ -344,10 +344,10 @@ "output_type": "stream", "text": [ "-- Some pre-defined attributes for variable temp:\n", - "('temp.dimensions:', (u'time', u'lat', u'lon'))\n", - "('temp.shape:', (0, 73, 144))\n", - "('temp.dtype:', dtype('float64'))\n", - "('temp.ndim:', 3)\n" + "temp.dimensions: ('time', 'lat', 'lon')\n", + "temp.shape: (0, 73, 144)\n", + "temp.dtype: float64\n", + "temp.ndim: 3\n" ] } ], @@ -379,7 +379,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 7, "metadata": { "collapsed": false, "internals": { @@ -395,8 +395,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "('-- Wrote data, temp.shape is now ', (3, 73, 144))\n", - "('-- Min/Max values:', 280.00283562143028, 329.99987991477548)\n" + "-- Wrote data, temp.shape is now (3, 73, 144)\n", + "-- Min/Max values: 280.002172874 329.997336101\n" ] } ], @@ -438,7 +438,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 8, "metadata": { "collapsed": false, "internals": { @@ -455,7 +455,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "('-- Wrote more data, temp.shape is now ', (4, 73, 144))\n" + "-- Wrote more data, temp.shape is now (4, 73, 144)\n" ] } ], @@ -483,7 +483,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 9, "metadata": { "collapsed": false, "internals": { @@ -501,18 +501,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", + "\n", "float64 time(time)\n", " units: hours since 1800-01-01\n", " long_name: time\n", "unlimited dimensions: time\n", "current shape = (4,)\n", - "filling on, default _FillValue of 9.96920996839e+36 used\n", + "filling on, default _FillValue of 9.969209968386869e+36 used\n", "\n", - "(, masked_array(data = [-- -- -- --],\n", - " mask = [ True True True True],\n", - " fill_value = 9.96920996839e+36)\n", - ")\n" + " [-- -- -- --]\n" ] } ], @@ -542,7 +539,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 10, "metadata": { "collapsed": false, "internals": { @@ -561,17 +558,17 @@ "output_type": "stream", "text": [ "[datetime.datetime(2014, 10, 1, 0, 0), datetime.datetime(2014, 10, 2, 0, 0), datetime.datetime(2014, 10, 3, 0, 0), datetime.datetime(2014, 10, 4, 0, 0)]\n", - "(array([ 1882440., 1882464., 1882488., 1882512.]), u'hours since 1800-01-01')\n", + "[ 1882440. 1882464. 1882488. 1882512.] hours since 1800-01-01\n", "[datetime.datetime(2014, 10, 1, 0, 0) datetime.datetime(2014, 10, 2, 0, 0)\n", " datetime.datetime(2014, 10, 3, 0, 0) datetime.datetime(2014, 10, 4, 0, 0)]\n" ] } ], "source": [ - "from datetime import datetime\n", + "import datetime as dt\n", "from netCDF4 import date2num,num2date\n", "# 1st 4 days of October.\n", - "dates = [datetime(2014,10,1,0),datetime(2014,10,2,0),datetime(2014,10,3,0),datetime(2014,10,4,0)]\n", + "dates = [dt.datetime(2014,10,1,0),dt.datetime(2014,10,2,0),dt.datetime(2014,10,3,0),dt.datetime(2014,10,4,0)]\n", "print(dates)\n", "times = date2num(dates, time.units)\n", "print(times, time.units) # numeric values\n", @@ -603,7 +600,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 11, "metadata": { "collapsed": false, "internals": { @@ -621,7 +618,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", + "\n", "root group (NETCDF4_CLASSIC data model, file format HDF5):\n", " title: My model data\n", " dimensions(sizes): lat(73), lon(144), time(4)\n", @@ -661,7 +658,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 12, "metadata": { "collapsed": false, "internals": { @@ -679,7 +676,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", + "\n", "root group (NETCDF4 data model, file format HDF5):\n", " dimensions(sizes): \n", " variables(dimensions): \n", @@ -722,7 +719,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 13, "metadata": { "collapsed": false, "internals": { @@ -740,13 +737,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "('model_run1', \n", + "('model_run1', \n", "group /model_run1:\n", " dimensions(sizes): \n", " variables(dimensions): \n", " groups: \n", ")\n", - "('model_run2', \n", + "('model_run2', \n", "group /model_run2:\n", " dimensions(sizes): \n", " variables(dimensions): \n", @@ -780,7 +777,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 14, "metadata": { "collapsed": false, "internals": { @@ -819,7 +816,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 15, "metadata": { "collapsed": false, "internals": { @@ -837,13 +834,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "('model_run1', \n", + "('model_run1', \n", "group /model_run1:\n", " dimensions(sizes): \n", " variables(dimensions): float64 \u001b[4mtemp\u001b[0m(time,lat,lon)\n", " groups: \n", ")\n", - "('model_run2', \n", + "('model_run2', \n", "group /model_run2:\n", " dimensions(sizes): \n", " variables(dimensions): float64 \u001b[4mtemp\u001b[0m(time,lat,lon)\n", @@ -886,7 +883,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 16, "metadata": { "collapsed": false, "internals": { @@ -904,14 +901,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "\n", + "\n", "compound cmplx_var(time, lat, lon)\n", "compound data type: [('real', '\n", + "\n", "vlen phony_vlen_var(time, lat, lon)\n", "vlen data type: int64\n", "path = /model_run2\n", "unlimited dimensions: time\n", "current shape = (1, 73, 144)\n", "\n", - "('data =\\n', array([[[array([0, 4, 0, 9, 2, 2, 2, 4, 2]), array([7, 5, 4, 4, 9, 8, 0]),\n", - " array([3, 6, 6, 8, 2, 7]), ..., array([5, 0, 0, 8, 8, 1, 5, 3]),\n", - " array([4, 2, 7]), array([0])],\n", - " [array([5, 6, 6, 6, 1, 0, 7]), array([7]),\n", - " array([7, 5, 8, 9, 6, 9, 3]), ..., array([0, 6, 5, 4]),\n", - " array([7, 1, 9, 7, 7, 2]), array([1, 4, 0])],\n", - " [array([4, 3, 1]), array([6, 3, 9, 7, 8]), array([8]), ...,\n", - " array([6, 5, 8, 0]), array([0]), array([0, 9, 6, 2, 4])],\n", - " ..., \n", - " [array([8, 4, 4]), array([4, 1, 6]), array([1, 4, 2, 3, 9]), ...,\n", - " array([9, 1]), array([7, 2, 5, 1, 5, 8, 2]),\n", - " array([2, 9, 9, 1, 4, 6, 3, 5, 2])],\n", - " [array([4, 7, 9, 8, 2, 3, 6, 6]),\n", - " array([1, 4, 1, 6, 1, 1, 2, 3, 9]),\n", - " array([9, 5, 6, 2, 4, 3, 8, 2, 9]), ..., array([9, 5, 7]),\n", - " array([3, 9]), array([4, 2, 6, 9])],\n", - " [array([8, 9, 9, 2, 2, 8, 8, 5]), array([3]),\n", - " array([8, 8, 0, 2, 9, 2, 3, 0, 9]), ..., array([7]),\n", - " array([5, 1, 0, 6, 8, 6]), array([8, 6, 3, 6, 9, 8, 4, 2, 5])]]], dtype=object))\n" + "data =\n", + " [[[array([3, 7]) array([6, 1, 6, 4, 2]) array([2, 0]) ...,\n", + " array([8, 5, 6, 8, 6, 1, 5, 4]) array([5, 0, 8, 2, 0, 1, 7, 9, 8])\n", + " array([0, 6])]\n", + " [array([8, 1, 9, 8, 3, 0, 7]) array([7, 9, 2, 3, 0, 2, 1, 5])\n", + " array([6, 1, 0]) ..., array([1, 7, 9, 7, 1, 9, 4, 7]) array([6, 2, 1])\n", + " array([5, 8, 8, 8, 3, 3, 3])]\n", + " [array([9, 3, 3, 7, 5]) array([1, 4, 2, 7, 3]) array([7]) ...,\n", + " array([3, 9, 0, 8, 5]) array([2, 0, 4, 2, 6, 4, 8, 9, 0])\n", + " array([3, 7, 7])]\n", + " ..., \n", + " [array([7, 6, 5, 6]) array([3]) array([9, 4, 4, 6, 0, 4]) ...,\n", + " array([5, 4]) array([2]) array([3])]\n", + " [array([6, 5, 0, 8]) array([0, 0, 6, 3, 8, 7, 6])\n", + " array([2, 3, 2, 4, 9, 4]) ..., array([0, 1, 4]) array([1, 9, 4, 5, 7])\n", + " array([7, 5, 5])]\n", + " [array([2, 2, 5, 3, 1, 3, 1, 3, 6]) array([2, 0, 5, 9])\n", + " array([2, 4, 4, 2, 2, 6, 9, 3]) ..., array([2]) array([3])\n", + " array([9, 3, 4, 8])]]]\n" ] } ], @@ -1108,7 +1105,7 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 20, "metadata": { "collapsed": false, "internals": {