chrisvwn / Rnightlights

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

Error running the Rnighlights code #76

Open tiamiyu99 opened 3 years ago

tiamiyu99 commented 3 years ago

Hi,

Thank you for creating this wonderful package. I had a problem when running the code. Please find below, I'd appreciate your support in resolving it.

load libraries

library(Rnightlights) library(lubridate) library(reshape2)

setwd(".")

getCtryNlData("KEN", "KEN_adm0", "VIIRS.Y", nlPeriods = nlRange("2015", "2016"), nlStats = "sum", ignoreMissing=FALSE)

The results below is what I then see

Error in if (!file.exists(ntLtsPageLocalName) || file.size(ntLtsPageLocalName) == : missing value where TRUE/FALSE needed

Once again, thank you.

JMejuto commented 3 years ago

Hi,

I am having exactly the same issue, thank you in advance.

chrisvwn commented 3 years ago

Hi,

Apologies for the late response. Please post the code that you are running.

JMejuto commented 3 years ago

Hi, @chrisvwn!

just the example from the web:

library(Rnightlights) library(lubridate) library(reshape2)

(Optional performance enhancement if you have aria2c and gdal installed)

pkgOptions(downloadMethod = "aria", cropMaskMethod = "gdal", extractMethod = "gdal", deleteTiles = TRUE)

Optional performance enhancement. If extractMethod="rast" you can specify the number of

CPU cores to use in parallel

pkgOptions(extractMethod = "rast", numCores=4)

ctry <- "TUR" #replace to run for any other country

download and process monthly VIIRS stats at the highest admin level

highestAdmLevelStats <- getCtryNlData(ctryCode = ctry, admLevel = "highest", nlType = "VIIRS.M", nlPeriods = nlRange("201401", "201412"), nlStats = list("sum",na.rm=TRUE), ignoreMissing=FALSE)

Optionally plot the data

library(ggplot2) library(plotly)

melt the stats into key-value format for easy multi-line plotting with ggplot2

highestAdmLevelStats <- melt(highestAdmLevelStats, id.vars = grep("NL_", names(highestAdmLevelStats), invert=TRUE), variable.name = "nlPeriod", value.name = "radiancesum")

extract date from the NL col names

highestAdmLevelStats$nlPeriod <- substr(highestAdmLevelStats$nlPeriod, 12, 17)

format period as date

highestAdmLevelStats$nlPeriod <- ymd(paste0(substr(highestAdmLevelStats$nlPeriod, 1,4), "-",substr(highestAdmLevelStats$nlPeriod, 5,6), "-01"))

plot 2nd admin level sums for the year

g <- ggplot(data = highestAdmLevelStats, aes(x=nlPeriod, y=radiancesum, color=highestAdmLevelStats[[2]])) + scale_x_date(date_breaks = "1 month", date_labels = "%Y-%m")+ geom_line()+geom_point() + labs(color = names(highestAdmLevelStats)[2]) + xlab("Month") + ylab("Sum of Radiances") + ggtitle(paste0(unique(names(highestAdmLevelStats)[2]), " sum of radiances for ", ctry))

print(g)

quick conversion to interactive map with plotly

ggplotly(g)

chrisvwn commented 3 years ago

Okay. Which version of Rnightlights do you have?

JMejuto commented 3 years ago

Rnightlights version 0.3.0.0

anoopwcc commented 3 years ago

Dear Chris, I run the following code library(Rnightlights) library(lubridate) library(reshape2) ctry <- "IND" #replace to run for any other country highestAdmLevelStats <- getCtryNlData(ctryCode = ctry, admLevel = "highest", nlType = "VIIRS.M", nlPeriods = nlRange("201401", "201405","VIIRS.M"), nlStats = list("sum",na.rm=TRUE), ignoreMissing=FALSE)

and I am getting the following error message. I have the latest version of nightlight and updated versions of all the package. Any help from your side is highly appreciated

processing missing data: IND:VIIRS.M:VCMCFG:avg_rade9:201401:sum, VIIRS.M:VCMCFG:avg_rade9:201402:sum, VIIRS.M:VCMCFG:avg_rade9:201403:sum, VIIRS.M:VCMCFG:avg_rade9:201404:sum, VIIRS.M:VCMCFG:avg_rade9:201405:sum. This may take a while. Note: Set 'ignoreMissing=TRUE' to return only data found or 'ignoreMissing=NULL' to return NULL if not all the data is found 2021-09-03 16:57:09: START PROCESSING: ctryCodes=IND, admLevels=list(IND = "gadm36_IND_1"), nlTypes=VIIRS.M, configNames=VCMCFG, extensions=avg_rade9, multiTileStrategy=all, multiTileMergeFun=mean, removeGasFlaresMethod=VTM, nlPeriods=c("201401", "201402", "201403", "201404", "201405"), nlStats=list(list("sum", na.rm = TRUE)), custPolyPath=NULL, gadmVersion=3.6, gadmPolyType=shpZip, downloadMethod=auto, cropMaskMethod=rast, extractMethod=rast 2021-09-03 16:57:09: Downloading country polygons ... | | 0%2021-09-03 16:57:09: Downloading polygon: IND 2021-09-03 16:57:09: Downloading ctry poly: IND 2021-09-03 16:57:09: Downloading ctry shpZip: IND 2021-09-03 16:57:09: Polygon dir for IND:3.6 already exists |===============================================================================================================| 100% 2021-09-03 16:57:09: Downloading country polygons ... DONE 2021-09-03 16:57:09: PROCESSING nlType:VIIRS.M | configName: VCMCFG | extension: avg_rade9 | nlPeriod:201401 2021-09-03 16:57:09: Checking tiles required for VIIRS.M 201401 2021-09-03 16:57:09: IND: Stats missing. Adding tiles 2021-09-03 16:57:09: numTiles: 1, Required tiles: 75N060E 2021-09-03 16:57:09: Downloading tile (1/1): 2014013 2021-09-03 16:57:11: Download token expired. Refresh token expired. Requesting new [1] "The request failed with status code: 401" [1] "The error is: unauthorized_client" "The error is: Invalid client secret" Cache-Control X-XSS-Protection Pragma "no-store" "1; mode=block" "no-cache" X-Frame-Options Referrer-Policy Date "SAMEORIGIN" "no-referrer" "Fri, 03 Sep 2021 11:27:12 GMT" Connection Strict-Transport-Security X-Content-Type-Options "keep-alive" "max-age=31536000; includeSubDomains" "nosniff" Content-Type Content-Length status "application/json" "75" "401" statusMessage "Unauthorized" [1] "Please ensure the username and password saved can login on the EOG site" trying URL 'https://eogdata.mines.edu/wwwdata/viirs_products/dnb_composites/v10//201401/vcmcfg/SVDNB_npp_20140101-20140131_75N060E_vcmcfg_v10_c201506171538.tgz' Error in utils::download.file(url = ntLtsFileUrl, destfile = ntLtsZipLocalNamePathVIIRS, : cannot open URL 'https://eogdata.mines.edu/wwwdata/viirs_products/dnb_composites/v10//201401/vcmcfg/SVDNB_npp_20140101-20140131_75N060E_vcmcfg_v10_c201506171538.tgz' In addition: Warning message: In utils::download.file(url = ntLtsFileUrl, destfile = ntLtsZipLocalNamePathVIIRS, : cannot open URL 'https://eogdata.mines.edu/wwwdata/viirs_products/dnb_composites/v10//201401/vcmcfg/SVDNB_npp_20140101-20140131_75N060E_vcmcfg_v10_c201506171538.tgz': HTTP status was '401 Unauthorized'

amtantravahi commented 3 years ago

I'm having the same issue as the person above, but I have ensured my login credentials are correct. Any idea what is causing it not to register?

chrisvwn commented 3 years ago

Hi,

So the package has not been maintained for a while and I guess there have been changes upstream. I may not be able to update the package any time soon. Please see if you can find an alternative for your use.

amtantravahi commented 2 years ago

Okay, no worries. Thanks for letting us know! All the best.