-
Notifications
You must be signed in to change notification settings - Fork 3
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
increase speed, decrease memory usage using dataarray selection #18
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes in the pull request focus on modifying the Changes
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
basininflow/inflow.py
(2 hunks)
🔇 Additional comments (2)
basininflow/inflow.py (2)
217-223
: Verify handling of 3-dimensional datasets
In the if ds.ndim == 3:
block, the code currently has a pass
statement, which means no action is taken for 3D datasets. Ensure that this is the intended behavior and that inflow_df
is correctly processed for 3D datasets without additional modifications.
268-268
: Confirm NetCDF default format compatibility
By not specifying the format
parameter when creating the NetCDF dataset, the code defaults to the NetCDF4 format. Verify that the downstream applications and users can work with this format. If compatibility with NetCDF classic format (NETCDF3_CLASSIC
) is required, consider specifying the format
explicitly.
basininflow/inflow.py
Outdated
elif ds.ndim == 4: | ||
inflow_df = ds.values[:, :, lat_indices, lon_indices] | ||
inflow_df = np.where(np.isnan(inflow_df[:, 0, :]), inflow_df[:, 1, :], inflow_df[:, 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.
Remove unintended trailing comma to fix variable assignment
The trailing comma at the end of line 221 results in inflow_df
being assigned as a tuple containing the array, rather than the array itself. This can cause issues when inflow_df
is used later in the code.
Apply this diff to fix the issue:
-inflow_df = np.where(np.isnan(inflow_df[:, 0, :]), inflow_df[:, 1, :], inflow_df[:, 0, :]),
+inflow_df = np.where(np.isnan(inflow_df[:, 0, :]), inflow_df[:, 1, :], inflow_df[:, 0, :])
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
inflow_df = np.where(np.isnan(inflow_df[:, 0, :]), inflow_df[:, 1, :], inflow_df[:, 0, :]), | |
inflow_df = np.where(np.isnan(inflow_df[:, 0, :]), inflow_df[:, 1, :], inflow_df[:, 0, :]) |
Significantly increased the speed with which this script runs by using fancy xarray indexing to avoid loading unnecessary values. Also removed netcdf classic since we'll be using river route from here on out
Summary by CodeRabbit
New Features
Bug Fixes
Chores