Skip to content

Conversation

@ma595
Copy link
Member

@ma595 ma595 commented Aug 30, 2025

This is a first attempt at bringing the granularity resampling to the evaluation project. We copy xgran in a vendored sense into spinup-evaluation. In future it could be packaged separately and introduced as a dependency depending on whether there is interest.

The problem

A common use case is illustrated in #54.

We need to compute metrics as defined in metrics.py at different temporal resolutions. Based on the arguments (temperature, ssh, velocity, salinity, UNUSED(salinity)) to these metric functions (temperature_500m_30NS_metric, temperature_BWbox_metric, temperature_DWbox_metric, ACC_Drake_metric_2) we can determine an intelligent resampling strategy to allow us to compute metrics even when variables at a certain temporal granularity is not available to us. We can only do downsamping by averaging from finer temporal granularity to coarser (up sampling is not allowed).
When averaging we use the finest available data (this needs to be tested).

Features of xgran

  • Analysis deduces what variables/files we have and what metrics we can calculate. It stores this information in a dictionary (analysis) that can be passed around.
  • The compute.py file implements a single pass resampling.
    • get_data is the core function that resamples data.
    • We must temporally align all data to some well known NEMO reference at that granularity, otherwise operations between metrics having differing temporal binning at a given granularity will fail - this is explained in Resampling anchor has to be consistent i.e. ME month end vs MS month start. #59.
      • Currently this is a two step process. We resample and then align all files separately given a reference. This works, but it could be compressed to a single pass. Everything is done lazily so this doesn't really have much of a performance hit.
  • The materialize.py approach forces this to behave in a two step process.

Resampling

Nemo files are center stamped. Whereas xarray resample at edges. See issue #59.

TODO

  • Wire in with the rest of spinup-evaluation using a thin layer
  • Tests how resampling assumptions affect the outputs of the metrics. Do results change? Write test.
  • Does the specification of the variable in the input file work? This is the current approach in spinup-evaluation.
  • Overwriting aligned_resampled data leads to error.

Closes #54, #59

@ma595 ma595 self-assigned this Aug 31, 2025
@ma595 ma595 marked this pull request as draft August 31, 2025 14:18
@ma595 ma595 added the enhancement New feature or request label Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metrics Granularity selection

2 participants