### =========================================================================== ### ### Periodicity of ORCA fields ### ### =========================================================================== ## ## Warning, to install, configure, run, use any of Olivier Marti's ## software or to read the associated documentation you'll need at least ## one (1) brain in a reasonably working order. Lack of this implement ## will void any warranties (either express or implied). ## O. Marti assumes no responsability for errors, omissions, ## data loss, or any other consequences caused directly or indirectly by ## the usage of his software by incorrectly or partially configured ## personal. ## ## SVN information __Author__ = "$Author$" __Date__ = "$Date$" __Revision__ = "$Revision$" __Id__ = "$Id$" __HeadURL = "$HeadURL$" import sys, numpy as np def __guessNperio__ (jpi, nperio) : """ Tries to guess the value of nperio """ if nperio == None : if jpi == 182 : nperio = 4 # ORCA2. We choose legacy orca2 if jpi == 362 : nperio = 6 # ORCA1. if jpi == 1442 : nperio = 6 # ORCA025. # if nperio == None : sys.exit ('in nemo.lbc : nperio not found, and cannot by guessed' ) else : print ('nperio set as {:d} (deduced from jpi={:d}'.format(nperio, jpi)) return nperio def lbc (ptab, nperio=None, cd_type='T', psgn=1.0) : """ Set periodicity on input fields ptab : Input array rank 2 at least : ptab[...., lat, lon] nperio : Type of periodicity 1, 4, 6 : Cyclic on i dimension (generaly longitudes) 2 : Obsolete (was symmetric condition at southern boundary ?) 3, 4 : North fold T-point pivot (legacy ORCA2) 5, 6 : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo) cd_type : Grid specification : T, U, V or F psgn : For change of sign for vector components (1 for scalars, -1 for vector components) See NEMO documentation for further details """ jpi = ptab.shape[-1] nperio = __guessNperio__ ( jpi, nperio ) psgn = ptab.dtype.type(psgn) # #> East-West boundary conditions # ------------------------------ if nperio in [1, 4, 6] : # ... cyclic ptab [...,:, 0] = ptab [...,:,-2] ptab [...,:, -1] = ptab [...,:, 1] # #> North-South boundary conditions # -------------------------------- if nperio in [3, 4] : # North fold T-point pivot if cd_type in [ 'T', 'W' ] : # T-, W-point ptab[..., -1, 1: ] = psgn * ptab[..., -3, -1:0:-1 ] ptab[..., -1, 0 ] = psgn * ptab[..., -3, 2 ] ptab[..., -2, jpi//2: ] = psgn * ptab[..., -2, jpi//2:0:-1 ] if cd_type == 'U' : ptab[..., -1, 0:-1 ] = psgn * ptab[..., -3, -1:0:-1 ] ptab[..., -1, 0 ] = psgn * ptab[..., -3, 1 ] ptab[..., -1, -1 ] = psgn * ptab[..., -3, -2 ] ptab[..., -2, jpi//2-1:] = psgn * ptab[..., -2, jpi//2+1:0:-1] if cd_type == 'V' : ptab[..., -2, 1: ] = psgn * ptab[..., -3, jpi-1:0:-1 ] ptab[..., -1, 1: ] = psgn * ptab[..., -4, -1:0:-1 ] ptab[..., -1, 0 ] = psgn * ptab[..., -4, 2 ] if cd_type == 'F' : ptab[..., -2, 0:-1 ] = psgn * ptab[..., -3, -1:0:-1 ] ptab[..., -1, 0:-1 ] = psgn * ptab[..., -4, -1:0:-1 ] ptab[..., -1, 0 ] = psgn * ptab[..., -4, 1 ] ptab[..., -1, -1 ] = psgn * ptab[..., -4, -2 ] if nperio in [5, 6] : # North fold F-point pivot if cd_type in ['T', 'W'] : ptab[..., -1, 0: ] = psgn * ptab[..., -2, -1::-1 ] if cd_type == 'U' : ptab[..., -1, 0:-1 ] = psgn * ptab[..., -2, -2::-1 ] ptab[..., -1, -1 ] = psgn * ptab[..., -2, 0 ] if cd_type == 'V' : ptab[..., -1, 0: ] = psgn * ptab[..., -3, -1::-1 ] ptab[..., -2, jpi//2: ] = psgn * ptab[..., -2, jpi//2-1::-1 ] if cd_type == 'F' : ptab[..., -1, 0:-1 ] = psgn * ptab[..., -3, -2::-1 ] ptab[..., -1, -1 ] = psgn * ptab[..., -3, 0 ] ptab[..., -2, jpi//2:-1] = psgn * ptab[..., -2, jpi//2-2::-1 ] return ptab def lbc_mask (ptab, nperio=None, cd_type='T') : # """ Mask fields on duplicated points ptab : Input array rank 2 at least : ptab[...., lat, lon] nperio : Type of periodicity 1, 4, 6 : Cyclic on i dimension (generaly longitudes) 2 : Obsolete (was symmetric condition at southern boundary ?) 3, 4 : North fold T-point pivot (legacy ORCA2) 5, 6 : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo) cd_type : Grid specification : T, U, V or F See NEMO documentation for further details """ jpi = ptab.shape[-1] nperio = __guessNperio__ ( jpi, nperio ) zero = ptab.dtype.type(0) # #> East-West boundary conditions # ------------------------------ if nperio in [1, 4, 6] : # ... cyclic ptab [...,:, 0] = zero ptab [...,:, -1] = zero # #> South (in which nperio cases ?) # -------------------------------- if nperio in [1, 3, 4, 5, 6] : ptab[...,0,:] = zero # #> North-South boundary conditions # -------------------------------- if nperio in [3, 4] : # North fold T-point pivot if cd_type in [ 'T', 'W' ] : # T-, W-point ptab[..., -1, 1: ] = zero ptab[..., -1, 0 ] = zero ptab[..., -2, jpi//2: ] = zero if cd_type == 'U' : ptab[..., -1, 0:-1 ] = zero ptab[..., -1, 0 ] = zero ptab[..., -1, -1 ] = zero ptab[..., -2, jpi//2-1:] = zero if cd_type == 'V' : ptab[..., -2, 1: ] = zero ptab[..., -1, 1: ] = zero ptab[..., -1, 0 ] = zero if cd_type == 'F' : ptab[..., -2, 0:-1 ] = zero ptab[..., -1, 0:-1 ] = zero ptab[..., -1, 0 ] = zero ptab[..., -1, -1 ] = zero if nperio in [5, 6] : # North fold F-point pivot if cd_type in ['T', 'W'] : ptab[..., -1, 0: ] = zero if cd_type == 'U' : ptab[..., -1, 0:-1 ] = zero ptab[..., -1, -1 ] = zero if cd_type == 'V' : ptab[..., -1, 0: ] = zero ptab[..., -2, jpi//2: ] = zero if cd_type == 'F' : ptab[..., -1, 0:-1 ] = zero ptab[..., -1, -1 ] = zero ptab[..., -2, jpi//2:-1] = zero return ptab ## =========================================================================== ## ## That's all folk's !!! ## ## ===========================================================================