Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💨wind vector stuff #19

Merged
merged 1 commit into from
Jun 17, 2024
Merged

💨wind vector stuff #19

merged 1 commit into from
Jun 17, 2024

Conversation

leaver2000
Copy link
Owner

@leaver2000 leaver2000 commented Jun 17, 2024

Summary by Sourcery

This pull request introduces new classes wind_vector and wind_components to encapsulate wind data, refactors existing wind-related functions to use these classes, and adds corresponding tests and documentation.

  • New Features:
    • Introduced wind_vector and wind_components classes to encapsulate wind data and provide conversion methods between direction/magnitude and u/v components.
  • Enhancements:
    • Refactored wind direction and magnitude calculations to use the new wind_vector and wind_components classes.
    • Updated the wind_direction function to simplify its logic and remove the from parameter.
    • Enhanced the wind_components and wind_vector classes with explicit constructors for better initialization and conversion.
  • Documentation:
    • Added detailed docstrings for theta_e and theta_w functions in libthermo.cpp.
    • Documented constants such as T0, E0, Cp, Rd, Rv, Lv, P0, Mw, Md, epsilon, and kappa in src/nzthermo/_core.pyx.
  • Tests:
    • Added tests for the new wind_vector function to ensure correct conversion between wind components and direction/magnitude.

Copy link

sourcery-ai bot commented Jun 17, 2024

Reviewer's Guide by Sourcery

This pull request refactors wind-related functions by introducing new classes for wind_vector and wind_components, along with conversion constructors. It also updates ufunc implementations and signatures, adds new thermodynamic constants, and improves documentation and test coverage.

File-Level Changes

Files Changes
src/lib/wind.cpp
src/include/wind.hpp
Refactored wind-related functions and introduced new classes for wind_vector and wind_components with conversion constructors.
src/nzthermo/_ufunc.pyx
src/nzthermo/_C.pxd
src/nzthermo/_ufunc.pyi
Updated ufunc implementations and signatures for wind_components and wind_vector, and removed outdated comments.
src/nzthermo/_core.pyx
src/nzthermo/_core.pyi
src/nzthermo/__init__.py
Added and documented new thermodynamic constants, and updated module exports.
src/lib/libthermo.cpp
src/include/libthermo.hpp
Added documentation for thermodynamic functions and simplified lcl class.
tests/ufunc_test.py Added and updated test cases for wind-related functions.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@leaver2000 leaver2000 merged commit 283f793 into master Jun 17, 2024
1 check failed
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @leaver2000 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 8 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.


return wdir;
constexpr T wind_direction(const T u, const T v) noexcept {
return fmod(degrees(atan2(u, v)) + 180.0, 360.0);
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential issue with wind direction calculation.

The new implementation of wind_direction always adds 180 degrees, which might not be the intended behavior. The previous implementation had a conditional check for the from parameter. Please verify if this change is intentional.

Comment on lines +9 to +10
template <floating T>
constexpr T wind_direction(const wind_components<T>& uv) noexcept {
Copy link

Choose a reason for hiding this comment

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

suggestion: Redundant function definition.

The new wind_direction function that takes wind_components<T> as a parameter seems redundant since it just calls the existing wind_direction function. Consider removing it to avoid unnecessary code duplication.

Suggested change
template <floating T>
constexpr T wind_direction(const wind_components<T>& uv) noexcept {
template <floating T>
constexpr T wind_direction(const wind_vector<T>& uv) noexcept {
return wind_direction(wind_components<T>(uv));
}

T speed;
T direction;
};
class wind_vector;
Copy link

Choose a reason for hiding this comment

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

suggestion: Forward declaration of wind_vector.

The forward declaration of wind_vector is not necessary here since the full definition is provided later in the file. Consider removing the forward declaration to improve code clarity.

Suggested change
class wind_vector;
template <floating T>

Comment on lines +86 to +87
@cython.ufunc
cdef (double, double) wind_vector(T u, T v) noexcept nogil:
Copy link

Choose a reason for hiding this comment

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

suggestion: Inconsistent function naming.

The function wind_vector might be better named as wind_vector_from_components to clearly indicate its purpose and avoid confusion with the wind_vector class.

Suggested change
@cython.ufunc
cdef (double, double) wind_vector(T u, T v) noexcept nogil:
@cython.ufunc
cdef (double, double) wind_vector_from_components(T u, T v) noexcept nogil:

Comment on lines +75 to +84
T0 = C.T0
"""`(J/kg*K)` - freezing point in kelvin"""
E0 = C.E0
"""`(Pa)` - vapor pressure at T0"""
Cp = C.Cp
"""`(J/kg*K)` - specific heat of dry air"""
Rd = C.Rd
"""`(J/kg*K)` - gas constant for dry air"""
Rv = C.Rv
"""`(J/kg*K)` - gas constant for water vapor"""
Copy link

Choose a reason for hiding this comment

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

suggestion: Missing documentation for constants.

Consider adding documentation comments for the newly added constants (T0, E0, Cp, etc.) to improve code readability and maintainability.

@@ -66,12 +66,12 @@ constexpr T potential_temperature(const T pressure, const T temperature) noexcep
template <floating T>
constexpr T equivalent_potential_temperature(
const T pressure, const T temperature, const T dewpoint
) noexcept; // theta_e
Copy link

Choose a reason for hiding this comment

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

suggestion: Removed comment for function purpose.

The comment // theta_e was removed. Consider re-adding it or providing a more detailed comment to describe the purpose of the equivalent_potential_temperature function.

@@ -66,12 +66,12 @@
template <floating T>
constexpr T equivalent_potential_temperature(
const T pressure, const T temperature, const T dewpoint
) noexcept; // theta_e
Copy link

Choose a reason for hiding this comment

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

suggestion: Removed comment for function purpose.

The comment // theta_w was removed. Consider re-adding it or providing a more detailed comment to describe the purpose of the wet_bulb_potential_temperature function.

Suggested change
) noexcept; // theta_e
template <floating T>
constexpr T wet_bulb_potential_temperature(
const T pressure, const T temperature, const T dewpoint
) noexcept; // Calculates the wet-bulb potential temperature (theta_w)

Comment on lines -103 to -110
// copy constructor
constexpr lcl(const lcl<T>& other) noexcept = default;
// move constructor
constexpr lcl(lcl<T>&& other) noexcept = default;
// copy assignment operator
constexpr lcl<T>& operator=(const lcl<T>& other) noexcept = default;
// destructor
~lcl() noexcept = default;
Copy link

Choose a reason for hiding this comment

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

question: Removed special member functions.

The copy constructor, move constructor, copy assignment operator, and destructor for the lcl class were removed. If these were intentionally removed, consider documenting why they are no longer needed.

Comment on lines +47 to +48
u, v = wind_components(WIND_DIRECTIONS, WIND_MAGNITUDES)
assert_allclose([WIND_DIRECTIONS, WIND_MAGNITUDES], wind_vector(u, v), atol=1e-9)
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Test for edge cases with zero wind magnitude

Consider adding tests for edge cases where the wind magnitude is zero. This will ensure that the wind_vector function handles these cases correctly.

Suggested change
u, v = wind_components(WIND_DIRECTIONS, WIND_MAGNITUDES)
assert_allclose([WIND_DIRECTIONS, WIND_MAGNITUDES], wind_vector(u, v), atol=1e-9)
u, v = wind_components(WIND_DIRECTIONS, WIND_MAGNITUDES)
assert_allclose([WIND_DIRECTIONS, WIND_MAGNITUDES], wind_vector(u, v), atol=1e-9)
zero_magnitude = [0, 0, 0]
zero_directions = [0, 90, 180]
u_zero, v_zero = wind_components(zero_directions, zero_magnitude)
assert_allclose([zero_directions, zero_magnitude], wind_vector(u_zero, v_zero), atol=1e-9)

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.

1 participant