Skip to content

NaN Support #24

Closed
Closed

Description

@jbphyswx

For intermittent data on a fixed grid, we should really support handling nans.

Since we expect vectorized methods to truly be so much faster, for intermittent gridded data we need to have nan exclusion support.
TBD if this is built in or via extension

need #23 to have the fast gridded methods

Activity

  1. self-assigned this
    on Jun 18, 2026
  2. jbphyswx commented on Sep 6, 2026

    @jbphyswx
    OwnerAuthor

    Done for gridded input, which is what this issue's dependency on #23 was about. Unstructured NaN is still open — see below.

    Gridded. Validity flows through the whole gridded path: field_validity(u, Val(D), cell_mask) combines the grid's own mask (which cells exist) with the field's finiteness (which cells hold a usable datum) — a cell can exist and still be NaN, so the two are separate questions. A pair counts only when both ends hold a datum.

    Both gridded algorithms honour it:

    • the lag sweep selects rather than multiplies (ok ? v : 0), because an empty cell may hold NaN and NaN * 0 is NaN
    • the transform replaces missing values with zero before transforming, for the same reason — one NaN would otherwise spread across the entire spectrum

    Counts are computed two different ways, deliberately. With a complete field the count stays exact integer arithmetic (∏ periodic ? n_d : n_d − |h_d|); with cells missing it is the mask autocorrelation. So the masked-transform-vs-masked-sweep test compares two genuinely different count computations rather than one against itself.

    This is also what makes spectra from gappy data work, which is the practical payoff. Recovering a spectrum through the structure function versus zero-filling the gaps and transforming directly, against the complete-field answer:

    cells missing via the structure function zero-fill and FFT
    10 % 0.015 0.191
    30 % 0.036 0.543
    50 % 0.041 0.769

    At half the data gone the structure-function route is within a few percent while the direct transform is off by ~80 %, because D(r) remains an unbiased average over surviving pairs while the field's own transform does not.

    Still open: unstructured NaN. On scattered points a NaN datum is simply a point to drop before the sweep, which is cheaper than carrying a mask — but there is currently no entry point that does it for you.

  3. jbphyswx commented on Nov 11, 2026

    @jbphyswx
    OwnerAuthor

    Closed by #39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions