I'm working with the nightlights data - 30 arc second grids, spanning -180 to 180 degrees longitude and -65 to 75 degrees latitude. I want to downsample it to 5 arc-min resolution.

Now my question is how to best do it? I'm using rasterio to load the data and looked at this way but it does not work for me as I'm using python 3 and get error - "TypeError: 'float' object cannot be interpreted as an integer" I'm also worried as to how it will impact my coordinate systems etc.

I haven't found anything latest on this yet. What's the best way to go about it?

nlight_path = "./data/nightlights/F182013.v4c_web.stable_lights.avg_vis.tif"
# open raster data
with rio.open(nlight_path) as src:
    nlight = src.read(masked=True, indexes = 1)
    nlight_meta = src.profile
    nlight_extent = rio.plot.plotting_extent(src)

(-180.00416666665, 180.00416522665, -65.00416610665, 75.00416666665)
{'driver': 'GTiff', 'dtype': 'uint8', 'nodata': None, 'width': 43201, 'height': 16801, 'count': 1, 'crs': CRS.from_dict(init='epsg:4326'), 'transform': Affine(0.0083333333, 0.0, -180.00416666665,
       0.0, -0.0083333333, 75.00416666665), 'tiled': False, 'interleave': 'band'}
(16801, 43201)
<class 'numpy.ma.core.MaskedArray'>

Also can I directly do the downsampling on masked array? But then how will it affect the mask?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.