source: TOOLS/MOSAIX/nemo.py @ 4083

Last change on this file since 4083 was 4083, checked in by omamce, 6 years ago

O.M. : add lbc_mask to nemo.py

  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 6.6 KB
RevLine 
[3723]1### ===========================================================================
2###
3### Periodicity of ORCA fields
4###
5### ===========================================================================
6##
7##  Warning, to install, configure, run, use any of Olivier Marti's
8##  software or to read the associated documentation you'll need at least
9##  one (1) brain in a reasonably working order. Lack of this implement
10##  will void any warranties (either express or implied).
11##  O. Marti assumes no responsability for errors, omissions,
12##  data loss, or any other consequences caused directly or indirectly by
13##  the usage of his software by incorrectly or partially configured
14##  personal.
15##
16## SVN information
[3725]17__Author__   = "$Author$"
18__Date__     = "$Date$"
19__Revision__ = "$Revision$"
20__Id__       = "$Id$"
21__HeadURL    = "$HeadURL$"
[3723]22
23def lbc (ptab, nperio=6, cd_type='T', psgn=1.0) :
[4083]24    # Set periodicity on input fields
[3740]25    """
26    ptab      : Input array
27      rank 2 at least : patb[...., lat, lon]
28    nperio    : Type of periodicity
29      1, 4, 6 : Cyclic on i dimension (generaly longitudes)
30      2       : Obsolete (was symmetric condition at southern boundary ?)
31      3, 4    : North fold T-point pivot (legacy ORCA2)
32      5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo)
33    cd_type   : Grid specification : T, U, V or F
34    psgn      : For change of sign for vector components
[3723]35   
[3740]36    See NEMO documentation for further details
37    """
38       
[3723]39    jpi = ptab.shape[-1]
40   
41    #
42    #> East-West boundary conditions
43    # --------------------------------
44
45    if nperio in [1, 4, 6] :
46        # ... cyclic
47        ptab [...,:,  0] = ptab [...,:,-2]
48        ptab [...,:, -1] = ptab [...,:, 1]
49   
50    #
51    #> North-South boundary conditions
52    # ----------------------------------
53    if nperio in [3, 4] :  # North fold T-point pivot     
54        if cd_type in [ 'T', 'W' ] : # T-, W-point
[3740]55            ptab[..., -1, 1:       ] = psgn * ptab[..., -3, -1:0:-1      ]     
56            ptab[..., -1, 0        ] = psgn * ptab[..., -3, 2            ]
57            ptab[..., -2, jpi//2:  ] = psgn * ptab[..., -2, jpi//2:0:-1  ]
[3723]58                     
59        if cd_type == 'U' :
[3740]60            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -3, -1:0:-1      ]       
61            ptab[..., -1,  0       ] = psgn * ptab[..., -3,  1           ]
62            ptab[..., -1, -1       ] = psgn * ptab[..., -3, -2           ] 
63            ptab[..., -2, jpi//2-1:] = psgn * ptab[..., -2, jpi//2+1:0:-1]
[3723]64           
65        if cd_type == 'V' : 
[3740]66            ptab[..., -2, 1:       ] = psgn * ptab[..., -3, jpi-1:0:-1   ]
67            ptab[..., -1, 1:       ] = psgn * ptab[..., -4, -1:0:-1      ]   
68            ptab[..., -1, 0        ] = psgn * ptab[..., -4, 2            ]
[3723]69           
70        if cd_type == 'F' :
[3740]71            ptab[..., -2, 0:-1     ] = psgn * ptab[..., -3, -1:0:-1      ]
72            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -4, -1:0:-1      ]
73            ptab[..., -1,  0       ] = psgn * ptab[..., -4,  1           ]
74            ptab[..., -1, -1       ] = psgn * ptab[..., -4, -2           ] 
[3723]75     
76    if nperio in [5, 6] :            #  North fold F-point pivot 
77        if cd_type in ['T', 'W']  :
[3740]78            ptab[..., -1, 0:       ] = psgn * ptab[..., -2, -1::-1       ]
[3723]79               
80        if cd_type == 'U' :
[3740]81            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -2, -2::-1       ]       
82            ptab[..., -1, -1       ] = psgn * ptab[..., -2, 0            ]
[3723]83             
84        if cd_type == 'V' :
[3740]85            ptab[..., -1, 0:       ] = psgn * ptab[..., -3, -1::-1       ]
86            ptab[..., -2, jpi/2:   ] = psgn * ptab[..., -2, jpi/2-1::-1  ]
[3723]87                             
88        if cd_type == 'F' :
[3740]89            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -3, -2::-1       ]
90            ptab[..., -1, -1       ] = psgn * ptab[..., -3, 0            ]
91            ptab[..., -2, jpi//2:-1] = psgn * ptab[..., -2, jpi//2-2::-1 ]
[3723]92
93    return ptab
[4083]94
95
96def lbc_mask (ptab, nperio=6, cd_type='T', psgn=1.0) :
97    # Mask fields on duplicate points
98    """
99    ptab      : Input array
100      rank 2 at least : patb[...., lat, lon]
101    nperio    : Type of periodicity
102      1, 4, 6 : Cyclic on i dimension (generaly longitudes)
103      2       : Obsolete (was symmetric condition at southern boundary ?)
104      3, 4    : North fold T-point pivot (legacy ORCA2)
105      5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo)
106    cd_type   : Grid specification : T, U, V or F
107    psgn      : For change of sign for vector components
108   
109    See NEMO documentation for further details
110    """
[3723]111       
[4083]112    jpi = ptab.shape[-1]
113    #
114    zero = 0
115   
116    #
117    #> East-West boundary conditions
118    # --------------------------------
119
120    if nperio in [1, 4, 6] :
121        # ... cyclic
122        ptab [...,:,  0] = zero
123        ptab [...,:, -1] = zero
124   
125    #
126    #> North-South boundary conditions
127    # ----------------------------------
128    if nperio in [3, 4] :  # North fold T-point pivot     
129        if cd_type in [ 'T', 'W' ] : # T-, W-point
130            ptab[..., -1, 1:       ] = zero
131            ptab[..., -1, 0        ] = zero
132            ptab[..., -2, jpi//2:  ] = zero
133                     
134        if cd_type == 'U' :
135            ptab[..., -1, 0:-1     ] = zero 
136            ptab[..., -1,  0       ] = zero
137            ptab[..., -1, -1       ] = zero
138            ptab[..., -2, jpi//2-1:] = zero
139           
140        if cd_type == 'V' : 
141            ptab[..., -2, 1:       ] = zero
142            ptab[..., -1, 1:       ] = zero   
143            ptab[..., -1, 0        ] = zero
144           
145        if cd_type == 'F' :
146            ptab[..., -2, 0:-1     ] = zero
147            ptab[..., -1, 0:-1     ] = zero
148            ptab[..., -1,  0       ] =zero
149            ptab[..., -1, -1       ] = zero
150     
151    if nperio in [5, 6] :            #  North fold F-point pivot 
152        if cd_type in ['T', 'W']  :
153            ptab[..., -1, 0:       ] = zero
154               
155        if cd_type == 'U' :
156            ptab[..., -1, 0:-1     ] = zero       
157            ptab[..., -1, -1       ] = zero
158             
159        if cd_type == 'V' :
160            ptab[..., -1, 0:       ] = zero
161            ptab[..., -2, jpi/2:   ] = zero
162                             
163        if cd_type == 'F' :
164            ptab[..., -1, 0:-1     ] = zero
165            ptab[..., -1, -1       ] = zero
166            ptab[..., -2, jpi//2:-1] = zero
167
168    return ptab
[3740]169## ===========================================================================
170##
171##                               That's all folk's !!!
172##
173## ===========================================================================
Note: See TracBrowser for help on using the repository browser.