Skip to content

Commit 8e4ed99

Browse files
ENH: Support for Open-Meteo API in the Environment class (#1119)
* ENH: add Open-Meteo API fetchers for forecast, history and ensemble Wraps the three Open-Meteo endpoints RocketPy needs to build atmospheric profiles: the forecast API, the historical-forecast API (for past launch dates) and the ensemble API. All of them serve pressure-level data as plain JSON over HTTPS, with no API key and no netCDF/OPeNDAP dependency. Note that Open-Meteo's ERA5 archive endpoint is deliberately not used: it serves surface variables only and answers with nulls at every pressure level, so the historical-forecast API (available from 2021 onwards) is the only archive that can feed a vertical profile. Ensemble models are restricted to the ones that actually publish pressure-level data (gfs05, ecmwf_ifs025, gem_global); the others return HTTP 200 with null values, which would otherwise surface as an opaque failure much later in the parsing step. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * ENH: support Open-Meteo atmospheric models in the Environment class Adds two new atmospheric model types to set_atmospheric_model: env.set_atmospheric_model("open_meteo") # best_match env.set_atmospheric_model("open_meteo", file="ecmwf_ifs025") env.set_atmospheric_model("open_meteo_ensemble", file="gfs05") Both build the usual pressure, temperature and wind profiles from Open-Meteo pressure-level data, so no external files and no netCDF/OPeNDAP libraries are involved. When the launch date is in the past, "open_meteo" transparently queries Open-Meteo's historical-forecast archive instead of the live forecast, which is what makes past-launch reconstruction work without downloading reanalysis files by hand. The ensemble processor stores every member, so select_ensemble_member() and plots.ensemble_member_comparison() work exactly as they do for GEFS. The unsuffixed control run is kept as member 0, matching the documented convention that member 0 is the unperturbed control. Open-Meteo reports wind as speed/direction rather than u/v components, so convert_wind_speed_direction_to_components is added to environment.tools; it converts the meteorological blows-from convention into RocketPy's East/North components. Temperatures are converted from Celsius to Kelvin and pressure levels from hPa to Pa. The model-type gates in the prints and plots classes were comparing capitalised literals ("Ensemble"), which never matched a lower-case type even though set_atmospheric_model documents the argument as case-insensitive. They now compare case-insensitively, so both the new Open-Meteo types and a lower-case "ensemble" report their time period and member count. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * TST: cover the Open-Meteo atmospheric models Adds 44 offline unit tests (tests/unit/environment/test_open_meteo.py) and 6 live integration tests marked slow. The unit tests patch the fetchers, so the whole module runs without network access: verified by re-running the suite with socket.connect blocked, where all 44 still pass. They cover the unit conversions (hPa to Pa, Celsius to Kelvin, speed/direction to u/v), the nearest-hour selection, skipping levels a model does not resolve, altitude sorting, the ensemble member layout with the control run as member 0, the endpoint routing for past versus future dates, error payload handling, and to_dict/from_dict round trips. The wind-component conversion is tested against the four cardinal directions and round-tripped through calculate_wind_heading, since getting that convention wrong would silently flip the wind by 180 degrees. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * FIX: drop gem_global from the usable Open-Meteo ensemble models Verifying the ensemble models against the live API showed gem_global cannot feed a RocketPy profile: it publishes temperature and geopotential height at pressure levels but no pressure-level winds at all (168/168 hours null for wind_speed and wind_direction at every level, at three different launch sites). The earlier check only probed temperature, which is why it looked usable. Accepting it meant "Open-Meteo returned fewer than two usable pressure levels" at profile-build time instead of an actionable message naming the model, so it is now rejected up front alongside gfs025, icon_global and bom_access_global_ensemble. gfs05 (31 members) and ecmwf_ifs025 (51 members) are the two that publish the full set; both member counts are confirmed against the API. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * DOC: document the Open-Meteo atmospheric models Adds docs/user/environment/1-atm-models/open_meteo.rst, covering the forecast, past-launch and ensemble workflows, the model tables, and the caveats worth knowing: coverage of pressure levels varies per model, the historical archive only reaches back to 2021, and Open-Meteo's ERA5 endpoint cannot be used because it serves no pressure-level data. Cross-references were added from the forecast, reanalysis and ensemble pages, since Open-Meteo is the lighter alternative in each of those cases -- notably for ensembles, where the GEFS shortcut is currently unavailable. Every code block in the new page runs as part of the docs build; all five were executed against the live API to confirm they work. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * ENH: warn when a launch date predates the Open-Meteo archive Open-Meteo answers historical requests for unsupported dates with HTTP 200 and null values at every pressure level, so a pre-archive launch date used to surface only as a generic "fewer than two usable pressure levels" error, with no hint that the date itself was the problem. Such dates now raise a warning naming the archive start and pointing at the reanalysis and sounding models. The cutoff was probed against the live API rather than assumed: 2021-03-15 comes back empty while 2021-03-23 is complete, so the archive starts in March 2021 and not in January as the previous constant implied. The constant is now a date instead of a year, and the docs state March 2021. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * MNT: satisfy pylint on the Open-Meteo code paths The CI lint job runs pylint, not just ruff, and flagged the new code: - process_open_meteo_atmosphere and process_open_meteo_ensemble exceeded the statement limit. Rather than suppress it, the profile-storing and member-stacking blocks were extracted into helpers, mirroring the existing _store_meteomatics_* pattern. The two processors now read as a sequence of named steps. - set_atmospheric_model exceeded the branch limit, since the two new model cases added to an already long match. The self-contained pressure_conversion_factor validation moved to a private validator next to the other validators, which also flattens its nested ifs. - Unused-argument and missing-docstring warnings in the new tests, from fakes that deliberately accept the real signature. Behaviour is unchanged: the pressure_conversion_factor error messages and the Open-Meteo profiles were re-verified against the original, and the full unit suite still passes (1954 passed, 16 skipped). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 25271f4 commit 8e4ed99

14 files changed

Lines changed: 1925 additions & 23 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Attention: The newest changes should be on top -->
3232

3333
### Added
3434

35+
- ENH: Support for Open Meteo API in the `Environment` class, adding the `open_meteo` and `open_meteo_ensemble` atmospheric models. Pressure-level forecasts, past forecasts (from 2021 onwards) and ensembles are read straight from a keyless JSON API, with no external files and no netCDF/OPeNDAP dependency. [#520](https://github.com/RocketPy-Team/RocketPy/issues/520)
3536
- ENH: Add simplified opening shock force estimation [#1092](https://github.com/RocketPy-Team/RocketPy/pull/1092)
3637
- ENH: Add Qodo PR-Agent workflow using Google Gemini [#1089](https://github.com/RocketPy-Team/RocketPy/pull/1089)
3738
- ENH: Support for Meteomatics API in the `Environment` class [#1079](https://github.com/RocketPy-Team/RocketPy/pull/1079)
@@ -46,6 +47,7 @@ Attention: The newest changes should be on top -->
4647

4748
### Fixed
4849

50+
- BUG: Report the atmospheric model time period and ensemble member count for lower-case model types. `set_atmospheric_model` documents `type` as case-insensitive, but `Environment.info()` and `all_info()` compared against capitalised literals, so `type="ensemble"` printed no time period and no member count, and skipped the ensemble comparison plot. [#520](https://github.com/RocketPy-Team/RocketPy/issues/520)
4951
- BUG: Give each `CustomSampler` input its own deterministic stream, and seed samplers sharing one generator once as a group. Existing fixed-seed `CustomSampler` baselines change, and samplers built on the legacy `RandomState` must move to `default_rng` because seeds now carry the full 128 bits. [#1102](https://github.com/RocketPy-Team/RocketPy/pull/1102)
5052
- BUG: Accept the callable parachute triggers `StochasticParachute` documents, and reject the ones it cannot mean. An invalid string, an empty list or a boolean now fails during validation instead of reaching `Parachute` or becoming a one-metre height trigger. [#1103](https://github.com/RocketPy-Team/RocketPy/pull/1103)
5153
- BUG: rocket with a late-starting thrust curve never leaves the rail [#1085](https://github.com/RocketPy-Team/RocketPy/pull/1085)

‎docs/user/environment/1-atm-models/ensemble.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Global Ensemble Forecast System (GEFS)
3434
provider (or a local copy), you can still load it explicitly by passing the
3535
dataset path/URL in ``file`` and a compatible mapping in ``dictionary``.
3636

37+
.. tip::
38+
39+
While the ``GEFS`` shortcut is unavailable, Open-Meteo offers the same GEFS
40+
ensemble (plus the ECMWF one) over a plain JSON API, and works with
41+
:meth:`rocketpy.Environment.select_ensemble_member` in exactly the same way.
42+
See :ref:`open_meteo`.
43+
3744

3845
The ``GEFS`` model is a global ensemble forecast system useful for uncertainty
3946
analysis, but RocketPy's automatic ``file="GEFS"`` shortcut is temporarily

‎docs/user/environment/1-atm-models/forecast.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Other generic forecasts can also be imported.
1616
If you want to simulate your rocket launch using past data, you should use \
1717
:ref:`reanalysis` or :ref:`soundings`.
1818

19+
.. tip::
20+
21+
The models on this page are fetched over OPeNDAP, which requires the
22+
``netCDF4`` library and can be slow. For a lighter alternative that serves
23+
the same kind of pressure-level forecast as plain JSON, see
24+
:ref:`open_meteo`.
25+
1926

2027
.. _global-forecast-system:
2128

‎docs/user/environment/1-atm-models/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ environment in the :class:`rocketpy.Environment` class.
1212

1313
Standard Atmosphere <standard_atmosphere.rst>
1414
Custom Atmosphere <custom_atmosphere.rst>
15+
Open-Meteo <open_meteo.rst>
1516
Forecasts <forecast.rst>
1617
Soundings <soundings.rst>
1718
Reanalysis <reanalysis.rst>
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
.. _open_meteo:
2+
3+
Open-Meteo
4+
==========
5+
6+
`Open-Meteo <https://open-meteo.com/>`_ is a weather API that serves
7+
pressure-level forecasts, past forecasts and ensemble forecasts as plain JSON
8+
over HTTPS.
9+
10+
It is often the most convenient weather source in RocketPy, because:
11+
12+
- **No API key** is required for non-commercial use.
13+
- **No heavy dependencies**: unlike the :ref:`forecast` and :ref:`reanalysis`
14+
models, no ``netCDF4``/OPeNDAP download is involved, so requests are quick.
15+
- **No external files**: recent past launches can be reconstructed straight from
16+
the API, without downloading reanalysis files by hand.
17+
- **Many models in one place**: GFS, ECMWF, ICON, MET Norway, Météo-France, JMA,
18+
GEM and UKMO are all reachable through the same interface.
19+
20+
.. note::
21+
22+
Open-Meteo is free for non-commercial use, with a limit on the number of
23+
daily requests. Please read
24+
`their terms <https://open-meteo.com/en/terms>`_ before using it, and
25+
consider their paid plans for heavier or commercial workloads.
26+
27+
28+
Forecasts
29+
---------
30+
31+
Set the atmospheric model to ``open_meteo``. The launch date must be set,
32+
because the vertical profile is taken at the hour closest to it.
33+
34+
.. jupyter-execute::
35+
36+
from datetime import datetime, timedelta
37+
from rocketpy import Environment
38+
39+
tomorrow = datetime.now() + timedelta(days=1)
40+
41+
env = Environment(
42+
date=tomorrow,
43+
latitude=39.3897,
44+
longitude=-8.28896388889,
45+
)
46+
47+
env.set_atmospheric_model(type="open_meteo")
48+
49+
env.plots.atmospheric_model()
50+
51+
Note that ``elevation`` was never specified above: Open-Meteo reports the
52+
elevation of the grid cell it answered for, and RocketPy uses it to set the
53+
launch site elevation automatically.
54+
55+
56+
Selecting a weather model
57+
^^^^^^^^^^^^^^^^^^^^^^^^^
58+
59+
By default RocketPy asks for ``"best_match"``, which lets Open-Meteo pick the
60+
highest-resolution model available for the requested location. A specific model
61+
can be requested through the ``file`` argument:
62+
63+
.. jupyter-execute::
64+
65+
env_ecmwf = Environment(
66+
date=tomorrow,
67+
latitude=39.3897,
68+
longitude=-8.28896388889,
69+
)
70+
env_ecmwf.set_atmospheric_model(type="open_meteo", file="ecmwf_ifs025")
71+
env_ecmwf.plots.atmospheric_model()
72+
73+
Frequently useful models are:
74+
75+
.. list-table::
76+
:header-rows: 1
77+
:widths: 30 70
78+
79+
* - Model
80+
- Description
81+
* - ``best_match``
82+
- Open-Meteo picks the best available model for the location (default).
83+
* - ``gfs_seamless``
84+
- NOAA GFS, global coverage.
85+
* - ``ecmwf_ifs025``
86+
- ECMWF IFS at 0.25°, global coverage.
87+
* - ``icon_seamless``
88+
- DWD ICON, global coverage with a higher-resolution European nest.
89+
* - ``meteofrance_seamless``
90+
- Météo-France ARPEGE/AROME.
91+
* - ``gem_seamless``
92+
- Environment Canada GEM.
93+
* - ``ukmo_seamless``
94+
- UK Met Office.
95+
96+
.. seealso::
97+
98+
The `Open-Meteo documentation <https://open-meteo.com/en/docs>`_ lists every
99+
model available, along with its resolution and update frequency.
100+
101+
.. important::
102+
103+
Not every model resolves every pressure level, and coverage varies with
104+
location. RocketPy silently drops the levels a model does not provide, so
105+
the resulting profile may reach a lower altitude for some models (for
106+
instance, ``ecmwf_ifs025`` tops out at 50 hPa while ``gfs_seamless``
107+
reaches 30 hPa). Check ``env.max_expected_height`` if the ceiling matters
108+
for your simulation.
109+
110+
111+
Past launches
112+
-------------
113+
114+
When the launch date is in the past, ``open_meteo`` transparently queries
115+
Open-Meteo's historical-forecast archive instead of the live forecast. No extra
116+
argument is needed:
117+
118+
.. jupyter-execute::
119+
120+
env_past = Environment(
121+
date=datetime(2024, 1, 10, 12),
122+
latitude=39.3897,
123+
longitude=-8.28896388889,
124+
)
125+
env_past.set_atmospheric_model(type="open_meteo")
126+
env_past.plots.atmospheric_model()
127+
128+
This is the quickest way to reconstruct the atmosphere of a past flight, since
129+
it needs neither an external file nor a sounding station nearby. For
130+
comparison, see :ref:`reanalysis` and :ref:`soundings`.
131+
132+
.. important::
133+
134+
Open-Meteo's historical data is built from its own archived forecast runs
135+
and only covers pressure levels **from around March 2021 onwards**. Earlier
136+
dates return no data, and RocketPy warns you when it detects one; use
137+
:ref:`reanalysis` or :ref:`soundings` for those instead.
138+
139+
.. note::
140+
141+
Open-Meteo also offers an ERA5 archive endpoint, but it serves surface
142+
variables only and provides no pressure-level data, so RocketPy does not
143+
use it: it cannot produce a vertical profile.
144+
145+
146+
Ensemble forecasts
147+
------------------
148+
149+
Open-Meteo also exposes ensemble forecasts, where each member represents a
150+
slightly different evolution of the atmosphere. They are used exactly like the
151+
other :ref:`ensemble_atmosphere` models:
152+
153+
.. jupyter-execute::
154+
155+
env_ensemble = Environment(
156+
date=tomorrow,
157+
latitude=39.3897,
158+
longitude=-8.28896388889,
159+
)
160+
env_ensemble.set_atmospheric_model(type="open_meteo_ensemble", file="gfs05")
161+
162+
print(f"Number of members: {env_ensemble.num_ensemble_members}")
163+
164+
env_ensemble.plots.ensemble_member_comparison()
165+
166+
Individual members are activated with
167+
:meth:`rocketpy.Environment.select_ensemble_member`:
168+
169+
.. jupyter-execute::
170+
171+
env_ensemble.select_ensemble_member(10)
172+
print(f"Wind speed at 1 km: {env_ensemble.wind_speed(1000):.2f} m/s")
173+
174+
Member ``0`` is the unperturbed control run and is the one selected by default.
175+
176+
Two ensemble models publish the complete set of pressure-level variables that
177+
RocketPy needs:
178+
179+
.. list-table::
180+
:header-rows: 1
181+
:widths: 30 20 50
182+
183+
* - Model
184+
- Members
185+
- Description
186+
* - ``gfs05``
187+
- 31
188+
- NOAA GEFS at 0.5° (default).
189+
* - ``ecmwf_ifs025``
190+
- 51
191+
- ECMWF ensemble at 0.25°.
192+
193+
The member counts above include the control run, which RocketPy exposes as
194+
member ``0``.
195+
196+
.. important::
197+
198+
The remaining Open-Meteo ensemble models cannot be used to build a vertical
199+
profile, so RocketPy rejects them with an explanatory error rather than
200+
failing later on. ``gfs025``, ``icon_global`` and
201+
``bom_access_global_ensemble`` answer successfully but return no
202+
pressure-level values at all, and ``gem_global`` provides temperature and
203+
geopotential height but no pressure-level winds.
204+
205+
206+
Further considerations
207+
----------------------
208+
209+
Requests may fail if the API is unreachable or if the daily free-tier limit is
210+
exceeded. RocketPy retries transient failures automatically and raises a
211+
``RuntimeError`` with the reason reported by Open-Meteo when the request cannot
212+
be satisfied.
213+
214+
.. seealso::
215+
216+
- :ref:`forecast` for OPeNDAP-based forecasts (GFS, NAM, RAP, HRRR).
217+
- :ref:`reanalysis` for ERA5 and MERRA-2 reanalysis files.
218+
- :ref:`ensemble_atmosphere` for the ensemble workflow in general.

‎docs/user/environment/1-atm-models/reanalysis.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ intervals
1313
Reanalysis data can be used to set up the environment in RocketPy.
1414
One common reanalysis dataset is the ERA5.
1515

16+
.. tip::
17+
18+
Reanalysis datasets must be downloaded as files before RocketPy can read
19+
them. If you only need the atmospheric conditions of a past launch from
20+
2021 onwards, :ref:`open_meteo` retrieves them straight from an API, with
21+
no file to download.
22+
1623
ERA5
1724
----
1825

0 commit comments

Comments
 (0)