Skip to content

Commit 3f8f2ad

Browse files
author
Chahan Kropf
committed
Update docstring to removed grid centroids + black
1 parent e3b8edc commit 3f8f2ad

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

climada/entity/exposures/base.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ def assign_centroids(
602602
and parameters.
603603
604604
The value -1 is used for distances larger than ``threshold`` in point distances.
605-
In case of raster hazards the value -1 is used for centroids outside of the raster.
606605
607606
Parameters
608607
----------
@@ -615,41 +614,44 @@ def assign_centroids(
615614
threshold : float
616615
If the distance (in km) to the nearest neighbor exceeds `threshold`,
617616
the index `-1` is assigned.
618-
Set `threshold` to 0, to disable nearest neighbor matching.
617+
Set `threshold` to 0, to disable nearest neighbor matching and enforce
618+
exact matching.
619619
Default: 100 (km)
620620
overwrite: bool
621621
If True, overwrite centroids already present. If False, do
622622
not assign new centroids. Default is True.
623623
624624
See Also
625625
--------
626-
climada.util.coordinates.match_grid_points: method to associate centroids to
627-
exposure points when centroids is a raster
628626
climada.util.coordinates.match_coordinates:
629627
method to associate centroids to exposure points
630628
Notes
631629
-----
632-
The default order of use is:
633-
634-
1. if centroid raster is defined, assign exposures points to
635-
the closest raster point.
636-
2. if no raster, assign centroids to the nearest neighbor using
637-
euclidian metric
638-
639-
Both cases can introduce innacuracies for coordinates in lat/lon
640-
coordinates as distances in degrees differ from distances in meters
641-
on the Earth surface, in particular for higher latitude and distances
642-
larger than 100km. If more accuracy is needed, please use 'haversine'
643-
distance metric. This however is slower for (quasi-)gridded data,
644-
and works only for non-gridded data.
630+
For coordinates in lat/lon coordinates distances in degrees differ from
631+
distances in meters on the Earth surface, in particular for higher
632+
latitude and distances larger than 100km. If more accuracy for degree
633+
coordinates is needed, please use 'haversine' distance metric,
634+
which however is slower.
635+
636+
Caution: bearest neighbourg matching can introduce serious artefacts
637+
such as:
638+
- exposure and hazard centroids with shifted grids can lead
639+
to systematically wrong assignements.
640+
- hazard centroids covering larger areas than exposures may lead
641+
to sub-optimal matching if the threshold is too large
642+
643+
Users are free to implement their own matching alrogithm and save the
644+
matching centroid index in the appropriate column ``centr_[hazard.HAZ_TYPE]``.
645645
"""
646646
haz_type = hazard.haz_type
647647
centr_haz = INDICATOR_CENTR + haz_type
648648
if centr_haz in self.gdf:
649-
LOGGER.info("Exposures matching centroids already found for %s", haz_type)
650649
if overwrite:
651650
LOGGER.info("Existing centroids will be overwritten for %s", haz_type)
652651
else:
652+
LOGGER.info(
653+
"Exposures matching centroids already found for %s", haz_type
654+
)
653655
return
654656

655657
LOGGER.info(
@@ -659,7 +661,7 @@ def assign_centroids(
659661
)
660662

661663
if not u_coord.equal_crs(self.crs, hazard.centroids.crs):
662-
raise ValueError("Set hazard and exposure to same CRS first!")
664+
raise ValueError("Set hazard and exposure to the same CRS first!")
663665
# Note: equal_crs is tested here, rather than within match_centroids(),
664666
# because exp.gdf.crs may not be defined, but exp.crs must be defined.
665667

0 commit comments

Comments
 (0)