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

ENH: add Function.low_pass_filter method #508

Merged
merged 13 commits into from
Dec 17, 2023
Merged

Conversation

kalounis
Copy link
Contributor

@kalounis kalounis commented Dec 8, 2023

Pull request type

  • Code changes (bugfix, features)

Checklist

  • Tests for the changes have been added (if needed)
  • Docs have been reviewed and added / updated
  • Lint (black rocketpy/ tests/) has passed locally
  • All tests (pytest --runslow) have passed locally

Current behavior

There were no functions to smooth a Function object.

New behavior

We added a "low_pass_filter" method applying an exponential smoothing to a Function object. This function takes a parameter "alpha" you have to chose to smooth the function.

Breaking change

  • No

Additional information

For a given dataset, the larger alpha is, the more closely the filtered function returned will match the function
the smaller alpha is, the smoother the filtered function returned will be (but with a phase shift)

Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

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

Overall good Work here! I've made a few suggestions in terms of formatting, the idea is to improve the code readability.

Are you familiar with unit tests? I think it would be nice to have a simple test for the new method.

We can help with that if needed.

Thanks for submitting your first PR, I think this will really improve rocketpy!

rocketpy/mathutils/function.py Outdated Show resolved Hide resolved
rocketpy/mathutils/function.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 8, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1a822a3) 71.16% compared to head (7eb4a73) 71.16%.
Report is 18 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #508      +/-   ##
===========================================
- Coverage    71.16%   71.16%   -0.01%     
===========================================
  Files           55       55              
  Lines         9273     9279       +6     
===========================================
+ Hits          6599     6603       +4     
- Misses        2674     2676       +2     
Flag Coverage Δ
unittests 71.16% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@styris00
Copy link
Contributor

styris00 commented Dec 8, 2023

Overall good Work here! I've made a few suggestions in terms of formatting, the idea is to improve the code readability.

Are you familiar with unit tests? I think it would be nice to have a simple test for the new method.

We can help with that if needed.

Thanks for submitting your first PR, I think this will really improve rocketpy!

We knew we would have to create some tests at some point but are not familiar with this in python and we do not really know how tests work in RocketPy as well, so we decided to wait to do it with you.

@Gui-FernandesBR Gui-FernandesBR changed the title Enh/filter method ENH: add Function.low_pass_filter method Dec 8, 2023
@Gui-FernandesBR
Copy link
Member

Overall good Work here! I've made a few suggestions in terms of formatting, the idea is to improve the code readability.
Are you familiar with unit tests? I think it would be nice to have a simple test for the new method.
We can help with that if needed.
Thanks for submitting your first PR, I think this will really improve rocketpy!

We knew we would have to create some tests at some point but are not familiar with this in python and we do not really know how tests work in RocketPy as well, so we decided to wait to do it with you.

That's fine. What you would need to do is basically:

  • go to the tests/unit/test_function.py file and
  • create a test_low_pass_filter method.
  • In this method, make sure you use the low_pass_filter to generate a Function object and guarantee this Function is giving correct results.
  • You could assert expected results are within a certain error limit.

My recommendations: first test the type of the return of the method, something like: assert isinstance(res, Function). Sencondly, try to test the function with the extreme values of alpha (0 and 1), and later test with arbitrary values of alpha as well.

We can give more details if you need. @lucasfourier is also currently studying unit tests creation and he could support you as well.

@styris00 styris00 linked an issue Dec 17, 2023 that may be closed by this pull request
@Gui-FernandesBR Gui-FernandesBR added the Enhancement New feature or request, including adjustments in current codes label Dec 17, 2023
Copy link
Member

@Gui-FernandesBR Gui-FernandesBR left a comment

Choose a reason for hiding this comment

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

Great work, this method will be very useful when dealing with real world data.
Thank you again for your contributions!

I've made the two latest commits and rebased the branch, please review it and merge it in your earliest convenience.

@kalounis kalounis merged commit 8a7ab31 into develop Dec 17, 2023
12 of 13 checks passed
@kalounis kalounis deleted the enh/filter-method branch December 17, 2023 19:50
@Gui-FernandesBR Gui-FernandesBR added this to the Release v1.X.0 milestone Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request, including adjustments in current codes
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

ENH: Function filters
5 participants