Closed HaasL closed 4 years ago
Hi @HaasL
Seems something to do with the date formating. Could you post a sample of the the dates i.e.
head(highestAdmLevelStats$nlPeriod)
I have the same errors:
> highestAdmLevelStats$nlPeriod <- ymd(paste0(substr(highestAdmLevelStats$nlPeriod, 1,4), > + "-",substr(highestAdmLevelStats$nlPeriod, 5,6), "-01")) Warning message: All formats failed to parse. No formats found.
And this:
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) Error in seq.int(r1$mon, 12 * (to0$year - r1$year) + to0$mon, by) : 'from' must be a finite number In addition: Warning messages: 1: Use of `highestAdmLevelStats[[2]]` is discouraged. Use `.data[[2]]` instead. 2: Use of `highestAdmLevelStats[[2]]` is discouraged. Use `.data[[2]]` instead
Also, I got this when I followed up with your suggestion:
head(highestAdmLevelStats$nlPeriod) [1] NA
How can I fix this? Could you please help me?
Hi @firatgundem
Which version of Rnightlights are you using? Also, could you post the whole set of code that you are running?
Since the Rnightlights package is not available anymore in CRAN, I used the code below: packageurl <- "https://cran.r-project.org/src/contrib/Archive/Rnightlights/Rnightlights_0.2.4.tar.gz"
install.packages(packageurl, repos=NULL, type="source") library(Rnightlights) library(dplyr) library(lubridate) library(reshape2)
pkgOptions(downloadMethod = "aria", cropMaskMethod = "gdal", extractMethod = "gdal", deleteTiles = TRUE)
ctry <- "KEN"
highestAdmLevelStats <- getCtryNlData(ctryCode = ctry, admLevel = "highest", nlType = "VIIRS.M", nlPeriods = nlRange("201401", "201412","VIIRS.M"), nlStats = list("sum",na.rm=TRUE), ignoreMissing=FALSE)
library(ggplot2) install.packages("plotly") library(plotly)
highestAdmLevelStats <- melt(highestAdmLevelStats, id.vars = grep("NL_", names("highestAdmLevelStats"), invert=TRUE), variable.name = "nlPeriod", value.name = "radiancesum")
highestAdmLevelStats$nlPeriod <- substr(highestAdmLevelStats$nlPeriod, 12, 17)
highestAdmLevelStats$nlPeriod <- ymd(paste0(substr(highestAdmLevelStats$nlPeriod, 1,4), "-",substr(highestAdmLevelStats$nlPeriod, 5,6), "-01")) Here I got this error: Warning message: All formats failed to parse. No formats found.
I kept running the rest of the code..
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))
Then I got this error:
Error in seq.int(r1$mon, 12 * (to0$year - r1$year) + to0$mon, by) :
'from' must be a finite number
In addition: Warning messages:
1: Use of highestAdmLevelStats[[2]]
is discouraged. Use .data[[2]]
instead.
2: Use of highestAdmLevelStats[[2]]
is discouraged. Use .data[[2]]
instead.
I followed the step that you suggested to @HaasL and then I got this as well: [1] NA
Am I doing something wrong? I am learning R very new I would appreciate if you can help me. Thanks.
Also, now I am getting this error as I was trying to fix the problem I posted above:
highestAdmLevelStats <- getCtryNlData(ctryCode = ctry, admLevel = "highest", nlType = "VIIRS.M", nlPeriods = nlRange("201401", "201412","VIIRS.M"), nlStats = list("sum",na.rm=TRUE), ignoreMissing=FALSE)
File'C:\Users\firat\AppData\Local\Temp\RtmpWS1kS1/.Rnightlights/data/NL_DATA_KEN_ADM1_GADM-3.6-SHPZIP.csv' does not exist or is non-readable. getwd()=='C:/Users/firat/Desktop/r_demo/lights'
In addition: Warning message:
In proj4string<-
(*tmp*
, value = crs) :
A new CRS was assigned to an object with an existing CRS:
+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
without reprojecting.
For reprojection, use function spTransform
I am trying to fix these for a long time but could not proceed. Could you please help me?
I am trying to fix the errors that I got but I am seeing a different error in each attempt. Do you have any idea what's going on here? Could you please help me?
Error in proj4string<-
(*tmp*
, value = crs) :
Geographical CRS given to non-conformant data: -1640.8982 2197.5138
In addition: Warning messages:
1: In proj4string<-
(*tmp*
, value = crs) :
A new CRS was assigned to an object with an existing CRS:
+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
without reprojecting.
For reprojection, use function spTransform
2: In proj4string<-
(*tmp*
, value = crs) :
A new CRS was assigned to an object with an existing CRS:
+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
without reprojecting.
For reprojection, use function spTransform
Since the Rnightlights package is not available anymore in CRAN, I used the code below: packageurl <- "https://cran.r-project.org/src/contrib/Archive/Rnightlights/Rnightlights_0.2.4.tar.gz"
install.packages(packageurl, repos=NULL, type="source") library(Rnightlights) library(dplyr) library(lubridate) library(reshape2)
pkgOptions(downloadMethod = "aria", cropMaskMethod = "gdal", extractMethod = "gdal", deleteTiles = TRUE)
ctry <- "KEN"
highestAdmLevelStats <- getCtryNlData(ctryCode = ctry, admLevel = "highest", nlType = "VIIRS.M", nlPeriods = nlRange("201401", "201412","VIIRS.M"), nlStats = list("sum",na.rm=TRUE), ignoreMissing=FALSE)
library(ggplot2) install.packages("plotly") library(plotly)
highestAdmLevelStats <- melt(highestAdmLevelStats, id.vars = grep("NL_", names("highestAdmLevelStats"), invert=TRUE), variable.name = "nlPeriod", value.name = "radiancesum")
highestAdmLevelStats$nlPeriod <- substr(highestAdmLevelStats$nlPeriod, 12, 17)
highestAdmLevelStats$nlPeriod <- ymd(paste0(substr(highestAdmLevelStats$nlPeriod, 1,4), "-",substr(highestAdmLevelStats$nlPeriod, 5,6), "-01")) Here I got this error: Warning message: All formats failed to parse. No formats found.
I kept running the rest of the code..
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))
Then I got this error: Error in seq.int(r1$mon, 12 * (to0$year - r1$year) + to0$mon, by) : 'from' must be a finite number In addition: Warning messages: 1: Use of
highestAdmLevelStats[[2]]
is discouraged. Use.data[[2]]
instead. 2: Use ofhighestAdmLevelStats[[2]]
is discouraged. Use.data[[2]]
instead.I followed the step that you suggested to @HaasL and then I got this as well: [1] NA
Am I doing something wrong? I am learning R very new I would appreciate if you can help me. Thanks.
If the formats failed to parse then the rest of the code will not work. This example is not the best code as there are hardcoded parts especially the substring which I believe is the cause of this problem.
I am trying to fix the errors that I got but I am seeing a different error in each attempt. Do you have any idea what's going on here? Could you please help me?
Error in
proj4string<-
(*tmp*
, value = crs) : Geographical CRS given to non-conformant data: -1640.8982 2197.5138 In addition: Warning messages: 1: Inproj4string<-
(*tmp*
, value = crs) : A new CRS was assigned to an object with an existing CRS: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 without reprojecting. For reprojection, use function spTransform 2: Inproj4string<-
(*tmp*
, value = crs) : A new CRS was assigned to an object with an existing CRS: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 without reprojecting. For reprojection, use function spTransform
I am not sure how you are trying to fix the errors, could you clarify? However, the main thing as pointed out above is to pull out the date here:
highestAdmLevelStats$nlPeriod <- substr(highestAdmLevelStats$nlPeriod, 12, 17)
highestAdmLevelStats$nlPeriod <- ymd(paste0(substr(highestAdmLevelStats$nlPeriod, 1,4),
"-",substr(highestAdmLevelStats$nlPeriod, 5,6), "-01"))
This is where you need to look. Could you print out highestAdmLevelStats$nlPeriod
before and after the substring? Then rewrite the substr
command to pick the date correctly.
I am trying to fix the errors that I got but I am seeing a different error in each attempt. Do you have any idea what's going on here? Could you please help me? Error in
proj4string<-
(*tmp*
, value = crs) : Geographical CRS given to non-conformant data: -1640.8982 2197.5138 In addition: Warning messages: 1: Inproj4string<-
(*tmp*
, value = crs) : A new CRS was assigned to an object with an existing CRS: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 without reprojecting. For reprojection, use function spTransform 2: Inproj4string<-
(*tmp*
, value = crs) : A new CRS was assigned to an object with an existing CRS: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 without reprojecting. For reprojection, use function spTransformI am not sure how you are trying to fix the errors, could you clarify? However, the main thing as pointed out above is to pull out the date from the column names
I just deleted and re-uploaded things. As I sad you before, I am very new in R and I could not run the codes even for once. What should I do? Thanks!
If you want to start afresh:
Uninstall the package
getCtryNlDataPath()
remove.packages("Rnightlights")
Delete the .Rnightlights folder where you created it at install time (The first command above should give you the path)
Reinstall the package as before
Closing this issue for now. If you would like to pursue this further please reopen.
Hey Chris, I downloaded the data but fail to complete the lasts steps. The download seems to be successful, but when trying to plot it says "all formats failed to parse." Can you tell me what went wrong ?