@@ -42,7 +42,7 @@ def check_reftime_consistency(tarfiles: list[Path], delta_h: int = 12):
4242
4343
4444def extract (
45- tar : Path , lead_time : list [int ], run_id : str , params : list [str ]
45+ tar : Path , lead_times : list [int ], run_id : str , params : list [str ]
4646) -> xr .Dataset :
4747 LOG .info (f"Extracting fields from { tar } ." )
4848 reftime = reftime_from_tarfile (tar )
@@ -54,7 +54,7 @@ def extract(
5454 raise ValueError ("Currently only COSMO-E and COSMO-1E are supported." )
5555 tar_archive = tarfile .open (tar , mode = "r:*" )
5656 out = ekd .SimpleFieldList ()
57- for lt in lead_time :
57+ for lt in lead_times :
5858 filename = f"{ tar .stem } /grib/{ gribname } { lt :03} _{ run_id } "
5959 LOG .info (f"Extracting { filename } ." )
6060 stream = tar_archive .extractfile (filename )
@@ -79,23 +79,19 @@ def extract(
7979class ScriptConfig (Namespace ):
8080 archive_dir : Path
8181 output_store : Path
82- lead_time : int
82+ steps : list [ int ]
8383 run_id : str
8484 params : list [str ]
8585
8686
87- def _parse_lead_time (lead_time : str ) -> int :
88- # check that lead_time is in the format "start/stop/step"
89- if "/" not in lead_time :
90- raise ValueError (
91- f"Expected lead_time in format 'start/stop/step', got '{ lead_time } '"
92- )
93- if len (lead_time .split ("/" )) != 3 :
94- raise ValueError (
95- f"Expected lead_time in format 'start/stop/step', got '{ lead_time } '"
96- )
97-
98- return list (range (* map (int , lead_time .split ("/" ))))
87+ def _parse_steps (steps : str ) -> int :
88+ # check that steps is in the format "start/stop/step"
89+ if "/" not in steps :
90+ raise ValueError (f"Expected steps in format 'start/stop/step', got '{ steps } '" )
91+ if len (steps .split ("/" )) != 3 :
92+ raise ValueError (f"Expected steps in format 'start/stop/step', got '{ steps } '" )
93+ start , end , step = map (int , steps .split ("/" ))
94+ return list (range (start , end + 1 , step ))
9995
10096
10197def main (cfg : ScriptConfig ):
@@ -135,7 +131,7 @@ def main(cfg: ScriptConfig):
135131
136132 for i in indices :
137133 file = tarfiles [i ]
138- ds = extract (file , cfg .lead_time , cfg .run_id , cfg .params )
134+ ds = extract (file , cfg .steps , cfg .run_id , cfg .params )
139135
140136 LOG .info (f"Extracted: { ds } " )
141137
@@ -167,7 +163,7 @@ def main(cfg: ScriptConfig):
167163 help = "Path to the output zarr store." ,
168164 )
169165
170- parser .add_argument ("--lead_time " , type = _parse_lead_time , default = "0/126 /6" )
166+ parser .add_argument ("--steps " , type = _parse_steps , default = "0/120 /6" )
171167
172168 parser .add_argument ("--run_id" , type = str , default = "000" )
173169
@@ -193,10 +189,10 @@ def main(cfg: ScriptConfig):
193189python workflow/scripts/extract_baseline_fct.py \
194190 --archive_dir /archive/mch/msopr/osm/COSMO-E/FCST20 \
195191 --output_store /store_new/mch/msopr/ml/COSMO-E/FCST20.zarr \
196- --lead_time 0/126 /6
192+ --steps 0/120 /6
197193
198194python workflow/scripts/extract_baseline_fct.py \
199195 --archive_dir /archive/mch/s83/osm/from_GPFS/COSMO-1E/FCST20 \
200196 --output_store /store_new/mch/msopr/ml/COSMO-1E/FCST20.zarr \
201- --lead_time 0/34 /1
197+ --steps 0/33 /1
202198"""
0 commit comments