Changeset 307 in lmdz_wrf
- Timestamp:
- Feb 26, 2015, 9:43:15 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r306 r307 704 704 return varvals 705 705 706 def numVector_String(vec,char): 707 """ Function to transform a vector of numbers to a single string [char] separated 708 numVector_String(vec,char) 709 vec= vector with the numerical values 710 char= single character to split the values 711 >>> print numVector_String(np.arange(10),' ') 712 0 1 2 3 4 5 6 7 8 9 713 """ 714 fname = 'numVector_String' 715 716 if vec == 'h': 717 print fname + '_____________________________________________________________' 718 print numVector_String.__doc__ 719 quit() 720 721 Nvals = len(vec) 722 723 string='' 724 for i in range(Nvals): 725 if i == 0: 726 string = str(vec[i]) 727 else: 728 string = string + char + str(vec[i]) 729 730 return string 731 732 def index_mat(mat,val): 733 """ Function to provide the coordinates of a given value inside a matrix 734 index_mat(mat,val) 735 mat= matrix with values 736 val= value to search 737 >>> index_mat(np.arange(27).reshape(3,3,3),22) 738 [2 1 1] 739 """ 740 741 fname = 'index_mat' 742 743 matshape = mat.shape 744 745 matlist = list(mat.flatten()) 746 ifound = matlist.index(val) 747 748 Ndims = len(matshape) 749 valpos = np.zeros((Ndims), dtype=int) 750 baseprevdims = np.zeros((Ndims), dtype=int) 751 752 for dimid in range(Ndims): 753 baseprevdims[dimid] = np.product(matshape[dimid+1:Ndims]) 754 if dimid == 0: 755 alreadyplaced = 0 756 else: 757 alreadyplaced = np.sum(baseprevdims[0:dimid]*valpos[0:dimid]) 758 valpos[dimid] = int((ifound - alreadyplaced )/ baseprevdims[dimid]) 759 760 return valpos 706 761 707 762 ####### ###### ##### #### ### ## # … … 11252 11307 # '001/full_concatenated.nc', 'PSFC') 11253 11308 11254 def numVector_String(vec,char):11255 """ Function to transform a vector of numbers to a single string [char] separated11256 numVector_String(vec,char)11257 vec= vector with the numerical values11258 char= single character to split the values11259 >>> print numVector_String(np.arange(10),' ')11260 0 1 2 3 4 5 6 7 8 911261 """11262 fname = 'numVector_String'11263 11264 if vec == 'h':11265 print fname + '_____________________________________________________________'11266 print numVector_String.__doc__11267 quit()11268 11269 Nvals = len(vec)11270 11271 string=''11272 for i in range(Nvals):11273 if i == 0:11274 string = str(vec[i])11275 else:11276 string = string + char + str(vec[i])11277 11278 return string11279 11280 11309 def interpolate_locs(locs,coords,kinterp): 11281 11310 """ Function to provide interpolate locations on a given axis … … 12588 12617 12589 12618 #netcdf_fold_concatenation('/media/data2/etudes/WRF_LMDZ/WL_HyMeX_HighRes/medic950116,Time', 'wrfout_d03', 'Times,XLONG,XLAT,T2,TH2,PSFC,U10,V10,MAPFAC_M') 12590 12591 def index_mat(mat,val):12592 """ Function to provide the coordinates of a given value inside a matrix12593 index_mat(mat,val)12594 mat= matrix with values12595 val= value to search12596 >>> index_mat(np.arange(27).reshape(3,3,3),22)12597 [2 1 1]12598 """12599 12600 fname = 'index_mat'12601 12602 matshape = mat.shape12603 12604 matlist = list(mat.flatten())12605 ifound = matlist.index(val)12606 12607 Ndims = len(matshape)12608 valpos = np.zeros((Ndims), dtype=int)12609 baseprevdims = np.zeros((Ndims), dtype=int)12610 12611 for dimid in range(Ndims):12612 baseprevdims[dimid] = np.product(matshape[dimid+1:Ndims])12613 if dimid == 0:12614 alreadyplaced = 012615 else:12616 alreadyplaced = np.sum(baseprevdims[0:dimid]*valpos[0:dimid])12617 valpos[dimid] = int((ifound - alreadyplaced )/ baseprevdims[dimid])12618 12619 return valpos12620 12619 12621 12620 def netcdf_concatenation(ncfile):
Note: See TracChangeset
for help on using the changeset viewer.