GithubHelp home page GithubHelp logo

mkkallio / hydrostreamer Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 5.0 3.19 MB

R package for downscaling off-the-shelf runoff products to explicit river network.

Home Page: https://mkkallio.github.io/hydrostreamer/

License: MIT License

R 93.51% C++ 6.49%

hydrostreamer's People

Contributors

mkkallio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hydrostreamer's Issues

raster_to_HS with brick throws error

Error in raster_to_HS(runoff, date = getZ(runoff), ...
  length(date) != length(rasters)

This occurs because length(date) is equal to number of layers, but length(rasters)=1

test3 <- any(class(rasters) %in%
c("RasterStack", "RasterBrick", "RasterLayer"))
if(test3) {
rasters <- list(rasters)

test <- !is.list(date) && length(date) != 1
if(test) date <- as.list(date)
test <- length(date) == length(rasters)
if(!test) stop("length(date) != length(rasters)")

A workaround specific to this input case is to replace L73 with:

test <- length(date) == nlayers(rasters[[1]])

It might be worth adding testthat cases covering common data ingestion to ensure there are no regressions.

Error creating river networks for routing

I am running into a tibble error when I run river_network function. The error "! The validate argument of as_tibble() was deprecated in tibble 2.0.0 and is now
defunct.
โ„น Please use the .name_repair argument instead."

How can I resolve this?

Voronoi creation doesn't work with degree coordinates

Traceback of Voronoi weighting with coordinates in degrees:

Error in CPL_geos_voronoi(x, st_sfc(envelope), dTolerance = dTolerance,  : 
  Evaluation error: TopologyException: Input geom 1 is invalid: Self-intersection at or near point 105.5125000008 15.5708336588 at 105.5125000008 15.5708336588. 
18.
stop(structure(list(message = "Evaluation error: TopologyException: Input geom 1 is invalid: Self-intersection at or near point 105.5125000008 15.5708336588 at 105.5125000008 15.5708336588.", 
    call = CPL_geos_voronoi(x, st_sfc(envelope), dTolerance = dTolerance, 
        bOnlyEdges = bOnlyEdges), cppstack = NULL), class = c("Rcpp::eval_error", 
"C++Error", "error", "condition"))) 
17.
CPL_geos_voronoi(x, st_sfc(envelope), dTolerance = dTolerance, 
    bOnlyEdges = bOnlyEdges) 
16.
st_sfc(CPL_geos_voronoi(x, st_sfc(envelope), dTolerance = dTolerance, 
    bOnlyEdges = bOnlyEdges)) 
15.
st_voronoi.sfc(sf::st_union(vorPoints), bbox, dTolerance = 0.1) 
14.
sf::st_voronoi(sf::st_union(vorPoints), bbox, dTolerance = 0.1) 
13.
eval(lhs, parent, parent) 
12.
eval(lhs, parent, parent) 
11.
sf::st_voronoi(sf::st_union(vorPoints), bbox, dTolerance = 0.1) %>% 
    sf::st_cast() %>% sf::st_cast("POLYGON") %>% sf::st_sf() %>% 
    sf::st_join(vorPoints) %>% lwgeom::st_make_valid() %>% dplyr::group_by_(riverID) %>% 
    dplyr::summarise() %>% sf::st_intersection(sf::st_geometry(aoi)) 
10.
withCallingHandlers(expr, warning = function(w) invokeRestart("muffleWarning")) 
9.
suppressWarnings(sf::st_voronoi(sf::st_union(vorPoints), bbox, 
    dTolerance = 0.1) %>% sf::st_cast() %>% sf::st_cast("POLYGON") %>% 
    sf::st_sf() %>% sf::st_join(vorPoints) %>% lwgeom::st_make_valid() %>% 
    dplyr::group_by_(riverID) %>% dplyr::summarise() %>% sf::st_intersection(sf::st_geometry(aoi))) 
8.
withCallingHandlers(expr, message = function(c) invokeRestart("muffleMessage")) 
7.
suppressMessages(suppressWarnings(sf::st_voronoi(sf::st_union(vorPoints), 
    bbox, dTolerance = 0.1) %>% sf::st_cast() %>% sf::st_cast("POLYGON") %>% 
    sf::st_sf() %>% sf::st_join(vorPoints) %>% lwgeom::st_make_valid() %>% 
    dplyr::group_by_(riverID) %>% dplyr::summarise() %>% sf::st_intersection(sf::st_geometry(aoi)))) at C:\Users\Vili\AppData\Local\Temp\RtmpiAXEnH\file1e587c4c7dfc#20
6.
river_voronoi(river, aoi, verbose = verbose) 
5.
compute_weights(rivers, grid, "area", aoi = st_sf(bbox), riverID = "SegmentID", 
    verbose = show_hs_output) at ucscript.R#102
4.
eval(ei, envir) 
3.
eval(ei, envir) 
2.
withVisible(eval(ei, envir)) 
1.
source("C:/Users/Vili/hydrostreamer/uncertainty/ucscript.R") 

Vector date throws error when using brick

Suppose raster_to_HS is called with a vector date and no timestep, which should be possible:

raster_to_HS(runoff, date = getZ(runoff),...)

Error is thrown:

Error in if (timestep == "month") { : argument is of length zero

Cause
As per #5, a brick is ingested as rasters=list(runoff), so within the rasters loop, rast=1

for(rast in seq_along(rasters)) {

dates is therefore always length 1, the vector date is not used, and timestep is queried when it shouldn't be needed:

dates <- date[[rast]]
if(length(dates) == 1) {
if(timestep == "month") {

Case specific workaround

Rewrite L159 to use dates directly - unlisted with purr::reduce because it's not clear why a list is needed here and unlist clobbers dates

dates <- reduce(date,c)

Also fix L174 to throw error on !test

test <- length(dates) == raster::nlayers(raster)
if(test) stop(paste0("length(dates) != nlayers(raster) for raster",
" number ",rast))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.