Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://hal.archives-ouvertes.fr/hal-04452256
20 February 2024, 14:40:46 UTC
  • Code
  • Branches (0)
  • Releases (1)
  • Visits
    • Branches
    • Releases
      • HEAD
    • e68ff9d
    • /
    • R
    • /
    • f_fdc_analysis.R
    Raw File Download

    To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
    Select below a type of object currently browsed in order to display its associated SWHID and permalink.

    • content
    • directory
    • snapshot
    • release
    origin badgecontent badge
    swh:1:cnt:5d754b36e4527f35d723355d56723234fb6f1eb0
    origin badgedirectory badge
    swh:1:dir:a9f1cf2137766b74e143323af9a9fbe49232c39f
    origin badgesnapshot badge
    swh:1:snp:8310261df5798cf39e9eff9e2565153bbefa20cd
    origin badgerelease badge
    swh:1:rel:b076d4e89c69861c65112117ecd2efc6969a7d84

    This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
    Select below a type of object currently browsed in order to generate citations for them.

    • content
    • directory
    • snapshot
    • release
    Generate software citation in BibTex format (requires biblatex-software package)
    Generating citation ...
    Generate software citation in BibTex format (requires biblatex-software package)
    Generating citation ...
    Generate software citation in BibTex format (requires biblatex-software package)
    Generating citation ...
    Generate software citation in BibTex format (requires biblatex-software package)
    Generating citation ...
    f_fdc_analysis.R
    ## ---------------------------
    ##
    ## Purpose of script: define functions for part of the app: analysis of classified discharges
    ##
    ## Author: Guillaume Cinkus
    ##
    ## Date Created: 2021-08-10
    ##
    ## Email: guillaume.cinkus@gmail.com
    ##
    ## ---------------------------
    ##
    ## Notes:
    ##   
    ##
    ## ---------------------------
    
    erfinv <- function(x) qnorm((x + 1)/2) / sqrt(2)
    
    log10_bounds <- function(x, method) {
      if (method == "ceiling") return(10 ^ (ceiling(log10(x))))
      if (method == "floor") return(10 ^ (floor(log10(x))))
    }
    
    fdc_mangin <- function(discharge) {
      discharge_ordered <- sort(discharge)
      non.NA <- sum(!is.na(discharge_ordered)) 
      # Compute & plot probability plot
      quant <- (1 : non.NA) / non.NA
      # get index of unique discharge value
      index_unique <- length(discharge_ordered) - match(unique(discharge_ordered), rev(discharge_ordered)) + 1
      # filter the initial discharge vector with only unique values
      discharge_ordered_unique <- discharge_ordered[index_unique]
      quant <- quant[index_unique]
      
      y_class <- sqrt(2) * erfinv(quant)
      discharge_duration_curve_df <- data.frame(discharge = discharge_ordered_unique, 
                                                prob_exceedance = y_class) %>% 
        dplyr::slice(1:(dplyr::n() - 1))
    }
    
    fdc_normal <- function(discharge) {
      discharge_ordered <- sort(discharge)
      non.NA <- sum(!is.na(discharge_ordered)) 
      # Compute & plot probability plot
      quant <- (1 : non.NA) / non.NA
      # get index of unique discharge value
      index_unique <- length(discharge_ordered) - match(unique(discharge_ordered), rev(discharge_ordered)) + 1
      # filter the initial discharge vector with only unique values
      discharge_ordered_unique <- discharge_ordered[index_unique]
      quant <- quant[index_unique]
      
      discharge_duration_curve_df <- data.frame(prob_exceedance = quant, 
                                                discharge = discharge_ordered_unique) %>% 
        dplyr::mutate(prob_exceedance = 1 - prob_exceedance)
    }
    
    plot_fdc <- function(fdc_df, method, xlog = FALSE) {
      
      # Define breaks when using logarithmic scale
      minor_breaks <- rep(1:9, 21) * (10 ^ rep(-10:10, each = 9))
      
      if (method == "mangin") {  
        yticks <- c(0.10, 0.30, 0.50, 0.70, 0.80, 0.90, 0.95, 0.98, 0.99, 0.995, 0.998, 0.9999)
        ylabel <- as.character(yticks)
        yticks <- sqrt(2) * erfinv(yticks)
        
        ggplot(fdc_df, aes(x = discharge, y = prob_exceedance)) + 
          geom_line(size = 0.8) +
          scale_y_continuous(breaks = yticks, labels = ylabel) +
          {
            if (xlog == TRUE) {
              # List two combine two ggplot2 elements
              list(scale_x_log10(minor_breaks = minor_breaks, 
                                 limits = c(
                                   log10_bounds(min(fdc_df$discharge), "floor"), 
                                   log10_bounds(max(fdc_df$discharge), "ceiling"))),
                   annotation_logticks(sides = "b"))
            }
          } +
          theme_bw() +
          ggtitle("Mangin Method") +
          xlab(expression("Discharge" ~(m^3~.s^-1))) +
          ylab("Probability exceedance") +
          theme(title = element_text(size = 16, color = "#2d2d2d"),
                axis.title = element_text(size = 16, color = "#2d2d2d"),
                axis.text = element_text(size = 14, color = "#2d2d2d"))
        
      } else if (method == "normal") {
        ggplot(fdc_df, aes(x = prob_exceedance, y = discharge)) + 
          geom_line(size = 0.8) +
          theme_bw() +
          ggtitle("Classic Method") +
          xlab("Probability exceedance") +
          ylab(expression("Discharge" ~(m^3~.s^-1))) +
          theme(title = element_text(size = 16, color = "#2d2d2d"),
                axis.title = element_text(size = 16, color = "#2d2d2d"),
                axis.text = element_text(size = 14, color = "#2d2d2d"))
      }
    }

    back to top

    Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
    The source code of Software Heritage itself is available on our development forge.
    The source code files archived by Software Heritage are available under their own copyright and licenses.
    Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API