rm(list=ls())
library(foreign)
library(rstan)
library(Hmisc)
library(data.table)
library(parallel)

setwd('~/research/gTiger/Article_citsci/open_code')
source('settings/parameters.r')
source('settings/paths.r')
source('settings/functions.r')

setwd(path_to_data)

D = readRDS('ovitraps.Rds')

D = D[I_year %in% 2014:2015 & !is.na(Expos_days) & !is.na(Egg_pres), ]

D$TigacellID = paste(round(floor(D$Long/.05)*.05, 2), round(floor(D$Lat/.05)*.05, 2), sep='_')

D$sea_days =  as.POSIXlt(D$F_date)$yday

std2 = function(x) (x-mean(x,na.rm=T))/(2*sd(x, na.rm=T))
invstd2 = function(x, d) (x*2*sd(d, na.rm=T))+mean(d,na.rm=T)

D$Expos_days_std2 = std2(D$Expos_days)
D$sea_days_std2 = std2(D$sea_days)
D$sea_days_std2_sq = D$sea_days_std2^2
D$sea_days_std2_cu = D$sea_days_std2^3

saveRDS(D, 'ovitrap_model_dataset.Rds')