def set_dist_coast(self, signed=False, precomputed=False, scheduler=None): """Set dist_coast attribute for every pixel or point in meters. Parameters ---------- signed : bool If True, use signed distances (positive off shore and negative on land). Default: False. precomputed : bool If True, use precomputed distances (from NASA). Default: False. scheduler : str Used for dask map_partitions. "threads", "synchronous" or "processes" """ if (not self.lat.size or not self.lon.size) and not self.meta: LOGGER.warning('No lat/lon, no meta, nothing to do!') return if precomputed: if not self.lat.size or not self.lon.size: self.set_meta_to_lat_lon() self.dist_coast = u_coord.dist_to_coast_nasa(self.lat, self.lon, highres=True, signed=signed) else: ne_geom = self._ne_crs_geom(scheduler) LOGGER.debug('Computing distance to coast for %s centroids.', str(self.lat.size)) self.dist_coast = u_coord.dist_to_coast(ne_geom, signed=signed)
def test_dist_to_coast_nasa(self): """Test point in coast and point not in coast""" points = np.array([ # Caribbean Sea: [13.208333333333329, -59.625000000000014], # South America: [-12.497529, -58.849505], # Very close to coast of Somalia: [1.96475615, 45.23249055], ]) dists = [-3000, -1393549.5, 48.77] dists_lowres = [416.66666667, 1393448.09801077, 1191.38205367] # Warning: This will download more than 300 MB of data! result = dist_to_coast_nasa(points[:, 0], points[:, 1], highres=True, signed=True) result_lowres = dist_to_coast_nasa(points[:, 0], points[:, 1]) for d, r in zip(dists, result): self.assertAlmostEqual(d, r) for d, r in zip(dists_lowres, result_lowres): self.assertAlmostEqual(d, r)
def set_dist_coast(self, signed=False, precomputed=False, scheduler=None): """Set dist_coast attribute for every pixel or point. Distance to coast is computed in meters. Parameters: signed (bool): If True, use signed distances (positive off shore and negative on land). Default: False. precomputed (bool): If True, use precomputed distances (from NASA). Default: False. scheduler (str): used for dask map_partitions. “threads”, “synchronous” or “processes” """ if precomputed: if not self.lat.size or not self.lon.size: self.set_meta_to_lat_lon() self.dist_coast = dist_to_coast_nasa(self.lat, self.lon, highres=True, signed=signed) else: ne_geom = self._ne_crs_geom(scheduler) LOGGER.debug('Computing distance to coast for %s centroids.', str(self.lat.size)) self.dist_coast = dist_to_coast(ne_geom, signed=signed)