-
Notifications
You must be signed in to change notification settings - Fork 1
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
🔢pressure and height vectors #25
Conversation
Reviewer's Guide by SourceryThis pull request introduces vertical_vector, pressure_vector, and height_vector classes to handle pressure and height comparisons and conversions. It updates various functions across the codebase to use these new classes, ensuring more robust and readable code. Additionally, it includes new and updated tests to verify the functionality of these classes. File-Level Changes
Tips
|
There was a problem hiding this 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: 5 issues found
- 🟢 Security: all looks good
- 🟡 Testing: 2 issues found
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
# ............................................................................................... # | ||
# helpers | ||
# ............................................................................................... # | ||
class vertical_vector(np.ndarray[_S, np.dtype[_T]], abc.ABC): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider using a more descriptive class name.
The class name vertical_vector
is somewhat generic. Consider using a more descriptive name that better conveys its purpose or functionality.
class vertical_vector(np.ndarray[_S, np.dtype[_T]], abc.ABC): | |
class VerticalVector(np.ndarray[_S, np.dtype[_T]], abc.ABC): |
|
||
return np.asarray(greater_or_close(self, top), np.bool_) | ||
|
||
def is_between(self, bottom, top, close=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential logical error in is_between
method.
The condition self < bottom & self > top
seems logically incorrect. It should likely be self > bottom & self < top
.
@@ -81,14 +79,14 @@ def _get_profile( | |||
return parcel_profile(pressure, t, td) | |||
|
|||
|
|||
class entrainment(Generic[_T]): | |||
class _entrainment(Generic[_T]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Class name starting with an underscore.
The class name _entrainment
starts with an underscore, which typically indicates a private class. If this is not intended to be private, consider renaming it.
@@ -108,6 +108,13 @@ def nanroll_2d( | |||
return args | |||
|
|||
|
|||
def arange_slice(x: slice, nd: int, axis: SupportsIndex = -1) -> tuple[slice, ...]: | |||
s = [slice(None)] * nd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider renaming variable s
.
The variable name s
is not very descriptive. Consider renaming it to something more meaningful, like slices
.
s = [slice(None)] * nd | |
slices = [slice(None)] * nd |
_T = TypeVar("_T") | ||
_DType_T_co = TypeVar("_DType_T_co", bound=np.dtype[Any]) | ||
|
||
class vertical_vector(np.ndarray[_S, _DType_T_co], abc.ABC): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider adding a docstring for the class.
Adding a docstring for the vertical_vector
class can help other developers understand its purpose and usage.
class vertical_vector(np.ndarray[_S, _DType_T_co], abc.ABC): | |
class vertical_vector(np.ndarray[_S, _DType_T_co], abc.ABC): | |
""" | |
A class representing a vertical vector, inheriting from numpy's ndarray. | |
This class is designed to handle vertical vector operations with specific | |
data types and shapes. | |
""" |
def test_pressure_vector() -> None: | ||
p = pressure_vector( | ||
[ | ||
101300.0, | ||
100000.0, | ||
97500.0, | ||
95000.0, | ||
92500.0, | ||
90000.0, | ||
87500.0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Consider adding edge case tests for pressure_vector
The test_pressure_vector function is comprehensive, but it would be beneficial to add edge cases such as empty arrays, arrays with a single element, and arrays with non-monotonic sequences to ensure robustness.
@@ -42,7 +42,7 @@ | |||
V = data["V"][step] | |||
print(np.abs(Q - data["Q"][step]).max()) | |||
|
|||
MSL: np.ndarray = data["Z"][step] | |||
MSL: height_vector = data["Z"][step].view(height_vector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Add test for height_vector edge cases
Consider adding tests to validate edge cases for height_vector, such as empty arrays, arrays with a single element, and arrays with non-monotonic sequences. This will help ensure the height_vector class handles these scenarios correctly.
@@ -108,6 +108,13 @@ | |||
return args | |||
|
|||
|
|||
def arange_slice(x: slice, nd: int, axis: SupportsIndex = -1) -> tuple[slice, ...]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider simplifying the code to maintain readability and reduce unnecessary complexity.
The new code introduces additional complexity that could be avoided. Here are some points to consider:
-
Introduction of
arange_slice
Function: While the newarange_slice
function aims for reusability, it adds an extra layer of abstraction that makes the code harder to follow. The original inline slice creation was more straightforward and easier to understand. -
Increased Indirection: Using the
arange_slice
function to create slices (s1
ands2
) adds an extra step for the reader to understand what these slices are doing. The original code directly created the slices, making it immediately clear what they represent. -
Changes in Variable Names: The variable names have been changed from
slice1
andslice2
tos1
ands2
. While shorter, these names are less descriptive and can make the code harder to understand at a glance. -
Tuple Creation: The new code uses tuple creation in the
zero_crossings
function, which adds unnecessary complexity. The original code was more straightforward in its approach.
Consider simplifying the code to maintain readability and reduce unnecessary complexity.
assert isinstance(p2, pressure_vector) | ||
assert np.allclose(p, p2) | ||
|
||
assert np.all(p.is_above(101325.0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (code-quality): Extract duplicate code into function (extract-duplicate-method
)
Summary by Sourcery
This pull request introduces new
vertical_vector
,pressure_vector
, andheight_vector
classes to enhance atmospheric pressure and height calculations. It also refactors existing functions to use these new classes, improving code organization and readability. Additionally, new tests are added to ensure the correctness of these changes.vertical_vector
class as an abstract base class forpressure_vector
andheight_vector
with methods for comparison and conversion.pressure_vector
andheight_vector
classes inheriting fromvertical_vector
, providing methods for atmospheric pressure and height calculations.ncape
function for calculating normalized convective available potential energy.pressure_vector
andheight_vector
to use newvertical_vector
base class, improving code organization and reusability.bunkers_storm_motion
and other functions to use newpressure_vector
andheight_vector
methods for cleaner and more readable code.ecape
function to use the new_entrainment
class for better encapsulation and clarity.nantrapz
function by addingwhere
parameter to exclude certain values from integration.pressure_vector
andheight_vector
to ensure correct functionality of comparison and conversion methods.pressure_vector
andheight_vector
implementations.