Commit 80dda161 authored by Modellers Operational's avatar Modellers Operational

Add apps to make a CMEMS warm start file instead of starting from constant T and S values

parent c47725b1
import multiprocessing
import numpy as np
import datetime as dt
import glob as gb
from pathlib import Path
import PyFVCOM as pf
from PyFVCOM.utilities.time import date_range
cmems_data_dir = sys.argv[1]
start_date = dt.datetime.strptime(sys.argv[2], '%Y-%m-%d')
grid = sys.argv[3]
donor_filepath = sys.argv[4]
"""
cmems_data_dir = '/data/sthenno1/scratch/modop/Data/CMEMS'
start_date = dt.datetime(2019,1,15)
grid = 'tamar_v2'
"""
cmems_time_res = 'hi'
fvcom_cmems_names = {'salinity':['SAL', 'vosaline'], 'temp':['TEM', 'votemper'],
'v':['CUR', 'vomecrty'], 'u':['CUR', 'vozocrtx'],
'zeta':['SSH', 'sossheig']}
# Modify a donor restart file.
restart = pf.preproc.Restart(donor_filepath,
variables=['siglay', 'siglev'])
# and alter the time variable
restart.time.datetime = np.asarray([start_date])
ref_date = dt.datetime(1858,11,17,0,0,0)
restart.time.time = np.asarray([(start_date - ref_date).days])
restart.time.Itime = np.asarray([(start_date - ref_date).days])
restart.time.Times = np.asarray(['{}T00:00:00.0000000'.format(start_date.strftime('%Y-%m-%d'))])
# We need to bracket the restart data in time with CMEMS data to ensure it interpolates properly.
for this_fvcom, this_var in fvcom_cmems_names.items():
cmems_file_list = []
offset = dt.timedelta(days=1)
for this_date_dt in date_range(start_date - offset, start_date + offset):
this_date = this_date_dt.strftime('%Y%m%d')
if this_var[0] == 'SSH':
poss_files = gb.glob('{}/*{}*{}*/*{}.nc'.format(cmems_data_dir, 'hi', this_var[0], this_date))
else:
poss_files = gb.glob('{}/*{}*{}*/*{}.nc'.format(cmems_data_dir, cmems_time_res, this_var[0], this_date))
# Handle that sometimes theres multiple files for one day from different forecast runs
if len(poss_files) > 1:
chosen_file = poss_files[0]
for this_file in poss_files[1:]:
if this_file > chosen_file:
chosen_file = this_file
cmems_file_list.append(chosen_file)
elif len(poss_files) == 1:
cmems_file_list.append(poss_files[0])
if this_var[0] =='SSH':
reg_reader = pf.preproc.Regular2DReader
else:
reg_reader = pf.preproc.RegularReader
this_data_reader = reg_reader(cmems_file_list[0], [this_var[1]])
if len(cmems_file_list) > 1:
for this_file in cmems_file_list[1:]:
this_data_reader += reg_reader(this_file, [this_var[1]])
# Interpolate onto the FVCOM grid.
if this_fvcom in ['u', 'v']:
this_mode = 'elements'
elif this_fvcom == 'zeta':
this_mode = 'surface'
else:
this_mode = 'nodes'
restart.replace_variable_with_regular(this_fvcom, this_var[1], this_data_reader, constrain_coordinates=True, mode=this_mode)
restart.write_restart('{}_restart_0001.nc'.format(grid))
[command]
default = python3 make_restart.py ${CMEMS_DATA_DIR} ${START_DAY} ${GRID_NAME} ${DONOR_RESTART_FILE_PATH}; cp ${GRID_NAME}_restart_0001.nc /${REMOTE_TRANSFER_DIR}/
[command]
default = cp /pml${REMOTE_TRANSFER_DIR}/${GRID_NAME}_restart_0001.nc ${ROSE_DATAC};
......@@ -48,6 +48,8 @@ BOUNDARY_FORCING='CMEMS'
HARMONICS_FILE_PATH='/users/modellers/modop/Models/FVCOM_tamar_harmonics/tamar_2006_harmonics.nc'
## Required for CMEMS
CMEMS_DATA_DIR='/data/sthenno1/scratch/modop/Data/CMEMS'
## Required for CMEMS warm start
DONOR_RESTART_FILE_PATH='/users/modellers/modop/Models/FVCOM_tamar_restart/tamar_v2_donor_restart.nc'
## Required for NEST_FILE
NEST_RUN_SUITE='fvcom-rosa'
# The time resolution of the nest output, as divisions of 1 day (i.e. 24 would be hourly, 48 every half hour)
......
......@@ -14,7 +14,12 @@
[[[R1]]]
graph = """
copy_common_to_remote => softlink_forcing_remote
write_run_namelist => hot_cold_start => run_fvcom
{%- if COLD_START and BOUNDARY_FORCING == 'CMEMS' %}
write_run_namelist => adjust_namelist & generate_CMEMS_start => mv_start_file => run_fvcom
{% elif COLD_START and BOUNDARY_FORCING == 'NEST_FILE' %}
write_run_namelist => adjust_namelist & generate_nest_start => mv_start_file => run_fvcom
{%- if COLD_START %}
"""
[[[P1D]]]
graph = """
......@@ -95,6 +100,7 @@
ARCHIVE_DIR={{ARCHIVE_DIR}}
HARMONICS_FILE_PATH={{HARMONICS_FILE_PATH}}
DONOR_RESTART_FILE_PATH={{DONOR_RESTART_FILE_PATH}}
CMEMS_DATA_DIR={{CMEMS_DATA_DIR}}
NEST_RUN_SUITE={{NEST_RUN_SUITE}}
NEST_INTERVAL={{NEST_INTERVAL}}
......@@ -263,20 +269,18 @@
[[run_fvcom]]
inherit = slurm_job
[[hot_cold_start]]
[[adjust_namelist]]
inherit = remote_job
{%- if COLD_START %}
script = """
sed -i "s|.*STARTUP_TYPE.*|STARTUP_TYPE = 'coldstart',|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
sed -i "s|.*STARTUP_FILE.*|STARTUP_FILE = 'none',|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
sed -i "s|.*STARTUP_UV_TYPE.*|STARTUP_UV_TYPE = 'default',|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
sed -i "s|.*STARTUP_TURB_TYPE.*|STARTUP_TURB_TYPE = 'default',|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
sed -i "s|.*STARTUP_TS_TYPE.*|STARTUP_TS_TYPE = 'constant',|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
sed -i "s|.*STARTUP_TS_TYPE.*|STARTUP_TS_TYPE = 'set values',|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
{%- if SEDIMENT %}
sed -i "s|.*SED_HOT_START.*|SED_HOT_START = F|" ${ROSE_DATAC}/cstms_sediment.inp
{%- endif %}
"""
{%- endif %}
[[generate_CMEMS_start]]
[[mv_start_file]]
[[transfer_data]]
inherit = slurm_job_1
[[transfer_data_today]]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment