SeasonSelect <- function(data, seasons) {
  time_dim <- which(names(dim(data)) == "time")
  
  
  ##Subset the data based on the users selected season:
  dates <- attributes(data)$Variables$dat1$time
  time_dim <- which(names(dim(data)) == "time")
  
  dates <- as.PCICt(dates, cal = attributes(dates)$variables$time$calendar, format = "%Y%m%d")
  jdays <- as.numeric(strftime(dates, format = "%j"))
  if (seasons == "DJF") {
    days <- c(c(335 : 365), c(1 : 59))
  } else if (seasons == "MAM") {
    days <- c(60 : 151)
  } else if (seasons == "JJA") {
    days <- c(152 : 243)
  } else {
    days <- c(244 : 334)
  }
  index <- which(jdays %in% days)
  data <- Subset(data, along = time_dim, indices = index, drop = "non-selected")
  dims <- dim(data)
  dims <- append(dims, c(length(days), dims[1] / length(days)), after = 1)
  dims <- dims[-1]
  dim(data) <- dims
  data <- aperm(data, c(2,1,3,4))
  names(dim(data)) <- c("year", "day", "lat", "lon")
  return(data)
}

