In [1]:
import numpy as np
import xarray as xr   # html_repr branch
In [2]:
lon = np.array([[-99.83, -99.32, -99.56],
                [-99.27, -99.39, -99.91],
                [-99.79, -99.23, -99.42]])
lat = np.array([[ 42.25,  42.21, 42.82],
                [ 42.91,  42.47, 42.71],
                [ 42.63,  42.59, 42.29]])

ds = xr.Dataset(data_vars={'foo': (('x', 'y'), np.random.rand(3, 3))},
                coords={
                    'x': [0, 1, 2], 'y': [0, 1, 2],
                    'lon': (('x', 'y'), lon, {'standard_name': 'longitude'}),
                    'lat': (('x', 'y'), lat, {'standard_name': 'latitude'})
                },
                attrs={'title': 'example dataset'})
In [3]:
ds
Out[3]:
xarray.Dataset
    • x: 3
    • y: 3
    • (x)int64
        array([0, 1, 2])
      • (y)int64
          array([0, 1, 2])
        • (x, y)float64
          • standard_name : longitude
          array([[-99.83, -99.32, -99.56],
                 [-99.27, -99.39, -99.91],
                 [-99.79, -99.23, -99.42]])
        • (x, y)float64
          • standard_name : latitude
          array([[ 42.25,  42.21,  42.82],
                 [ 42.91,  42.47,  42.71],
                 [ 42.63,  42.59,  42.29]])
        • (x, y)float64
            array([[ 0.12099674,  0.5573085 ,  0.04989096],
                   [ 0.98033112,  0.84505955,  0.77337044],
                   [ 0.43097088,  0.34742313,  0.59263735]])
          • title : example dataset
        In [4]:
        ds.foo
        
        Out[4]:
        xarray.DataArray
        'foo'
        • x: 3
        • y: 3
        • 0.121 0.5573 0.04989 0.9803 0.8451 0.7734 0.431 0.3474 0.5926
          array([[ 0.12099674,  0.5573085 ,  0.04989096],
                 [ 0.98033112,  0.84505955,  0.77337044],
                 [ 0.43097088,  0.34742313,  0.59263735]])
          • (x)int64
              array([0, 1, 2])
            • (y)int64
                array([0, 1, 2])
              • (x, y)float64
                • standard_name : longitude
                array([[-99.83, -99.32, -99.56],
                       [-99.27, -99.39, -99.91],
                       [-99.79, -99.23, -99.42]])
              • (x, y)float64
                • standard_name : latitude
                array([[ 42.25,  42.21,  42.82],
                       [ 42.91,  42.47,  42.71],
                       [ 42.63,  42.59,  42.29]])
              In [5]:
              ds.foo.variable
              
              Out[5]:
              xarray.Variable
              • x: 3
              • y: 3
              • 0.121 0.5573 0.04989 0.9803 0.8451 0.7734 0.431 0.3474 0.5926
                array([[ 0.12099674,  0.5573085 ,  0.04989096],
                       [ 0.98033112,  0.84505955,  0.77337044],
                       [ 0.43097088,  0.34742313,  0.59263735]])
                In [6]:
                ds.foo.x.variable
                
                Out[6]:
                xarray.IndexVariable
                'x'
                • x: 3
                • 0 1 2
                  array([0, 1, 2])
                  In [7]:
                  ds.foo.lat
                  
                  Out[7]:
                  xarray.DataArray
                  'lat'
                  • x: 3
                  • y: 3
                  • 42.25 42.21 42.82 42.91 42.47 42.71 42.63 42.59 42.29
                    array([[ 42.25,  42.21,  42.82],
                           [ 42.91,  42.47,  42.71],
                           [ 42.63,  42.59,  42.29]])
                    • (x)int64
                        array([0, 1, 2])
                      • (y)int64
                          array([0, 1, 2])
                        • (x, y)float64
                          • standard_name : longitude
                          array([[-99.83, -99.32, -99.56],
                                 [-99.27, -99.39, -99.91],
                                 [-99.79, -99.23, -99.42]])
                        • (x, y)float64
                          • standard_name : latitude
                          array([[ 42.25,  42.21,  42.82],
                                 [ 42.91,  42.47,  42.71],
                                 [ 42.63,  42.59,  42.29]])
                        • standard_name : latitude
                      In [8]:
                      xr.Dataset()
                      
                      Out[8]:
                      xarray.Dataset
                            In [9]:
                            xr.DataArray(1)
                            
                            Out[9]:
                            xarray.DataArray
                            • 1
                              array(1)
                                In [ ]: