elapid
elapid copied to clipboard
Boyce index code
PR Description: Add Continuous Boyce Index Calculation and Test Cases
Summary:
In this pull request, I have added functionality to calculate the continuous Boyce index as described in Hirzel et al. (2006) . This method provides a reliable way to evaluate habitat suitability models, specifically for presence-only data. Along with the implementation, I have also added test cases to ensure the correctness and robustness of the new function.
Key Updates:
-
Boyce Index Calculation:
- Implemented a function to compute the continuous Boyce index based on intervals of habitat suitability values.
- This includes handling both sliding window and fixed-bin approaches, as well as ensuring compatibility with NumPy, Pandas, and GeoPandas data structures.
- Added logic to handle edge cases like empty arrays, NaN values, and invalid inputs (e.g., non-1D arrays).
-
Test Cases:
- Created test cases to validate the behavior of the Boyce index calculation under various scenarios (e.g., different bin sizes, presence of NaN values).
- Ensured that the function calculates the correct predicted-to-expected (P/E) ratio and returns accurate Spearman correlation coefficients.
-
Notebook Update:
- Updated the notebook
WorkingWithGeospatialData.ipynbto include a detailed example demonstrating how to use the continuous Boyce index function.
- Updated the notebook
Testing:
The test cases ensure that the continuous Boyce index function works as expected. The test cases cover:
- Different binning strategies.
- Varying habitat suitability ranges.
- Handling of NaN values in input data.
This PR enhances the project by providing a robust and well-tested method to evaluate habitat suitability models using presence-only data, with clear examples in the updated notebook.
Any updates?
@PC-FSU let me know if you plan to finish up this contribution. If not, I'll go ahead and merge it and make the remaining updates. Cheers,
@earth-chris Please give me some time. I will be able to push it after 2nd April.
I've added the suggestions you mentioned. I also spent some time thinking about how to improve the explanation of the Boyce Index in the notebook, but I couldn't come up with a concise way to do it. Could you clarify what you had in mind? The example in the notebook feels fairly limited.
I've reviewed this PR again and want to document the next steps.
PF-FSU has contributed a large PR with several pieces. There are still a number of changes I want to make to simplify these new features, however. I think this will best be done by merging this PR then submitting the new changes. These include:
- update the CBI call to accept
yobs, ypredas the inputs instead of having users pre-index the background/presence points - update the plotting function to compute the CBI values then make the plot, which currently requires x/y values that are the outputs from the CBI function (the mean intervals and f scores, respectively).
- remove some redundant and verbose type checking and instead simply use
.asarray()to enforce type harmonization - remove the use of a string 'default' option and instead set a numerical default
- only import the cbi and plotting functions to the main API
- add the evaluate.py module to the docs
- add clearer usage examples in the simple maxent model notebook (instead of the overloaded geospatial data notebook)