From 1750c0c61cab65c624601e336490bae372431292 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Oriol=20Tint=C3=B3?= <oriol.tinto@lmu.de>
Date: Wed, 28 Jun 2023 13:25:06 +0200
Subject: [PATCH] Interpolating first-guess as well.

---
 templates/event-generator/adapt_member.sh       |  4 +++-
 templates/event-generator/adapt_member_utils.sh | 13 +++++++------
 templates/event-generator/prepare_namelist.py   |  7 ++++---
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/templates/event-generator/adapt_member.sh b/templates/event-generator/adapt_member.sh
index 6575f2b..585fabc 100644
--- a/templates/event-generator/adapt_member.sh
+++ b/templates/event-generator/adapt_member.sh
@@ -25,6 +25,7 @@ cd ${MEMBER_DIR} || exit
 
 # Get analysis file path
 ANALYSIS_FILE=$(find . -name "igaf*.m*.grb" -print -quit)
+FG_FILE=$(find . -name "igfff00030000.m*.grb" -print -quit)
 
 
 # Load spack
@@ -56,7 +57,8 @@ integrate_sst_to_extpar "${INTERPOLATED_SST}" "${EXTERNAL_PARAMETERS_FILE}"
 
 
 # Interpolate analysis
-interpolate_analysis "icon_grid_0024_R02B06_G.nc" "${ANALYSIS_FILE}" "${DESTINATION_GRID}"
+interpolate_initial_conditions "icon_grid_0024_R02B06_G.nc" "${ANALYSIS_FILE}" "${DESTINATION_GRID}" "interpolated_analysis.nc"
+interpolate_initial_conditions "icon_grid_0024_R02B06_G.nc" "${FG}" "${DESTINATION_GRID}" "first_guess.nc"
 
 
 integrate_sst_to_analysis "${INTERPOLATED_SST}"
diff --git a/templates/event-generator/adapt_member_utils.sh b/templates/event-generator/adapt_member_utils.sh
index 0dcc00e..3d5eee0 100644
--- a/templates/event-generator/adapt_member_utils.sh
+++ b/templates/event-generator/adapt_member_utils.sh
@@ -110,21 +110,22 @@ END
   fi
 }
 
-function interpolate_analysis() {
+function interpolate_initial_conditions() {
 
   local INPUT_GRID="$1"
-  local ANALYSIS_FILE="$2"
+  local IC_FILE="$2"
   local OUTPUT_GRID="$3"
+  local OUTPUT_FILENAME="$4"
 
-  echo "Converting analysis to netcdf"
+  echo "Interpolating ${IC_FILE} to destination grid"
 
   cat >remap.nml <<END
 &remap_nml
-in_filename = "${ANALYSIS_FILE}"
+in_filename = "${IC_FILE}"
 in_grid_filename = "${INPUT_GRID}"
 in_type = 2
 out_grid_filename = "${OUTPUT_GRID}"
-out_filename = "interpolated_analysis.nc"
+out_filename = "${OUTPUT_FILENAME}
 out_type = 2
 out_filetype = 4
 /
@@ -133,7 +134,7 @@ END
   cat <<END >extend_remap_namelist.py
 from enstools.io import read
 
-with read("${ANALYSIS_FILE}") as ds, open('remap.nml', 'a') as file:
+with read("${IC_FILE}") as ds, open('remap.nml', 'a') as file:
     all_vars = list(ds.data_vars)
     remap_vars = []
     for var in all_vars:
diff --git a/templates/event-generator/prepare_namelist.py b/templates/event-generator/prepare_namelist.py
index 0223de6..35888d5 100644
--- a/templates/event-generator/prepare_namelist.py
+++ b/templates/event-generator/prepare_namelist.py
@@ -25,9 +25,10 @@ MASTER_NAMELIST_PATH = Path("%simulation.namelist_paths.master%")
 analysis_filename = "analysis.nc"
 
 
-first_guess_filename = (RUNDIR / "igfff00030000.m*.grb").resolve()
-first_guess_filename = first_guess_filename.parent.glob(first_guess_filename.name).__next__()
-first_guess_filename = first_guess_filename.name
+# first_guess_filename = (RUNDIR / "igfff00030000.m*.grb").resolve()
+# first_guess_filename = first_guess_filename.parent.glob(first_guess_filename.name).__next__()
+# first_guess_filename = first_guess_filename.name
+first_guess_filename = "first_guess.nc"
 
 
 # Example of date format "2018-06-01T00:00:00Z"
-- 
GitLab