NEDAS.models.nextsim.dg.forcing module

This module is used to perturb the forcing variables for the next forecast cycle.

This module is specifically designed for neXtSIM-DG in NEDAS. The design follows the perturbation strategy in TOAPZ4 where the perturbation is temporally correlationed as an AR1 process.

Parameters of the perturbation are read from the yaml file. The perturbation is applied to the forcing variables in the forcing files.

NEDAS.models.nextsim.dg.forcing.get_fname_daterange(current_date: datetime, initial_date: str, interval: str, forcing_file_date_format: str) tuple[str, str][source]

Inferring the date range of the forcing file for the current time, the forcing start date and the forcing interval in the initial forcing file given by yaml file.

Parameters:
  • current_date (datetime) – current date

  • initial_date (str) – forcing start date

  • interval (str) – forcing interval

  • forcing_file_date_format (str) – forcing file date format expressed in strftime format

Returns:

start date and end date of the forcing file for current time

Return type:

tuple[str, str]

NEDAS.models.nextsim.dg.forcing.get_time_from_nc(fname: str, time_varname: str, time_units_name: str, time: datetime, next_time: datetime, debug: bool = False) tuple[ndarray, list[datetime]][source]

Get the indices and corresponding time that includes time and next_time from the netcdf file

This function is not seeking the exact time and next_time in the forcing file, but the time steps that include the time and next_time such that the perturbed forcing file can be a bit smaller. Therefore, we allow for a few more time steps in this file.

Parameters:
  • fname (str) – forcing file name

  • time_varname (str) – time variable name in the forcing file

  • time_units_name (str) – variable name that gives time units in the forcing file

  • time (datetime) – current time

  • next_time (datetime) – time at the end of the forecast cycle

Returns:

indices and corresponding time for the next forecast cycle

Return type:

tuple[np.ndarray, np.ndarray]

NEDAS.models.nextsim.dg.forcing.get_time_index(fname: str, time_varname: str, time_units_name: str, time: datetime) int[source]

Get the index of time in a netcdf file

NEDAS.models.nextsim.dg.forcing.get_prev_time_from_nc(fname: str, time_varname: str, time_units_name: str, itime: int) datetime[source]

Get the previous time in the netcdf file before the start of the forecast cycle

Parameters:
  • fname (str) – forcing file name

  • time_varname (str) – time variable name in the forcing file

  • time_units_name (str) – variable name that gives time units in the forcing file

  • itime (int) – current time index in the forcing file

NEDAS.models.nextsim.dg.forcing.read_var(fname: str, varnames: list[str], itime: int) MaskedArray[source]

reading a variable from a netcdf file

Parameters:
  • fname (str) – forcing file name

  • varnames (list[str]) – list of variable names

  • itime (int) – time index in the forcing file

NEDAS.models.nextsim.dg.forcing.write_var(fname: str, varnames: list[str], data: ndarray, itime: int) None[source]

Write the perturbed variable back to the forcing file

Parameters:
  • fname (str) – forcing file name

  • varnames (list[str]) – list of variable names

  • itime (int) – time index in the forcing file

NEDAS.models.nextsim.dg.forcing.geostrophic_perturb(fname: str, grid: RegularGrid, options: dict, itime: int, pert: ndarray, varname: str) None[source]

Perturb the atmosphere wind by the geostrophic balance. This applies to horizontal 2D wind fields.

Parameters:
  • fname (str) – forcing file name

  • options (dict) – perturbation options for the geostrophic_wind_adjust section of atmosphere forcing from yaml file

  • itime (int) – current time index in the forcing file

  • pert (np.ndarray) – perturbation array

  • varname (str) – name of the variable to be used to perturb wind fields

Return type:

None

NEDAS.models.nextsim.dg.forcing.get_forcing_filename(forcing_file_options: dict, i_ens: int, time: datetime) str[source]

Get the forcing file name based on the current time and the forcing file format

Parameters:
  • forcing_file_options (dict) – forcing file options in the file section of the subsections of perturb section from the yaml file

  • i_ens (int) – ensemble index

  • time (datetime) – current time

Returns:

forcing file name

Return type:

str

NEDAS.models.nextsim.dg.forcing.perturb_forcing(forcing_options: dict, file_options: dict, i_ens: int, time: datetime, next_time: datetime, debug=False) None[source]

perturb the forcing variables

Parameters:
  • forcing_options (dict) – perturbation options from the yaml file

  • file_options (dict) – forcing file options in the corresponding subsection of the file section from the yaml file e.g., info in the file/forcing/atmosphere is used in the perturb/forcing/atmosphere section Before calling this function, one must add the following keys to the file_options dictionary: - fname: the exact filename of the perturbed forcing file under absbolute path

  • i_ens (int) – ensemble index

  • time (datetime) – current time as the begining of the forecast cycle

  • next_time (datetime) – end time of the next forecast cycle