Open kellyecoles opened 1 year ago
Hi @kellyecoles - are you sure the coordinates are in decimal degrees? That's a common problem that crops up. Also, if all the points are within 0.2 km of each other, then you might also get this error.
HI @kellyecoles and @mlammens - I have had exactly this problem tonight. I successfully used that code yesterday and tonight I am getting the above error. I have two data sets for two different projects. Yesterdays data set would not work tonight even though it worked yesterday. My coordinates are in decimal degrees. I ended up getting into QGIS and thinning by hand. Tedious but the job is done.
I would still love to solve this problem.
That's pretty strange @RuthPalsson . I don't suppose you could share the points, or a subset of them, so I can trouble shoot the problem?
Thanks for your reply @mlammens My data. This set worked a few days ago and now will not. I get this error message: Beginning Spatial Thinning. Script Started at: Wed Mar 08 08:15:48 2023Error in .subset2(x, i, exact = exact) : attempt to select less than one element in get1index
My code: thin( loc.data = input, lat.col = "latitude", long.col = "longitude", spec.col = "species", thin.par = 1, reps = 10, locs.thinned.list.return = TRUE, write.files = TRUE, max.files = 10, out.dir = "outputs/", out.base = "Cineatrip", write.log.file = TRUE, log.file = "Cineatrip.txt" )
@mlammens, this is working perfectly this morning!! Who knows what was going on!!
Odd. Usually I've seen that error when the points are too close to each other (relative to the thin distance), but that does not appear to be the case here. It is a random algorithm, so I suppose it's not totally impossible for it to work sometimes but not others. I'll have to tweak this going forward.
@mlammens, the data I sent you had worked initially but then didn't. I had two other sets of data that I knew had locs closer than 0.2 km - I had thinned them manually in QGIS and then yesterday, I got spThin to thin both of them to <1 km apart. Is it in the dodumentation that points need to be >0.2 km apart? I did not notice it. Thanks for your help.
Hii, I am trying to work with a certain species for spatial thinning and am stuck with the same error. My CSV file has a species column, lat and long columns with values in decimal.
head(hyp) Species Latitude Longitude X X.1 1 M. (L.) Kuntze -6.563056 147.0306 NA NA 2 M. (L.) Kuntze -7.058333 146.6750 NA NA 3 M. (L.) Kuntze -9.391667 147.3083 NA NA 4 M. (L.) Kuntze -6.758333 147.0083 NA NA 5 M. (L.) Kuntze -5.250000 145.7500 NA NA 6 M. (L.) Kuntze -5.750000 145.1667 NA NA
thin(
- loc.data <- subset_hyp,
- lat.col = "LATITUDE",
- long.col = "LONGITUDE",
- spec.col = "SPECIES",
- thin.par = 1,
- rep = 100,
- locs.thinned.list.return = FALSE,
- write.files = TRUE,
- max.files = 1,
- out.dir = ("~/dissertation/Lifeform article'24"),
- out.base = "thinned data",
- write.log.file = TRUE,
- log.file = "spatial_thin_hyp.csv",
- verbose = TRUE
- )
Beginning Spatial Thinning. Script Started at: Wed Jan 31 16:42:09 2024Error in .subset2(x, i, exact = exact) : attempt to select less than one element in get1index
Would be of great help if anyone could help me out on this. Thanks in advance!
@riyapakhre , I think this error might be from the labels your using for the Latitude / Longitude columns in the data set being different from the names you are using in the thin
function -- i.e., "LATITUDE" and "LONGITUDE". Case matters in R.
I am working with a dataset of occurrence locations for an endangered species, so I am not able to share data.
I have an excel file with three columns: species, longitude and latitude.
I am working with that in R, and trying to thin the >400 points, because many of them are repeats (individuals within just one population). I have used spThin successfully in the past but am unable to get it to work now. My code is:
Reading in Occurrences
occs <- read.xlsx("Bapmeg/BAPMEG_FL.xlsx", sheetIndex = 1)
Thinning Occurrence Points
thin(loc.data = occs, lat.col = "latitude", long.col = "longitude", spec.col = "name", thin.par = 0.2, reps = 100, locs.thinned.list.return = TRUE, write.files = TRUE, max.files = 1, out.dir = "Bapmeg/", out.base = "Bapmeg_Thin", write.log.file = TRUE, log.file = "BapMegThin.txt")
However, I keep getting the same error: Error in .subset2(x, i, exact = exact) : attempt to select less than one element in get1index
I can't figure out why. I saw another thread where someone added a species column, and the code worked, but I already have a species column. Is there a minimum number of occurrences necessary? This is an extremely rare species, with probably less than 12 occurrences in the area in question.
Thanks! And if I have failed to include information, I apologize. I am very new to all this.