Prov.Calibration<-function(recipe,data,graph,type){
  #Define Calibration parameters
  cal<-recipe$Analysis$Workflow$Calibration$method
  cal.method<-switch(cal,
                    "qmap"="Quantile Mapping",
                    "bias"="Bias Correction (Only)",
                    "evmos"="Error Variance Minimization Objective Score",
                    "mse_min"="Mean Squared Error (Minimizing)",
                    "crps_min"="Continuous Ranked Probability Score (Minimizing)",
                    "rpc-based"="Rank Probability Score based"
                    )
  cal.description<-switch(cal,  
                    "qmap"="Quantile mapping calibration is a statistical technique used in climatology to adjust model output or observational data to match the probability distribution of a reference dataset. 
                            By aligning quantiles, it corrects biases and improves the accuracy of climate model simulations or observational datasets, 
                            enhancing their reliability for various applications such as climate change studies or impact assessments.",             
                    "bias"="This method not only corrects the bias but also applies a variance inflation technique to ensure that the corrected system maintains correspondence with the variance of the observation. 
                            It aims to adjust both bias and variance.",
                    "evmos"="Error Variance Minimization Objective Score",
                    "mse_min"="his ensemble calibration method aims to correct bias, overall system variance, and ensemble spread. It minimizes a constrained mean-squared error using three parameters. 
                               The goal is to adjust the system to match the observed variance and spread.",
                    "crps_min"="This ensemble calibration method corrects bias, overall system variance, and ensemble spread. 
                               It does so by minimizing the Continuous Ranked Probability Score (CRPS) using four parameters. 
                               CRPS is a scoring rule that evaluates the probabilistic systems.",
                    "rpc-based"="This method adjusts the system variance to ensure that the ratio of predictable components (RPC) is equal to one. 
                                 It aims to balance the system variance in relation to the predictability of the system."
                    )
  cal.class<-"cal:BiasCorrection"
  if(!(cal=="qmap")){
    comment="For more details, see the  CSTools documentation for CST_Calibration()"
  }else{
    comment="For more details, see the  CSTools documentation for CST_QuantileMapping()"
  }
  referenceURL="https://cran.r-project.org/web/packages/CSTools/CSTools.pdf"
  reference.nodename<-graph$parentnodename$parentnodename_obs
  #Define last node to which Calibration is applied
  if(type=="fcst" | type=="hcst"){
    i<-switch(type,
            "fcst"="parentnodename_fcst",
            "hcst"="parentnodename_hcst")
    parentnodename<-graph$parentnodename[[i]]
    graph<-graph$graph

    #Add Calibration node and vertex
    cal.nodename<-paste0("Calibration_",type)
    graph <- my_add_vertices(graph,
                             name = cal.nodename,
                             label = "Calibration",
                             className = "cal:Calibration")
    graph <- add_edges(graph, 
                       c(getNodeIndexbyName(graph, parentnodename),
                         getNodeIndexbyName(graph, cal.nodename)),
                       label = "cal:hadCalibration")
    
    #Update SpatialExtent
    refgraph<-getSpatialExtent(data, type, Cal=TRUE)
    graph <- my_union_graph(graph, refgraph$graph)
    graph <- add_edges(graph,
                       c(getNodeIndexbyName(graph, cal.nodename),
                         getNodeIndexbyName(graph, refgraph$parentnodename)),
                       label = "ds:hasHorizontalExtent")    

    #Adding Calibration Method
    calmethod.nodename<-paste0("CalibrationMethod_","all")
    graph <- my_add_vertices(graph,
                             name = calmethod.nodename,
                             label = cal.method,
                             className = cal.class,
                             attr=list("dc:description"=cal.description,
                             "dc:comment"=comment,
                             "ds:referenceURL"=referenceURL)
                             )
    graph <- add_edges(graph, 
                       c(getNodeIndexbyName(graph, cal.nodename),
                         getNodeIndexbyName(graph, calmethod.nodename)),
                       label = "cal:withCalibrationMethod")
    
    #Reference node
    graph <- add_edges(graph, 
                       c(getNodeIndexbyName(graph, cal.nodename),
                         getNodeIndexbyName(graph, reference.nodename)),
                       label = "cal:withReferenceData")

  print(paste0("Calibration provenance computed for ", type))
  
    return(list("graph"=graph, "parentnodename"=cal.nodename))
  }else{
    return(list("graph"=graph$graph, "parentnodename"=graph$parentnodename$parentnodename_obs))
  }
  
}