forked from wildlife-dynamics/ecoscope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 108/test_coverage
- Loading branch information
Showing
11 changed files
with
193 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import mapclassify | ||
|
||
classification_methods = { | ||
"equal_interval": mapclassify.EqualInterval, | ||
"natural_breaks": mapclassify.NaturalBreaks, | ||
"quantile": mapclassify.Quantiles, | ||
"std_mean": mapclassify.StdMean, | ||
"max_breaks": mapclassify.MaximumBreaks, | ||
"fisher_jenks": mapclassify.FisherJenks, | ||
} | ||
|
||
|
||
# pass in a series and output the series | ||
def apply_classification(x, labels=None, scheme="natural_breaks", **kwargs): | ||
""" | ||
Classifies the data in a GeoDataFrame column using specified classification scheme. | ||
Args: | ||
y : An array containing the data to classify. | ||
labels (str): labels of bins, use bin edges if labels==None. | ||
scheme (str): Classification scheme to use [equal_interval, natural_breaks, quantile, std_mean, max_breaks, | ||
fisher_jenks] | ||
**kwargs: Additional keyword arguments specific to the classification scheme. | ||
Returns: | ||
result: an array of corresponding labels of the input data. | ||
""" | ||
|
||
classifier_class = classification_methods.get(scheme) | ||
|
||
if not classifier_class: | ||
raise ValueError(f"Invalid classification scheme. Choose from: {list(classification_methods.keys())}") | ||
|
||
classifier = classifier_class(x, **kwargs) | ||
if labels is None: | ||
labels = classifier.bins | ||
assert len(labels) == len(classifier.bins) | ||
return [labels[i] for i in classifier.yb] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.7.0" | ||
__version__ = "1.7.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.