...
 
Commits (4)
......@@ -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 = 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')
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;
python3 make_ncks_script.py ${ROSE_DATAC}/output ${GRID_NAME} ${START_DAY} ${END_DAY};
bash ./make_daily_nc.sh;
mv *.nc ${REMOTE_ARCHIVE_DIR}/
......@@ -70,12 +70,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
"""
......@@ -317,4 +316,10 @@
"""
[[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
"""