Skip to content

Commit 14be14f

Browse files
author
Weatherbench authors
committed
No public description
PiperOrigin-RevId: 585547662
1 parent a613ca7 commit 14be14f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scripts/compute_derived_variables.py

+20
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
--job_name=compute-derived-variables-$USER
3535
```
3636
"""
37+
import ast
3738
from absl import app
3839
from absl import flags
3940
import apache_beam as beam
@@ -90,6 +91,14 @@
9091
' "total_precipitation_6hr" for backwards compatibility.'
9192
),
9293
)
94+
RENAME_VARIABLES = flags.DEFINE_string(
95+
'rename_variables',
96+
None,
97+
help=(
98+
'Dictionary of variable to rename to standard names. E.g. {"2t":'
99+
' "2m_temperature"}'
100+
),
101+
)
93102
WORKING_CHUNKS = flag_utils.DEFINE_chunks(
94103
'working_chunks',
95104
'',
@@ -143,6 +152,17 @@ def main(argv: list[str]) -> None:
143152
{RAW_TP_NAME.value: 'total_precipitation'}
144153
)
145154

155+
rename_variables = (
156+
ast.literal_eval(RENAME_VARIABLES.value)
157+
if RENAME_VARIABLES.value
158+
else None
159+
)
160+
if rename_variables:
161+
source_dataset = source_dataset.rename(rename_variables)
162+
source_chunks = {
163+
rename_variables.get(k, k): v for k, v in source_chunks.items()
164+
}
165+
146166
for var_name in PREEXISTING_VARIABLES_TO_REMOVE.value:
147167
if var_name in source_dataset:
148168
del source_dataset[var_name]

0 commit comments

Comments
 (0)