chrisvwn / Rnightlights

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

Having Error when running codes #18

Closed marinewave closed 5 years ago

marinewave commented 5 years ago

Hi Chris, As I am beginner in R, so sorry for asking "silly" questions. I want to get data on nightlight for 201201 to 201712 for Indian districts. But while I am running the program as is directed in the program, I am facing some problem while running the codes. I am attaching the response from R- Error in melt(highestAdmLevelStats, id.vars = grep("NL_", names(highestAdmLevelStats), : object 'highestAdmLevelStats' not found.

Can you help me regarding how to resolve the issue?

chrisvwn commented 5 years ago

Hi @marinewave No silly questions. Could you post the whole output from the previous commands as well. This error seems to say that the highestAdmLevelStats variable does not exist. If all went well you should have it. If not, as I suspect is the case, the output from the previous commands should tell us what happened.

marinewave commented 5 years ago

Hi Chris, Thank you for your kind help. I am have pasted the code below:

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

Attaching package: ‘lubridate’

The following object is masked from ‘package:base’:

date

pkgOptions(extractMethod = "rast", numCores=4) ctry <- "IND" highestAdmLevelStats <- getCtryNlData(ctryCode = ctry,

  • admLevel = "highest",
  • nlType = "VIIRS.M",
  • nlPeriods = nlRange("201401", "201412"),
  • nlStats = list("sum",na.rm=TRUE),
  • ignoreMissing=FALSE) 2018-12-18 12:56:57: NlRange autodetected nlType: VIIRS.M Processing missing data: IND:VIIRS.M:201403:sum, VIIRS.M:201404:sum, VIIRS.M:201405:sum, VIIRS.M:201406:sum, VIIRS.M:201407:sum, VIIRS.M:201408:sum, VIIRS.M:201409:sum, VIIRS.M:201410:sum, VIIRS.M:201411:sum, VIIRS.M:201412: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 2018-12-18 12:56:59: Downloading country polygons ... 2018-12-18 12:56:59: Downloading polygon: IND 2018-12-18 12:56:59: Downloading ctry poly: IND 2018-12-18 12:56:59: Polygon dir for IND:3.6 already exists 2018-12-18 12:56:59: Downloading country polygons ... DONE 2018-12-18 12:56:59: PROCESSING nlType:VIIRS.M nlPeriod:201401 2018-12-18 12:56:59: Checking tiles required for VIIRS.M 201401 2018-12-18 12:57:00: IND: Stats missing. Adding tiles 2018-12-18 12:57:011 Required tiles: 75N060E 2018-12-18 12:57:01: Cropped raster C:\Users\DBA_GIS\Documents/.Rnightlights/outputrasters/NL_IND_VIIRS.M_201401_GADM-3.6.tif already exists. Skipping tile download 2018-12-18 12:57:01: processNLCountry: IND gadm36_IND_1 VIIRS.M 201401 2018-12-18 12:57:01: Check for existing data file 2018-12-18 12:57:01: Data file found: C:\Users\DBA_GIS\Documents/.Rnightlights/data/NL_DATA_IND_ADM1_GADM-3.6.csv 2018-12-18 12:57:02: All stats exist for IND gadm36_IND_1 201401. Skipping 2018-12-18 12:57:02: COMPLETED PROCESSING nlType:VIIRS.M nlPeriod:201401 2018-12-18 12:57:02: PROCESSING nlType:VIIRS.M nlPeriod:201402 2018-12-18 12:57:02: Checking tiles required for VIIRS.M 201402 2018-12-18 12:57:02: IND: Stats missing. Adding tiles 2018-12-18 12:57:021 Required tiles: 75N060E 2018-12-18 12:57:03: Cropped raster C:\Users\DBA_GIS\Documents/.Rnightlights/outputrasters/NL_IND_VIIRS.M_201402_GADM-3.6.tif already exists. Skipping tile download 2018-12-18 12:57:03: processNLCountry: IND gadm36_IND_1 VIIRS.M 201402 2018-12-18 12:57:03: Check for existing data file 2018-12-18 12:57:03: Data file found: C:\Users\DBA_GIS\Documents/.Rnightlights/data/NL_DATA_IND_ADM1_GADM-3.6.csv 2018-12-18 12:57:03: All stats exist for IND gadm36_IND_1 201402. Skipping 2018-12-18 12:57:03: COMPLETED PROCESSING nlType:VIIRS.M nlPeriod:201402 library(ggplot2) library(plotly)

Attaching package: ‘plotly’

The following object is masked from ‘package:ggplot2’:

last_plot

The following object is masked from ‘package:stats’:

filter

The following object is masked from ‘package:graphics’:

layout

highestAdmLevelStats <- melt(highestAdmLevelStats,

  • id.vars = grep("NL_", names(highestAdmLevelStats),
  • invert=TRUE),
  • variable.name = "nlPeriod",
  • value.name = "radiancesum") Error in melt(highestAdmLevelStats, id.vars = grep("NL_", names(highestAdmLevelStats), : object 'highestAdmLevelStats' not found

Thank you once again.

Regards, Raja

chrisvwn commented 5 years ago

This is strange. Everything looks like it was successful. I am suspecting that this might be a copy-paste problem as the paste of the code also looks strange. Could you try copying this into notepad first to remove any special characters or type out the whole example manually?

chrisvwn commented 5 years ago

Closing issue. Please reopen if you need to pursue this further.