Changeset 26184
- Timestamp:
- 04/08/21 04:47:08 (4 years ago)
- Location:
- issm/trunk-jpl/src/m
- Files:
-
- 13 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/clusters/generic.py
r26183 r26184 121 121 122 122 if IssmConfig('_HAVE_MPI_')[0]: 123 fid.write('mpiexec -np {} {} --leak-check=full {} {}/{} {} {}/{} {} 2> {}.errlog>{}.outlog '.format(self.np, self.valgrind, supstring, self.codepath, executable, solution, self.executionpath, dirname, modelname, modelname, modelname))124 #fid.write('mpiexec -np {} {} --tool=callgrind {}/{} {} {}/{} {} 2>{}.errlog>{}.outlog '.format(self.np, self.valgrind, self.codepath, executable, solution, self.executionpath, dirname, modelname, modelname, modelname))123 fid.write('mpiexec -np {} {} --leak-check=full {} {}/{} {} {}/{} {} 2> {}.errlog > {}.outlog '. 124 format(self.np, self.valgrind, supstring, self.codepath, executable, solution, self.executionpath, dirname, modelname, modelname, modelname)) 125 125 else: 126 126 fid.write('{} --leak-check=full {} {}/{} {} {}/{} {} 2> {}.errlog > {}.outlog '. -
issm/trunk-jpl/src/m/classes/model.py
r26183 r26184 38 38 from generic import generic 39 39 from pfe import pfe 40 from vilje import vilje 41 from hexagon import hexagon 40 42 from cyclone import cyclone 43 from stallo import stallo 41 44 from saga import saga 42 45 from balancethickness import balancethickness … … 182 185 def __repr__(obj): #{{{ 183 186 # TODO: 184 # - Convert all formatting to calls to <string>.format (see any 187 # - Convert all formatting to calls to <string>.format (see any 185 188 # already converted <class>.__repr__ method for examples) 186 189 # … … 890 893 md.hydrology.__dict__[field] = project2d(md, md.hydrology.__dict__[field], 1) 891 894 895 # Materials 892 896 md.materials.rheology_B = DepthAverage(md, md.materials.rheology_B) 893 897 md.materials.rheology_n = project2d(md, md.materials.rheology_n, 1) -
issm/trunk-jpl/src/m/coordsystems/gmtmask.m
r26183 r26184 6 6 % 7 7 8 %are we doing a recursive call? 8 %are we doing a recursive call? 9 9 if nargin==3, 10 10 recursive=1; 11 else 11 else 12 12 recursive=0; 13 13 end 14 14 15 15 if(recursive)disp(sprintf(' recursing: num vertices %i',length(lat))); 16 16 else disp(sprintf('gmtmask: num vertices %i',length(lat))); 17 17 end 18 19 %Check lat and long size is not more than 50,000; If so, recursively call gmtmask: 18 19 %Check lat and long size is not more than 50,000; If so, recursively call gmtmask: 20 20 if length(lat)>50000, 21 21 for i=1:50000:length(lat), … … 28 28 return 29 29 end 30 30 31 31 %First, write our lat,long file for gmt: 32 32 nv=length(lat); 33 filename_all = ['all_vertices-' num2str(feature('GetPid')) '.txt']; 34 filename_oce = ['oce_vertices-' num2str(feature('GetPid')) '.txt']; 33 filename_all = ['all_vertices-' num2str(feature('GetPid')) '.txt']; 34 filename_oce = ['oce_vertices-' num2str(feature('GetPid')) '.txt']; 35 35 dlmwrite(filename_all,[long lat (1:nv)'],'delimiter','\t','precision',10); 36 37 %Avoid bypassing of the ld library path by Matlab (:()38 %39 % TODO: Do we really need this (we can/already set it in etc/environment.sh)?40 if ismac,41 dyld_library_path_old=getenv('DYLD_LIBRARY_PATH');42 setenv('DYLD_LIBRARY_PATH',[ issmdir '/externalpackages/curl/install/lib:' issmdir '/externalpackages/hdf5/install/lib:' issmdir '/externalpackages/netcdf/install/lib' ]);43 end44 45 %Find path to gmt, list all possible known paths to gmt (you may need to add yours to the list)46 gmtpaths = {[issmdir '/bin/gmt'],[issmdir '/externalpackages/gmt/install/bin/gmt'],'/Applications/GMT-5.4.3.app/Contents/Resources/bin/gmt', '/usr/bin/gmt'};47 gmtpath = '';48 for i=gmtpaths49 if exist(i{1},'file'),50 gmtpath = i{1};51 break;52 end53 end54 if isempty(gmtpath),55 error('gmt not found! Make sure it is properly installed, or add its path to this file.');56 end57 58 36 59 37 %figure out which vertices are on the ocean, which one on the continent: … … 63 41 end 64 42 65 %reset DYLD_LIBRARY_PATH to what it was:66 if ismac,67 setenv('DYLD_LIBRARY_PATH',dyld_library_path_old);68 end69 43 %read the con_vertices.txt file and flag our mesh vertices on the continent 70 44 fid=fopen(['./' filename_oce],'r'); 71 line=fgets(fid); 45 line=fgets(fid); 72 46 line=fgets(fid); 73 47 oce_vertices=[]; … … 81 55 mask=zeros(nv,1); 82 56 mask(oce_vertices)=1; 83 57 84 58 system(['rm -rf ./' filename_all ' ./' filename_oce ' ./gmt.history']); 85 if ~recursive, 86 disp(sprintf('gmtmask: done')); 87 end 59 if ~recursive, disp(sprintf('gmtmask: done')); end; -
issm/trunk-jpl/src/m/coordsystems/gmtmask.py
r26183 r26184 44 44 np.savetxt('./all_vertices.txt', np.transpose([long, lat, np.arange(1, nv + 1)]), delimiter='\t', fmt='%.10f') 45 45 46 #Avoid bypassing of the ld library path by Matlab (:()47 issm_dir = issmdir()48 49 try:50 ismac51 except NameError:52 ismac = False53 54 # TODO: Do we really need this (we can/already set it in etc/environment.sh)?55 if ismac:56 dyld_library_path_old = os.getenv('DYLD_LIBRARY_PATH')57 os.putenv('DYLD_LIBRARY_PATH', issm_dir + '/externalpackages/curl/install/lib:' + issm_dir + '/externalpackages/hdf5/install/lib:' + issm_dir + '/externalpackages/netcdf/install/lib')58 59 #Find path to gmt (you may need to add yours to the list).60 #61 # NOTE: Assumes gmtselect is also in this directory.62 #63 gmtpaths = ['/usr/bin/gmt',64 issm_dir + '/bin/gmt',65 issm_dir + '/externalpackages/gmt/install/bin/gmt',66 '/Applications/GMT-5.4.3.app/Contents/Resources/bin/gmt']67 gmtpath = ''68 for i in range(len(gmtpaths)):69 if os.path.isfile(gmtpaths[i]):70 gmtpath = gmtpaths[i]71 break72 73 if gmtpath == '':74 raise Exception('gmt not found! Make sure it is properly installed, or add its path to this file.')75 76 46 #figure out which vertices are on the ocean, which one on the continent: 77 47 subprocess.call('gmtselect ./ all_vertices.txt -h0 -Df -R0/360/-90/90 -A0 -JQ180/200 -Nk/s/s/k/s > ./oce_vertices.txt', shell=True) -
issm/trunk-jpl/src/m/dev/devpath.m
r26183 r26184 1 1 % clear the last warning to focus on the warnings of the ISSM path 2 lastwarn(''); 2 lastwarn(''); 3 3 4 4 %Recover ISSM_DIR , or if on a Windows machine, ISSM_DIR_WIN … … 7 7 else 8 8 ISSM_DIR=getenv('ISSM_DIR'); 9 ISSM_DEV_DIR=getenv('ISSM_DEV_DIR');10 9 end 11 10 … … 14 13 end 15 14 16 %Now add all issm code paths necessary to run issm smoothly. 17 %We capture the error output, so that we can warn the user to update 18 %the variable ISSM_DIR in this file, in case it is not correctly setup. 15 %Now add all issm code paths necessary to run issm smoothly. 16 %We capture the error output, so that we can warn the user to update 17 %the variable ISSM_DIR in this file, in case it is not correctly setup. 19 18 20 19 %ISSM path 21 addpath([ISSM_D EV_DIR '/src/m/os/']); %load recursivepath22 addpath([ISSM_D EV_DIR '/lib']); %load mex23 addpath(recursivepath([ISSM_D EV_DIR '/src/m']));20 addpath([ISSM_DIR '/src/m/os/']); %load recursivepath 21 addpath([ISSM_DIR '/lib']); %load MEX files 22 addpath(recursivepath([ISSM_DIR '/src/m'])); 24 23 addpath(recursivepath([ISSM_DIR '/externalpackages/scotch'])); 25 24 addpath(recursivepath([ISSM_DIR '/externalpackages/canos'])); … … 33 32 clear ISSM_DIR; 34 33 35 %Check on any warning messages that might indicate that the paths were not correct. 34 %Check on any warning messages that might indicate that the paths were not correct. 36 35 if ~isempty(lastwarn), 37 36 fprintf('\n Error trying to setup ''ISSM'' code paths. Try and update the ISSM_DIR variable in your .cshrc or .bashrc!\n'); -
issm/trunk-jpl/src/m/dev/devpath.py
r26183 r26184 6 6 #Recover ISSM_DIR and USERNAME 7 7 ISSM_DIR = os.getenv('ISSM_DIR') 8 ISSM_DEV_DIR = os.getenv('ISSM_DEV_DIR')9 8 USERNAME = os.getenv('USER') 10 9 JPL_SVN = os.getenv('JPL_SVN') … … 13 12 14 13 #Go through src/m and append any directory that contains a *.py file to PATH 15 for root, dirs, files in os.walk(ISSM_D EV_DIR + '/src/m'):14 for root, dirs, files in os.walk(ISSM_DIR + '/src/m'): 16 15 if '.svn' in dirs: 17 16 dirs.remove('.svn') … … 23 22 24 23 #Also add the Nightly run directory 25 if ISSM_D EV_DIR + '/test/NightlyRun' not in sys.path:26 sys.path.append(ISSM_D EV_DIR + '/test/NightlyRun')27 if ISSM_D EV_DIR + '/lib' not in sys.path:28 sys.path.append(ISSM_D EV_DIR + '/lib')29 if ISSM_D EV_DIR + '/src/wrappers/python/.libs' not in sys.path:30 sys.path.append(ISSM_D EV_DIR + '/src/wrappers/python/.libs')24 if ISSM_DIR + '/test/NightlyRun' not in sys.path: 25 sys.path.append(ISSM_DIR + '/test/NightlyRun') 26 if ISSM_DIR + '/lib' not in sys.path: 27 sys.path.append(ISSM_DIR + '/lib') 28 if ISSM_DIR + '/src/wrappers/python/.libs' not in sys.path: 29 sys.path.append(ISSM_DIR + '/src/wrappers/python/.libs') 31 30 32 31 # If using clusters, we need to have the path to the cluster settings directory … … 49 48 50 49 print("\n ISSM development path correctly loaded") 51 print("Current path is {}\n\n".format(ISSM_D EV_DIR))50 print("Current path is {}\n\n".format(ISSM_DIR)) -
issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.m
r26183 r26184 14 14 % md.mesh=gmshplanet('radius',6000,'resolution',100); 15 15 % md.mesh=gmshplanet('radius',6000,'resolution',100); 16 17 %Find path to gmsh18 paths = {[issmdir() 'bin/gmsh'],...19 [issmdir() 'externalpackages/gmsh/install/gmsh'],...20 ['/usr/bin/gmsh']...21 };22 disp(paths{1})23 gmshpath = '';24 for i=paths25 if exist(i{1},'file'),26 gmshpath = i{1};27 break;28 end29 end30 if isempty(gmshpath),31 error('gmsh not found, make sure it is properly installed');32 end33 16 34 17 % Get Gmsh version … … 138 121 % Call gmsh 139 122 % 140 % NOTE: The default format in Gmsh 3 is "msh2". Rather than conditionally 141 % modifying our parsing scheme for Gmsh 4, for now, we simply set the 123 % NOTE: The default format in Gmsh 3 is "msh2". Rather than conditionally 124 % modifying our parsing scheme for Gmsh 4, for now, we simply set the 142 125 % "-format" option. 143 126 % -
issm/trunk-jpl/src/m/mesh/planet/gmsh/gmshplanet.py
r26183 r26184 29 29 subproc = subprocess.Popen(subproc_args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 30 30 outs, errs = subproc.communicate() 31 if errs .decode('UTF-8')!= '':31 if errs != '': 32 32 raise Exception("gmshplanet: call to gmsh failed: {}".format(errs)) 33 33 gmshmajorversion = int(outs) … … 124 124 # Call gmsh 125 125 # 126 # NOTE: The default format in Gmsh 3 is "msh2". Rather than conditionally 127 # modifying our parsing scheme for Gmsh 4, for now, we simply set the 126 # NOTE: The default format in Gmsh 3 is "msh2". Rather than conditionally 127 # modifying our parsing scheme for Gmsh 4, for now, we simply set the 128 128 # "-format" option. 129 129 # -
issm/trunk-jpl/src/m/miscellaneous/normfit_issm.py
r26183 r26184 10 10 # check for any NaN in any columns 11 11 if not np.isnan(x).any(): 12 12 13 # explicitly calculate the moments 13 14 muhat = np.mean(x, 0) 14 # numpy defaults to 0 delta degrees of freedom; matlab uses 1 15 # just check on lenght to avoid dividing by 0 16 if len(x) <= 1: 17 sigmahat = np.std(x, 0, ddof=0) 18 else: 19 sigmahat = np.std(x, 0, ddof=1) 15 # numpy defaults to 0 delta degrees of freedom; matlab uses 1 16 sigmahat = np.std(x, 0, ddof=1) 17 20 18 # no way to ask this in python, assume 4 outputs 21 19 #if (nargout > 2): … … 41 39 sigmaci[0, :] = sigmahat 42 40 sigmaci[1, :] = sigmahat 43 44 41 else: 45 42 # must loop over columns, since number of elements could be different … … 51 48 # remove any NaN and recursively call column 52 49 for j in range(np.shape(x, 1)): 53 #[muhat[j], sigmahat[j], muci[:, j], sigmaci[:, j]] = normfit_issm(x[not np.isnan(x[:, j]), j], alpha) 54 muhat[j], sigmahat[j], muci[:, j], sigmaci[:, j] = normfit_issm(x[not np.isnan(x[:, j]), j], alpha) 50 [muhat[j], sigmahat[j], muci[:, j], sigmaci[:, j]] = normfit_issm(x[not np.isnan(x[:, j]), j], alpha) 55 51 56 return muhat, sigmahat, np.squeeze(muci), np.squeeze(sigmaci) 57 #return [muhat, sigmahat, muci, sigmaci] 52 return [muhat, sigmahat, muci, sigmaci] -
issm/trunk-jpl/src/m/partition/partitioner.py
r26183 r26184 46 46 #partitioning essentially happens in 2D. So partition in 2D, then 47 47 #extrude the partition vector vertically. 48 md3d = copy.deepcopy(md) 48 md3d = copy.deepcopy(md) # save for later 49 49 md.mesh.elements = md.mesh.elements2d 50 50 md.mesh.x = md.mesh.x2d … … 58 58 #adjacency matrix if needed: 59 59 if recomputeadjacency == 'on': 60 print("adj calll")61 60 md = adjacency(md) 62 61 else: … … 68 67 else: 69 68 # default method (from chaco.m) 70 method = np.array([1, 1, 0, 0, 1, 1, 50, 0, 0.001, 7654321]) #.conj().transpose()69 method = np.array([1, 1, 0, 0, 1, 1, 50, 0, 0.001, 7654321]).conj().transpose() 71 70 method[0] = 3 # global method (3 = inertial (geometric)) 72 71 method[2] = 0 # vertex weights (0 = off, 1 = on) … … 85 84 86 85 # partition into nparts 87 print("ChacoCall")88 86 if isinstance(md.mesh, mesh2d): 89 print("caseA") 90 part = Chaco(md.qmu.adjacency, weights, np.array([]), md.mesh.x, md.mesh.y, np.zeros((md.mesh.numberofvertices)), method, npart, np.array([]))[0].conj().transpose() + 1 #index partitions from 1 up. like metis. 87 part = Chaco(md.qmu.adjacency, weights, np.array([]), md.mesh.x, md.mesh.y, np.zeros((md.mesh.numberofvertices, 1)), method, npart, np.array([]))[0].conj().transpose() + 1 #index partitions from 1 up. like metis. 91 88 else: 92 print("caseB") 93 part = Chaco(md.qmu.adjacency, weights, np.array([]), md.mesh.x, md.mesh.y, md.mesh.z, method, npart, np.array([]))[0].conj().transpose() + 1 #index partitions from 1 up. like metis. 94 print("Done") 95 89 part = Chaco(md.qmu.adjacency, weights, np.array([]), md.mesh.x, md.mesh.y, md.mesh.z, method, npart, np.array([]))[0].conj().transpose() + 1 #index partitions from 1 up. like metis. 96 90 elif package == 'scotch': 97 91 if vectortype == 'element': … … 99 93 else: 100 94 #are we using weights? 101 if options.getfieldvalue('weighting') == 'on':95 if m.strcmpi(options.getfieldvalue('weighting'), 'on'): 102 96 weights = np.floor(md.qmu.vertex_weight / min(md.qmu.vertex_weight)) 103 97 else: … … 105 99 maptab = Scotch(md.qmu.adjacency, [], weights, [], 'cmplt', [npart]) 106 100 107 part = maptab[:, 1] + 1 101 part = maptab[:, 1] + 1 #index partitions from 1 up. like metis. 108 102 109 103 elif package == 'linear': … … 122 116 else: 123 117 raise RuntimeError('partitioner error message: could not find {} partitioner'.format(package)) 124 print("extrude") 118 125 119 #extrude if we are in 3D: 126 120 if md.mesh.dimension() == 3: -
issm/trunk-jpl/src/m/plot/plotmodel.py
r26182 r26184 14 14 def plotmodel(md, *args): 15 15 ''' 16 PLOTMODEL - At command prompt, type 'plotdoc()' for additional 16 PLOTMODEL - At command prompt, type 'plotdoc()' for additional 17 17 documentation. 18 18 … … 31 31 subplotwidth = ceil(sqrt(numberofplots)) 32 32 33 # TODO: Check that commenting this out is correct; we do not need a hold 33 # TODO: Check that commenting this out is correct; we do not need a hold 34 34 # under matplotlib, right? 35 35 # … … 40 40 if options.list[0].exist('nrows'): 41 41 nrows = options.list[0].getfieldvalue('nrows') 42 nr = True 42 43 else: 43 if options.list[0].exist('ncols'): 44 ncols = options.list[0].getfieldvalue('ncols') 45 nrows = np.ceil(numberofplots / ncols) 46 else: 47 nrows = np.ceil(numberofplots / subplotwidth) 44 nrows = np.ceil(numberofplots / subplotwidth) 45 nr = False 48 46 49 47 if options.list[0].exist('ncols'): 50 48 ncols = options.list[0].getfieldvalue('ncols') 51 n rows = np.ceil(numberofplots / ncols)49 nc = True 52 50 else: 53 51 ncols = int(subplotwidth) 52 nc = False 54 53 ncols = int(ncols) 55 54 nrows = int(nrows) 56 55 56 #check that nrows and ncols were given at the same time! 57 if nr != nc: 58 raise Exception('plotmodel error message: nrows and ncols need to be specified together, or not at all') 59 57 60 # Go through plots 58 61 # 59 # NOTE: The following is where Python + matplolib differs substantially in 62 # NOTE: The following is where Python + matplolib differs substantially in 60 63 # implementation and inteface from MATLAB. 61 64 # … … 80 83 plotnum = None 81 84 82 # NOTE: The inline comments for each of the following parameters are 85 # NOTE: The inline comments for each of the following parameters are 83 86 # taken from https://matplotlib.org/api/_as_gen/mpl_toolkits.axes_grid1.axes_grid.ImageGrid.html 84 87 # 85 direction = options.list[0].getfieldvalue('direction', 'row') 86 axes_pad = options.list[0].getfieldvalue('axes_pad', 0.25) 87 add_all = options.list[0].getfieldvalue('add_all', True) 88 share_all = options.list[0].getfieldvalue('share_all', True) 89 label_mode = options.list[0].getfieldvalue('label_mode', 'L') 88 direction = options.list[0].getfieldvalue('direction', 'row') # {"row", "column"}, default: "row" 89 axes_pad = options.list[0].getfieldvalue('axes_pad', 0.25) # float or (float, float), default : 0.02; Padding or (horizonal padding, vertical padding) between axes, in inches 90 add_all = options.list[0].getfieldvalue('add_all', True) # bool, default: True 91 share_all = options.list[0].getfieldvalue('share_all', True) # bool, default: False 92 label_mode = options.list[0].getfieldvalue('label_mode', 'L') # {"L", "1", "all"}, default: "L"; Determines which axes will get tick labels: "L": All axes on the left column get vertical tick labels; all axes on the bottom row get horizontal tick labels;. "1": Only the bottom left axes is labelled. "all": all axes are labelled. 90 93 91 94 # Translate MATLAB colorbar mode to matplotlib 92 95 # 93 96 # TODO: 94 # - Add 'edge' option (research if there is a corresponding option in 97 # - Add 'edge' option (research if there is a corresponding option in 95 98 # MATLAB)? 96 99 # … … 106 109 raise RuntimeError('plotmodel error: colorbar mode \'{}\' is not a valid option'.format(colorbar)) 107 110 108 cbar_mode = colorbar 109 cbar_location = options.list[0].getfieldvalue('colorbarpos', 'right') 110 cbar_pad = options.list[0].getfieldvalue('colorbarpad', 0.025) 111 cbar_size = options.list[0].getfieldvalue('colorbarsize', '5%') 111 cbar_mode = colorbar # {"each", "single", "edge", None }, default: None 112 cbar_location = options.list[0].getfieldvalue('colorbarpos', 'right') # {"left", "right", "bottom", "top"}, default: "right" 113 cbar_pad = options.list[0].getfieldvalue('colorbarpad', 0.025) # float, default: None 114 cbar_size = options.list[0].getfieldvalue('colorbarsize', '5%') # size specification (see Size.from_any), default: "5%" 112 115 113 116 # NOTE: Second parameter is: … … 115 118 # rect(float, float, float, float) or int 116 119 # 117 # The axes position, as a (left, bottom, width, height) tuple or as a 120 # The axes position, as a (left, bottom, width, height) tuple or as a 118 121 # three-digit subplot position code (e.g., "121"). 119 122 # -
issm/trunk-jpl/src/m/qmu/dakota_out_parse.py
r26183 r26184 8 8 from helpers import * 9 9 10 # NOTE: May be rewritten later to take advantage of Python's file I/O11 # mechanics. As it is written now, it is often difficult to work with, but is12 # 10 # NOTE: May be rewritten later to take advantage of Python's file I/O 11 # mechanics. As it is written now, it is often difficult to work with, but is 12 # analagous to the MATLAB version of dakota_out_parse. 13 13 14 14 … … 32 32 prcm (double array, partial rank correlation matrix) 33 33 34 The filei will be prompted for if empty. The fields of dresp are particular 35 to the data contained within the file. The scm, pcm, srcm, and prcm are 34 The filei will be prompted for if empty. The fields of dresp are particular 35 to the data contained within the file. The scm, pcm, srcm, and prcm are 36 36 output by Dakota only for the sampling methods. 37 37 38 This function reads a Dakota .out output file and parses it into the Python 39 runtime. It operates in a content-driven fashion, where it skips the 40 intermediate data and then parses whatever output data it encounters in the 41 order in which it exists in the file, rather than searching for data based 42 on the particular method (this makes it independent of method). It also can 38 This function reads a Dakota .out output file and parses it into the Python 39 runtime. It operates in a content-driven fashion, where it skips the 40 intermediate data and then parses whatever output data it encounters in the 41 order in which it exists in the file, rather than searching for data based 42 on the particular method (this makes it independent of method). It also can 43 43 read and parse the .dat tabular_output file. 44 44 45 This data would typically be used for plotting and other postprocessing 45 This data would typically be used for plotting and other postprocessing 46 46 within MATLAB or Excel. 47 47 48 48 TODO: 49 - Figure out why output from Dakota is different under MATLAB and Python 49 - Figure out why output from Dakota is different under MATLAB and Python 50 50 (is it the input file that we write?) 51 51 52 "Copyright 2009, by the California Institute of Technology. ALL RIGHTS 53 RESERVED. United States Government Sponsorship acknowledged. Any commercial 54 use must be negotiated with the Office of Technology Transfer at the 52 "Copyright 2009, by the California Institute of Technology. ALL RIGHTS 53 RESERVED. United States Government Sponsorship acknowledged. Any commercial 54 use must be negotiated with the Office of Technology Transfer at the 55 55 California Institute of Technology. (NTR 47078) 56 56 57 This software may be subject to U.S. export control laws. By accepting this 58 software, the user agrees to comply with all applicable U.S. export laws 59 and regulations. User has the responsibility to obtain export licenses, or 60 other export authority as may be required before exporting such information 57 This software may be subject to U.S. export control laws. By accepting this 58 software, the user agrees to comply with all applicable U.S. export laws 59 and regulations. User has the responsibility to obtain export licenses, or 60 other export authority as may be required before exporting such information 61 61 to foreign countries or providing access to foreign persons." 62 62 """ … … 78 78 raise RuntimeError('File ' + filei + ' is empty') 79 79 80 dresp = [] 80 dresp = [] # of struct() 81 81 scm = struct() 82 82 pcm = struct() … … 189 189 [ntokens, tokens] = fltokens(fline) 190 190 191 if fline.startswith('%eval_id interface'):# Dakota versions >= 6191 if strncmpi(fline, '%eval_id interface', 18): # Dakota versions >= 6 192 192 offset = 2 193 193 else: # Dakota versions < 6 … … 223 223 print('Number of rows (Dakota func evals) = ' + str(nrow)) 224 224 225 # Calculate statistic 225 # Calculate statistics 226 226 if (np.size(data, 0) > 1): 227 227 #dmean = mean(data) … … 229 229 [dmean, dstddev, dmeanci, dstddevci] = normfit_issm(data, 0.05) 230 230 else: 231 dmean = np.zeros(( np.size(data, 1)))232 dstddev = np.zeros(( np.size(data, 1)))231 dmean = np.zeros((1, np.size(data, 1))) 232 dstddev = np.zeros((1, np.size(data, 1))) 233 233 dmeanci = np.zeros((2, np.size(data, 1))) 234 234 dstddevci = np.zeros((2, np.size(data, 1))) 235 235 for i in range(np.size(data, 1)): 236 dmean[i], dstddev[i], dmeanci[:, i], dstddevci[:, i] = normfit_issm(data[:, i], 0.05)236 [dmean[0, i], dstddev[0, i], dmeanci[:, i], dstddevci[:, i]] = normfit_issm(data[:, i], 0.05) 237 237 238 238 dmin = data.min(axis=0) … … 244 244 dmax95 = prctile_issm(data, 95, 0) 245 245 246 # NOTE: The following line may cause the following warning (should not 247 # crash or invalidate results) when one of the inputs does not change with 246 # NOTE: The following line may cause the following warning (should not 247 # crash or invalidate results) when one of the inputs does not change with 248 248 # respect to the other(s), causing an internal divide-by-zero error, 249 249 # … … 487 487 fline = fidi.readline() 488 488 icdf = 0 489 while (fline != '' and not fline.isspace()) and not fline.startswith('Cumulative Distribution Function'):489 while (fline != '' and not fline.isspace()) and not strncmpi(fline, 'Cumulative Distribution Function', 32): 490 490 [ntokens, tokens] = fltokens(fline) 491 491 icdf = icdf + 1 … … 546 546 fline = fidi.readline() 547 547 ipdf = 0 548 while (fline != '' and not fline.isspace()) and not fline.startswith('PDF for'):548 while (fline != '' and not fline.isspace()) and not strncmpi(fline, 'PDF for', 7): 549 549 [ntokens, tokens] = fltokens(fline) 550 550 ipdf = ipdf + 1 … … 624 624 ndresp = 0 625 625 626 while fline.startswith('MV Statistics for '):626 while (fline != '' and not fline.isspace()) and strncmpi(fline, 'MV Statistics for ', 18): 627 627 628 628 # add new response function and moments … … 649 649 dresp[-1].sens = [] 650 650 651 while 'Importance Factor for variable' in fline:651 while (fline != '' and not fline.isspace()) and strncmpi(fline, ' Importance Factor for variable ', 33): 652 652 [ntokens, tokens] = fltokens(fline) 653 653 idvar = idvar + 1 … … 667 667 dresp[-1].impfac = [] 668 668 dresp[-1].sens = [] 669 while type(fline) == str and (fline != '' and not fline.isspace()) and 'Cumulative Distribution Function' not in fline and 'MV Statistics for ' not in fline and '---' not in fline:669 while type(fline) == str and (fline != '' and not fline.isspace()) and not strncmpi(fline, 'Cumulative Distribution Function', 32) and not strncmpi(fline, 'MV Statistics for ', 18) and not strncmp(fline, ' - ', 1): 670 670 fline = fidi.readline() 671 671 … … 682 682 fline = fidi.readline() 683 683 684 while fline.startswith('Cumulative Distribution Function'):684 while (fline != '' and not fline.isspace()) and strncmpi(fline, 'Cumulative Distribution Function', 32): 685 685 [ntokens, tokens] = fltokens(fline) 686 686 … … 705 705 # read and add cdf table to response function 706 706 fline = fidi.readline() 707 while (fline != '' and not fline.isspace()) and not fline.startswith('MV Statistics for ') and '---' not in fline:707 while (fline != '' and not fline.isspace()) and not strncmpi(fline, 'MV Statistics for ', 18) and not strncmp(fline, ' - ', 1): 708 708 [ntokens, tokens] = fltokens(fline) 709 709 icdf = icdf + 1 … … 724 724 print(' Cumulative Distribution Function not available') 725 725 dresp[ndresp].cdf = [] 726 while (fline != '' and not fline.isspace()) and not fline.startswith('MV Statistics for ') and '---' not in fline:726 while (fline != '' and not fline.isspace()) and not strncmpi(fline, 'MV Statistics for ', 18) and not strncmp(fline, ' - ', 1): 727 727 fline = fidi.readline() 728 728 … … 737 737 738 738 if fline is None or fline == '' or fline.isspace(): 739 fline = findline(fidi, ' <<<<< Best ')739 fline = findline(fidi, ' < < < < < Best ') 740 740 if fline is None: 741 741 return … … 747 747 print('Reading values for best function evaluation:') 748 748 749 while fline.startswith('<<<<< Best '):749 while (fline != '' and not fline.isspace()) and strncmpi(fline, ' < < < < < Best ', 11): 750 750 [ntokens, tokens] = fltokens(fline) 751 751 752 752 # read and add best parameter(s) 753 753 754 if str (tokens[2]).startswith('parameter'):754 if strncmpi(str(tokens[2]), 'parameter', 9): 755 755 print(' ' + fline) 756 756 … … 759 759 dresp.best.descriptor = '' 760 760 761 while (fline != '' and not fline.isspace()) and not fline.startswith('<<<<< Best '):761 while (fline != '' and not fline.isspace()) and not strncmpi(fline, ' < < < < < Best ', 11): 762 762 [ntokens, tokens] = fltokens(fline) 763 763 dresp.best.param.append([0]) … … 767 767 768 768 # read and add best objective function(s) 769 elif str (tokens[2]).startswith('objective') and str(tokens[3]).startswith('function'):769 elif strncmpi(str(tokens[2]), 'objective', 9) and strncmpi(str(tokens[3]), 'function', 8): 770 770 print(' ' + fline) 771 771 … … 773 773 dresp.best.of = [] 774 774 775 while (fline != '' and not fline.isspace()) and not fline.startswith('<<<<< Best '):775 while (fline != '' and not fline.isspace()) and not strncmpi(fline, ' < < < < < Best ', 11): 776 776 [ntokens, tokens] = fltokens(fline) 777 777 dresp.best.of.append(0) … … 780 780 781 781 # read and add best residual norms 782 elif str (tokens[2]).startswith('residual') and str(tokens[3]).startswith('norm'):782 elif strncmpi(str(tokens[2]), 'residual', 8) and strncmpi(str(tokens[3]), 'norm', 4): 783 783 print(' ' + fline) 784 784 dresp.best.norm = tokens[5] … … 787 787 fline = fidi.readline() 788 788 789 while (fline != '' and not fline.isspace()) and not strncmpi(fline, ' <<<<< Best ', 11):789 while (fline != '' and not fline.isspace()) and not strncmpi(fline, ' < < < < < Best ', 11): 790 790 fline = fidi.readline() 791 791 792 792 # read and add best residual term(s) 793 elif str (tokens[2]).startswith('residual') and str(tokens[3]).startswith('term'):793 elif strncmpi(str(tokens[2]), 'residual', 8) and strncmpi(str(tokens[3]), 'term', 4): 794 794 print(' ' + fline) 795 795 … … 797 797 dresp.best.res = [] 798 798 799 while (fline != '' and not fline.isspace()) and not fline.startswith('<<<<< Best '):799 while (fline != '' and not fline.isspace()) and not strncmpi(fline, '<<<<<Best ', 11): 800 800 [ntokens, tokens] = fltokens(fline) 801 801 dresp.best.res.append(0) … … 804 804 805 805 # read and add best constraint value(s) 806 elif str (tokens[2]).startswith('constraint') and str(tokens[3]).startswith('value'):806 elif strncmpi(str(tokens[2]), 'constraint', 10) and strncmpi(str(tokens[3]), 'value', 5): 807 807 print(' ' + fline) 808 808 … … 810 810 dresp.best.nc = [] 811 811 812 while (fline != '' and not fline.isspace()) and not fline.startswith('<<<<< Best '):812 while (fline != '' and not fline.isspace()) and not strncmpi(fline, '<<<<<Best ', 11): 813 813 [ntokens, tokens] = fltokens(fline) 814 814 dresp.best.nc.append(0) … … 817 817 818 818 # read and add best data captured 819 elif str (tokens[2]).startswith('data') and str(tokens[3]).startswith('captured'):819 elif strncmpi(str(tokens[2]), 'data', 4) and strncmpi(str(tokens[3]), 'captured', 8): 820 820 print(' ' + fline) 821 821 dresp.best.eval = tokens[7] … … 823 823 fline = fidi.readline() 824 824 825 while (fline != '' and not fline.isspace()) and not fline.startswith('<<<<< Best '):825 while (fline != '' and not fline.isspace()) and not strncmpi(fline, ' < < < < < Best ', 11): 826 826 fline = fidi.readline() 827 827 … … 832 832 fline = fidi.readline() 833 833 834 while (fline != '' and not fline.isspace()) and not fline.startswith('<<<<< Best '):834 while (fline != '' and not fline.isspace()) and not strncmpi(fline, ' < < < < < Best ', 11): 835 835 fline = fidi.readline() 836 836 … … 903 903 for fline in fidi: 904 904 npos += len(fline) 905 if fline.startswith(string):905 if (strncmpi(fline, string, len(string))): 906 906 if goto_line: 907 907 fidi.seek(npos, 0) -
issm/trunk-jpl/src/m/solve/parseresultsfromdisk.py
r26183 r26184 3 3 import numpy as np 4 4 from results import solution 5 from netCDF4 import Dataset6 5 7 6 … … 76 75 # }}} 77 76 78 79 77 def parseresultsfromdiskioserial(md, filename): # {{{ 80 78 # Open file 81 79 try: 82 80 fid = open(filename, 'rb') 83 except IOError :81 except IOError as e: 84 82 raise IOError("parseresultsfromdisk error message: could not open {} for binary reading".format(filename)) 85 print(md.results) 83 86 84 # Collect all results in a list 87 85 allresults = [] … … 89 87 # Read next result 90 88 result = ReadData(fid, md) 89 91 90 if result is None: 92 91 if allresults == []: … … 94 93 else: 95 94 break 96 # print("now got {} for time {}".format(result['fieldname'], result['time']))97 # print("with keys {}".format(result.keys()))98 # print("==============================")99 95 100 96 allresults.append(result) … … 123 119 return results 124 120 # }}} 125 126 127 def parseresultsfromdisktonc(md, filin, filout): # {{{128 verbose = 0129 # Open file130 try:131 fid = open(filin, 'rb')132 except IOError:133 raise IOError("parseresultsfromdisk error message: could not open {} for binary reading".format(filin))134 135 NCData = Dataset(filout, 'w', format='NETCDF4')136 UnlimDim = NCData.createDimension('Unlim', None)137 DimDict = {len(UnlimDim): 'Inf'}138 dimindex = 2139 dimlist = [2, md.mesh.numberofelements, md.mesh.numberofvertices, np.shape(md.mesh.elements)[1]]140 dimnames = ['DictDummy', 'EltNum', 'VertNum', 'VertPerElt']141 if verbose > 0:142 print('===Creating dimensions ===')143 for i, newdim in enumerate(dimlist):144 if newdim not in list(DimDict.keys()):145 dimindex += 1146 NewDim = NCData.createDimension(dimnames[i], newdim)147 DimDict[len(NewDim)] = dimnames[i]148 149 typelist = [bool, str, int, float, complex,150 collections.OrderedDict,151 np.int64, np.ndarray, np.float64]152 153 # Collect all results in a list154 allresults = []155 while True:156 # Read next result157 result = ReadData(fid, md)158 if result is None:159 if allresults == []:160 raise Exception('no results found in binary file ' + filename)161 else:162 break163 print("now got {} for time {}".format(result['fieldname'], result['time']))164 print("with keys {}".format(result.keys()))165 print("==============================")166 167 allresults.append(result)168 fid.close()169 170 # Now, process all results and find out how many steps we have171 numresults = len(allresults)172 allsteps = np.zeros((numresults, 1))173 for i in range(numresults):174 allsteps[i] = allresults[i]['step']175 pos = np.where(allsteps != -9999)176 allsteps = np.sort(np.unique(allsteps[pos]))177 178 # Ok, now construct structure179 results = solution()180 181 for i in range(numresults):182 result = allresults[i]183 index = 0184 if result['step'] != -9999:185 index = np.where(result['step'] == allsteps)[0][0]186 setattr(results[index], 'step', result['step'])187 if result['time'] != -9999:188 setattr(results[index], 'time', result['time'])189 setattr(results[index], result['fieldname'], result['field'])190 return results191 # }}}192 193 121 194 122 def ReadData(fid, md): # {{{ … … 393 321 # }}} 394 322 395 396 323 def addfieldtorecord(a, descr): #{{{ 397 324 if a.dtype.fields is None:
Note:
See TracChangeset
for help on using the changeset viewer.