Changeset 3741


Ignore:
Timestamp:
04/12/18 12:10:00 (6 years ago)
Author:
omamce
Message:

O.M. : improve documentation

Location:
TOOLS/CPLRESTART
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/CPLRESTART/FillOceRestart.py

    r3738 r3741  
    3232    From https://stackoverflow.com/questions/5551286/filling-gaps-in-a-numpy-array 
    3333     
    34     Input:  InputData : numpy masked array of any dimension. 
     34    Input:  InputData : numpy.ma array of any dimension. 
    3535 
    3636    Output: Return a filled array.  
     
    4444 
    4545def usage () : 
    46     texte = """%(prog)s usage : 
    47 python %(prog)s [-d] [-i <orca grid file>] [-n <perio>] 
     46    __help__ = """%(prog)s usage : 
     47python %(prog)s [-d] -i <sstoce file> [-n <perio>] [-v variables] [-o <output file>] 
    4848 -d           | --debug                : debug 
    4949 -i <file>    | --input=<file>         : input file  (default: none) 
    50  -v <varlist> | --variable=<variables> : list of variable to fill (defautl: none) 
     50 -o <file>    | --output=<file>        : output file (default : build a name form input file) 
     51 -r           | --replace              : replace input file by new file with filled variables 
     52 -v <varlist> | --variable=<variables> : list of variable to fill (defautlt: all variable in file) 
     53 -x           | --exclude              : fills all variable in files, except those given in -v|--variable 
    5154 -n <perio>   | --perio=<perio> : periodicity type (default: try to guess) 
    52     #   1, 4, 6 : Cyclic on i dimension (generaly longitudes) 
    53     #   2       : Obsolete (was symmetric condition at southern boundary ?) 
    54     #   3, 4    : North fold T-point pivot (legacy ORCA2) 
    55     #   5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo) 
     55    1, 4, 6 : Cyclic on i dimension (generaly longitudes) 
     56    2       : Obsolete (was symmetric condition at southern boundary ?) 
     57    3, 4    : North fold T-point pivot (legacy ORCA2) 
     58    5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo) 
    5659    If <perio> is not specified, %(prog)s will try to guess it from the grid dimensions 
    5760example : 
     
    5962    python %(prog)s -n 4 -i sstoce_ORCA2.3.nc -v O_SSTSST,OIceFrc 
    6063    """ 
    61     print ( texte % { 'prog':sys.argv[0] } ) 
     64    print ( __help__ % { 'prog':sys.argv[0] } ) 
    6265 
    6366## Default input parameters 
     
    7275## Command line options 
    7376try: 
    74     myopts, myargs = getopt.getopt ( sys.argv[1:], 'i:o:rv:xp:hd', [ 'input=', 'output=', 'replace', 'exclude', 'variable=', 'perio=', 'debug', 'help' ] ) 
     77    myopts, myargs = getopt.getopt ( sys.argv[1:], 'i:o:rv:xp:hd', 
     78                                         [ 'input=', 'output=', 'replace', 'exclude', 'variable=', 'variables=', 'perio=', 'debug', 'help' ] ) 
    7579except getopt.GetoptError as cmdle : 
    7680    print ( "Command line error : "+str(cmdle)+"\n" ) 
     
    97101        else : 
    98102            if Debug : print ("Out file set to input file") 
    99             OuFile   = InFile ; s  
     103            OuFile   = InFile ; 
    100104    elif myopt in [ '-p', '--perio'     ] : nperio = int(myval) ; 
    101     elif myopt in [ '-v', '--variable'  ] : 
    102         if Exclude : 
    103             ListExclude = myval.split(',')           
    104         else : 
    105             ListVarName = myval.split(',') 
     105    elif myopt in [ '-v', '--variable', '--variables'  ] : 
     106        if Exclude : ListExclude = myval.split(',')           
     107        else :       ListVarName = myval.split(',') 
    106108    elif myopt in [ '-x', '--exclude'  ] : 
    107109        Exclude = True 
     
    124126# Try to guess periodicity type 
    125127if nperio == None : 
    126     print ("Trying to guess nperio parameter") 
     128    print ( "Trying to guess nperio parameter" ) 
    127129    jpoi = OuFile.dimensions["x"].size 
    128130    jpoj = OuFile.dimensions["y"].size 
    129131    print ("Grid dimensions: ("+str(jpoj)+", "+str(jpoi)+")") 
    130     if (jpoj, jpoi) == (149, 182) : 
    131         print ("ORCA 2 grid found: nperio may vary for this configuration") 
     132    if   'ORCA2' in InFile : 
     133        print ("ORCA 2 grid found from file name: nperio may vary for this configuration") 
     134        print ("Choosen nperio=4") 
     135    elif 'ORCA1' in InFile : 
     136        if 'eORCA1' in InFile :  
     137            print ("eORCA 1 grid found from file name, nperio=6") 
     138        else : 
     139            print ("ORCA 1 grid found from file name, nperio=6") 
     140    elif (jpoj, jpoi) == (149, 182) : 
     141        print ("ORCA 2 grid found from dimension: nperio may vary for this configuration") 
    132142        print ("Choosen nperio=4") 
    133143        nperio = 4 
    134     if (jpoj, jpoi) == (332, 292) : 
     144    elif (jpoj, jpoi) == (332, 292) : 
    135145        nperio = 6 
    136         print ("ORCA1 grid found, nperio=6" ) 
    137     if (jpoj, jpoi) == (332, 362) : 
     146        print ("ORCA1 grid found from dimensions, nperio=6" ) 
     147    elif (jpoj, jpoi) == (332, 362) : 
    138148        nperio = 6 
    139         print ("eORCA1 grid found, nperio=6" ) 
    140  
     149        print ("eORCA1 grid found from dimensions, nperio=6" ) 
     150         
    141151if nperio == None : 
    142     print ("%(prog)s could not guess the periodicity type of your file") 
    143     print ("Please specify -n|--nperio") 
     152    print ("%(prog)s couldn't guess the periodicity type of your file") 
     153    print ("Please specify -p|--perio") 
    144154    usage () 
    145155    sys.exit(1) 
     
    149159 
    150160# Exclude some var if needed 
    151 if Exclude : 
     161if Exclude :  
    152162    for Var in ListExclude :  
    153163        if Var in ListVarName : ListVarName.remove(Var) 
     
    155165# Loop on variables 
    156166for VarName in ListVarName : 
    157  
    158167    Var    = OuFile.variables[VarName] 
    159     if 'mask' in dir(Var[:,...]) : 
     168    if 'mask' in dir(Var[...]) : 
    160169        print ( "Working on " + VarName ) 
    161         NewVar = MyFill ( InputData = Var[:,:] ) 
     170        NewVar = MyFill ( InputData = Var[...] ) 
    162171        NewVar = nemo.lbc (NewVar, nperio=nperio, cd_type='T', psgn=1.0) 
    163172        OuFile.variables[VarName][:,:] = NewVar[:,:] 
     
    166175         
    167176# Close file : writes update variables.     
    168 #OuFile.close() 
     177OuFile.close() 
    169178 
    170179## =========================================================================== 
  • TOOLS/CPLRESTART/nemo.py

    r3739 r3741  
    2222 
    2323def lbc (ptab, nperio=6, cd_type='T', psgn=1.0) : 
    24     """ 
    25     ptab      : Input array 
     24      """ 
     25      ptab      : Input array 
    2626      rank 2 at least : patb[...., lat, lon] 
    27     nperio    : Type of periodicity 
    28       1, 4, 6 : Cyclic on i dimension (generaly longitudes) 
    29       2       : Obsolete (was symmetric condition at southern boundary ?) 
    30       3, 4    : North fold T-point pivot (legacy ORCA2) 
    31       5, 6    : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo) 
    32     cd_type   : Grid specification : T, U, V or F 
    33     psgn      : For change of sign for vector components 
     27      nperio    : Type of periodicity 
     28         1, 4, 6   : Cyclic on i dimension (generaly longitudes) 
     29         2         : Obsolete (was symmetric condition at southern boundary ?) 
     30         3, 4      : North fold T-point pivot (legacy ORCA2) 
     31         5, 6      : North fold F-point pivot (ORCA1, ORCA025, ORCA2 with new grid for paleo) 
     32      cd_type   : Grid specification : T, U, V or F 
     33      psgn      : For change of sign for vector components 
     34       
     35      See NEMO documentation for further details 
     36      """ 
     37      jpi = ptab.shape[-1] 
    3438     
    35     See NEMO documentation for further details 
    36     """ 
    37          
    38     jpi = ptab.shape[-1] 
    39      
    40     # 
    41     #> East-West boundary conditions 
    42     # -------------------------------- 
    43  
    44     if nperio in [1, 4, 6] : 
    45         # ... cyclic 
    46         ptab [...,:,  0] = ptab [...,:,-2] 
    47         ptab [...,:, -1] = ptab [...,:, 1] 
    48     
    49     # 
    50     #> North-South boundary conditions 
    51     # ---------------------------------- 
    52     if nperio in [3, 4] :  # North fold T-point pivot      
    53         if cd_type in [ 'T', 'W' ] : # T-, W-point 
    54             ptab[..., -1, 1:       ] = psgn * ptab[..., -3, -1:0:-1      ]       
    55             ptab[..., -1, 0        ] = psgn * ptab[..., -3, 2            ] 
    56             ptab[..., -2, jpi//2:  ] = psgn * ptab[..., -2, jpi//2:0:-1  ] 
    57                        
    58         if cd_type == 'U' : 
    59             ptab[..., -1, 0:-1     ] = psgn * ptab[..., -3, -1:0:-1      ]        
    60             ptab[..., -1,  0       ] = psgn * ptab[..., -3,  1           ] 
    61             ptab[..., -1, -1       ] = psgn * ptab[..., -3, -2           ]  
    62             ptab[..., -2, jpi//2-1:] = psgn * ptab[..., -2, jpi//2+1:0:-1] 
     39      # 
     40      #> East-West boundary conditions 
     41      # -------------------------------- 
     42       
     43      if nperio in [1, 4, 6] : 
     44            # ... cyclic 
     45            ptab [...,:,  0] = ptab [...,:,-2] 
     46            ptab [...,:, -1] = ptab [...,:, 1] 
     47       
     48      # 
     49      #> North-South boundary conditions 
     50      # ---------------------------------- 
     51      if nperio in [3, 4] :  # North fold T-point pivot      
     52            if cd_type in [ 'T', 'W' ] : # T-, W-point 
     53                  ptab[..., -1, 1:       ] = psgn * ptab[..., -3, -1:0:-1      ]       
     54                  ptab[..., -1, 0        ] = psgn * ptab[..., -3, 2            ] 
     55                  ptab[..., -2, jpi//2:  ] = psgn * ptab[..., -2, jpi//2:0:-1  ] 
     56                   
     57            if cd_type == 'U' : 
     58                  ptab[..., -1, 0:-1     ] = psgn * ptab[..., -3, -1:0:-1      ]        
     59                  ptab[..., -1,  0       ] = psgn * ptab[..., -3,  1           ] 
     60                  ptab[..., -1, -1       ] = psgn * ptab[..., -3, -2           ]  
     61                  ptab[..., -2, jpi//2-1:] = psgn * ptab[..., -2, jpi//2+1:0:-1] 
     62                   
     63            if cd_type == 'V' :  
     64                  ptab[..., -2, 1:       ] = psgn * ptab[..., -3, jpi-1:0:-1   ] 
     65                  ptab[..., -1, 1:       ] = psgn * ptab[..., -4, -1:0:-1      ]    
     66                  ptab[..., -1, 0        ] = psgn * ptab[..., -4, 2            ] 
     67               
     68            if cd_type == 'F' : 
     69                  ptab[..., -2, 0:-1     ] = psgn * ptab[..., -3, -1:0:-1      ] 
     70                  ptab[..., -1, 0:-1     ] = psgn * ptab[..., -4, -1:0:-1      ] 
     71                  ptab[..., -1,  0       ] = psgn * ptab[..., -4,  1           ] 
     72                  ptab[..., -1, -1       ] = psgn * ptab[..., -4, -2           ]  
     73                   
     74      if nperio in [5, 6] :            #  North fold F-point pivot   
     75            if cd_type in ['T', 'W']  : 
     76                  ptab[..., -1, 0:       ] = psgn * ptab[..., -2, -1::-1       ] 
    6377             
    64         if cd_type == 'V' :  
    65             ptab[..., -2, 1:       ] = psgn * ptab[..., -3, jpi-1:0:-1   ] 
    66             ptab[..., -1, 1:       ] = psgn * ptab[..., -4, -1:0:-1      ]    
    67             ptab[..., -1, 0        ] = psgn * ptab[..., -4, 2            ] 
    68              
    69         if cd_type == 'F' : 
    70             ptab[..., -2, 0:-1     ] = psgn * ptab[..., -3, -1:0:-1      ] 
    71             ptab[..., -1, 0:-1     ] = psgn * ptab[..., -4, -1:0:-1      ] 
    72             ptab[..., -1,  0       ] = psgn * ptab[..., -4,  1           ] 
    73             ptab[..., -1, -1       ] = psgn * ptab[..., -4, -2           ]  
    74        
    75     if nperio in [5, 6] :            #  North fold F-point pivot   
    76         if cd_type in ['T', 'W']  : 
    77             ptab[..., -1, 0:       ] = psgn * ptab[..., -2, -1::-1       ] 
    78                  
    79         if cd_type == 'U' : 
    80             ptab[..., -1, 0:-1     ] = psgn * ptab[..., -2, -2::-1       ]        
    81             ptab[..., -1, -1       ] = psgn * ptab[..., -2, 0            ] 
    82               
    83         if cd_type == 'V' : 
    84             ptab[..., -1, 0:       ] = psgn * ptab[..., -3, -1::-1       ] 
    85             ptab[..., -2, jpi/2:   ] = psgn * ptab[..., -2, jpi/2-1::-1  ] 
    86                               
    87         if cd_type == 'F' : 
    88             ptab[..., -1, 0:-1     ] = psgn * ptab[..., -3, -2::-1       ] 
    89             ptab[..., -1, -1       ] = psgn * ptab[..., -3, 0            ] 
    90             ptab[..., -2, jpi//2:-1] = psgn * ptab[..., -2, jpi//2-2::-1 ] 
    91  
    92     return ptab 
    93          
     78            if cd_type == 'U' : 
     79                  ptab[..., -1, 0:-1     ] = psgn * ptab[..., -2, -2::-1       ]        
     80                  ptab[..., -1, -1       ] = psgn * ptab[..., -2, 0            ] 
     81               
     82            if cd_type == 'V' : 
     83                  ptab[..., -1, 0:       ] = psgn * ptab[..., -3, -1::-1       ] 
     84                  ptab[..., -2, jpi/2:   ] = psgn * ptab[..., -2, jpi/2-1::-1  ] 
     85               
     86            if cd_type == 'F' : 
     87                  ptab[..., -1, 0:-1     ] = psgn * ptab[..., -3, -2::-1       ] 
     88                  ptab[..., -1, -1       ] = psgn * ptab[..., -3, 0            ] 
     89                  ptab[..., -2, jpi//2:-1] = psgn * ptab[..., -2, jpi//2-2::-1 ] 
     90               
     91      return ptab 
     92   
    9493## =========================================================================== 
    9594## 
Note: See TracChangeset for help on using the changeset viewer.