Commit 8873f598 authored by Modellers Operational's avatar Modellers Operational

Merge changes

parents fc2107ac e6aba03c
......@@ -7,9 +7,9 @@ import sys
import PyFVCOM as pf
"""
cmems_data_dir = '/data/sthenno1/backup/mbe/Data/CMEMS'
start_date = dt.datetime(2018,9,26)
end_date = dt.datetime(2018,9,27)
cmems_data_dir = '/data/sthenno1/scratch/modop/Data/CMEMS'
start_date = dt.datetime(2019,4,30)
end_date = dt.datetime(2019,5,2)
grid = 'tamar_v2_grd.dat'
sigma_file = 'sigma_gen.dat'
native_coordinates = 'cartesian'
......@@ -41,9 +41,9 @@ aqua_prep.add_nests(4)
aqua_prep.add_nests_harmonics(fvcom_harmonics, harmonics_vars=['u', 'v', 'ua', 'va', 'zeta'], constituents=constituents, pool_size=20)
# Make the regular readers for the CMEMS data
fvcom_cmems_names = {'salinity':['SAL', 'vosaline'], 'temp':['TEM', 'votemper'],
'v':['CUR', 'vomecrty'], 'u':['CUR', 'vozocrtx'],
'zeta':['SSH', 'sossheig']}
fvcom_cmems_names = {'salinity':['SAL', 'so'], 'temp':['TEM', 'thetao'],
'v':['CUR', 'vo'], 'u':['CUR', 'uo'],
'zeta':['SSH', 'zos']}
dt_list = [start_date + dt.timedelta(days = int(i)) for i in np.arange(-1, (end_date - start_date).days + 2)]
datestr_list = [this_date.strftime('%Y%m%d') for this_date in dt_list]
......
......@@ -22,9 +22,9 @@ 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']}
fvcom_cmems_names = {'salinity':['SAL', 'so'], 'temp':['TEM', 'thetao'],
'v':['CUR', 'vo'], 'u':['CUR', 'uo'],
'zeta':['SSH', 'zos']}
# Modify a donor restart file.
......@@ -84,6 +84,9 @@ for this_fvcom, this_var in fvcom_cmems_names.items():
restart.replace_variable_with_regular(this_fvcom, this_var[1], this_data_reader, constrain_coordinates=True, mode=this_mode)
for this_var in fvcom_cmems_names.keys():
setattr(restart.data, this_var, getattr(restart.data,this_var)[np.newaxis,...])
# replace Times as need to be a 26 character array
restart.time.Times = np.asarray(list(restart.time.Times[0]))[np.newaxis,:]
restart.write_restart('{}_restart_0001.nc'.format(grid))
......
#!/bin/bash --login
set -eu
# Get today's forecast data from CMEMS for the NW Shelf domain. Delete yesterday's whilst we're at it.
# CMEMS FTP username and password are stored in ~/.netrc to make this more secure.
forecast_days=$1
cmems_dir=$2
cd ${cmems_dir}
today=${today:-$(date +%Y%m%d)}
for day in $(seq -2 $forecast_days); do
end=$(date +%Y%m%d -d "$today + $day days")
echo -n "Getting forecast $today-$end "
for var in CUR SAL SSH TEM; do
dir=MetO-NWS-PHYS-hi-${var}
if [ ! -d $dir ]; then
mkdir $dir
fi
file=metoffice_foam1_amm7_NWS_${var}_b${today}_hi${end}.nc
# Don't fail if we didn't get the file. This might just mean we're doing a hindcast download.
#wget -qc ftp://nrt.cmems-du.eu/Core/NORTHWESTSHELF_ANALYSIS_FORECAST_PHYS_004_001_b/$dir/$file -O$dir/$file || true
wget -c ftp://nrt.cmems-du.eu/Core/NORTHWESTSHELF_ANALYSIS_FORECAST_PHYS_004_001_b/$dir/$file -O$dir/$file || true
# If we're doing a hindcast download we might end up with an empty file, so nuke it here.
if [ ! -s $dir/$file ]; then
rm $dir/$file
fi
# If we've got a new forecast for day x then delete all other files for day x
if [ -f $dir/$file ]; then
echo "Clearing old forecast ${end}"
ls ${dir}/metoffice_foam1_amm7_NWS_${var}_b*_hi${end}.nc | grep -v metoffice_foam1_amm7_NWS_${var}_b${today}_hi${end}.nc | xargs rm || true
fi
done
echo "done."
done
# Create a residual of the currents and sea surface height for the files we've just downloaded.
#module load mpi/mpich-x86_64
#cd ~/Models/FVCOM/fvcom-projects/stemm-ccs/python/tides/
#for day in $(seq -1 $forecast_days); do
# day=$(date +%Y%m%d -d "$today + $day days")
# mpirun -n $(nproc) python3 nemo_tides.py ${day:0:4} ${day:4:2} ${day:6:2} SSH sossheig
# #mpirun -n $(nproc) python3 nemo_tides.py ${day:0:4} ${day:4:2} ${day:6:2} CUR vozocrtx
# #mpirun -n $(nproc) python3 nemo_tides.py ${day:0:4} ${day:4:2} ${day:6:2} CUR vomecrty
#done
##python3 make_residual.py ${today:0:4} ${today:4:2} SSH sossheig
##python3 make_residual.py ${today:0:4} ${today:4:2} CUR vozocrtx
##python3 make_residual.py ${today:0:4} ${today:4:2} CUR vozocrtx
[command]
default = bash get_nws_forecast.sh 5 ${CMEMS_DATA_DIR}
[command]
default = ln -s ${WRF_FORECAST_FILE_DIR}/today_wrf.nc ${ROSE_DATAC}/${GRID_NAME}_wnd.nc
default = ln -sf ${WRF_FORECAST_FILE_DIR}/${FORECAST_DAY}/today_wrf.nc ${ROSE_DATAC}/${GRID_NAME}_wnd.nc
[command]
default = cp /pml${REMOTE_TRANSFER_DIR}/${GRID_NAME}_restart_0001.nc ${ROSE_DATAC};
default = rm -f ${ROSE_DATAC}/${GRID_NAME}_restart_0001.nc;
cp /pml${REMOTE_TRANSFER_DIR}/${GRID_NAME}_restart_0001.nc ${ROSE_DATAC};
import matplotlib as mpl
mpl.use('Agg')
import sys
import multiprocessing
import numpy as np
from cmocean import cm
import PyFVCOM as pf
import pmltools as pt
labels = {'q2': 'Turbulent kinetic energy $(m^{2}s^{-2})$',
'l': 'Turbulent macroscale $(m^{3}s^{-2})$',
'q2l': 'Turbulent kinetic\nenergy x turblent\nmacroscale ($cm^{3}s^{-2}$)',
'tke': 'Turbulent kinetic energy $(m^{2}s^{-2})$',
'viscofh': 'Horizontal Turbulent Eddy Viscosity $(m^{2}s^{-1})$',
'teps': 'Turbulent kinetic\nenergy x turblent\nmacroscale ($cm^{3}s^{-2}$)',
'tauc': 'Bed shear stress $(m^{2}s^{-2})$',
'temp': 'Temperature ($\degree C$)',
'salinity': 'Salinity (PSU)',
'zeta': 'Surface elevation (m)',
'uv': 'Speed $(ms^{-1})$',
'uava': 'Depth averaged speed $(ms^{-1})$',
'uvanomaly': 'Speed anomaly $(ms^{-1})$',
'direction': 'Direction $(\degree)$',
'O3_c': 'Carbonate total dissolved\ninorganic carbon $(mmol C/m^3)$',
'O3_pH': 'Carbonate pH',
'O3_TA': 'Total alkalinity $(umol/kg)$',
'O3_fair': 'Carbonate air-sea flux of $CO_{2} (mmol C/m^{2}/d)$',
'volume': 'Node-based control water column volume $(m^{3})$'}
def plot_var(idx):
plot = pf.plot.Plotter(fvcom, figsize=(23, 18), cmap=cmap, cb_label=label, extend=extension, res=None)
plot.plot_field(np.squeeze(getattr(fvcom.data, var))[idx, level, :])
plot.tripcolor_plot.set_clim(clim[0], clim[1])
plot.axes.set_title(fvcom.time.Times[idx][:-7].replace('T', ' '))
suffix = ''
plot.figure.savefig('{}_{:04d}.png'.format(var, idx + 1),
bbox_inches='tight',
pad_inches=0.2,
dpi=120)
plot.close()
fname = sys.argv[1]
var = sys.argv[2]
clim = [float(sys.argv[3]), float(sys.argv[4])]
print(fname)
cmap = pt.plotting.pmlcmaps(var)
pool_size = 4
fvcom = pf.read.FileReader(fname, [var])
label = labels[var]
extension = pt.plotting.colourbar_extension(*clim, getattr(fvcom.data, var).min(), getattr(fvcom.data, var).max())
level = 0
time_indices = range(fvcom.dims.time)
# Launch the parallel plotting and then close the pool ready for the
# next variable.
pool = multiprocessing.Pool(pool_size)
pool.map(plot_var, time_indices)
pool.close()
[command]
default = today_output=/${ARCHIVE_DIR}/${FORECAST_DAY}/${GRID_NAME}_0001.nc; echo ${today_output}
python3 plot_var.py ${today_output} temp 8 18; python3 plot_var.py ${today_output} salinity 31 36;
mkdir -p /${PLOT_DIR}/${FORECAST_DAY}/; mv *.png /${PLOT_DIR}/${FORECAST_DAY}/
import numpy as np
import datetime as dt
import sys
import PyFVCOM as pf
fvcom_output_path = sys.argv[1]
fvcom_grid_name = sys.argv[2]
start_date = dt.datetime.strptime(sys.argv[3], '%Y-%m-%d')
end_date = dt.datetime.strptime(sys.argv[4], '%Y-%m-%d') - dt.timedelta(days=1)
date_list = pf.utilities.time.date_range(start_date, end_date)
with open('make_daily_nc.sh', 'w') as f:
f.write('#!/bin/bash \n')
this_filestr = '{}/{}_0001.nc'.format(fvcom_output_path,fvcom_grid_name)
this_fr = pf.read.FileReader(this_filestr)
for i, this_date in enumerate(date_list):
time_ind = [np.argwhere(this_fr.time.datetime == this_date), np.argwhere(this_fr.time.datetime == this_date + dt.timedelta(hours=23))]
this_out_filestr = '{}_{}.nc'.format(fvcom_grid_name, this_date.strftime('%Y-%m-%d'))
with open('make_daily_nc.sh', 'a') as f:
f.write('ncks -d time,{},{} {} {} \n'.format(np.squeeze(time_ind[0]), np.squeeze(time_ind[1]), this_filestr, this_out_filestr))
[command]
default = module purge; module load ipd; module load nco;
python3 make_ncks_script.py ${ROSE_DATAC}/output ${GRID_NAME} ${START_DAY} ${END_DAY};
bash ./make_daily_nc.sh;
mv *.nc ${REMOTE_ARCHIVE_DIR}/
[command]
default = ln -s ${COMMON_FILES_PATH}/* ${ROSE_DATAC};
default = ln -sf ${COMMON_FILES_PATH}/* ${ROSE_DATAC};
[command]
default = ln -s ${ROSE_DATA}/* ${ROSE_DATAC};
default = ln -sf ${ROSE_DATA}/* ${ROSE_DATAC};
......@@ -32,10 +32,10 @@ else:
missing_dates = np.asarray([start_date + dt.timedelta(days=int(this_ind)) for this_ind in np.arange(0, (end_date - start_date).days + 1)])
for this_missing_loop in np.arange(0, no_miss_loops):
for this_missing_loop in np.arange(-1, no_miss_loops):
new_missing_dates = []
for this_date in missing_dates:
if this_missing_loop > 0:
if this_missing_loop >= 0:
print('Trying again to fill for {}'.format(this_date))
else:
print(this_date)
......
[command]
default = cp update_river_data.py ${RIVER_MODEL_PATH}; cd ${RIVER_MODEL_PATH}; python3 update_river_data.py ${WRF_ARCHIVE_DIR} ${START_DAY}; rm update_river_data.py
default = cp update_river_data.py ${RIVER_MODEL_PATH}; cd ${RIVER_MODEL_PATH}; python3 update_river_data.py ${WRF_ARCHIVE_DIR} ${WRF_ARCHIVE_DATEFMT} ${START_DAY}; rm update_river_data.py
[command]
default = cp ${GRID_NAME}_run.nml ${ROSE_DATAC}; mkdir ${ROSE_DATAC}/output
default = cp ${GRID_NAME}_run.nml ${ROSE_DATAC}; mkdir -p ${ROSE_DATAC}/output
[file:${GRID_NAME}_run.nml]
source = namelist:NML_CASE namelist:NML_STARTUP namelist:NML_IO namelist:NML_INTEGRATION namelist:NML_RESTART namelist:NML_NETCDF namelist:NML_NETCDF_AV namelist:NML_SURFACE_FORCING namelist:NML_HEATING_CALCULATED namelist:NML_PHYSICS namelist:NML_RIVER_TYPE namelist:NML_OPEN_BOUNDARY_CONTROL namelist:NML_GRID_COORDINATES namelist:NML_GROUNDWATER namelist:NML_LAG namelist:NML_ADDITIONAL_MODELS namelist:NML_PROBES namelist:NML_STATION_TIMESERIES namelist:NML_FABM namelist:NML_NESTING namelist:NML_NCNEST namelist:NML_NCNEST_WAVE namelist:NML_BOUNDSCHK namelist:NML_DYE_RELEASE namelist:NML_PWP namelist:NML_SST_ASSIMILATION namelist:NML_SSTGRD_ASSIMILATION namelist:NML_SSHGRD_ASSIMILATION namelist:NML_TSGRD_ASSIMILATION namelist:NML_CUR_NGASSIMILATION namelist:NML_CUR_OIASSIMILATION namelist:NML_TS_NGASSIMILATION namelist:NML_TS_OIASSIMILATION
......
[jinja2:suite.rc]
## Run properties
COLD_START=True
COLD_START=False
SEDIMENT=False
USE_CETO=True
NODES=10
......@@ -8,10 +8,13 @@ FORECAST=True
REMOTE_USER='modop'
MAIL_TO='mbe@pml.ac.uk'
INITIAL_START_DATE='2019-02-05T00:00:00Z'
INITIAL_START_DATE='2019-05-10T00:00:00Z'
FINAL_CYCLE_POINT='NONE'
RUNDAYS=1
HINDCAST_DAYS=1
FORECAST_DAYS=2
ARCHIVE_DIR='data/sthenno1/scratch/modop/Model/FVCOM_rosa/output'
REMOTE_ARCHIVE_DIR='/gpfs1/users/modellers/modop/Output/FVCOM_rosa_rolling'
## Grid properties and files
GRID_NAME='aqua_v16'
......@@ -21,10 +24,6 @@ PLOT_DIR='data/sthenno1/scratch/modop/Model/FVCOM_rosa/plots'
TEMP_ACTIVE='T'
SALT_ACTIVE='T'
TEMP_ACTIVE='T'
SALT_ACTIVE='T'
## Atmospheric setup
WIND_ON='T'
HEATING_ON='T'
......@@ -34,7 +33,7 @@ AIR_PRESSURE_ON='T'
WRF_RUN_SUITE='wrf'
WRF_FORECAST_FILE_DIR='/gpfs1/users/modellers/modop/Models/WRF_transfer_dir/'
WRF_ARCHIVE_DIR='/data/sthenno1/scratch/modop/Model/WRF/output'
WRF_ARCHIVE_DATEFMT='%Y%m%d'
WRF_ARCHIVE_DATEFMT='%Y-%m-%d'
## River setup
## Between 'NONE', 'NEURAL_NET', and 'CLIMATOLOGY'
......@@ -59,11 +58,11 @@ NEST_RUN_SUITE='rose-rosa'
NEST_INTERVAL='24'
## FVCOM namelist settings
EXT_TSTEP='.150'
ISPLIT='5'
STARTUP_DMAX='5.00'
HORIZONTAL_MIXING_COEFFICIENT='2.000000e-01'
VERTICAL_MIXING_COEFFICIENT='1.000000e-05'
EXT_TSTEP='1.5'
ISPLIT='10'
STARTUP_DMAX='-3'
HORIZONTAL_MIXING_COEFFICIENT='0.04'
VERTICAL_MIXING_COEFFICIENT='1.000000e-06'
COORDINATES='cartesian'
# Output options
......
......@@ -18,6 +18,8 @@ MAIL_TO='mbe@pml.ac.uk'
GRID_NAME='tamar_v2'
COMMON_FILES_PATH='/users/modellers/modop/Models/FVCOM_tamar_common/'
ARCHIVE_DIR='data/sthenno1/scratch/modop/Model/FVCOM_tamar/output'
PLOT_DIR='data/sthenno1/scratch/modop/Model/FVCOM_tamar/plots'
REMOTE_ARCHIVE_DIR='/gpfs1/users/modellers/modop/Output/FVCOM_tamar_rolling'
TEMP_ACTIVE='T'
SALT_ACTIVE='T'
......@@ -30,8 +32,8 @@ AIR_PRESSURE_ON='T'
## WRF suite settings if any of the above are on
WRF_RUN_SUITE='wrf'
WRF_FORECAST_FILE_DIR='/gpfs1/users/modellers/modop/Models/WRF_transfer_dir/'
WRF_ARCHIVE_DIR='data/sthenno1/backup/pica/models/WRF/wrf-preprocess-gfs/output'
WRF_ARCHIVE_DATEFMT='%Y%m%d'
WRF_ARCHIVE_DIR='/data/sthenno1/scratch/modop/Model/WRF/output'
WRF_ARCHIVE_DATEFMT='%Y-%m-%d'
## River setup
......
......@@ -18,6 +18,8 @@
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
{% else %}
transfer_restart => run_fvcom
{% endif %}
"""
[[[P1D]]]
......@@ -25,7 +27,14 @@
run_fvcom[-P1D] => start_cycle => softlink_forcing & softlink_forcing_remote => write_run_namelist
{% if FORECAST and (WIND_ON == 'T' or HEATING_ON == 'T' or PRECIPITATION_ON == 'T' or AIR_PRESSURE_ON == 'T') %}
start_cycle => wrf_suite_trigger <wrf::transfer_for_fvcom> => get_wrf_file => write_run_namelist
start_cycle => wrf_suite_trigger <wrf::transfer_for_fvcom>
wrf_suite_trigger <wrf::transfer_for_fvcom>:succeeded & softlink_forcing_remote => get_wrf_file
wrf_suite_trigger <wrf::transfer_for_fvcom>:failed | get_wrf_file => write_run_namelist
wrf_suite_trigger <wrf::transfer_for_fvcom>:succeeded => !adjust_namelist_met
wrf_suite_trigger <wrf::transfer_for_fvcom>:failed & write_run_namelist => adjust_namelist_met
(wrf_suite_trigger <wrf::transfer_for_fvcom>:succeeded & write_run_namelist) | adjust_namelist_met => run_fvcom
{% elif WIND_ON == 'T' or HEATING_ON == 'T' or PRECIPITATION_ON == 'T' or AIR_PRESSURE_ON == 'T' %}
start_cycle => get_archive_wrf_file => convert_wrf_file => write_run_namelist
{% endif %}
......@@ -46,8 +55,8 @@
{% if RIVER_MODEL == 'NEURAL_NET' and FORECAST %}
start_cycle => wrf_archive_trigger <wrf::cycle_finished> & update_river_model & softlink_forcing => generate_rivers
generate_rivers:failed => trigger_archive_wrf & write_empty_river_nml
generate_rivers:succeeded => !trigger_archive_wrf & !write_empty_river_nml
wrf_archive_trigger <wrf::cycle_finished>:failed | generate_rivers:failed => write_empty_river_nml
generate_rivers:succeeded => !write_empty_river_nml
generate_rivers:succeeded | write_empty_river_nml => mv_river_files => write_river_number
write_run_namelist => write_river_number => run_fvcom
......@@ -63,12 +72,11 @@
{% endif %}
{% if FORECAST %}
write_run_namelist => run_fvcom => transfer_data => transfer_data_today
write_run_namelist => run_fvcom => transfer_data => transfer_data_today => remote_archive => clean_output
{% else %}
write_run_namelist => run_fvcom => transfer_data
write_run_namelist => run_fvcom => transfer_data => clean_output
{% endif %}
run_fvcom => nan_check
transfer_data => plot_surf_vars
"""
......@@ -102,6 +110,7 @@
REMOTE_TRANSFER_DIR={{REMOTE_TRANSFER_DIR}}
ARCHIVE_DIR={{ARCHIVE_DIR}}
PLOT_DIR={{PLOT_DIR}}
REMOTE_ARCHIVE_DIR={{REMOTE_ARCHIVE_DIR}}
HARMONICS_FILE_PATH={{HARMONICS_FILE_PATH}}
DONOR_RESTART_FILE_PATH={{DONOR_RESTART_FILE_PATH}}
......@@ -135,6 +144,7 @@
WRF_FORECAST_FILE_DIR={{WRF_FORECAST_FILE_DIR}}
WRF_ARCHIVE_DIR={{WRF_ARCHIVE_DIR}}
WRF_ARCHIVE_DATEFMT={{WRF_ARCHIVE_DATEFMT}}
COMMON_FILES_PATH={{COMMON_FILES_PATH}}
WRF_ARCHIVE_DATESTR=$(rose date --print-format={{WRF_ARCHIVE_DATEFMT}} $CYLC_TASK_CYCLE_POINT)
......@@ -248,11 +258,19 @@
max-polls = 1440
[[[job]]]
execution retry delays = 3*PT15M
[[get_archive_wrf_file]]
inherit = remote_job
[[convert_wrf_file]]
inherit = slurm_job_1
[[adjust_namelist_met]]
inherit = remote_job
script = """
sed -i "s|.*AIRPRESSURE_ON.*|AIRPRESSURE_ON=F,|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
sed -i "s|.*HEATING_ON.*|HEATING_ON=F,|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
sed -i "s|.*RECIPITATION_ON.*|PRECIPITATION_ON=F,|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
sed -i "s|.*WIND_ON.*|WIND_ON=T,|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
"""
[[update_river_model]]
[[generate_rivers]]
......@@ -266,14 +284,9 @@
NO_RIVERS=$(grep "&NML_RIVER" ${ROSE_DATAC}/${GRID_NAME}_riv.nml | wc -l);
sed -i "s|.*RIVER_NUMBER.*| RIVER_NUMBER = ${NO_RIVERS},|" ${ROSE_DATAC}/${GRID_NAME}_run.nml
"""
[[trigger_archive_wrf]]
script = """
echo "Get the dates missing from the river model and pass to the wrf archive run"
"""
[[write_empty_river_nml]]
script = """
echo "Make a fake riv.nml and copy to run directory"
touch ${GRID_NAME}_riv.nml; cp ${GRID_NAME}_riv.nml /${REMOTE_TRANSFER_DIR}/
"""
[[run_fvcom]]
......@@ -300,10 +313,16 @@
echo "starting forecast cycle"
"""
[[transfer_restart]]
inherit = slurm_job
inherit = slurm_job_1
script = """
ln -s ${ROSE_DATACP1D}/output/${GRID_NAME}_restart_0001.nc ${ROSE_DATAC}/${GRID_NAME}_restart_0001.nc
ln -sf ${ROSE_DATACP1D}/output/${GRID_NAME}_restart_0001.nc ${ROSE_DATAC}/${GRID_NAME}_restart_0001.nc
"""
[[nan_check]]
inherit = remote_job
[[plot_surf_vars]]
[[remote_archive]]
inherit = remote_job
[[clean_output]]
inherit = remote_job
script = """
rm ${ROSE_DATAC}/output/${GRID_NAME}_0001.nc
"""
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