-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add notebook to check Herbie's CRS extraction matches pygrib
- Loading branch information
1 parent
9ffc5a3
commit 925abb5
Showing
9 changed files
with
375,082 additions
and
6,669 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Check CRS extraction\n", | ||
"\n", | ||
"I was having issues with pygrib running into segmentation faults in my GitHub Actions after it was updated to support Numpy v2+. I was only using pygrib to extract coordinate reference system (CRS) data, and I would like to remove it as a dependency.\n", | ||
"\n", | ||
"Here I am comparing the CRS proj parameters extracted by pygrib and what is extracted by Herbie (from the keys read by cfgrib). \n", | ||
"\n", | ||
"**Since pygrib doesn't work in GitHub actions for me for whatever reason, I should run this notebook before any release to manually test the values between pygrib and Herbie agree.**" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from herbie import Herbie\n", | ||
"import pygrib\n", | ||
"from pyproj import CRS\n", | ||
"from herbie.crs import get_cf_crs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"\n", | ||
"Model: HRRR\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'lat_0': 38.5, 'lat_1': 38.5, 'lat_2': 38.5, 'lon_0': 262.5, 'proj': 'lcc'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'lat_0': 38.5, 'lat_1': 38.5, 'lat_2': 38.5, 'lon_0': 262.5, 'proj': 'lcc'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: HRRRAK\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'lat_0': 90.0, 'lat_ts': 60.0, 'lon_0': 225.0, 'proj': 'stere'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'lat_0': 90, 'lat_ts': 60.0, 'lon_0': 225.0, 'proj': 'stere'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: GFS\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" equal= True\n", | ||
"👨🏻🏭 Created directory: [/home/blaylock/data/graphcast/20250101]\n", | ||
"\n", | ||
"Model: GRAPHCAST\n", | ||
" pygrib {'a': 4326.0, 'b': 4326.0, 'proj': 'longlat'}\n", | ||
" Herbie {'a': 4326.0, 'b': 4326.0, 'proj': 'longlat'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: CFS\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: IFS\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: AIFS\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: GEFS\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: GEFS\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: HAFSA\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'proj': 'longlat'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: HREF\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'lat_0': 25.0, 'lat_1': 25.0, 'lat_2': 25.0, 'lon_0': 265.0, 'proj': 'lcc'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'lat_0': 25.0, 'lat_1': 25.0, 'lat_2': 25.0, 'lon_0': 265.0, 'proj': 'lcc'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: NAM\n", | ||
" pygrib {'a': 6371229, 'b': 6371229, 'lat_0': 38.5, 'lat_1': 38.5, 'lat_2': 38.5, 'lon_0': 262.5, 'proj': 'lcc'}\n", | ||
" Herbie {'a': 6371229, 'b': 6371229, 'lat_0': 38.5, 'lat_1': 38.5, 'lat_2': 38.5, 'lon_0': 262.5, 'proj': 'lcc'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: URMA\n", | ||
" pygrib {'a': 6371200.0, 'b': 6371200.0, 'lat_0': 25.0, 'lat_1': 25.0, 'lat_2': 25.0, 'lon_0': 265.0, 'proj': 'lcc'}\n", | ||
" Herbie {'a': 6371200.0, 'b': 6371200.0, 'lat_0': 25.0, 'lat_1': 25.0, 'lat_2': 25.0, 'lon_0': 265.0, 'proj': 'lcc'}\n", | ||
" equal= True\n", | ||
"\n", | ||
"Model: RTMA\n", | ||
" pygrib {'a': 6371200.0, 'b': 6371200.0, 'lat_0': 25.0, 'lat_1': 25.0, 'lat_2': 25.0, 'lon_0': 265.0, 'proj': 'lcc'}\n", | ||
" Herbie {'a': 6371200.0, 'b': 6371200.0, 'lat_0': 25.0, 'lat_1': 25.0, 'lat_2': 25.0, 'lon_0': 265.0, 'proj': 'lcc'}\n", | ||
" equal= True\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for model, search in [\n", | ||
" (dict(model=\"hrrr\"), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"hrrrak\"), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"gfs\"), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"graphcast\"), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"cfs\", member=1, product=\"6_hourly\", kind=\"flxf\"), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"ifs\"), \":2t:\"),\n", | ||
" (dict(model=\"aifs\"), \":2t:\"),\n", | ||
" (dict(model=\"gefs\", member=1), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"gefs\", product=\"wave\", member=1), \":WIND:surf\"),\n", | ||
" (dict(model=\"hafsa\", product=\"storm.atm\", storm=\"07s\"), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"href\", products=\"mean\", domain=\"conus\", fxx=1), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"nam\"), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"urma\"), \":TMP:2 m above\"),\n", | ||
" (dict(model=\"rtma\"), \":TMP:2 m above\"),\n", | ||
"]:\n", | ||
" if model[\"model\"] in (\"hafsa\", \"href\"): # only on nomads\n", | ||
" date = \"2025-01-16 06:00\"\n", | ||
" else:\n", | ||
" date = \"2025-01-01\"\n", | ||
"\n", | ||
" ds = Herbie(date, verbose=False, **model).xarray(\n", | ||
" search, remove_grib=False, _use_pygrib_for_crs=False\n", | ||
" )\n", | ||
"\n", | ||
" print()\n", | ||
" print(f\"Model: {model['model'].upper()}\")\n", | ||
" with pygrib.open(str(ds.local_grib)) as grb:\n", | ||
" msg = grb.message(1)\n", | ||
" projparams_dict_pygrib = dict(sorted(msg.projparams.items()))\n", | ||
" print(\" pygrib\", projparams_dict_pygrib)\n", | ||
"\n", | ||
" projparams_dict_herbie = dict(\n", | ||
" sorted(get_cf_crs(ds, _return_projparams=True).items())\n", | ||
" )\n", | ||
" print(\" Herbie\", projparams_dict_herbie)\n", | ||
" print(\" equal=\", projparams_dict_herbie == projparams_dict_pygrib)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "herbie-dev", | ||
"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.13.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
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
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
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
Oops, something went wrong.