diff --git a/DESCRIPTION b/DESCRIPTION index ac8e5b24..4fa63c87 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: RstoxBase Version: 2.2.1 -Date: 2026-06-25 +Date: 2026-07-06 Title: Base StoX Functions Authors@R: c( person(given = "Arne Johannes", @@ -47,7 +47,7 @@ Imports: jsonlite (>= 1.6), lwgeom (>= 0.2-0), maps (>= 0.2-0), - RstoxData (>= 2.2.0), + RstoxData (>= 2.2.1), sf (>= 0.9.0), stringi (>= 1.4.0), units (>= 0.7), diff --git a/NEWS.md b/NEWS.md index a469b8c7..fea0d02b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# RstoxBase v2.2.1 (2026-07-04) +* Fixed bug in SuperIndividuals() due to SampleWeight or SampleNumber = 0. This is now OK if there are no individuals with length in the sample. + + # RstoxBase v2.2.1-9006 (2026-06-22) * Reduced processing time for the functions MeanNASC, AcousticDensity, MeanDensity and Abundance to approximately 30% for a StoX project with large acoustic data (regular survey with 10 m channels and 0.1 nautical mile log distance). This can lead to approximately 50 % reduction in Bootstrap time. diff --git a/R/Abundance.R b/R/Abundance.R index 6fbaa3a4..94d3b24d 100644 --- a/R/Abundance.R +++ b/R/Abundance.R @@ -372,6 +372,7 @@ SuperIndividuals <- function( SuperIndividualsData[, Abundance := Abundance * individualWeightFactor] # Test whether the sum of the Abundance is equal to that of the QuantityData. Note that if all SuperIndividualsData$Abundance and all QuantityData$Data$Abundance are NA, the totalAbundanceInSuperIndividualsData and totalAbundanceInQuantityData will be 0 due to the na.rm = TRUE. Before, testEqualTo1() was used here, but this returned NA for 0 / 0 = NaN, and the condition in the test failed. Thus the testEqual() is used instead: + totalAbundanceInSuperIndividualsData <- sum(SuperIndividualsData$Abundance, na.rm = TRUE) totalAbundanceInQuantityData <- sum(QuantityData$Data$Abundance, na.rm = TRUE) if(!testEqual(totalAbundanceInSuperIndividualsData, totalAbundanceInQuantityData)) { diff --git a/R/LengthDistribution.R b/R/LengthDistribution.R index e05976c1..69d2f4a6 100644 --- a/R/LengthDistribution.R +++ b/R/LengthDistribution.R @@ -152,14 +152,13 @@ LengthDistribution <- function( #LengthDistributionData <- addLayerProcessData(LengthDistributionData, dataType = "LengthDistributionData", layerProcessData = if(IncludeLayer) BioticLayer) ###################################################### - ####################################################### ##### 5. Aggregate multiple samples to each haul: ##### ####################################################### # Create a data table of different raising factors in the columns: raisingFactorTable <- data.frame( - Weight = LengthDistributionData$CatchFractionWeight / LengthDistributionData$SampleWeight, - Number = LengthDistributionData$CatchFractionNumber / LengthDistributionData$SampleNumber#, + Weight = ifelse(LengthDistributionData$SampleWeight == 0, NA, LengthDistributionData$CatchFractionWeight / LengthDistributionData$SampleWeight), + Number = ifelse(LengthDistributionData$SampleNumber == 0, NA, LengthDistributionData$CatchFractionNumber / LengthDistributionData$SampleNumber)#, #Percent = 1 ) @@ -177,6 +176,8 @@ LengthDistribution <- function( raisingFactorIndex <- apply(raisingFactorTable, 1, getIndexOfFirstNonNA, LengthDistributionType = LengthDistributionType) LengthDistributionData$raisingFactor <- raisingFactorTable[cbind(seq_along(raisingFactorIndex), raisingFactorIndex)] + + # Set raisingFactor to 1 if LengthDistributionType == "Percent" and only one sample: if(LengthDistributionType == "Percent") { LengthDistributionData[numberOfSubSamples == 1 & is.na(raisingFactor), raisingFactor := 1]