uxarray icon indicating copy to clipboard operation
uxarray copied to clipboard

Optimize Non-Conservative Zonal Average in `zonal.py`

Open hongyuchen1030 opened this issue 8 months ago • 0 comments
trafficstars

Proposed new feature or change:

Overview

The goal of this issue is to optimize the non-conservative zonal average routine by:

  • Avoiding redundant recalculations
  • Reusing intermediary computational steps to minimize overhead

Note: The current implementation uses data copying in its general helper function to support broad user scenarios. This behavior will remain for user-facing functions.

Proposed Approach

  • Dedicated Helper Functions:
    Build specialized helper functions tailored for the non-conservative zonal average routine.

  • Specialized Routine for Internal Use:
    Implement an optimized version that avoids unnecessary data copying internally, while preserving the general helper function that uses copies for general user use.

  • Intermediary Step Reuse:
    Identify and reuse common intermediary steps in the computation to avoid redundant calculations.

  • Module Organization:
    Create a separate zonal.py file that bundles all related functions for clarity and maintainability.

Tasks

  • [ ] Review the current implementation in zonal.py for inefficiencies.
  • [ ] Design and implement specialized helper functions optimized for the zonal average routine.
  • [ ] Maintain the current general helper function (with data copies) for users who need its generality.
  • [ ] Implement caching or reuse of intermediary steps to reduce recalculation.
  • [ ] Test the new implementation to ensure performance improvements and correctness.
  • [ ] Update documentation and add unit tests for the new code.

Example Reference

In a similar non-conservative zonal average implementation, dedicated helper functions are built to work specifically for that routine. While general helper functions may use data copying for broad usability, an optimized internal version can focus on performance by reusing intermediary steps and minimizing overhead.

hongyuchen1030 avatar Mar 12 '25 02:03 hongyuchen1030