rotation of vectors incorrectly handled in nemo_bdy_lib.py
Created by: jdha
a case of lost in translation from the matlab to the python. Original matlab syntax:
function [prot] = nemo_rot_rep(pxin,pyin,cd_type,cdtodo,gcos,gsin)
% nemo_rot_rep rotate nemo vector components
% [PROT] = nemo_rot_rep(PXIN,PYIN,CD_TYPE,CDTODO,GCOS,GSIN) adapted
% from rot_rep NEMO v3.3.1 routine. Rotate the Repere: Change vector
% componantes between geographic grid <--> stretched coordinates grid.r
%
% In:
% pxin, pyin ! vector componantes
% cd_type ! define the nature of pt2d array grid-points
% cdtodo ! specify the work to do:
% 'en->i' east-north to model i componante
% 'en->j' east-north to model j componante
% 'ij->e' model i-j componantes to east componante
% 'ij->n' model i-j componantes to north componante
% gcos rotation angle from nemo_grid_angle.m
% gsin rotation angle from nemo_grid_angle.m
%
% Out:
% prot
%
% Example:
%
% Author: J Harle (jdha@noc.ac.uk) 24-05-11
%
% See also nemo_grid_angle
switch (cdtodo)
case ('en->i') % 'en->i' est-north to model i componante
switch (cd_type)
case ('T') ; prot = pxin.*gcos + pyin.*gsin ;
otherwise ; error( 'Only T, U, V and F grid points are coded' )
end
case ('en->j') % 'en->j' est-north to model j componante
switch (cd_type)
case ('T') ; prot = pyin.*gcos - pxin.*gsin ;
otherwise ; error( 'Only T, U, V and F grid points are coded' )
end
case ('ij->e') % 'ij->e' model i-j componantes to est componante
switch (cd_type)
case ('T') ; prot = pxin.*gcos - pyin.*gsin ;
otherwise ; error( 'Only T, U, V and F grid points are coded' )
end
case ('ij->n') % 'ij->n' model i-j componantes to est componante
switch (cd_type)
case ('T') ; prot = pyin.*gcos + pxin.*gsin ;
otherwise ; error( 'Only T, U, V and F grid points are coded' )
end
otherwise ; error( 'rot_rep: Syntax Error in the definition of cdtodo' )
end
The logic in the python (utils/nemo_bdy_lib.py) appears to be incorrect, try replacing:
def rot_rep(pxin, pyin, dummy, cd_todo, gcos, gsin):
"""rotate function"""
if cd_todo.lower() in ['en to i', 'ij to e']:
x_var, y_var = pxin, pyin
elif cd_todo.lower() in ['en to j', 'ij to n']:
x_var, y_var = pyin, pxin*-1
else:
raise SyntaxError('rot_rep cd_todo %s is invalid' %cd_todo)
return x_var * gcos + y_var * grin
with:
def rot_rep(pxin, pyin, dummy, cd_todo, gcos, gsin):
"""rotate function"""
if cd_todo.lower() == 'en to i':
x_var, y_var = pxin, pyin
elif cd_todo.lower() == 'en to j':
x_var, y_var = pyin, pxin*-1
elif cd_todo.lower() == 'ij to e':
x_var, y_var = pxin, pyin*-1
elif cd_todo.lower() == 'ij to n':
x_var, y_var = pyin, pxin
else:
raise SyntaxError('rot_rep cd_todo %s is invalid' %cd_todo)
return x_var * gcos + y_var * gsin
or similar ... need also to have benchmark in place to verify that this is working (e.g. two tests with U[:,:]=1, V[:,:]=0 and vice versa