Rel/v1.12.0 by MateusStano · Pull Request #935 · RocketPy-Team/RocketPy

@C8H10O2

* ENH: Add contextily as a dependency for Monte Carlo simulations in pyproject.toml and requirements-optional.txt

* ENH: Add background map functionality to Monte Carlo plots

- 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 #890

* DOC: Enhance documentation for _get_background_map method in Monte Carlo 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.

* MNT: Move imageio import to conditional block in _MonteCarloPlots class

- 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.

* TST: Add unit tests for ellipses background functionality in Monte Carlo plots

- Introduced a new test file to validate the behavior of the `ellipses` method with various background options including None, satellite, street, terrain, and custom providers.
- Implemented tests to ensure proper error handling when the MonteCarlo object lacks necessary attributes.
- Added checks for warnings when contextily is not installed and verified that images take precedence over backgrounds.

* TST: Add integration test for Monte Carlo background map options at Kennedy Space Center

- Introduced a new test script to visualize and validate various background map options for Monte Carlo simulations at Kennedy Space Center.
- The script generates simulated data and tests background options including None, satellite, street, terrain, and custom providers, saving the results as images.

* DOC: Updated CHANGELOG.md

* STY: Reformat with black

* MNT: Fix wrong usage for set_aspect in _MonteCarloPlots.ellipses_comparison

* MNT: Refactor _get_background_map in _MonteCarloPlots class

- Removed unnecessary else statements and improved indentation issues.

* MNT: Move mercator_to_wgs84 from_MonteCarloPlots class to tools

- Removed the local definition of mercator_to_wgs84 and replaced it with an import from tools.
- Updated calls to mercator_to_wgs84 to include the earth_radius parameter for improved accuracy.

* MNT: Decompose _get_background_map and move utilities to tools.py

- Refactors `_get_background_map` into modular functions and extracts shared utility logic into `tools.py`. This significantly improves maintainability and separation of concerns.

* BUG: Fix map alignment by enforcing standard Earth radius in plots

- Previously, `_get_environment_coordinates` retrieved the Earth radius
directly from the environment object. When simulations utilized a
custom or local Earth radius for high-precision physics, this value was
incorrectly applied to the map projection calculations.

- Since background map providers (like Contextily) rely on the standard
Web Mercator projection (based on ~6,378,137m), using a non-standard
radius caused the background map to be shifted or scaled incorrectly
relative to the scatter plot data.

- This change forces the plotting module to use the standard WGS84 radius.
This ensures visual accuracy for map overlays without affecting the
physical integrity of the simulation data itself.

* TST: Add Kennedy Space Center environment fixture

- Add example_kennedy_env fixture to replace create_kennedy_environment helper function in tests. This follows the same pattern as other environment fixtures and improves test consistency.
- Make test_all_background_options() a a parametrized test.
- Remove main from test

* ENH: Improve error handling and documentation for automatically download background
- Enhanced error messages for missing or invalid map providers, providing clearer guidance on potential issues.
- Removed warnings for missing contextily library and replaced them with exceptions to enforce required dependencies.
- Updated docstring to include raised exceptions and clarify the function's behavior when fetching background maps.

* TST: Enhance Monte Carlo background map unit tests

- Refactored tests to improve error handling for missing environment attributes and invalid map providers.
- Replaced warnings with exceptions for missing dependencies, ensuring stricter validation.
- Added assertions to verify error messages for better clarity on issues encountered during background map fetching.
- Introduced new tests for handling network errors and invalid map provider scenarios.

* TST: Refactor Monte Carlo plot tests with mock class

- Introduced a MockMonteCarlo class to simulate Monte Carlo data for testing background map options without real simulations.
- Updated tests to utilize the MockMonteCarlo, improving clarity and maintainability.
- Simplified environment handling in tests by creating a SimpleEnvironment class for latitude and longitude attributes.
- Enhanced error handling and assertions in tests for various background map scenarios.

* DOC: Add background map options to documentation

- Updated the user documentation for the Monte Carlo simulations to include details on the new ``background`` parameter for displaying various map types.
- Provided examples for using satellite, street, and terrain maps, along with instructions for listing available providers.

* DOC: Update Monte Carlo analysis notebook with background parameter

* REV: Remove background documents form mrs.rst

* TST: Refactor Monte Carlo plot tests to remove cleanup function

- Since we switched to MockMonteCarlo for testing. Since it does not inherit MonteCarlo.__init__(), no files that need cleanup are produced.
- Removed the `_post_test_file_cleanup` function to streamline test cases.
- Updated tests to directly handle file cleanup for test_ellipses_background_save.

* TST: Enhance Monte Carlo plot tests with file cleanup

- Added file cleanup functionality to the Monte Carlo plot tests to ensure generated files are removed after execution.

* DOC: Update docstring for background map provider resolution

- Enhanced the docstring for the background map provider function to include details on potential ValueError exceptions.

* ENH: Improve error handling in Monte Carlo background map fetching

- 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.

* TST: Parameterize tests for bounds2img failure scenarios

- 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.

* TST: Parameterize background map option tests in Monte Carlo plots

- 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.

* MNT: Formatting monte_carlo_class_usage.ipynb with ruff

* TST: Refactor imports in Monte Carlo plot tests for consistency

- 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.

* TST: Skip tests requiring contextily in Monte Carlo plot tests

- Added pytest.importorskip for contextily in both integration and unit test files to ensure tests are only run if the required library is installed.

* TST: Update contextily import in Monte Carlo plot tests

- Replaced direct import of contextily with pytest.importorskip to ensure tests are skipped if the library is not available, enhancing test robustness.

* Update contextily dependency in pyproject.toml and requirements-optional.txt

- Modified contextily dependency in pyproject.toml to conditionally require it for Python versions below 3.14.

* DOC: Update monte_carlo_class_usage.ipynb to note about contextily issue on python 3.14