title: xarray create Dataset from list of lat/lon points (not square!)
body: <p>I need to create a Dataset from an irregular list of latitudes/longitudes. These have been stacked into a list of 'pixels' that I need to unstack and convert back to a regular grid of latitude/longitudes. Because the data values are not complete for every pixel in the grid I need to fill the missing values as <code>np.nan</code>.</p>
  <p>I am having trouble creating the <code>xr.Dataset</code> with an irregular list of lat lon points (pixels).</p>
  <h2> Reproducible Example:</h2>
  <h3> Create an example of how my data looks</h3>
  <p>Note: the data is not complete, it is of shape <code>(99,)</code> and so I cannot simply reshape the data to fit within the unique latitudes / longitudes.</p>
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  import xarray as xr
  
  unique_latitudes = np.arange(0, 10)
  unique_longitudes = np.arange(0, 10)
  _ = np.array((np.meshgrid(latitudes, longitudes))).T.reshape(-1, 2)
  
  # we don't have a complete grid of pixels
  pixels = _[:99]
  latitudes = pixels[:, 0]
  longitudes = pixels[:, 1]
  pixel_id = [i for i in range(len(pixels))]
  
  # there is one missing datapoint (only 99 pixels so can't simply reshape data)
  data = np.random.choice([0,1,2], (pixels.shape[0]))
  coords = {'pixel': pixels}
  dims = ['pixel']
  
  xr.Dataset({'data': (dims, data)})
  
  Out[]:
  &lt;xarray.Dataset&gt;
  Dimensions:  (pixel: 99)
  Dimensions without coordinates: pixel
  Data variables:
      data     (pixel) int64 1 1 2 0 1 0 1 1 0 1 1 2 1 ... 2 2 0 0 1 2 1 2 0 1 1 2
  </code></pre>
  <p>This is as far as I have got with my data. I have a length 99 array. But each of these values corresponds to one latitude and one longitude.</p>
  <pre class="lang-py prettyprint-override"><code>pixels[:5]
  
  Out[]:
  array([[0, 0],
         [0, 1],
         [0, 2],
         [0, 3],
         [0, 4]])
  </code></pre>
  <h3> What I want is a <code>xr.Dataset</code> with the appropriately labeled <code>lat</code>/<code>lon</code> coordinates</h3>
  <pre class="lang-py prettyprint-override"><code>data = np.random.choice([0,1,2], (100)).astype('float')
  data = data.reshape(len(unique_latitudes), len(unique_longitudes))
  # remember there is one missing data point in the above data
  data[np.unravel_index(99, data.shape)] = np.nan
  
  correct_dims = ['lat', 'lon']
  correct_coords = {'lat': unique_latitudes, 'lon': unique_longitudes}
  correct_ds = xr.Dataset({'data': (correct_dims, data)}, coords=correct_coords)
  
  correct_ds
  
  Out[]:
  &lt;xarray.Dataset&gt;
  Dimensions:  (lat: 10, lon: 10)
  Coordinates:
    * lat      (lat) int64 0 1 2 3 4 5 6 7 8 9
    * lon      (lon) int64 0 1 2 3 4 5 6 7 8 9
  Data variables:
      data     (lat, lon) float64 0.0 1.0 0.0 1.0 0.0 2.0 ... 2.0 1.0 1.0 2.0 nan
  
  </code></pre>