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

Removes np.nan in output of spatial_filter.py #1292

Closed
wants to merge 1 commit into from

Conversation

bjmarfito
Copy link
Contributor

@bjmarfito bjmarfito commented Nov 12, 2024

Description of proposed changes

Removes np.nan when using spatial_filter.py. This is useful to generate velocity using timeseries2velocity.py.

Reminders

  • Fix #xxxx
  • Pass Pre-commit check (green)
  • Pass Codacy code review (green)
  • Pass Circle CI test (green)
  • Make sure that your code follows our style. Use the other functions/files as a basis.
  • If modifying functionality, describe changes to function behavior and arguments in a comment below the function declaration.
  • If adding new functionality, add a detailed description to the documentation and/or an example.

Summary by Sourcery

Bug Fixes:

  • Remove np.nan values from the output of spatial_filter.py to ensure compatibility with timeseries2velocity.py.

Copy link

sourcery-ai bot commented Nov 12, 2024

Reviewer's Guide by Sourcery

The PR modifies the spatial filtering functionality to handle NaN values by zeroing them out after filtering. This change is implemented by adding a single line of code that multiplies the filtered data with a boolean mask where NaN values are False.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Modified spatial filtering to handle NaN values by converting them to zeros
  • Added multiplication with boolean mask (~np.isnan(data)) to convert NaN values to zeros after filtering
  • Ensures compatibility with timeseries2velocity.py processing
src/mintpy/spatial_filter.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codeautopilot bot commented Nov 12, 2024

PR summary

This Pull Request addresses the issue of np.nan values in the output of the spatial_filter.py script. By removing these np.nan values, the script's output becomes more suitable for subsequent processing, such as generating velocity using timeseries2velocity.py. The change involves a simple modification where the data is multiplied by the negation of its np.isnan result, effectively setting np.nan values to zero.

Suggestion

To ensure robustness, consider adding a test case to verify that the removal of np.nan values does not inadvertently alter valid data. Additionally, it might be beneficial to include a comment in the code explaining the purpose of the data *= ~np.isnan(data) line for future maintainers.

Disclaimer: This comment was entirely generated using AI. Be aware that the information provided may be incorrect.

Current plan usage: 0.00%

Have feedback or need help?
Discord
Documentation
[email protected]

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 @bjmarfito - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The NaN handling could be more explicit - consider using np.nan_to_num() or np.where() instead of boolean multiplication. This would make the intention clearer.
  • Please document this behavior change in the function's docstring, explaining what happens to NaN values and why this change was needed.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 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 and I'll use the feedback to improve your reviews.

@yunjunz yunjunz self-requested a review November 15, 2024 03:23
Copy link
Member

@yunjunz yunjunz left a comment

Choose a reason for hiding this comment

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

I don't get the intention here, this line of change won't do anything, from my simple testing. Could you clarify? and add some inline comment or a new option instead?

@bjmarfito
Copy link
Contributor Author

Hi @yunjunz, after looking at the code, I found out that adding this line of code does not solve the issue of generating velocity using timeseries2velocity.py after using spatial_filter.py. Need to look in-depth regarding this problem.

Closing this PR.

@bjmarfito bjmarfito closed this Nov 15, 2024
@bjmarfito bjmarfito deleted the bjmarfito-patch-1 branch November 21, 2024 01:37
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.

2 participants