ENH: Add native Meteomatics API support to the Environment class - #1079
Open
Gui-FernandesBR wants to merge 3 commits into
Open
ENH: Add native Meteomatics API support to the Environment class#1079Gui-FernandesBR wants to merge 3 commits into
Gui-FernandesBR wants to merge 3 commits into
Conversation
Gui-FernandesBR
force-pushed
the
enh/545-meteomatics-api
branch
from
July 21, 2026 12:00
2c5b291 to
64030a3
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class Meteomatics Weather API support to RocketPy’s Environment, following the existing “fetcher + process_*_atmosphere” integration style and enabling fully mocked tests/docs for the new workflow.
Changes:
- Implement Meteomatics authentication + grouped profile fetching in
rocketpy/environment/fetchers.py. - Add
Environment.process_meteomatics_atmosphere()and wire"meteomatics"intoset_atmospheric_model()and (de)serialization metadata handling. - Add unit tests (fully mocked), user docs, and a changelog entry for the new API support.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
rocketpy/environment/fetchers.py |
Adds Meteomatics token and atmospheric-profile fetching logic with retries/timeouts and parameter grouping. |
rocketpy/environment/environment.py |
Adds Meteomatics atmospheric model processing and integrates it into the Environment model selection and restore path. |
tests/unit/environment/test_fetchers.py |
Adds mocked unit tests covering Meteomatics token retrieval, grouping/parsing, and error handling. |
tests/unit/environment/test_environment.py |
Adds unit tests validating Meteomatics integration behavior in Environment (profiles, env-var credentials, edge cases). |
docs/user/environment/3-further/other_apis.rst |
Documents Meteomatics usage and configuration options for users. |
CHANGELOG.md |
Records the feature addition in the changelog. |
Gui-FernandesBR
force-pushed
the
enh/545-meteomatics-api
branch
from
July 24, 2026 12:20
64030a3 to
77a28e6
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1079 +/- ##
===========================================
+ Coverage 82.18% 82.44% +0.25%
===========================================
Files 122 122
Lines 16355 16505 +150
===========================================
+ Hits 13441 13607 +166
+ Misses 2914 2898 -16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds a new "meteomatics" atmospheric model to Environment.set_atmospheric_model, porting and generalizing the implementation from the EuRoC-Dev repository. - fetchers.py: fetch_meteomatics_token + fetch_atmospheric_data_from_meteomatics authenticate with username/password (short-lived token), query temperature, pressure and wind components by height above ground level, grouping the parameters to respect the account's per-request limit. - environment.py: process_meteomatics_atmosphere converts the height-AGL data to above-sea-level profiles using the Environment elevation; set_atmospheric_model gains username/password kwargs (falling back to METEOMATICS_USERNAME / METEOMATICS_PASSWORD env vars); save/load handles the new model type. - Network requests use timeouts, do not retry deterministic 4xx failures, and surface actionable RuntimeError messages. - Tests fully mock the API (no real requests, no charges); docs and changelog updated. Closes #545 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follow-up cleanups from the code review of the Meteomatics support:
- Collapse the duplicated request/error ladder of the login and data
endpoints into a single `_meteomatics_request_json` helper.
- Have `_build_meteomatics_parameters` return a {parameter: (profile,
height)} mapping so the response parser no longer regex-parses back
the strings this module just built. Drops the regex constant and the
variable-to-profile table.
- Generalize `to_profile_array` to several profiles at once, so the
wind u/v grid intersection reuses it instead of repeating it inline.
- Reuse the existing `__validate_datetime` helper for the launch-date
check, and simplify the model default to `model or "mix"`.
- Normalize `atmospheric_model_type` once in `from_dict`. The type is
stored as the user spelled it, so the previously case-sensitive
`match` and `== "ensemble"` branches silently dropped the ensemble
arrays for an Environment built with `type="Ensemble"`.
- Trim the elevation warning and raise it before the API call, so it is
shown even when the request later fails.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Gui-FernandesBR
force-pushed
the
enh/545-meteomatics-api
branch
from
July 30, 2026 16:26
d7a8249 to
85b2a92
Compare
Two points raised in the PR review: - `fetch_atmospheric_data_from_meteomatics` stamped the instant with a trailing "Z" without normalizing the timezone, so an aware datetime in a non-UTC zone was sent as the wrong instant. Aware datetimes are now converted to UTC; naive ones are documented as assumed UTC. - Degenerate sampling arguments (`query_limit=0`, resolutions below 2) reached `range()`/`linspace()` and failed with an opaque low-level error after the login had already been paid for. They are now validated up front by `_validate_meteomatics_sampling`. - `process_meteomatics_atmosphere` silently coerced any non-string model to "mix", hiding a mistake such as passing a Dataset or a path as `file` and querying the wrong model. It now accepts None (default) or a string, and raises otherwise. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request type
Checklist
CHANGELOG.mdhas been updatedDescription
Closes #545.
Brings native Meteomatics weather-API support into the
Environmentclass,porting and generalizing the implementation that already lived in the
EuRoC-Devrepository. The API model mirrors the existing Windy integration(a fetcher + a
process_*_atmospheremethod).Usage:
Credentials fall back to the
METEOMATICS_USERNAME/METEOMATICS_PASSWORDenvironment variables when the kwargs are omitted.
What was added
rocketpy/environment/fetchers.pyfetch_meteomatics_token— authenticates with username/password andobtains a short-lived access token.
fetch_atmospheric_data_from_meteomatics— queries temperature, pressureand both wind components at several heights above ground level, grouping
parameters to respect the account's per-request limit.
rocketpy/environment/environment.pyprocess_meteomatics_atmosphere— converts the height-AGL data toabove-sea-level profiles using the
Environmentelevation and sets thepressure/temperature/wind functions.
set_atmospheric_modelgainsusername/passwordkwargs and a"meteomatics"case;to_dict/from_dictround-trips the new type.Notes on the two points raised in the issue
done via
type="Meteomatics".layer (the
requests.getcall in the fetcher tests, and the fetcher itselfin the Environment tests), so no real requests are made.
Robustness
RuntimeErrormessages (invalid model, out-of-range altitude, badcredentials, malformed response); transient/5xx errors are retried with
backoff.
Authentication note
Meteomatics does not use a static API token: you authenticate with a personal
username + password and a short-lived bearer token is generated automatically.
That is what the
username/passwordarguments carry.