<jupyter_start><jupyter_text>Grid mappingcfgrib does not appear to parse the CF "grid_mapping" attribute.<jupyter_code>from herbie.archive import Herbie
import metpy
H = Herbie('2021-9-21')
ds = H.xarray('TMP:2 m')
ds.metpy.parse_cf().metpy_crs.item().to_cartopy()
grid_mapping = f'{ds.model}_projection'
ds[grid_mapping] = None
ds[grid_mapping].attrs['long_name'] = f"{ds.model.upper()} model grid projection"

var = list(ds)[0]
attrs = ds[var].attrs
if attrs['GRIB_gridType'] == 'lambert':
    ds[grid_mapping].attrs['grid_mapping_name'] = 'lambert_conformal_conic'
    ds[grid_mapping].attrs['standard_parallel'] = (attrs.get("GRIB_Latin1InDegrees"), attrs.get("GRIB_Latin2InDegrees"))
    ds[grid_mapping].attrs['longitude_of_central_meridian'] = attrs.get("GRIB_LoVInDegrees")
    ds[grid_mapping].attrs['latitude_of_projection_origin'] = attrs.get("GRIB_LaDInDegrees")
    ds[grid_mapping].attrs['false_easting'] = 0
    ds[grid_mapping].attrs['false_northing'] = 0
    
elif attrs['GRIB_gridType'] == 'polar_stereographic':
    ds[grid_mapping].attrs['grid_mapping_name'] = 'polar_stereographic'
    ds[grid_mapping].attrs['straight_vertical_longitude_from_pole'] = "not enough info"
    ds[grid_mapping].attrs['latitude_of_projection_origin'] = "not enough info (either +90 or -90)"
    ds[grid_mapping].attrs['standard_parallel'] = "not enough info"
    ds[grid_mapping].attrs['false_easting'] = 0
    ds[grid_mapping].attrs['false_northing'] = 0

elif attrs['GRIB_gridType'] == 'regular_ll':
    ds[grid_mapping].attrs['grid_mapping_name'] = 'latitude_longitude'

else:
    warnings.warn(f'GRIB_gridType [{attrs["GRIB_gridType"]}] is not recognized.')
                  
for v in list(ds):
    ds[v].attrs['grid_mapping'] = grid_mapping

import metpy
ds.metpy.parse_cf().metpy_crs.item().to_cartopy()
ds.metpy.parse_cf().metpy_crs.item().to_cartopy().proj4_params
ds.herbie.crs.proj4_params
Hak = Herbie('2021-09-21', model='hrrrak').xarray('TMP:2 m')
Hak
Hak.t2m
Hgfs = Herbie('2021-09-21', model='gfs').xarray('TMP:2 m above')
Hgfs
Hgfs.t2m<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15898174831892412, 'fraction_numerical': 0.0196926032660903, 'mean_word_length': 6.360424028268551, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '382262', 'license': 'MIT', 'n_tokens_mistral': 808, 'n_tokens_neox': 790, 'n_words': 111, 'path': 'notebooks/issues/cfgrib_parse_grid_mapping.ipynb', 'repo_name': 'WToma/Herbie', 'size': '2082'}