Skip to content

Commit b33c47f

Browse files
Merge pull request #505 from StoXProject/develop
Develop
2 parents 0e1c903 + 3899be6 commit b33c47f

11 files changed

Lines changed: 83 additions & 12 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: RstoxData
2-
Version: 2.2.1-9004
3-
Date: 2026-05-04
2+
Version: 2.2.1-9005
3+
Date: 2026-05-21
44
Title: Tools to Read and Manipulate Fisheries Data
55
Authors@R: c(
66
person(given = "Arne Johannes",

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# RstoxData v2.2.1-9005 (2026-05-21)
2+
* Fixed bug in TranslateICESAcoustic() where translation of the tables Calibration, DataAcquisition, DataProcessing did not work due to error in the keys generated with expandICESKeysWithPrefix().
3+
* Changed ICESBiotic() to NOT set NA to 0 for SubsampleWeight in the Catch table, since the ICES acoustic database only accepts NA or a positive number as of the beginning of 2026.
4+
* In ICESBiotic() changed BioticData_NMDToICESBioticOne() to set SubsamplingFactor to catchweight / lengthsampleweight if both catchcount and lengthsamplecount are missing.
5+
6+
17
# RstoxData v2.2.1-9004 (2026-05-05)
28
* Fixed bug in StoxAcoustic where BeamKey was corrupted for data read by ReadAcoustic() from file in the ICESAcoustic format (LU25/LUF26 from LSSS). This resulted in NASC data being mixed between frequencies in the output from StoxAcoustic. The fix was to set sort = FALSE when merging in the Instrument table.
39
* Fixed bug where TranslateICESAcoustic() did not manage to translate variables in the tables Instrument, Calibration, DataAcquisition and DataProcessing.

R/Filter.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ processFilter <- function(filters) {
375375
filterOneTable <- function(tableName, filter, data, treeStruct, propagateDownwards = TRUE, propagateUpwards = FALSE) {
376376

377377
# Special operators defined for filter operations. These are also supported in RstoxFramework:
378+
# No longer needed since %notin% is now in the R base package, but still needed for oldreleases. We need to change this not in R 4.6 but in 4.7:
378379
`%notin%` <- Negate(`%in%`)
380+
# Why did we introduce this (in 2021)? Could it be for users who do not understand !=?
379381
`%notequal%` <- function(x, table) is.na(x) | x %notin% table
380382

381383
# Declare the output

R/Read.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ check_landing_duplicates <- function(LandingData, warn=T, fix=F){
5454
#'
5555
#' @param FileNames The paths of the biotic files.
5656
#'
57+
#' @details
58+
#' The file is read using the ICESBiotic XSD defined by ICES acoustic database (https://www.ices.dk/data/data-portals/Pages/acoustic.aspx), with additional information about headers defined by the internal function \code{icesAcousticPreprocess}.
59+
#'
60+
#' One particular case is when headers (e.g. LocalID) are stored as NA in the file. This results in the string "NA" and not the missing value NA. To read fields as NA, the field must be left out in the file.
61+
#'
5762
#' @return
5863
#' An object of StoX data type BioticData: A list of a list of data.tables of the different levels of the input biotic files.
5964
#'
@@ -96,6 +101,11 @@ ReadBiotic <- function(FileNames = character()) {
96101
#'
97102
#' @param FileNames The paths of the acoustic files.
98103
#'
104+
#' @details
105+
#' The file is read using the ICESAcoustic XSD defined by ICES acoustic database (https://www.ices.dk/data/data-portals/Pages/acoustic.aspx), with additional information about headers defined by the internal function \code{icesAcousticPreprocess}.
106+
#'
107+
#' One particular case is when headers (e.g. LocalID) are stored as NA in the file. This results in the string "NA" and not the missing value NA. To read fields as NA, the field must be left out in the file.
108+
#'
99109
#' @return
100110
#' An object of StoX data type AcousticData: A list of a list of data.tables of the different levels of the input acoustic files.
101111
#'

R/StoxExport.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,17 @@ BioticData_NMDToICESBioticOne <- function(
742742
SpeciesCategoryNumber = catchcount,
743743
WeightUnit = "kg", # Always kg in NMDBiotic (see http://www.imr.no/formats/nmdbiotic/)
744744
SpeciesCategoryWeight = catchweight,
745+
# At IMR we do not split catches by sex, but record sex at the individual level:
745746
SpeciesSex = NA_character_,
746747

747-
#SubsampledNumber = lengthsamplecount,
748+
# Samples:
748749
SubsampledNumber = lengthsamplecount,
749-
SubsamplingFactor = catchcount / lengthsamplecount,
750+
# Prioritize count before weight, since before only catchcount / lengthsamplecount was used here:
751+
#SubsamplingFactor = catchcount / lengthsamplecount,
752+
SubsamplingFactor = ifelse(!is.na(lengthsamplecount) | is.na(catchcount), catchcount / lengthsamplecount, catchweight / lengthsampleweight),
753+
754+
755+
ifelse(is.na(lengthsamplecount) | is.na(catchcount), catchweight / lengthsampleweight, catchcount / lengthsamplecount),
750756
#SubsamplingFactor = ifelse(is.na(lengthsampleweight), 1, catchcount / lengthsamplecount),
751757
SubsampleWeight = lengthsampleweight,
752758
#SubsampleWeight = ifelse(is.na(lengthsampleweight), catchweight, lengthsampleweight),
@@ -763,8 +769,9 @@ BioticData_NMDToICESBioticOne <- function(
763769
Catch[is.na(SpeciesCategoryNumber) & is.na(SpeciesCategoryWeight) & !is.na(SubsampledNumber), SpeciesCategoryNumber := SubsampledNumber]
764770
Catch[is.na(SpeciesCategoryNumber) & is.na(SpeciesCategoryWeight) & !is.na(SubsampleWeight), SpeciesCategoryWeight := SubsampleWeight]
765771

766-
# NA means that nothing is subsampled
767-
Catch[!is.na(SpeciesCategoryWeight) & is.na(SubsampleWeight), SubsampleWeight := 0]
772+
# This violated the requirement of the ICES Acoustic database that SubsampleWeight cannot be 0 (only missing or positive):
773+
# # NA means that nothing is subsampled
774+
# Catch[!is.na(SpeciesCategoryWeight) & is.na(SubsampleWeight), SubsampleWeight := 0]
768775

769776

770777
# Combine required tables for the Biology level
@@ -836,7 +843,6 @@ BioticData_NMDToICESBioticOne <- function(
836843

837844

838845

839-
840846
#' Write ICESBiotic to CSV fille
841847
#'
842848
#' Writes \code{\link{ICESBioticData}} to a csv file for each input acoustic file used to create the \code{\link{ICESBioticData}}

R/Utilities.R

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,17 +1210,54 @@ asIntegerAfterRound <- function(x, prec = sqrt(.Machine$double.eps)) {
12101210

12111211
expandICESKeysWithPrefix <- function(ICESKeys) {
12121212

1213+
12131214
# Declare the output:
12141215
ICESKeysOut <- ICESKeys
12151216

1216-
# Loop through the tables in reversed order, and paste the table name to the keys, overwriting as we move to the higher tables:
1217-
reversedTableOrder <- rev(names(ICESKeys))
1218-
for(tableName1 in reversedTableOrder) {
1219-
for(tableName2 in reversedTableOrder) {
1220-
ICESKeysOut[[tableName1]][ICESKeys[[tableName1]] %in% ICESKeys[[tableName2]]] <- paste0(tableName2, ICESKeys[[tableName1]][ICESKeys[[tableName1]] %in% ICESKeys[[tableName2]]])
1217+
# We use a translation table to do the renaming of the keys:
1218+
translation <- NULL
1219+
1220+
# Loop through the tables:
1221+
tableNames <- names(ICESKeys)
1222+
for(tableName in tableNames) {
1223+
1224+
# If the table only contains one key, prefix with the table name and overwrite the translation table:
1225+
if(length(ICESKeys[[tableName]]) == 1) {
1226+
1227+
# Set the key directly, without use of the translation table here:
1228+
newName <- paste0(tableName, ICESKeys[[tableName]])
1229+
ICESKeysOut[[tableName]] <- newName
1230+
1231+
# Overwrite the translation table:
1232+
translation <- data.table(
1233+
from = ICESKeys[[tableName]],
1234+
to = newName
1235+
)
1236+
}
1237+
# For other tables add the table name prefixed keys to the translation table and then perform the actual translation:
1238+
else {
1239+
1240+
# Identify the keys that are not already fixed in the translation table:
1241+
areNotAlreadyPrepended <- ! ICESKeys[[tableName]] %in% translation$from
1242+
notAlreadyPrepended <- ICESKeys[[tableName]][areNotAlreadyPrepended]
1243+
newName <- paste0(tableName, notAlreadyPrepended)
1244+
1245+
# Add to the translation table:
1246+
translation <- rbind(
1247+
translation,
1248+
data.table(
1249+
from = ICESKeys[[tableName]][areNotAlreadyPrepended],
1250+
to = newName
1251+
)
1252+
)
1253+
1254+
# Do the translation:
1255+
at <- match(ICESKeys[[tableName]], translation$from)
1256+
ICESKeysOut[[tableName]] <- translation$to[at]
12211257
}
12221258
}
12231259

1260+
12241261
return(ICESKeysOut)
12251262
}
12261263

data/stoxBioticObject.rda

-73 Bytes
Binary file not shown.

data/xsdObjects.rda

-9 Bytes
Binary file not shown.

inst/extdata/functionArguments.rds

179 Bytes
Binary file not shown.

man/ReadAcoustic.Rd

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)