Skip to content

Commit

Permalink
Add example to sel docstring pydata#4630
Browse files Browse the repository at this point in the history
  • Loading branch information
EricKeenan committed Dec 18, 2020
1 parent 7355c35 commit 40f0050
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,55 @@ def sel(
Dataset.sel
DataArray.isel
Examples
--------
>>> ds = xr.tutorial.open_dataset("air_temperature")
>>> ds
<xarray.Dataset>
Dimensions: (lat: 25, lon: 53, time: 2920)
Coordinates:
* lat (lat) float32 75.0 72.5 70.0 67.5 65.0 ... 25.0 22.5 20.0 17.5 15.0
* lon (lon) float32 200.0 202.5 205.0 207.5 ... 322.5 325.0 327.5 330.0
* time (time) datetime64[ns] 2013-01-01 ... 2014-12-31T18:00:00
Data variables:
air (time, lat, lon) float32 ...
Attributes:
Conventions: COARDS
title: 4x daily NMC reanalysis (1948)
description: Data is from NMC initialized reanalysis\n(4x/day). These a...
platform: Model
references: http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly...
>>> tgt_lat = xr.DataArray(np.linspace(40, 45, num=6), dims="points")
>>> tgt_lon = xr.DataArray(np.linspace(200, 205, num=6), dims="points")
>>> da = ds['air'].sel(lon=tgt_lon, lat=tgt_lat, method='nearest')
>>> da
<xarray.DataArray 'air' (time: 2920, points: 6)>
array([[284.6 , 284.6 , 283.19998, 283.19998, 280.19998, 280.19998],
[283.29 , 283.29 , 282.79 , 282.79 , 280.79 , 280.79 ],
[282. , 282. , 280.79 , 280.79 , 280. , 280. ],
...,
[282.49 , 282.49 , 281.29 , 281.29 , 280.49 , 280.49 ],
[282.09 , 282.09 , 280.38998, 280.38998, 279.49 , 279.49 ],
[282.09 , 282.09 , 280.59 , 280.59 , 279.19 , 279.19 ]],
dtype=float32)
Coordinates:
lat (points) float32 40.0 40.0 42.5 42.5 45.0 45.0
lon (points) float32 200.0 200.0 202.5 202.5 205.0 205.0
* time (time) datetime64[ns] 2013-01-01 ... 2014-12-31T18:00:00
Dimensions without coordinates: points
Attributes:
long_name: 4xDaily Air temperature at sigma level 995
units: degK
precision: 2
GRIB_id: 11
GRIB_name: TMP
var_desc: Air temperature
dataset: NMC Reanalysis
level_desc: Surface
statistic: Individual Obs
parent_stat: Other
actual_range: [185.16 322.1 ]
"""
ds = self._to_temp_dataset().sel(
indexers=indexers,
Expand Down

0 comments on commit 40f0050

Please sign in to comment.