Created
April 18, 2014 01:33
-
-
Save douglatornell/11020457 to your computer and use it in GitHub Desktop.
IPython Notebook Exploring How netCDF4 Variable fill_value=0 Works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from __future__ import print_function\n", | |
"\n", | |
"import netCDF4 as nc\n", | |
"import numpy as np" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 56 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"foo = nc.Dataset('foo.nc', 'w', zlib=True)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 57 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"foo.createDimension('x', 10)\n", | |
"x = foo.createVariable('x', 'float32', ('x',), fill_value=0, least_significant_digit=1, zlib=True)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 58 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"foo.close()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 59 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"!ncdump -c foo.nc" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"netcdf foo {\r\n", | |
"dimensions:\r\n", | |
"\tx = 10 ;\r\n", | |
"variables:\r\n", | |
"\tfloat x(x) ;\r\n", | |
"\t\tx:_FillValue = 0.f ;\r\n", | |
"\t\tx:least_significant_digit = 1L ;\r\n", | |
"data:\r\n", | |
"\r\n", | |
" x = _, _, _, _, _, _, _, _, _, _ ;\r\n", | |
"}\r\n" | |
] | |
} | |
], | |
"prompt_number": 60 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"bar = nc.Dataset('bar.nc', 'w', zlib=True)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 66 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"bar.createDimension('x', 10)\n", | |
"x = bar.createVariable('x', 'float32', ('x',), fill_value=0, least_significant_digit=1, zlib=True)\n", | |
"z = np.ma.masked_equal(np.zeros(10), 0)\n", | |
"x[:] = z\n", | |
"z" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 67, | |
"text": [ | |
"masked_array(data = [-- -- -- -- -- -- -- -- -- --],\n", | |
" mask = [ True True True True True True True True True True],\n", | |
" fill_value = 0.0)\n" | |
] | |
} | |
], | |
"prompt_number": 67 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"bar.close()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 68 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"!ncdump -c bar.nc" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"netcdf bar {\r\n", | |
"dimensions:\r\n", | |
"\tx = 10 ;\r\n", | |
"variables:\r\n", | |
"\tfloat x(x) ;\r\n", | |
"\t\tx:_FillValue = 0.f ;\r\n", | |
"\t\tx:least_significant_digit = 1L ;\r\n", | |
"data:\r\n", | |
"\r\n", | |
" x = _, _, _, _, _, _, _, _, _, _ ;\r\n", | |
"}\r\n" | |
] | |
} | |
], | |
"prompt_number": 69 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"baz = nc.Dataset('baz.nc', 'w')" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 70 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"baz.createDimension('x', 10)\n", | |
"x = bar.createVariable('x', 'float32', ('x',), zlib=True)\n", | |
"x[:] = np.zeros(10)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 71 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"baz.close()" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 72 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"!ncdump -c baz.nc" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"netcdf baz {\r\n", | |
"dimensions:\r\n", | |
"\tx = 10 ;\r\n", | |
"variables:\r\n", | |
"\tfloat x(x) ;\r\n", | |
"data:\r\n", | |
"\r\n", | |
" x = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;\r\n", | |
"}\r\n" | |
] | |
} | |
], | |
"prompt_number": 73 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [] | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment