NOGAPS#
This demonstrates how to use data from historical archive of NOGAPS from NCEI for historical analyses from 1997 to 2008 at 0.5 and 1.0 degree grids.
[2]:
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from paint.standard2 import cm_tmp
from toolbox import EasyMap, pc
from herbie import Herbie
[3]:
H = Herbie("2008-07-28 12:00", model="nogaps", product="058_240")
β
Found β model=nogaps β product=058_240 β 2008-Jul-28 12:00 UTC F00 β GRIB2 @ ncei β IDX @ ncei
[4]:
# TODO: Herbie cant read this NOGAPS inventory files
H.inventory("TMP")
---------------------------------------------------------------------------
ParserError Traceback (most recent call last)
Cell In[4], line 3
1 # TODO: Herbie cant read NOGAPS inventory files
----> 3 H.read_idx("TMP")
File ~\_GITHUB\Herbie\herbie\archive.py:718, in Herbie.read_idx(self, search)
697 def read_idx(self, search=None):
698 """
699 Inspect the GRIB2 file contents by reading the index file.
700
(...)
716 A Pandas DataFrame of the index file.
717 """
--> 718 df = self.index_as_dataframe
720 # Filter DataFrame by search
721 if search not in [None, ":"]:
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\functools.py:981, in cached_property.__get__(self, instance, owner)
979 val = cache.get(self.attrname, _NOT_FOUND)
980 if val is _NOT_FOUND:
--> 981 val = self.func(instance)
982 try:
983 cache[self.attrname] = val
File ~\_GITHUB\Herbie\herbie\archive.py:575, in Herbie.index_as_dataframe(self)
572 read_this_idx = StringIO(response.text)
573 response.close()
--> 575 df = pd.read_csv(
576 read_this_idx,
577 sep=":",
578 names=[
579 "grib_message",
580 "start_byte",
581 "reference_time",
582 "variable",
583 "level",
584 "forecast_time",
585 "?",
586 "??",
587 "???",
588 ],
589 )
591 # Format the DataFrame
592 df["reference_time"] = pd.to_datetime(
593 df.reference_time, format="d=%Y%m%d%H"
594 )
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\util\_decorators.py:211, in deprecate_kwarg.<locals>._deprecate_kwarg.<locals>.wrapper(*args, **kwargs)
209 else:
210 kwargs[new_arg_name] = new_arg_value
--> 211 return func(*args, **kwargs)
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\util\_decorators.py:331, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs)
325 if len(args) > num_allow_args:
326 warnings.warn(
327 msg.format(arguments=_format_argument_list(allow_args)),
328 FutureWarning,
329 stacklevel=find_stack_level(),
330 )
--> 331 return func(*args, **kwargs)
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\io\parsers\readers.py:950, in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, error_bad_lines, warn_bad_lines, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options)
935 kwds_defaults = _refine_defaults_read(
936 dialect,
937 delimiter,
(...)
946 defaults={"delimiter": ","},
947 )
948 kwds.update(kwds_defaults)
--> 950 return _read(filepath_or_buffer, kwds)
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\io\parsers\readers.py:611, in _read(filepath_or_buffer, kwds)
608 return parser
610 with parser:
--> 611 return parser.read(nrows)
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\io\parsers\readers.py:1778, in TextFileReader.read(self, nrows)
1771 nrows = validate_integer("nrows", nrows)
1772 try:
1773 # error: "ParserBase" has no attribute "read"
1774 (
1775 index,
1776 columns,
1777 col_dict,
-> 1778 ) = self._engine.read( # type: ignore[attr-defined]
1779 nrows
1780 )
1781 except Exception:
1782 self.close()
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py:230, in CParserWrapper.read(self, nrows)
228 try:
229 if self.low_memory:
--> 230 chunks = self._reader.read_low_memory(nrows)
231 # destructive to chunks
232 data = _concatenate_chunks(chunks)
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\_libs\parsers.pyx:808, in pandas._libs.parsers.TextReader.read_low_memory()
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\_libs\parsers.pyx:866, in pandas._libs.parsers.TextReader._read_rows()
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\_libs\parsers.pyx:852, in pandas._libs.parsers.TextReader._tokenize_rows()
File c:\Users\blaylock\Miniconda3\envs\herbie-dev\lib\site-packages\pandas\_libs\parsers.pyx:1973, in pandas._libs.parsers.raise_parser_error()
ParserError: Error tokenizing data. C error: EOF inside string starting at row 74
[5]:
H = Herbie("2008-07-28 12:00", model="nogaps", product="008_240")
β
Found β model=nogaps β product=008_240 β 2008-Jul-28 12:00 UTC F00 β GRIB2 @ ncei β IDX @ ncei
[6]:
H.inventory("TMP")
[6]:
grib_message | start_byte | end_byte | range | reference_time | valid_time | variable | level | forecast_time | ? | ?? | ??? | search_this | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 21 | 228297 | 21-228297 | 2008-07-28 12:00:00 | 2008-07-28 12:00:00 | TMP | 0 mb | kpds=11,100,0 | anl | winds are N/S | Temp. [K]\n2:89724:D=2008072812:HGT:0 mb:kpds=... | :TMP:0 mb:kpds=11,100,0:anl:winds are N/S:Temp... |
2 | 5 | 407705 | 644127 | 407705-644127 | 2008-07-28 12:00:00 | 2008-07-28 12:00:00 | TMP | 1 mb | kpds=11,100,1 | anl | winds are N/S | Temp. [K]\n6:505554:D=2008072812:HGT:1 mb:kpds... | :TMP:1 mb:kpds=11,100,1:anl:winds are N/S:Temp... |
4 | 9 | 823535 | 1068101 | 823535-1068101 | 2008-07-28 12:00:00 | 2008-07-28 12:00:00 | TMP | 2 mb | kpds=11,100,2 | anl | winds are N/S | Temp. [K]\n10:929528:D=2008072812:HGT:2 mb:kpd... | :TMP:2 mb:kpds=11,100,2:anl:winds are N/S:Temp... |
6 | 13 | 1231217 | 1467639 | 1231217-1467639 | 2008-07-28 12:00:00 | 2008-07-28 12:00:00 | TMP | 5 mb | kpds=11,100,5 | anl | winds are N/S | Temp. [K]\n14:1337210:D=2008072812:HGT:5 mb:kp... | :TMP:5 mb:kpds=11,100,5:anl:winds are N/S:Temp... |
[7]:
ds = H.xarray("TMP:5 mb")
π¨π»βπ Created directory: [C:\Users\blaylock\data\nogaps\20080728]
C:\Users\blaylock\_GITHUB\Herbie\herbie\archive.py:1041: UserWarning: sorry, on windows I couldn't remove the file.
warnings.warn("sorry, on windows I couldn't remove the file.")
[8]:
ds
[8]:
<xarray.Dataset> Dimensions: (latitude: 181, longitude: 360) Coordinates: time datetime64[ns] 2008-07-28T12:00:00 step timedelta64[ns] 00:00:00 isobaricInhPa float64 5.0 * latitude (latitude) float64 -90.0 -89.0 -88.0 ... 88.0 89.0 90.0 * longitude (longitude) float64 -1.0 0.0 1.0 ... 356.0 357.0 358.0 valid_time datetime64[ns] 2008-07-28T12:00:00 Data variables: t (latitude, longitude) float32 210.5 210.5 ... 252.4 gh (latitude, longitude) float32 3.048e+04 ... 3.679e+04 gribfile_projection object None Attributes: GRIB_edition: 1 GRIB_centre: fnmo GRIB_centreDescription: US Navy - Fleet Numerical Oceanography Center GRIB_subCentre: 0 Conventions: CF-1.7 institution: US Navy - Fleet Numerical Oceanography Center model: nogaps product: 008_240 description: Navy Operational Global Atmospheric Prediction S... remote_grib: https://www.ncei.noaa.gov/data/navy-operational-... local_grib: C:\Users\blaylock\data\nogaps\20080728\subset_b9... search: TMP:5 mb
[10]:
ax = EasyMap(crs=ds.herbie.crs, figsize=[8, 8]).ax
p = ax.pcolormesh(
ds.longitude, ds.latitude, ds.t, transform=pc, **cm_tmp(units="K").cmap_kwargs
)
plt.colorbar(
p, ax=ax, orientation="horizontal", pad=0.01, **cm_tmp(units="K").cbar_kwargs
)
ax.set_title(f"{ds.t.GRIB_name} {ds.isobaricInhPa.item()} hPa", loc="right")
ax.set_title(f"{H.model.upper()}: {H.product_description}", loc="left")
[10]:
Text(0.0, 1.0, 'NOGAPS: ?')
[ ]:
[ ]: