credit.output#

Content:
  • load_metadata()

  • make_xarray()

  • save_netcdf_increment()

Attributes#

Functions#

load_metadata(conf)

Load metadata attributes from yaml file in credit/metadata directory.

split_and_reshape(tensor, conf)

Split the output tensor of the model to upper air variables and diagnostics/surface variables.

make_xarray(pred, forecast_datetime, lat, lon, conf)

Create two xarray.DataArray objects for upper air and surface variables.

make_xarray_diag(pred, forecast_datetime, lat, lon, conf)

save_netcdf_increment(darray_upper_air, ...)

Save CREDIT model prediction output to netCDF file. Also performs pressure level

save_netcdf_clean(darray_upper_air, ...[, use_logger])

Save forecast data (upper-air and optionally single-level variables) to a NetCDF file.

save_netcdf_diag(darray_single_level, nc_foldername, ...)

Module Contents#

credit.output.logger#
credit.output.load_metadata(conf)#

Load metadata attributes from yaml file in credit/metadata directory.

If the configured path is a bare filename (no directory separators), it is resolved against the installed credit.metadata package directory so users don’t need to hard-code absolute paths.

By default the function will assume era5.yaml as the default metadata file.

credit.output.split_and_reshape(tensor, conf)#

Split the output tensor of the model to upper air variables and diagnostics/surface variables.

Upperair level arrangement: top-of-atmosphere–> near-surface –> single layer An example: U (top-of-atmosphere) –> U (near-surface) –> V (top-of-atmosphere) –> V (near-surface) The shape of the output tensor is (variables, latitude, longitude)

Parameters:
  • tensor – PyTorch Tensor containing output of the AI NWP model

  • conf – config file for the model

credit.output.make_xarray(pred, forecast_datetime, lat, lon, conf)#

Create two xarray.DataArray objects for upper air and surface variables.

Parameters:
  • pred (torch.Tensor or np.ndarray) – Prediction tensor containing both upper air and surface variables.

  • forecast_datetime (datetime) – The forecast initialization datetime.

  • lat (np.ndarray or list) – Latitude values.

  • lon (np.ndarray or list) – Longitude values.

  • conf (dict) – Configuration dictionary containing details about the data structure

  • variables. (and)

Returns:

DataArray containing upper air variables with dimensions

[time, vars, level, latitude, longitude].

darray_single_level (xarray.DataArray): DataArray containing surface variables with dimensions

[time, vars, latitude, longitude].

Return type:

darray_upper_air (xarray.DataArray)

credit.output.make_xarray_diag(pred, forecast_datetime, lat, lon, conf)#
credit.output.save_netcdf_increment(darray_upper_air: xarray.DataArray, darray_single_level: xarray.DataArray, nc_filename: str, forecast_hour: int, meta_data: dict, conf: dict)#

Save CREDIT model prediction output to netCDF file. Also performs pressure level interpolation on the output if you wish.

Parameters:
  • darray_upper_air (xr.DataArray) – upper air variable predictions

  • darray_single_level (xr.DataArray) – surface variable predictions

  • nc_filename (str) – file description to go into output filenames

  • forecast_hour (int) – how many hours since the initialization of the model.

  • meta_data (dict) – metadata dictionary for output variables

  • conf (dict) – configuration dictionary for training and/or rollout

credit.output.save_netcdf_clean(darray_upper_air, darray_single_level, nc_filename, forecast_hour, meta_data, conf, use_logger=True)#

Save forecast data (upper-air and optionally single-level variables) to a NetCDF file.

This function is similar to save_netcdf_increment but cleaned-up all the interpolations

Parameters:
  • darray_upper_air (xr.DataArray) – Upper-air forecast data with dimension “vars”.

  • darray_single_level (xr.DataArray or None) – Single-level forecast data with dimension “vars”. If None, only upper-air variables are included.

  • nc_filename (str) – Base filename (used as subdirectory and prefix for the saved file).

  • forecast_hour (int) – Forecast lead time in hours.

  • meta_data (dict or bool) – Dictionary containing variable metadata attributes. If False, no metadata is applied and default time encoding is used.

  • conf (dict) – Configuration dictionary. Must include at least: - conf[“predict”][“save_forecast”]: directory where forecasts are saved. - conf[“predict”][“save_vars”]: (optional) list of variable names to keep.

  • use_logger (bool, optional) – If True (default), configure logging and print progress messages.

Notes

  • Files are saved into:

    {conf['predict']['save_forecast']}/{nc_filename}/pred_{nc_filename}_{forecast_hour:03d}.nc

  • If meta_data is provided, variable attributes are updated accordingly. Otherwise, a default gregorian calendar encoding is applied to the “time” variable.

  • If conf[‘predict’][‘save_vars’] is non-empty, variables not listed there are dropped before saving.

Returns:

The function saves a NetCDF file to disk and does not return a value.

Return type:

None

credit.output.save_netcdf_diag(darray_single_level: xarray.DataArray, nc_foldername: str, nc_filename: str, forecast_hour: int, meta_data: dict, conf: dict)#