Created
April 26, 2017 18:00
-
-
Save lesserwhirls/debb06235520cb2d0b5577f1f21c4bbc to your computer and use it in GitHub Desktop.
Get spatial and temporal bounds from datasets listed in a catalog using NCSS
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from siphon.catalog import TDSCatalog\n", | |
"from siphon.ncss import NCSS" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true, | |
"deletable": true, | |
"editable": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# turn off noisy logging - fixed in PR https://github.com/Unidata/siphon/pull/127\n", | |
"import logging\n", | |
"log = logging.getLogger().setLevel(logging.ERROR)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true, | |
"deletable": true, | |
"editable": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# read catalog\n", | |
"cat_url = 'http://www.star.nesdis.noaa.gov/thredds//catalog/swathNPPVIIRSL2WW00/2017/108/catalog.xml'\n", | |
"viirs_swath_cat = TDSCatalog(cat_url)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false, | |
"deletable": true, | |
"editable": true | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"VRSVCW.B2017108.001304.nc\n", | |
" %s {'west': -174.8323, 'east': -126.6557, 'south': -58.2421, 'north': -46.5352}\n", | |
" %s {'begin': '2017-04-18T00:13:48.904Z', 'end': '2017-04-18T00:13:48.904Z'}\n", | |
"\n", | |
"VRSVCW.B2017108.001429.nc\n", | |
" %s {'west': -174.3289, 'east': -130.9466, 'south': -53.3018, 'north': -42.2289}\n", | |
" %s {'begin': '2017-04-18T00:15:14.309Z', 'end': '2017-04-18T00:15:14.309Z'}\n", | |
"\n", | |
"VRSVCW.B2017108.001554.nc\n", | |
" %s {'west': -174.1979, 'east': -134.5475, 'south': -48.3689, 'north': -37.795}\n", | |
" %s {'begin': '2017-04-18T00:16:39.714Z', 'end': '2017-04-18T00:16:39.714Z'}\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"# get spatial and temporal bounds for each dataset\n", | |
"datasets = list(viirs_swath_cat.datasets)\n", | |
"# let's just look at the first 3 datasets\n", | |
"for ds_name in datasets[0:3]:\n", | |
" ds = viirs_swath_cat.datasets[ds_name]\n", | |
" ncss_access_url = ds.access_urls['NetcdfSubset']\n", | |
" ncss = NCSS(ncss_access_url)\n", | |
" print(ds_name)\n", | |
" print(' %s', ncss.metadata.lat_lon_box)\n", | |
" print(' %s', ncss.metadata.time_span)\n", | |
" print('')\n", | |
" # now you can to checking to see if a given ds is within your lat/lon/time of interest" | |
] | |
} | |
], | |
"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.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment