


source("modules/Loading/Loading.R")
library(metaclipR)
library(loadeR)
library(transformeR)
library(metaclipR)
library(igraph)

recipe_file <- "recipes/atomic_recipes/recipe_seasonal_provenance.yml"
recipe <- prepare_outputs(recipe_file)

data <- Loading(recipe)

xyCoords<-list("x","y")

xyCoords$x<-data$hcst$coords$latitude [1:22]
xyCoords$y<-data$hcst$coords$longitude [1:53]

graph0 <-make_empty_graph(directed = TRUE)

graph1<-metaclipR.SpatialExtent(xyCoords=xyCoords)

graph0 <- metaclipR.Dataset(
  Dataset.name = "SUNSET Sample Seasonal Dataset",
  #DataProvider = "ECMWF",
  # DataProvider.URL = url,
  Dataset.subclass = "SeasonalOperationalForecast",  # Right?
  #Project = "SEAS5", # ?
  #ModellingCenter = "ECMWF"
)

graph3 <- metaclipR.Dataset(
  Dataset.name = "Training data",
  DataProvider = "ECMWF",
  # DataProvider.URL = url,
  Dataset.subclass = "SeasonalHindcast",  # Right?
  Project = "SEAS5", # ?
  ModellingCenter = "ECMWF"
)

graph2 <- metaclipR.Dataset(
  Dataset.name = "Observations",
  DataProvider = "SEAS5",
  # DataProvider.URL = url,
  Dataset.subclass = "ObservationalDataset",  # Right?
  Project = "SEAS5", # ?
  ModellingCenter = "SEAS5"
)

graph<- metaclipR.BiasCorrection(package = "Calibration", version = "1.0",
  fun = "/modules/Calibration/Calibration.R", arg.list=list(), graph=graph0, TrainingGraph=graph3, ReferenceGraph=graph2,
  ReferenceGraphSpatialExtent = graph1, BC.method= "QDM",
  BC.class = "BiasCorrection")

#graph<- metaclipR.DatasetSubset(package = "transformeR",
  #version = as.character(packageVersion(package)), graph = NULL,
  #fun = "metaclipR.SpatialExtent", arg.list = list("xyCoords"), output = NULL,
  #RefSpatialExtent = graph1, xmin = NULL, xmax = NULL, ymin = NULL,
  #ymax = NULL, proj = NULL, resX = NULL, resY = NULL,
  #disable.command = FALSE)

plot(graph$graph)
graph2json(graph$graph, "/esarchive/scratch/apuiggro/graph222.json")



