Skip to content

Instantly share code, notes, and snippets.

@ocefpaf
Created November 24, 2015 20:47
Show Gist options
  • Save ocefpaf/ce7c23b25263050550c0 to your computer and use it in GitHub Desktop.
Save ocefpaf/ce7c23b25263050550c0 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "import iris\n\nurl = 'http://oos.soest.hawaii.edu/thredds/dodsC/pacioos/hycom/global'\n\ncubes = iris.load_raw(url)",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "print(cubes)",
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": "0: surface salinity trend (psu/day) / (1e-3 day-1) (time: 1229; latitude: 2170; longitude: 4500)\n1: sea_water_potential_temperature / (Celsius) (time: 3160; altitude: 10; latitude: 2170; longitude: 4500)\n2: sea_water_salinity / (1e-3) (time: 3160; altitude: 10; latitude: 2170; longitude: 4500)\n3: surface temperature trend (degc/day) / (Celsius day-1) (time: 1229; latitude: 2170; longitude: 4500)\n4: eastward_sea_water_velocity / (meter second-1) (time: 3160; altitude: 10; latitude: 2170; longitude: 4500)\n5: water_flux_into_ocean / (kg m-2 s-1) (time: 1229; latitude: 2170; longitude: 4500)\n6: ocean_mixed_layer_thickness / (m) (time: 1229; latitude: 2170; longitude: 4500)\n7: northward_sea_water_velocity / (meter second-1) (time: 3160; altitude: 10; latitude: 2170; longitude: 4500)\n8: surface_downward_heat_flux_in_air / (watt meter-2) (time: 1229; latitude: 2170; longitude: 4500)\n9: sea_surface_height / (meter) (time: 1229; latitude: 2170; longitude: 4500)\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "cube = cubes.extract_overlapping('sea_surface_height')\n\nprint(cube)",
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": "< No cubes >\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "from netCDF4 import Dataset\n\nwith Dataset(url) as nc:\n print(nc['ssh'])\n # Let's try to get the last step:\n nc['ssh'][-1, ...]",
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"text": "<type 'netCDF4._netCDF4.Variable'>\nfloat32 ssh(time2d, lat, lon)\n _FillValue: 1.26765e+30\n missing_value: 1.26765e+30\n long_name: sea surface elevation (m) \n units: meter\n standard_name: sea_surface_height\nunlimited dimensions: \ncurrent shape = (1229, 2170, 4500)\nfilling off\n\n",
"name": "stdout"
},
{
"output_type": "error",
"ename": "RuntimeError",
"evalue": "NetCDF: file not found",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-4-2c20be618964>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'ssh'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;31m# Let's try to get the last step:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mnc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'ssh'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m.\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32mnetCDF4/_netCDF4.pyx\u001b[0m in \u001b[0;36mnetCDF4._netCDF4.Variable.__getitem__ (netCDF4/_netCDF4.c:36349)\u001b[1;34m()\u001b[0m\n",
"\u001b[1;32mnetCDF4/_netCDF4.pyx\u001b[0m in \u001b[0;36mnetCDF4._netCDF4.Variable._get (netCDF4/_netCDF4.c:46119)\u001b[1;34m()\u001b[0m\n",
"\u001b[1;31mRuntimeError\u001b[0m: NetCDF: file not found"
]
}
]
}
],
"metadata": {
"kernelspec": {
"name": "python2",
"display_name": "Python 2",
"language": "python"
},
"language_info": {
"mimetype": "text/x-python",
"nbconvert_exporter": "python",
"name": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10",
"file_extension": ".py",
"codemirror_mode": {
"version": 2,
"name": "ipython"
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment