From 90d852a4c7d41c0e8b06f1420d6995278eda905f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20Tint=C3=B3?= <oriol.tinto@lmu.de> Date: Tue, 27 Jun 2023 11:40:53 +0200 Subject: [PATCH] Trying to convert the analysis to netcdf. --- .../event-generator/adapt_member_utils.sh | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/templates/event-generator/adapt_member_utils.sh b/templates/event-generator/adapt_member_utils.sh index cbbe625..be48780 100644 --- a/templates/event-generator/adapt_member_utils.sh +++ b/templates/event-generator/adapt_member_utils.sh @@ -111,6 +111,60 @@ END } function integrate_sst_to_analysis() { + + local DYNAMICS_GRID_FILE="$1" + local ANALYSIS_FILE="$2" + + echo "Converting analysis to netcdf" + + cat >remap.nml <<END +&remap_nml +in_filename = "${ANALYSIS_FILE}" +in_grid_filename = "${DYNAMICS_GRID_FILE}" +in_type = 1 +out_grid_filename = "${DYNAMICS_GRID_FILE}" +out_filename = "analysis.nc" +out_type = 2 +out_filetype = 4 +/ +END + + cat <<END >extend_remap_namelist.py +import xarray as xr + +with xr.open_dataset("${ANALYSIS_FILE}") as ds, open('remap.nml', 'a') as file: + for ida, da in enumerate(ds): + file.write('&input_field_nml\n') + file.write(f'inputname = "{da}"\n') + file.write(f'outputname = "{da}"\n') + file.write('/\n\n') +END + + python3 extend_remap_namelist.py + + ulimit -s unlimited + OMP_NUM_THREADS=1 iconremap --remap_nml remap.nml #-vvv + rm remap.nml + +# # Somehow, when we interpolate we lose some attributes. +# # Here we solve this issue adding the attributes. +# cat <<END >add_attributes.py +## Add sst field to analysis file. +#from enstools.io import read +# +## Open files +#with read("tmp_extpar.nc") as ds, read("${EXTERNAL_PARAMETERS_FILE}") as original_extpar_ds: +# if "rawdata" in original_extpar_ds.attrs: +# ds.attrs["rawdata"] = original_extpar_ds.attrs["rawdata"] +# ds.to_netcdf("extpar.nc") +#END +# python3 add_attributes.py +# +# rm "tmp_extpar.nc" + +} + +function old_integrate_sst_to_analysis() { local INTERPOLATED_SST="$1" local ANALYSIS_FILE="$2" @@ -171,4 +225,3 @@ END python integrate_sst_to_extpar.py } - -- GitLab