Repository: pangeo-data/xESMF

Issue:
conservative regrid changes sum by factor of almost 10
My conservative regrid is producing a regridded dataset whose sum is lower by a factor of nearly 10.  I am sure I am misunderstanding the way that conservative is defined or the input requirements of xesmf.Regridder, but I sure haven't been able to figure out how.

A minimal example, using two grids in the area of Auckland, New Zealand.  

```python
import numpy as np
import xarray as xr
import xesmf

destination_grid_dict = {'coords': {'lon': {'dims': ('lon',), 'attrs': {}, 'data': [172.0, 172.01353383458647, 172.02706766917294, 172.0406015037594, 172.05413533834587, 172.06766917293234, 172.0812030075188, 172.09473684210525, 172.10827067669172, 172.12180451127819, 172.13533834586465, 172.14887218045112, 172.1624060150376, 172.17593984962406, 172.18947368421053, 172.203007518797, 172.21654135338346, 172.23007518796993, 172.2436090225564, 172.25714285714287, 172.27067669172934, 172.2842105263158, 172.29774436090224, 172.3112781954887, 172.32481203007518, 172.33834586466165, 172.35187969924812, 172.36541353383458, 172.37894736842105, 172.39248120300752, 172.406015037594, 172.41954887218046, 172.43308270676692, 172.4466165413534, 172.46015037593986, 172.4736842105263, 172.48721804511277, 172.50075187969924, 172.5142857142857, 172.52781954887217, 172.54135338345864, 172.5548872180451, 172.56842105263158, 172.58195488721805, 172.59548872180451, 172.60902255639098, 172.62255639097745, 172.63609022556392, 172.6496240601504, 172.66315789473686, 172.6766917293233, 172.69022556390976, 172.70375939849623, 172.7172932330827, 172.73082706766917, 172.74436090225564, 172.7578947368421, 172.77142857142857, 172.78496240601504, 172.7984962406015, 172.81203007518798, 172.82556390977444, 172.8390977443609, 172.85263157894735, 172.86616541353382, 172.8796992481203, 172.89323308270676, 172.90676691729323, 172.9203007518797, 172.93383458646616, 172.94736842105263, 172.9609022556391, 172.97443609022557, 172.98796992481203, 173.0015037593985, 173.01503759398497, 173.02857142857144, 173.0421052631579, 173.05563909774435, 173.06917293233082, 173.08270676691728, 173.09624060150375, 173.10977443609022, 173.1233082706767, 173.13684210526316, 173.15037593984962, 173.1639097744361, 173.17744360902256, 173.19097744360903, 173.2045112781955, 173.21804511278197, 173.2315789473684, 173.24511278195487, 173.25864661654134, 173.2721804511278, 173.28571428571428, 173.29924812030075, 173.3127819548872, 173.32631578947368, 173.33984962406015, 173.35338345864662, 173.3669172932331, 173.38045112781955, 173.39398496240602, 173.4075187969925, 173.42105263157896, 173.4345864661654, 173.44812030075187, 173.46165413533834, 173.4751879699248, 173.48872180451127, 173.50225563909774, 173.5157894736842, 173.52932330827068, 173.54285714285714, 173.5563909774436, 173.56992481203008, 173.58345864661655, 173.59699248120302, 173.61052631578946, 173.62406015037593, 173.6375939849624, 173.65112781954886, 173.66466165413533, 173.6781954887218, 173.69172932330827, 173.70526315789473, 173.7187969924812, 173.73233082706767, 173.74586466165414, 173.7593984962406, 173.77293233082708, 173.78646616541354, 173.8, 173.81353383458645, 173.82706766917292, 173.8406015037594, 173.85413533834586, 173.86766917293232, 173.8812030075188, 173.89473684210526, 173.90827067669173, 173.9218045112782, 173.93533834586466, 173.94887218045113, 173.9624060150376, 173.97593984962407, 173.9894736842105, 174.00300751879698, 174.01654135338345, 174.0300751879699, 174.04360902255638, 174.05714285714285, 174.07067669172932, 174.0842105263158, 174.09774436090225, 174.11127819548872, 174.1248120300752, 174.13834586466166, 174.15187969924813, 174.1654135338346, 174.17894736842106, 174.1924812030075, 174.20601503759397, 174.21954887218044, 174.2330827067669, 174.24661654135338, 174.26015037593984, 174.2736842105263, 174.28721804511278, 174.30075187969925, 174.31428571428572, 174.32781954887218, 174.34135338345865, 174.35488721804512, 174.36842105263156, 174.38195488721803, 174.3954887218045, 174.40902255639097, 174.42255639097743, 174.4360902255639, 174.44962406015037, 174.46315789473684, 174.4766917293233, 174.49022556390977, 174.50375939849624, 174.5172932330827, 174.53082706766918, 174.54436090225565, 174.55789473684212, 174.57142857142856, 174.58496240601502, 174.5984962406015, 174.61203007518796, 174.62556390977443, 174.6390977443609, 174.65263157894736, 174.66616541353383, 174.6796992481203, 174.69323308270677, 174.70676691729324, 174.7203007518797, 174.73383458646617, 174.7473684210526, 174.76090225563908, 174.77443609022555, 174.78796992481202, 174.80150375939849, 174.81503759398495, 174.82857142857142, 174.8421052631579, 174.85563909774436, 174.86917293233083, 174.8827067669173, 174.89624060150376, 174.90977443609023, 174.9233082706767, 174.93684210526317, 174.9503759398496, 174.96390977443608, 174.97744360902254, 174.990977443609, 175.00451127819548, 175.01804511278195, 175.03157894736842, 175.04511278195488, 175.05864661654135, 175.07218045112782, 175.0857142857143, 175.09924812030076, 175.11278195488723, 175.12631578947367, 175.13984962406013, 175.1533834586466, 175.16691729323307, 175.18045112781954, 175.193984962406, 175.20751879699247, 175.22105263157894, 175.2345864661654, 175.24812030075188, 175.26165413533835, 175.27518796992481, 175.28872180451128, 175.30225563909775, 175.31578947368422, 175.32932330827066, 175.34285714285713, 175.3563909774436, 175.36992481203006, 175.38345864661653, 175.396992481203, 175.41052631578947, 175.42406015037594, 175.4375939849624, 175.45112781954887, 175.46466165413534, 175.4781954887218, 175.49172932330828, 175.50526315789472, 175.51879699248119, 175.53233082706765, 175.54586466165412, 175.5593984962406, 175.57293233082706, 175.58646616541353, 175.6, 175.61353383458646, 175.62706766917293, 175.6406015037594, 175.65413533834587, 175.66766917293234, 175.6812030075188, 175.69473684210527, 175.7082706766917, 175.72180451127818, 175.73533834586465, 175.74887218045112, 175.76240601503758, 175.77593984962405, 175.78947368421052, 175.803007518797, 175.81654135338346, 175.83007518796992, 175.8436090225564, 175.85714285714286, 175.87067669172933, 175.88421052631577, 175.89774436090224, 175.9112781954887, 175.92481203007517, 175.93834586466164, 175.9518796992481, 175.96541353383458, 175.97894736842105, 175.99248120300751, 176.00601503759398, 176.01954887218045, 176.03308270676692, 176.0466165413534, 176.06015037593986, 176.07368421052632, 176.08721804511276, 176.10075187969923, 176.1142857142857, 176.12781954887217, 176.14135338345864, 176.1548872180451, 176.16842105263157, 176.18195488721804, 176.1954887218045, 176.20902255639098, 176.22255639097745, 176.2360902255639, 176.24962406015038, 176.26315789473682, 176.2766917293233, 176.29022556390976, 176.30375939849623, 176.3172932330827, 176.33082706766916, 176.34436090225563, 176.3578947368421, 176.37142857142857, 176.38496240601503, 176.3984962406015, 176.41203007518797, 176.42556390977444, 176.4390977443609, 176.45263157894738, 176.46616541353382, 176.47969924812028, 176.49323308270675, 176.50676691729322, 176.5203007518797, 176.53383458646616, 176.54736842105262, 176.5609022556391, 176.57443609022556, 176.58796992481203, 176.6015037593985, 176.61503759398497, 176.62857142857143, 176.64210526315787, 176.65563909774434, 176.6691729323308, 176.68270676691728, 176.69624060150375, 176.7097744360902, 176.72330827067668, 176.73684210526315, 176.75037593984962, 176.7639097744361, 176.77744360902255, 176.79097744360902, 176.8045112781955, 176.81804511278196, 176.83157894736843, 176.84511278195487, 176.85864661654134, 176.8721804511278, 176.88571428571427, 176.89924812030074, 176.9127819548872, 176.92631578947368, 176.93984962406014, 176.9533834586466, 176.96691729323308, 176.98045112781955, 176.99398496240602, 177.00751879699249, 177.02105263157893, 177.0345864661654, 177.04812030075186, 177.06165413533833, 177.0751879699248, 177.08872180451127, 177.10225563909773, 177.1157894736842, 177.12932330827067, 177.14285714285714, 177.1563909774436, 177.16992481203008, 177.18345864661654, 177.196992481203, 177.21052631578948, 177.22406015037592, 177.2375939849624, 177.25112781954886, 177.26466165413532, 177.2781954887218, 177.29172932330826, 177.30526315789473, 177.3187969924812, 177.33233082706766, 177.34586466165413, 177.3593984962406, 177.37293233082707, 177.38646616541354, 177.39999999999998, 177.41353383458645, 177.4270676691729, 177.44060150375938, 177.45413533834585, 177.46766917293232, 177.4812030075188, 177.49473684210525, 177.50827067669172, 177.5218045112782, 177.53533834586466, 177.54887218045113, 177.5624060150376, 177.57593984962406, 177.58947368421053, 177.60300751879697, 177.61654135338344, 177.6300751879699, 177.64360902255638, 177.65714285714284, 177.6706766917293, 177.68421052631578, 177.69774436090225, 177.71127819548872, 177.72481203007519, 177.73834586466165, 177.75187969924812, 177.7654135338346, 177.77894736842103, 177.7924812030075, 177.80601503759397, 177.81954887218043, 177.8330827067669, 177.84661654135337, 177.86015037593984, 177.8736842105263, 177.88721804511277, 177.90075187969924, 177.9142857142857, 177.92781954887218, 177.94135338345865, 177.95488721804512, 177.96842105263158, 177.98195488721802, 177.9954887218045, 178.00902255639096, 178.02255639097743, 178.0360902255639, 178.04962406015036, 178.06315789473683, 178.0766917293233, 178.09022556390977, 178.10375939849624, 178.1172932330827, 178.13082706766917, 178.14436090225564, 178.15789473684208, 178.17142857142855, 178.18496240601502, 178.1984962406015, 178.21203007518795, 178.22556390977442, 178.2390977443609, 178.25263157894736, 178.26616541353383, 178.2796992481203, 178.29323308270676, 178.30676691729323, 178.3203007518797, 178.33383458646617, 178.34736842105264, 178.36090225563908, 178.37443609022554, 178.387969924812, 178.40150375939848, 178.41503759398495, 178.42857142857142, 178.44210526315788, 178.45563909774435, 178.46917293233082, 178.4827067669173, 178.49624060150376, 178.50977443609023, 178.5233082706767, 178.53684210526313, 178.5503759398496, 178.56390977443607, 178.57744360902254, 178.590977443609, 178.60451127819547, 178.61804511278194, 178.6315789473684, 178.64511278195488, 178.65864661654135, 178.67218045112782, 178.68571428571428, 178.69924812030075, 178.71278195488722, 178.7263157894737, 178.73984962406013, 178.7533834586466, 178.76691729323306, 178.78045112781953, 178.793984962406, 178.80751879699247, 178.82105263157894, 178.8345864661654, 178.84812030075187, 178.86165413533834, 178.8751879699248, 178.88872180451128, 178.90225563909775, 178.91578947368419, 178.92932330827065, 178.94285714285712, 178.9563909774436, 178.96992481203006, 178.98345864661653, 178.996992481203, 179.01052631578946, 179.02406015037593, 179.0375939849624, 179.05112781954887, 179.06466165413534, 179.0781954887218, 179.09172932330827, 179.10526315789474, 179.11879699248118, 179.13233082706765, 179.14586466165412, 179.15939849624058, 179.17293233082705, 179.18646616541352, 179.2]}, 'lat': {'dims': ('lat',), 'attrs': {}, 'data': [-39.5, -39.48645833333333, -39.47291666666667, -39.459375, -39.44583333333333, -39.432291666666664, -39.41875, -39.405208333333334, -39.391666666666666, -39.378125, -39.364583333333336, -39.35104166666667, -39.3375, -39.32395833333333, -39.31041666666667, -39.296875, -39.28333333333333, -39.26979166666667, -39.25625, -39.24270833333333, -39.229166666666664, -39.215625, -39.202083333333334, -39.188541666666666, -39.175, -39.161458333333336, -39.14791666666667, -39.134375, -39.12083333333333, -39.10729166666667, -39.09375, -39.08020833333333, -39.06666666666667, -39.053125, -39.03958333333333, -39.026041666666664, -39.0125, -38.998958333333334, -38.985416666666666, -38.971875, -38.958333333333336, -38.94479166666667, -38.93125, -38.91770833333333, -38.90416666666667, -38.890625, -38.87708333333333, -38.86354166666667, -38.85, -38.83645833333333, -38.822916666666664, -38.809375, -38.795833333333334, -38.782291666666666, -38.76875, -38.755208333333336, -38.74166666666667, -38.728125, -38.71458333333333, -38.70104166666667, -38.6875, -38.67395833333333, -38.66041666666667, -38.646875, -38.63333333333333, -38.619791666666664, -38.60625, -38.592708333333334, -38.579166666666666, -38.565625, -38.552083333333336, -38.53854166666667, -38.525, -38.51145833333333, -38.49791666666667, -38.484375, -38.47083333333333, -38.45729166666667, -38.44375, -38.43020833333333, -38.416666666666664, -38.403125, -38.389583333333334, -38.376041666666666, -38.3625, -38.348958333333336, -38.33541666666667, -38.321875, -38.30833333333333, -38.29479166666667, -38.28125, -38.26770833333333, -38.25416666666667, -38.240625, -38.22708333333333, -38.213541666666664, -38.2, -38.186458333333334, -38.172916666666666, -38.159375, -38.145833333333336, -38.13229166666667, -38.11875, -38.10520833333333, -38.09166666666667, -38.078125, -38.06458333333333, -38.05104166666667, -38.0375, -38.02395833333333, -38.010416666666664, -37.996875, -37.983333333333334, -37.969791666666666, -37.95625, -37.942708333333336, -37.92916666666667, -37.915625, -37.90208333333333, -37.88854166666667, -37.875, -37.86145833333333, -37.84791666666667, -37.834375, -37.82083333333333, -37.807291666666664, -37.79375, -37.780208333333334, -37.766666666666666, -37.753125, -37.739583333333336, -37.72604166666667, -37.7125, -37.69895833333333, -37.68541666666667, -37.671875, -37.65833333333333, -37.64479166666667, -37.63125, -37.61770833333333, -37.604166666666664, -37.590625, -37.577083333333334, -37.563541666666666, -37.55, -37.536458333333336, -37.52291666666667, -37.509375, -37.49583333333333, -37.48229166666667, -37.46875, -37.45520833333333, -37.44166666666666, -37.428125, -37.41458333333333, -37.401041666666664, -37.3875, -37.373958333333334, -37.360416666666666, -37.346875, -37.333333333333336, -37.31979166666667, -37.30625, -37.29270833333333, -37.27916666666667, -37.265625, -37.25208333333333, -37.23854166666666, -37.225, -37.21145833333333, -37.197916666666664, -37.184375, -37.170833333333334, -37.157291666666666, -37.14375, -37.130208333333336, -37.11666666666667, -37.103125, -37.08958333333333, -37.07604166666667, -37.0625, -37.04895833333333, -37.03541666666666, -37.021875, -37.00833333333333, -36.994791666666664, -36.98125, -36.967708333333334, -36.954166666666666, -36.940625, -36.927083333333336, -36.91354166666667, -36.9, -36.88645833333333, -36.87291666666667, -36.859375, -36.84583333333333, -36.83229166666666, -36.81875, -36.80520833333333, -36.791666666666664, -36.778125, -36.764583333333334, -36.751041666666666, -36.7375, -36.723958333333336, -36.71041666666667, -36.696875, -36.68333333333333, -36.66979166666667, -36.65625, -36.64270833333333, -36.62916666666666, -36.615625, -36.60208333333333, -36.588541666666664, -36.575, -36.561458333333334, -36.547916666666666, -36.534375, -36.520833333333336, -36.50729166666667, -36.49375, -36.48020833333333, -36.46666666666667, -36.453125, -36.43958333333333, -36.42604166666666, -36.4125, -36.39895833333333, -36.385416666666664, -36.371875, -36.358333333333334, -36.344791666666666, -36.33125, -36.317708333333336, -36.30416666666667, -36.290625, -36.27708333333333, -36.26354166666667, -36.25, -36.23645833333333, -36.22291666666666, -36.209375, -36.19583333333333, -36.182291666666664, -36.16875, -36.155208333333334, -36.141666666666666, -36.128125, -36.114583333333336, -36.10104166666667, -36.0875, -36.07395833333333, -36.06041666666667, -36.046875, -36.03333333333333, -36.01979166666666, -36.00625, -35.99270833333333, -35.979166666666664, -35.965625, -35.952083333333334, -35.938541666666666, -35.925, -35.911458333333336, -35.89791666666667, -35.884375, -35.87083333333333, -35.85729166666667, -35.84375, -35.83020833333333, -35.81666666666666, -35.803125, -35.78958333333333, -35.776041666666664, -35.7625, -35.748958333333334, -35.735416666666666, -35.721875, -35.708333333333336, -35.69479166666667, -35.68125, -35.66770833333333, -35.65416666666667, -35.640625, -35.62708333333333, -35.61354166666666, -35.6, -35.58645833333333, -35.572916666666664, -35.559375, -35.545833333333334, -35.532291666666666, -35.51875, -35.505208333333336, -35.49166666666667, -35.478125, -35.46458333333334, -35.45104166666667, -35.4375, -35.42395833333333, -35.41041666666666, -35.396875, -35.38333333333333, -35.369791666666664, -35.35625, -35.342708333333334, -35.329166666666666, -35.315625, -35.302083333333336, -35.28854166666667, -35.275, -35.26145833333334, -35.24791666666667, -35.234375, -35.22083333333333, -35.20729166666666, -35.19375, -35.18020833333333, -35.166666666666664, -35.153125, -35.139583333333334, -35.126041666666666, -35.1125, -35.098958333333336, -35.08541666666667, -35.071875, -35.05833333333334, -35.04479166666667, -35.03125, -35.01770833333333, -35.00416666666666, -34.990625, -34.97708333333333, -34.963541666666664, -34.95, -34.936458333333334, -34.922916666666666, -34.909375, -34.895833333333336, -34.88229166666667, -34.86875, -34.85520833333334, -34.84166666666667, -34.828125, -34.81458333333333, -34.80104166666666, -34.7875, -34.77395833333333, -34.760416666666664, -34.746875, -34.733333333333334, -34.719791666666666, -34.70625, -34.692708333333336, -34.67916666666667, -34.665625, -34.65208333333334, -34.63854166666667, -34.625, -34.61145833333333, -34.59791666666666, -34.584375, -34.57083333333333, -34.557291666666664, -34.54375, -34.530208333333334, -34.516666666666666, -34.503125, -34.489583333333336, -34.47604166666667, -34.4625, -34.44895833333334, -34.43541666666667, -34.421875, -34.40833333333333, -34.39479166666666, -34.38125, -34.36770833333333, -34.354166666666664, -34.340625, -34.327083333333334, -34.313541666666666, -34.3, -34.286458333333336, -34.27291666666667, -34.259375, -34.24583333333334, -34.23229166666667, -34.21875, -34.20520833333333, -34.19166666666666, -34.178125, -34.16458333333333, -34.151041666666664, -34.1375, -34.123958333333334, -34.110416666666666, -34.096875, -34.083333333333336, -34.06979166666667, -34.05625, -34.04270833333334, -34.02916666666667, -34.015625, -34.00208333333333, -33.98854166666666, -33.975, -33.96145833333333, -33.947916666666664, -33.934375, -33.920833333333334, -33.907291666666666, -33.89375, -33.880208333333336, -33.86666666666667, -33.853125, -33.83958333333334, -33.82604166666667, -33.8125, -33.79895833333333, -33.78541666666666, -33.771875, -33.75833333333333, -33.744791666666664, -33.73125, -33.717708333333334, -33.704166666666666, -33.690625, -33.677083333333336, -33.66354166666667, -33.65, -33.63645833333334, -33.62291666666667, -33.609375, -33.59583333333333, -33.58229166666666, -33.56875, -33.55520833333333, -33.541666666666664, -33.528125, -33.514583333333334, -33.501041666666666, -33.4875, -33.473958333333336, -33.46041666666667, -33.446875, -33.43333333333334, -33.41979166666667, -33.40625, -33.39270833333333, -33.37916666666666, -33.365625, -33.35208333333333, -33.338541666666664, -33.325, -33.311458333333334, -33.297916666666666, -33.284375, -33.270833333333336, -33.25729166666667, -33.24375, -33.23020833333333, -33.21666666666667, -33.203125, -33.18958333333333, -33.17604166666666, -33.1625, -33.14895833333333, -33.135416666666664, -33.121875, -33.108333333333334, -33.094791666666666, -33.08125, -33.067708333333336, -33.05416666666667, -33.040625, -33.02708333333333, -33.01354166666667, -33.0]}}, 'attrs': {}, 'dims': {'lon': 533, 'lat': 481}, 'data_vars': {}}

#==================================================

source_data_dict = {'coords': {'latitude': {'dims': ('latitude',), 'attrs': {}, 'data': [-37.35138884, -37.34687495, -37.34236106, -37.33784717, -37.333333280000005, -37.32881939000001, -37.32430550000001, -37.31979161000001, -37.31527772000001, -37.31076383000001, -37.306249940000015, -37.30173605000002, -37.29722216000002, -37.29270827000002, -37.28819438000002, -37.28368049000002, -37.279166600000025, -37.274652710000026, -37.27013882000003, -37.26562493000003, -37.26111104000003, -37.25659715000003, -37.252083260000035, -37.247569370000036, -37.24305548000004, -37.23854159000004, -37.23402770000004, -37.22951381000004, -37.224999920000045, -37.220486030000046, -37.21597214000005, -37.21145825000005, -37.20694436000005, -37.20243047000005, -37.197916580000054, -37.193402690000056, -37.18888880000006, -37.18437491000006, -37.17986102000006, -37.17534713000006, -37.170833240000064, -37.166319350000066, -37.16180546000007, -37.15729157000007, -37.15277768000007, -37.14826379000007, -37.143749900000074, -37.139236010000076, -37.13472212000008, -37.13020823000008, -37.12569434000008, -37.12118045000008, -37.116666560000084, -37.112152670000086, -37.10763878000009, -37.10312489000009, -37.09861100000009, -37.09409711000009, -37.089583220000094, -37.085069330000096, -37.0805554400001, -37.0760415500001, -37.0715276600001, -37.0670137700001, -37.062499880000104, -37.057985990000105, -37.05347210000011, -37.04895821000011, -37.04444432000011, -37.03993043000011, -37.035416540000114, -37.030902650000115, -37.02638876000012, -37.02187487000012, -37.01736098000012, -37.01284709000012, -37.00833320000012, -37.003819310000125, -36.99930542000013, -36.99479153000013, -36.99027764000013, -36.98576375000013, -36.98124986000013, -36.976735970000135, -36.97222208000014, -36.96770819000014, -36.96319430000014, -36.95868041000014, -36.95416652000014, -36.949652630000145, -36.94513874000015, -36.94062485000015, -36.93611096000015, -36.93159707000015, -36.92708318000015, -36.922569290000155, -36.918055400000156, -36.91354151000016, -36.90902762000016, -36.90451373000016, -36.89999984000016, -36.895485950000165, -36.890972060000166, -36.88645817000017, -36.88194428000017, -36.87743039000017, -36.87291650000017, -36.868402610000174, -36.863888720000176, -36.85937483000018, -36.85486094000018, -36.85034705000018, -36.84583316000018, -36.841319270000184, -36.836805380000186, -36.83229149000019, -36.82777760000019, -36.82326371000019, -36.81874982000019, -36.814235930000194, -36.809722040000196, -36.8052081500002, -36.8006942600002, -36.7961803700002, -36.7916664800002, -36.787152590000204, -36.782638700000206, -36.77812481000021, -36.77361092000021, -36.76909703000021, -36.76458314000021, -36.760069250000214, -36.755555360000216, -36.75104147000022, -36.74652758000022, -36.74201369000022, -36.73749980000022, -36.732985910000224, -36.728472020000225, -36.72395813000023, -36.71944424000023, -36.71493035000023, -36.71041646000023, -36.705902570000234, -36.701388680000235, -36.69687479000024, -36.69236090000024, -36.68784701000024, -36.68333312000024, -36.678819230000244, -36.674305340000245, -36.66979145000025, -36.66527756000025, -36.66076367000025, -36.65624978000025, -36.65173589000025, -36.647222000000255, -36.64270811000026, -36.63819422000026, -36.63368033000026, -36.62916644000026, -36.62465255000026, -36.620138660000265, -36.61562477000027, -36.61111088000027, -36.60659699000027, -36.60208310000027, -36.59756921000027, -36.593055320000275, -36.58854143000028, -36.58402754000028, -36.57951365000028, -36.57499976000028, -36.57048587000028, -36.565971980000285, -36.561458090000286, -36.55694420000029, -36.55243031000029, -36.54791642000029, -36.54340253000029, -36.538888640000295, -36.534374750000296, -36.5298608600003, -36.5253469700003, -36.5208330800003, -36.5163191900003, -36.511805300000304, -36.507291410000306, -36.50277752000031, -36.49826363000031, -36.49374974000031, -36.48923585000031, -36.484721960000314, -36.480208070000316, -36.47569418000032, -36.47118029000032, -36.46666640000032, -36.46215251000032, -36.457638620000324, -36.453124730000326, -36.44861084000033, -36.44409695000033, -36.43958306000033, -36.43506917000033, -36.430555280000334, -36.426041390000336, -36.42152750000034, -36.41701361000034, -36.41249972000034, -36.40798583000034, -36.403471940000344, -36.398958050000346, -36.39444416000035, -36.38993027000035, -36.38541638000035, -36.38090249000035, -36.376388600000354, -36.371874710000355, -36.36736082000036, -36.36284693000036, -36.35833304000036, -36.35381915000036, -36.349305260000364, -36.344791370000365, -36.34027748000037, -36.33576359000037, -36.33124970000037, -36.32673581000037, -36.32222192000037, -36.317708030000375, -36.31319414000038, -36.30868025000038, -36.30416636000038, -36.29965247000038, -36.29513858000038, -36.290624690000385, -36.28611080000039, -36.28159691000039, -36.27708302000039, -36.27256913000039, -36.26805524000039, -36.263541350000395, -36.2590274600004, -36.2545135700004, -36.2499996800004, -36.2454857900004, -36.2409719000004, -36.236458010000405, -36.231944120000406, -36.22743023000041, -36.22291634000041, -36.21840245000041, -36.21388856000041, -36.209374670000415, -36.204860780000416, -36.20034689000042, -36.19583300000042, -36.19131911000042, -36.18680522000042, -36.182291330000425, -36.177777440000426, -36.17326355000043, -36.16874966000043, -36.16423577000043, -36.15972188000043, -36.155207990000434, -36.150694100000436, -36.14618021000044, -36.14166632000044, -36.13715243000044, -36.13263854000044, -36.128124650000444, -36.123610760000446, -36.11909687000045, -36.11458298000045, -36.11006909000045, -36.10555520000045, -36.101041310000454, -36.096527420000456, -36.09201353000046, -36.08749964000046, -36.08298575000046, -36.07847186000046, -36.073957970000464, -36.069444080000466, -36.06493019000047, -36.06041630000047, -36.05590241000047, -36.05138852000047, -36.046874630000474, -36.042360740000476, -36.03784685000048, -36.03333296000048, -36.02881907000048, -36.02430518000048, -36.019791290000484, -36.015277400000485, -36.01076351000049, -36.00624962000049, -36.00173573000049, -35.99722184000049, -35.992707950000494, -35.988194060000495, -35.9836801700005, -35.9791662800005, -35.9746523900005]}, 'longitude': {'dims': ('longitude',), 'attrs': {}, 'data': [174.05263073, 174.05714201, 174.06165329, 174.06616457, 174.07067585000001, 174.07518713000002, 174.07969841000002, 174.08420969000002, 174.08872097000003, 174.09323225000003, 174.09774353000003, 174.10225481000003, 174.10676609000004, 174.11127737000004, 174.11578865000004, 174.12029993000004, 174.12481121000005, 174.12932249000005, 174.13383377000005, 174.13834505000005, 174.14285633000006, 174.14736761000006, 174.15187889000006, 174.15639017000007, 174.16090145000007, 174.16541273000007, 174.16992401000007, 174.17443529000008, 174.17894657000008, 174.18345785000008, 174.18796913000008, 174.1924804100001, 174.1969916900001, 174.2015029700001, 174.2060142500001, 174.2105255300001, 174.2150368100001, 174.2195480900001, 174.2240593700001, 174.2285706500001, 174.2330819300001, 174.2375932100001, 174.24210449000012, 174.24661577000012, 174.25112705000012, 174.25563833000012, 174.26014961000013, 174.26466089000013, 174.26917217000013, 174.27368345000014, 174.27819473000014, 174.28270601000014, 174.28721729000014, 174.29172857000015, 174.29623985000015, 174.30075113000015, 174.30526241000015, 174.30977369000016, 174.31428497000016, 174.31879625000016, 174.32330753000016, 174.32781881000017, 174.33233009000017, 174.33684137000017, 174.34135265000018, 174.34586393000018, 174.35037521000018, 174.35488649000018, 174.3593977700002, 174.3639090500002, 174.3684203300002, 174.3729316100002, 174.3774428900002, 174.3819541700002, 174.3864654500002, 174.3909767300002, 174.3954880100002, 174.3999992900002, 174.4045105700002, 174.40902185000022, 174.41353313000022, 174.41804441000022, 174.42255569000022, 174.42706697000023, 174.43157825000023, 174.43608953000023, 174.44060081000023, 174.44511209000024, 174.44962337000024, 174.45413465000024, 174.45864593000024, 174.46315721000025, 174.46766849000025, 174.47217977000025, 174.47669105000026, 174.48120233000026, 174.48571361000026, 174.49022489000026, 174.49473617000027, 174.49924745000027, 174.50375873000027, 174.50827001000027, 174.51278129000028, 174.51729257000028, 174.52180385000028, 174.52631513000028, 174.5308264100003, 174.5353376900003, 174.5398489700003, 174.5443602500003, 174.5488715300003, 174.5533828100003, 174.5578940900003, 174.5624053700003, 174.5669166500003, 174.5714279300003, 174.5759392100003, 174.58045049000032, 174.58496177000032, 174.58947305000032, 174.59398433000032, 174.59849561000033, 174.60300689000033, 174.60751817000033, 174.61202945000034, 174.61654073000034, 174.62105201000034, 174.62556329000034, 174.63007457000035, 174.63458585000035, 174.63909713000035, 174.64360841000035, 174.64811969000036, 174.65263097000036, 174.65714225000036, 174.66165353000036, 174.66616481000037, 174.67067609000037, 174.67518737000037, 174.67969865000038, 174.68420993000038, 174.68872121000038, 174.69323249000038, 174.6977437700004, 174.7022550500004, 174.7067663300004, 174.7112776100004, 174.7157888900004, 174.7203001700004, 174.7248114500004, 174.7293227300004, 174.7338340100004, 174.7383452900004, 174.7428565700004, 174.74736785000042, 174.75187913000042, 174.75639041000042, 174.76090169000042, 174.76541297000043, 174.76992425000043, 174.77443553000043, 174.77894681000043, 174.78345809000044, 174.78796937000044, 174.79248065000044, 174.79699193000044, 174.80150321000045, 174.80601449000045, 174.81052577000045, 174.81503705000046, 174.81954833000046, 174.82405961000046, 174.82857089000046, 174.83308217000047, 174.83759345000047, 174.84210473000047, 174.84661601000047, 174.85112729000048, 174.85563857000048, 174.86014985000048, 174.86466113000048, 174.8691724100005, 174.8736836900005, 174.8781949700005, 174.8827062500005, 174.8872175300005, 174.8917288100005, 174.8962400900005, 174.9007513700005, 174.9052626500005, 174.9097739300005, 174.91428521000051, 174.91879649000052, 174.92330777000052, 174.92781905000052, 174.93233033000053, 174.93684161000053, 174.94135289000053, 174.94586417000053, 174.95037545000054, 174.95488673000054, 174.95939801000054, 174.96390929000054, 174.96842057000055, 174.97293185000055, 174.97744313000055, 174.98195441000055, 174.98646569000056, 174.99097697000056, 174.99548825000056, 174.99999953000057, 175.00451081000057, 175.00902209000057, 175.01353337000057, 175.01804465000058, 175.02255593000058, 175.02706721000058, 175.03157849000058, 175.0360897700006, 175.0406010500006, 175.0451123300006, 175.0496236100006, 175.0541348900006, 175.0586461700006, 175.0631574500006, 175.0676687300006, 175.0721800100006, 175.0766912900006, 175.0812025700006, 175.08571385000062, 175.09022513000062, 175.09473641000062, 175.09924769000062, 175.10375897000063, 175.10827025000063, 175.11278153000063, 175.11729281000063, 175.12180409000064, 175.12631537000064, 175.13082665000064, 175.13533793000065, 175.13984921000065, 175.14436049000065, 175.14887177000065, 175.15338305000066, 175.15789433000066, 175.16240561000066, 175.16691689000066, 175.17142817000067, 175.17593945000067, 175.18045073000067, 175.18496201000067, 175.18947329000068, 175.19398457000068, 175.19849585000068, 175.20300713000069, 175.2075184100007, 175.2120296900007, 175.2165409700007, 175.2210522500007, 175.2255635300007, 175.2300748100007, 175.2345860900007, 175.2390973700007, 175.2436086500007, 175.2481199300007, 175.25263121000071, 175.25714249000072, 175.26165377000072, 175.26616505000072, 175.27067633000073, 175.27518761000073, 175.27969889000073, 175.28421017000073, 175.28872145000074, 175.29323273000074, 175.29774401000074, 175.30225529000074, 175.30676657000075, 175.31127785000075, 175.31578913000075, 175.32030041000075, 175.32481169000076, 175.32932297000076, 175.33383425000076, 175.33834553000077, 175.34285681000077, 175.34736809000077, 175.35187937000077, 175.35639065000078, 175.36090193000078, 175.36541321000078, 175.36992449000078, 175.3744357700008, 175.3789470500008, 175.3834583300008, 175.3879696100008]}}, 'attrs': {}, 'dims': {'latitude': 306, 'longitude': 297}, 'data_vars': {}}

ds_destination_grid = xr.Dataset.from_dict(destination_grid_dict)
ds_source = xr.Dataset.from_dict(source_data_dict)
ds_source = ds_source.assign(
    vals=(
        ("latitude", "longitude"),
        np.ones((ds_source.latitude.size, ds_source.longitude.size)),
    )
)
regridder = xesmf.Regridder(ds_source, ds_destination_grid, method="conservative")
ds_regridded = regridder(ds_source)

print("ds_source total: {:0.4e}".format(float(ds_source.vals.sum())))
print("ds_regridded total: {:0.4e}".format(float(ds_regridded.vals.sum())))
```

For me this results in
ds_source total: 9.0882e+04
ds_regridded total: 1.0098e+04

I expected ds_regridded.sum() to be very close to 9.0882e+04.

Discussion:

Patch:
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 892a4e8..db376f2 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -48,6 +48,11 @@ jobs:
           extra-specs: |
             python=${{ matrix.python-version }}
             esmpy=${{ matrix.esmf-version }}
+      - name: Fix env for esmpy 8.4
+        run: |
+          if [ "${{ matrix.esmf-version }}" == "8.4" ]; then
+              conda install "importlib-metadata<8.0.0"
+          fi
       - name: Install Xesmf (editable)
         run: |
           python -m pip install --no-deps -e .
diff --git a/CHANGES.rst b/CHANGES.rst
index e8f65fc..34ec9ea 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -3,6 +3,7 @@ What's new
 
 0.8.6 (unreleased)
 ------------------
+* New ``xe.util.cell_area`` utility to compute the cell area using ESMF's internal mechanism. (:pull:`372`, :issue:`369`) By `Jiawei Zhuang <https://github.com/JiaweiZhuang>`_  and `Pascal Bourgault <https://github.com/aulemahal>`_.
 * Compatibility with Numpy 2.0 (NaN vs nan) (:pull:`373`) By `Pascal Bourgault <https://github.com/aulemahal>`_.
 
 0.8.5 (2024-04-11)
diff --git a/xesmf/util.py b/xesmf/util.py
index 4790b11..354c67d 100644
--- a/xesmf/util.py
+++ b/xesmf/util.py
@@ -4,6 +4,11 @@ import numpy as np
 import xarray as xr
 from shapely.geometry import MultiPolygon, Polygon
 
+try:
+    import esmpy as ESMF
+except ImportError:
+    import ESMF
+
 LON_CF_ATTRS = {'standard_name': 'longitude', 'units': 'degrees_east'}
 LAT_CF_ATTRS = {'standard_name': 'latitude', 'units': 'degrees_north'}
 
@@ -159,7 +164,6 @@ def grid_global(d_lon, d_lat, cf=False, lon1=180):
             '180 cannot be divided by d_lat = {}, '
             'might not cover the globe uniformly'.format(d_lat)
         )
-
     lon0 = lon1 - 360
 
     if cf:
@@ -356,3 +360,50 @@ def _mdist(x1, x2):
 
 
 # end code from https://github.com/NOAA-GFDL/ocean_model_grid_generator
+
+
+def cell_area(ds, earth_radius=None):
+    """
+    Get cell area of a grid, assuming a sphere.
+
+    Parameters
+    ----------
+    ds : xarray Dataset
+        Input grid, longitude and latitude required.
+        Curvilinear coordinate system also require cell bounds to be present.
+    earth_radius : float, optional
+        Earth radius, assuming a sphere, in km.
+
+    Returns
+    -------
+    area : xarray DataArray
+        Cell area. If the earth radius is given, units are km^2, otherwise they are steradian (sr).
+    """
+    from .frontend import _get_lon_lat, ds_to_ESMFgrid  # noqa
+
+    grid, _, names = ds_to_ESMFgrid(ds, need_bounds=True)
+    field = ESMF.Field(grid)
+    field.get_area()  # compute area
+
+    # F-ordering to C-ordering
+    # copy the array to make sure it persists after ESMF object is freed
+    area = field.data.T.copy()
+    field.destroy()
+
+    # Wrap in xarray
+    area = xr.DataArray(
+        area,
+        dims=names,
+        attrs={
+            'units': 'sr',
+            'standard_name': 'cell_area',
+            'long_name': 'Cell area, assuming a sphere.',
+        },
+    )
+    # Fancy trick to get all related coordinates without needing to list them explicitly.
+    # We add all and let xarray choose which one to keep when selecting the variable
+    area = ds.coords.to_dataset().assign(area=area).area
+
+    if earth_radius is not None:
+        area = (area * earth_radius**2).assign_attrs(units='km2')
+    return area


Test patch:
diff --git a/xesmf/tests/test_util.py b/xesmf/tests/test_util.py
index b2d7c2d..5e0680f 100644
--- a/xesmf/tests/test_util.py
+++ b/xesmf/tests/test_util.py
@@ -1,4 +1,6 @@
+import numpy as np
 import pytest
+from numpy.testing import assert_almost_equal
 
 import xesmf as xe
 
@@ -34,6 +36,14 @@ def test_grid_global_bad_resolution():
         xe.util.grid_global(1.23, 1.5)
 
 
+def test_cell_area():
+    ds = xe.util.grid_global(2.5, 2)
+    area = xe.util.cell_area(ds)
+
+    # total area of a unit sphere
+    assert_almost_equal(area.sum(), np.pi * 4)
+
+
 def test_simple_tripolar_grid():
     lon, lat = xe.util.simple_tripolar_grid(360, 180, lat_cap=60, lon_cut=-300.0)