Created
November 29, 2017 08:31
-
-
Save rutj3/ed6089ff369590ec3a26863645c06e67 to your computer and use it in GitHub Desktop.
netCDF4 issue
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'1.3.1'" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import netCDF4\n", | |
"netCDF4.__version__" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"url = r'http://opendap.nccs.nasa.gov:9090/dods/GEOS-5/fp/0.25_deg/assim/tavg1_2d_slv_Nx'\n", | |
"\n", | |
"f = netCDF4.Dataset(url)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# 2014-08-20\n", | |
"# 2014-08-21\n", | |
"lyrs = [4344, 4367]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"px, py = (672, 340)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Each layer individually" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"4344 89590.7\n", | |
"4345 89625.9\n", | |
"4346 89681.0\n", | |
"4347 89769.1\n", | |
"4348 89844.6\n", | |
"4349 89890.8\n", | |
"4350 89933.8\n", | |
"4351 89892.6\n", | |
"4352 89824.8\n", | |
"4353 89723.4\n", | |
"4354 89626.7\n", | |
"4355 89534.5\n", | |
"4356 89448.9\n", | |
"4357 89420.2\n", | |
"4358 89449.0\n", | |
"4359 89510.3\n", | |
"4360 89577.4\n", | |
"4361 89627.6\n", | |
"4362 89692.8\n", | |
"4363 89725.6\n", | |
"4364 89702.9\n", | |
"4365 89658.8\n", | |
"4366 89599.8\n", | |
"4367 89557.8\n" | |
] | |
} | |
], | |
"source": [ | |
"for lyr in range(lyrs[0], lyrs[1]+1): \n", | |
" print(lyr, f.variables['ps'][lyr, py, px])" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### All layers at once" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([ 89590.734375 , 89625.90625 , 89681. , 276.59707642,\n", | |
" 276.59747314, 218.75848389, 216.04185486, 216.07647705,\n", | |
" 216.07681274, 216.08854675, 216.14804077, 218.81274414,\n", | |
" 238.08773804, 266.54556274, 266.35198975, 266.8302002 ,\n", | |
" 269.02648926, 269.08581543, 269.2666626 , 269.28094482,\n", | |
" 269.25271606, 269.30371094, 271.02593994, 274.77075195], dtype=float32)" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"f.variables['ps'][lyrs[0]:lyrs[1]+1, py, px]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Start five layers \"later\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([ 89890.796875 , 89933.8046875, 89892.59375 , 89824.765625 ,\n", | |
" 89723.4140625, 89626.7421875, 89534.5 , 89448.8671875,\n", | |
" 89420.21875 , 89448.9765625, 89510.25 , 89577.4453125,\n", | |
" 89627.609375 , 89692.8046875, 89725.6484375, 89702.8671875,\n", | |
" 89658.8203125, 89599.7734375, 89557.765625 ], dtype=float32)" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"f.variables['ps'][lyrs[0]+5:lyrs[1]+1, py, px]" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment