Skip to content

Add preprocessor t_test - #3133

Open
FranziskaWinterstein wants to merge 36 commits into
mainfrom
add_ttest
Open

Add preprocessor t_test#3133
FranziskaWinterstein wants to merge 36 commits into
mainfrom
add_ttest

Conversation

@FranziskaWinterstein

@FranziskaWinterstein FranziskaWinterstein commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

This new preprocessor function calculates a t-test and adds the resulted p-value as an Ancillary Variable to the model cubes. This p-value can later be used for hatching non-significant values when plotting the bias of model and reference. It is planned to add such in monitor/multi_datasets.py.

This works well with masked/non-masked and lazy/non-lazy data (also tested with distributed schedulers).

Link to documentation:

Closes #3132

Test recipe:

# ESMValTool
---
documentation:
  description: Test
  authors:
    - schlund_manuel
  title: Test.

datasets:
  - {dataset: BCC-ESM1, project: CMIP6, exp: historical, ensemble: r1i1p1f1, grid: gn, timerange: 2000/2005}
  - {dataset: bcc-csm1-1, version: v1, project: CMIP5, exp: historical, ensemble: r1i1p1, reference_for_t_test: true, timerange: 2000/2005}

preprocessors:
  t-test:
    regrid:
      target_grid: 10x10
      scheme: linear
    mask_landsea:
      mask_out: sea
    t_test:
      coords: [time]
      # nan_policy: omit  # omit: masked values are ignored in t-test calculation
      # equal_var: false  # false: perform Welch's t-test

diagnostics:

  t-test:
    variables:
      tas:
        mip: Amon
        timerange: 1850/2005
        preprocessor: t-test
    scripts:
      null

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.


@CLAassistant

CLAassistant commented Jun 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@FranziskaWinterstein
FranziskaWinterstein marked this pull request as draft June 24, 2026 09:44
@FranziskaWinterstein

FranziskaWinterstein commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Currently the processing fails with

  File "/work/bd1132/b309109/conda_envs/envs/esmvaltool/lib/python3.13/site-packages/numpy/_core/fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
      ^^^^^^^^^^^^^^^^^
numpy.exceptions.AxisError: <exception str() failed>

see also attached main_log_debug.txt

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.31%. Comparing base (08a8dbb) to head (cff6911).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3133      +/-   ##
==========================================
+ Coverage   96.30%   96.31%   +0.01%     
==========================================
  Files         280      280              
  Lines       16252    16310      +58     
==========================================
+ Hits        15651    15709      +58     
  Misses        601      601              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@schlunma schlunma changed the title Add ttest Add preprocessor t_test Jul 1, 2026
@schlunma schlunma added this to the v2.16.0 milestone Jul 1, 2026
@schlunma schlunma added the preprocessor Related to the preprocessor label Jul 1, 2026
@schlunma

schlunma commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Currently the processing fails with

  File "/work/bd1132/b309109/conda_envs/envs/esmvaltool/lib/python3.13/site-packages/numpy/_core/fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
      ^^^^^^^^^^^^^^^^^
numpy.exceptions.AxisError: <exception str() failed>

see also attached main_log_debug.txt

This should be fixed now.

I also updated the code so it properly works with lazy/non-lazy and masked/non-masked data, and added corresponding tests.

Would be great if you can check if it still works as you would expect!

Note that I renamed the preprocessor to t_test to avoid 100s of errors from codespell. This is probably also more readable.

Still missing:

@schlunma
schlunma marked this pull request as ready for review July 21, 2026 10:37
@schlunma

Copy link
Copy Markdown
Contributor

This is ready for review now.

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

Labels

preprocessor Related to the preprocessor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding ttest as a preprocessor function

3 participants