Skip to content

Preserve weighted data across covariance map queries - #166

Open
antonsoo wants to merge 1 commit into
ajdawson:mainfrom
antonsoo:fix/119-preserve-weighted-covariance-data
Open

antonsoo wants to merge 1 commit into
ajdawson:mainfrom
antonsoo:fix/119-preserve-weighted-covariance-data

Conversation

@antonsoo

Copy link
Copy Markdown

Fixes #119. eofsAsCovariance() unweights a view of the solver's stored data in place, so each call divides the data by its weights again. Repeating the same query can therefore return a different map:

import numpy as np
from eofs.standard import Eof

solver = Eof(
    np.array([[1., 0.], [2., 1.], [3., 3.], [4., 2.]]),
    weights=np.array([.5, 1.]),
)
first = solver.eofsAsCovariance(neofs=1)
second = solver.eofsAsCovariance(neofs=1)
print(np.allclose(first, second))  # Before: False; after: True

Copy the data view when weights are present before dividing it. This preserves the first query's result and leaves the unweighted path unchanged. Add repeated-query checks for all three PC scalings to the existing solver-interface tests.

The configured suite passes with Iris, xarray and Dask on Python 3.12. It also passes on Python 3.8, with the unavailable optional Iris cases skipped. The configured pre-commit checks pass. Repeated queries on both bundled height/SST examples match independent covariance products; first-query results, complete unweighted controls and output metadata remain exact.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in eofsAsCovariance when using weights

1 participant