Skip to main content

fuzzy_water

Optical water type classification of reflectance spectra

fuzzy_water sorts remote-sensing reflectance (Rrs) spectra into optical water types (OWTs). It brings together the OC-CCI fuzzy classification code, the CERTO classification toolbox and the earlier fuzzy_water framework, and adds the approaches of Wei et al. (2022), Bi & Hieronymi (2024) and the Forel-Ule colour scale (Wernand et al. 2013).

The package has three parts.

Training data (fuzzy_water.training) makes and reads training data in one standard layout. It reads the Bi & Hieronymi (2024) simulations, the GLORIA hyperspectral data (Lehmann et al. 2023) and the Valente et al. (2022) in situ compilation. It also samples time series of regional Level-3 files, and draws global OC-CCI samples stratified by Longhurst province through seagrid.

Classification (fuzzy_water.classify) holds the classifiers. They all have the same interface, so a class set can be swapped for another without changing the code around it.

Classifier Approach Class sets
MahalanobisClassifier Chi-squared membership of the Mahalanobis distance (Moore et al. 2001, 2009) occci_v5(), 14 types (Jackson et al. 2017)
FuzzyCMeans Fuzzy c-means (Bezdek 1981; Spyrakos et al. 2018), fuzziness from the data (Bi et al. 2019) fitted, or bi2019(), bi2021(), moore2014() (Moore et al. 2014) from FCMm
GaussianMixtureClassifier Gaussian mixture, posterior or chi-squared memberships fitted
SpectralAngleClassifier Cosine of the spectral angle (Wei et al. 2016) wei2022(), 23 types (Wei et al. 2022)
BiHieronymiClassifier AVW, Area and NDI feature space (Bi and Hieronymi 2024) fitted to the published training data
ForelUleClassifier Hue angle (Novoa et al. 2013; Wernand et al. 2013), sensor corrections (Woerd and Wernand 2015) FU 1 to 21
SupervisedClassifier Any scikit-learn classifier, e.g. random forest (Breiman 2001) fitted

Spectra can be screened for unusual shapes with QWIP (Dierssen et al. 2022).

Products (fuzzy_water.products) applies a classifier to gridded data chunk by chunk. It reads Rrs from any seagrid source (OC-CCI by default) and writes one netCDF file of memberships per time step.

A first example

import numpy as np
from fuzzy_water.classify import occci_v5

clf = occci_v5()
rrs = np.array([[0.008, 0.007, 0.005, 0.003, 0.0015, 0.0002],
                [0.002, 0.003, 0.005, 0.006, 0.008, 0.003]])
clf.predict(rrs)
array([ 4., 14.])

The first spectrum is clear blue water and falls in OC-CCI type 4. The second is green and turbid and falls in a high-numbered type. The memberships show how well each spectrum fits each type.

clf.memberships(rrs).round(2)
array([[0.  , 0.04, 0.35, 0.78, 0.44, 0.65, 0.45, 0.3 , 0.11, 0.  , 0.  ,
        0.  , 0.  , 0.  ],
       [0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  , 0.  ,
        0.  , 0.76, 1.  ]])

Installing

The package uses uv.

uv sync                        # the package and the test tools
uv sync --all-extras           # also seagrid, dask, matplotlib and shapely
uv run pytest                  # the tests

See Getting started for the input formats and a tour of the interface.

References

Bezdek, J. C. 1981. Pattern recognition with fuzzy objective function algorithms, Plenum Press.
Bi, S., and M. Hieronymi. 2024. Holistic optical water type classification for ocean, coastal, and inland waters. Limnology and Oceanography. doi:10.1002/lno.12606
Bi, S., Y. Li, J. Xu, and others. 2019. Optical classification of inland waters based on an improved fuzzy c-means method. Optics Express 27: 34838–34856. doi:10.1364/OE.27.034838
Breiman, L. 2001. Random forests. Machine Learning 45: 5–32. doi:10.1023/A:1010933404324
Dierssen, H. M., R. A. Vandermeulen, B. B. Barnes, A. Castagna, E. Knaeps, and Q. Vanhellemont. 2022. QWIP: A quantitative metric for quality control of aquatic reflectance spectral shape using the apparent visible wavelength. Frontiers in Remote Sensing 3: 869611. doi:10.3389/frsen.2022.869611
Jackson, T., S. Sathyendranath, and F. Mélin. 2017. An improved optical classification scheme for the Ocean Colour Essential Climate Variable and its applications. Remote Sensing of Environment 203: 152–161. doi:10.1016/j.rse.2017.03.036
Lehmann, M. K., D. Gurlin, N. Pahlevan, and others. 2023. GLORIA - a globally representative hyperspectral in situ dataset for optical sensing of water quality. Scientific Data 10: 100. doi:10.1038/s41597-023-01973-y
Moore, T. S., J. W. Campbell, and M. D. Dowell. 2009. A class-based approach to characterizing and mapping the uncertainty of the MODIS ocean chlorophyll product. Remote Sensing of Environment 113: 2424–2430. doi:10.1016/j.rse.2009.07.016
Moore, T. S., J. W. Campbell, and H. Feng. 2001. A fuzzy logic classification scheme for selecting and blending satellite ocean color algorithms. IEEE Transactions on Geoscience and Remote Sensing 39: 1764–1776. doi:10.1109/36.942555
Moore, T. S., M. D. Dowell, S. Bradt, and A. Ruiz Verdu. 2014. An optical water type framework for selecting and blending retrievals from bio-optical algorithms in lakes and coastal waters. Remote Sensing of Environment 143: 97–111. doi:10.1016/j.rse.2013.11.021
Novoa, S., M. R. Wernand, and H. J. van der Woerd. 2013. The Forel-Ule scale revisited spectrally: Preparation protocol, transmission measurements and chromaticity. Journal of the European Optical Society: Rapid Publications 8: 13057. doi:10.2971/jeos.2013.13057
Spyrakos, E., R. O’Donnell, P. D. Hunter, and others. 2018. Optical types of inland and coastal waters. Limnology and Oceanography 63: 846–870. doi:10.1002/lno.10674
Valente, A., S. Sathyendranath, V. Brotas, and others. 2022. A compilation of global bio-optical in situ data for ocean colour satellite applications, version three. Earth System Science Data 14: 5737–5770. doi:10.5194/essd-14-5737-2022
Wei, J. and others. 2022. Global satellite water classification data products over oceanic, coastal, and inland waters. Remote Sensing of Environment 282: 113233. doi:10.1016/j.rse.2022.113233
Wei, J., Z. Lee, and S. Shang. 2016. A system to measure the data quality of spectral remote sensing reflectance of aquatic environments. Journal of Geophysical Research: Oceans 121: 8189–8207. doi:10.1002/2016JC012126
Wernand, M. R., A. Hommersom, and H. J. van der Woerd. 2013. MERIS-based ocean colour classification with the discrete Forel-Ule scale. Ocean Science 9: 477–487. doi:10.5194/os-9-477-2013
Woerd, H. J. van der, and M. R. Wernand. 2015. True colour classification of natural waters with medium-spectral resolution satellites: SeaWiFS, MODIS, MERIS and OLCI. Sensors 15: 25663–25680. doi:10.3390/s151025663