-
-
Notifications
You must be signed in to change notification settings - Fork 224
Enh/automatically download images #896
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
base: develop
Are you sure you want to change the base?
Enh/automatically download images #896
Conversation
tests/integration/simulation/test_monte_carlo_plots_background_kennedy.py
Outdated
Show resolved
Hide resolved
tests/integration/simulation/test_monte_carlo_plots_background_kennedy.py
Outdated
Show resolved
Hide resolved
tests/integration/simulation/test_monte_carlo_plots_background_kennedy.py
Outdated
Show resolved
Hide resolved
tests/integration/simulation/test_monte_carlo_plots_background_kennedy.py
Outdated
Show resolved
Hide resolved
Gui-FernandesBR
left a comment
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.
Impressive work by @C8H10O2 !
Could you update monte carlo documentation and also the monte carlo example notebook to include this new feature?
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
0ee44b9 to
f35dc18
Compare
|
Hi @Gui-FernandesBR , all review comments are addressed, and I've also updated the Monte Carlo documentation and example notebook to include the new feature. |
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.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated 8 comments.
tests/integration/simulation/test_monte_carlo_plots_background.py
Outdated
Show resolved
Hide resolved
|
@C8H10O2 just a few more comments to solve and we are done. Almost there! |
…project.toml and requirements-optional.txt
- Introduced a new method `_get_background_map` to fetch and display background maps using contextily. - Added support for various map types: "satellite", "street", "terrain", and custom contextily providers. - Updated `ellipses` and comparison methods to integrate background maps, enhancing visualization capabilities. - Included error handling and warnings for missing dependencies and attributes. - See issue RocketPy-Team#890
…rlo plots - Added detailed docstring for the _get_background_map method, outlining parameters, return values, and background map options. - Clarified usage of background types including "satellite", "street", "terrain", and contextily providers.
- Moved the import of imageio to be conditional upon the presence of an image, improving dependency management. - This change ensures that imageio is only imported when necessary, optimizing performance and reducing unnecessary imports.
- Enhanced exception handling for various error scenarios when fetching background map tiles, including invalid coordinates, network issues, and image data errors. - Added detailed error messages to guide users on potential causes and solutions for encountered issues.
- Introduced parameterized tests to cover various exception types raised during background map fetching, including ValueError, ConnectionError, and RuntimeError. - Enhanced assertions to verify specific error messages, improving clarity on the nature of failures encountered. - Updated the test for bounds2img to handle different network and image data errors, ensuring comprehensive coverage of edge cases.
- Introduced parameterization for the `test_all_background_options` function to streamline testing of various background map options. - Enhanced the test structure by removing hardcoded background options and utilizing pytest's parameterization feature for improved clarity and maintainability. - Updated docstring to reflect new parameters and their usage in the test.
85b608f to
2e53b53
Compare
|
Hi @Gui-FernandesBR, I've pushed the new changes addressing your latest feedback. Ready for a final look when you have a moment, thanks! |
Gui-FernandesBR
left a comment
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.
LGTM
|
@C8H10O2 can you fix linters and tests please? |
- Moved import statements for numpy and rocketpy.tools to the top of the test functions to adhere to best practices and improve readability. - Added pylint disable comments for imports outside of the top-level to maintain code quality standards.
I fixed the issues with the linters, but regarding the tests, it looks like it's because there is no rasterio wheel package available on Python 3.14. It needs to be compiled from source, and the compilation process depends on GDAL. I think the GitHub Actions configuration needs to be upgraded to automatically install the GDAL library. |
|
@C8H10O2 Is there a way to get the same results with a default RocketPy dependency?I assume that (generally) we should avoid adding new libraries in the interest of optimization. (unless this a specific case @Gui-FernandesBR ? ) |
@Monta120 That is a valid concern regarding optimization, but I believe adding contextily is necessary in this specific case. If we were to implement the map downloading feature manually, we would run into two main issues: 1. Maintenance burden: To allow users to simply pass 2. Redundancy: Building this functionality natively would essentially mean re-implementing contextily from scratch within RocketPy. It feels like "reinventing the wheel" rather than leveraging a library that already handles this efficiently. |
contextily is an optional requirement. No problem. |
|
@C8H10O2 tests are still not passing on CI. Is it passing locally? |
|
I ran the tests locally. They passed (after installing contextily). The PR’s checker fails because the contextily library depends on rasterio, and rasterio needs the GDAL tools (gdal-config) to be installed on the CI machine; since GDAL is missing there, pip cannot build rasterio and aborts during pip install with the “A GDAL API version must be specified” error. What you can do is make the import completely optional in your helper inside monte_carlo_plots.py ( _get_background_map)(so remove the top import) then ask pytest to skip the tests on the machines that don't have contextily installed (using pytest.importorskip). |
Good option. Please proceed with the change but leaving a small comment explaining why the import was moved out of the top of the file |
Hi, The current implementation actually already handles this as you suggested: Instead, I am using: contextily = import_optional_dependency("contextily")By utilizing the existing raise ImportError(
f"{package_name} is an optional dependency and is not installed.\n"
+ f"\t\tUse 'pip install {package_name}' to install it or "
+ "'pip install rocketpy[all]' to install all optional dependencies."
) from exc |
|
I don't understand why the tests are failing on CI then. Sorry if I misunderstood (I work on several projects on GitHub, sometimes my reviews are a bit "too quick but shallow"). @Monta120 how hard would it to require the GDAL installation on CI? Would that mean that every user need to download it before using the feature? |
- Added pytest.importorskip for contextily in both integration and unit test files to ensure tests are only run if the required library is installed.
- Replaced direct import of contextily with pytest.importorskip to ensure tests are skipped if the library is not available, enhancing test robustness.
If it's only added to the CI and not as a dependency then no, users wouldn't need to install it nor would it install automatically when a user clones the rocketpy repository. I also don't believe we as contributors can modify the CI outside of our fork. |
|
@C8H10O2 I think a module level pytest.importorskip would be better (at the top of the file) |
1. The CI Failure: Simply put, rasterio (a dependency of 2. Fixing CI: It shouldn't be too complicated. I will try updating 3. User Impact: For now, yes, users on Python 3.14 would need GDAL installed system-wide. However, this is temporary. According to the rasterio issue #3419, Python 3.14 wheels should be released soon. Once available, users won't need to build from source or install GDAL manually. |
Please check the previous commit, I've already implemented module-level pytest.importorskip in both the unit test and integration test files. |
As I said, I'm not sure you have the required permissions to edit the CI beyond our fork.And if this check passes then there's no need to touch the CI at all. |
|
I will take a look at it during the weekend |
1 similar comment
|
I will take a look at it during the weekend |
|
@Gui-FernandesBR While installing GDAL and compiling Given this, I propose we temporarily restrict the dependency in This ensures contextily is only installed on supported Python versions. I will also update the documentation to reflect this limitation. I have already tested this configuration on my fork, and the CI pipeline passed successfully. If you agree with this solution, please let me know, and I will submit a commit to update pyproject.toml and the documentation. |
|
@C8H10O2 brilliant!! Please move forward with your implementation. If you don't mind... Something we usually do in open-source project when facing problems like that is to raise an issue on the dependency repo so we can follow the development of GDAL binaries for py3.14+windows from the contextly side. |

Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyCHANGELOG.mdhas been updated (if relevant)Current behavior
There is no built-in way to visualize these ellipses against a real-world map background directly within the Python environment (e.g., Jupyter Notebooks or saved logic). Users currently see only a white background with axes, which lacks context regarding the launch site, safety zones, or geographical landmarks.
The only current available option is to manually add a background image to the matplotlib figure.
See issue #890
New behavior
Users may specify the map background provider via the background parameter in
MonteCarlo.plots.ellipses()andMonteCarlo.plots.ellipses_comparison().Currently available options are:
Utilised on-demand imports, with proper handling of projection coordinate system conversions and network errors.
Breaking change