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

O.M. : improve documentation

File:
1 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## =========================================================================== 
Note: See TracChangeset for help on using the changeset viewer.