source: TOOLS/MOSAIX/nemo.py @ 4259

Last change on this file since 4259 was 4259, checked in by omamce, 5 years ago

O.M. : MOSAIX

  • Two versions of fraction on atmosphere grid to be compatible with both DYNAMICO and LMDZ
  • Various improvments
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 7.4 KB
Line 
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
17__Author__   = "$Author$"
18__Date__     = "$Date$"
19__Revision__ = "$Revision$"
20__Id__       = "$Id$"
21__HeadURL    = "$HeadURL$"
22
23import sys, numpy as np
24
25def __guessNperio__ (jpi, nperio) :
26    """
27    Tries to guess the value of nperio
28    """
29    if nperio == None :
30        if jpi ==  182 : nperio = 4 #   ORCA2. We choose legacy orca2
31        if jpi ==  362 : nperio = 6 #   ORCA1.
32        if jpi == 1442 : nperio = 6 # ORCA025.
33        #
34        if nperio == None :
35            sys.exit ('in nemo.lbc : nperio not found, and cannot by guessed' )
36        else :
37            print ('nperio set as {:d} (deduced from jpi={:d}'.format(nperio, jpi))
38
39    return nperio   
40           
41def lbc (ptab, nperio=None, cd_type='T', psgn=1.0) :
42    """
43    Set periodicity on input fields
44    ptab      : Input array
45      rank 2 at least : ptab[...., lat, lon]
46    nperio    : Type of periodicity
47      1, 4, 6 : Cyclic on i dimension (generaly longitudes)
48      2       : Obsolete (was symmetric condition at southern boundary ?)
49      3, 4    : North fold T-point pivot (legacy ORCA2)
50      5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo)
51    cd_type   : Grid specification : T, U, V or F
52    psgn      : For change of sign for vector components (1 for scalars, -1 for vector components)
53   
54    See NEMO documentation for further details
55    """
56       
57    jpi    = ptab.shape[-1]
58    nperio = __guessNperio__ ( jpi, nperio )
59    psgn   = ptab.dtype.type(psgn)
60   
61    #
62    #> East-West boundary conditions
63    # ------------------------------
64
65    if nperio in [1, 4, 6] :
66        # ... cyclic
67        ptab [...,:,  0] = ptab [...,:,-2]
68        ptab [...,:, -1] = ptab [...,:, 1]
69   
70    #
71    #> North-South boundary conditions
72    # --------------------------------
73    if nperio in [3, 4] :  # North fold T-point pivot
74        if cd_type in [ 'T', 'W' ] : # T-, W-point
75            ptab[..., -1, 1:       ] = psgn * ptab[..., -3, -1:0:-1      ]     
76            ptab[..., -1, 0        ] = psgn * ptab[..., -3, 2            ]
77            ptab[..., -2, jpi//2:  ] = psgn * ptab[..., -2, jpi//2:0:-1  ]
78                     
79        if cd_type == 'U' :
80            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -3, -1:0:-1      ]       
81            ptab[..., -1,  0       ] = psgn * ptab[..., -3,  1           ]
82            ptab[..., -1, -1       ] = psgn * ptab[..., -3, -2           ] 
83            ptab[..., -2, jpi//2-1:] = psgn * ptab[..., -2, jpi//2+1:0:-1]
84           
85        if cd_type == 'V' : 
86            ptab[..., -2, 1:       ] = psgn * ptab[..., -3, jpi-1:0:-1   ]
87            ptab[..., -1, 1:       ] = psgn * ptab[..., -4, -1:0:-1      ]   
88            ptab[..., -1, 0        ] = psgn * ptab[..., -4, 2            ]
89           
90        if cd_type == 'F' :
91            ptab[..., -2, 0:-1     ] = psgn * ptab[..., -3, -1:0:-1      ]
92            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -4, -1:0:-1      ]
93            ptab[..., -1,  0       ] = psgn * ptab[..., -4,  1           ]
94            ptab[..., -1, -1       ] = psgn * ptab[..., -4, -2           ] 
95     
96    if nperio in [5, 6] :            #  North fold F-point pivot 
97        if cd_type in ['T', 'W']  :
98            ptab[..., -1, 0:       ] = psgn * ptab[..., -2, -1::-1       ]
99               
100        if cd_type == 'U' :
101            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -2, -2::-1       ]       
102            ptab[..., -1, -1       ] = psgn * ptab[..., -2, 0            ]
103             
104        if cd_type == 'V' :
105            ptab[..., -1, 0:       ] = psgn * ptab[..., -3, -1::-1       ]
106            ptab[..., -2, jpi//2:  ] = psgn * ptab[..., -2, jpi//2-1::-1 ]
107                             
108        if cd_type == 'F' :
109            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -3, -2::-1       ]
110            ptab[..., -1, -1       ] = psgn * ptab[..., -3, 0            ]
111            ptab[..., -2, jpi//2:-1] = psgn * ptab[..., -2, jpi//2-2::-1 ]
112
113    return ptab
114
115
116def lbc_mask (ptab, nperio=None, cd_type='T') :
117    #
118    """
119    Mask fields on duplicated points
120    ptab      : Input array
121      rank 2 at least : ptab[...., lat, lon]
122    nperio    : Type of periodicity
123      1, 4, 6 : Cyclic on i dimension (generaly longitudes)
124      2       : Obsolete (was symmetric condition at southern boundary ?)
125      3, 4    : North fold T-point pivot (legacy ORCA2)
126      5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo)
127    cd_type   : Grid specification : T, U, V or F
128   
129    See NEMO documentation for further details
130    """
131
132    jpi    = ptab.shape[-1]
133    nperio = __guessNperio__ ( jpi, nperio )
134    zero   = ptab.dtype.type(0)
135   
136    #
137    #> East-West boundary conditions
138    # ------------------------------
139    if nperio in [1, 4, 6] :
140        # ... cyclic
141        ptab [...,:,  0] = zero
142        ptab [...,:, -1] = zero
143
144    #
145    #> South (in which nperio cases ?)
146    # --------------------------------
147    if nperio in [1, 3, 4, 5, 6] :
148        ptab[...,0,:] = zero
149       
150    #
151    #> North-South boundary conditions
152    # --------------------------------
153    if nperio in [3, 4] :  # North fold T-point pivot     
154        if cd_type in [ 'T', 'W' ] : # T-, W-point
155            ptab[..., -1, 1:       ] = zero
156            ptab[..., -1, 0        ] = zero
157            ptab[..., -2, jpi//2:  ] = zero
158                     
159        if cd_type == 'U' :
160            ptab[..., -1, 0:-1     ] = zero 
161            ptab[..., -1,  0       ] = zero
162            ptab[..., -1, -1       ] = zero
163            ptab[..., -2, jpi//2-1:] = zero
164           
165        if cd_type == 'V' : 
166            ptab[..., -2, 1:       ] = zero
167            ptab[..., -1, 1:       ] = zero   
168            ptab[..., -1, 0        ] = zero
169           
170        if cd_type == 'F' :
171            ptab[..., -2, 0:-1     ] = zero
172            ptab[..., -1, 0:-1     ] = zero
173            ptab[..., -1,  0       ] = zero
174            ptab[..., -1, -1       ] = zero
175     
176    if nperio in [5, 6] :            #  North fold F-point pivot 
177        if cd_type in ['T', 'W']  :
178            ptab[..., -1, 0:       ] = zero
179               
180        if cd_type == 'U' :
181            ptab[..., -1, 0:-1     ] = zero       
182            ptab[..., -1, -1       ] = zero
183             
184        if cd_type == 'V' :
185            ptab[..., -1, 0:       ] = zero
186            ptab[..., -2, jpi//2:  ] = zero
187                             
188        if cd_type == 'F' :
189            ptab[..., -1, 0:-1     ] = zero
190            ptab[..., -1, -1       ] = zero
191            ptab[..., -2, jpi//2:-1] = zero
192
193    return ptab
194## ===========================================================================
195##
196##                               That's all folk's !!!
197##
198## ===========================================================================
Note: See TracBrowser for help on using the repository browser.