-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_all_nonbreed_locs.R
84 lines (65 loc) · 3.16 KB
/
map_all_nonbreed_locs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Map of all locations
# filtered to remove the 25% worst positions around the equinox
# between day 86-109 and 229-269
# Check if have required packages installed and install if not
list.of.packages <- c("dplyr","ggplot2","readr","gridExtra","viridis","MASS","data.table","lubridate","fasttime",
"wesanderson","sp","raster","rgdal","sf","ggspatial")
# compare to existing packages
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
# install missing packages
if(length(new.packages)>0) {install.packages(new.packages)}
# load required packages
lapply(list.of.packages, library, character.only = TRUE)
# read in and prepare location data
# 500 chains
locs500<- read_csv("data/gdr_locs_final_500_all_yr_v2021-06-03.csv")%>%
mutate(doy=as.numeric(format(time1,"%j")))%>%
filter(!doy%in%c(86:109)&!doy%in%c(229:269))%>%
mutate(year=factor(season+1),month=month(time1))
# read in GDR deploy file to filter out birds with incomplete tracks
gdr_depl <- read_csv("data/croz_royds_gdr_depl_all_v2021-08-27.csv")
# filter to files that are complete
locs500_depl <-locs500%>%
left_join(dplyr::select(gdr_depl,bird_fn,season,data,br_col))%>%
filter(data=="c")
# check how many deployments and unique IDs
# unique IDs
nrow(distinct(locs500_depl,bird_fn)) # 111
locs500_depl%>%
group_by(bird_fn,season)%>%
dplyr::select(bird_fn,season)%>%
distinct() # 185 deployments with complete data
nrow(locs500_depl)/500
# 62715 total locations
# clear environment
rm(list = ls())
# restart R session to clear memory...
# reload packages
list.of.packages <- c("dplyr","ggplot2","readr","gridExtra","viridis","MASS","data.table","lubridate","fasttime",
"wesanderson","sp","raster","rgdal","sf","ggspatial")
# load required packages
lapply(list.of.packages, library, character.only = TRUE)
# set data frame projection
proj <- CRS("+proj=longlat +ellps=WGS84 +lon_0=-169 +lon_wrap")
proj_ant <-CRS("+proj=stere +lat_0=-90 +lat_ts=-70 +lon_0=180 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs")
# read in MAP layers ####
MPA <- readOGR("GIS/mpa-shapefile-EPSG102020.shp")
# reproject MPA
mpa_t <- spTransform(MPA, proj_ant)
# read in and project antarctica coastline
ant <- spTransform(readOGR("GIS/ADDcstpoly_edit_2021_11_23.shp"), proj_ant)
# read in and project grid lines for plotting
polar_grid <-spTransform(readOGR("GIS/latlong_stereo.shp"), proj_ant)
# read in and project 1000m isobath
iso1000 <- spTransform(readOGR("GIS/1000_m_isobath.shp"),proj_ant)
# read in and project ACC boundary
front <-spTransform(readOGR("GIS/acc_fronts.shp"),proj_ant)
# Function to summarize molt locations and make figures of summarized data ####
source("code/molt_locs_summary_function.R")
cr_all <- plot_mlocs(data=locsall,colony=c("CROZ","ROYD"),seasons=c(2016:2018),grid_size=50000,
legend.title = "Location\nDensity",xlab="Longitude", ylab="Latitude",
legend.position="none",
title="",
rast_path = "data/summary_rasters/nonbreed_locs_filt_17_19.tiff",
poly_path = "data/contours/nonbreed_locs_filt_17_19")
print(cr_all)