Skip to content

Commit abe6992

Browse files
add first exercise
1 parent 4d614e8 commit abe6992

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

content/xarray.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,24 @@ Exercises 1 (if time allows)
288288

289289
.. challenge:: Exercises: Xarray-1
290290

291-
Take example dataset and perform a series of operations on it using labels and plot the results. Details coming soon.
291+
Download the ``NARR_19930313_0000.nc`` dataset have a look at all Data variables. Calculate the geopotential height at ``x=5148.3726`` averaged over ``y`` and return the median value. You can use the ``.plot()`` method to check on the way whether you use the correct dimensions and indices.
292292

293293
.. solution:: Solutions: Xarray-1
294294

295-
Solution to Exercise 1 coming soon.
295+
One way of calculating this is: ::
296+
297+
>>> from pythia_datasets import DATASETS
298+
>>> import xarray as xr
299+
>>>
300+
>>> filepath = DATASETS.fetch('NARR_19930313_0000.nc')
301+
>>> ds = xr.open_dataset(filepath)
302+
>>> ds['Geopotential_height_isobaric'].sel(x=5148.3726).mean('y').median()
303+
<xarray.DataArray 'Geopotential_height_isobaric' ()> Size: 4B
304+
array(4395.487, dtype=float32)
305+
Coordinates:
306+
x float32 4B 5.148e+03
307+
308+
296309

297310

298311
Creating your own Xarray Dataset

0 commit comments

Comments
 (0)