Skip to content

getMACA() producing incorrectly ordered data #105

Description

@madeleineburns

I have been using the climateR and climatePy packages to get approximately 80 years of MACA data for a small watershed and aggregate the data. I have a working Python script that uses climatePy and accurately pulls/processes MACA data.

However, the R script that I have written that uses climateR to pull the same MACA data for the same watershed produces datasets that are clearly incorrect. Temperature projections for the future time period, which spans 75ish years (2023-2100) demonstrate a sinusoidal pattern with three significant waves. Precipitation projections show three distinct peaks over the same 75ish year period. All 13 models and 2 RCP scenarios that I queried demonstrate these trends (with varying magnitudes), and the error is reproducible across different watersheds. It is possible that there is an error with the code that I am using to process and aggregate the data, but I have carefully gone through it and do not believe this to be the case. After further investigation, it looks like the error occurs in the ordering/processing of the data before it gets returned by getMACA(). The object that gets returned from getMACA() in R is sorted by Model, then RCP, then Date, while the object that gets returned from getMACA() in climatePy is sorted by Date, then Model, then RCP - but the underlying data is the same. Manually re-ordering the data returned from getMACA() in climateR produces the same results as getMACA() in climatePy.

Incorrect MACA projections from the climateR package:
image
image

Minimum reproducible example:

aoi<- st_read(here("RedwoodCreek_shapefile","layers","globalwatershed.shp")
gcm_list <- c('BNU-ESM', 'CCSM4', 'CNRM-CM5', 'CSIRO-Mk3-6-0', 'CanESM2','GFDL-ESM2G', 'HadGEM2-CC365', 
              'IPSL-CM5A-LR', 'MIROC5', 'MIROC-ESM-CHEM','MRI-CGCM3', 'NorESM1-M', 'inmcm4')

future_climate_data <- getMACA(aoi, c('tasmin','tasmax','pr'), timeRes='day', model=gcm_list, scenario=c('rcp45','rcp85'), 
                            startDate = '2023-01-01', endDate = '2099-12-31')
  precip <- as.data.frame(colMeans(as.data.frame(values(future_climate_data$precipitation))))
  temp <- as.data.frame(colMeans(as.data.frame(values(future_climate_data$air_temperature))))
  
  temp <- data.frame(do.call(rbind, strsplit(rownames(temp), "_")), temp, stringsAsFactors = FALSE)
  colnames(temp) <- c("Variable", "Date","Model","Run","Scenario","Temp_K")
  rownames(temp) <- NULL; temp$Run <- NULL
  temp <- temp %>% arrange(Date, Model, Scenario)
  
  precip <- data.frame(do.call(rbind, strsplit(rownames(precip), "_")), precip, stringsAsFactors = FALSE)
  colnames(precip) <- c("Variable", "Date","Model","Run","Scenario","precip")
  rownames(precip) <- NULL; precip$Run <- NULL
  precip <- precip %>% arrange(Date, Model, Scenario)

plot(precip[precip$Model=='HadGEM2-CC365' & precip$Scenario=='rcp45',]$precip)
plot(temp[temp$Model=='HadGEM2-CC365' & temp$Scenario=='rcp45' & temp$Variable=='tasmin',]$Temp_K)

The raw data for the climatePy output (first image) shows that the CCSM4 RCP4.5 model has 5.8 mm of precipitation at one point location in the watershed on 1/1/2023. The raw data for the climateR output (second image) shows that the CCSM4 RCP4.5 model has 0 mm of precipitation at all point locations in the watershed on 1/1/2023.
getMACA_climatePy
getMACA_climateR

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions