-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GeoAI_2021_unit_02_EX_Remote_Sensing_classification_hands_on #3
Comments
Recursive Partitioning and Regression Trees : prediction_cart <- raster::predict(stack, cart, type='class', progress = 'text')
error message : Error in eval(predvars, data, env) : object 'band1' not found
I guess thats because we labeled DF2 in different way than stack, so I changed in the step before
names(DF) = c("id","band1","band2","band3","band4","band5","band6","band7","band8","band9","band10","band11") to : names(DF) = c("id","S2B2A_20210613_108_MOF_BOA_10.1","S2B2A_20210613_108_MOF_BOA_10.2","S2B2A_20210613_108_MOF_BOA_10.3","S2B2A_20210613_108_MOF_BOA_10.4","S2B2A_20210613_108_MOF_BOA_10.5","S2B2A_20210613_108_MOF_BOA_10.6","S2B2A_20210613_108_MOF_BOA_10.7","S2B2A_20210613_108_MOF_BOA_10.8","S2B2A_20210613_108_MOF_BOA_10.9","S2B2A_20210613_108_MOF_BOA_10.10","S2B2A_20210613_108_MOF_BOA_10.11") which are the original label names from the raster layer (stack) and it worked : ) |
@nilsbo123that is exactly the reason. however, my suggestion would be to rename the raster stack. preferably directly at the time of creation. # pasting a filename
fn_noext=xfun::sans_ext(basename(list.files(paste0(envrmt$path_research_area,"/BOA/"),pattern = "S2B2A")))
fn = basename(list.files(paste0(envrmt$path_research_area,"/BOA/"),pattern = "S2B2A"))
# creating a raster stack
stack=raster::stack(paste0(envrmt$path_research_area,"/BOA/",fn))
names(stack) = c("band1","band2","band3","band4","band5","band6","band7","band8","band9","band10","band11")
|
The small code section of "Digitize fast forward traning data" takes a lot of time to run on my system to a point, where I am not able to continue: fields <- mapview::viewRGB(stack, r = 8, g = 4, b = 3) %>% mapedit::editMap() Is there any solution for this? It takes me hours and it seems to go on forever without finishing and I am not sure what could be the problem. |
To save my results I had to adjust the code and change it to "saveRDS(train_areas, file.path(envrmt$path_sentinel,"train_areas.RDS"))". Without this change, the data was saved under a wrong name in the data folder. |
|
I do not exactly understand what you mean with wrong name? The name is case senitive hoever it should not matter for reainging and writing. |
When you print envrmt$path_sentinel the last backslash is missing (don't know why), thats why the two strings aren't connected with a backslash print(paste0(envrmt$path_sentinel,"train_areas.rds")) -->
C:/Users/nils/Documents/edu/geoAI/data/sentineltrain_areas.rds And is safed with the "wrong" name in data folder. appendProjectDirList = c("data/sentinel//",
"data/vector_data//",
"data/sentinel/S2//",
"data/sentinel/SAFE//",
"data/sentinel/research_area//")
print(envrmt$path_sentinel) -> C:/Users/nils/Documents/edu/geoAI/data/sentinel/ |
When I try to apply the classification on the airborne imagery dataset it takes really long to calculate the DF (DF <- raster::extract(stack, tp, df=TRUE)) and the resulting object is quite big. The further calculations for the different classifications then either take long too or I get error messages like the folowing when I try to run the random forest classification code: "model fit failed for Fold01: mtry=2 Error : kann Vektor der Gr��e 5.1 GB nicht allozieren". |
For the training data extraction you can consider an alternative approach: extr = exact_extract(rasterStack, tp, include_cols = c( "class", "id"))
extr = extr[sapply(extr, is.data.frame)]
df = do.call(rbind, extr) Them memory problem is unfortunately pretty difficult to address.
# check memory limit
m=memory.limit()
# set new memory limit e.g.
memory.limit(size=m + a senseful number) see documentation |
you could aggregate the image (with loss of visual information) but for digitizing this would be ok. #
stack_by2 = aggregate(stack,2)
# if still to big
stack_by2 = aggregate(stack,4) |
@gisma @mforoushani I tried to run the script with the aerial image "marburg_dop.tif". Therefore I safed trainings areas consisting of buildings, field, meadows, forest and roads under ther filename "/train_areas_marburg.rds". I then transformed them in the correct crs, extracted them and renamed the to "Marburg_01", "Marburg_02", "Marburg_03" and "Marburg_04", added the "class" category and deleted the geometry. Then I tried to make kmean prediction using 25000 samples, 5 classes, 25 starts and 250 iterations. I showed the foto with mapview and 4 collums, changed them to factors, sown the classification tree and tried to predict my cart. Then I got the message: |
@Muenchj4 I need the source coude to have a chance of reproducing it |
@gisma My script looks like this: add define project specific subfoldersappendProjectDirList = c("data/sentinel/",
"Error in eval(predvars, data, env) : object 'Marburg_01' not found |
@Muenchj4 pls sent the utput of |
@gisma |
still missing the output of |
@gisma |
So finally I need the |
head(DF2) |
I try to run it again with the same names of the RasterLayer as it is "red", "green", "blue" and "nir". Still I am waiting for the output. |
It is only necessary that the pred stacks names and the corresponding training data names are identical. Obviously this is fine. Due to the fact that you are working on highresolution data you have to reduce your training data sample doing somthing like |
ok thank you |
why you are training a regression model? To avoid this you need to define the Respons col as of factor type |
I now have reduced my training data sample and set the respose col as factor as well. But ist is still trying to build a regression model, which semms not to work with random forest.
|
@Muenchj4 as far as I see is your |
Does somebody know, how to load the nlcd data used for the example scripts? Under the written Link I cannot find it. There is other nlcd data I can find, but none of them have got tif files. |
Sorry but actually I dont know what do you mean with nlcd data. |
I want to work through the section about supervised classification and I think it would be helpfull to use the same or at least very similar data as in the examples. |
Trying to write the classification script as rmarkdown file and saving the "meadows" trainings areas following error occurs: |
the error occures writing as usual script and changing into rmarkdown and also writing as Rmarkdown script from the beginning - and only with class "meadows". Does somebody know why? |
@Muenchj4 did you get B02? does it work? |
I am afraid. There are still NAs.
At the moment I am trying to change my hands on script into RMarkdown.
But for the "meadows" class I always get the reply there were no
method for the geometry although it had worked with the further
classes. Do you know why?
LG
J. Münch
Zitat von Mansour Ahmadi Foroushani ***@***.***>:
… @Muenchj4 did you get B02? does it work?
--
Reply to this email directly or view it on GitHub:
#3 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
@mforoushani @gisma
In spite of this I tried to define a cart model with rpart function and got the message:
and of course occurred again trying to show by mapview. |
@Muenchj4 did you run the file from Marburg or that one from FL (USA)? But overall, I think it happened coz large samples. try to make gridded=TRUE, then maxpixels may be ignored to get a larger sample. You can use the following link and rearrange the plot command. https://rdrr.io/cran/raster/man/plot.html |
@mforoushani I used the Marburg File. I will try as you said. |
@Muenchj4 I think we go in circles. To support you more effienctly please do one of the following things. Either zip your whole working enviroment togehter with all necessary data and share it with me or push it to github (preferred). |
@gisma Finally I have finished my prediction scripts, which was not possible before since some packages needed to be updated. Now I tried to plot my prediction, but following error occurred. : ---Plotting predictions---
Error in as.double(y) : P.S. My prediction stack looks like this: |
@Muenchj4 the message says that there is noch plot method for your object. actually if you look into the example code you you will find that you are not plotting the prediction_rf = predict(stack ,cv_model, progress = "text")
mapview(prediction_rf,col.regions = c('darkgreen', 'burlywood', 'green', 'orange')) you usually have to check what is the class the object . For instant if you want to plot the classification map of a RSToolbox result you need to choose the layer like |
@ok thank you. I will check it.
Zitat von Chris Reudenbach ***@***.***>:
… @Muenchj4 the message says that there is noch plot method for your
object. actually if you look into the example code you you will
find that you are not plotting the ***@***.***` but the object
```r
prediction_rf = predict(stack ,cv_model, progress = "text")
mapview(prediction_rf,col.regions = c('darkgreen', 'burlywood',
'green', 'orange'))
```
you usually have to check what is the class the object . For instant
if you want to plot the classification map of a RSToolbox result you
need to choose the layer like ***@***.***`
--
Reply to this email directly or view it on GitHub:
#3 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
At the moment I have some trouble with the number of layers. As you can see here:
Error in |
I got two error messages with the variables prediction_cart & prediction_rf because the raster stack is not named like the data frame. To rename the stack something like names(stack) = c("band1","band2",.....) should work.
The text was updated successfully, but these errors were encountered: