I'm looking for a process to convert ASCII gridded data (in this case 60min/1 degree gridded ASCII population data (GPW) from SEDAC: https://sedac.ciesin.columbia.edu/data/set/gpw-v4-population-count-adjusted-to-2015-unwpp-country-totals-rev11/data-download) to a CSV with three columns: lon, lat, and value using open source tools.
This is the data header:
ncols 360
nrows 180
xllcorner -180
yllcorner -90
cellsize 1.0000000000001
NODATA_value -9999
so the data is structured as space-separated values, with each value occupying a position within 360 columns and 180 rows that represents its coordinates via that position:
-9999 -9999 -9999 -9999 -9999 -9999 0.000936705 0.002529013 0.001377391 0.001723122 0.0004472999 ...
I only want to include positive values in the lon/lat CSV.
I've been using GDAL for other tasks and have been looking in the documentation, but I'm not seeing this type of data manipulation in its scope.
Best Answer
You can do this with rioxarray:
Note: I used
data
for the column name asvalues
is a pandas specific attribute.