Changeset 25483
- Timestamp:
- 08/27/20 03:29:30 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/contrib/defleurian/paraview/exportVTK.py
r24565 r25483 143 143 144 144 if 'clipping' in kwargs.keys(): 145 # first get the boundaries and check them 146 [Xmin, Xmax, Ymin, Ymax] = kwargs['clipping'] 147 if Xmin > Xmax: 148 raise ClipError('Xmax ({}) should be larger than Xmin ({})'.format(Xmax, Xmin)) 149 if Ymin > Ymax: 150 raise ClipError('Ymax ({}) should be larger than Ymin ({})'.format(Ymax, Ymin)) 151 if Xmin > np.nanmax(points[:, 0]) or Xmax < np.nanmin(points[:, 0]): 152 raise ClipError('Your X boundaries [{}, {}] are outside of the model domain [{},{}]'.format(Xmin, Xmax, np.nanmin(points[:, 0]), np.nanmax(points[:, 0]))) 153 if Ymin > np.nanmax(points[:, 1]) or Ymax < np.nanmin(points[:, 1]): 154 raise ClipError('Your Y boundaries [{}, {}] are outside of the model domain [{},{}]'.format(Ymin, Ymax, np.nanmin(points[:, 1]), np.nanmax(points[:, 1]))) 155 156 #boundaries should be fine lets do stuff 157 InX = np.where(np.logical_and(points[:, 0] >= Xmin, points[:, 0] <= Xmax)) 158 InY = np.where(np.logical_and(points[:, 1] >= Ymin, points[:, 1] <= Ymax)) 159 160 Isinside = np.zeros(np.shape(points)[0], dtype=bool) 161 clip_convert_index = np.nan * np.ones(np.shape(points)[0]) 162 163 Inclipping = np.intersect1d(InX, InY) 164 Isinside[Inclipping] = True 165 points = points[Inclipping, :] 166 num_of_points = np.shape(points)[0] 167 168 clipconnect = np.asarray([], dtype=int) 169 for elt in connect: 170 if set(elt).issubset(Inclipping): 171 clipconnect = np.append(clipconnect, elt, axis=0) 172 173 num_of_elt = int(np.size(clipconnect) / 3) 174 connect = clipconnect.reshape(num_of_elt, 3) 175 176 clip_convert_index = np.asarray([[i, np.where(Inclipping == i)[0][0]] for i, val in enumerate(clip_convert_index) if any(Inclipping == i)]) 177 enveloppe_index = enveloppe_index[clip_convert_index[:, 0]] 178 for elt in range(0, num_of_elt): 179 try: 180 connect[elt, 0] = clip_convert_index[np.where(clip_convert_index == connect[elt, 0])[0], 1][0] 181 except IndexError: 182 connect[elt, 0] = -1 183 try: 184 connect[elt, 1] = clip_convert_index[np.where(clip_convert_index == connect[elt, 1])[0], 1][0] 185 except IndexError: 186 connect[elt, 1] = -1 187 try: 188 connect[elt, 2] = clip_convert_index[np.where(clip_convert_index == connect[elt, 2])[0], 1][0] 189 except IndexError: 190 connect[elt, 2] = -1 191 192 connect = connect[np.where(connect != -1)[0], :] 193 num_of_elt = np.shape(connect)[0] 145 if kwargs['clipping'] is not None: 146 # first get the boundaries and check them 147 [Xmin, Xmax, Ymin, Ymax] = kwargs['clipping'] 148 if Xmin > Xmax: 149 raise ClipError('Xmax ({}) should be larger than Xmin ({})'.format(Xmax, Xmin)) 150 if Ymin > Ymax: 151 raise ClipError('Ymax ({}) should be larger than Ymin ({})'.format(Ymax, Ymin)) 152 if Xmin > np.nanmax(points[:, 0]) or Xmax < np.nanmin(points[:, 0]): 153 raise ClipError('Your X boundaries [{}, {}] are outside of the model domain [{},{}]'.format(Xmin, Xmax, np.nanmin(points[:, 0]), np.nanmax(points[:, 0]))) 154 if Ymin > np.nanmax(points[:, 1]) or Ymax < np.nanmin(points[:, 1]): 155 raise ClipError('Your Y boundaries [{}, {}] are outside of the model domain [{},{}]'.format(Ymin, Ymax, np.nanmin(points[:, 1]), np.nanmax(points[:, 1]))) 156 157 #boundaries should be fine lets do stuff 158 InX = np.where(np.logical_and(points[:, 0] >= Xmin, points[:, 0] <= Xmax)) 159 InY = np.where(np.logical_and(points[:, 1] >= Ymin, points[:, 1] <= Ymax)) 160 161 Isinside = np.zeros(np.shape(points)[0], dtype=bool) 162 clip_convert_index = np.nan * np.ones(np.shape(points)[0]) 163 164 Inclipping = np.intersect1d(InX, InY) 165 Isinside[Inclipping] = True 166 points = points[Inclipping, :] 167 num_of_points = np.shape(points)[0] 168 169 clipconnect = np.asarray([], dtype=int) 170 for elt in connect: 171 if set(elt).issubset(Inclipping): 172 clipconnect = np.append(clipconnect, elt, axis=0) 173 174 num_of_elt = int(np.size(clipconnect) / 3) 175 connect = clipconnect.reshape(num_of_elt, 3) 176 177 clip_convert_index = np.asarray([[i, np.where(Inclipping == i)[0][0]] for i, val in enumerate(clip_convert_index) if any(Inclipping == i)]) 178 enveloppe_index = enveloppe_index[clip_convert_index[:, 0]] 179 for elt in range(0, num_of_elt): 180 try: 181 connect[elt, 0] = clip_convert_index[np.where(clip_convert_index == connect[elt, 0])[0], 1][0] 182 except IndexError: 183 connect[elt, 0] = -1 184 try: 185 connect[elt, 1] = clip_convert_index[np.where(clip_convert_index == connect[elt, 1])[0], 1][0] 186 except IndexError: 187 connect[elt, 1] = -1 188 try: 189 connect[elt, 2] = clip_convert_index[np.where(clip_convert_index == connect[elt, 2])[0], 1][0] 190 except IndexError: 191 connect[elt, 2] = -1 192 193 connect = connect[np.where(connect != -1)[0], :] 194 num_of_elt = np.shape(connect)[0] 194 195 195 196 # }}}
Note:
See TracChangeset
for help on using the changeset viewer.