preprocessing

preprocessing

Preprocessing of the SEAS5 / DCSM-5 model data: ports of the KNMI R scripts readmixed.R, concat_multi_ex.R and concat_wind.R (archive Update_statistiek_zeewaterstand_wind_06_archive_Feb2026).

These scripts make the input files _multi_int.RData and _wind.RData of the statistics notebooks from the model output on the KNMI servers:

  1. read_mixed (readmixed.R): for each SEAS5 run listed in selection_stress_wind_tide.txt, collocate the high-tide water levels of DCSM-5 with the SEAS5 wind and wind stress of the nearest grid point. Writes one file __int per station and run.
  2. concat_multi (concat_multi_ex.R): concatenate the files of step 1 per station to _multi_int (dt, wl, surge, mstress, dstress, mwind, dwind, timelength).
  3. concat_wind (concat_wind.R): concatenate the SEAS5 wind and wind stress of all runs per station to _wind (dt, mstress, dstress, mwind, dwind, timelength).

Corrections of the findings of the code review (section “Data voorbewerking”); the R behaviour is available with discard_first_month=False:

  • First month of each run (spin-up). In selection_stress_wind_tide.txt, 6 runs (member 00 of 198101-198106) have tstart = 1, so their first month ends up in _multi_int; 500 runs of February in leap years start at 29 February. read_mixed discards everything before the first day of the month after the start of the run (in addition to tstart / tend).
  • concat_wind.R loads half-year files that KNMI made from the SEAS5 netCDF files (not in the archive) and fails on the netCDF files themselves. concat_wind also reads the SEAS5 netCDF files directly: wind and wind stress of the grid point nearest to each station, months 2 to 7 of each run (the same window as the water levels in selection_stress_wind_tide.txt).
  • Texel Noordzee: SEAS5_hwloc_230.RData was not made with readmixed.R and its script is missing; this cannot be reconstructed here.

The Python versions write netCDF instead of .RData (Python cannot write R lists); read_seas5_wind and read_seas5_multi read both. Times are POSIXct seconds (since 1970-01-01 UTC), as in R. concat_multi reads the files of step 1 written by R (.RData) as well as by Python (.nc).

Attributes

Name Description
WLEVELS_TIME_VARS

Functions

Name Description
collocate_station Body of the station loop of readmixed.R for one run and one station.
concat_multi concat_multi_ex.R: concatenate the files _*_int of read_mixed in //
concat_wind concat_wind.R: concatenate the SEAS5 wind and wind stress of all runs to
month_start POSIXct seconds of the first day of the month of t (POSIXct seconds), plus months months.
read_mixed readmixed.R: collocate high-tide water levels, tide, wind and wind stress of all SEAS5 runs in
read_mixed_file One iteration of the loop over the SEAS5 runs in readmixed.R. Writes
read_selection read.table(“selection_stress_wind_tide.txt”, sep = ” “): one row per SEAS5 run with the water

collocate_station

preprocessing.collocate_station(
    val_wl,
    val_tide,
    dt_wl,
    dt_tide,
    dt_wind,
    wind,
    tstart,
    tend,
    tmin=None,
)

Body of the station loop of readmixed.R for one run and one station.

val_wl and val_tide are the water level and tide-only series (same time axis); dt_wl, dt_tide and dt_wind the POSIXct seconds of the water level, tide and wind series; wind a dict with the SEAS5 series u10, v10, iews, inss at the nearest grid point; tstart and tend the 1-based indices in dt_wl of the period to keep. tmin is an optional earliest time to keep (POSIXct seconds); it is not in R and is used to discard the first month of the run.

Returns the R list wlevels as a dict: tide, wl, dt_tide, dt_wl, u10, v10, iews, inss.

concat_multi

preprocessing.concat_multi(path, stations=CONCAT_MULTI_STATIONS, out_path=None)

concat_multi_ex.R: concatenate the files _*_int of read_mixed in // to /_multi_int.nc (out_path defaults to path, as in R).

Returns the paths written.

concat_wind

preprocessing.concat_wind(
    path,
    stations=CONCAT_WIND_STATIONS,
    out_path=None,
    lat=None,
    lon=None,
    discard_first_month=True,
    n_months=6,
    recursive=False,
)

concat_wind.R: concatenate the SEAS5 wind and wind stress of all runs to /_wind.nc (out_path defaults to path, as in R).

The input files are all files in path with “nc” in the name (as in R; with recursive, also in subdirectories, e.g. seasonal/system5//). These can be

  • the SEAS5 netCDF files themselves (seasonal_system5...nc): wind and wind stress of the grid point nearest to each station (coordinates lat, lon; default: those of readmixed.R). With discard_first_month, only months 2 .. 1 + n_months of each run are kept (default: the 6 months after the spin-up month, as for the water levels); with discard_first_month=False the whole file. concat_wind.R cannot read these files.
  • the half-year files that concat_wind.R loads (.RData with dt and matrices time x station): station j is column j, so stations must be in the column order of the files. These files are used as they are (they were already cut by KNMI).

Returns the paths written.

month_start

preprocessing.month_start(t, months=0)

POSIXct seconds of the first day of the month of t (POSIXct seconds), plus months months.

read_mixed

preprocessing.read_mixed(
    selection_file,
    out_dir='.',
    path_map=None,
    stations=MIXED_STATIONS,
    lat=MIXED_LAT,
    lon=MIXED_LON,
    runs=None,
    discard_first_month=True,
)

readmixed.R: collocate high-tide water levels, tide, wind and wind stress of all SEAS5 runs in selection_file (selection_stress_wind_tide.txt).

  • out_dir: directory of the output files __int.nc (R: the working directory).
  • path_map: optional {old prefix: new prefix} to translate the paths in the selection file (on the KNMI servers, /net/pc200003/…) to the local location of the model output.
  • stations, lat, lon: stations (variable names in the water level files) and their coordinates, used to pick the nearest SEAS5 grid point (default: those of readmixed.R).
  • runs: optional selection of row numbers (0-based) of the selection file; None = all runs. R’s test mode is read_mixed_file with the test files.
  • discard_first_month: discard the first month (spin-up) of every run, also for the runs whose tstart in the selection file does not (see the module documentation); False = as readmixed.R.

Returns the paths of the files written.

read_mixed_file

preprocessing.read_mixed_file(
    wl_file,
    tide_file,
    wind_file,
    tstart,
    tend,
    out_name,
    out_dir='.',
    stations=MIXED_STATIONS,
    lat=MIXED_LAT,
    lon=MIXED_LON,
    discard_first_month=True,
)

One iteration of the loop over the SEAS5 runs in readmixed.R. Writes /__int.nc for each station; returns the paths written (an empty list, as in R, if the time units of the wind file cannot be read).

With discard_first_month, high waters before the first day of the month after the start of the water level series (the start of the run) are removed, also if tstart points to an earlier time. discard_first_month=False gives the results of readmixed.R.

read_selection

preprocessing.read_selection(path)

read.table(“selection_stress_wind_tide.txt”, sep = ” “): one row per SEAS5 run with the water level file (V1), the first and last time index to keep (V2, V3; 1-based), the tide-only file (V6) and the SEAS5 wind/stress file (V7).