Example #1
0
    def test_dist_to_coast(self):
        """ Test point in coast and point not in coast """
        res = dist_to_coast(13.208333333333329, -59.625000000000014)
        self.assertAlmostEqual(2594.2071059573445, res[0])

        res = dist_to_coast(-12.497529, -58.849505)
        self.assertAlmostEqual(1382985.2459744606, res[0])
Example #2
0
    def test_dist_to_coast(self):
        point = (13.208333333333329, -59.625000000000014)
        res = dist_to_coast(point)
        self.assertAlmostEqual(5.7988200982894105, res[0])

        point = (13.958333333333343, -58.125)
        res = dist_to_coast(point)
        self.assertAlmostEqual(166.36505441711506, res[0])
    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(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.96768, 45.23219],
        ])
        dists = [2594.2071059573445, 1382985.2459744606, 0.088222234]
        for d, p in zip(dists, points):
            res = dist_to_coast(*p)
            self.assertAlmostEqual(d, res[0])

        # All at once requires more than one UTM
        res = dist_to_coast(points)
        for d, r in zip(dists, res):
            self.assertAlmostEqual(d, r)
Example #5
0
    def set_dist_coast(self, scheduler=None):
        """ Set dist_coast attribute for every pixel or point. Distance to
        coast is computed in meters.

        Parameter:
            scheduler (str): used for dask map_partitions. “threads”,
                “synchronous” or “processes”
        """
        ne_geom = self._ne_crs_geom(scheduler)
        LOGGER.debug('Setting dist_coast %s points.', str(self.lat.size))
        self.dist_coast = dist_to_coast(ne_geom)
Example #6
0
    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)
Example #7
0
    def test_dist_since_lf_pass(self):
        """ Test _dist_since_lf for andrew tropical cyclone."""
        tc_track = TCTracks()
        tc_track.read_processed_ibtracs_csv(TC_ANDREW_FL)
        track = tc_track.get_track()
        track['on_land'] = ('time', coord_on_land(track.lat.values,
             track.lon.values))
        track['dist_since_lf'] = ('time', tc._dist_since_lf(track))

        self.assertTrue(np.all(np.isnan(track.dist_since_lf.values[track.on_land == False])))
        self.assertEqual(track.dist_since_lf.values[track.on_land == False].size, 38)

        self.assertTrue(track.dist_since_lf.values[-1] >
                        dist_to_coast(track.lat.values[-1], track.lon.values[-1])/1000)
        self.assertEqual(1020.5431562223974, track['dist_since_lf'].values[-1])

        # check distances on land always increase, in second landfall
        dist_on_land = track.dist_since_lf.values[track.on_land]
        self.assertTrue(np.all(np.diff(dist_on_land)[1:] > 0))
Example #8
0
 def set_dist_coast(self):
     """ Set dist_coast attribute for every pixel or point. Distan to 
     coast is computed in meters """
     lon, lat = self._ne_crs_xy()
     LOGGER.debug('Setting dist_coast %s points.', str(self.lat.size))
     self.dist_coast = dist_to_coast(lat, lon)
Example #9
0
 def set_dist_coast(self):
     """Add dist_coast attribute: distance to coast in km for each centroids.
     No distinction between sea and land centroids."""
     self.dist_coast = dist_to_coast(self.coord)