JGCRI / tethys

Spatiotemporal downscaling model for global water use
https://jgcri.github.io/tethys/
BSD 2-Clause "Simplified" License
26 stars 11 forks source link

regrid (lines 151-160) in gridded.py may have issues #71

Open zarrarkhan opened 3 months ago

zarrarkhan commented 3 months ago

@crvernon @hassaniazi

Please note that Mengqi & I were trying to use the regrid part of this code for the Building Energy Demand (BED) model and were running into issues when testing line 151-160 in gridded.py. We were performing a manual check on how this chunk was re-gridding examples co-ordinates and we thought it was not working as expected. Someone, should just double check this code again.

https://github.com/JGCRI/tethys/blob/933d117831cc30647c1babf91202941a9136f90e/tethys/datareader/gridded.py#L151

if method == 'label':
    ds = ds.isel(lon=np.arange(ds.lon.size).repeat(r)).coarsen(lon=s).max()
    ds = ds.isel(lat=np.arange(ds.lat.size).repeat(r)).coarsen(lat=s).max()
else:
    ds = ds.isel(lon=np.arange(ds.lon.size).repeat(r)).coarsen(lon=s).sum()
    ds = ds.isel(lat=np.arange(ds.lat.size).repeat(r)).coarsen(lat=s).sum()
    if method == 'extensive':
        ds = ds / (r * r)  # preserve original sum
    elif method == 'intensive':
        ds = ds / (s * s)  # take average
crvernon commented 3 months ago

Thanks @zarrarkhan! I'll check this out ASAP.