.correlation_eno <- function(exp, obs, time_dim, method, alpha, test.type, pval){
  
  cor <- NULL
  cor$r = cor(x = exp, y = obs, method = method) # Correlation coefficient
  
  n_eff = s2dv::Eno(data = obs, time_dim = time_dim, na.action = na.pass, ncores = 1)
  
  if (test.type == 'one-sided'){
    
    t_alpha_n2 = qt(p=alpha, df = n_eff-2, lower.tail = FALSE)
    t = cor$r * sqrt(n_eff-2) / sqrt(1-cor$r^2)
    
    if (anyNA(c(t,t_alpha_n2)) == FALSE & t >= t_alpha_n2 & cor$r > 0){
      cor$sign = TRUE
    } else {
      cor$sign = FALSE
    }
    
    # cor$n_eff <- n_eff
    
    if (isTRUE(pval)){
      cor$pval <- pt(q = t, df = n_eff-2, lower.tail = FALSE)
    }
    
  } else if (test.type == 'two-sided'){
    
    t_alpha2_n2 = qt(p=alpha/2, df = n_eff-2, lower.tail = FALSE)
    t = abs(cor$r) * sqrt(n_eff-2) / sqrt(1-cor$r^2)
    
    if (anyNA(c(t,t_alpha2_n2)) == FALSE & t >= t_alpha2_n2){
      cor$sign = TRUE
    } else {
      cor$sign = FALSE
    }
    
    cor$n_eff <- n_eff
    
    if (isTRUE(pval)){
      cor$pval <- 2 * pt(q = t, df = n_eff-2, lower.tail = FALSE)
    }
    
  } else {stop('test.type not supported')}
  
  return(cor)
}
