NEDAS.models.qg.python.qg_python_model module
NEDAS Model interface for the Python QG spectral model.
Mirrors QGFortranModel in structure; runs QGModel in-process (no external executable). Supports both offline (file-based .npy) and online (in-memory) IO modes.
File format
Each snapshot is stored as a single NumPy .npy file containing the full spectral streamfunction psi of shape (nz, nky, nkx), complex128. Filename: <path>/<member_str>/output_<YYYYMMDD_HH>.npy
Array conventions
Physical variables returned to / received from NEDAS have shape (ny, nx) for scalars or (2, ny, nx) for vector (u, v), in NEDAS grid convention where axis-0 = y direction and axis-1 = x direction.
The QG spectral model internally uses spec2grid() which returns (nx, ny) with axis-0 = x direction, so _derive_var() and _psi_from_var() apply .T when crossing the boundary between the two conventions.
- class NEDAS.models.qg.python.qg_python_model.QGPythonModel(**kwargs)[source]
Bases:
ModelNEDAS Model interface for the pure-Python QG spectral model.
Configuration mirrors QGFortranModel and the QGModel dataclass. All physics parameters (kmax, nz, F, beta, bot_drag, …) are read from default.yml and overridden by the user YAML / CLI args via parse_config().
- kmax: int
- nz: int
- restart_dt: float
- F: float
- beta: float
- read_grid(**kwargs)[source]
Read the grid information from the model output.
- Parameters:
**kwargs – Keyword arguments for reading the grid.
- z_coords(**kwargs)[source]
Get the vertical coordinates of the model.
- Parameters:
**kwargs – Keyword arguments for getting the vertical coordinates.
- Returns:
The vertical coordinates.
- Return type:
np.ndarray
- preprocess(*args, **kwargs)[source]
Preprocess the model data.
- Parameters:
**kwargs – Keyword arguments for preprocessing.
- postprocess(*args, **kwargs)[source]
Postprocess the model data.
- Parameters:
**kwargs – Keyword arguments for postprocessing.
- run(*args, **kwargs)[source]
Run the model forward in time.
- Parameters:
*args – Arguments
**kwargs – Keyword arguments
- Keyword Arguments:
time (datetime) – current time when forecast starts
restart_dir (str) – directory where restart files are located
forecast_period (int) – forecast period in hours
If self.ens_run_strategy == ‘batch’, the method will run all ensemble members in one go, expect additional kwargs[‘nens’] to be the ensemble size. If self.ens_run_strategy == ‘scheduler’, the method runs a single member indexed by kwargs[‘member’], and kwargs[‘worker_id’] is the pid assigned by the scheduler to run this method.