How rainy is the rainy season?

visualisation
humanitarian
R

A time serie analysis of precipitation in Cox’ Bazar

Author
Affiliation

Himalayan Institute of Alternatives Ladakh

Published

April 18, 2024

When planning for construction work, rainfall become a very crucial factor. Data is easily available with month averages but more insights into historical data may be beneficial. I gathered data from Cox Bazaar weather station and did some analysis.

Data gathering

Analysis of daily rainy precipitation recorded at Cox’s Bazar weather station, 1970 to 2016. Data source.

Code
#https://www.kaggle.com/datasets/redikod/historical-rainfall-data-in-bangladesh?resource=download
#https://towardsdatascience.com/rainfall-time-series-analysis-and-forecasting-87a29316494e
library(rbokeh)
library(lubridate)
library(ggplot2)
library(tidyverse)
library(dplyr)
library(astsa)
library(forecast)
library(readxl)
library(urca)
library(ggfortify)
library(tsutils)
library(reshape2)
library(xts)
library(tidyr)
## Load data, select station and erase NA
raw <- read.csv("bgd_hist_precipitation.csv")%>%filter(Station=="CoxsBazar")
raw$Date <- as.Date(paste(raw$Year,raw$Month,raw$Day,sep="-"))
raw <- filter(raw,!is.na(raw$Date))

#Create day of the year
raw$DayOfYear <- lubridate::yday(raw$Date)
raw$MonWord<- format(raw$Date, "%h")

# Create timeserie
data_ts <- xts(raw$Rainfall, raw$Date) 

# Compute stats based on DoY
rain_day <- data.frame(rain=raw$Rainfall, day=raw$DayOfYear)
rain_avg <- rain_day %>% group_by(day) %>%
  summarize(mean = mean(rain),
            median= median(rain),
            rain_perc=sum(rain > 0)/length(rain),
            rain_heavy=sum(rain > 80)/length(rain))
# Add months and day
rain_avg$month <- raw[1:366, "Month"]
rain_avg$daymonth <- raw[1:366, "Day"]
rain_avg$monword <- raw[1:366, "MonWord"]


#raw$singleday <- paste(raw$Month,raw$Day,sep="-")
raw$DayOfYear <- lubridate::yday(raw$Date)

##Filter data for Cox bazar
data_cox <- filter(raw, raw$Station=="CoxsBazar")
data_cox <- filter(data_cox,!is.na(data_cox$Date))
data_ts <- xts(raw$Rainfall, raw$Date) 
rain_ts_df <-data.frame(Y=as.matrix(data_ts), date=time(data_ts))
write.csv(data_cox, "data_cox.csv")

Basic exploration

Plot of rainfall timeseries for Cox Bazar. While this is interesting, it gives only information on max precipitation, an idea about seasonl cycle.

More interesting is to see precipitation across the same day of the year (numbered from 1-365)

Decomposition

Decomposition of the time series in seasonality remainer and trend

  Trend.Strength Seasonal.Strength
1              0               0.2

Above a given threshold

Another analysis could show the occurrence of a rainy day (expressed as fraction 0 to 1) based on the historical data.The plot below shows that in July around 85% of the days in the dataset reported rainy events. This could also be done with a specific threshold of rain (ex. 80mm/24h) indicating the occurance of heavy storms for a given day of the year.

Anallysis for a single day

Let’s imagine there is a construction work in the first week of June (day 153 to 160)