Skip to content

Add latitude weighting to SVDplusDCovariance#230

Merged
ph-kev merged 3 commits intomainfrom
kp/lat-weights
Oct 3, 2025
Merged

Add latitude weighting to SVDplusDCovariance#230
ph-kev merged 3 commits intomainfrom
kp/lat-weights

Conversation

@ph-kev
Copy link
Member

@ph-kev ph-kev commented Sep 22, 2025

closes #229, closes #199 - This PR adds latitude weighting to the SVDplusDCovariance matrix.

@ph-kev ph-kev force-pushed the kp/lat-weights branch 3 times, most recently from 2168c29 to 69473ee Compare September 22, 2025 19:44
@ph-kev ph-kev marked this pull request as ready for review September 22, 2025 19:45
Copy link
Member

@nefrathenrici nefrathenrici left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good so far! Just a few comments.

Comment on lines 253 to 264
"""
_apply_lat_weights_to_samples!(stacked_sample_matrix,
vars::Iterable{OutputVar},
start_date,
end_date,
min_cosd_lat)

Apply latitude weights to the matrix of samples.

The latitude weights applied is `1 / sqrt(max(cosd(lat), 0.1))` to each column
of the matrix.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update this docstring to match the function signature?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this docstring matches the function signature? The only difference is the Iterable{OutputVar}, but there is no easy way to specify that an iterable of OutputVars as a type.

Copy link
Member

@nefrathenrici nefrathenrici Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the the behavior for SVDplusDCovariance but this function itself doesn't have a default min_cosd_lat, I think it should be 1 / sqrt(max(cosd(lat), min_cosd_lat))


"""The minimum cosine weight when using latitude weighting"""
min_cosd_lat::FT3
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a single FT type parameter for this struct?

Copy link
Member Author

@ph-kev ph-kev Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this, but should I do it for all the structs in ObservationRecipe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be the best, we don't need separate FT parameters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little difficult, since there are default keyword arguments whose float types can differ from what the user put in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then it's fine as-is, there isn't much benefit to enforcing one FT anyway.

Copy link
Member

@nefrathenrici nefrathenrici left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines 253 to 264
"""
_apply_lat_weights_to_samples!(stacked_sample_matrix,
vars::Iterable{OutputVar},
start_date,
end_date,
min_cosd_lat)

Apply latitude weights to the matrix of samples.

The latitude weights applied is `1 / sqrt(max(cosd(lat), 0.1))` to each column
of the matrix.
"""
Copy link
Member

@nefrathenrici nefrathenrici Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the the behavior for SVDplusDCovariance but this function itself doesn't have a default min_cosd_lat, I think it should be 1 / sqrt(max(cosd(lat), min_cosd_lat))


"""The minimum cosine weight when using latitude weighting"""
min_cosd_lat::FT3
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be the best, we don't need separate FT parameters.

Comment on lines 770 to 773
@test !isequal(
svd_plus_d_covar_with_lat_weights.svd_cov,
svd_plus_d_covar_with_no_lat_weights.svd_cov,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be isapprox

@ph-kev ph-kev force-pushed the kp/lat-weights branch 2 times, most recently from e801a6a to 8afea03 Compare September 25, 2025 17:33
@ph-kev ph-kev merged commit 3f26188 into main Oct 3, 2025
9 of 13 checks passed
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.

Add latitude weighting to SVDplusD covariance matrix Typo in docs for observation recipe

2 participants