This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi, So what you'll need is to create a fully CF-compliant set of projection information (http://cfconventions.org). In this case, since you're working in latitude/longitude space, you should: 1. Add a variable (can be called anything, like "LatLonProjection") to the Dataset. At a minimum this variable needs to have an attribute "grid_mapping_name" with a "latitude_longitude". 2. Add an attribute to all of your data fields (e.g. "potential temperature", "u wind") called "grid_mapping" with a value equal to the name of the variable you created in (1) (e.g. "LatLonProjection"). Then you should be able to do e.g. dataset.metpy.parse_cf() or dataset.metpy.parse_cf('u wind'). Unfortunately, this won't work right now: arr = dataset['potential temperature'] arr.metpy.crs = ccrs.LambertConformal() because the `crs` attribute is read-only. Improvements to the cross-section functionality to make it easier to work with other data sets is being tracked in: https://github.com/Unidata/MetPy/issues/1004 Ryan > I have some WRF output in sigma coordinates, with the lat-lon grid in 2 > dimensional arrays. After converting the output into isobaric coordinates, I > want to create a new xarray with the output so I can use metpy to plot a > cross-section. However, I am getting 2 errors: > AttributeError: 'Dataset' object has no attribute 'crs' > AttributeError: cannot set attribute 'crs' on a 'Dataset' object. Use > __setitem__ style assignment (e.g., `ds['name'] = ...`) instead to assign > variables. > > How do I set up my data to be compatible with the metpy cross-section > feature? I looked into Issue 949 and Issue 1004, but I haven't been able to > find a solution. > > Attached is my code. The WRF output is too large to send, but it is a > standard output file in netCDF format. Ticket Details =================== Ticket ID: SWP-244115 Department: Support Python Priority: Low Status: Closed =================== NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.