Skip to content

Instantly share code, notes, and snippets.

@flamingbear
Created January 15, 2014 21:12
Show Gist options
  • Save flamingbear/8444786 to your computer and use it in GitHub Desktop.
Save flamingbear/8444786 to your computer and use it in GitHub Desktop.
sample of computing extents from rutger's snowcover site.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Questions about NetCDF CDR data vs. File downloaded from Rutger's snow website.\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# require numpy and h5py\n",
"import numpy as np\n",
"import h5py\n"
],
"language": "python",
"outputs": [],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# use the Rutgers netcdf file\n",
"fn = '/Users/savoie/projects/sota/snowcover/input_data/nhsce_v01r01_19661004_20131202.nc'"
],
"language": "python",
"outputs": [],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"nc = h5py.File(fn, 'r')\n",
"lats = nc['latitude']\n",
"lons = nc['longitude']\n",
"area = nc['area']\n",
"time = nc['time']\n",
"data = nc['snow_cover_extent']"
],
"language": "python",
"outputs": [],
"prompt_number": 65
},
{
"cell_type": "markdown",
"source": [
"## The area of the grids in the files are 88x88\n",
"This is different from the 89x89 I expect from the documentation on the website.\n",
"[http://climate.rutgers.edu/snowcover/docs.php?target=vis]"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(area.shape)\n",
"print(data.shape)"
],
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"(88, 88)\n",
"(2461, 88, 88)\n"
]
}
],
"prompt_number": 66
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print( time[:])\n",
"print(dict(time.attrs.items())['units'])"
],
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[ 7 14 21 ..., 17213 17220 17227]\n",
"days since 1966-10-03\n"
]
}
],
"prompt_number": 61
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"def compute_area(idx):\n",
" # return the sum of the area grid * snow_cover_extent grid\n",
" griddata = area * data[idx, :, :]\n",
" return np.sum(griddata)"
],
"language": "python",
"outputs": [],
"prompt_number": 62
},
{
"cell_type": "markdown",
"source": [
"## Here's the first 10 values in `wkcov.nhland.txt` from \n",
"[http://climate.rutgers.edu/snowcover/files/wkcov.nhland.txt]\n",
"\n",
"\n",
" 1966 40 15187919\n",
" 1966 41 22836856\n",
" 1966 42 26497731\n",
" 1966 43 26952159\n",
" 1966 44 30329648\n",
" 1966 45 36078179\n",
" 1966 46 36287197\n",
" 1966 47 35991970\n",
" 1966 48 38597502\n",
" 1966 49 40541181\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"## here are the same values comptued from the NetCDF file."
],
"language": "python",
"outputs": [],
"prompt_number": 63
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for i in np.arange(10):\n",
" print \"{:8.0f}\".format(compute_area(i))\n"
],
"language": "python",
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"15187923\n",
"22836860\n",
"26497726\n",
"26952160\n",
"30329638\n",
"36078196\n",
"36287192\n",
"35991976\n",
"38597520\n",
"40541208\n"
]
}
],
"prompt_number": 64
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"## so I'm confused and can't reconcile the data from the rutgers text file and the data in the netcdf file."
],
"language": "python",
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"outputs": []
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment