Aim

To explore a tagging event in March 2017 on a seamount with a curious pattern of recoveries, ie the majority of fish swam directly northwest being caught a month later in a relatively feature-less (no seamount) stretch of ocean.

Step 1

Here I attach to the internal PostgreSQL database maintained at ICCAT HQ and read in the data directly using ODBC. It may be possible that this can be set up on an external server but for now it will currently not work outside ICCAT. The code could be adapted to work with the geopackage or csv files available here, AOTTP tag recapture data

## Read in AOTTP data from DB ##
aottp <- dbConnect(RPostgreSQL::PostgreSQL(),
                 dbname="aottp",
                 host= "172.16.1.48",
                port= 5432,
                user= "aottpw",
                  password="tunasw")
 strSQL <- "SELECT * FROM releases_recoveries;"
 rs <- dbSendQuery(aottp, strSQL)
 rel_rec <- dbFetch(rs)
dbClearResult(rs)
## [1] TRUE
simpleCap <- function(x) {
  s <- strsplit(x, " ")[[1]]
  paste(toupper(substring(s, 1,1)), substring(s, 2),
      sep="", collapse=" ")
}

'%notin%' <- Negate(`%in%`)

# Get vessel name and add it on
vs <- dbSendQuery(aottp,"SELECT * from vessels;")
vessels <- dbFetch(vs)
dbClearResult(vs)
## [1] TRUE
vessels$vesselname[vessels$vesselid == 862] <- 'ACORIANA'
vessels$vesselname[vessels$vesselid == 1019] <- 'ALDEBARAN_1'
vessels$vesselname[vessels$vesselid == 1047] <- 'TUBURAO_TIGRE'
vessels <- vessels[vessels$vesselname %notin% c("AT000USA00050", 'XIXILI'),]
vessels$vesselname <- gsub("\r\n\t\r\n","",vessels$vesselname)
vessels1 <- vessels[!is.na(vessels$vesselrecovery) & vessels$vesselrecovery ==1,]
vessels1$rcvesselname <- unlist(lapply(tolower(vessels1$vesselname),simpleCap))

Step 2

Add on useful vectors such as Exclusive Economic Zone. This (e.g. function spatialVectors) requires the library ‘FLTag’ which is available from AOTTP Coordination.

# Add on useful vectors, e.g. julian day, month, year, EEZ
rel_rec <- formatTagdata(input=rel_rec);
rel_rec <- timeVectors(input=rel_rec,orig.date="2016-01-01");
rel_rec <- spatialVectors(input=rel_rec);
rel_rec <- rel_rec[!is.na(rel_rec$relonx) & !is.na(rel_rec$relaty),]
rel_rec <- rel_rec[rel_rec$rcstagecode_re == 'R-1',]
rel_rec$rcvesselname <- vessels1$rcvesselname[match(rel_rec$rcvesselid,vessels1$vesselid)]
#dim(rel_rec) = 113188
# Speed (nautical miles per day)
rel_rec$speed<- (rel_rec$distance_nm/rel_rec$days_at_liberty) # nautical miles per day
# Remove very short days at liberty
rel_rec <- rel_rec[!is.na(rel_rec$days_at_liberty) & rel_rec$days_at_liberty > 0,]
# put on rhumb bearing where we have location data
loc<-cbind(rel_rec$relonx,rel_rec$relaty,rel_rec$rclonx,rel_rec$rclaty)
rel_rec$nlocs <- apply(apply(loc,2,is.na),1,sum)
p1 <- cbind(rel_rec$relonx[rel_rec$nlocs==0],rel_rec$relaty[rel_rec$nlocs==0])
p2 <- cbind(rel_rec$rclonx[rel_rec$nlocs==0],rel_rec$rclaty[rel_rec$nlocs==0])
rel_rec$bearingRhumb[rel_rec$nlocs==0] <- bearingRhumb(p1,p2)

Step 3

Extract data for 2 seamount areas.

# Area 1
sm <- rel_rec[!is.na(rel_rec$bearingRhumb) & rel_rec$relonx >= -24 & rel_rec$relonx <= -17 & rel_rec$relaty >=5 & rel_rec$relaty <= 10 ,]
# Area 2
sm2 <- sm[sm$relonx >= -23 & sm$relonx <= -22 & sm$relaty >=6 & sm$relaty <= 7 ,]


sm2<-orderBy(~retimestamp,data=sm2)
ind <- (1:length(sm2[,1]))[sm2$speciescode !='UNK' & sm2$speed < 10]
sm2 <- sm2[ind,]

# <!-- write.table(cbind(numtag1 =sm2$numtag1,relonx=sm2$relonx,relaty=sm2$relaty,redate=as.character(sm2$redate),rclonx=sm2$rclonx,rclaty=sm2$rclaty,rcdate=as.character(sm2$rcdate),relen=sm2$relen,rclen=sm2$rclen,speciescode=sm2$speciescode,rcvesselid=sm2$rcvesselid,distance_nm=sm2$distance_nm,ndays=sm2$ndays,rcnotes=sm2$rcnotes),file="sm406022.csv",row.names=F,sep=',')  -->

Table 1. Fish tagged in Area 2 between October 2017 and March 2017

  2016-10-29 2017-02-21 2017-02-22 2017-03-18
BET 422 14 10 344
SKJ 0 16 4 30
YFT 220 48 108 165

Step 4

Map the tracks of the tagging done in March 2017

mapTrack(sm2[sm2$redate > "2017-02-28",], what.species=c('BET','YFT'),what.size=0.1,what.distance=50,
lon.limits=c(-36,0),lat.limits=c(-10,20))
**Figure 1. BET and YFT tagged at Seamount 406022 in March 2017**

Figure 1. BET and YFT tagged at Seamount 406022 in March 2017

Step 5

Rhumb bearing of the path taken by each tagged tuna. Table 2. Rhumb bearing of all fish tagged in Area 2 in March 2017

sm2$cb <- cut(sm2$bearingRhumb,seq(0,360,by=45))
cb<-table(sm2$cb[sm2$reyrmon == 'Mar 2017'],sm2$speciescode[sm2$reyrmon == 'Mar 2017'])
pander(cb)
  BET SKJ YFT
(0,45] 11 5 11
(45,90] 13 5 11
(90,135] 122 2 51
(135,180] 14 1 12
(180,225] 1 1 2
(225,270] 5 0 1
(270,315] 167 10 67
(315,360] 11 6 10

Step 6

Wind Rose for the tuna tagged in March 2017 showing that most headed off to the NW.

sm2$reyrmon2 <- as.character(sm2$reyrmon)

windRose(sm2[sm2$reyrmon == 'Mar 2017',],ws="speed",wd="bearingRhumb",bias.corr = TRUE,border=TRUE,type = "reyrmon2",width = 0.5,grid.line = 10,
         statistic = "prop.count",offset = 10, paddle =FALSE,cols="hue",annotate=FALSE,auto.text=FALSE,
         ws.int=10,breaks=floor(seq(0,100,length=5)),key = F, key.footer = "(m/hour)", key.position = "bottom",na.action=NULL,
         key.header = "Movement Speed",main="Seamount 406022",font.main=1,sub="\nData source: ICCAT AOTTP",font.sub=2)
**Figure 3. Wind rose of BET and YFT tagged at Seamount 406022 in March 2017**

Figure 3. Wind rose of BET and YFT tagged at Seamount 406022 in March 2017

Step 7

Polar frequency for the BET tuna tagged in March 2017.

# Has to contain columns with 'ws', 'wd', and 'date'
sm2$ws<-sm2$speed
sm2$wd<-sm2$bearingRhumb
sm2$date<- sm2$redate

polarFreq(sm2[sm2$speciescode == 'BET' & sm2$reyrmon == 'Mar 2017',],type='redate',pollutant='ws',statistic='frequency',grid.line=2,ws.int=2,
wd.nint=36,ws.upper=10,key=T,auto.text=F)
**Figure 4. Polar frequency plot of BET tagged at Seamount 406022 in March 2017**

Figure 4. Polar frequency plot of BET tagged at Seamount 406022 in March 2017

Step 8

‘Wind’ vectors as a funcion of time for the BET tuna tagged in March 2017.

ggplot(sm2[sm2$speciescode == 'BET' & sm2$reyrmon == 'Mar 2017',]) +
  geom_segment(aes(x = retimestamp,
                   y = 0,
                   xend = retimestamp + lubridate::dhours(speed * 1 * -cos((270-bearingRhumb) / 360 * 2 * pi)),
                   yend = speed * 1 * -sin((270-bearingRhumb) / 360 * 2 * pi),
                   col = speciescode
                   ),
               arrow = arrow(length = unit(0.25, "cm")),size=.5 ) +
  geom_point(aes(retimestamp, 0), size = 1) +
  coord_fixed(3600) +
  scale_x_datetime(name="")+
          scale_y_continuous(name = "NM/Days at liberty")
**Figure 5. Wind vector stick plot of BET tagged at Seamount 406022 in March 2017**

Figure 5. Wind vector stick plot of BET tagged at Seamount 406022 in March 2017

Step 9

Explore Vessel ‘X’ (chosen since it recorded the majority of tags recovered) tag recovery locations.

a15 <- rel_rec[!is.na(rel_rec$rcvesselname) & rel_rec$rcvesselid == 941 & rel_rec$recovered ==T,]


# numbers of fish caught by day and location

tt <- melt(table(round(a15$rclonx,1),round(a15$rclaty,1),
a15$rcdate))
tt<- tt[tt$value>0,]
dimnames(tt)[[2]] <- c('rclonx','rclaty','rcdate','freq')
tt$rcdate<- as.POSIXct(as.character(tt$rcdate))
tt$lfreq <- log(tt$freq)
tt$year<-year(tt$rcdate)

world <- map_data('world');
lon.limits <- c(-40,10);lat.limits <- c(-10,30)

pp <- ggplot(data=tt,
    aes_string(x="rclonx",y="rclaty"))+
    coord_fixed(1.3,xlim=lon.limits,ylim=lat.limits) +
    geom_point(data=tt,aes_string(x="rclonx",y="rclaty",size="freq",color="freq"),
    alpha=1,show.legend = FALSE)+
    geom_polygon(data=world,aes(x=long,y=lat,group=group),col='darkgreen',fill='darkgreen')

pp
**Figure 6. Vessel X Tag Recoveries**

Figure 6. Vessel X Tag Recoveries

Step 10

Animate Vessel X tag recovery locations as a function of recovery date for a bit of fun.

ppp <- pp + transition_time(rcdate)+
  labs(title = "Recovery date:{frame_time}")
#shadow_wake(wake_length = 0.01, alpha = TRUE)
ppp
Figure 7. Animation of Vessel X Tag Recoveries over time

Figure 7. Animation of Vessel X Tag Recoveries over time

#anim_save(ppp,file='a15.gif')
#system('convert -coalesce a15.gif a15%04d.png')