source: TOOLS/MOSAIX/nemo.py @ 4359

Last change on this file since 4359 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
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
[4259]23import sys, numpy as np
24
25def __guessNperio__ (jpi, nperio) :
[3740]26    """
[4259]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
[3740]44    ptab      : Input array
[4259]45      rank 2 at least : ptab[...., lat, lon]
[3740]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
[4259]52    psgn      : For change of sign for vector components (1 for scalars, -1 for vector components)
[3723]53   
[3740]54    See NEMO documentation for further details
55    """
56       
[4259]57    jpi    = ptab.shape[-1]
58    nperio = __guessNperio__ ( jpi, nperio )
59    psgn   = ptab.dtype.type(psgn)
[3723]60   
61    #
62    #> East-West boundary conditions
[4259]63    # ------------------------------
[3723]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
[4259]72    # --------------------------------
73    if nperio in [3, 4] :  # North fold T-point pivot
[3723]74        if cd_type in [ 'T', 'W' ] : # T-, W-point
[3740]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  ]
[3723]78                     
79        if cd_type == 'U' :
[3740]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]
[3723]84           
85        if cd_type == 'V' : 
[3740]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            ]
[3723]89           
90        if cd_type == 'F' :
[3740]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           ] 
[3723]95     
96    if nperio in [5, 6] :            #  North fold F-point pivot 
97        if cd_type in ['T', 'W']  :
[3740]98            ptab[..., -1, 0:       ] = psgn * ptab[..., -2, -1::-1       ]
[3723]99               
100        if cd_type == 'U' :
[3740]101            ptab[..., -1, 0:-1     ] = psgn * ptab[..., -2, -2::-1       ]       
102            ptab[..., -1, -1       ] = psgn * ptab[..., -2, 0            ]
[3723]103             
104        if cd_type == 'V' :
[3740]105            ptab[..., -1, 0:       ] = psgn * ptab[..., -3, -1::-1       ]
[4259]106            ptab[..., -2, jpi//2:  ] = psgn * ptab[..., -2, jpi//2-1::-1 ]
[3723]107                             
108        if cd_type == 'F' :
[3740]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 ]
[3723]112
113    return ptab
[4083]114
115
[4259]116def lbc_mask (ptab, nperio=None, cd_type='T') :
117    #
[4083]118    """
[4259]119    Mask fields on duplicated points
[4083]120    ptab      : Input array
[4259]121      rank 2 at least : ptab[...., lat, lon]
[4083]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    """
[4259]131
132    jpi    = ptab.shape[-1]
133    nperio = __guessNperio__ ( jpi, nperio )
134    zero   = ptab.dtype.type(0)
[4083]135   
136    #
137    #> East-West boundary conditions
[4259]138    # ------------------------------
[4083]139    if nperio in [1, 4, 6] :
140        # ... cyclic
141        ptab [...,:,  0] = zero
142        ptab [...,:, -1] = zero
[4259]143
[4083]144    #
[4259]145    #> South (in which nperio cases ?)
146    # --------------------------------
147    if nperio in [1, 3, 4, 5, 6] :
148        ptab[...,0,:] = zero
149       
150    #
[4083]151    #> North-South boundary conditions
[4259]152    # --------------------------------
[4083]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
[4259]173            ptab[..., -1,  0       ] = zero
[4083]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
[4259]186            ptab[..., -2, jpi//2:  ] = zero
[4083]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
[3740]194## ===========================================================================
195##
196##                               That's all folk's !!!
197##
198## ===========================================================================
Note: See TracBrowser for help on using the repository browser.