sunset_prov_indices<-function(recipe,data,graph_calibrated,graph){
#Graph definitions
graph_main<-graph$main_graph
parentnodenames<-graph$main_graph$parentnodename
graph_fcst<-graph_calibrated$graph_fcst
graph_hcst<-graph_calibrated$graph_hcst
graph_obs<-graph_calibrated$graph_obs

#Hindcast aggregation
hcst_agg<- metaclipR.Aggregation(package = "Indices",
  version = "2.0", graph_hcst,
  fun = "/modules/Indices/Indices.R", arg.list = NULL, use.arg.list = FALSE,
  disable.command = TRUE, dc.description = NULL)

#Observation aggregation
obs_agg<- metaclipR.Aggregation(package = "Indices",
  version = "2.0", graph_obs,
  fun = "/modules/Indices/Indices.R", arg.list = NULL, use.arg.list = FALSE,
  disable.command = TRUE, dc.description = NULL)
  #Should addd a description explaining how the aggregation takes place in SUNSET particularly!!!!

index_name<-names(recipe$Analysis$Workflow$Indices)

#Hindcast Index Calculation
indi_hcst<- metaclipR.ClimateIndex(hcst_agg, package = "indices",
  version = "2.0" , index.code= index_name,
  fun = "modules/Indices/Indices.R", disable.command = TRUE)

#Observation index calculation
indi_obs<-metaclipR.ClimateIndex(obs_agg, package = "indices",
  version = "2.0" , index.code= index_name,
  fun = "modules/Indices/Indices.R", disable.command = TRUE)

#Union of the graphs and parentnodenames
graph<-my_union_graph(graph_main$graph, indi_hcst$graph, indi_obs$graph)

parentnodename<-list(indi_hcst$parentnodename, indi_obs$parentnodename, hcst_agg$parentnodename, obs_agg$parentnodename)

#Common command call generation
graph <- metaclip.graph.Command(graph, "Indices", "2.0.0", "/modules/Indices/Indices.R", arg.list=list("Recipe"=recipe$Run$output_dir, "Calibrated_Data"),parentnodename)

#Outputs
if(!is.null(graph_fcst)){
graph<-list("graph"=graph, "parentnodename"=list(graph_fcst$parentnodename, graph_hcst$parentnodename, graph_obs$parentnodename,parentnodename))
return(list("main_graph"=graph, "graph_fcst"=graph_fcst, "graph_hcst"=graph_hcst, "graph_obs"=graph_obs))
}else{
graph<-list("graph"=graph, "parentnodename"=list( graph_hcst$parentnodename, graph_obs$parentnodename,parentnodename))
return(list("main_graph"=graph, "graph_hcst"=graph_hcst, "graph_obs"=graph_obs))  
}
}

