Repository: Ouranosinc/xclim

Issue:
Add support in subset_gridpoint for 1D lat lon. 
### Description
<!--Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.-->

`subset_gridpoint` assumes that lats and lons are on a 2D grid. If used with 1D coordinates, it fails. This would be useful to find the nearest point on an unstructured grid. A use case would be finding the closest weather station to a given point. 



Discussion:

Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 026c37e2..ba05dad9 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -2,6 +2,10 @@
 History
 =======
 
+0.15.x
+------
+* Fix bug in subset_gridpoint to work on lat/lon coords of any dimension when they are not a dimension of the data.
+
 0.14.x (2020-02-21)
 -------------------
 * Refactoring of the documentation.
diff --git a/xclim/subset.py b/xclim/subset.py
index e0c8d1f6..1df9a9fe 100644
--- a/xclim/subset.py
+++ b/xclim/subset.py
@@ -832,13 +832,10 @@ def subset_gridpoint(
                 dist = distance(da, lon, lat)
 
                 # Find the indices for the closest point
-                iy, ix = np.unravel_index(dist.argmin(), dist.shape)
+                inds = np.unravel_index(dist.argmin(), dist.shape)
 
                 # Select data from closest point
-                xydims = [x for x in dist.dims]
-                args = dict()
-                args[xydims[0]] = iy
-                args[xydims[1]] = ix
+                args = {xydim: ind for xydim, ind in zip(dist.dims, inds)}
                 da = da.isel(**args)
         else:
             raise (


Test patch:
diff --git a/tests/test_subset.py b/tests/test_subset.py
index ef829490..6be98ee2 100644
--- a/tests/test_subset.py
+++ b/tests/test_subset.py
@@ -222,6 +222,26 @@ class TestSubsetGridPoint:
         np.testing.assert_almost_equal(out2.lat, lat, 1)
         np.testing.assert_array_equal(out, out2.tasmax)
 
+        # Dataset with lon and lat as 1D arrays
+        lon = -60
+        lat = -45
+        da = xr.DataArray(
+            np.random.rand(5, 4),
+            dims=("time", "site"),
+            coords={"time": np.arange(5), "site": np.arange(4)},
+        )
+        ds = xr.Dataset(
+            data_vars={
+                "da": da,
+                "lon": ("site", np.linspace(lon, lon + 10, 4)),
+                "lat": ("site", np.linspace(lat, lat + 5, 4)),
+            }
+        )
+        gp = subset.subset_gridpoint(ds, lon=lon, lat=lat)
+        np.testing.assert_almost_equal(gp.lon, lon)
+        np.testing.assert_almost_equal(gp.lat, lat)
+        assert gp.site == 0
+
     def test_positive_lons(self):
         da = xr.open_dataset(self.nc_poslons).tas
         lon = -72.4