Repository navigation
New Spectral Complex - #754
Open
joobog wants to merge 44 commits into
Open
New Spectral Complex #754joobog wants to merge 44 commits into
joobog wants to merge 44 commits into
Conversation
Spectral complex packing of a field with a very steep spectrum (like the SPP random patterns 213131-213160) aborts with an assertion instead of returning an error, in GRIB1 and GRIB2. The test builds a T1279 field (sub-truncation 20, 16 bits) whose row norms follow the values of the issue, from 5.8e-2 at n=0 to 1.2e-52 at n=1279, and falls below 1e-15 just above the sub-truncation. It checks: 1. GRIB1: set the values, re-pack the decoded values, convert to GRIB2 2. GRIB2: set the values, re-pack the decoded values 3./4. GRIB1/GRIB2 with an operator set by the user that cannot be coded: an error must be returned instead of an abort Each case can be run alone: grib_ecc-2393 <1-4>
…ectrum calculate_pfactor sets the row norms below zeps=1e-15 to zeps and gives them a negligible weight. For a very steep spectrum, the laplacian operator is then fitted on a few steep rows just above the sub-truncation. Applied up to the full truncation, it makes the scaled coefficients overflow the reference value (IEEE/IBM float) and the binary scale factor, and packing aborted with an assertion. - calculate_pfactor: if the fitted operator would make the scaled coefficients overflow, fit again on the real row norms (only zero rows are ignored). This gives the slope of the spectrum tail, e.g. 9.9 for the SPP patterns, the value IFS writes. If the scaled coefficients would still be too large, use the largest operator that keeps them below 1e30. The fit of all other fields is unchanged (bit-identical output). - pack_double: check that the scaled values can be coded (reference value and binary scale factor) and return GRIB_OUT_OF_RANGE instead of failing an assertion, e.g. for an operator set by the user.
…ECC-2393) sc::optimalLaplacianOperator returns the operator that minimises the expected squared error of the packed coefficients, (2^E / 10^D)^2 / 12 * sum (2n + 1) (n(n + 1))^(-2P), among the operators that the message can store (GRIB1: thousandths, GRIB2: millionths) and with which the coefficients can be coded. There are no fitted constants: the only limits are those of the format. The scaling that sc::parameters chooses for an operator is computed exactly from the largest and the smallest packed coefficient of each degree. The search starts at the minimum of the error with a continuous step (convex) and visits only the largest operator of each step. The unit test compares the result with brute force over all 65533 GRIB1 operators. Not used by sc::laplacianOperator or by ecCodes yet.
…o be coded sc::optimalLaplacianOperator throws 'cannot be coded with any laplacian operator' for fields whose packed coefficients underflow with every operator that GRIB1 can store (e.g. 1e-120). sc::parameters codes such fields (all codes zero, as legacy ecCodes). Found by the attack tests; the test fails until the fix.
If the packed coefficients underflow with every operator that the message can store, sc::optimalLaplacianOperator returns 0 instead of throwing: sc::parameters then codes all coefficients as zero, as legacy ecCodes. An operator with which different coefficients get the same scaled value (their products underflow) is not taken as an operator that codes the field.
…both signs For packed coefficients that are all positive or all negative, the scaled range is not monotone in P (it has a dip where the scaled coefficients are nearly equal) and the search can end in a local minimum; brute force found an error 1.07 times the minimum for such a field. The documentation now says so. Real fields are not affected: their imaginary parts of m = 0 are zero. Also: scaled coefficients that become equal only after the decimal scaling are an underflow as well.
… coded Found by the attack tests (pre-existing): a decimal scale factor of 2e9 takes 16 seconds (10^D by |D| multiplications) and 10^-400 = 0 is accepted; an operator whose factor overflows only where the coefficients are zero passes (0 * infinity = NaN is ignored) and sc::pack fails later; an operator with a subnormal factor makes sc::unpack return infinity and NaN. The test fails until the fix.
…erators that cannot be coded
…by mutation testing
… by the coded range
…n ecCodes, as legacy
…ator, simpler search
Legacy ecCodes returns the operator 1 if fewer than two packed rows are above 1e-15 (ECC-2381, now in calculate_pfactor). The frozen legacy reference has it too; the library does not yet, the tests fail: operator_reference, zero_packed_part, the new ecc_2381_zero_padded, and grib_spectral_complex_legacy of ecCodes (a zero-padded field coded with ECCODES_USE_SC=1 differs from legacy).
…15, as legacy (ECC-2381) sc::laplacianOperator follows calculate_pfactor of legacy ecCodes again: a field zero-padded to a higher truncation whose coefficients end just above the sub-truncation gets the operator 1 instead of a fit driven by the artificial norms of the zero rows. With ECCODES_USE_SC=1 such fields are coded byte-identical to legacy.
joobog
force-pushed
the
feature/spectral_complex
branch
from
December 4, 2026 10:36
879f78c to
d145623
Compare
joobog
force-pushed
the
feature/spectral_complex
branch
from
December 4, 2026 12:52
0a2d953 to
1423580
Compare
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.
Description
This pull request adds a new
spectral_complexlibrary for GRIB spectral complex packing, integrates it into the build system, and provides supporting infrastructure for development and testing. The changes add the library as an optional component, enable standalone builds, and provide configuration, documentation, and quality tools.Contributor Declaration
By opening this pull request, I affirm the following:
📖 Documentation preview 📖
https://sites.ecmwf.int/docs/dev-section/eccodes/pull-requests/PR-754