def _jigsaw_hmat_worker(path, window, hmin, hmax, geom): geom = None raster = Raster(path) x = raster.get_x(window) y = raster.get_y(window) _y = np.repeat(np.min(y), len(x)) _x = np.repeat(np.min(x), len(y)) _tx = utm.from_latlon(_y, x)[0] _ty = np.flip(utm.from_latlon(y, _x)[1]) hmat = jigsaw_msh_t() hmat.mshID = "euclidean-grid" hmat.ndims = +2 hmat.xgrid = _tx.astype(jigsaw_msh_t.REALS_t) hmat.ygrid = _ty.astype(jigsaw_msh_t.REALS_t) hmat.value = np.flipud( raster.get_values(band=1, window=window) ).astype(jigsaw_msh_t.REALS_t) # init opts opts = jigsaw_jig_t() # additional configuration options opts.verbosity = 1 opts.mesh_dims = 2 opts.hfun_scal = 'absolute' opts.optm_tria = True if hmin is not None: opts.hfun_hmin = hmin else: opts.hfun_hmin = np.min(hmat.value) if hmax is not None: opts.hfun_hmax = hmax else: opts.hfun_hmax = np.max(hmat.value) # output mesh mesh = jigsaw_msh_t() # call jigsaw to create local mesh libsaw.jigsaw( opts, geom, mesh, hfun=hmat ) breakpoint() return mesh
def run(self, sieve=None, quality_metric=1.05): hfun_msh_t = self.hfun.msh_t() output_mesh = jigsaw_msh_t() output_mesh.mshID = 'euclidean-mesh' output_mesh.ndims = 2 self.opts.hfun_hmin = np.min(hfun_msh_t.value) self.opts.hfun_hmax = np.max(hfun_msh_t.value) self.opts.mesh_rad2 = float(quality_metric) geom_msh_t = self.geom.msh_t() # When the center of geom and hfun are NOT the same, utm # zones would be different for resulting msh_t. if geom_msh_t.crs != hfun_msh_t.crs: utils.reproject(hfun_msh_t, geom_msh_t.crs) output_mesh.crs = hfun_msh_t.crs _logger.info('Calling libsaw.jigsaw() ...') libsaw.jigsaw(self.opts, geom_msh_t, output_mesh, init=hfun_msh_t if self._init is True else None, hfun=hfun_msh_t) # post process if output_mesh.tria3['index'].shape[0] == 0: _err = 'ERROR: Jigsaw returned empty mesh.' _logger.error(_err) raise Exception(_err) if self._crs is not None: utils.reproject(output_mesh, self._crs) _logger.info('Finalizing mesh...') # Don't need to use ad-hoc fix since Jigsaw tiny element # issue is resolve. In case needed add a flag for remesh # since it's computationally expensive # if self.opts.hfun_hmin > 0: # output_mesh = utils.remesh_small_elements( # self.opts, geom_msh_t, output_mesh, hfun_msh_t) utils.finalize_mesh(output_mesh, sieve) _logger.info('done!') return Mesh(output_mesh)
def jigsaw(opts, geom, mesh, init=None, hfun=None): return libsaw.jigsaw(opts, geom, mesh, init, hfun)