1

I want to regrid population data from 0.05 degrees to 0.1 degrees. Because it is population, I should aggregate (sum) population values for resampling data to a coarser resolution. Although I thought that there going to be a simple answer to this question, I did find any yet. I think my question does not need sample data, but you may find the population data from Gridded Population of the World (GPW), v4.

Thanks for your help.

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86

3 Answers3

2

With NCO you would first convert the population data to an intensive field (population per unit area), then "regrid", then, if you want, convert back to an extensive variable (population), e.g.,

ncap2 -s 'pop_per_area=pop/area' in.nc pop_area.nc
ncremap -G latlon=1800,3600 -g dest_grid.nc
ncremap -d dest_grid.nc pop_area.nc out.nc
ncap2 -s 'pop=pop_per_area*area' out.nc pop.nc

All commands documented here. Good luck!

Charlie Zender
  • 5,929
  • 14
  • 19
2

You could also duplicate Charlie's conversion approach using cdo, but because your gridbox sizes (before/after) are an integral multiple of each other (i.e. you want to aggregate over a 2x2 pixel square), then it is simpler to directly use the cdo function gridboxsum

 cdo gridboxsum,2,2 in.nc out.nc
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
0

What about using xarray packages to read the netcdf files, convert the ND xarray data arrays to pandas dataframes. Then use pandas to achieve what you need. Then you can convert pandas dataframes back to xarray data arrays and save out as netCDF files. Everything should be straightforward using xarray. My only concern is that xarray may not work for some netCDF files, which have sub data groups. In those cases, you may need other Python packages to read the netcdf files, like netCDF.

Or there is a Python regridding tool called xESMF, but I have not tried it yet.

Jeremy
  • 849
  • 6
  • 15
  • Thanks for your reply. I have used NetCDF 4 packages to read NetCDF data, then I used binned_statistic_2d. It is more straightforward than pandas in that in binned_statistic_2d you do not need to apply group by and aggregate functions. – Seyed Omid Nabavi Aug 31 '21 at 13:02