generated from NEFSC/NEFSC-Template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
672fbef
commit 3a24b5b
Showing
14 changed files
with
710 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Use pulled survdat.rds file to get environmental thresholds for Atlantis groups | ||
library(dplyr) | ||
library(here) | ||
# Get output data | ||
NRHA_dt <-read.csv(here("data","NRHA_data.csv")) | ||
atlantis_groups_dt <- read.csv(here("inputs","atlantis_codes_svspp_survey_thresholds.csv")) | ||
# Modify data tables for ease of use | ||
colnames(atlantis_groups_dt)[2] <- "COMNAME" | ||
atlantis_groups_dt <- group_by(atlantis_groups_dt,Code) | ||
atlantis_NRHA_dt <- inner_join(NRHA_dt,atlantis_groups_dt,by="COMNAME") | ||
|
||
# The data includes a lot of 0's in the surface temperature data and some above 40 (104 F) | ||
# for the surface temperature data. This constricts the ranges to exclude 0's and temperatures above 40. | ||
atlantis_NRHA_dt$BottTEMP[(atlantis_NRHA_dt$BottTEMP == 0) | (atlantis_NRHA_dt$BottTEMP > 40)] <- NA | ||
atlantis_NRHA_dt$SurfTEMP[(atlantis_NRHA_dt$SurfTEMP == 0) | (atlantis_NRHA_dt$SurfTEMP > 40)] <- NA | ||
|
||
atlantis_NRHA_summary_table <- group_by(atlantis_NRHA_dt,Code,SEASON) | ||
atlantis_NRHA_summary_table_SEASON <- summarise(atlantis_NRHA_summary_table, min_bottom_temp = min(BottTEMP, na.rm=T), max_bottom_temp = max(BottTEMP, na.rm=T), | ||
min_surface_temp = min(SurfTEMP,na.rm=T), max_surface_temp = max(SurfTEMP,na.rm=T), | ||
min_bottom_sal = min(BottSALIN,na.rm=T), max_bottom_sal = max(BottSALIN,na.rm=T), | ||
min_surface_sal = min(SurfSALIN,na.rm=T), max_surface_sal = max(SurfSALIN,na.rm=T)) | ||
|
||
atlantis_NRHA_summary_table_SPECIES <- group_by(atlantis_NRHA_dt,Code) | ||
atlantis_NRHA_summary_table_SPECIES <- summarise(atlantis_NRHA_summary_table_SPECIES, min_bottom_temp = min(BottTEMP, na.rm=T), max_bottom_temp = max(BottTEMP, na.rm=T), | ||
min_surface_temp = min(SurfTEMP,na.rm=T), max_surface_temp = max(SurfTEMP,na.rm=T), | ||
min_bottom_sal = min(BottSALIN,na.rm=T), max_bottom_sal = max(BottSALIN,na.rm=T), | ||
min_surface_sal = min(SurfSALIN,na.rm=T), max_surface_sal = max(SurfSALIN,na.rm=T)) | ||
|
||
# Removes infinity values from the outputs and sets to NA | ||
atlantis_NRHA_summary_table_SEASON$min_bottom_sal[(atlantis_NRHA_summary_table_SEASON$min_bottom_sal == 'Inf') | (atlantis_NRHA_summary_table_SEASON$min_bottom_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SEASON$max_bottom_sal[(atlantis_NRHA_summary_table_SEASON$max_bottom_sal == 'Inf') | (atlantis_NRHA_summary_table_SEASON$max_bottom_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SEASON$min_surface_sal[(atlantis_NRHA_summary_table_SEASON$min_surface_sal == 'Inf') | (atlantis_NRHA_summary_table_SEASON$min_surface_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SEASON$max_surface_sal[(atlantis_NRHA_summary_table_SEASON$max_surface_sal == 'Inf') | (atlantis_NRHA_summary_table_SEASON$max_surface_sal == '-Inf')] <- 'NA' | ||
|
||
atlantis_NRHA_summary_table_SPECIES$min_bottom_sal[(atlantis_NRHA_summary_table_SPECIES$min_bottom_sal == 'Inf') | (atlantis_NRHA_summary_table_SPECIES$min_bottom_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SPECIES$max_bottom_sal[(atlantis_NRHA_summary_table_SPECIES$max_bottom_sal == 'Inf') | (atlantis_NRHA_summary_table_SPECIES$max_bottom_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SPECIES$min_surface_sal[(atlantis_NRHA_summary_table_SPECIES$min_surface_sal == 'Inf') | (atlantis_NRHA_summary_table_SPECIES$min_surface_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SPECIES$max_surface_sal[(atlantis_NRHA_summary_table_SPECIES$max_surface_sal == 'Inf') | (atlantis_NRHA_summary_table_SPECIES$max_surface_sal == '-Inf')] <- 'NA' | ||
|
||
write.csv(atlantis_NRHA_summary_table_SEASON,here("thresholds","atlantis_seasonal_thresholds_NRHA.csv"),row.names=FALSE) | ||
write.csv(atlantis_NRHA_summary_table_SPECIES,here("thresholds","atlantis_group_thresholds_NRHA.csv"),row.names=FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
# Use pulled survdat.rds file to get environmental thresholds for Atlantis groups | ||
library(dplyr) | ||
library(here) | ||
library(geosphere) | ||
|
||
# Temporal and spatial bounds | ||
|
||
isWithinBounds <- function(CTD_loc,p1_loc,SPATIAL_BOUND) { | ||
|
||
distance <- distm(CTD_loc,p1_loc,fun=distGeo) * 0.000621371 | ||
if (distance <= SPATIAL_BOUND) { | ||
return(TRUE) | ||
} else { | ||
return(FALSE) | ||
} | ||
} | ||
|
||
convertCTDdate <- function(date) { | ||
split.points <- c(4,6,8) | ||
converted_date <- substring(date,c(1,split.points + 1), c(split.points, nchar(date))) | ||
converted_date <- as.Date(paste(converted_date[1],"-",converted_date[2],"-",converted_date[3],sep="")) | ||
return(converted_date) | ||
} | ||
|
||
TEMPORAL_BOUND <- 7 # days | ||
SPATIAL_BOUND <- 1 # miles | ||
# Get output data | ||
NRHA_dt <-read.csv(here("data","NRHA_data.csv")) | ||
CTD_dt <-read.csv(here("data","CTD_data.csv")) | ||
|
||
# create empty dts to be filled for later analysts | ||
rows_CTD_dt <- nrow(CTD_dt) | ||
surfbot_dt <- CTD_dt[-c(1:rows_CTD_dt),] | ||
nearest_dt <- surfbot_dt | ||
|
||
# create list of uniqueIDs for CTD casts | ||
uniqueID_list <- unique(CTD_dt$UniqueID)[] | ||
|
||
|
||
# Make temporary data structure with just first (surface) and last (bottom) records, | ||
# and add the first row to nearest_dt and the first and last to to surfbot_dt | ||
|
||
numCasts <- length(uniqueID_list) | ||
|
||
for(i in 1:numCasts) { | ||
print(i) | ||
temp_dt <- filter(CTD_dt, UniqueID == uniqueID_list[i]) | ||
nearest_dt <- rbind(nearest_dt,temp_dt[1,]) | ||
surfbot_dt <- rbind(surfbot_dt,temp_dt[1,]) | ||
surfbot_dt <- rbind(surfbot_dt,temp_dt[nrow(temp_dt),]) | ||
} | ||
|
||
surfbot_dt_old <- surfbot_dt | ||
nearest_dt_old <- nearest_dt | ||
|
||
|
||
nearest_dt <- mutate(nearest_dt, DATE = convertCTDdate(Date)) | ||
surfbot_dt$Date <- convertCTDdate(surfbot_dt$Date) | ||
|
||
surfbot_numRows <- nrow(surfbot_dt) | ||
|
||
newDates <- c(convertCTDdate(surfbot_dt$Date[1])) | ||
for (i in 2:surfbot_numRows) { | ||
print(i) | ||
newDate <- convertCTDdate(surfbot_dt$Date[i]) | ||
newDates <- append(newDates,newDate) | ||
} | ||
|
||
surfbot_dt$Date <- newDates | ||
atlantis_groups_dt <- read.csv(here("inputs","atlantis_codes_svspp_survey_thresholds.csv")) | ||
|
||
# Modify data tables for ease of use | ||
colnames(atlantis_groups_dt)[2] <- "COMNAME" | ||
atlantis_groups_dt <- group_by(atlantis_groups_dt,Code) | ||
|
||
atlantis_NRHA_dt <- inner_join(NRHA_dt,atlantis_groups_dt,by="COMNAME") | ||
|
||
atlantis_NRHA_tows_dt <- unique(select(atlantis_NRHA_dt,DATE,Start_Lat,Start_Lon)) | ||
|
||
atlantis_NRHA_dt$SurfTEMP <- NA | ||
atlantis_NRHA_dt$BottTEMP <- NA | ||
atlantis_NRHA_dt$SurfSALIN <- NA | ||
atlantis_NRHA_dt$BottSALIN <- NA | ||
|
||
# Convert date columns to date object | ||
atlantis_NRHA_dt$DATE <- as.Date(atlantis_NRHA_dt$DATE) | ||
|
||
numRecords <- nrow(atlantis_NRHA_dt) | ||
|
||
for (n in 1:numRecords) { | ||
loc_tow <- c(atlantis_NRHA_dt$Start_Lat[n], atlantis_NRHA_dt$Start_Lon[n]) | ||
date_tow <- as.Date(atlantis_NRHA_dt$DATE[n]) | ||
|
||
min_date <- date_tow - TEMPORAL_BOUND | ||
max_date <- date_tow + TEMPORAL_BOUND | ||
|
||
min_lat <- atlantis_NRHA_dt$Start_Lat[n] - 0.2 | ||
max_lat <- atlantis_NRHA_dt$Start_Lat[n] + 0.2 | ||
min_lon <- atlantis_NRHA_dt$Start_Lon[n] - 0.2 | ||
max_lon <- atlantis_NRHA_dt$Start_Lon[n] + 0.2 | ||
|
||
surfbot_dt_filtered <- filter(surfbot_dt, Date >= min_date & Date <= max_date) | ||
surfbot_dt_filtered <- filter(surfbot_dt_filtered, Latitude >= min_lat & Latitude <= max_lat & Longitude >= min_lon & Longitude <= max_lon) | ||
print(n) | ||
numCasts <- nrow(surfbot_dt_filtered) | ||
|
||
if (numCasts > 0) { | ||
for (i in 1:numCasts) { | ||
loc_ctd <- c(surfbot_dt_filtered$Latitude[i], surfbot_dt_filtered$Longitude[i]) | ||
if (isWithinBounds(loc_tow,loc_ctd,SPATIAL_BOUND)) { | ||
print("Within Bounds") | ||
atlantis_NRHA_dt$SurfTEMP[n] <- surfbot_dt_filtered$Temperature[i] | ||
atlantis_NRHA_dt$SurfSALIN[n] <- surfbot_dt_filtered$Salinity[i] | ||
i <- i + 1 | ||
atlantis_NRHA_dt$BottTEMP[n] <- surfbot_dt_filtered$Temperature[i] | ||
atlantis_NRHA_dt$BottSALIN[n] <- surfbot_dt_filtered$Salinity[i] | ||
} else { | ||
i <- i + 1 | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
# The data includes a lot of 0's in the surface temperature data and some above 40 (104 F) | ||
# for the surface temperature data. This constricts the ranges to exclude 0's and temperatures above 40. | ||
|
||
atlantis_NRHA_dt$BottTEMP[(atlantis_NRHA_dt$BottTEMP == 0) | (atlantis_NRHA_dt$BottTEMP > 40)] <- NA | ||
atlantis_NRHA_dt$SurfTEMP[(atlantis_NRHA_dt$SurfTEMP == 0) | (atlantis_NRHA_dt$SurfTEMP > 40)] <- NA | ||
|
||
atlantis_NRHA_summary_table <- group_by(atlantis_NRHA_dt,Code,SEASON) | ||
atlantis_NRHA_summary_table_SEASON <- summarise(atlantis_NRHA_summary_table, min_bottom_temp = min(BottTEMP, na.rm=T), max_bottom_temp = max(BottTEMP, na.rm=T), | ||
min_surface_temp = min(SurfTEMP,na.rm=T), max_surface_temp = max(SurfTEMP,na.rm=T), | ||
min_bottom_sal = min(BottSALIN,na.rm=T), max_bottom_sal = max(BottSALIN,na.rm=T), | ||
min_surface_sal = min(SurfSALIN,na.rm=T), max_surface_sal = max(SurfSALIN,na.rm=T)) | ||
|
||
|
||
atlantis_NRHA_summary_table_SPECIES <- group_by(atlantis_NRHA_dt,Code) | ||
atlantis_NRHA_summary_table_SPECIES <- summarise(atlantis_NRHA_summary_table_SPECIES, min_bottom_temp = min(BottTEMP, na.rm=T), max_bottom_temp = max(BottTEMP, na.rm=T), | ||
min_surface_temp = min(SurfTEMP,na.rm=T), max_surface_temp = max(SurfTEMP,na.rm=T), | ||
min_bottom_sal = min(BottSALIN,na.rm=T), max_bottom_sal = max(BottSALIN,na.rm=T), | ||
min_surface_sal = min(SurfSALIN,na.rm=T), max_surface_sal = max(SurfSALIN,na.rm=T)) | ||
|
||
# Removes infinity values from the outputs and sets to NA | ||
atlantis_NRHA_summary_table_SEASON$min_bottom_sal[(atlantis_NRHA_summary_table_SEASON$min_bottom_sal == 'Inf') | (atlantis_NRHA_summary_table_SEASON$min_bottom_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SEASON$max_bottom_sal[(atlantis_NRHA_summary_table_SEASON$max_bottom_sal == 'Inf') | (atlantis_NRHA_summary_table_SEASON$max_bottom_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SEASON$min_surface_sal[(atlantis_NRHA_summary_table_SEASON$min_surface_sal == 'Inf') | (atlantis_NRHA_summary_table_SEASON$min_surface_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SEASON$max_surface_sal[(atlantis_NRHA_summary_table_SEASON$max_surface_sal == 'Inf') | (atlantis_NRHA_summary_table_SEASON$max_surface_sal == '-Inf')] <- 'NA' | ||
|
||
atlantis_NRHA_summary_table_SPECIES$min_bottom_sal[(atlantis_NRHA_summary_table_SPECIES$min_bottom_sal == 'Inf') | (atlantis_NRHA_summary_table_SPECIES$min_bottom_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SPECIES$max_bottom_sal[(atlantis_NRHA_summary_table_SPECIES$max_bottom_sal == 'Inf') | (atlantis_NRHA_summary_table_SPECIES$max_bottom_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SPECIES$min_surface_sal[(atlantis_NRHA_summary_table_SPECIES$min_surface_sal == 'Inf') | (atlantis_NRHA_summary_table_SPECIES$min_surface_sal == '-Inf')] <- 'NA' | ||
atlantis_NRHA_summary_table_SPECIES$max_surface_sal[(atlantis_NRHA_summary_table_SPECIES$max_surface_sal == 'Inf') | (atlantis_NRHA_summary_table_SPECIES$max_surface_sal == '-Inf')] <- 'NA' | ||
|
||
|
||
write.csv(atlantis_NRHA_summary_table_SEASON,here("thresholds","seasonal_thresholds_NRHA_ecomon_t7_d1.csv"),row.names=FALSE) | ||
write.csv(atlantis_NRHA_summary_table_SPECIES,here("thresholds","group_thresholds_NRHA_ecomon_t7_d1.csv"),row.names=FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"Code","min_bottom_temp","max_bottom_temp","min_surface_temp","max_surface_temp","min_bottom_sal","max_bottom_sal","min_surface_sal","max_surface_sal" | ||
"BLF",5.78,28.08,5.94,27.05,"-1e+10","36.447","-1e+10","36.389" | ||
"BSB",3.15,28.8,3.25,27.53,"-1e+10","36.43","-1e+10","36.404" | ||
"BUT",2.53,29.23,3.8,27.5,"-1e+10","36.578","-1e+10","36.509" | ||
"COD",0.88,23.08,1.35,17.89,"-1e+10","34.085","-1e+10","35.5" | ||
"DOG",1.21,27.66,2.09,22.91,"-1e+10","36.578","-1e+10","36.255" | ||
"DRM",4.54,29.04,4.15,28.33,"-1e+10","36.578","-1e+10","36.455" | ||
"FDE",0.88,25.9,1.27,26.6,"-1e+10","36.031","-1e+10","36.168" | ||
"HAD",1.17,27.59,2.69,18.58,"-1e+10","36.089","-1e+10","35.785" | ||
"HAL",1.17,16.27,2.55,13.61,"-1e+10","33.64","31.663","35.001" | ||
"HER",0.88,25.16,1.23,21.233,"-1e+10","35.393","-1e+10","35.645" | ||
"LSK",0.88,28.36,0.32,23.45,"-1e+10","36.114","-1e+10","35.894" | ||
"MAK",1.21,23.42,2.48,22.53,"-1e+10","36.031","-1e+10","35.838" | ||
"OHK",3.87,29.21,4.63,15.59,"-1e+10","36.579","-1e+10","35.956" | ||
"OPT",1.3,27.59,1.27,19.85,"-1e+10","35.321","-1e+10","35.688" | ||
"PLA",1.21,22.04,1.35,17.174,"-1e+10","34.176","30.544","35.56" | ||
"POL",1.21,22.84,2.18,17.14,"-1e+10","35.26","-1e+10","35.512" | ||
"QHG",6.07,18.7199,3.57,13.05,"30.521","33.751","30.559","34.185" | ||
"RED",1.68,22.29,2.34,14.72,"-1e+10","34.783","31.43","35.58" | ||
"RHK",1.21,27.59,1.71,22.0707,"-1e+10","36.466","-1e+10","36.312" | ||
"SAL",Inf,-Inf,Inf,-Inf,"NA","NA","NA","NA" | ||
"SCU",4.25,29.23,4.12,28.33,"-1e+10","36.478","-1e+10","36.5" | ||
"SDF",6.05,22.92,5.33,14.08,"20.77","34.645","24.49","35.505" | ||
"SHK",1.21,29.21,1.74,24.46,"-1e+10","36.578","-1e+10","36.2" | ||
"SK",1.17,29.76,2.18,27.5,"-1e+10","36.579","-1e+10","36.5" | ||
"SUF",1.55,29.4,1.74,28.22,"-1e+10","36.558","-1e+10","36.554" | ||
"TAU",2.89,24.94985,2.84,23.03,"-1e+10","33.582","-1e+10","33.818" | ||
"TYL",6.42,28.51,7.95,17.95,"-1e+10","36.407","33.118","36.359" | ||
"WHK",1.64,26.68,2.92,18.01,"-1e+10","36.409","29.206","35.845" | ||
"WIF",0.88,24.47,0.32,23.12,"-1e+10","35.209","-1e+10","35.187" | ||
"WPF",0.88,28.58,0.32,26.7,"-1e+10","36.089","-1e+10","35.587" | ||
"WSK",0.88,23.77,0.32,21.88,"-1e+10","36.089","-1e+10","35.764" | ||
"WTF",1.55,27.17,2.09,18.33,"-1e+10","36.409","-1e+10","35.894" | ||
"YTF",1.17,25.21,0.32,20.02,"-1e+10","35.772","-1e+10","35.645" |
Oops, something went wrong.