<jupyter_start><jupyter_text>Regridding`coecms.regrid.Regridder` provides regridding functionality for xarray DataArrays.First let's load our libraries and some sample data<jupyter_code>%matplotlib inline

from coecms.regrid import Regridder
from coecms import grid

import xarray
import numpy
import matplotlib.pyplot as plt

ds = xarray.open_dataset('http://dapds00.nci.org.au/thredds/dodsC/rr3/CMIP5/output1/CSIRO-BOM/ACCESS1-3/historical/mon/atmos/Amon/r1i1p1/latest/tas/tas_Amon_ACCESS1-3_historical_r1i1p1_185001-200512.nc',
                         chunks={'time':10})

ds.tas<jupyter_output><empty_output><jupyter_text>Target gridThe target grid can be defined in several ways: * Using a `coecms.grid.Grid` object * Using another `xarray.DataArray` object (reading in the lats and lons) * By using weights generated by an external program (e.g. [`ESMF_RegridWeightGen`](https://www.earthsystemcog.org/projects/regridweightgen/)) like:   ``` r = Regridder(ds.tas, weights=xarray.open_datset('weights.nc')) ``` Here I'm using a regular Lat-Lon grid. The Regridder object feeds this information into CDO to generate the weights - this may take a really long time for big grids! If generating the weights does take a long time consider using the external weights method<jupyter_code>g = grid.LonLatGrid(lons=numpy.linspace(0, 360, endpoint=False), lats=numpy.linspace(-90,90))
r = Regridder(ds.tas, g)<jupyter_output><empty_output><jupyter_text>RegriddingThe `Regridder` will generate and save the regridding weights, so the same weights can be re-used multiple times. Call `Regridder.regrid()` to apply the weights to a dataset.This is Dask aware, so should work fine for large input datasets<jupyter_code>tas_regrid = r.regrid(ds.tas)
tas_regrid<jupyter_output><empty_output><jupyter_text>Checking ResultsPlotting the results is a good way to check the regridding is performing correctly<jupyter_code>plt.figure(figsize=(15,5))
plt.subplot(121)
ds.tas.isel(time=-1).plot()
plt.title("Original")
plt.subplot(122)
tas_regrid.isel(time=-1).plot.pcolormesh('lon','lat')
plt.title("Regridded")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10546139359698682, 'fraction_numerical': 0.022598870056497175, 'mean_word_length': 6.107023411371237, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '182095', 'license': 'Apache-2.0', 'n_tokens_mistral': 766, 'n_tokens_neox': 733, 'n_words': 183, 'path': 'notebooks/regridding.ipynb', 'repo_name': 'coecms/coecms-util', 'size': '2124'}