1010# weathergen-common = { path = "../../../../../packages/common" }
1111# weathergen = { path = "../../../../../" }
1212# ///
13- ## Example USAGE: uv run export --run-id grwnhykd --stream ERA5 --output-dir /p/home/jusers/owens1/jureca/WeatherGen/test_output1 --format netcdf --type prediction target --fsteps 1 --samples 1
13+ ## Example USAGE: uv run export --run-id grwnhykd --stream ERA5 \
14+ ## --output-dir /p/home/jusers/owens1/jureca/WeatherGen/test_output1 \
15+ ## --format netcdf --type prediction target --fsteps 1 --samples 1
1416import argparse
1517import logging
1618import re
@@ -66,9 +68,11 @@ def find_pl(all_variables: list) -> tuple[dict[str, list[str]], list[int]]:
6668 """
6769 Find all the pressure levels for each variable using regex and returns a dictionary
6870 mapping variable names to their corresponding pressure levels.
71+
6972 Parameters
7073 ----------
7174 all_variables : list of variable names with pressure levels (e.g.,'q_500','t_2m').
75+
7276 Returns
7377 -------
7478 A tuple containing:
@@ -333,14 +337,17 @@ def output_filename(
333337 forecast_ref_time : np .datetime64 ,
334338) -> Path :
335339 """
336- Generate output filename based on prefix (should refer to type e.g. pred/targ), run_id, sample index, output directory, format and forecast_ref_time.
340+ Generate output filename based on prefix (should refer to type e.g. pred/targ), run_id, sample
341+ index, output directory, format and forecast_ref_time.
342+
337343 Parameters
338344 ----------
339345 prefix : Prefix for file name (e.g., 'pred' or 'targ').
340346 run_id :Run ID to include in the filename.
341347 output_dir : Directory to save the output file.
342348 output_format : Output file format (currently only 'netcdf' supported).
343349 forecast_ref_time : Forecast reference time to include in the filename.
350+
344351 Returns
345352 -------
346353 Full path to the output file.
@@ -358,9 +365,11 @@ def output_filename(
358365def get_data_worker (args : tuple ) -> xr .DataArray :
359366 """
360367 Worker function to retrieve data for a single sample and forecast step.
368+
361369 Parameters
362370 ----------
363371 args : Tuple containing (sample, fstep, run_id, stream, type).
372+
364373 Returns
365374 -------
366375 xarray DataArray for the specified sample and forecast step.
@@ -397,18 +406,30 @@ def get_data(
397406
398407 Parameters
399408 ----------
400- run_id : Run ID to identify the Zarr store.
401- samples : Sample to process
402- stream : Stream name to retrieve data for (e.g., 'ERA5').
403- type : Type of data to retrieve ('target' or 'prediction').
404- fsteps : List of forecast steps to retrieve. If None, retrieves all available forecast steps.
405- channels :List of channels to retrieve. If None, retrieves all available channels.
406- n_processes : Number of parallel processes to use for data retrieval.
407- ecpoch : Epoch number to identify the Zarr store.
408- rank : Rank number to identify the Zarr store.
409- output_dir : Directory to save the NetCDF files.
410- output_format : Output file format (currently only 'netcdf' supported).
411- config : Loaded config for cf_parser function.
409+ run_id : str
410+ Run ID to identify the Zarr store.
411+ samples : list
412+ Sample to process
413+ stream : str
414+ Stream name to retrieve data for (e.g., 'ERA5').
415+ dtype : str
416+ Type of data to retrieve ('target' or 'prediction').
417+ fsteps : list
418+ List of forecast steps to retrieve. If None, retrieves all available forecast steps.
419+ channels : list
420+ List of channels to retrieve. If None, retrieves all available channels.
421+ n_processes : list
422+ Number of parallel processes to use for data retrieval.
423+ ecpoch : int
424+ Epoch number to identify the Zarr store.
425+ rank : int
426+ Rank number to identify the Zarr store.
427+ output_dir : str
428+ Directory to save the NetCDF files.
429+ output_format : str
430+ Output file format (currently only 'netcdf' supported).
431+ config : OmegaConf
432+ Loaded config for cf_parser function.
412433 """
413434 if dtype not in ["target" , "prediction" ]:
414435 raise ValueError (f"Invalid type: { dtype } . Must be 'target' or 'prediction'." )
@@ -451,7 +472,8 @@ def get_data(
451472 f"{ list (set (channels ) - set (existing_channels ))} . Skipping them."
452473 )
453474 result = result .sel (channel = existing_channels )
454- # reshape result - use adaptive function to handle both regular and Gaussian grids
475+ # reshape result - use adaptive function to handle both regular and Gaussian
476+ # grids
455477 result = reshape_dataset_adaptive (result )
456478 da_fs .append (result )
457479
@@ -484,12 +506,14 @@ def save_sample_to_netcdf(
484506) -> None :
485507 """
486508 Uses list of pred/target xarray DataArrays to save one sample to a NetCDF file.
509+
487510 Parameters
488511 ----------
489512 type_str : str
490513 Type of data ('pred' or 'targ') to include in the filename.
491514 dict_sample_all_steps : dict
492- Dictionary where keys is sample index and values is a list of xarray DataArrays for all the forecast steps
515+ Dictionary where keys is sample index and values is a list of xarray DataArrays
516+ for all the forecast steps
493517 fstep_hours : np.timedelta64
494518 Time difference between forecast steps (e.g., 6 hours).
495519 run_id : str
@@ -595,7 +619,8 @@ def parse_args(args: list) -> argparse.Namespace:
595619 type = int ,
596620 nargs = "+" ,
597621 default = None ,
598- help = "List of forecast steps to retrieve (e.g. 1 2 3). If not provided, retrieves all available forecast steps." ,
622+ help = "List of forecast steps to retrieve (e.g. 1 2 3). "
623+ "If not provided, retrieves all available forecast steps." ,
599624 )
600625
601626 parser .add_argument (
@@ -611,7 +636,8 @@ def parse_args(args: list) -> argparse.Namespace:
611636 type = str ,
612637 nargs = "+" ,
613638 default = None ,
614- help = "List of channels to retrieve (e.g., 'q_500 t_2m'). If not provided, retrieves all available channels." ,
639+ help = "List of channels to retrieve (e.g., 'q_500 t_2m'). "
640+ "If not provided, retrieves all available channels." ,
615641 )
616642
617643 parser .add_argument (
0 commit comments