Skip to content

Commit

Permalink
Updating AFSC grids for EBS / NBS and adding Chukchi ... (#79)
Browse files Browse the repository at this point in the history
... h/t Jason Conner for these improvements!
  • Loading branch information
James-Thorson-NOAA authored Mar 17, 2022
1 parent bf73f79 commit 51c7713
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 12 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: FishStatsUtils
Type: Package
Title: Utilities (shared code and data) for FishStats spatio-temporal modeling toolbox
Version: 2.10.2
Date: 2021-11-08
Version: 2.11.0
Date: 2022-03-17
Authors@R:
c(person(given = "James",
family = "Thorson",
Expand Down Expand Up @@ -57,6 +57,6 @@ License: GPL-3
LazyData: yes
BuildVignettes: yes
Encoding: UTF-8
RoxygenNote: 7.1.1
RoxygenNote: 7.1.2
URL: http://github.com/james-thorson-NOAA/FishStatsUtils
BugReports: http://github.com/james-thorson-NOAA/FishStatsUtils/issues
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export(Prepare_AI_Extrapolation_Data_Fn)
export(Prepare_BC_Coast_Extrapolation_Data_Fn)
export(Prepare_BFISH_MHI_Extrapolation_Data_Fn)
export(Prepare_BSslope_Extrapolation_Data_Fn)
export(Prepare_Chukchi_Extrapolation_Data_Fn)
export(Prepare_EBS_Extrapolation_Data_Fn)
export(Prepare_GOA_Extrapolation_Data_Fn)
export(Prepare_GOM_Extrapolation_Data_Fn)
Expand Down
44 changes: 41 additions & 3 deletions R/Prepare_XXXX_Extrapolation_Data_Fn.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function( strata.limits=NULL, projargs=NA, zone=NA, flip_around_dateline=TRUE, .

# Extra junk
Data_Extrap = cbind( Data_Extrap, 'Include'=1)
Data_Extrap[,c('E_km','N_km')] = tmpUTM[,c('X','Y')]
Data_Extrap = cbind( Data_Extrap, "E_km"=tmpUTM[,'X'], "N_km"=tmpUTM[,'Y'] )

# Return
Return = list( "a_el"=a_el, "Data_Extrap"=Data_Extrap, "zone"=attr(tmpUTM,"zone"), "projargs"=attr(tmpUTM,"projargs"),
Expand Down Expand Up @@ -325,7 +325,7 @@ function( strata.limits=NULL, projargs=NA, zone=NA, flip_around_dateline=FALSE,
Area_km2_x = Data_Extrap[,'Area_in_survey_km2']

# Augment with strata for each extrapolation cell
Tmp = cbind("BEST_DEPTH_M"=0, "BEST_LAT_DD"=Data_Extrap[,'Lat'], "propInSurvey"=1)
Tmp = cbind("BEST_DEPTH_M"=0, "BEST_LAT_DD"=Data_Extrap[,'Lat'], "BEST_LON_DD"=Data_Extrap[,'Lon'], "propInSurvey"=1)
a_el = as.data.frame(matrix(NA, nrow=nrow(Data_Extrap), ncol=nrow(strata.limits), dimnames=list(NULL,strata.limits[,'STRATA'])))
for(l in 1:ncol(a_el)){
a_el[,l] = apply(Tmp, MARGIN=1, FUN=match_strata_fn, strata_dataframe=strata.limits[l,,drop=FALSE])
Expand All @@ -338,7 +338,45 @@ function( strata.limits=NULL, projargs=NA, zone=NA, flip_around_dateline=FALSE,

# Extra junk
Data_Extrap = cbind( Data_Extrap, 'Include'=1)
Data_Extrap[,c('E_km','N_km')] = tmpUTM[,c('X','Y')]
Data_Extrap = cbind( Data_Extrap, "E_km"=tmpUTM[,'X'], "N_km"=tmpUTM[,'Y'] )

# Return
Return = list( "a_el"=a_el, "Data_Extrap"=Data_Extrap, "zone"=attr(tmpUTM,"zone"), "projargs"=attr(tmpUTM,"projargs"),
"flip_around_dateline"=flip_around_dateline, "Area_km2_x"=Area_km2_x)
return( Return )
}

#' @export
Prepare_Chukchi_Extrapolation_Data_Fn <-
function( strata.limits=NULL, projargs=NA, zone=NA, flip_around_dateline=FALSE, ... ){
# Infer strata
if( is.null(strata.limits)){
strata.limits = data.frame('STRATA'="All_areas")
}
message("Using strata ", strata.limits)

# Read extrapolation data
utils::data( chukchi_sea_grid, package="FishStatsUtils" )
Data_Extrap <- chukchi_sea_grid

# Survey areas
Area_km2_x = Data_Extrap[,'Area_in_survey_km2']

# Augment with strata for each extrapolation cell
Tmp = cbind("BEST_DEPTH_M"=0, "BEST_LAT_DD"=Data_Extrap[,'Lat'], "BEST_LON_DD"=Data_Extrap[,'Lon'], "propInSurvey"=1)
a_el = as.data.frame(matrix(NA, nrow=nrow(Data_Extrap), ncol=nrow(strata.limits), dimnames=list(NULL,strata.limits[,'STRATA'])))
for(l in 1:ncol(a_el)){
a_el[,l] = apply(Tmp, MARGIN=1, FUN=match_strata_fn, strata_dataframe=strata.limits[l,,drop=FALSE])
a_el[,l] = ifelse( is.na(a_el[,l]), 0, Area_km2_x)
}
#
# Convert extrapolation-data to an Eastings-Northings coordinate system
#tmpUTM = Convert_LL_to_UTM_Fn( Lon=Data_Extrap[,'Lon'], Lat=Data_Extrap[,'Lat'], zone=zone, flip_around_dateline=flip_around_dateline) #$
tmpUTM = project_coordinates( X=Data_Extrap[,'Lon'], Y=Data_Extrap[,'Lat'], projargs=projargs, zone=zone, flip_around_dateline=flip_around_dateline) #$

# Extra junk
Data_Extrap = cbind( Data_Extrap, 'Include'=1)
Data_Extrap = cbind( Data_Extrap, "E_km"=tmpUTM[,'X'], "N_km"=tmpUTM[,'Y'] )

# Return
Return = list( "a_el"=a_el, "Data_Extrap"=Data_Extrap, "zone"=attr(tmpUTM,"zone"), "projargs"=attr(tmpUTM,"projargs"),
Expand Down
9 changes: 7 additions & 2 deletions R/make_extrapolation_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
#' \item{\code{"california_current"}}{The spatial fooprint of the bottom trawl surveys operated by AFSC/NWFSC, including the AFSC triennial from 1977-2004 and the NWFSC combined shelf-slope survey from 2003 onward (as identified by B. Feist and C. Whitmire); specify subsets via \code{surveyname}}
#' \item{\code{"west_coast_hook_and_line"}}{The spatial fooprint of the fixed-station hook-and-line survey in the California Bight operated by NWFSC (as identified by J. Harms)}
#' \item{\code{"british_columbia"}}{The spatial fooprint of the various stratified-random bottom trawl surveys operated by PBS (as identified by N. Olsen); see \code{strata_to_use} for further specification}
#' \item{\code{"eastern_bering_sea"}}{The spatial fooprint of the fixed station bottom trawl survey operated by AFSC in the eastern Bering Sea (as identified by A. Greig)}
#' \item{\code{"northern_bering_sea"}}{The spatial fooprint of the fixed station bottom trawl survey operated by AFSC in the northern Bering Sea (as identified by J. Conner)}
#' \item{\code{"eastern_bering_sea"}}{The spatial fooprint of the fixed station bottom trawl survey operated by AFSC in the eastern Bering Sea (as identified by J. Conner)}
#' \item{\code{"northern_bering_sea"}}{The spatial fooprint of the systematic bottom trawl survey operated by AFSC in the northern Bering Sea (as identified by J. Conner)}
#' \item{\code{"bering_sea_slope"}}{The spatial fooprint of the stratified random bottom trawl survey operated by AFSC in the Bering Sea slope (as identified by A. Greig)}
#' \item{\code{"chukchi_sea"}}{The spatial fooprint of the systematic bottom trawl survey operated by AFSC in the Bering Sea slope (as identified by J. Conner)}
#' \item{\code{"st_matthews_island"}}{The spatial fooprint of the survey area defined around St. Matthews Island, representing regular and corner stations from the eastern Bering Sea bottom trawl survey}
#' \item{\code{"aleutian_islands"}}{The spatial fooprint of the stratified random bottom trawl survey operated by AFSC in the Aleutian Islands (as identified by A. Greig)}
#' \item{\code{"gulf_of_alaska"}}{The spatial fooprint of the stratified random bottom trawl survey operated by AFSC in the Gulf of Alaska and containing shallow and deep stations, where the latter are not consistently sampled in later years (as identified by A. Greig)}
Expand Down Expand Up @@ -145,6 +146,10 @@ make_extrapolation_info = function( Region,
if(missing(flip_around_dateline)) flip_around_dateline = FALSE
Extrapolation_List = Prepare_BSslope_Extrapolation_Data_Fn( strata.limits=strata.limits, projargs=projargs, zone=zone, flip_around_dateline=flip_around_dateline, ... )
}
if( tolower(Region[rI]) == "chukchi_sea" ){ #
if(missing(flip_around_dateline)) flip_around_dateline = FALSE
Extrapolation_List = Prepare_Chukchi_Extrapolation_Data_Fn( strata.limits=strata.limits, projargs=projargs, zone=zone, flip_around_dateline=flip_around_dateline, ... )
}
if( tolower(Region[rI]) %in% c("st_matthews_island","smi") ){ #
if(missing(flip_around_dateline)) flip_around_dateline = TRUE
Extrapolation_List = Prepare_SMI_Extrapolation_Data_Fn( strata.limits=strata.limits, projargs=projargs, zone=zone, flip_around_dateline=flip_around_dateline, ... )
Expand Down
Binary file added data/chukchi_sea_grid.rda
Binary file not shown.
Binary file modified data/eastern_bering_sea_grid.rda
Binary file not shown.
Binary file modified data/northern_bering_sea_grid.rda
Binary file not shown.
5 changes: 3 additions & 2 deletions man/make_extrapolation_info.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/make_settings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 51c7713

Please sign in to comment.