Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Using Xarray for Data read and selection

Use Xarray module to read in model data from nomads server.

This example uses the xarray module to access data from the nomads server for archive NAM analysis data via OPeNDAP. Xarray makes it easier to select times and levels, although you still have to know the coordinate variable name. A simple 500 hPa plot is created after selecting with xarray.

Import all of our needed modules

Accessing data using Xarray

NAM data is in a projected coordinate and you get back the projection X and Y values in km

Getting the valid times in a more useable format

[datetime.datetime(2016, 4, 16, 18, 0)]

Xarray has some nice functionality to choose the time and level that you specifically want to use. In this example the time variable is ‘time’ and the level variable is ‘isobaric1’. Unfortunately, these can be different with each file you use, so you’ll always need to check what they are by listing the coordinate variable names

Now make the 500-hPa map

<Figure size 1700x1100 with 1 Axes>