Skip to content

change regridding method

@b324056 , @b381971

currently crop data is regridded to the grid of climatological data and is set up as nearest_s2d, we have 3 crop info. How should we handle it?

Variable Type Recommended Method Notes
Natural area (e.g., land cover) Categorical nearest_s2d Keep category labels intact; avoid interpolation
DOY (Day of Year) Intensive bilinear Continuous variable; spatially smooth
Yield (dt/ha) Intensive* conservative Use area-weighted conversion: rate → total → regrid → rate again

Since we would want to preserve the crop production we would need to transform rates to total quantities, regrid conservatively and then recalculate the rates again. For that we need the areacell, the area x grid point

Luckily I do have a subroutine that calculates that in my spatial_utils.py.

so, it should be sthign roughly like this (I write it here so I do not forget):

import xesmf as xe

# 1. Convert yield rate (dt/ha) → total yield (dt)
# Note: 1 ha = 10,000 m²
calc_area_in = compute_area(yield_rate) # ds = self._calc_area(ds, ds_info)
total_yield = yield_rate * (calc_area_in / 10_000)  # [dt]

# 2. Wrap into a Dataset if needed for regridding
total_yield_ds = total_yield.to_dataset(name='total_yield')

# 3. Create regridder and apply conservative regridding
regridder = xe.Regridder(total_yield_ds, ds_out, method='conservative')
regridded_total_yield = regridder(total_yield_ds)['total_yield']

# 4. Recompute area on the output grid (same way you did before)
# Assume you use the same area computation routine on ds_out:
calc_area_out = compute_area(ds_out)  # your existing function

# 5. Convert total yield back to yield rate (dt/ha)
regridded_yield_rate = regridded_total_yield * (10_000 / calc_area_out)

@b381971 : your yield data you calculate in decitons? in another unit? (I would probably need to modify this to accomodate your pontential data)