feat(cycle): align_observations and analysis_time_in_window for irregular observation streams

Open
#167 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
data

Research direction

Start with packages/pipekit-cycle/src/pipekit_cycle/da.py and cycle.py to understand SmootherCycle and WindowedCycle, then inspect the package exports and pipekit_array.batching.batch for the padding behavior to match. Implement the public helper in the specified windows.py path and update AnalysisStep documentation; done means the listed boundary, padding, overflow, and analysis-index cases pass, with the documented default behavior preserved.

Written by the indexing model from the issue text.

Description

area:code priority:p2 type:feature

Problem / Request

Add a helper that groups an irregular observation stream into fixed-shape analysis windows, and let SmootherCycle place the analysis inside its window.

User Story

As a DA practitioner with irregular satellite times, I want observations grouped into same-sized windows with a validity mask, so that a JAX consumer can run the whole cycle under one lax.scan.

Motivation

WindowedCycle and SmootherCycle assume that each window's observations arrive already grouped.
Any real observation stream needs this grouping, and padding each window to one count is what keeps a downstream cycle's shapes stable.
The analysis is also always taken after the last step, whereas smoothers commonly place it mid-window.
This comes from the survey of DataAssimBench in #44.

Proposed API

# Shapes: N_y observation times; W windows; M the padded per-window count
# proposed (this issue)
class WindowIndices(NamedTuple):
    indices: tuple[int, ...]      # length M: positions in obs_times
    valid: tuple[bool, ...]       # length M: True marks a real observation
    t_start: float
    t_end: float

def align_observations(
    obs_times: Sequence[float],
    *,
    t0: float,
    window: float,
    stride: float | None = None,  # defaults to window
    n_windows: int | None = None,
    max_obs: int | None = None,   # defaults to the largest window's count
) -> list[WindowIndices]: ...

# usage
windows = align_observations(times, t0=0.0, window=6.0)          # W entries of length M
  • A window covers [t_start, t_end), so that an observation on a boundary belongs to exactly one window when stride == window.
  • Padding repeats the window's last real index with valid=False, the rule that pipekit_array.batch(pad="last") already uses.
  • An empty window has all valid=False and indices of 0.
  • A window with more than max_obs observations raises ValueError; it never silently drops data.
  • The helper is pure Python, because pipekit-cycle's base install has no array dependency.
# proposed (this issue)
class SmootherCycle(StatefulOperator):
    def __init__(self, ..., analysis_time_in_window: float | None = None): ...

analysis_time_in_window is a fraction in [0, 1]. None keeps today's behaviour, and otherwise analysis_step also receives analysis_index=round(f * (window - 1)).

Design Snapshot

SmootherCycle._apply today, from packages/pipekit-cycle/src/pipekit_cycle/da.py @ 7c446f1, steps window times and calls analysis_step(forecasts, observations, obs_op=..., obs_err_cov=...) once.
It can't see the window's start state.
That is a separate gap, recorded in geostack report 10, and it stays out of this issue.

References & Existing Code

  • dabench/dacycler/_utils.py and analysis_time_in_window in DataAssimBench (https://github.com/StevePny/DataAssimBench).
  • WindowedCycle in cycle.py and SmootherCycle in da.py @ 7c446f1.
  • pipekit_array.batching.batch @ 7c446f1 for the padding rule.

Implementation Steps

  • Add WindowIndices and align_observations in packages/pipekit-cycle/src/pipekit_cycle/windows.py, and re-export them.
  • Add analysis_time_in_window to SmootherCycle, validating the range, and add it to get_config.
  • Document the extra keyword for AnalysisStep implementers.

Definition of Done

  • Code lands at the intended path.
  • Tests pass: make test.
  • Lint + typecheck pass: make lint && make typecheck.
  • Docstrings (Google-style) on all public symbols.

Testing

  • Every observation inside the covered range appears in exactly one window when stride == window, including one exactly on a boundary.
  • Every window has length max_obs, and padded positions repeat the last real index with valid=False.
  • An empty window is all invalid, and max_obs smaller than a window's count raises ValueError.
  • With analysis_time_in_window=None, SmootherCycle results are identical to today's.
  • analysis_time_in_window=0.5 on a window of 5 passes analysis_index=2.

Documentation

  • SmootherCycle docstring, with an irregular-times example.

Relationships

  • Parent (theme epic): #149
  • Related: #44, #163
Dominant language
Python
Stars
0
Forks
0
Avg merge
3h 50m
Merged PRs (30d)
143

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/pipekit

All issues in jejjohnson/pipekit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.