Skip to content

Commit

Permalink
Merge pull request #161 from NOAA-OWP/fix_links
Browse files Browse the repository at this point in the history
Fix Docstring Links
  • Loading branch information
fernando-aristizabal authored Sep 27, 2023
2 parents 67bc983 + 901f069 commit ddd0ff4
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 85 deletions.
8 changes: 4 additions & 4 deletions src/gval/accessors/gval_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ def compute_categorical_metrics(
References
----------
.. [1] [Evaluation of binary classifiers](https://en.wikipedia.org/wiki/Evaluation_of_binary_classifiers)
.. [2] [7th International Verification Methods Workshop](https://www.cawcr.gov.au/projects/verification/#Contingency_table)
.. [3] [3.3. Metrics and scoring: quantifying the quality of predictions](https://scikit-learn.org/stable/modules/model_evaluation.html)
.. [1] `Evaluation of binary classifiers <https://en.wikipedia.org/wiki/Evaluation_of_binary_classifiers>`_
.. [2] `7th International Verification Methods Workshop <https://www.cawcr.gov.au/projects/verification/#Contingency_table>`_
.. [3] `3.3. Metrics and scoring: quantifying the quality of predictions <https://scikit-learn.org/stable/modules/model_evaluation.html>`_
"""

return _compute_categorical_metrics(
Expand Down Expand Up @@ -126,7 +126,7 @@ def rasterize_data(
References
----------
.. [1] [geocube `make_geocube`](https://corteva.github.io/geocube/html/geocube.html)
.. [1] `make_geocube <https://corteva.github.io/geocube/html/geocube.html>`_
"""

Expand Down
31 changes: 4 additions & 27 deletions src/gval/accessors/gval_xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,8 @@ def cat_plot(
References
----------
.. [1] [Matplotlib figure](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html)
.. [2] [Matplotlib legend](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html)
.. [1] `Matplotlib figure <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html>`_
.. [2] `Matplotlib legend <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html>`_
"""

return _map_plot(
Expand Down Expand Up @@ -797,8 +797,8 @@ def cont_plot(
References
----------
.. [1] [Matplotlib figure](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html)
.. [2] [Matplotlib legend](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html)
.. [1] `Matplotlib figure <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html>`_
.. [2] `Matplotlib legend <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html>`_
"""

return _map_plot(
Expand All @@ -823,26 +823,3 @@ def vectorize_data(self) -> gpd.GeoDataFrame:
"""

return _vectorize_data(self._obj)


if __name__ == "__main__":
import rioxarray as rxr

path = "/home/sven/repos/gval/notebooks/"
subsample_df = gpd.read_file(f"{path}subsample_two-class_polygons.gpkg")
subsample_df.gval.create_subsampling_df(subsampling_type="include", inplace=True)

candidate = rxr.open_rasterio(
f"{path}candidate_map_multiband_two_class_categorical.tif", mask_and_scale=True
)
benchmark = rxr.open_rasterio(
f"{path}benchmark_map_multiband_two_class_categorical.tif", mask_and_scale=True
)

ag, ctab, met = candidate.gval.categorical_compare(
benchmark_map=benchmark,
positive_categories=[2],
negative_categories=[0, 1],
subsampling_df=subsample_df,
subsampling_average="full-detail",
)
10 changes: 5 additions & 5 deletions src/gval/comparison/agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def _compute_agreement_map(
References
----------
.. [1] [Creating NumPy universal function](https://numba.readthedocs.io/en/stable/user/vectorize.html)
.. [2] [NumPy vectorize](https://numpy.org/doc/stable/reference/generated/numpy.vectorize.html)
.. [3] [NumPy frompyfunc](https://numpy.org/doc/stable/reference/generated/numpy.frompyfunc.html)
.. [4] [Rioxarray Manage Information Loss](https://corteva.github.io/rioxarray/stable/getting_started/manage_information_loss.html)
.. [5] [Rioxarray NoData Management](https://corteva.github.io/rioxarray/stable/getting_started/nodata_management.html)
.. [1] `Creating NumPy universal function <https://numba.readthedocs.io/en/stable/user/vectorize.html>`_
.. [2] `NumPy vectorize <https://numpy.org/doc/stable/reference/generated/numpy.vectorize.html>`_
.. [3] `NumPy frompyfunc <https://numpy.org/doc/stable/reference/generated/numpy.frompyfunc.html>`_
.. [4] `Rioxarray Manage Information Loss <https://corteva.github.io/rioxarray/stable/getting_started/manage_information_loss.html>`_
.. [5] `Rioxarray NoData Management <https://corteva.github.io/rioxarray/stable/getting_started/nodata_management.html>`_
"""

"""
Expand Down
6 changes: 3 additions & 3 deletions src/gval/comparison/compute_categorical_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def _compute_categorical_metrics(
References
----------
.. [1] [Evaluation of binary classifiers](https://en.wikipedia.org/wiki/Evaluation_of_binary_classifiers)
.. [2] [7th International Verification Methods Workshop](https://www.cawcr.gov.au/projects/verification/#Contingency_table)
.. [3] [3.3. Metrics and scoring: quantifying the quality of predictions](https://scikit-learn.org/stable/modules/model_evaluation.html)
.. [1] `Evaluation of binary classifiers <https://en.wikipedia.org/wiki/Evaluation_of_binary_classifiers>`_
.. [2] `7th International Verification Methods Workshop <https://www.cawcr.gov.au/projects/verification/#Contingency_table>`_
.. [3] `3.3. Metrics and scoring: quantifying the quality of predictions <https://scikit-learn.org/stable/modules/model_evaluation.html>`_
"""

#########################################################################################
Expand Down
4 changes: 2 additions & 2 deletions src/gval/comparison/compute_continuous_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def _compute_continuous_metrics(
References
----------
.. [1] [7th International Verification Methods Workshop](https://www.cawcr.gov.au/projects/verification/)
.. [2] [3.3. Metrics and scoring: quantifying the quality of predictions](https://scikit-learn.org/stable/modules/model_evaluation.html)
.. [1] `7th International Verification Methods Workshop <https://www.cawcr.gov.au/projects/verification/>`_
.. [2] `3.3. Metrics and scoring: quantifying the quality of predictions <https://scikit-learn.org/stable/modules/model_evaluation.html>`_
"""

if not isinstance(agreement_map, list):
Expand Down
10 changes: 5 additions & 5 deletions src/gval/comparison/pairing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def cantor_pair(c: Number, b: Number) -> Number: # pragma: no cover
References
----------
.. [1] [Cantor and Szudzik Pairing Functions](https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik)
.. [1] `Cantor and Szudzik Pairing Functions <https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik>`_
"""
_is_not_natural_number(c, True)
_is_not_natural_number(b, True)
Expand Down Expand Up @@ -111,7 +111,7 @@ def szudzik_pair(c: Number, b: Number) -> Number: # pragma: no cover
References
----------
.. [1] [Cantor and Szudzik Pairing Functions](https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik)
.. [1] `Cantor and Szudzik Pairing Functions <https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik>`_
"""
_is_not_natural_number(c, True)
_is_not_natural_number(b, True)
Expand Down Expand Up @@ -139,7 +139,7 @@ def _negative_value_transformation(x: Number) -> Number: # pragma: no cover
References
----------
.. [1] [Cantor and Szudzik Pairing Functions](https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik)
.. [1] `Cantor and Szudzik Pairing Functions <https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik>`_
"""
if np.isnan(x):
return x
Expand All @@ -166,7 +166,7 @@ def cantor_pair_signed(c: Number, b: Number) -> Number: # pragma: no cover
References
----------
.. [1] [Cantor and Szudzik Pairing Functions](https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik)
.. [1] `Cantor and Szudzik Pairing Functions <https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik>`_
"""
ct = _negative_value_transformation(c)
bt = _negative_value_transformation(b)
Expand Down Expand Up @@ -196,7 +196,7 @@ def szudzik_pair_signed(c: Number, b: Number) -> Number: # pragma: no cover
References
----------
.. [1] [Cantor and Szudzik Pairing Functions](https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik)
.. [1] `Cantor and Szudzik Pairing Functions <https://www.vertexfragment.com/ramblings/cantor-szudzik-pairing-functions/#signed-szudzik>`_
"""
ct = _negative_value_transformation(c)
bt = _negative_value_transformation(b)
Expand Down
6 changes: 3 additions & 3 deletions src/gval/homogenize/spatial_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ def _spatial_alignment(
References
----------
.. [1] [`xr.reproject_match](https://corteva.github.io/rioxarray/stable/rioxarray.html#rioxarray.raster_dataset.RasterDataset.reproject)
.. [2] [`xr.reproject](https://corteva.github.io/rioxarray/stable/rioxarray.html#rioxarray.raster_dataset.RasterDataset.reproject)
.. [2] [`rasterio.warp.reproject](https://rasterio.readthedocs.io/en/latest/api/rasterio.warp.html#rasterio.warp.reproject)
.. [1] `xr.reproject_match <https://corteva.github.io/rioxarray/stable/rioxarray.html#rioxarray.raster_dataset.RasterDataset.reproject>`_
.. [2] `xr.reproject <https://corteva.github.io/rioxarray/stable/rioxarray.html#rioxarray.raster_dataset.RasterDataset.reproject>`_
.. [2] `rasterio.warp.reproject <https://rasterio.readthedocs.io/en/latest/api/rasterio.warp.html#rasterio.warp.reproject>`_
"""

Expand Down
40 changes: 20 additions & 20 deletions src/gval/statistics/categorical_stat_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def true_positive_rate(tp: Number, fn: Number) -> float:
References
----------
.. [1] [Sensitivity and Specificity](https://en.wikipedia.org/wiki/Sensitivity_and_specificity)
.. [1] `Sensitivity and Specificity <https://en.wikipedia.org/wiki/Sensitivity_and_specificity>`_
"""
return tp / (tp + fn)

Expand All @@ -47,7 +47,7 @@ def true_negative_rate(tn: Number, fp: Number) -> float:
References
----------
.. [1] [Sensitivity and Specificity](https://en.wikipedia.org/wiki/Sensitivity_and_specificity)
.. [1] `Sensitivity and Specificity <https://en.wikipedia.org/wiki/Sensitivity_and_specificity>`_
"""
return tn / (tn + fp)

Expand All @@ -70,7 +70,7 @@ def positive_predictive_value(tp: Number, fp: Number) -> float:
References
----------
.. [1] [Sensitivity and Specificity](https://en.wikipedia.org/wiki/Sensitivity_and_specificity)
.. [1] `Sensitivity and Specificity <https://en.wikipedia.org/wiki/Sensitivity_and_specificity>`_
"""
return tp / (tp + fp)

Expand All @@ -93,7 +93,7 @@ def negative_predictive_value(tn: Number, fn: Number) -> float:
References
----------
.. [1] [Sensitivity and Specificity](https://en.wikipedia.org/wiki/Sensitivity_and_specificity)
.. [1] `Sensitivity and Specificity <https://en.wikipedia.org/wiki/Sensitivity_and_specificity>`_
"""
return tn / (tn + fn)

Expand All @@ -116,7 +116,7 @@ def false_negative_rate(tp: Number, fn: Number) -> float:
References
----------
.. [1] [Type I and Type II Errors](https://en.wikipedia.org/wiki/Type_I_and_type_II_errors#False_positive_and_false_negative_rates)
.. [1] `Type I and Type II Error <https://en.wikipedia.org/wiki/Type_I_and_type_II_errors#False_positive_and_false_negative_rates>`_
"""
return fn / (fn + tp)

Expand All @@ -139,7 +139,7 @@ def false_positive_rate(tn: Number, fp: Number) -> float:
References
----------
.. [1] [Type I and Type II Errors](https://en.wikipedia.org/wiki/Type_I_and_type_II_errors#False_positive_and_false_negative_rates)
.. [1] `Type I and Type II Errors <https://en.wikipedia.org/wiki/Type_I_and_type_II_errors#False_positive_and_false_negative_rates>`_
"""
return fp / (fp + tn)

Expand All @@ -162,7 +162,7 @@ def false_discovery_rate(tp: Number, fp: Number) -> float:
References
----------
.. [1] [False Discovery Rate](https://en.wikipedia.org/wiki/False_discovery_rate)
.. [1] `False Discovery Rate <https://en.wikipedia.org/wiki/False_discovery_rate>`_
"""
return fp / (fp + tp)

Expand All @@ -185,7 +185,7 @@ def false_omission_rate(tn: Number, fn: Number) -> float:
References
----------
.. [1] [Positive and Negative Predictive Values](https://en.wikipedia.org/wiki/Positive_and_negative_predictive_values)
.. [1] `Positive and Negative Predictive Values <https://en.wikipedia.org/wiki/Positive_and_negative_predictive_values>`_
"""
return fn / (fn + tn)

Expand All @@ -212,7 +212,7 @@ def positive_likelihood_ratio(tp: Number, tn: Number, fp: Number, fn: Number) ->
References
----------
.. [1] [Likelihood Ratios](https://en.wikipedia.org/wiki/Likelihood_ratios_in_diagnostic_testing#positive_likelihood_ratio)
.. [1] `Likelihood Ratios <https://en.wikipedia.org/wiki/Likelihood_ratios_in_diagnostic_testing#positive_likelihood_ratio>`_
"""
return (tp / (tp + fn)) / (fp / (fp + tn))

Expand All @@ -239,7 +239,7 @@ def negative_likelihood_ratio(tp: Number, tn: Number, fp: Number, fn: Number) ->
References
----------
.. [1] [Likelihood Ratios](https://en.wikipedia.org/wiki/Likelihood_ratios_in_diagnostic_testing#positive_likelihood_ratio)
.. [1] `Likelihood Ratios <https://en.wikipedia.org/wiki/Likelihood_ratios_in_diagnostic_testing#positive_likelihood_ratio>`_
"""
return (fn / (fn + tp)) / (tn / (tn + fp))

Expand All @@ -266,7 +266,7 @@ def prevalence_threshold(tp: Number, tn: Number, fp: Number, fn: Number) -> floa
References
----------
.. [1] [Prevalence Threshold](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7540853/)
.. [1] `Prevalence Threshold <https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7540853/>`_
"""
return math.sqrt(fp / (fp + tn)) / (
math.sqrt(tp / (tp + fn)) + math.sqrt(fp / (fp + tn))
Expand Down Expand Up @@ -295,7 +295,7 @@ def critical_success_index(tp: Number, fp: Number, fn: Number) -> float:
References
----------
.. [1] [Critical Success Index](https://www.swpc.noaa.gov/sites/default/files/images/u30/Forecast%20Verification%20Glossary.pdf#page=4)
.. [1] `Critical Success Index <https://www.swpc.noaa.gov/sites/default/files/images/u30/Forecast%20Verification%20Glossary.pdf#page=4>`_
"""
return tp / (tp + fn + fp)

Expand All @@ -322,7 +322,7 @@ def prevalence(tp: Number, tn: Number, fp: Number, fn: Number) -> float:
References
----------
.. [1] [Prevalence](https://en.wikipedia.org/wiki/Prevalence)
.. [1] `Prevalence <https://en.wikipedia.org/wiki/Prevalence>`_
"""
return (tp + fn) / (tp + fp + tn + fn)

Expand All @@ -349,7 +349,7 @@ def accuracy(tp: Number, tn: Number, fp: Number, fn: Number) -> float:
References
----------
.. [1] [Accuracy and Precision](https://en.wikipedia.org/wiki/Accuracy_and_precision)
.. [1] `Accuracy and Precision <https://en.wikipedia.org/wiki/Accuracy_and_precision>`_
"""
return (tp + tn) / (tp + fp + tn + fn)

Expand All @@ -374,7 +374,7 @@ def f_score(tp: Number, fp: Number, fn: Number) -> float:
References
----------
.. [1] [F-score](https://en.wikipedia.org/wiki/F-score)
.. [1] `F-score <https://en.wikipedia.org/wiki/F-score>`_
"""
return 2 * tp / (2 * tp + fp + fn)

Expand Down Expand Up @@ -404,7 +404,7 @@ def matthews_correlation_coefficient(
References
----------
.. [1] [Matthews Correlation Coefficient](https://en.wikipedia.org/wiki/Phi_coefficient)
.. [1] `Matthews Correlation Coefficient <https://en.wikipedia.org/wiki/Phi_coefficient>`_
"""
return (tp * tn - fp * fn) / math.sqrt(
(tp + fp) * (tp + fn) * (tn + fp) * (tn + fn)
Expand All @@ -431,7 +431,7 @@ def fowlkes_mallows_index(tp: Number, fp: Number, fn: Number) -> float:
References
----------
.. [1] [Fowlkes-Mallows Index](https://en.wikipedia.org/wiki/Fowlkes%E2%80%93Mallows_index)
.. [1] `Fowlkes-Mallows Index <https://en.wikipedia.org/wiki/Fowlkes%E2%80%93Mallows_index>`_
"""
return math.sqrt((tp / (tp + fp)) * (tp / (tp + fn)))

Expand All @@ -458,7 +458,7 @@ def equitable_threat_score(tp: Number, tn: Number, fp: Number, fn: Number) -> fl
References
----------
.. [1] [Equitable Threat Score](https://resources.eumetrain.org/data/4/451/english/msg/ver_categ_forec/uos2/uos2_ko4.htm)
.. [1] `Equitable Threat Score <https://resources.eumetrain.org/data/4/451/english/msg/ver_categ_forec/uos2/uos2_ko4.htm>`_
"""
total_population = tp + tn + fp + fn
Expand Down Expand Up @@ -488,7 +488,7 @@ def balanced_accuracy(tp: Number, tn: Number, fp: Number, fn: Number) -> float:
References
----------
.. [1] [Balanced Accuracy](https://neptune.ai/blog/balanced-accuracy#Balanced%20Accuracy)
.. [1] `Balanced Accuracy <https://neptune.ai/blog/balanced-accuracy#Balanced%20Accuracy>`_
"""

return ((tp / (tp + fn)) + (tn / (tn + fp))) / 2
Expand All @@ -514,7 +514,7 @@ def overall_bias(tp: Number, fp: Number, fn: Number) -> float:
References
----------
.. [1] [Forecast Verification Glossary](https://www.swpc.noaa.gov/sites/default/files/images/u30/Forecast%20Verification%20Glossary.pdf)
.. [1] `Forecast Verification Glossary <https://www.swpc.noaa.gov/sites/default/files/images/u30/Forecast%20Verification%20Glossary.pdf>`_
"""

Expand Down
Loading

0 comments on commit ddd0ff4

Please sign in to comment.