This blog is run by Jason Jon Benedict and Doug Beare to share insights and developments on open source software that can be used to analyze patterns and trends in in all types of data from the natural world. Jason currently works as a geospatial professional based in Malaysia. Doug lives in the United Kingdom and is currently Director of Globefish Consultancy Services which provides scientific advice to organisations that currently include the STECF [Scientific, Technical and Economic Committee for Fisheries, https://stecf.jrc.europe.eu/] and ICCAT, https://www.iccat.int/en/

Monday, 21 April 2014

Penang: hot nights driving long-term change

 Key points of post
  • It is getting hotter in Penang

  • This change is 'driven' by night-time temperatures


In our previous blog posts (20 and 25 February 2014), we plotted monthly temperature data for Penang International Airport which showed how average air temperatures have increased steadily since the mid-1970s.

Time-series analysis, however, can be a tricky business and interpretations can only be made at the level of temporal aggregation (monthly, quarterly, weekly) initially selected. It is difficult to decide which level of aggregation is ‘best’. A general rule would be that you would want to analyze your time-series at the finest resolution possible. When you do aggregate your series in ‘chunks of time’, you need to make sure that any source of bias or confounding is not being masked or disguised by the aggregation step itself. You might, for example, have a series with missing Januaries at the start and missing Augusts at the end. Clearly it would be possible to plot and analyze the data at a quarterly resolution, but any long-term trends observed would be biased.

 
Here we have plotted the same temperature data that we have seen before, but this time at hourly resolution (for selected years). Plotting the data in this way shows the pronounced difference between night-time and day-time temperatures. Not surprisingly it’s generally a lot warmer during the day (red and orange bands) than it is at night (blue bands). You might also notice the spots and bands in grey at certain sections of the plot which are actually gaps in the hourly temperature data records.

What’s interesting, though, is that it is not the day-time temperatures that have increased over time, but the night-time temperatures. [Note the much bluer banding at night in 1979, 1985, and 1989 than is seen in more recent years (2010 & 2013)].

This demonstrates that the long-term trends in air temperature in Penang that we’ve seen before are not due to warmer day-time temperatures, which have been rather stable, but to warmer nights. It’s always tempting to attribute long-term changes in temperatures to climate change due to global warming. This warming trend, however, could just as easily be an ‘urban heat island’ effect. Penang’s economic development has been rapid over the last four decades and the ‘built environment’ is much larger than it used to be. All this extra concrete might be storing up heat during the day to release at night.

Whatever the cause, for ordinary Penangites it is still hotter, and the average temperatures still higher. As usual the data for this analysis are available freely online and the code to produce the plot is outlined below.

The raw data that was used to produce the hourly temperature 'strip' plot was acquired from the Integrated Surface Database (ISD) maintained by the National Climatic Data Centre at NOAA (http://www.ncdc.noaa.gov/oa/climate/isd/). According to the website, the database comprises over 20,000 stations worldwide, with some having data as far back as 1901, though the data show a substantial increase in volume in the 1940's and again in the early 1970's. Currently there are over 11,000 stations "active" and updated daily. This data is again available to be requested and downloaded without charge from the website.

The above hourly temperature plot was produced with one of the functions as part of an R package called 'Metvurst' (METeorological Visualisation Utilities Using R for Science and Teaching) developed by Tim Salabim and you can find more information and instructions on how to install and use it at the following link - http://metvurst.wordpress.com

The package can also be downloaded via the GitHub page below

http://tim-salabim.github.io/metvurst/


The detailed R code used to produce the plot is as below
# Setting work directory
 
setwd("d:\\ClimData")
 
list.files()
 
# Reading and reformatting raw daily data downloaded from ISD NCDC
 
dat<-read.table("2110827004508dat.txt",header=TRUE,fill=TRUE,na.strings=c("*","**","***","****","*****","******","0.00T*****"))
 
colnames(dat)<-tolower(colnames(dat))
 
# Convert hourly data from UTC to local time zone
 
Sys.setenv(TZ = "UTC")
dat$dates <- as.POSIXct(strptime(dat$yr..modahrmn,format="%Y%m%d%H%M"))  + 8 * 60 * 60
  
# Convert temperatures in Degree Fahrenheit to Degree Celcius
  
dat$tempc <- (dat$temp-32) * (5/9)
 
dat$tempc[dat$tempc<=10] <- NA
dat$tempc[dat$tempc>=40] <- NA 
 
# Extract years and month 
 
dat$year <- as.numeric(format(dat$dates,"%Y"))
 
dat$month <- as.numeric(format(dat$dates,"%m"))
  
# Load metvurst library
 
library(metvurst)
 
 
# Subset data for selected years
 
datsub <- subset(dat,year == 1979 | year == 1985 | year == 1989  | year == 1999 | year == 2001 | year == 2005 | year == 2010 | year == 2013 )
 
png(filename = "Penang_Daily_Temps_Cairo.png",height=8,width=12,
    bg = "white",units='in', res = 600, family = "", restoreConsole = TRUE,
    type = "cairo-png")
 
# Plot hourly air temperatures using the 'strip' function
 
plot.air.temp <- strip(x = datsub$tempc,
                       date = datsub$dates,
                       cond = datsub$year,
                       arrange = "long",
                       colour = colorRampPalette(rev(brewer.pal(11, "Spectral"))),
                       main = "Daily Air Temperature in Penang (Bayan Station) on Selected Years\n\nTemperature [°C]",
                       sub="Data source: Integrated Surface Database (ISD) - National Climatic Data Centre (NCDC)",font.sub=2)
 
print(plot.air.temp)
 
 
dev.off()
Created by Pretty R at inside-R.org

Wednesday, 12 March 2014

2014 has seen drought and forest fires on Penang Island

Key point of post
  •  February 2014 was the driest since 1990 and in the top 5 warmest

     

 2014 and ‘The Pearl of the Orient’ is looking parched. The grass is brown, the epiphytes that normally festoon the ‘rain’ trees in the Youth Park are wilted, and we’ve even had forest fires in the hills behind the main conurbations (see photos below). Last week aircraft were collecting seawater off Gurney Drive to douse the flames and, according to our friends in Penang, the current dry spell is unprecedented.









Further down south on the steep slopes of Bukit Jambul, there are recurring fires at various patches along the hills. The photo below was taken a few nights ago showing the fires on the hills just behind the Bukit Jambul High School and it has yet to cease entirely since this post was created.

 

As we’ve seen in previous post, while there is some ‘predictable’ seasonality in rainfall on Penang, it is also rather erratic or variable. We’ve plotted daily total rainfall at Penang Airport, below, for 7 selected years, and the first 2 months of 2014. These years give an illustration of some typical patterns. Generally speaking December, January and February are indeed quite dry but this is not always true. January 2000 and February 2005 were, for example, quite wet; early February 2005 seeing greater than 50mms rain in one day.



So what about 2014? There was a bit of rain in mid-January (at least at the airport) but none fell at all in February. Total February rainfall (blue line) since 1990 is plotted below, together with average daily air temperatures for February (red line). February 2014 was the driest for nearly 25 years but not by that much. Februaries 1995 and 2001 were also very dry. [Data for further back in time were available but incomplete records and lines of zeros made us suspect their veracity.]



Perhaps then higher temperatures than usual have exacerbated the low rainfall situation and helped stoke the forest fires? Previously we demonstrated that temperatures have been rising in Penang over the last 20 or so years and the hot period of the year now lasts longer than in the past. February 2014 was pretty hot at around 28.5°C, but nothing like as sweltering as 2010 when a mean temperature of around 29°C was recorded, together with also quite low rainfall.

So what of the connection between temperature and rainfall? The average February temperatures and rainfall 1990-2014 are plotted against each other below. There is obviously a negative relationship between the two (the correlation coefficient = -0.4). Wetter Februaries tend to be cooler and vice-versa.

 


February 2014 has been the driest since 1990 but not the hottest (1998, 2002, 2005, 2010 were all warmer). In summary the relationship between rainfall, temperature, and the triggers for forest fires are complex. Other factors that we have not examined such as humidity and wind speed may also have contributed.

Nevertheless we have shown that February 2014 has been the driest since 1990 on Penang Island and is in the Top 5 warmest years.

As usual, we include the R code we have used to produce the plots in this post. The raw data for these plots however was downloaded from the Global Surface Summary of the Day (GSOD) which is a product developed by the National Climatic Data Centre (NCDC) based in the US. The input data used in building these daily summaries are the Integrated Surface Data (ISD), which includes global data obtained from the USAF Climatology Center, located in the Federal Climate Complex with NCDC. The latest daily summary data are normally available 1-2 days after the date-time of the observations used in the daily summaries.

The datasets can be downloaded from NCDC via a normal web interface at the link below
http://www7.ncdc.noaa.gov/CDO/cdoselect.cmd?datasetabbv=GSOD

or through their FTP site at the following link
# Setting work directory
 
setwd("d:\\ClimData")
 
list.files()
 
# Reading and reformatting raw data downloaded from NCDC
 
dat<-read.table("CDO2812586929956.txt",header=F,skip=1)
 
colnames(dat)<-c("stn","wban","yearmoda","temp","tempc","dewp","dewpc","slp","slpc","stp","stpc","visib","visibc","wdsp","wdspc","mxspd","gust","maxtemp","mintemp","prcp","sndp","frshtt")
 
dat$yearmoda <- strptime(dat$yearmoda,format="%Y%m%d")
 
min.date <- min(dat$yearmoda)
max.date <- max(dat$yearmoda)
 
dat$prcp <- as.character(dat$prcp)
dat$prcp1<- as.numeric(substr(dat$prcp,1,4))
dat$prcpflag <- substr(dat$prcp,5,5)
 
dat$rain  <- dat$prcp1*25.4
dat$tempdc <- (dat$temp-32) * (5/9)
 
dat$rain[dat$rain > 1000 ] <- NA
 
dat$year <- as.numeric(format(dat$yearmoda,"%Y"))
dat$month <- as.numeric(format(dat$yearmoda,"%m"))
dat$day <- as.numeric(format(dat$yearmoda,"%d"))
 
# Plotting precipitation for various years in Penang from daily precipitation data
 
library(ggplot2)
library(scales)
 
dat$date<-as.Date(dat$yearmoda)
 
datsub <- subset(dat, year == 1990 | year == 1995 | year == 2000 | year == 2005 | year == 2010 | year == 2012 | year ==2013 | year == 2014)
 
dat1 <- transform(datsub, date = as.Date(paste(2000, month, day, sep="/")))
 
boxplot.title = 'Precipitation in Penang'
boxplot.subtitle = 'Data source : Federal Climate Complex, Global Surface Summary Of Day Data Version 7'
 
g <- ggplot(dat1, aes(date, rain)) +
  geom_line(col="blue", size=0.65) + 
  facet_wrap( ~ year, ncol = 2) +
  xlab("") + ylab("Precipitation (mms)") +
  scale_x_date(label = date_format("%b"), breaks = seq(min(dat1$date), max(dat1$date), "month")) +
  scale_y_continuous(limits = c(0,150)) +
  ggtitle(bquote(atop(.(boxplot.title), atop(italic(.(boxplot.subtitle)), "")))) + theme(plot.title = element_text(face = "bold",size = 16,colour="black")) +
  theme(legend.position = "none") + theme_bw()
g
 
ggsave(g, file="Penang_GSOD_Prcp_Plots.png", width=10, height=7)
 
# Plotting Average monthly temperature and total precipitation
 
avgtemp <- aggregate(tempdc ~ year + month, data = dat, FUN = mean)
totrain <- aggregate(rain ~ year + month, data = dat, FUN = sum)
 
avgtempfeb <- subset(avgtemp, month == 2 & year >= 1990)
totrainfeb <- subset(totrain, month == 2 & year >= 1990)
 
par(mar=c(5,4,4,5)+.1)
plot(avgtempfeb$year,avgtempfeb$tempdc,type="b",col="red",lwd=3,xlab="",ylab="")
par(new=TRUE)
plot(avgtempfeb$year,totrainfeb$rain,,type="b",col="blue",lwd=3,xaxt="n",yaxt="n",xlab="Year",ylab="Temperature (Degree C)",
     main = "Average temperature and total precipitation \n for the month of February in Penang for years 1990-2014")
axis(4)
mtext("Precipitation (mms)",side=4,line=3)
abline(v=1949:2014,lty=3,col='grey70')
legend("topleft",col=c("red","blue"),lwd=3,legend=c("Temperature","Precipitation"))
 
dev.off()
 
# Plot correlation between average temperature and total precipitation
 
png(filename = "Penang_TempPrcp_Correlation_Years_1990-2014.png",height=5,width=10,
    bg = "white",units='in', res = 300, family = "", restoreConsole = TRUE,
    type = "windows")
 
reg <- lm(totrainfeb$rain~avgtempfeb$tempdc)
plot(avgtempfeb$tempdc,totrainfeb$rain,type='n',xlab="Temperature (Degree C)",ylab="Precipitation (mms)",
     main = "Correlation between average temperature and total precipitation \n for the month of February in Penang for years 1990-2014")
 
abline(v=c(27.5,28,28.5,29,29.5,30),lty=3,col='grey70')
abline(h=c(0,50,100,150,200.250,300),lty=3,col='grey70')
text(avgtempfeb$tempdc,totrainfeb$rain,as.character(totrainfeb$year),cex=1.2,col="red")
box(lty = "solid", col = 'black',lwd=3)
 
# Correlation value between total precipitation and temperatures
 
cor(totrainfeb$rain,avgtempfeb$tempdc)
 
dev.off()
Created by Pretty R at inside-R.org

Tuesday, 25 February 2014

Penang: seasonality in air temperature and rainfall


 Key points of post
  • Warmest month in Penang is April

  • Wettest month in Penang is October

  • The warm season is now much longer than it used to be


Living in Penang, a tropical island off the northwest coast of peninsular Malaysia it often feels as if the weather is pretty much the same all year round; ie. hot, sweaty and sticky. Not true, however.

The data Jason and I have been analyzing suggest a different story with both air temperature and rainfall cycling substantially each year. 

The box and whisker plots below show monthly rainfall and air temperatures at Bayan Weather Station, Penang Airport, between 1935 and 2013.  Clearly one can expect a deluge at any time of the year.  Such events, however, are most likely in September and October and least likely in January and February.  Air temperatures, perhaps unsurprisingly, are coolest around the time when rainfall is highest, and hottest when rainfall is lowest





There’s a clear trade-off for the visitor.  If you like it hot, come between February and May, but if you prefer cooler temperatures come between September and November when you should expect some heavy downpours.

These box and whisker plots, however, best summarize the average air temperatures and precipitation over the years 1934 to 2013 and must be interpreted with some caution.  The boxes themselves, together with the whiskers, do give some indication of variability.  In some years, for example, temperatures can be higher in October which is typically the coolest month than temperatures in April, often the hottest month. The problem with the box and whisker plots is that there is no way to tell which years were unusually hot (or cool or wet).

A good way to explore how seasonality changes is to plot the time-series data (monthly averages, see our February 20 2014 post) three-dimensionally, scaling the variable of interest (e.g. temperature) to different colors. We have done this in the plot below for monthly average air temperatures between 1934 and 2013.  Year is along the x-axis and month along the y-axis.  The graph shows the relatively recent expansion (2000 to 2013) of higher temperatures throughout the year. In the 1950s, 1960s, 1970s, and early 1980s the hottest period seemed to be between February and May but now it extends much further into June, July, and August.


 
Hence one is much less likely, nowadays, to experience the relatively cool temperatures (around 26°C between July and December) that visitors in the past would have enjoyed.

The R code used to produce the box and whisker plots as well as the three-dimension temperature plot depicting the seasonality in Penang are shown below. The code continues from the one used in the previous post describing the monthly average temperatures in Penang.