Search code examples
pandasnumpydata-sciencepython-xarraygrib

Xarray combine datasets with different dimensions?


I'm trying to merge two Xarray datasets. The resolutions of the datasets are different (one has more points than the other). Ultimately, I need to multiply the values together into one dataset.

I need it to be pretty fast, so nested "for" loops through x and y coordinates won't be optimal (I'm working with big datasets). Is there any clean way to do this that I'm not yet aware of? Thanks so much.


Solution

  • For xarray Datasets named xrds1 and xrds2 covering the same area, but with different resolutions, you can use xr.Dataset.interp_like. Something like:

    xrds_merged = xrds2.merge(xrds1.interp_like(xrds2))
    

    If the two datasets have variables with the same name, you may have to rename one first with xr.Dataset.rename_vars() if you want to retain both.

    Note that this (interp_like) requires scipy to be installed.