# IMPORTANT: This is recipe is not intended to represent a real workflow: it is only a template showcasing ALL available options.
Description:
  Author: N. Pérez-Zanón
  Info: This recipe can be use to test Crossval_anomlaies.R and Crossval_skill.R for single and multimodel.
Analysis:
  Horizon: seasonal # Mandatory, str: 'seasonal', or 'decadal'. Subseasonal is in development
  Variables:
    # name: variable name(s) in the /esarchive (Mandatory, str)
    # freq: 'monthly_mean', 'daily' or 'daily_mean' (Mandatory, str)
    # units: desired data units for each variable. Only available for temperature,
    #   precipitation, and pressure variables.
    - {name: 'tas', freq: 'monthly_mean', units: 'K'}
    # To request more variables to be divided in atomic recipes, add them this way:
    #   - {name: 'prlr', freq: 'monthly_mean', units: 'mm'}
    # To request multiple variables *in the same* atomic recipe, add them this way:
    #   - {name: 'tas, prlr', freq: 'monthly_mean', units: {tas: 'C', prlr: 'mm'}}
  Datasets:
    System:
      # name: System name (Mandatory, str)
      # member: 'all' or individual members, separated by a comma and in quotes (decadal only, str)
      - {name: 'ECMWF-SEAS5.1', member: 'all'}
      - {name: 'Meteo-France-System7'}
      # To request more Systems to be divided in atomic recipes, add them this way:
      #  - {name: 'Meteo-France-System7'}
    Multimodel:
      execute: no # Either yes/true or no/false (Mandatory, bool)
      approach: pooled # Multimodel computation approach. 'pooled' currently the only option (str)
      createFrom: Anomalies # Which module should the anomalies be created from (str)
    Reference:
      - {name: 'ERA5'} # Reference name (Mandatory, str)
      # To request more References to be divided into atomic recipes, add them this way:
      # - {name: 'ERA5Land'}
  Time:
    sdate:
      - '0101'
      - '0201'
      - '0301'
      - '0401'
      - '0501'
      - '0601'
      - '0701'
      - '0801'
      - '0901'
      - '1001'
      - '1101'
      - '1201' # Start date, 'mmdd' (Mandatory, int)
      # To request more startdates to be divided into atomic recipes, add them this way:
      # - '0101'
      # - '0201'
      # ...
    fcst_year: '2020' # Forecast initialization year 'YYYY' (Optional, int)
    hcst_start: '1993' # Hindcast initialization start year 'YYYY' (Mandatory, int)
    hcst_end: '2016' # Hindcast initialization end year 'YYYY' (Mandatory, int)
    ftime_min: 1 # First forecast time step in months. Starts at “1”. (Mandatory, int)
    ftime_max: 6 # Last forecast time step in months. Starts at “1”. (Mandatory, int)
  Region:
    # latmin: minimum latitude (Mandatory, int)
    # latmax: maximum latitude (Mandatory, int)
    # lonmin: # minimum longitude (Mandatory, int)
    # lonmax: # maximum longitude (Mandatory, int)
    - {name: global, latmin: -90, latmax: 90, lonmin: 0, lonmax: 359.9}
    # To request more regions to be divided in atomic recipes, add them this way:
    # {name: "nino34", latmin: -5, latmax: 5, lonmin: -10, lonmax: 60}
  Regrid:
    method: conservative # Interpolation method (Mandatory, str)
    type: to_system # Interpolate to: 'to_system', 'to_reference', 'none',
                    # or CDO-accepted grid. (Mandatory, str)
  Workflow:
    # This is the section of the recipe where the parameters for each module are specified
    Calibration:
      method: raw # Calibration method. (Mandatory, str)
      save: 'none' # Options: 'all', 'none', 'exp_only', 'fcst_only' (Mandatory, str) 
    Anomalies:
      compute: yes # Either yes/true or no/false (Mandatory, bool)
      cross_validation: no # Either yes/true or no/false (Mandatory if 'compute: yes', bool)
      save: 'all' # Options: 'all', 'none', 'exp_only', 'fcst_only' (Mandatory, str)
    Downscaling:
      # Assumption 1: leave-one-out cross-validation is always applied
      # Assumption 2: for analogs, we select the best analog (minimum distance)
      type: intbc  # mandatory, 'none', 'int', 'intbc', 'intlr', 'analogs', 'logreg'.
      int_method: conservative # regridding method accepted by CDO. (Mandatory, str)
      bc_method: bias  # If type=intbc. Options: 'bias', 'calibration', 'quantile_mapping', 'qm', 'evmos', 'mse_min', 'crps_min', 'rpc-based'.
      lr_method: # If type=intlr. Options: 'basic', 'large_scale', '9nn'
      log_reg_method: # If type=logreg. Options: 'ens_mean', 'ens_mean_sd', 'sorted_members'
      target_grid: /esarchive/recon/ecmwf/era5/monthly_mean/tas_f1h/tas_200002.nc  # nc file or grid accepted by CDO
      nanalogs: # If type analgs. Number of analogs to be searched
      save: 'all' # Options: 'all'/'none'/'exp_only' (Mandatory, str)
    Time_aggregation:
      execute: no # # Either yes/true or no/false. Defaults to false. (Mandatory, bool)
      method: average # Aggregation method. Available methods: 'average, 'accumulated'. (Mandatory, string)
      # ini and end: list, pairs initial and final time steps to aggregate.
      # In this example, aggregate from 1 to 2; from 2 to 3 and from 1 to 3
      ini: [1, 2, 1]
      end: [2, 3, 3]
      # user_def: List of lists, Custom user-defined forecast times to aggregate.
      #   Elements should be named, named can be chosen by the user.
      #   An R expression can be entered using '!expr"; it will be evaluated by the code.
      # If both ini/end and user_def are defined, ini/end takes preference.
      user_def:
        DJF_Y1: [1, 3] # aggregate from 1 to 3 forecast times
        DJF: !expr sort(c(seq(1, 120, 12), seq(2, 120, 13), seq(3, 120, 14))) # aggregate 1,2,3,13,14,15,...
    Indices:
      ## Indices available: - NAO (for psl and/or z500);
      #                     - Nino1+2, Nino3, Nino3.4, Nino4 (for tos)
      ## Each index can only be computed if its area is within the selected region.
      # obsproj: NAO computation method (see s2dv::NAO()) Default is yes/true. (Optional, bool)
      # save: What to save. Options: 'all'/'none'. Default is 'all'.
      # plot_ts: Generate time series plot? Default is yes/true. (Optional, bool)
      # plot_sp: Generate spatial pattern plot? Default is yes/true. (Optional, bool)
      # alpha: Significance threshold. Default value is 0.05 (Optional, numeric)
      #Nino1+2: {save: 'all', plot_ts: yes, plot_sp: yes, alpha: 0.05}
      #Nino3: {save: 'all', plot_ts: yes, plot_sp: yes, alpha: 0.05}
      #Nino3.4: {save: 'all', plot_ts: yes, plot_sp: yes, alpha: 0.05}
      #Nino4: {save: 'all', plot_ts: yes, plot_sp: yes, alpha: 0.05}
      # Also available if variable is psl and/or z500:
      # NAO: {obsproj: yes, save: 'all', plot_ts: yes, plot_sp: yes}
    Skill:
      metric: mean_bias enscorr rpss crpss enssprerr rps crps rms rmss # List of skill metrics separated by spaces or commas. (Mandatory, str)
      alpha: 0.05
      save: 'all' # Options: 'all', 'none' (Mandatory, str)
    Statistics:
      metric: cov std var n_eff # List of statistics separated by spaces or commas. (Mandatory, str)
      save: 'all' # Options: 'all', 'none' (Mandatory, str)
    Probabilities:
      percentiles: [[1/3, 2/3]] # Thresholds 
      # for quantiles and probability categories. Each set of thresholds should be
      # enclosed within brackets. For now, they are INDEPENDENT from skill metrics. (Optional)
      save: 'percentiles_only' # Options: 'all', 'none', 'bins_only', 'percentiles_only' (Mandatory, str)
    Visualization:
      plots: skill_metrics, most_likely_terciles, forecast_ensemble_mean # Types of plots to generate (Optional, str)
      multi_panel: no # Multi-panel plot or single-panel plots. Default is 'no/false'. (Optional, bool)
      projection: 'robinson' # Options: 'cylindrical_equidistant', 'robinson', 'lambert_europe'. Default is cylindrical equidistant. (Optional, str)
      mask_terciles: no # Whether to mask the non-significant points by rpss in the most likely tercile plot. yes/true, no/false or 'both'. Default is no/false. (Optional, str)
      dots_terciles: yes # Whether to dot the non-significant by rpss in the most likely tercile plot. yes/true, no/false or 'both'. Default is no/false. (Optional, str)
      mask_ens: no # Whether to mask the non-significant points by rpss in the forecast ensemble mean plot. yes/true, no/false or 'both'. Default is no/false. (Optional, str)
      file_format: 'PNG' # Final file format of the plots. Formats available: PNG, JPG, JPEG, EPS. Defaults to PDF.
    Scorecards:
      execute: yes # yes/no
      regions: 
        # Mandatory: Define regions for which the spatial aggregation will be performed.
        # The regions must be included within the area defined in the 'Analysis:Region' section.
        Extra-tropical NH:  {lon.min: 0,  lon.max: 360, lat.min: 30, lat.max: 90}
        Tropics: {lon.min: 0,  lon.max: 360, lat.min: -30, lat.max: 30}
        Extra-tropical SH : {lon.min: 0,  lon.max: 360, lat.min: -90, lat.max: -30}
      start_months: 1, 2, 3 # Mandatory, int: start months to visualise in scorecard table. Options: 'all' or a sequence of numbers.
      metric: mean_bias enscorr rpss crpss enssprerr # Mandatory: metrics to visualise in scorecard table
      metric_aggregation: 'score' # Mandatory, str: level of aggregation for skill scores. Options: 'score' or 'skill'
      inf_to_na: True # Optional, bool: set inf values in data to NA, default is no/False
      table_label: NULL # Optional, str: extra information to add in scorecard table title
      fileout_label: NULL # Optional, str: extra information to add in scorecard output filename
      col1_width: NULL # Optional, int: to adjust width of first column in scorecards table
      col2_width: NULL # Optional, int: to adjust width of second column in scorecards table
      calculate_diff: False # Mandatory, bool: True/False
  cross.method: 'leave-one-out' # Default 'leave-one-out'
  ncores: 16 # Number of cores to be used in parallel computation.
             # If left empty, defaults to 1. (Optional, int)
  remove_NAs: yes # Whether to remove NAs.
                   # If left empty, defaults to no/false. (Optional, bool)
  Output_format: 'Scorecards' # 'S2S4E' or 'Scorecards'. Determines the format of the output. Default is 'S2S4E'.
Run:
  filesystem: esarchive # Name of the filesystem as defined in the archive configuration file
  Loglevel: INFO # Minimum category of log messages to display: 'DEBUG', 'INFO', 'WARN', 'ERROR' or 'FATAL'. 
                 # Default value is 'INFO'. (Optional, str)
  Terminal: yes  # Optional, bool: Whether to display log messages in the terminal.
                 # Default is yes/true.
  output_dir: /esarchive/scratch/nperez/git4/ # Output directory. Must have write permissions. (Mandatory, str)
  code_dir: /esarchive/scratch/nperez/git4/sunset/ # Directory where the code is stored. Is used when launching jobs (not running interactively)
  autosubmit: no # Whether or not to run with Autosubmit. Only for non-atomic recipes (not running interactively)
  # fill only if using autosubmit
  auto_conf:
    script: ./example_scripts/multimodel_seasonal.R # replace with the path to your script
    expid: a6wq # replace with your EXPID
    hpc_user: bsc032339 # replace with your hpc username
    wallclock: 01:00 # wallclock for single-model jobs, hh:mm
    wallclock_multimodel: 02:00 # wallclock for multi-model jobs, hh:mm. If empty, 'wallclock' will be used.
    processors_per_job: 4 # processors to request for each single-model job.
    processors_multimodel: 16 # processors to request for each multi-model job. If empty, 'processors_per_job' will be used.
    custom_directives: ['#SBATCH --exclusive'] # custom scheduler directives for single-model jobs.
    custom_directives_multimodel: ['#SBATCH --exclusive', '#SBATCH --constraint=highmem'] # custom scheduler directives for multi-model jobs. If empty, 'custom_directives' will be used.
    platform: nord3v2 # platform (for now, only nord3v2 is available)
    email_notifications: yes # enable/disable email notifications. Change it if you want to.
    email_address: nuria.perez@bsc.es # replace with your email address
    notify_completed: yes # notify me by email when a job finishes
    notify_failed: yes # notify me by email when a job fails
