diff --git a/conf/event-generator/simulation.yml b/conf/event-generator/simulation.yml index 8df8a41e907031763f1601063d35dbcc4373a8b0..b464dcedaef8386af931bbb5c5751b9e8365d09c 100644 --- a/conf/event-generator/simulation.yml +++ b/conf/event-generator/simulation.yml @@ -7,7 +7,8 @@ simulation: radiation_grid_filename: icon_grid_0015_R02B05_R.nc # external_parameters_filename: icon_extpar_0010_R02B04_G.nc - external_parameters_filename: icon_extpar_0024_R02B06_G_20200917_tiles.nc +# external_parameters_filename: icon_extpar_0024_R02B06_G_20200917_tiles.nc + external_parameters_filename: icon_extpar_0016_R02B06_G_20131206.nc date_format: '%Y-%m-%dT%H:%M:%SZ' namelist_paths: # Path to the namelists diff --git a/templates/event-generator/adapt_member.sh b/templates/event-generator/adapt_member.sh index 8e9bd2ef96d6bf77ff9972d82fc2658e0d95c047..606cce30aec52b007359be3d6fed9dd770bb87bd 100644 --- a/templates/event-generator/adapt_member.sh +++ b/templates/event-generator/adapt_member.sh @@ -48,7 +48,12 @@ interpolate_SST "${DESTINATION_GRID}" "${SST_FORCING}" "${INTERPOLATED_SST}" # Interpolate extpar -interpolate_extpar "${DESTINATION_GRID}" "${EXTERNAL_PARAMETERS_FILE}" +#interpolate_extpar "${DESTINATION_GRID}" "${EXTERNAL_PARAMETERS_FILE}" + + +# Integrate sst to extpar +integrate_sst_to_extpar "${INTERPOLATED_SST}" "${EXTERNAL_PARAMETERS_FILE}" + # Integrate sst to analysis diff --git a/templates/event-generator/adapt_member_utils.sh b/templates/event-generator/adapt_member_utils.sh index 1154254d8f97eab1cb30cbdbfc258aa3ddfeb7b2..da4db52886c14e4581cb9d20b0454854b242b518 100644 --- a/templates/event-generator/adapt_member_utils.sh +++ b/templates/event-generator/adapt_member_utils.sh @@ -133,3 +133,40 @@ END python integrate_sst_to_analysis.py } + +function integrate_sst_to_extpar() { + local INTERPOLATED_SST="$1" + local EXTERNAL_PARAMETERS_FILE="$2" + + cat <<END >integrate_sst_to_extpar.py +# Add sst field to analysis file. +from enstools.io import read +import os +import numpy as np + +os.environ['ECCODES_GRIB_NO_INDEX'] = '1' +# Open files +with read("${EXTERNAL_PARAMETERS_FILE}") as ds, read("${INTERPOLATED_SST}") as sst_ds: + da = sst_ds["T_SEA"] + year = 2000 # or any other year + dates = [(datetime(year, 1, 1) + timedelta(days=idx)).month for idx, _ in enumerate(da['time'].values)] + + da['time'] = dates + + # Replace analysis T_SEA with monthly mean from the sst_ds. + monthly_means = [da.sel(time=month).mean(dim="time") for month in range(1,13)] + concat_da = xr.concat(monthly_means, dim='time') + concat_da['time'] = np.arange(1, 13) # replace 'time' with month numbers + concat_da = concat_da.drop(['clon', 'clat']) + + # Replace analysis T_SEA with monthly mean from the sst_ds. + ds["T_SEA"] = concat_da + + ds.to_netcdf("extpar.nc") + +END + + python integrate_sst_to_extpar.py + +} +