chrisvwn / Rnightlights

R package to extract data from satellite nightlights.
GNU General Public License v3.0
47 stars 14 forks source link

Zonal stats and custom function #20

Closed jigten closed 5 years ago

jigten commented 5 years ago

Hi Chris, Thanks for the great package and sorry to submit an issue but I really need some help. Are the zonal statistics calculated in the lowest resolution possible? For example, if I were to calculate the standard deviation, is it the standard deviation of the brightness of each pixel observed inside an administrative boundary? Also, I want to calculate the GINI coefficient to determine the inequality of night light in a given administrative boundary, is this possible? Can you maybe provide some pointers on how I could implement this? Thank you once again.

chrisvwn commented 5 years ago

Hi @jigten , You're welcome and I'm glad you are finding it useful. Yes, the zonal statistics are calculated at the pixel level on the raster tiles, so each pixel in an admin boundary is included in calculations. Using your standard deviation example the result would be the standard deviation of all the pixels in each member of an admin level E.g. for the USA it would be the standard deviation of all the pixels that fall in each state for example. So you would have 50 standard deviations calculated.

You should be able to calculate the GINI coefficient. Note, you can apply any function to each member of a country admin boundary. So for example, you can create a function to calculate your estimate of wealth and pass it to getCtryNlData. It should be able to take in a numeric vector (pixel radiances) and return a scalar. This would give you a number for each member at the given admin boundary level. Using these values you should be able to calculate the GINI coefficient.

HTH.

jigten commented 5 years ago

Hi Chris, Thanks for the swift reply. I was able to calculate the GINI index for the admin levels that I wanted. One last question, is there a method to extract the raw pixel radiance for each pixel inside a given admin level? Or would the resulting data be too large?

Thanks again.

chrisvwn commented 5 years ago

Hi @jigten ,

I am glad you got that working. Yes, retrieving raw pixel radiances would be cumbersome. However, you have the raster from which you can extract the pixel values directly using the raster package. The cropped raster can be found in the Rnightlights outputrasters folder.

chrisvwn commented 5 years ago

Closing this issue.