NOAA-EDAB / survdat

https://noaa-edab.github.io/survdat/
https://noaa-edab.github.io/survdat/
Other
2 stars 1 forks source link

New clams survey strata #59

Open Laurels1 opened 7 months ago

Laurels1 commented 7 months ago

Code from Dan Hennen: The clams survey has new strata after 2016 and are now divided into the 2 assessment regions for the purposes of meat weight and other biological parameter calculations. The areas are south (strata 1-6) and north (strata 7-12). All of the old regions except GBK would be south (see the one line R function below). Below is a translation function in R that maps the old strata to the new strata that needs to be updated in survdat:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

getRegNew=function(strata) ifelse(strata%in%c("1S","2S","3S","4S","5S","6S","1Q","2Q","3Q","4Q","5Q","6Q"),"South","GBK")

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Convert from old strata to new strata - requires some additional arguments - see bleow:

StratumConvert=function(dt1,svspp=403,Conv=T){

dt1 is a data.frame that has at least the columns "Strata2" (Strata with the 6 and 0 removed), "Lat", "Lon", "Depth", "CRUISE6"

svspp is the species code for surfclams (403) or quahogs (409)

stratum2=dt1$Strata2 #Need to make sure we don't change the strata %in% 2018; stratum=paste(stratum2) lat=dt1$Lat lon=dt1$Lon depth=na.replace(dt1$Depth) cruise6=dt1$CRUISE6

CONVERT LATITUDE & LONGITUDE TO DECIMAL DEGREES;

-- latitude first;

if(Conv){ degrees=floor(lat/100); minutes=(lat-degrees*100)/60; lat=degrees+minutes;

-- longitude too;

degrees=floor(lon/100);
minutes=(lon-degrees*100)/60;
lon=degrees+minutes;
lon=-1*lon

}

The formula for determ%in%%in%g if a po%in%t is one side or the other of a line is: ;

d=(lon-x[1])(y[2]-y[1])-(lat-y[1])(x[2]-x[1]) ;

for(i in 1:nrow(dt1)) { if(stratum[i] %in% c('47') ) { #Need to determine the split of stratum[i] 47; if( ( (lon[i]-69.23)(41-40)-(lat[i]-40)(69.03-69.23) ) > 0 ) { stratum[i] = '471'; } else { stratum[i] = '472'} }

if(stratum[i] %in% c('73') ) { #Need to determine the split of stratum[i] 73;
  if( ( (lon[i]-66.8)*(41.9-41.35)-(lat[i]-41.35)*(67.5-66.8) ) > 0) { stratum[i] = '73';
  } else {  stratum[i] = '74'}
}

#The Hudson canyon quahog split is complicated!;
#This is a line along the bottom of Hudson Canyon;
if(svspp %in% c(409) & stratum[i] %in% c('25', '26') & lat[i] >= 39.3 & lat[i]<= 40.2 ) { #Need to determine the split of strata 26 27 28;
  if( ( (lon[i]-72)*(40.2-39.3)-(lat[i]-39.3)*(73.75-72) ) < 0) { #above the line;
    if (stratum[i] %in% c('26')) { stratum[i] = '30'
    } else { if(stratum[i] %in% c('25')) { stratum[i] = '29'} }
  }
}
#This is the same line along the bottom of Hudson Canyon;
if(svspp %in% c(409) & stratum[i] %in% c( '31', '32') ) { #Need to determine the split of strata 31 32;
  if( ( (lon[i]-72)*(40.2-39.3)-(lat[i]-39.3)*(73.75-72) ) < 0) { #below the line;
    if(stratum[i] %in% c('31')) { stratum[i] = '27'
    } else { if(stratum[i] %in% c('32')) { stratum[i] = '28'} }
  }
}
# This is a t%in%y line segment that is completely conta%in%ed %in% stratum[i] 25 & 26;
if(svspp %in% c(409) & stratum[i] %in% c('25', '26') & lat[i] >= 40.2 & lat[i]<= 40.25) { #Need to determine the split of stratum[i] 26;
  if( ( (lon[i]-73.75)*(40.25-40.2)-(lat[i]-40.25)*(73.775-73.75) ) < 0) { #right of the line;
    if(stratum[i] %in% c('25')) { stratum[i] = '29'
    } else { if(stratum[i] %in% c('26')) { stratum[i] = '30'} }
  }
}
# This is a short line segment that is completely conta%in%ed %in% stratum[i] 25 & 26;
if(svspp %in% c(409) & stratum[i] %in% c('25', '26') & lat[i] >= 40.25 & lat[i]<= 40.5) { #Need to determine the split of stratum[i] 26;
  if( ( (lon[i]-73.775)*(40.5-40.25)-(lat[i]-40.25)*(73.825-73.775) ) < 0) { #right of the line;
    if(stratum[i] %in% c('25')) { stratum[i] = '29'
    } else { if(stratum[i] %in% c('26')) { stratum[i] = '30'} }
  }
}

#Finally we have to split the southernmost big strata for oq only;
if(svspp %in% c(409) & stratum[i] %in% c('17') ) { #Need to determine the split of strata 17;
  if( ( (lon[i]-74.29)*(38.6-38.94)-(lat[i]-38.94)*(74.57-74.29) ) < 0) { stratum[i] = '0'} #left of the line;
}
if(svspp %in% c(409) & stratum[i] %in% c('13') & lat[i] >= 38.41) { #Need to determine the split of stratum[i] 13;
  if( ( (lon[i]-74.57)*(38.41-38.6)-(lat[i]-38.6)*(74.64-74.57) ) < 0) { stratum[i] = '0'} #left of the line;
}
if(svspp %in% c(409) & stratum[i] %in% c('13') & lat[i] >= 38.15 & lat[i]<= 38.41) { #Need to determine the split of stratum[i] 13;
  if( ( (lon[i]-74.64)*(38.15-38.41)-(lat[i]-38.41)*(74.67-74.64) ) < 0) { stratum[i] = '0'} #left of the line;
}
if(svspp %in% c(409) & stratum[i] %in% c('13') & lat[i]<= 38.15) { #Need to determine the split of stratum[i] 13;
  if( ( (lon[i]-74.67)*(37.83-38.15)-(lat[i]-38.15)*(74.87-74.67) ) < 0) { stratum[i] = '0'} #left of the line;
}

#Now we can assign the new strata by the old strata;
if (svspp %in% c(403) & (as.numeric(cruise6[i])/100)<2018) { #Surfclam
  if (stratum[i] %in% c('05','09','81') ) { stratum2[i] = "1S"}
  if (stratum[i] %in% c('84', '85', '86', '87')) { stratum2[i] = "2S"}  #NJ DMV %in%shore
  if (stratum[i] %in% c('13', '17', '21', '25', '29')) { stratum2[i] = "3S"}   #DMV, NJ & LI mid depth
  if (stratum[i] %in% c('10', '14', '18', '22')) { stratum2[i] = "4S"}   #NJ, DMV & LI off shore
  if (stratum[i] %in% c('88', '89', '90', '91', '92', '93')) { stratum2[i] = "5S"}   #LI & NJ %in%shore
  if (stratum[i] %in% c('45', '46', '95', '96')) { stratum2[i] = "6S"}  #SNE
  #GBK-surfs
  if (stratum[i] %in% c('53', '54')) { stratum2[i] = "7S" }  #NW deep
  if (stratum[i] %in% c('67', '69', '70')) { stratum2[i] = "8S" }  #West shallow
  if (stratum[i] %in% c('57', '58', '59', '60')) { stratum2[i] = "9S" }  #S deep
  if (stratum[i] %in% c('65', '66')) { stratum2[i] = "10S" }  #NE deep
  if (stratum[i] %in% c('68', '72', '73')) { stratum2[i] = "11S" }  #middle shallow
  if (stratum[i] %in% c('71', '74')) { stratum2[i] = "12S" }  #middle east shallow
  if (!stratum[i] %in% c('05','09','81','84', '85', '86', '87','13', '17', '21', '25', '29'
                         ,'10', '14', '18', '22','88', '89', '90', '91', '92', '93','45', '46', '95', '96'
                         ,'53', '54','67', '69', '70','57', '58', '59', '60','65', '66','68', '72', '73'
                         ,'71', '74')) {stratum2[i] = '0'}
}

if (svspp %in% c(409) & (as.numeric(cruise6[i])/100)<2018) { #Quahog
  if (stratum[i] %in% c('10', '11', '12', '14', '15', '16', '18', '19', '20')) { stratum2[i] = "1Q" }  #DMV deep
  if (stratum[i] %in% c('13', '17', '21', '22', '25', '26')) { stratum2[i] = "2Q"}   #NJ mid depth
  if (stratum[i] %in% c('23', '24', '27', '28', '31', '32', '35', '36')) { stratum2[i] = "3Q" }  #LI & NJ deep
  if (stratum[i] %in% c('29', '30', '33', '34')) { stratum2[i] = "4Q" }  #NJ & LI mid
  if (stratum[i] %in% c('92', '93', '94', '95', '37', '41')) { stratum2[i] = "5Q"  } #DMV/SVA
  if (stratum[i] %in% c('38', '39', '40', '46', '471', '48')) { stratum2[i] = "6Q" }  #NJ DMV %in%shore

  #GBK-Quahogs
  if (stratum[i] %in% c('53','54','55','56','472','56')) { stratum2[i] = "7Q"  } #West side deep
  if (stratum[i] %in% c('70')) { stratum2[i] = "8Q" }  #middle shallow
  if (stratum[i] %in% c('57','58','59','60')) { stratum2[i] = "9Q" }  #S deep
  if (stratum[i] %in% c('65','66')) { stratum2[i] = "10Q" }  #NE deep
  if (stratum[i] %in% c('74')) { stratum2[i] = "11Q" } #East side mid-depth
  if (stratum[i] %in% c('61','62')) { stratum2[i] = "12Q"  } #SE deep
  if(!stratum[i] %in% c('10', '11', '12', '14', '15', '16', '18', '19', '20','13', '17', '21', '22', '25', '26'
                        ,'23', '24', '27', '28', '31', '32', '35', '36', '29', '30', '33', '34','92', '93'
                        , '94', '95', '37', '41','38', '39', '40', '46', '471', '48', '53','54','55','56','472','56'
                        ,'70', '57','58','59','60','65','66','74','61','62') ) { stratum2[i] = '0'}
}
if(depth[i]>80) { stratum2[i] = '0'}

} return(stratum2)

}