PyAPS icon indicating copy to clipboard operation
PyAPS copied to clipboard

possible bug in int2P2H

Open DennyChee opened this issue 1 year ago • 4 comments

the val calculated by the end flag did not make sense as it was calculating a pressure value of ~102 at a higher altitude, which was greater than the previous value of 100 at a lower altitude in test_calc.py

Summary by Sourcery

Bug Fixes:

  • Correct the calculation of pressure values in the intP2H function by changing the operation from subtraction to addition when the end flag is true.

DennyChee avatar Oct 30 '24 01:10 DennyChee

Reviewer's Guide by Sourcery

This PR fixes a bug in the interpolation calculation within the intP2H function. The change modifies the formula used to calculate pressure values at higher altitudes by changing a subtraction operation to an addition, which resolves an issue where pressure values were incorrectly increasing with altitude.

Class diagram for intP2H function changes

classDiagram
    class intP2H {
        - lvls
        - hgt
        - gph
        - tmp
        - vpr
        - cdic
        - verbose
        + intP2H(lvls, hgt, gph, tmp, vpr, cdic, verbose)
        + // Modified calculation for pressure values
    }
    note for intP2H "The calculation for pressure values at higher altitudes was changed from subtraction to addition."

File-Level Changes

Change Details Files
Fixed interpolation formula for pressure calculation at altitude boundaries
  • Changed the sign in the interpolation formula from subtraction to addition
  • Corrected the calculation to prevent illogical pressure increases at higher altitudes
  • Applied the same fix to three identical code blocks handling different cases
src/pyaps3/processor.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

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Oct 30 '24 01:10 sourcery-ai[bot]

PR summary

This Pull Request addresses a potential bug in the intP2H function within the processor.py file. The issue was that the calculation of a pressure value at a higher altitude was incorrectly resulting in a value greater than the pressure at a lower altitude. The fix involves changing the calculation from subtracting to adding a term, which corrects the pressure value computation to reflect a more realistic atmospheric pressure gradient.

Suggestion

To ensure the robustness of this fix, it would be beneficial to add or update unit tests in test_calc.py to verify that the pressure values now decrease with increasing altitude, as expected. This will help prevent similar issues in the future and confirm that the fix works as intended across different scenarios.

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]

codeautopilot[bot] avatar Oct 30 '24 01:10 codeautopilot[bot]

Please provide more description and the value / plot comparison before / after the bugfix proposal.

yunjunz avatar Jan 26 '25 10:01 yunjunz

For the interpolation of pressure values within processor.py, the eFlag interpolation gives ~102 which i think is a wrong value at the highest elevation. I used the test_calc.py data

Screenshot 2025-07-14 at 17 19 16

If my understanding is correct, the interpolated pressure value should be lower than 100 since it is at a higher elevation. After changing the - to +, it gives a lower pressure value

Screenshot 2025-07-14 at 17 21 20

Im not sure if a similar change for the interpolation of temperature and vapor pressure values is needed

DennyChee avatar Jul 14 '25 09:07 DennyChee