Skip to content

Commit

Permalink
Remove unecessary conversion to ne_geom
Browse files Browse the repository at this point in the history
  • Loading branch information
Chahan Kropf committed Nov 24, 2023
1 parent cfecf10 commit 510f53f
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions climada/hazard/centroids/centr.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,18 @@ def get_closest_point(self, x_lon, y_lat, scheduler=None):
close_idx = self.geometry.distance(Point(x_lon, y_lat)).values.argmin()
return self.lon[close_idx], self.lat[close_idx], close_idx

def set_region_id(self, scheduler=None):
def set_region_id(self):
"""Set region_id as country ISO numeric code attribute for every pixel or point.
Parameters
----------
scheduler : str
used for dask map_partitions. “threads”, “synchronous” or “processes”
"""
ne_geom = self._ne_crs_geom(scheduler)
LOGGER.debug('Setting region_id %s points.', str(self.size))
if u_coord.equal_crs(self.crs, 'epsg:4326'):
self.gdf['region_id'] = u_coord.get_country_code(
ne_geom.geometry[:].y.values, ne_geom.geometry[:].x.values)
self.lat, self.lon)
else:
raise NotImplementedError(
'The region id can only be assigned if the crs is epsg:4326'
Expand All @@ -375,7 +374,7 @@ def get_elevation(self, topo_path):
"""
return u_coord.read_raster_sample(topo_path, self.lat, self.lon)

def get_dist_coast(self, signed=False, precomputed=False, scheduler=None):
def get_dist_coast(self, signed=False, precomputed=False):
"""Get dist_coast attribute for every pixel or point in meters.
Parameters
Expand All @@ -385,8 +384,6 @@ def get_dist_coast(self, signed=False, precomputed=False, scheduler=None):
precomputed : bool
If True, use precomputed distances (from NASA). Works only for crs=epsg:4326
Default: False.
scheduler : str
Used for dask map_partitions. "threads", "synchronous" or "processes"
"""
if not u_coord.equal_crs(self.crs, 'epsg:4326'):
raise NotImplementedError(
Expand All @@ -397,11 +394,11 @@ def get_dist_coast(self, signed=False, precomputed=False, scheduler=None):
return u_coord.dist_to_coast_nasa(
self.lat, self.lon, highres=True, signed=signed)
else:
ne_geom = self._ne_crs_geom(scheduler)
ne_geom = self._ne_crs_geom()
LOGGER.debug('Computing distance to coast for %s centroids.', str(self.size))
return u_coord.dist_to_coast(ne_geom, signed=signed)

def set_on_land(self, scheduler=None):
def set_on_land(self,):
"""Set on_land attribute for every pixel or point.
Parameters
Expand All @@ -415,10 +412,10 @@ def set_on_land(self, scheduler=None):
'Please use .to_default_crs to change to epsg:4326'
)

ne_geom = self._ne_crs_geom(scheduler)
LOGGER.debug('Setting on_land %s points.', str(self.lat.size))
self.gdf['on_land'] = u_coord.coord_on_land(
ne_geom.geometry[:].y.values, ne_geom.geometry[:].x.values)
self.lat, self.lon
)

@classmethod
def remove_duplicate_points(cls, centroids):
Expand Down Expand Up @@ -781,14 +778,9 @@ def _legacy_from_hdf5(cls, data):
)


def _ne_crs_geom(self, scheduler=None):
def _ne_crs_geom(self):
"""Return `geometry` attribute in the CRS of Natural Earth.
Parameters
----------
scheduler : str
used for dask map_partitions. “threads”, “synchronous” or “processes”
Returns
-------
geo : gpd.GeoSeries
Expand Down

0 comments on commit 510f53f

Please sign in to comment.