Changeset 1455 in lmdz_wrf
- Timestamp:
- Feb 24, 2017, 7:21:27 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1448 r1455 121 121 # SliceVar: Function to slice a given variable throughout a given list of dimensions 122 122 # SliceVarDict: Function to slice a given variable throughout a dictionary 123 # slice_createArray: Function to create a variable from a list which contains slicing-variable values 123 124 # slice_variable: Function to return a slice of a given variable according to values to its dimensions 124 125 # sorttimesmat: Function to sort the time values of a given file … … 18984 18985 return 18985 18986 18987 def slice_createArray(listslice, typev=np.float): 18988 """ Function to create a variable from a list which contains slicing-variable values 18989 listslice= list with ordered slice insrtuctions to be used to slice a variable 18990 typev= type of the array to create 18991 >>> slice_createArray([1, slice(0,3,None)], typev=np.float) 18992 [ 0. 0. 0.] 18993 >>> slice_createArray([slice(0,20,3), slice(0,3,None)], typev=type(True)) 18994 [[False False False] 18995 [False False False] 18996 [False False False] 18997 [False False False] 18998 [False False False] 18999 [False False False]] 19000 """ 19001 19002 dimsize = [] 19003 for slc in listslice: 19004 if type(slc) == type(slice(0,1,None)): 19005 iv = slc.start 19006 ev = slc.stop 19007 sv = slc.step 19008 if sv is not None: 19009 Lslc = (ev - iv)/sv 19010 else: 19011 Lslc = ev - iv 19012 elif type(slc) == int or type(slc) == np.int64: 19013 Lslc = 0 19014 if Lslc != 0: dimsize.append(Lslc) 19015 19016 if typev == int: 19017 arrayvalues = np.zeros(tuple(dimsize), dtype=int) 19018 elif typev == np.float: 19019 arrayvalues = np.zeros(tuple(dimsize), dtype=np.float) 19020 elif typev == np.float64: 19021 arrayvalues = np.zeros(tuple(dimsize), dtype=np.float64) 19022 elif typev == type(True): 19023 arrayvalues = np.zeros(tuple(dimsize), dtype=bool) 19024 else: 19025 print errormsg 19026 print ' ' + fname + ': type', typev, 'not ready !!' 19027 quit(-1) 19028 19029 return arrayvalues 19030 18986 19031 #quit()
Note: See TracChangeset
for help on using the changeset viewer.