Skip to content

Instantly share code, notes, and snippets.

@rsignell-usgs
Created September 2, 2021 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsignell-usgs/d7fa16be2bb4323ae9d700a17b1fe2cb to your computer and use it in GitHub Desktop.
Save rsignell-usgs/d7fa16be2bb4323ae9d700a17b1fe2cb to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a8898c2e-4ec6-41ca-846a-c7241bfb6cc9",
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import fsspec"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d2dbea82-491e-4c07-b711-ab13619b8b4c",
"metadata": {},
"outputs": [],
"source": [
"fs = fsspec.filesystem('s3', anon=True)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d68a4293-5e78-45ad-96ca-84bcb6008785",
"metadata": {},
"outputs": [],
"source": [
"url = 's3://noaa-hrrr-bdp-pds/hrrr.20210902/conus/hrrr.t12z.wrfsfcf01.grib2'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f14691c4-4d86-4dee-b4ff-5c30270fb8c5",
"metadata": {},
"outputs": [],
"source": [
"_ = fs.download(url, 'test.grib2')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f9332063-90c5-4852-bef0-0c8a3618ac51",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Ignoring index file 'test.grib2.9810b.idx' older than GRIB file\n"
]
}
],
"source": [
"ds = xr.open_dataset('test.grib2', engine='cfgrib', \n",
" backend_kwargs={'filter_by_keys': {'typeOfLevel': 'heightAboveGround', 'level': 2}}) "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "57d64a94-2c91-4460-90fb-37fb7f6e8390",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Data variables:\n",
" unknown (y, x) float32 ...\n",
" t2m (y, x) float32 ...\n",
" pt (y, x) float32 ...\n",
" sh2 (y, x) float32 ...\n",
" d2m (y, x) float32 ...\n",
" r2 (y, x) float32 ..."
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds.data_vars"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1a26c620-cc15-4c37-8bff-dcf420821519",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Ignoring index file 'test.grib2.9810b.idx' older than GRIB file\n"
]
},
{
"data": {
"text/plain": [
"Data variables:\n",
" u10 (y, x) float32 ...\n",
" v10 (y, x) float32 ...\n",
" si10 (y, x) float32 ...\n",
" unknown (y, x) float32 ..."
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds1 = xr.open_dataset('test.grib2', engine='cfgrib', \n",
" backend_kwargs={'filter_by_keys': {'typeOfLevel': 'heightAboveGround', 'level': 10}}) \n",
"ds1.data_vars"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cce0dc27-926b-44e2-a34b-99b11b470990",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:pangeo]",
"language": "python",
"name": "conda-env-pangeo-py"
},
"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.9.6"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment