Skip to content

Commit

Permalink
Fixed issue with plotting with other column variables than 'Area' in …
Browse files Browse the repository at this point in the history
…PlotFisheriesOverviewSpatial (#147).
  • Loading branch information
Edvin Fuglebakk authored and Edvin Fuglebakk committed Dec 27, 2024
1 parent afd3ffe commit 83bad00
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Replaced DefinePSUSamplingParameters (processdata) with ComputePSUSamplingParameters (no processdata) and ReadPSUSamplingParameters (no processdata). This change breaks some pre-release projects (v. v1.3-9006). (#127)
* Replaced DefineIndividualSamplingParameters (processdata) with ComputeIndividualSamplingParameters (no processdata). This change breaks some pre-release projects (v. v1.3-9006).
* Added documentation for ECA convergence analsysis (#153)
* Fixed issue with running RunRecaModels with temporal resolution æmonth' (#144)
* Fixed issue with running RunRecaModels with temporal resolution 'month' (#144)
* Fixed issue with plotting with other column variables than 'Area' in PlotFisheriesOverviewSpatial (#147)
* Fixed naming of age groups in reports from analytical estimates (#145)
* Fixed documentation for handling NA age groups (#151)
* Fixed issue with using integer columns in landings as stratification column in ratio estimates (#133)
Expand Down
7 changes: 4 additions & 3 deletions R/StoxPlots.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,19 @@ PlotFisheriesOverviewSpatial <- function(ReportFdaLandingData, StratumPolygon, A
stop("Plot cannot be construceted for more than one grouping variable in 'ReportFdaLandingData'")
}

if (!all(ReportFdaLandingData$FisheriesLandings$Area %in% StratumPolygon$StratumName)){
groupvars <- ReportFdaLandingData$GroupingVariables$GroupingVariables
if (!all(ReportFdaLandingData$FisheriesLandings[[groupvars]] %in% StratumPolygon$StratumName)){
stop(paste("The provided polygons does not include all areas in ", ReportFdaLandingData$GroupingVariables$GroupingVariables[[1]]))
}

ftab <- ReportFdaLandingData$FisheriesLandings
groupvars <- ReportFdaLandingData$GroupingVariables$GroupingVariables[ReportFdaLandingData$GroupingVariables$GroupingVariables != "Area"]


sfPoly <- sf::st_as_sf(StratumPolygon)
sfPoly$area <- sf::st_area(sfPoly)

sfPoly <- merge(sfPoly, ReportFdaLandingData
$FisheriesLandings, by.y="Area", by.x="StratumName", all.x=T)
$FisheriesLandings, by.y=groupvars, by.x="StratumName", all.x=T)

sfPoly$CatchDensity <- sfPoly$LandedRoundWeight / as.numeric(sfPoly$area)
sfPoly$CatchDensity[sfPoly$CatchDensity==0] <- NA
Expand Down
8 changes: 8 additions & 0 deletions inst/tinytest/test-StoxPlots.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ expect_warning(RstoxFDA:::PlotPosteriorTraces(predictiondatafile, Nclust = 10),
StoxLandingFile <- system.file("testresources","StoxLandingData.rds", package="RstoxFDA")
StoxLandingData <- readRDS(StoxLandingFile)

areacodeconv <- RstoxFDA:::areaCodeConversionTable(RstoxFDA::mainareaFdir2018, RstoxFDA::ICESareas)
StoxLandingData$Landing$IcesArea <- RstoxFDA::convertCodes(StoxLandingData$Landing$Area, areacodeconv)

tab1 <- RstoxFDA::ReportFdaLandings(StoxLandingData, GroupingVariables = c("Gear", "CatchDate"), Unit = "kg")
tab2 <- RstoxFDA::ReportFdaLandings(StoxLandingData, GroupingVariables = c("Gear","Area", "CatchDate"), Unit = "ton")
RstoxFDA:::PlotFisheriesOverviewTemporal(tab1)
Expand All @@ -66,6 +69,11 @@ RstoxFDA:::PlotFisheriesOverviewTable(tab3)
RstoxFDA:::PlotFisheriesOverviewTable(tab2)


# test with ICES areas
tab4 <- RstoxFDA::ReportFdaLandings(StoxLandingData, GroupingVariables = c("IcesArea"), Unit = "kg")
RstoxFDA:::PlotFisheriesOverviewSpatial(tab4, RstoxFDA::ICESareas)
RstoxFDA:::PlotFisheriesOverviewSpatial(tab4, RstoxFDA::ICESareas, AreaLabels = T)

catchAtAgeFlat <- readRDS(system.file("testresources", "recaPredictionFlat.rds", package="RstoxFDA"))
catchAtAgeDecomp <- readRDS(system.file("testresources", "recaPredictionDecomp.rds", package="RstoxFDA"))

Expand Down

0 comments on commit 83bad00

Please sign in to comment.