Second-order plotting: draw bin averages at geometric bin centres (#382)#396
Open
gustavdelius wants to merge 1 commit into
Open
Second-order plotting: draw bin averages at geometric bin centres (#382)#396gustavdelius wants to merge 1 commit into
gustavdelius wants to merge 1 commit into
Conversation
Once a quantity is a finite-volume cell average N_j it no longer lives at the
left bin edge w_j but at the geometric bin centre w*_j = sqrt(w_j w_{j+1}) =
w_j sqrt(beta) (the log-midpoint, exact for the community spectrum w^-2).
Plotting it at the bin boundary mis-places it by half a bin.
This adds a `representation` tag ("point"/"average") to the
ArraySpeciesBySize and ArrayTimeBySpeciesBySize classes, threaded through the
constructors, subset/slice methods and the MizerSim rate path
(sim_size_rate / get_species_size_rate_from_sim). The central size-axis helpers
get_ArraySpeciesBySize_w() and the new get_ArrayTimeBySpeciesBySize_w() return
the geometric bin centres (new bin_midpoints() helper) for "average" arrays,
but only when the model uses second-order bin-averaging
(second_order_w[["bin_average"]]) -- so default plots, as.data.frame() output
and vdiffr snapshots are unchanged.
The bin-averaged sinks getPredMort/getFMort/getMort/getExtMort and the
reproductive investment getERepro tag themselves "average"; point-valued
quantities (encounter, growth) stay "point" and on the nodes. Everything
downstream (prepare_*_plot_data, as.data.frame, plot2) follows the central
helpers automatically.
plotSpectra/plotCDF build their own data frames and handle the w^power weight;
their centre placement is the separate #383. Snapshots gained only the new
benign `representation` attribute (accepted). Full suite: 2824 pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #377 — the rendering counterpart of the bin-averaging programme. Once a
quantity is a bin average, plotting it at the bin boundary is wrong.
The problem
All size-resolved plots route their x-locations through
get_ArraySpeciesBySize_w(),which returns the grid nodes
params@w/params@w_full— the left binedges. A bin average
N_j = (1/Δw_j)∫_{w_j}^{w_{j+1}} N dwdoes not live atthe boundary, so it is mis-placed by half a bin.
Where averaged values belong
The geometric bin centre
w*_j = sqrt(w_j w_{j+1}) = w_j·sqrt(β)— log-symmetric,second-order-correct, and exact for the community spectrum
N ∝ w^{-2}. Auniform half-bin shift to the right on the log axis.
Design
A
representationtag ("point"/"average", default"point") on theArraySpeciesBySizeandArrayTimeBySpeciesBySizeconstructors:getPredMort(),getFMort(),getMort(),getExtMort()and the reproductive investmentgetERepro()tag themselves"average"; point-valued quantities (encounter,growth) keep the
"point"default.get_ArraySpeciesBySize_w()andthe new
get_ArrayTimeBySpeciesBySize_w()return the geometric bin centres(new internal
bin_midpoints()helper) for"average"arrays only whensecond_order_w[["bin_average"]]is set. So first-order/default models, theiras.data.frame()output and all vdiffr snapshots are unchanged; asecond-order model is internally consistent across dynamics, diagnostics and
plot placement.
[subset, the time-slice, and theMizerSim rate path (
sim_size_rate/get_species_size_rate_from_simthread arepresentationargument to the constructors). Everything downstream(
prepare_*_plot_data,as.data.frame,plot2) follows the central helpersautomatically.
Scope
plotSpectra/plotCDFbuild their own data frames and apply thew^powerweight; their centre placement (and the CDF's opposite, edge placement) is the
separate #383, which reuses
bin_midpoints().Tests
test-ArraySpeciesBySize.R/test-ArrayTimeBySpeciesBySize.R: producers taghonestly;
bin_midpointsare the geometric centres; the size axis shifts to thecentres only under
second_order_w(point quantities stay on nodes);as.data.framex-values follow the tag; subsetting/slicing preserve it. Therate-function and backwards-compat snapshots gained only the new benign
representationattribute (accepted). Full suite: 2824 pass.Docs
NEWS entry; a "Plotting follows the same distinction" note in the
"Point values and bin averages" section of the numerical-details vignette.
🤖 Generated with Claude Code