Ambre Arrivé
Ambre Arrivé

Reputation: 21

Reorganize dataset in Xarray

I am new to using xarray in python. Actually, I work in a jupyter environment to view my satellite data.

My Dataset

Usually I Have time, latitude and longitude dimensions only which allows me to display a map. But here, i have these dimensions but accompany others et not organized as usual so it don't display a map. So, i want to know which command of xarray i have to use to just display data with only the three dimensions (time, latitude, longitude) and in this order.

Upvotes: 2

Views: 395

Answers (1)

Michael Delgado
Michael Delgado

Reputation: 15452

Congrats! You've made it to xarray's deep end :)

You have data variables in there that I would consider to be non-dimensional coordinates: [time, valid_time, latitude, longitude, lambert_azimuthal...]. You can think of non-dimensional coordinates as additional labeling information about the coordinates in your arrays, but which you don't generally want to do math on. You can categorize these as coordinates rather than data_variables with ds.set_coords, e.g.:

# skipping lambert ...
ds = ds.set_coords(['time', 'valid_time', 'latitude', 'longitude'])

You also have dimensions without coordinates. In your dataset, member is a dimension of rdis but does not appear in the coordinates list. See the docs on creating a DataArray for an example. You can select elements from member as if it's a RangeIndex (e.g. containing elements [0, 1, .., 24]

Finally, for the most difficult part - you have multi-dimensional coordinates latitude(y, x) and longitude(y, x). These are a bit trickier to work with. Usually this occurs when your data is in a particular cartographic projection. The docs I linked to above have a helpful starting point.

As a quick example (paraphrased from the docs), you can plot your projected data on a map with cartopy:

plt.figure(figsize=(14, 6))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_global()
ds.rdis.isel(step=0, member=0).plot.pcolormesh(
    ax=ax, transform=ccrs.PlateCarree(), x="longitude", y="latitude"
)
ax.coastlines()

Also relevant to multidimensional coords:

Upvotes: 0

Related Questions