1

I'm trying to plot some meteorological data in NetCDF format accessed via the Unidata siphon package.

I've imported what the MetPy docs suggest are the relevant libraries

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
from netCDF4 import num2date
import numpy as np
import xarray as xr
from siphon.catalog import TDSCatalog
from datetime import datetime

import metpy.calc as mpcalc
from metpy.units import units

and I've constructed a query for data as per the Siphon docs

best_gfs = TDSCatalog('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/Global_0p25deg/catalog.xml?dataset=grib/NCEP/GFS/Global_0p25deg/Best')

best_ds = best_gfs.datasets[0]
ncss = best_ds.subset()
query = ncss.query()
query.lonlat_box(north=55, south=20, east=-60, west=-90).time(datetime.utcnow())
query.accept('netcdf4')
query.variables('Vertical_velocity_pressure_isobaric','Relative_humidity_isobaric','Temperature_isobaric','u-component_of_wind_isobaric','v-component_of_wind_isobaric','Geopotential_height_isobaric')

data = ncss.get_data(query)

Unfortunately, when I attempt to parse the dataset using the code from the Metpy docs

data = data.metpy.parse_cf()

I get an error: "AttributeError: NetCDF: Attribute not found"

When attempting to fix this problem, I came across another SO post that seems to have the same issue, but the solution suggested there -- to update my metpy to the latest version, -- did not work for me. I updated metpy using Conda but got the same problem as before I updated. Any other ideas on how to get this resolved?

mustaccio
  • 18,234
  • 16
  • 48
  • 57
Jack Sillin
  • 75
  • 1
  • 9

1 Answers1

0

Right now the following code in Siphon

data = ncss.get_data(query)

will return a Dataset object from netcdf4-python. You need one extra step to hand this to xarray, which will make MetPy's parse_cf available:

from xarray.backends import NetCDF4DataStore
ds = xr.open_dataset(NetCDF4DataStore(data))
data = ds.metpy.parse_cf()
DopplerShift
  • 5,472
  • 1
  • 21
  • 20