Skip to content

Commit 17ba0a5

Browse files
enssowowens1iluise
authored
Sorcha/dev/571 (ecmwf#957)
* debug for netcdf pipeline * zarr_netcdf first draft * fixing pipeline * linter checks * removing debug prints from io.py * refactoring, found issue with forecast_ref_time * deleting unnecessary lines * proper docstrings * moving filepaths * linting * multithread processing added * debug info * debugging * refactoring * linting * fstep as argument * change assert --------- Co-authored-by: owens1 <owens1@jrlogin09.jureca> Co-authored-by: iluise <72020169+iluise@users.noreply.github.com> Co-authored-by: ilaria luise <luise.ilaria@gmail.com>
1 parent 43eb49b commit 17ba0a5

6 files changed

Lines changed: 733 additions & 3 deletions

File tree

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# This file controls the conversion from Zarr format to CF-compliant NetCDF files in weathergen.evaluate.zarr_nc.zarr_to_netcdf.
2+
# It defines the mapping of variable and dimension names, their standard names, units, and level types.
3+
variables:
4+
q:
5+
var: q
6+
long: specific_humidity_on_pressure_level
7+
std: specific_humidity
8+
wg_unit: kg kg**-1
9+
std_unit: kg kg-1
10+
level_type: pl
11+
t:
12+
var: t
13+
long: temperature_on_pressure_levels
14+
std: air_temperature
15+
wg_unit: K
16+
std_unit: K
17+
level_type: pl
18+
u:
19+
var: u
20+
long: u_wind_on_pressure_levels
21+
std: x_wind
22+
wg_unit: m s**-1
23+
std_unit: m s-1
24+
level_type: pl
25+
v:
26+
var: v
27+
long: v_wind_on_pressure_levels
28+
std: y_wind
29+
wg_unit: m s**-1
30+
std_unit: m s-1
31+
level_type: pl
32+
z:
33+
var: z
34+
long: geopotential_height_on_pressure_levels
35+
std: geopotential_height
36+
wg_unit: m**2 s**-2
37+
std_unit: m
38+
level_type: pl
39+
10u:
40+
var: u10
41+
long: u_wind_at_10m
42+
std: x_wind
43+
wg_unit: m s**-1
44+
std_unit: m s-1
45+
level_type: sfc
46+
10v:
47+
var: v10
48+
long: v_wind_at_10m
49+
std: y_wind
50+
wg_unit: m s**-1
51+
std_unit: m s-1
52+
level_type: sfc
53+
2d:
54+
var: d2m
55+
long: 2m_dewpoint_temperature
56+
std: dew_point_temperature
57+
wg_unit: K
58+
std_unit: K
59+
level_type: sfc
60+
2t:
61+
var: t2m
62+
long: 2m_temperature
63+
std: air_temperature
64+
#near-surface (usually, 2 meter) : https://pcmdi.llnl.gov/mips/cmip3/variableList.html
65+
wg_unit: K
66+
std_unit: K
67+
level_type: sfc
68+
msl:
69+
var: msl
70+
long: mean_sea_level_pressure
71+
std: air_pressure_at_mean_sea_level
72+
wg_unit: Pa
73+
std_unit: Pa
74+
level_type: sfc
75+
skt:
76+
var: skt
77+
# The standard name for skin temperature is sea_surface_skin_temperature, which is defined as "The temperature of the very thin layer at the surface of the sea that is in contact with the atmosphere".
78+
# It is strongly recommended that a variable with this standard name should have a units_metadata attribute, with one of the values "on-scale" or "difference", whichever is appropriate for the data, because it is essential to know whether the temperature is on-scale (meaning relative to the origin of the scale indicated by the units) or refers to temperature differences (implying that the origin of the temperature scale is irrevelant)
79+
long: skin_temperature
80+
std: sea_surface_skin_temperature
81+
wg_unit: K
82+
std_unit: K
83+
level_type: sfc
84+
sp:
85+
var: sp
86+
long: surface_pressure
87+
std: surface_air_pressure
88+
wg_unit: Pa
89+
std_unit: Pa
90+
level_type: sfc
91+
92+
93+
coordinates:
94+
sfc:
95+
valid_time: valid_time
96+
lat: latitude
97+
lon: longitude
98+
stream: stream
99+
forecast_step: forecast_period
100+
forecast_ref_time: forecast_ref_time
101+
pl:
102+
pressure_level: pressure
103+
valid_time: valid_time
104+
lat: latitude
105+
lon: longitude
106+
stream: stream
107+
forecast_step: forecast_period
108+
forecast_ref_time: forecast_ref_time
109+
dimensions:
110+
valid_time:
111+
wg: valid_time
112+
std: time
113+
lat:
114+
wg: latitude
115+
std: latitude
116+
std_unit: degrees_north
117+
lon:
118+
wg: longitude
119+
std: longitude
120+
std_unit: degrees_east
121+
pressure_level:
122+
wg: pressure
123+
std: air_pressure
124+
std_unit: hPa
125+
forecast_ref_time:
126+
wg: forecast_ref_time
127+
std: forecast_ref_time
128+
forecast_step:
129+
wg: forecast_period
130+
std: forecast_period
131+
stream:
132+
wg: stream
133+
std: stream
134+
#TODO maybe absorb stream as an attribute
135+
# forecast_step: forecast_step
136+
# don't want forecast_step anyway
137+

packages/common/src/weathergen/common/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ def _get_model_config_file_name(run_id: str, epoch: int | None):
100100
epoch_str = f"_epoch{epoch:05d}"
101101
return f"model_{run_id}{epoch_str}.json"
102102

103+
def get_model_results(run_id: str, epoch: int, rank: int) -> Path:
104+
"""
105+
Get the path to the model results zarr store from a given run_id and epoch.
106+
"""
107+
run_results = Path(_load_private_conf(None)["path_shared_working_dir"]) / f"results/{run_id}"
108+
zarr_path = run_results / f"validation_epoch{epoch:05d}_rank{rank:04d}.zarr"
109+
if not zarr_path.exists() or not zarr_path.is_dir():
110+
raise FileNotFoundError(f"Zarr file {zarr_path} does not exist or is not a directory.")
111+
return zarr_path
103112

104113
def _apply_fixes(config: Config) -> Config:
105114
"""
@@ -126,7 +135,6 @@ def _check_logging(config: Config) -> Config:
126135

127136
return config
128137

129-
130138
def load_config(
131139
private_home: Path | None,
132140
from_run_id: str | None,

packages/common/src/weathergen/common/io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ def as_xarray(self, chunk_nsamples=CHUNK_N_SAMPLES) -> xr.Dataset:
139139
coords = da.from_zarr(self.coords).compute()
140140
times = da.from_zarr(self.times).compute()
141141
geoinfo = da.from_zarr(self.geoinfo).compute()
142-
143142
geoinfo = {name: ("ipoint", geoinfo[:, i]) for i, name in enumerate(self.geoinfo_channels)}
144143
# TODO: make sample, stream, forecast_step DataArray attribute, test how it
145144
# interacts with concatenating

packages/evaluate/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dev = [
2323

2424
[project.scripts]
2525
evaluation = "weathergen.evaluate.run_evaluation:evaluate"
26-
26+
export = "weathergen.evaluate.export_inference:export"
2727

2828
[tool.ruff.lint]
2929
# All disabled until the code is formatted.

0 commit comments

Comments
 (0)