Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • HabitatSampler HabitatSampler
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 5
    • Issues 5
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Habitat Sampler
  • HabitatSamplerHabitatSampler
  • Issues
  • #51
Closed
Open
Created Jan 06, 2022 by Johannes Knoch@jknochMaintainer

plot_results breaks with error

plot_results(inPath=outPath)

often does not work and gives the error

Error in as.data.frame.default(x) : 
  cannot coerce class 'structure("RasterStack", package = "raster")' to a data.frame

I tried it in many different ways (jupyter-lab, console, Rstudio; with installed HaSa or from a freshly pulled HaSa-directory and even on the Rstudio Server with HaSa1.3.1 installed) but it was almost always the same error. I think the problem comes from line 100 in plot_results.r:

modelHS <- merge(class[[1:(numberHabitats + 1)]])

The strange thing is now, when I run the code of plot_results.r manually (without the function) through console, it works.


But there is also another error in the final_habitat_map.tif, which I think is related to the error mentioned above.

Namely the not classified pixels which should be an extra class (e.g. you have 9 classes they should appear as 10 in the final_habitat_map.tif) are tagged as inf which leads to "holes" in the map.

When the error appears the variable "dummy" (line 86.., in plot_result.R) has already inf as value for the "not assigned" pixels in the raster.

for (i in 1:(length(files) + 1)) {
        if (i == (length(files) + 1)) {
            dummy <- raster::raster(files[(i - 1)])
            dummy[dummy < thres[(i - 1)]] <- i
            dummy[dummy >= thres[(i - 1)]] <- NA
            class[[i]] <- dummy
        } else {
            dummy <- raster::raster(files[i])
            dummy[dummy < thres[i]] <- NA
            dummy[dummy >= thres[i]] <- i
            class[[i]] <- dummy
        }
    }

Right now I can't see a pattern, when the errors appear. Sometimes they are both there sometimes only one of them.

Edited Jan 13, 2022 by Johannes Knoch
Assignee
Assign to
Time tracking