insarlab / MintPy

Miami InSAR time-series software in Python
https://mintpy.readthedocs.io
Other
618 stars 260 forks source link

`gnss`: handle longitude <=-180 or >=360 #1290

Closed yunjunz closed 2 weeks ago

yunjunz commented 2 weeks ago

Description of proposed changes

This error occurs for the GNSS_UNR sites in Japan, where the longitude of G073 can be -229. In the old code, this results in a NaN value for inc/az_angle extraction from the geometry file.

Reminders

Summary by Sourcery

Ensure longitude values are correctly handled within the GNSS module by introducing a function to set longitude ranges, preventing errors in data processing.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 2 weeks ago

Reviewer's Guide by Sourcery

This PR introduces a new longitude handling mechanism in the GNSS module to properly handle longitude values that fall outside the standard ranges. The implementation adds a new utility function _set_longitude_range() that normalizes longitude values to either (-180, 180] or [0, 360) ranges, and updates all GNSS child classes to use this function.

Class diagram for GNSS longitude handling update

classDiagram
    class GNSS {
        +_set_longitude_range(lon, lon_range)
    }
    class GNSSChild1 {
        +get_site_lat_lon(print_msg)
    }
    class GNSSChild2 {
        +get_site_lat_lon(print_msg)
    }
    class GNSSChild3 {
        +get_site_lat_lon(print_msg)
    }
    GNSS <|-- GNSSChild1
    GNSS <|-- GNSSChild2
    GNSS <|-- GNSSChild3
    note for GNSS "New method _set_longitude_range added to handle longitude normalization"
    note for GNSSChild1 "Updated to use _set_longitude_range for longitude normalization"
    note for GNSSChild2 "Updated to use _set_longitude_range for longitude normalization"
    note for GNSSChild3 "Updated to use _set_longitude_range for longitude normalization"

File-Level Changes

Change Details Files
Added new longitude normalization utility function
  • Implements longitude range normalization to either (-180, 180] or [0, 360)
  • Handles both scalar and numpy array inputs
  • Ensures input values are first normalized to (-180, 360) range before final range conversion
src/mintpy/objects/gnss.py
Updated longitude handling across GNSS classes
  • Replaced direct longitude adjustments with calls to _set_longitude_range()
  • Standardized longitude range to (-180, 180] across all GNSS child classes
  • Added longitude normalization after loading site coordinates
src/mintpy/objects/gnss.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](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
codeautopilot[bot] commented 2 weeks ago

PR summary

This Pull Request addresses a bug in the GNSS module related to handling longitude values that fall outside the typical range, specifically for GNSS_UNR sites in Japan. The changes introduce a new function, standardize_longitude(), which ensures longitude values are standardized within a specified range, either (-180, 180] or [0, 360). This prevents errors such as NaN values during data processing, particularly in the inc/az_angle extraction from geometry files.

Suggestion

Consider adding unit tests for the standardize_longitude() function to ensure its robustness and correctness across various input scenarios. This will help maintain code quality and prevent future regressions. Additionally, updating the documentation to reflect these changes and the new function's usage would be beneficial for users and developers.