Changeset 26569
- Timestamp:
- 11/09/21 06:58:37 (3 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/colormaps/demmap.py
r24261 r26569 64 64 cmx = nland * interval 65 65 66 clim = [cmn, cmx]67 68 66 if strcmpi(colorscheme, 'dem'): 69 67 # concatenate and transpose to match matplotlib's colormap format -
issm/trunk-jpl/src/m/plot/plotmodel.py
r26184 r26569 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 # … … 60 60 # Go through plots 61 61 # 62 # NOTE: The following is where Python + matplolib differs substantially in 62 # NOTE: The following is where Python + matplolib differs substantially in 63 63 # implementation and inteface from MATLAB. 64 64 # … … 83 83 plotnum = None 84 84 85 # NOTE: The inline comments for each of the following parameters are 85 # NOTE: The inline comments for each of the following parameters are 86 86 # taken from https://matplotlib.org/api/_as_gen/mpl_toolkits.axes_grid1.axes_grid.ImageGrid.html 87 87 # … … 95 95 # 96 96 # TODO: 97 # - Add 'edge' option (research if there is a corresponding option in 97 # - Add 'edge' option (research if there is a corresponding option in 98 98 # MATLAB)? 99 99 # … … 118 118 # rect(float, float, float, float) or int 119 119 # 120 # 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 121 121 # three-digit subplot position code (e.g., "121"). 122 122 # … … 127 127 direction=direction, 128 128 axes_pad=axes_pad, 129 add_all=add_all,130 129 share_all=share_all, 131 130 label_mode=label_mode, -
issm/trunk-jpl/src/m/plot/processdata.py
r26352 r26569 15 15 See also: PLOTMODEL, PROCESSMESH 16 16 """ 17 # {{{ Initialization and grabbing auxiliaries17 # Initialization and grabbing auxiliaries {{{ 18 18 # check format 19 19 if (len(data) == 0 or (len(data) == 1 and not isinstance(data, dict) and np.isnan(data).all())): … … 22 22 if 'numberofvertices2d' in dir(md.mesh): 23 23 numberofvertices2d = md.mesh.numberofvertices2d 24 numberofelements2d = md.mesh.numberofelements2d25 24 else: 26 25 numberofvertices2d = np.nan 27 numberofelements2d = np.nan 26 27 if options.exist('amr'): 28 step = options.getfieldvalue('amr', 0) 29 numberofvertices = len(md.results.TransientSolution[step].MeshX) 30 numberofelements = np.shape(md.results.TransientSolution[step].MeshElements)[0] 31 else: 32 numberofvertices = md.mesh.numberofvertices 33 numberofelements = md.mesh.numberofelements 34 28 35 procdata = np.copy(data) 29 36 #initialize datatype … … 44 51 raise ValueError('data passed to plotmodel has bad dimensions; check that column vectors are rank - 1') 45 52 # }}} 46 # {{{ process NaN's if any 53 54 # log {{{ 55 if options.exist('log'): 56 cutoff = options.getfieldvalue('log', 1) 57 procdata[np.where(procdata < cutoff)] = cutoff 58 # }}} 59 60 # quiver plot {{{ 61 if datasize[1] > 1 and datasize[0] != numberofvertices + 1: 62 if datasize[0] == numberofvertices and datasize[1] == 2: 63 datatype = 3 64 else: 65 raise ValueError('plotmodel error message: data should have two columns of length md.mesh.numberofvertices for a quiver plot') 66 # }}} 67 68 # element data{{{ 69 if datasize[0] == numberofelements and datasize[1] == 1: 70 #initialize datatype if non patch 71 if datatype != 4 and datatype != 5: 72 datatype = 1 73 # AMR {{{ 74 if options.exist('amr'): 75 nonan = np.nonzero(~np.isnan(md.results.TransientSolution[step].MeshElements)) 76 procdata = procdata[nonan] 77 # }}} 78 # mask {{{ 79 if options.exist('mask'): 80 flags = options.getfieldvalue('mask') 81 hide = np.invert(flags) 82 if np.size(flags) == numberofvertices: 83 EltMask = np.asarray([np.any(np.in1d(index, np.where(hide))) for index in md.mesh.elements - 1]) 84 procdata = np.ma.array(procdata, mask=EltMask) 85 options.addfielddefault('cmap_set_bad', 'w') 86 elif np.size(flags) == numberofelements: 87 procdata = np.ma.array(procdata, mask=hide) 88 options.addfielddefault('cmap_set_bad', 'w') 89 else: 90 print('Warning: processdata.py: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements') 91 # }}} 92 93 # }}} 94 95 # node data {{{ 96 if datasize[0] in [numberofvertices, numberofvertices2d] and datasize[1] == 1: 97 datatype = 2 98 # AMR {{{ 99 if options.exist('amr'): 100 nonan = np.nonzero(~np.isnan(md.results.TransientSolution[step].MeshX)) 101 procdata = procdata[nonan] 102 # }}} 103 # Mask {{{ 104 if options.exist('mask'): 105 flags = options.getfieldvalue('mask') 106 hide = np.invert(flags) 107 if np.size(flags) == numberofvertices: 108 procdata = np.ma.array(procdata, mask=hide) 109 options.addfielddefault('cmap_set_bad', 'w') 110 elif np.size(flags) == numberofelements: 111 NodeMask = np.zeros(np.shape(md.mesh.x), dtype=bool) 112 HideElt = md.mesh.elements[np.where(hide)[0]] - 1 113 NodeMask[HideElt] = True 114 procdata = np.ma.array(procdata, mask=NodeMask) 115 options.addfielddefault('cmap_set_bad', 'w') 116 else: 117 print('Warning: processdata.py: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements') 118 # }}} 119 # }}} 120 121 # spc time series {{{ 122 if datasize[0] == numberofvertices + 1: 123 datatype = 2 124 spccol = options.getfieldvalue('spccol', 0) 125 print('multiple-column spc field; specify column to plot using option "spccol"') 126 print(('column ', spccol, ' plotted for time: ', procdata[-1, spccol])) 127 procdata = procdata[0:-1, spccol] 128 129 #mask? 130 131 #layer projection? 132 133 #control arrow density if quiver plot 134 # }}} 135 136 # convert rank - 2 array to rank - 1 {{{ 137 if np.ndim(procdata) == 2 and np.shape(procdata)[1] == 1: 138 procdata = procdata.reshape(-1, ) 139 # }}} 140 141 # process NaN's if any {{{ 47 142 nanfill = options.getfieldvalue('nan', -9999) 48 143 if np.any(np.isnan(procdata)): … … 53 148 ub = ub + 0.5 54 149 nanfill = lb - 1 55 #procdata[np.isnan(procdata)] = nanfill150 procdata[np.isnan(procdata)] = nanfill 56 151 procdata = np.ma.array(procdata, mask=np.isnan(procdata)) 57 options.addfielddefault('clim', [lb, ub]) 152 #clim looks to be deprecated and replaced by caxis 153 #options.addfielddefault('clim', [lb, ub]) 58 154 options.addfielddefault('cmap_set_under', '1') 59 155 print(("WARNING: nan's treated as", nanfill, "by default. Change using pairoption 'nan', nan_fill_value in plotmodel call")) 60 156 # }}} 61 # {{{ log62 if options.exist('log'):63 cutoff = options.getfieldvalue('log', 1)64 procdata[np.where(procdata < cutoff)] = cutoff65 # }}}66 # {{{ quiver plot67 if datasize[1] > 1 and datasize[0] != md.mesh.numberofvertices + 1:68 if datasize[0] == md.mesh.numberofvertices and datasize[1] == 2:69 datatype = 370 else:71 raise ValueError('plotmodel error message: data should have two columns of length md.mesh.numberofvertices for a quiver plot')72 # }}}73 # {{{ element data74 157 75 if datasize[0] == md.mesh.numberofelements and datasize[1] == 1: 76 #initialize datatype if non patch 77 if datatype != 4 and datatype != 5: 78 datatype = 1 79 # {{{mask 80 if options.exist('mask'): 81 flags = options.getfieldvalue('mask') 82 hide = np.invert(flags) 83 if np.size(flags) == md.mesh.numberofvertices: 84 EltMask = np.asarray([np.any(np.in1d(index, np.where(hide))) for index in md.mesh.elements - 1]) 85 procdata = np.ma.array(procdata, mask=EltMask) 86 options.addfielddefault('cmap_set_bad', 'w') 87 elif np.size(flags) == md.mesh.numberofelements: 88 procdata = np.ma.array(procdata, mask=hide) 89 options.addfielddefault('cmap_set_bad', 'w') 90 else: 91 print('Warning: processdata.py: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements') 92 # }}} 93 94 # }}} 95 # {{{ node data 96 if datasize[0] == md.mesh.numberofvertices and datasize[1] == 1: 97 datatype = 2 98 # {{{ Mask 99 if options.exist('mask'): 100 flags = options.getfieldvalue('mask') 101 hide = np.invert(flags) 102 if np.size(flags) == md.mesh.numberofvertices: 103 procdata = np.ma.array(procdata, mask=hide) 104 options.addfielddefault('cmap_set_bad', 'w') 105 elif np.size(flags) == md.mesh.numberofelements: 106 NodeMask = np.zeros(np.shape(md.mesh.x), dtype=bool) 107 HideElt = md.mesh.elements[np.where(hide)[0]] - 1 108 NodeMask[HideElt] = True 109 procdata = np.ma.array(procdata, mask=NodeMask) 110 options.addfielddefault('cmap_set_bad', 'w') 111 else: 112 print('Warning: processdata.py: mask length not supported yet (supported length are md.mesh.numberofvertices and md.mesh.numberofelements') 113 # }}} 114 # }}} 115 # {{{ spc time series 116 if datasize[0] == md.mesh.numberofvertices + 1: 117 datatype = 2 118 spccol = options.getfieldvalue('spccol', 0) 119 print('multiple-column spc field; specify column to plot using option "spccol"') 120 print(('column ', spccol, ' plotted for time: ', procdata[-1, spccol])) 121 procdata = procdata[0:-1, spccol] 122 123 #mask? 124 125 #layer projection? 126 127 #control arrow density if quiver plot 128 # }}} 129 # {{{ convert rank - 2 array to rank - 1 130 if np.ndim(procdata) == 2 and np.shape(procdata)[1] == 1: 131 procdata = procdata.reshape(-1, ) 132 # }}} 133 # {{{ if datatype is still zero, error out 158 # if datatype is still zero, error out {{{ 134 159 if datatype == 0: 135 160 raise ValueError("processdata error: data provided not recognized or not supported") -
issm/trunk-jpl/src/m/plot/processmesh.py
r25456 r26569 41 41 if hasattr(md.mesh, 'elements2d'): 42 42 elements2d = md.mesh.elements2d 43 numofvertices2d = md.mesh.numberofvertices2d 44 numofelements2d = md.mesh.numberofelements2d 45 else: 46 numofvertices2d = np.nan 47 numofelements2d = np.nan 43 48 44 49 if options.exist('amr'): 45 50 step = options.getfieldvalue('amr') 46 x = md.results.TransientSolution[step].MeshX 47 y = md.results.TransientSolution[step].MeshY 48 elements = md.results.TransientSolution[step].MeshElements 51 nonan = np.nonzero(~np.isnan(md.results.TransientSolution[step].MeshX)) 52 x = md.results.TransientSolution[step].MeshX[nonan] 53 y = md.results.TransientSolution[step].MeshY[nonan] 54 nonan = np.nonzero(~np.isnan(md.results.TransientSolution[step].MeshElements)) 55 elements = md.results.TransientSolution[step].MeshElements[nonan] - 1 56 eldim = np.shape(md.results.TransientSolution[step].MeshElements)[1] 57 elements = np.reshape(elements, ((int(len(elements) / eldim), eldim))) 58 49 59 else: 50 elements = md.mesh.elements 60 elements = md.mesh.elements - 1 51 61 if options.getfieldvalue('coord', 'xy') != 'latlon': 52 62 x = md.mesh.x … … 65 75 z = getattr(md, z) 66 76 77 force2D = numofelements2d in np.shape(data) or numofvertices2d in np.shape(data) 67 78 #is it a 2D plot? 68 if md.mesh.dimension() == 2 or options.getfieldvalue('layer', 0) >= 1 :79 if md.mesh.dimension() == 2 or options.getfieldvalue('layer', 0) >= 1 or force2D: 69 80 is2d = 1 70 81 else: 71 82 is2d = 0 72 83 73 elements = md.mesh.elements - 174 75 84 #layer projection? 76 if options.getfieldvalue('layer', 0) >= 1 :85 if options.getfieldvalue('layer', 0) >= 1 or force2D: 77 86 if options.getfieldvalue('coord', 'xy') == 'latlon': 78 87 raise Exception('processmesh error message: cannot work with 3D meshes for now')
Note:
See TracChangeset
for help on using the changeset viewer.