Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Improvement to statistics.py module #138

Merged
merged 4 commits into from
Jun 7, 2019
Merged

Improvement to statistics.py module #138

merged 4 commits into from
Jun 7, 2019

Conversation

andersy005
Copy link
Contributor

@andersy005 andersy005 commented Jun 6, 2019

Checklist

  • Enable and install pre-commit to ensure style-guides and code checks are followed.
  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.

@andersy005 andersy005 marked this pull request as ready for review June 7, 2019 16:52
Copy link
Contributor

@mnlevy1981 mnlevy1981 left a comment

Choose a reason for hiding this comment

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

I verified that this PR lets me drop the dim= argument to esmlab.statistics.weighted_mean():

$ git diff marbl_diags
diff --git a/marbl_diags/analysis_ops.py b/marbl_diags/analysis_ops.py
index cd6f8d6..506053e 100644
--- a/marbl_diags/analysis_ops.py
+++ b/marbl_diags/analysis_ops.py
@@ -125,8 +125,8 @@ def _plot_climo(AnalysisElement, valid_time_dims):
 def _compute_stats(field, TAREA):
     fmin = np.nanmin(field)
     fmax = np.nanmax(field)
-    fmean = esmlab.statistics.weighted_mean(field, dim=field.dims, weights=TAREA).load().values
-    fRMS = np.sqrt(esmlab.statistics.weighted_mean(field*field, dim=field.dims, weights=TAREA).load().values)
+    fmean = esmlab.statistics.weighted_mean(field, weights=TAREA).load().values
+    fRMS = np.sqrt(esmlab.statistics.weighted_mean(field*field, weights=TAREA).load().values)

Thanks for updating this!

@andersy005
Copy link
Contributor Author

Awesome! @mnlevy1981, thank you for confirming that this PR addresses the issue.

@andersy005 andersy005 merged commit bbad55c into NCAR:master Jun 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

statistics.weighted_mean() doesn't work with dim=None
2 participants