Changeset 24894
- Timestamp:
- 05/22/20 16:21:43 (5 years ago)
- Location:
- issm/trunk-jpl/src/m
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/mesh3dsurface.m
r24885 r24894 232 232 233 233 %increase counter: 234 counter =counter+3;234 counter += 3; 235 235 end 236 236 elseif strcmpi(geometry,'polygon'), 237 % TODO: Refactor the following to reduce repeated code, or 238 % leave as is because it is more readable? 237 239 if isempty(index), 238 counter=1;239 240 for i=1:self.numberofelements, 240 241 el=self.elements(i,:); 241 242 contours(i).x=[self.long(el(1)) self.long(el(2)) self.long(el(3)) self.long(el(1))]; 242 243 contours(i).y=[self.lat(el(1)) self.lat(el(2)) self.lat(el(3)) self.lat(el(1))]; 244 contours(i).Id = i; 243 245 contours(i).Geometry = 'Polygon'; 244 contours(i).Id = i;245 246 end 246 247 else 247 counter=1;248 248 for i=1:length(index), 249 249 el=self.elements(index(i),:); … … 255 255 end 256 256 else 257 error(sprintf('mesh3dsurface ''export'' error message: geometry %s not supported yet (should be ''point'' or ''line'' ',geometry));257 error(sprintf('mesh3dsurface ''export'' error message: geometry %s not supported yet (should be ''point'' or ''line'' or ''polygon'')',geometry)); 258 258 end 259 259 -
issm/trunk-jpl/src/m/classes/mesh3dsurface.py
r24213 r24894 1 import numpy as np 2 3 from checkfield import checkfield 4 from fielddisplay import fielddisplay 1 5 from MatlabFuncs import * 2 6 from model import * 3 import numpy as np4 from fielddisplay import fielddisplay5 from checkfield import checkfield6 7 from WriteData import WriteData 7 8 … … 12 13 # Usage: 13 14 # mesh3dsurface = mesh3dsurface(); 14 def __init__(self, *args): 15 def __init__(self, *args): # {{{ 15 16 self.x = np.nan 16 17 self.y = np.nan … … 51 52 # }}} 52 53 53 def __repr__(self): 54 def __repr__(self): # {{{ 54 55 string = ' 2D tria Mesh (horizontal):' 55 56 … … 83 84 # }}} 84 85 85 def loadobj(self): 86 def loadobj(self): # {{{ 86 87 # This def is directly called by matlab when a model() selfect is 87 88 # loaded. Update old properties here … … 101 102 # }}} 102 103 103 def setdefaultparameters(self): 104 def setdefaultparameters(self): # {{{ 104 105 #the connectivity is the averaged number of nodes linked to a 105 106 #given node through an edge. This connectivity is used to initially … … 111 112 # }}} 112 113 113 def checkconsistency(self, md, solution, analyses): 114 def checkconsistency(self, md, solution, analyses): # {{{ 114 115 md = checkfield(md, 'fieldname', 'mesh.x', 'NaN', 1, 'Inf', 1, 'size', [md.mesh.numberofvertices]) 115 116 md = checkfield(md, 'fieldname', 'mesh.y', 'NaN', 1, 'Inf', 1, 'size', [md.mesh.numberofvertices]) … … 133 134 # }}} 134 135 135 def marshall(self, prefix, md, fid): 136 def marshall(self, prefix, md, fid): # {{{ 136 137 WriteData(fid, prefix, 'name', 'md.mesh.domain_type', 'data', 'Domain' + self.domaintype(), 'format', 'String') 137 138 WriteData(fid, prefix, 'name', 'md.mesh.domain_dimension', 'data', self.dimension(), 'format', 'Integer') … … 151 152 # }}} 152 153 153 def domaintype(self): 154 def domaintype(self): # {{{ 154 155 return '3Dsurface' 155 156 # }}} 156 157 157 def dimension(self): 158 def dimension(self): # {{{ 158 159 return 2 159 160 # }}} 160 161 161 def elementtype(self): 162 def elementtype(self): # {{{ 162 163 return 'Tria' 163 164 # }}} 164 165 165 def processmesh(self, options): 166 def processmesh(self, options): # {{{ 166 167 isplanet = 1 167 168 is2d = 0 … … 174 175 # }}} 175 176 176 def savemodeljs(self, fid, modelname): 177 def savemodeljs(self, fid, modelname): # {{{ 177 178 fid.write(' #s.mesh = new mesh3dsurface()\n' % modelname) 178 179 writejs1Darray(fid, [modelname, '.mesh.x'], self.x) … … 195 196 writejs1Darray(fid, [modelname, '.mesh.extractedvertices'], self.extractedvertices) 196 197 writejs1Darray(fid, [modelname, '.mesh.extractedelements'], self.extractedelements) 197 198 # }}} 198 # }}} 199 200 def export(self, *args): # {{{ 201 options = pairoptions(*args) 202 203 filename = options.getfieldvalue('filename') 204 format = options.getfieldvalue('format', 'shp') 205 geometry = options.getfieldvalue('geometry', 'line') 206 index = options.getfieldvalue('index', []) 207 proj = options.getfieldvalue('projection', '') 208 209 #prepare contours: 210 contours = [] 211 if geometry == 'point': 212 for i in range(len(self.numberofvertices)): 213 contour = OrderedStruct() 214 contour.x = self.long[i] 215 contour.y = self.lat[i] 216 contour.id = i 217 contour.Geometry = 'Point' 218 contours[i] = contour 219 elif geometry == 'line': 220 counter = 0 221 for i in range(len(self.numberofelements)): 222 el = self.elements[i] 223 224 #first line: 225 contour = OrderedStruct() 226 contour.x = [self.long[el[0]] self.long[el[1]]] 227 contour.y = [self.lat[el[0]] self.lat[el[1]]] 228 contour.Geometry = 'Line' 229 contours[counter] = contour 230 231 #second line: 232 contour = OrderedStruct() 233 contour.x = [self.long[el[1]] self.long[el[2]]] 234 contour.y = [self.lat[el[1]] self.lat[el[2]]] 235 contour.Geometry = 'Line' 236 contours[counter + 1] = contour 237 238 #second line: 239 contour = OrderedStruct() 240 contour.x = [self.long[el[2]] self.long[el[0]]] 241 contour.y = [self.lat[el[2]] self.lat[el[0]]] 242 contour.Geometry = 'Line' 243 contours[counter + 2] = contour 244 245 #increase counter: 246 counter += 3 247 elif geometry == 'polygon': 248 # TODO: Refactor the following to reduce repeated code, or 249 # leave as is because it is more readable? 250 if index == []: 251 for i in range(len(self.numberofelements)): 252 el = self.elements[i] 253 254 contour = OrderedStruct() 255 contour.x = [self.long[el[0]] self.long[el[1]] self.long[el[2]]] 256 contour.y = [self.lat[el[0]] self.lat[el[1]] self.lat[el[2]]] 257 contour.Id = i 258 contour.Geometry = 'Polygon' 259 contours[i] = contour 260 else: 261 for i in range(len(index)): 262 el = self.elements[index[i]] 263 264 contour = OrderedStruct() 265 contour.x = [self.long[el[0]] self.long[el[1]] self.long[el[2]]] 266 contour.y = [self.lat[el[0]] self.lat[el[1]] self.lat[el[2]]] 267 contour.Id = index[i] 268 contour.Geometry = 'Polygon' 269 contours[i] = contour 270 else: 271 raise RuntimeError("mesh3dsurface 'export' error message: geometry %s not supported yet (should be 'point' or 'line' or 'polygon')" % geometry) 272 273 #write file: 274 if format == 'shp': 275 shpwrite(contours, filename) 276 elif format == 'exp': 277 expwrite(contours, filename) 278 else: 279 raise RuntimeError("mesh3dsurface 'export' error message: file format %s not supported yet" % format) 280 281 #write projection file: 282 if proj != '': 283 proj2shpprj(filename, proj) 284 285 #write style file: 286 applyqgisstyle(filename, 'mesh') 287 # }}} -
issm/trunk-jpl/src/m/qmu/helpers.py
r24870 r24894 17 17 attributes other than the array 18 18 19 List - based and struct -based behaviors work normally, however they are referenced19 List-based and struct-based behaviors work normally, however they are referenced 20 20 as if the other does not exist; len(x) corresponds only to 21 21 the list component of x, len(x.a) corresponds to x.a, x.__dict__ 22 corresponds only to the non - x -list attributes22 corresponds only to the non-x-list attributes 23 23 24 24 Example uses: … … 64 64 ''' 65 65 A form of dictionary-like structure that maintains the 66 ordering in which its fields /attributes and their66 ordering in which its fields/attributes and their 67 67 corresponding values were added. 68 68 69 69 OrderedDict is a similar device, however this class 70 can be used as an "ordered struct /class" giving70 can be used as an "ordered struct/class" giving 71 71 it much more flexibility in practice. It is 72 72 also easier to work with fixed valued keys in-code. … … 128 128 129 129 if len(args) % 2 != 0: 130 raise RuntimeError('OrderedStruct input error: OrderedStruct(*args) call must have an even number of inputs, in key /value pairs')130 raise RuntimeError('OrderedStruct input error: OrderedStruct(*args) call must have an even number of inputs, in key/value pairs') 131 131 132 132 for a, b in zip(args[0::2], args[1::2]): … … 186 186 def __copy__(self): 187 187 # shallow copy, hard copies of trivial attributes, 188 # references to structures like lists /OrderedDicts188 # references to structures like lists/OrderedDicts 189 189 # unless redefined as an entirely different structure 190 190 newInstance = type(self)() … … 234 234 return True 235 235 236 # if anything in that array /matrix is not empty, the whole thing is not empty236 # if anything in that array/matrix is not empty, the whole thing is not empty 237 237 try: 238 238 x = np.concatenate(x)
Note:
See TracChangeset
for help on using the changeset viewer.