title: Change dataset resolution to match another dataset
body: <p>I have two datasets: one modelled and one observational. I need to get the observational dataset to the same resolution as the model.</p>
  <p>Currently the model data had 100 longitude and 100 latitude points, so each datapoint is 1.8 degrees by 3.6 degrees.</p>
  <p>I've tried the following, but the datapoints don't quite match up so I can't concatenate the datasets.</p>
  <pre><code>import xarray as xa
  import numpy as np
  import cmocean.cm as cm
  import matplotlib.patches as mpatches
  from matplotlib.patches import Patch
  from matplotlib.lines import Line2D
  import matplotlib.pyplot as plt
  import seaborn as sns
  import pandas as pd
  import cartopy.crs as ccrs
  import cartopy.feature as cfeat
  
  
  # =============================================================================
  #  Step 1: Get data
  # =============================================================================
      
  data_model = xa.open_dataset(&quot;PD_tavg_out_diss_5.nc&quot;,decode_times = False)
  
  sal_obs_data = xa.open_dataset(&quot;sal_obs_NS_all.nc&quot;,decode_times = False)
  temp_obs_data = xa.open_dataset(&quot;temp_obs_NS_all.nc&quot;,decode_times = False)
  
  data_obs = xa.merge([sal_obs_data,temp_obs_data])
  data_obs = data_obs.rename(lon = &quot;longitude&quot;,
                             lat = &quot;latitude&quot;)
  
  
  
  
  data_extract = data_model[[&quot;O_cons_temp&quot;,&quot;O_abs_sal&quot;]]
  long1 = data_extract.longitude.values
  long1[long1&gt;180]-=360
  data_extract[&quot;longitude&quot;] = long1
  data_sorted = data_extract.sortby(&quot;longitude&quot;)
      
      
  long2 = data_obs.longitude.values
  long2[long2&gt;180]-=360
  data_obs[&quot;longitude&quot;] = long2
  data_sorted_obs = data_obs.sortby(&quot;longitude&quot;)
  
  
  long_max = 1.8
  long_min = -1.8
  lat_max = 60.3
  lat_min = 54.9
  dep_max = 100
  dep_min = 0
  tim_max = 35422.0
  tim_min = 35421.0 
  
  def extract_shelf_sea(long_max, long_min, 
                        lat_max, lat_min,
                        dep_max, dep_min,
                        tim_max, tim_min):
  
  # =============================================================================
  #  Step 3: Extract data
  # =============================================================================
  
      extract_model_data = data_sorted.sel(longitude = slice(long_min,long_max),
                                           latitude = slice(lat_min,lat_max),
                                           depth = slice(dep_min,dep_max),
                                           time = slice(tim_min,tim_max))
  
  
      extract_obs_data = data_obs.sel(time = data_obs.time,
                                      longitude = slice(long_min,long_max),
                                      latitude = slice(lat_min,lat_max))
      
      new_lon = np.linspace(extract_obs_data.longitude[0],extract_obs_data.longitude[7],extract_model_data.sizes['longitude'])
      new_lat = np.linspace(extract_obs_data.latitude[0],extract_obs_data.latitude[10],extract_model_data.sizes['latitude'])
      obs_interpolated = extract_obs_data.interp(latitude = new_lat, longitude = new_lon)
      
      
      extract_obs_depth = obs_interpolated.sel(depth = extract_model_data.depth, method=&quot;nearest&quot;)
  </code></pre>
  <p>Observation outputs:</p>
  <pre><code>extract_obs_depth
  Out[178]: 
  &lt;xarray.Dataset&gt;
  Dimensions:    (depth: 2, latitude: 4, longitude: 2, time: 12)
  Coordinates:
    * depth      (depth) float64 15.07 82.92
    * time       (time) float32 480.5 481.5 482.5 483.5 ... 489.5 490.5 491.5
    * latitude   (latitude) float64 54.25 56.42 58.58 60.75
    * longitude  (longitude) float64 -1.75 1.75
  Data variables:
      salt       (time, depth, latitude, longitude) float64 nan 34.56 ... 35.38
      temp       (time, depth, latitude, longitude) float64 nan 6.586 ... 8.907
  </code></pre>
  <p>Model outputs:</p>
  <pre><code>extract_model_data
  Out[179]: 
  &lt;xarray.Dataset&gt;
  Dimensions:      (depth: 2, latitude: 4, longitude: 2, time: 12)
  Coordinates:
    * time         (time) float64 3.542e+04 3.542e+04 ... 3.542e+04 3.542e+04
    * longitude    (longitude) float64 -1.8 1.8
    * latitude     (latitude) float64 54.9 56.7 58.5 60.3
    * depth        (depth) float64 17.5 82.5
  Data variables:
      O_cons_temp  (time, depth, latitude, longitude) float64 5.615 ... 7.437
      O_abs_sal    (time, depth, latitude, longitude) float64 33.28 ... 35.21
  </code></pre>
  <p>Any suggestions for how I can get the latitude and longitude to match perfectly would be much appreciated. Thanks in advance.</p>
  <p>By the way, unfortunately I can't upload the datasets as they're too big.</p>