Skip to content

ENH: Add native Meteomatics API support to the Environment class#1079

Open
Gui-FernandesBR wants to merge 2 commits into
developfrom
enh/545-meteomatics-api
Open

ENH: Add native Meteomatics API support to the Environment class#1079
Gui-FernandesBR wants to merge 2 commits into
developfrom
enh/545-meteomatics-api

Conversation

@Gui-FernandesBR

Copy link
Copy Markdown
Member

Pull request type

  • Code changes (feature, bug fix, etc.)

Checklist

  • Tests have been added (fully mocked — no real API calls, no charges)
  • Docs have been added / updated
  • CHANGELOG.md has been updated

Description

Closes #545.

Brings native Meteomatics weather-API support into the Environment class,
porting and generalizing the implementation that already lived in the
EuRoC-Dev repository. The API model mirrors the existing Windy integration
(a fetcher + a process_*_atmosphere method).

Usage:

env.set_atmospheric_model(
    type="Meteomatics",
    file="mix",              # Meteomatics weather model
    username="your_username",
    password="your_password",
)

Credentials fall back to the METEOMATICS_USERNAME / METEOMATICS_PASSWORD
environment variables when the kwargs are omitted.

What was added

  • rocketpy/environment/fetchers.py
    • fetch_meteomatics_token — authenticates with username/password and
      obtains a short-lived access token.
    • fetch_atmospheric_data_from_meteomatics — queries temperature, pressure
      and both wind components at several heights above ground level, grouping
      parameters to respect the account's per-request limit.
  • rocketpy/environment/environment.py
    • process_meteomatics_atmosphere — converts the height-AGL data to
      above-sea-level profiles using the Environment elevation and sets the
      pressure/temperature/wind functions.
    • set_atmospheric_model gains username / password kwargs and a
      "meteomatics" case; to_dict / from_dict round-trips the new type.

Notes on the two points raised in the issue

  1. Allow users to use the Meteomatics API when creating Environment objects
    done via type="Meteomatics".
  2. Test the feature without being charged — every test fully mocks the HTTP
    layer (the requests.get call in the fetcher tests, and the fetcher itself
    in the Environment tests), so no real requests are made.

Robustness

  • Network requests use timeouts.
  • Deterministic client errors (4xx) are not retried and surface actionable
    RuntimeError messages (invalid model, out-of-range altitude, bad
    credentials, 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 / password arguments carry.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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" into set_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.

Comment on lines +721 to +726
if max_altitude <= min_altitude:
raise ValueError("max_altitude must be greater than min_altitude.")

token = fetch_meteomatics_token(username, password)

date_string = date.strftime("%Y-%m-%dT%H:%M:%SZ")
If credentials are missing, if no launch date is set, or if the API
returns no usable data.
"""
model = model if isinstance(model, str) else "mix"
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>
@Gui-FernandesBR
Gui-FernandesBR force-pushed the enh/545-meteomatics-api branch from 64030a3 to 77a28e6 Compare July 24, 2026 12:20
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.24806% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.44%. Comparing base (e0ff281) to head (d7a8249).
⚠️ Report is 15 commits behind head on develop.

Files with missing lines Patch % Lines
rocketpy/environment/fetchers.py 87.17% 10 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

CI now installs ruff 0.16.0 (unpinned), which formats Python code inside
Markdown fenced blocks. README.md predates this and fails `ruff format
--check .`, blocking the lint job on every open PR. Reformat it here (4-space
indent, double quotes, no logic change) so this PR's lint is green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants