'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 1:[1]
You can use reindex_like to reindex the datarray with the lowest resolution. See: https://xarray.pydata.org/en/stable/generated/xarray.DataArray.reindex_like.html
Solution 2:[2]
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(xrds1))
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thrasy |
| Solution 2 | climatestudent |
