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

⛈️clean up, testing, documentation #23

Merged
merged 1 commit into from
Jun 23, 2024
Merged

⛈️clean up, testing, documentation #23

merged 1 commit into from
Jun 23, 2024

Conversation

leaver2000
Copy link
Owner

@leaver2000 leaver2000 commented Jun 23, 2024

Summary by Sourcery

This pull request introduces new functions for calculating meteorological parameters such as CCL, CAPE, and CIN. It also includes significant refactoring to improve code clarity and functionality, updates to documentation, and enhancements to the testing suite.

  • New Features:
    • Introduced ccl function to calculate the convective condensation level (CCL) and convective temperature.
    • Added cape_cin function to calculate CAPE and CIN.
    • Implemented most_unstable_cape_cin function to calculate the most unstable CAPE and CIN.
  • Enhancements:
    • Refactored parcel_mixing_ratio function to include detailed docstrings and improved parameter handling.
    • Updated mixed_layer function to handle broadcasting and added support for the where parameter.
    • Replaced Vector1d and Vector2d classes with Parcel and Profile classes for better clarity and functionality.
    • Enhanced intersect_nz and zero_crossings functions to return Profile objects instead of Vector2d.
  • Documentation:
    • Added detailed docstrings for parcel_mixing_ratio, ccl, cape_cin, most_unstable_cape_cin, and mixed_layer functions.
    • Updated documentation for equivalent_potential_temperature and theta_w functions in libthermo.cpp.
  • Tests:
    • Added new tests for ccl function with various parameter combinations.
    • Updated tests for mixed_layer to include cases with and without interpolation.
    • Refactored existing tests to use assert_array_equal for better accuracy and consistency.

@leaver2000 leaver2000 merged commit e9ea12b into master Jun 23, 2024
1 check failed
Copy link

sourcery-ai bot commented Jun 23, 2024

Reviewer's Guide by Sourcery

This pull request focuses on cleaning up the code, adding tests, and improving documentation. The changes include refactoring code for better readability and maintainability, adding new test cases, and enhancing the documentation for various functions.

File-Level Changes

Files Changes
src/nzthermo/core.py
src/nzthermo/utils.py
src/nzthermo/functional.py
Refactored core functionality, updated class names, and added detailed docstrings for better readability and maintainability.
tests/core_test.py
tests/conftest.py
Added new test cases, removed redundant tests, and updated existing tests to match the new function signatures and behaviors.
src/lib/libthermo.cpp
src/lib/functional.cpp
Updated C++ helper functions for better compatibility and readability.
src/nzthermo/_core.pyx
src/nzthermo/_ufunc.pyi
src/include/libthermo.hpp
src/nzthermo/_C.pxd
src/nzthermo/_core.pyi
Renamed methods and updated type hints for better consistency and readability.

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



FASTPATH: dict[str, Any] = {"__fastpath": True}


@broadcast_nz
Copy link

Choose a reason for hiding this comment

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

question: Decorator placement might be unnecessary.

The @broadcast_nz decorator is used here, but it's not clear if the function parcel_mixing_ratio requires broadcasting. Please ensure that this decorator is necessary for this function.

mixing ratio is calculated using the dewpoint upto the LCL (lifting condensation level)
and the temperature above the LCL.

Returns
Copy link

Choose a reason for hiding this comment

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

issue: Incomplete return documentation.

The return section for the ccl function is marked as TODO. Please complete this section to provide clarity on what the function returns.

@@ -203,7 +244,8 @@
which_lfc: L["bottom", "top"] = "bottom",
which_el: L["bottom", "top"] = "top",
dewpoint_start: np.ndarray[shape[N], np.dtype[_T]] | None = None,
) -> tuple[Vector1d[_T], Vector1d[_T]] | Vector1d[_T]:
) -> tuple[Parcel[_T], Parcel[_T]] | Parcel[_T]:
r"""short cut for el, lfc, and el_lfc functions."""
Copy link

Choose a reason for hiding this comment

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

suggestion: Docstring is too brief.

The docstring for _el_lfc is very brief and does not provide enough context. Consider expanding it to explain the purpose and usage of the function.

Suggested change
r"""short cut for el, lfc, and el_lfc functions."""
r"""
Shortcut for calculating the Equilibrium Level (EL),
Level of Free Convection (LFC), and a combined EL and LFC.
Returns:
A tuple of Parcel objects representing EL and LFC, or a single Parcel object.
"""

@@ -564,15 +603,15 @@
depth: Pascal[float] = 30000.0,
bottom: Pascal[float] | None = None,
) -> tuple[np.ndarray, np.ndarray]:
r"""TODO ...
r"""Calculate most unstable CAPE and CIN.
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 most_unstable_cape_cin is marked as TODO. Please complete this section to provide clarity on the function's purpose and usage.

# ............................................................................................... #
# nzthermo.core.ccl
# ............................................................................................... #
@pytest.mark.ccl
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 test_ccl_metpy_regression

Consider adding a test case for when height is provided, even if it raises a NotImplementedError. This will ensure that the function behaves as expected when this parameter is used.

@@ -1331,7 +1337,6 @@
assert_array_equal(
most_unstable_parcel(P, T, Td, depth=depth),
most_unstable_parcel(np.broadcast_to(P, T.shape), T, Td, depth=depth),
err_msg="most_unstable_parcel failed to on broadcasted pressure input.",
Copy link

Choose a reason for hiding this comment

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

issue (testing): Remove commented-out error messages

The commented-out error messages should be either re-enabled or removed. Keeping them commented out can lead to confusion and clutter in the test code.

@@ -1356,15 +1361,11 @@
# ............................................................................................... #
@pytest.mark.broadcasting
@pytest.mark.most_unstable_cape_cin
def test_most_unstable_cape_cin_broadcasting():
@pytest.mark.parametrize("depth", [30000.0])
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Add more depth values for test_most_unstable_cape_cin_broadcasting

Consider adding more depth values to the parametrize decorator to ensure the function is tested across a wider range of scenarios.

Suggested change
@pytest.mark.parametrize("depth", [30000.0])
@pytest.mark.parametrize("depth", [10000.0, 20000.0, 30000.0, 40000.0, 50000.0])

"""

assert_allclose(
assert_array_equal(
Copy link

Choose a reason for hiding this comment

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

issue (testing): Remove outdated comments

The outdated comments explaining the use of assert_allclose should be removed as they are no longer relevant.

Comment on lines +88 to +93
r = saturation_mixing_ratio(
pressure,
temperature,
out=saturation_mixing_ratio(pressure, dewpoint, where=where),
where=~where,
)
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Inline variable that is immediately returned (inline-immediately-returned-variable)

Comment on lines +59 to +65
temperature = temperature[sort][:, ::-1]
dewpoint = dewpoint[sort][:, ::-1]
else:
sort = np.arange(pressure.shape[0])[:, np.newaxis], p_sort
pressure = pressure[sort][:, ::-1]
temperature = temperature[sort][:, ::-1]
dewpoint = dewpoint[sort][:, ::-1]
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Hoist repeated code outside conditional statement [×2] (hoist-statement-from-if)

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