Skip to content

Commit d538d42

Browse files
uniKorqi422Copilot
andauthored
Update docs/notebooks/era5_to_rocketpy_patch.py
Co-authored-by: Copilot <[email protected]>
1 parent 7573d87 commit d538d42

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

docs/notebooks/era5_to_rocketpy_patch.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,45 @@
88
import os
99

1010
def create_era5_compatible_surface(input_path, output_path, target_lat, target_lon):
11-
"""Patch ERA5 surface data to be RocketPy-compatible."""
11+
"""
12+
Patch ERA5 surface data to be RocketPy-compatible for RocketPy EnvironmentAnalysis.
13+
14+
This function loads an ERA5 NetCDF surface file, renames and adds required variables,
15+
snaps the data to the nearest grid point to the target latitude and longitude, and
16+
writes the patched dataset to a new NetCDF file.
17+
18+
Parameters
19+
----------
20+
input_path : str
21+
Path to the input ERA5 NetCDF surface file.
22+
output_path : str
23+
Path to the output patched NetCDF file.
24+
target_lat : float
25+
Target latitude (in degrees) to snap to the nearest grid point.
26+
target_lon : float
27+
Target longitude (in degrees) to snap to the nearest grid point.
28+
29+
Returns
30+
-------
31+
best_lat : float
32+
Latitude of the nearest grid point to the target latitude.
33+
best_lon : float
34+
Longitude of the nearest grid point to the target longitude.
35+
36+
Raises
37+
------
38+
FileNotFoundError
39+
If the input_path does not exist.
40+
KeyError
41+
If required variables (e.g., 'u10', 'latitude', 'longitude') are missing from the dataset.
42+
43+
Example
44+
-------
45+
>>> best_lat, best_lon = create_era5_compatible_surface(
46+
... "input_surface.nc", "patched_surface.nc", -23.5, -46.6
47+
... )
48+
>>> print(best_lat, best_lon)
49+
"""
1250
print(f"Loading ERA5 surface: {input_path}")
1351
ds = xr.open_dataset(input_path)
1452

0 commit comments

Comments
 (0)