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

Development #22

Merged
merged 6 commits into from
Jun 21, 2024
Merged

Development #22

merged 6 commits into from
Jun 21, 2024

Conversation

leaver2000
Copy link
Owner

@leaver2000 leaver2000 commented Jun 21, 2024

Summary by Sourcery

This pull request introduces new features for calculating mixed-layer CAPE and CIN, enhances type annotations and docstrings for better clarity, and adds comprehensive tests to ensure functionality and regression coverage. Additionally, it includes code refactoring and cleanup to improve maintainability.

  • New Features:
    • Introduced mixed_layer_cape_cin and mixed_parcel functions to calculate mixed-layer CAPE and CIN, and mixed parcel properties respectively.
  • Enhancements:
    • Added detailed parameter and return type annotations to several functions for better clarity and type safety.
    • Refactored pressure_vector class to include additional methods for pressure comparisons and broadcasting support.
    • Improved the lcl class and related functions with better initialization and method definitions.
  • Documentation:
    • Updated docstrings for several functions to include detailed descriptions, parameters, return types, and examples.
  • Tests:
    • Added new tests for mixed_layer_cape_cin and mixed_parcel functions to ensure correct functionality and regression testing.
    • Enhanced existing tests with additional assertions and parameterized test cases for better coverage.
    • Introduced broadcasting tests for cape_cin, most_unstable_cape_cin, and mixed_parcel functions to validate broadcasting behavior.
  • Chores:
    • Removed redundant and commented-out code to improve code readability and maintainability.
    • Reorganized imports and cleaned up unused imports across multiple files.

@leaver2000 leaver2000 merged commit 8311b9c into master Jun 21, 2024
1 check failed
Copy link

sourcery-ai bot commented Jun 21, 2024

Reviewer's Guide by Sourcery

This pull request introduces several new functions and updates existing ones with additional parameters, improved docstrings, and better type safety. It also adds new utility functions and updates imports. The tests have been expanded to cover the new functionality, and the code has been reformatted and cleaned up for better readability and performance.

File-Level Changes

Files Changes
src/nzthermo/core.py
src/nzthermo/_core.pyx
src/nzthermo/_core.pyi
src/nzthermo/_ufunc.pyx
src/nzthermo/_ufunc.pyi
Introduced new functions and updated existing ones with additional parameters, improved docstrings, and better type safety. Added new utility functions and updated imports.
tests/core_test.py
tests/ufunc_test.py
Added new test cases for the newly introduced functions and updated existing tests with new constants and better organization.
src/include/libthermo.hpp
src/lib/libthermo.cpp
src/lib/functional.cpp
src/include/wind.hpp
src/lib/wind.cpp
Reformatted and cleaned up code for better readability and performance. Added new helper functions and updated existing ones.

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.

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: 7 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues 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.

@@ -72,9 +74,10 @@ def downdraft_cape(
temperature: Kelvin[np.ndarray[shape[N, Z], np.dtype[_T]]],
dewpoint: Kelvin[np.ndarray[shape[N, Z], np.dtype[_T]]],
/,
*,
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider using keyword-only arguments.

The addition of *, makes all following arguments keyword-only. This is a good practice for clarity and to avoid potential bugs. Ensure this change is intentional and consistent with the rest of the codebase.

where: np.ndarray[shape[N, Z], np.dtype[np.bool_]] | None = None,
) -> np.ndarray[shape[N], np.dtype[_T]]:
"""Calculate downward CAPE (DCAPE).
r"""Calculate downward CAPE (DCAPE).
Copy link

Choose a reason for hiding this comment

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

question: Raw string literal usage.

Using a raw string literal (r""") for the docstring is unusual unless there are backslashes in the text. Ensure this is necessary.

Temperature (K) at the levels given by `pressure`
dewpoint : `array_like[[N, Z], floating]`
Dewpoint (K) at the levels given by `pressure`
TODO : ...
Copy link

Choose a reason for hiding this comment

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

issue: Incomplete docstring.

The docstring for the ccl function is incomplete. Ensure that the TODOs are addressed before merging.

@@ -289,6 +356,26 @@
which_el: L["bottom", "top"] = "top",
dewpoint_start: np.ndarray[shape[N], np.dtype[_T]] | None = None,
) -> tuple[Vector1d[_T], Vector1d[_T]]:
r"""TODO ...
Copy link

Choose a reason for hiding this comment

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

issue: Incomplete docstring.

The docstring for the el_lfc function is incomplete. Ensure that the TODOs are addressed before merging.

@@ -346,6 +453,26 @@
Kelvin[np.ndarray[shape[N], np.dtype[_T]]],
np.ndarray[shape[N, Z], np.dtype[np.intp]],
]:
r"""Calculate the most unstable parcel profile.
Copy link

Choose a reason for hiding this comment

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

issue: Incomplete docstring.

The docstring for the most_unstable_parcel function is incomplete. Ensure that the TODOs are addressed before merging.

temperature: Kelvin[np.ndarray[shape[N, Z], np.dtype[np.floating[Any]]]],
dewpoint: Kelvin[np.ndarray[shape[N, Z], np.dtype[np.floating[Any]]]],
/,
*,
where: np.ndarray[shape[N], np.dtype[np.bool_]] | None = ...,
) -> tuple[
Pascal[np.ndarray[shape[N, Z], np.dtype[T]]],
Pascal[pressure_vector[shape[N, Z], np.dtype[T]]],
Copy link

Choose a reason for hiding this comment

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

suggestion: Type hinting for pressure_vector.

The use of pressure_vector in type hinting improves code clarity. Ensure this is consistent across the codebase.

Suggested change
Pascal[pressure_vector[shape[N, Z], np.dtype[T]]],
Pascal[np.ndarray[shape[N, Z], np.dtype[T]]],
Pascal[pressure_vector[shape[N, Z], np.dtype[T]]],

Comment on lines +28 to +29
T fabs[T](T) noexcept
bint isnan(double) noexcept
Copy link

Choose a reason for hiding this comment

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

suggestion (performance): Use of C++ standard library functions.

The inclusion of fabs and isnan from the C++ standard library is a good practice for performance. Ensure these are used consistently.

Suggested change
T fabs[T](T) noexcept
bint isnan(double) noexcept
cdef extern from "<cmath>" namespace "std" nogil:
T fabs[T](T) noexcept
bint isnan(double) noexcept
cdef inline T abs_value[T](T x) nogil:
return fabs(x)
cdef inline bint is_nan(double x) nogil:
return isnan(x)

# nzthermo.core.most_unstable_parcel
# nzthermo.core.cape_cin
# ............................................................................................... #
@pytest.mark.cape_cin
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Missing edge case for cape_cin function

Consider adding a test case for the cape_cin function where the input arrays contain NaN values. This will help ensure that the function handles missing data gracefully.

Suggested change
@pytest.mark.cape_cin
@pytest.mark.cape_cin
@pytest.mark.broadcasting
def test_cape_cin_broadcasting_with_nan():
input_data_with_nan = np.array([[300.0, np.nan], [np.nan, 310.0]])
result = cape_cin(input_data_with_nan)
assert not np.isnan(result).all()

# nzthermo.core.most_unstable_cape_cin
# ............................................................................................... #
@pytest.mark.broadcasting
@pytest.mark.most_unstable_cape_cin
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Missing edge case for most_unstable_cape_cin function

Consider adding a test case for the most_unstable_cape_cin function where the input arrays contain NaN values. This will help ensure that the function handles missing data gracefully.

Suggested change
@pytest.mark.most_unstable_cape_cin
@pytest.mark.most_unstable_cape_cin
def test_most_unstable_cape_cin_with_nan():
input_data_with_nan = np.array([[np.nan, 300], [250, np.nan]])
result = most_unstable_cape_cin(input_data_with_nan)
assert np.isnan(result).any()

Td,
depth=30000.0,
),
@pytest.mark.mixed_layer_cape_cin
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Missing edge case for mixed_layer_cape_cin function

Consider adding a test case for the mixed_layer_cape_cin function where the input arrays contain NaN values. This will help ensure that the function handles missing data gracefully.

Suggested change
@pytest.mark.mixed_layer_cape_cin
@pytest.mark.mixed_layer_cape_cin
def test_mixed_layer_cape_cin_with_nan() -> None:
"""
Test mixed_layer_cape_cin function with NaN values in input arrays.
"""
Td = np.array([np.nan, 10.0, 20.0])
depth = 30000.0
result = mixed_layer_cape_cin(Td, depth)
assert np.isnan(result).any()

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