Changeset 3741 for TOOLS/CPLRESTART/FillOceRestart.py
- Timestamp:
- 04/12/18 12:10:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/CPLRESTART/FillOceRestart.py
r3738 r3741 32 32 From https://stackoverflow.com/questions/5551286/filling-gaps-in-a-numpy-array 33 33 34 Input: InputData : numpy maskedarray of any dimension.34 Input: InputData : numpy.ma array of any dimension. 35 35 36 36 Output: Return a filled array. … … 44 44 45 45 def usage () : 46 texte= """%(prog)s usage :47 python %(prog)s [-d] [-i <orca grid file>] [-n <perio>]46 __help__ = """%(prog)s usage : 47 python %(prog)s [-d] -i <sstoce file> [-n <perio>] [-v variables] [-o <output file>] 48 48 -d | --debug : debug 49 49 -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 51 54 -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) 56 59 If <perio> is not specified, %(prog)s will try to guess it from the grid dimensions 57 60 example : … … 59 62 python %(prog)s -n 4 -i sstoce_ORCA2.3.nc -v O_SSTSST,OIceFrc 60 63 """ 61 print ( texte% { 'prog':sys.argv[0] } )64 print ( __help__ % { 'prog':sys.argv[0] } ) 62 65 63 66 ## Default input parameters … … 72 75 ## Command line options 73 76 try: 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' ] ) 75 79 except getopt.GetoptError as cmdle : 76 80 print ( "Command line error : "+str(cmdle)+"\n" ) … … 97 101 else : 98 102 if Debug : print ("Out file set to input file") 99 OuFile = InFile ; s103 OuFile = InFile ; 100 104 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(',') 106 108 elif myopt in [ '-x', '--exclude' ] : 107 109 Exclude = True … … 124 126 # Try to guess periodicity type 125 127 if nperio == None : 126 print ( "Trying to guess nperio parameter")128 print ( "Trying to guess nperio parameter" ) 127 129 jpoi = OuFile.dimensions["x"].size 128 130 jpoj = OuFile.dimensions["y"].size 129 131 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") 132 142 print ("Choosen nperio=4") 133 143 nperio = 4 134 if (jpoj, jpoi) == (332, 292) :144 elif (jpoj, jpoi) == (332, 292) : 135 145 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) : 138 148 nperio = 6 139 print ("eORCA1 grid found , nperio=6" )140 149 print ("eORCA1 grid found from dimensions, nperio=6" ) 150 141 151 if 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") 144 154 usage () 145 155 sys.exit(1) … … 149 159 150 160 # Exclude some var if needed 151 if Exclude : 161 if Exclude : 152 162 for Var in ListExclude : 153 163 if Var in ListVarName : ListVarName.remove(Var) … … 155 165 # Loop on variables 156 166 for VarName in ListVarName : 157 158 167 Var = OuFile.variables[VarName] 159 if 'mask' in dir(Var[ :,...]) :168 if 'mask' in dir(Var[...]) : 160 169 print ( "Working on " + VarName ) 161 NewVar = MyFill ( InputData = Var[ :,:] )170 NewVar = MyFill ( InputData = Var[...] ) 162 171 NewVar = nemo.lbc (NewVar, nperio=nperio, cd_type='T', psgn=1.0) 163 172 OuFile.variables[VarName][:,:] = NewVar[:,:] … … 166 175 167 176 # Close file : writes update variables. 168 #OuFile.close()177 OuFile.close() 169 178 170 179 ## ===========================================================================
Note: See TracChangeset
for help on using the changeset viewer.