Introduction

Climate Data API provides access to past, present, and future climate data time series.

In this project, I want to plot the results of the general circulation models(GCMs). GCMs are climate models that consider various fluid motion variables such as earth surface pressure, temperature and water vapor, and radiation. These models also include time to forecast the past, present, and future of climate changes.

The goal is to compare two general circulation models (GCM) for future temperatures in United Kingdom. I will first extract the data for both models and then create line plots to visualize them.

Using World Bank API

The API documentation provides all the information about API endpoints that are supported.

library(ggplot2)
library(httr)

wordbank_api_response <- function(endpoint, queries = list()){
    url <-  
    modify_url("http://climatedataapi.worldbank.org",
    path = endpoint)
    
    response <- GET(url, query = queries)
    content <- content(response, "text")
    content_df <- jsonlite::fromJSON(content)
    return(content_df)
}

climate_nigeria_2039_1 <- wordbank_api_response("climateweb/rest/v1/country/manom/bccr_bcm2_0/a2/tas/2020/2039/GBR")
climate_nigeria_2039_2 <- wordbank_api_response("climateweb/rest/v1/country/manom/cccma_cgcm3_1/a2/tas/2020/2039/GBR")
str(climate_nigeria_2039_1)
## 'data.frame':    1 obs. of  6 variables:
##  $ scenario : chr "a2"
##  $ gcm      : chr "bccr_bcm2_0"
##  $ variable : chr "tas"
##  $ monthVals:List of 1
##   ..$ : num  0.713 0.77 0.424 1.101 0.732 ...
##  $ fromYear : int 2020
##  $ toYear   : int 2039
str(climate_nigeria_2039_2)
## 'data.frame':    1 obs. of  6 variables:
##  $ scenario : chr "a2"
##  $ gcm      : chr "cccma_cgcm3_1"
##  $ variable : chr "tas"
##  $ monthVals:List of 1
##   ..$ : num  0.968 0.814 0.724 0.909 0.647 ...
##  $ fromYear : int 2020
##  $ toYear   : int 2039
#Setting up vectors for month-wise dataframe 
month_vals_1 <- unlist(climate_nigeria_2039_1$monthVals)
month_vals_2 <- unlist(climate_nigeria_2039_2$monthVals)
value <- c(month_vals_1, month_vals_2)

month <- c('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')

gcm <- c(rep('bccr_bcm2_0', times = 12), rep('cccma_cgcm3_1', times = 12))

df_to_plot <- data.frame(gcm, month, value)
head(df_to_plot)
##           gcm month     value
## 1 bccr_bcm2_0   Jan 0.7126880
## 2 bccr_bcm2_0   Feb 0.7702698
## 3 bccr_bcm2_0   Mar 0.4235132
## 4 bccr_bcm2_0   Apr 1.1009265
## 5 bccr_bcm2_0   May 0.7323438
## 6 bccr_bcm2_0   Jun 0.4697241
ggplot(data = df_to_plot,
      aes(x = factor(month, levels = month.abb), 
          y = value, 
          group = gcm, 
          color = gcm)) + 
    geom_line() + 
    ylab("Average monthly change of Temperature (anomaly)") + 
    xlab("Month") +
    ggtitle("Predictions for Average Monthly Change in Temperature: Nigeria")

Conclusion

This plot shows that the bccr_bcm2_0 model is less optimistic than cccma_cgcm3_1 because the monthly anomaly levels predicted by bccr_bcm2_0 are more than those predicted by cccma_cgcm3_1. We can also notice that these two models agree (show the same values) only in a few months over the whole years.