From 624a5bdcd4ca32f2a3f6841dea1b3ac85dba2057 Mon Sep 17 00:00:00 2001 From: DXC Date: Tue, 9 Jun 2026 11:24:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(water=5Findex):=20=E7=94=A8=20waterind?= =?UTF-8?q?ex.csv=20=E9=A9=B1=E5=8A=A8=E5=85=AC=E5=BC=8F=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=EF=BC=8C=E7=A7=BB=E9=99=A4=2045=20=E4=B8=AA=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gui/model/waterindex.csv | 92 +-- src/utils/band_math.py | 114 ++-- src/utils/water_index.py | 1026 +++++++--------------------------- 3 files changed, 314 insertions(+), 918 deletions(-) diff --git a/src/gui/model/waterindex.csv b/src/gui/model/waterindex.csv index 0dfee5f..a91b73a 100644 --- a/src/gui/model/waterindex.csv +++ b/src/gui/model/waterindex.csv @@ -1,46 +1,46 @@ -Formula_Name,Category,Formula,Reference -BGA_Am09KBBI,Phycocyanin (BGA_PC),(w686 - w658) / (w686 + w658),"Amin, R.; Zhou, J.; Gilerson, A.; Gross, B.; Moshary, F.; Ahmed, S.; Novel optical techniques for detecting and classifying toxic dinoflagellate Karenia brevis blooms using satellite imagery, Optics Express, 2009, 17, 11, 1-13." -BGA_Be162B643sub629,Phycocyanin (BGA_PC),w644 - w629,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538." -BGA_Be162B700sub601,Phycocyanin (BGA_PC),w700 - w601,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539." -BGA_Be162BsubPhy,Phycocyanin (BGA_PC),w715 - w615,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 540." -BGA_Be16FLHBlueRedNIR,Phycocyanin (BGA_PC),w658 - (w857 + (w458 - w857)),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538." -BGA_Be16FLHGreenRedNIR,Phycocyanin (BGA_PC),w658 - (w857 + (w558 - w857)),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539." -BGA_Be16FLHVioletRedNIR,Phycocyanin (BGA_PC),w658 - (w857 + (w444 - w857)),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538." -BGA_Be16MPI,Phycocyanin (BGA_PC),(w615 - w601) - (w644 - w601),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539." -BGA_Be16NDPhyI,Phycocyanin (BGA_PC),(w700 - w622) / (w700 + w622),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 540." -BGA_Be16NDPhyI644over615,Phycocyanin (BGA_PC),(w644 - w615) / (w644 + w615),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 541." -BGA_Be16NDPhyI644over629,Phycocyanin (BGA_PC),(w644 - w629) / (w644 + w629),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 542." -BGA_Be16Phy2BDA644over629,Phycocyanin (BGA_PC),w644 / w629,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 545." -BGA_Da052BDA,Phycocyanin (BGA_PC),w714 / w672,"Wynne, T. T., Stumpf, R. P., Tomlinson, M. C., Warner, R. A., Tester, P. A., Dyble, J.; Relating spectral shape to cyanobacterial blooms in the Laurentian Great Lakes. Int. J. Remote Sens., 2008, 29, 3665-3672." -BGA_Go04MCI,Phycocyanin (BGA_PC),w709 - w681 - (w753 - w681),"Gower, J.F.R.; Brown,L.; Borstad, G.A.; Observation of chlorophyll fluorescence in west coast waters of Canada using the MODIS satellite sensor. Can. J. Remote Sens., 2004, 30 (1), 17闁?5." -BGA_HU103BDA,Phycocyanin (BGA_PC),(((1 / w615) - (1 / w600)) - w725),"Hunter, P.D.; Tyler, A.N.; Willby, N.J.; Gilvear, D.J.; The spatial dynamics of vertical migration by Microcystis aeruginosa in a eutrophic shallow lake: A case study using high spatial resolution time-series airborne remote sensing. Limn. Oceanogr. 2008, 53, 2391-2406" -BGA_Ku15PhyCI,Phycocyanin (BGA_PC),(-1 * (W681 - W665 - (W709 - W665))),"Kudela, R.M., Palacios, S.L., Austerberry, D.C., Accorsi, E.K., Guild, L.S.; Application of hyperspectral remote sensing to cyanobacterial blooms in inland waters, Torres-Perez, J., 2015, Remote Sens. Environ., 2015, 167, 1-10." -BGA_Ku15SLH,Phycocyanin (BGA_PC),(w715 - w658) + (w715 - w658),"Kudela, R.M., Palacios, S.L., Austerberry, D.C., Accorsi, E.K., Guild, L.S.; Application of hyperspectral remote sensing to cyanobacterial blooms in inland waters, Torres-Perez, J., 2015, Remote Sens. Environ., 2015, 167, 1-11." -BGA_MI092BDA,Phycocyanin (BGA_PC),w700 / w600,"Mishra, S.; Mishra, D.R.; Schluchter, W. M., A novel algorithm for predicting PC concentrations in cyanobacteria: A proximal hyperspectral remote sensing approach. Remote Sens., 2009, 1, 758闁?75." -BGA_MM092BDA,Phycocyanin (BGA_PC),w724 / w600,"Mishra, S.; Mishra, D.R.; Schluchter, W. M., A novel algorithm for predicting PC concentrations in cyanobacteria: A proximal hyperspectral remote sensing approach. Remote Sens., 2009, 1, 758闁?76." -BGA_MM12NDCIalt,Phycocyanin (BGA_PC),(w700 - w658) / (w700 + w658),"Mishra, S.; Mishra, D.R.; A novel remote sensing algorithm to quantify phycocyanin in cyanobacterial algal blooms, Env. Res. Lett., 2014, 9 (11), DOI:10.1088/1748-9326/9/11/114003" -BGA_MM143BDAopt,Phycocyanin (BGA_PC),((1 / w629) - (1 / w659)) * w724,"Mishra, S.; Mishra, D.R.; A novel remote sensing algorithm to quantify phycocyanin in cyanobacterial algal blooms, Env. Res. Lett., 2014, 9 (11), DOI:10.1088/1748-9326/9/11/114004" -BGA_SI052BDA,Phycocyanin (BGA_PC),w709 / w620,"Simis, S. G. H.; Peters, S.W. M.; Gons, H. J.; Remote sensing of the cyanobacteria pigment phycocyanin in turbid inland water. Limn. Oceanogr., 2005, 50, 237闁?45" -BGA_SM122BDA,Phycocyanin (BGA_PC),w709 / w600,"Mishra, S. Remote sensing of cyanobacteria in turbid productive waters, PhD Dissertation. Mississippi State University, USA. 2012." -BGA_SY002BDA,Phycocyanin (BGA_PC),w650 / w625,"Schalles, J.; Yacobi, Y. Remote detection and seasonal patterns of phycocyanin, carotenoid and chlorophyll-a pigments in eutrophic waters. Archiv fur Hydrobiologie, Special Issues Advances in Limnology, 2000, 55,153闁?68" -BGA_Wy08CI,Phycocyanin (BGA_PC),(-1 * (W686 - W672 - (W715 - W672))),"Wynne, T. T., Stumpf, R. P., Tomlinson, M. C., Warner, R. A., Tester, P. A., Dyble, J.; Relating spectral shape to cyanobacterial blooms in the Laurentian Great Lakes. Int. J. Remote Sens., 2008, 29, 3665-3672." -Chl_Al10SABI,chlorophyll_a,(w857 - w644) / (w458 + w529),"Alawadi, F. Detection of surface algal blooms using the newly developed algorithm surface algal bloom index (SABI). Proc. SPIE 2010, 7825." -Chl_Am092Bsub,chlorophyll_a,w681 - w665,"Amin, R.; Zhou, J.; Gilerson, A.; Gross, B.; Moshary, F.; Ahmed, S. Novel optical techniques for detecting and classifying toxic dinoflagellate Karenia brevis blooms using satellite imagery. Opt. Express 2009, 17, 9126闁?144." -Chl_Be16FLHblue,chlorophyll_a,w529 - (w644 + (w458 - w644)),"Beck, R.A. and 22 others; Comparison of satellite reflectance algorithms for estimating chlorophyll-a in a temperate reservoir using coincident hyperspectral aircraft imagery and dense coincident surface observations, Remote Sens. Environ., 2016, 178, 15-30." -Chl_Be16FLHviolet,chlorophyll_a,w529 - (w644 + (w429 - w644)),"Beck, R.A. and 22 others; Comparison of satellite reflectance algorithms for estimating chlorophyll-a in a temperate reservoir using coincident hyperspectral aircraft imagery and dense coincident surface observations, Remote Sens. Environ., 2016, 178, 15-30." -Chl_Be16NDTIblue,chlorophyll_a,(w658 - w458) / (w658 + w458),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 543." -Chl_Be16NDTIviolet,chlorophyll_a,(w658 - w444) / (w658 + w444),"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 544." -Chl_De933BDA,chlorophyll_a,w600 - w648 - w625,"Dekker, A.; Detection of the optical water quality parameters for eutrophic waters by high resolution remote sensing, Ph.D. thesis, 1993, Free University, Amsterdam." -Chl_Gi033BDA,chlorophyll_a,((1 / w672) - (1 / w715)) * w757,"Gitelson, A.A.; U. Gritz, and M. N. Merzlyak.; Relationships between leaf chlorophyll content and spectral reflectance and algorithms for non-destructive chlorophyll assessment in higher plant leaves. J. Plant Phys. 2003, 160, 271-282." -Chl_Kn07KIVU,chlorophyll_a,(w458 - w644) / w529,"Kneubuhler, M.; Frank T.; Kellenberger, T.W; Pasche N.; Schmid M.; Mapping chlorophyll-a in Lake Kivu with remote sensing methods. 2007, Proceedings of the Envisat Symposium 2007, Montreux, Switzerland 23闁?7 April 2007 (ESA SP-636, July 2007)." -Chl_MM12NDCI,chlorophyll_a,(w715 - w686) / (w715 + w686),"Mishra, S.; and Mishra, D.R. Normalized difference chlorophyll index: A novel model for remote estimation of chlorophyll-a concentration in turbid productive waters, Remote Sens. Environ., 2012, 117, 394-406" -Chl_Zh10FLH,chlorophyll_a,w686 - (w715 + (w672 - w751)),"Zhao, D.Z.; Xing, X.G.; Liu, Y.G.; Yang, J.H.; Wang, L. The relation of chlorophyll-a concentration with the reflectance peak near 700 nm in algae-dominated waters and sensitivity of fluorescence algorithms for detecting algal bloom. Int. J. Remote Sens. 2010, 31, 39-48" -Turb_Be16GreenPlusRedBothOverViolet,Turbidity,(w558 + w658) / w444,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538" -Turb_Be16RedOverViolet,Turbidity,w658 / w444,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539" -Turb_Bow06RedOverGreen,Turbidity,w658 / w558,"Bowers, D. G., and C. E. Binding. 2006. 闁炽儲缈籬e Optical Properties of Mineral Suspended Particles: A Review and Synthesis.闁?Estuarine Coastal and Shelf Science 67 (1闁?): 219闁?30. doi:10.1016/j.ecss.2005.11.010" -Turb_Chip09NIROverGreen,Turbidity,w857 / w558,"Chipman, J. W.; Olmanson, L.G.; Gitelson, A.A.; Remote sensing methods for lake management: A guide for resource managers and decision-makers. 2009." -Turb_Dox02NIRoverRed,Turbidity,w857 / w658,"Doxaran, D., Froidefond, J.-M.; Castaing, P. ; A reflectance band ratio used to estimate suspended matter concentrations in sediment-dominated coastal waters, Remote Sens., 2002, 23, 5079-5085" -Turb_Frohn09GreenPlusRedBothOverBlue,Turbidity,(w558 + w658) / w458,"Frohn, R. C., & Autrey, B. C. (2009). Water quality assessment in the Ohio River using new indices for turbidity and chlorophyll-a with Landsat-7 Imagery. Draft Internal Report, US Environmental Protection Agency." -Turb_Harr92NIR,Turbidity,w857,"Schiebe F.R., Harrington J.A., Ritchie J.C. Remote-Sensing of Suspended Sediments闁炽儲鏁刪e Lake Chicot, Arkansas Project. Int. J. Remote Sens. 1992;13:1487闁?509" -Turb_Lath91RedOverBlue,Turbidity,w658 / w458,"Lathrop, R. G., Jr., T. M. Lillesand, and B. S. Yandell, 1991. Testing the utility of simple multi-date Thematic Mapper calibration algorithms for monitoring turbid inland waters. International Journal of Remote Sensing" -Turb_Moore80Red,Turbidity,w658,"Moore, G.K., Satellite remote sensing of water turbidity, Hydrological Sciences, 1980, 25, 4, 407-422" +Formula_Name,Category,Formula_Type,Formula,Coefficient,Reference +BGA_Am09KBBI,Phycocyanin (BGA_PC),ratio,(w686 - w658) / (w686 + w658),1.0,"Amin, R.; Zhou, J.; Gilerson, A.; Gross, B.; Moshary, F.; Ahmed, S.; Novel optical techniques for detecting and classifying toxic dinoflagellate Karenia brevis blooms using satellite imagery, Optics Express, 2009, 17, 11, 1-13." +BGA_Be162B643sub629,Phycocyanin (BGA_PC),ratio,w644 - w629,1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538." +BGA_Be162B700sub601,Phycocyanin (BGA_PC),ratio,w700 - w601,1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539." +BGA_Be162BsubPhy,Phycocyanin (BGA_PC),ratio,w715 - w615,1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 540." +BGA_Be16FLHBlueRedNIR,Phycocyanin (BGA_PC),ratio,w658 - (w857 + (w458 - w857)),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538." +BGA_Be16FLHGreenRedNIR,Phycocyanin (BGA_PC),ratio,w658 - (w857 + (w558 - w857)),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539." +BGA_Be16FLHVioletRedNIR,Phycocyanin (BGA_PC),ratio,w658 - (w857 + (w444 - w857)),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538." +BGA_Be16MPI,Phycocyanin (BGA_PC),ratio,(w615 - w601) - (w644 - w601),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539." +BGA_Be16NDPhyI,Phycocyanin (BGA_PC),ratio,(w700 - w622) / (w700 + w622),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 540." +BGA_Be16NDPhyI644over615,Phycocyanin (BGA_PC),ratio,(w644 - w615) / (w644 + w615),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 541." +BGA_Be16NDPhyI644over629,Phycocyanin (BGA_PC),ratio,(w644 - w629) / (w644 + w629),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 542." +BGA_Be16Phy2BDA644over629,Phycocyanin (BGA_PC),ratio,w644 / w629,1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 545." +BGA_Da052BDA,Phycocyanin (BGA_PC),ratio,w714 / w672,1.0,"Wynne, T. T., Stumpf, R. P., Tomlinson, M. C., Warner, R. A., Tester, P. A., Dyble, J.; Relating spectral shape to cyanobacterial blooms in the Laurentian Great Lakes. Int. J. Remote Sens., 2008, 29, 3665-3672." +BGA_Go04MCI,Phycocyanin (BGA_PC),ratio,w709 - w681 - (w753 - w681),1.0,"Gower, J.F.R.; Brown,L.; Borstad, G.A.; Observation of chlorophyll fluorescence in west coast waters of Canada using the MODIS satellite sensor. Can. J. Remote Sens., 2004, 30 (1), 17-25." +BGA_HU103BDA,Phycocyanin (BGA_PC),ratio,(((1 / w615) - (1 / w600)) - w725),1.0,"Hunter, P.D.; Tyler, A.N.; Willby, N.J.; Gilvear, D.J.; The spatial dynamics of vertical migration by Microcystis aeruginosa in a eutrophic shallow lake: A case study using high spatial resolution time-series airborne remote sensing. Limn. Oceanogr. 2008, 53, 2391-2406" +BGA_Ku15PhyCI,Phycocyanin (BGA_PC),ratio,(-1 * (W681 - W665 - (W709 - W665))),1.0,"Kudela, R.M., Palacios, S.L., Austerberry, D.C., Accorsi, E.K., Guild, L.S.; Application of hyperspectral remote sensing to cyanobacterial blooms in inland waters, Torres-Perez, J., 2015, Remote Sens. Environ., 2015, 167, 1-10." +BGA_Ku15SLH,Phycocyanin (BGA_PC),ratio,(w715 - w658) + (w715 - w658),1.0,"Kudela, R.M., Palacios, S.L., Austerberry, D.C., Accorsi, E.K., Guild, L.S.; Application of hyperspectral remote sensing to cyanobacterial blooms in inland waters, Torres-Perez, J., 2015, Remote Sens. Environ., 2015, 167, 1-11." +BGA_MI092BDA,Phycocyanin (BGA_PC),ratio,w700 / w600,1.0,"Mishra, S.; Mishra, D.R.; Schluchter, W. M., A novel algorithm for predicting PC concentrations in cyanobacteria: A proximal hyperspectral remote sensing approach. Remote Sens., 2009, 1, 758-775." +BGA_MM092BDA,Phycocyanin (BGA_PC),ratio,w724 / w600,1.0,"Mishra, S.; Mishra, D.R.; Schluchter, W. M., A novel algorithm for predicting PC concentrations in cyanobacteria: A proximal hyperspectral remote sensing approach. Remote Sens., 2009, 1, 758-776." +BGA_MM12NDCIalt,Phycocyanin (BGA_PC),ratio,(w700 - w658) / (w700 + w658),1.0,"Mishra, S.; Mishra, D.R.; A novel remote sensing algorithm to quantify phycocyanin in cyanobacterial algal blooms, Env. Res. Lett., 2014, 9 (11), DOI:10.1088/1748-9326/9/11/114003" +BGA_MM143BDAopt,Phycocyanin (BGA_PC),ratio,((1 / w629) - (1 / w659)) * w724,1.0,"Mishra, S.; Mishra, D.R.; A novel remote sensing algorithm to quantify phycocyanin in cyanobacterial algal blooms, Env. Res. Lett., 2014, 9 (11), DOI:10.1088/1748-9326/9/11/114004" +BGA_SI052BDA,Phycocyanin (BGA_PC),ratio,w709 / w620,1.0,"Simis, S. G. H.; Peters, S.W. M.; Gons, H. J.; Remote sensing of the cyanobacteria pigment phycocyanin in turbid inland water. Limn. Oceanogr., 2005, 50, 237-245" +BGA_SM122BDA,Phycocyanin (BGA_PC),ratio,w709 / w600,1.0,"Mishra, S. Remote sensing of cyanobacteria in turbid productive waters, PhD Dissertation. Mississippi State University, USA. 2012." +BGA_SY002BDA,Phycocyanin (BGA_PC),ratio,w650 / w625,1.0,"Schalles, J.; Yacobi, Y. Remote detection and seasonal patterns of phycocyanin, carotenoid and chlorophyll-a pigments in eutrophic waters. Archiv fur Hydrobiologie, Special Issues Advances in Limnology, 2000, 55,153-168" +BGA_Wy08CI,Phycocyanin (BGA_PC),ratio,(-1 * (W686 - W672 - (W715 - W672))),1.0,"Wynne, T. T., Stumpf, R. P., Tomlinson, M. C., Warner, R. A., Tester, P. A., Dyble, J.; Relating spectral shape to cyanobacterial blooms in the Laurentian Great Lakes. Int. J. Remote Sens., 2008, 29, 3665-3672." +Chl_Al10SABI,chlorophyll_a,ratio,(w857 - w644) / (w458 + w529),1.0,"Alawadi, F. Detection of surface algal blooms using the newly developed algorithm surface algal bloom index (SABI). Proc. SPIE 2010, 7825." +Chl_Am092Bsub,chlorophyll_a,ratio,w681 - w665,1.0,"Amin, R.; Zhou, J.; Gilerson, A.; Gross, B.; Moshary, F.; Ahmed, S. Novel optical techniques for detecting and classifying toxic dinoflagellate Karenia brevis blooms using satellite imagery. Opt. Express 2009, 17, 9126-9144." +Chl_Be16FLHblue,chlorophyll_a,ratio,w529 - (w644 + (w458 - w644)),1.0,"Beck, R.A. and 22 others; Comparison of satellite reflectance algorithms for estimating chlorophyll-a in a temperate reservoir using coincident hyperspectral aircraft imagery and dense coincident surface observations, Remote Sens. Environ., 2016, 178, 15-30." +Chl_Be16FLHviolet,chlorophyll_a,ratio,w529 - (w644 + (w429 - w644)),1.0,"Beck, R.A. and 22 others; Comparison of satellite reflectance algorithms for estimating chlorophyll-a in a temperate reservoir using coincident hyperspectral aircraft imagery and dense coincident surface observations, Remote Sens. Environ., 2016, 178, 15-30." +Chl_Be16NDTIblue,chlorophyll_a,ratio,(w658 - w458) / (w658 + w458),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 543." +Chl_Be16NDTIviolet,chlorophyll_a,ratio,(w658 - w444) / (w658 + w444),1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 544." +Chl_De933BDA,chlorophyll_a,ratio,w600 - w648 - w625,1.0,"Dekker, A.; Detection of the optical water quality parameters for eutrophic waters by high resolution remote sensing, Ph.D. thesis, 1993, Free University, Amsterdam." +Chl_Gi033BDA,chlorophyll_a,ratio,((1 / w672) - (1 / w715)) * w757,1.0,"Gitelson, A.A.; U. Gritz, and M. N. Merzlyak.; Relationships between leaf chlorophyll content and spectral reflectance and algorithms for non-destructive chlorophyll assessment in higher plant leaves. J. Plant Phys. 2003, 160, 271-282." +Chl_Kn07KIVU,chlorophyll_a,ratio,(w458 - w644) / w529,1.0,"Kneubuhler, M.; Frank T.; Kellenberger, T.W; Pasche N.; Schmid M.; Mapping chlorophyll-a in Lake Kivu with remote sensing methods. 2007, Proceedings of the Envisat Symposium 2007, Montreux, Switzerland 23-27 April 2007 (ESA SP-636, July 2007)." +Chl_MM12NDCI,chlorophyll_a,ratio,(w715 - w686) / (w715 + w686),1.0,"Mishra, S.; and Mishra, D.R. Normalized difference chlorophyll index: A novel model for remote estimation of chlorophyll-a concentration in turbid productive waters, Remote Sens. Environ., 2012, 117, 394-406" +Chl_Zh10FLH,chlorophyll_a,ratio,w686 - (w715 + (w672 - w751)),1.0,"Zhao, D.Z.; Xing, X.G.; Liu, Y.G.; Yang, J.H.; Wang, L. The relation of chlorophyll-a concentration with the reflectance peak near 700 nm in algae-dominated waters and sensitivity of fluorescence algorithms for detecting algal bloom. Int. J. Remote Sens. 2010, 31, 39-48" +Turb_Be16GreenPlusRedBothOverViolet,Turbidity,ratio,(w558 + w658) / w444,1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538" +Turb_Be16RedOverViolet,Turbidity,ratio,w658 / w444,1.0,"Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539" +Turb_Bow06RedOverGreen,Turbidity,ratio,w658 / w558,1.0,"Bowers, D. G., and C. E. Binding. 2006. The Optical Properties of Mineral Suspended Particles: A Review and Synthesis. Estuarine Coastal and Shelf Science 67 (1-2): 219-230. doi:10.1016/j.ecss.2005.11.010" +Turb_Chip09NIROverGreen,Turbidity,ratio,w857 / w558,1.0,"Chipman, J. W.; Olmanson, L.G.; Gitelson, A.A.; Remote sensing methods for lake management: A guide for resource managers and decision-makers. 2009." +Turb_Dox02NIRoverRed,Turbidity,ratio,w857 / w658,1.0,"Doxaran, D., Froidefond, J.-M.; Castaing, P. ; A reflectance band ratio used to estimate suspended matter concentrations in sediment-dominated coastal waters, Remote Sens., 2002, 23, 5079-5085" +Turb_Frohn09GreenPlusRedBothOverBlue,Turbidity,ratio,(w558 + w658) / w458,1.0,"Frohn, R. C., & Autrey, B. C. (2009). Water quality assessment in the Ohio River using new indices for turbidity and chlorophyll-a with Landsat-7 Imagery. Draft Internal Report, US Environmental Protection Agency." +Turb_Harr92NIR,Turbidity,ratio,w857,1.0,"Schiebe F.R., Harrington J.A., Ritchie J.C. Remote-Sensing of Suspended Sediments-the Lake Chicot, Arkansas Project. Int. J. Remote Sens. 1992;13:1487-1509" +Turb_Lath91RedOverBlue,Turbidity,ratio,w658 / w458,1.0,"Lathrop, R. G., Jr., T. M. Lillesand, and B. S. Yandell, 1991. Testing the utility of simple multi-date Thematic Mapper calibration algorithms for monitoring turbid inland waters. International Journal of Remote Sensing" +Turb_Moore80Red,Turbidity,ratio,w658,1.0,"Moore, G.K., Satellite remote sensing of water turbidity, Hydrological Sciences, 1980, 25, 4, 407-422" \ No newline at end of file diff --git a/src/utils/band_math.py b/src/utils/band_math.py index 8e20a9d..ffdb166 100644 --- a/src/utils/band_math.py +++ b/src/utils/band_math.py @@ -134,81 +134,103 @@ class BandMathCalculator: print(f"第 {i} 行计算失败,使用NaN填充") return results + def _parse_coeff(self, coeff_str: str) -> np.ndarray: + """ + 将 Coefficient 字符串解析为 numpy 多项式系数数组。 + + - "1.0" → [1.0] + - "a,b,c" → [a, b, c] (多项式,从高次到低次,供 np.polyval 直接使用) + - "1.0,2.0" → [1.0, 2.0] (线性 y = a*x + b) + """ + s = str(coeff_str).strip() if not pd.isna(coeff_str) else "" + if s in ("", "nan", "None"): + return np.array([1.0]) + parts = [float(x.strip()) for x in s.split(",")] + return np.array(parts) + def process_formulas_from_csv(self, formula_csv_file, formula_names=None, output_file=None): """ - 从公式CSV文件中批量计算并添加到数据文件中 - + 从公式CSV文件中批量计算并添加到数据文件中。 + + 支持两种 CSV 格式: + - 新版(6列):Formula_Name, Category, Formula_Type, Formula, Coefficient, Reference + - 旧版(≥3列):第一列=公式名,第三列=表达式(兼容处理) + + Formula_Type 为 'concentration' 时,计算比值后额外通过 np.polyval 应用 Coefficient。 + 参数: - formula_csv_file: 公式CSV文件路径,第一列为公式名称,第三列为具体公式 + formula_csv_file: 公式CSV文件路径 formula_names: 要计算的公式名称列表,如果为None则计算所有公式 output_file: 输出文件路径,如果为None则自动生成 - + 返回: 包含计算结果的新DataFrame """ - # 读取公式CSV文件 try: formulas_df = pd.read_csv(formula_csv_file) print(f"读取到 {len(formulas_df)} 个公式") - - # 检查CSV格式,假设第一列为公式名称,第三列为具体公式 - if len(formulas_df.columns) < 3: - raise ValueError("公式CSV文件需要至少3列") - - formula_name_col = formulas_df.columns[0] # 第一列:公式名称 - formula_expr_col = formulas_df.columns[2] # 第三列:具体公式 - - # 创建结果DataFrame的副本 + + has_new_format = set(["Formula_Name", "Formula_Type", "Formula", "Coefficient"]).issubset( + set(formulas_df.columns) + ) + + if has_new_format: + name_col = "Formula_Name" + type_col = "Formula_Type" + expr_col = "Formula" + coeff_col = "Coefficient" + else: + name_col = formulas_df.columns[0] + type_col = None + expr_col = formulas_df.columns[2] + coeff_col = None + result_df = self.df.copy() - - # 如果指定了公式名称,则只计算这些公式 + if formula_names is not None: if isinstance(formula_names, str): - formula_names = [formula_names] # 转换为列表 - - # 筛选出指定的公式 - selected_formulas = formulas_df[formulas_df[formula_name_col].isin(formula_names)] - print(f"找到 {len(selected_formulas)} 个指定的公式") - - if len(selected_formulas) == 0: - print(f"警告: 未找到指定的公式: {formula_names}") + formula_names = [formula_names] + selected = formulas_df[formulas_df[name_col].isin(formula_names)] + print(f"找到 {len(selected)} 个指定公式") + if len(selected) == 0: + print(f"警告: 未找到指定公式: {formula_names}") return result_df - - formulas_to_process = selected_formulas + formulas_to_process = selected else: - # 计算所有公式 formulas_to_process = formulas_df - - # 为每个公式计算所有行 + for _, row in formulas_to_process.iterrows(): - formula_name = row[formula_name_col] - formula_expr = row[formula_expr_col] - + formula_name = row[name_col] + formula_expr = row[expr_col] + if pd.isna(formula_name) or pd.isna(formula_expr): - print(f"跳过空公式: {row}") + print(f"跳过空公式: {row.to_dict()}") continue - - print(f"\n计算公式: {formula_name} = {formula_expr}") - - # 计算所有行的结果 + + ftype = str(row[type_col]).strip().lower() if type_col and not pd.isna(row.get(type_col)) else "ratio" + coeff_str = str(row[coeff_col]).strip() if coeff_col and not pd.isna(row.get(coeff_col)) else "1.0" + + print(f"\n计算公式: {formula_name} = {formula_expr} [type={ftype}, coeff={coeff_str}]") + results = self.calculate_all_rows(formula_expr) - - # 将结果添加到DataFrame + + if ftype == "concentration": + coeff = self._parse_coeff(coeff_str) + results = np.polyval(coeff, np.array(results)) + result_df[formula_name] = results - print(f"公式 '{formula_name}' 计算完成,添加到数据中") - - # 保存结果 + print(f"公式 '{formula_name}' 计算完成") + if output_file is None: - # 自动生成输出文件名 import os base_name = os.path.splitext(os.path.basename(formula_csv_file))[0] output_file = f"band_math_results_{base_name}.csv" - + result_df.to_csv(output_file, index=False) print(f"结果已保存到: {output_file}") - + return result_df - + except Exception as e: print(f"处理公式CSV文件时出错: {e}") import traceback diff --git a/src/utils/water_index.py b/src/utils/water_index.py index 00ba9af..57d3279 100644 --- a/src/utils/water_index.py +++ b/src/utils/water_index.py @@ -1,861 +1,235 @@ - +import os +import sys import pandas as pd import numpy as np import re +from pathlib import Path from typing import Dict, List, Optional, Union +from .band_math import BandMathCalculator + + +def _get_resource_path(relative_path: str) -> str: + """获取资源文件路径,兼容开发/PyInstaller onedir/onefile 三种环境。""" + if hasattr(sys, '_MEIPASS'): + internal = os.path.join(sys._MEIPASS, '_internal', relative_path) + if os.path.exists(internal): + return internal + return os.path.join(sys._MEIPASS, relative_path) + + exe_dir = os.path.dirname(sys.executable) + internal = os.path.join(exe_dir, '_internal', relative_path) + if os.path.exists(internal): + return internal + + base_dir = Path(__file__).resolve().parent.parent / "gui" / "model" + target = base_dir / os.path.basename(relative_path) + return str(target) + + class WaterQualityIndexCalculator: """ - 水质光谱指数计算器 - 为每个算法创建单独的函数,自动查找最接近的波长列 + 水质光谱指数计算器(CSV驱动架构) + 所有算法公式由 waterindex.csv 配置,不再硬编码。 + 支持两种 Formula_Type: + - ratio :直接使用 BandMathCalculator 计算比值结果 + - concentration:先用 BandMathCalculator 计算比值,再通过 np.polyval 应用 Coefficient 多项式系数 """ - - def __init__(self): - self.references = {} - - def find_closest_wavelength(self, df_columns: List[str], target_wl: int) -> str: + + DEFAULT_CSV = "waterindex.csv" + + def __init__(self, csv_path: Optional[str] = None): """ - 在数据框列名中查找最接近目标波长的列 - + 初始化时加载 waterindex.csv 并缓存为字典。 + Args: - df_columns: 数据框的所有列名 - target_wl: 目标波长 - + csv_path: 可选,指定公式CSV路径;默认使用内置 waterindex.csv + """ + if csv_path is None: + csv_path = _get_resource_path(self.DEFAULT_CSV) + + self._csv_path = csv_path + self._df_cfg: pd.DataFrame = pd.read_csv(csv_path) + + self._formula_cache: Dict[str, Dict] = {} + self._build_cache() + + def _build_cache(self): + """将 CSV 配置缓存为 {Formula_Name: {Type, Formula, Coeff}} 字典。""" + required_cols = {"Formula_Name", "Category", "Formula_Type", "Formula", "Coefficient", "Reference"} + missing = required_cols - set(self._df_cfg.columns) + if missing: + raise ValueError(f"waterindex.csv 缺少列: {missing}") + + for _, row in self._df_cfg.iterrows(): + name = row["Formula_Name"] + self._formula_cache[name] = { + "category": str(row["Category"]), + "type": str(row["Formula_Type"]).strip().lower(), + "formula": str(row["Formula"]), + "coeff": str(row["Coefficient"]).strip(), + "reference": str(row["Reference"]), + } + + def _parse_coeff(self, coeff_str: str) -> np.ndarray: + """ + 将 Coefficient 字符串解析为 numpy 多项式系数数组。 + + - "1.0" → [1.0] (恒等变换,等同于乘 1) + - "a,b,c" → [a, b, c] (多项式系数,从高次到低次) + - "1.0,2.0" → [1.0, 2.0] (线性 y = a*x + b) + - "0.5" → [0.5] (标量缩放) + Returns: - 最接近的列名 + numpy 数组,系数从高次到低次排列(polyval 直接接收此格式) """ - # 提取所有数值型波长 - numeric_wavelengths = [] - for col in df_columns: + s = coeff_str.strip() + if s in ("", "nan", "None"): + return np.array([1.0]) + + parts = [float(x.strip()) for x in s.split(",")] + return np.array(parts) + + def _band_math_all_rows(self, df: pd.DataFrame, expression: str) -> pd.Series: + """ + 使用 BandMathCalculator 的公式计算引擎,在整个 DataFrame 上批量求值。 + + Args: + df: 输入光谱数据(列名为 wNNN 格式) + expression: 波段计算表达式,如 "(w715 - w686) / (w715 + w686)" + + Returns: + pd.Series,与 df 等长的计算结果 + """ + calc = BandMathCalculator.__new__(BandMathCalculator) + calc.df = df.copy() + calc.wavelengths = calc._extract_wavelengths() + + variables = calc._parse_expression(expression) + results = [] + for i in range(len(calc.df)): + sub_dict = calc._create_substitution_dict(variables, i) + calc_expr = expression + for var_pattern, value in sub_dict.items(): + calc_expr = re.sub( + r'\b' + re.escape(var_pattern) + r'\b', + f"({value})", + calc_expr, + ) try: - # 从列名中提取数字 - numbers = re.findall(r'\d+', col) - if numbers: - wavelength = int(numbers[0]) - numeric_wavelengths.append((col, wavelength)) - except: - continue - - if not numeric_wavelengths: - raise ValueError(f"无法从列名中提取波长信息: {df_columns}") - - # 找到最接近的波长 - closest_col, closest_wl = min(numeric_wavelengths, - key=lambda x: abs(x[1] - target_wl)) - - print(f"为波长 {target_wl}nm 找到最接近的列: {closest_col} ({closest_wl}nm)") - return closest_col - + r = eval(calc_expr, {"__builtins__": None}, {"nan": np.nan, "inf": np.inf, "np": np}) + except Exception: + r = np.nan + results.append(r) + + return pd.Series(results, index=df.index, name=expression) + + def calculate_one(self, name: str, df: pd.DataFrame) -> pd.Series: + """ + 计算单个水质指数。 + + Args: + name: 公式名称(对应 Formula_Name) + df: 光谱反射率 DataFrame + + Returns: + pd.Series,计算结果 + """ + if name not in self._formula_cache: + raise KeyError(f"未在 waterindex.csv 中找到公式: {name}") + + cfg = self._formula_cache[name] + expr = cfg["formula"] + ftype = cfg["type"] + coeff_str = cfg["coeff"] + + raw = self._band_math_all_rows(df, expr) + + if ftype == "concentration": + coeff = self._parse_coeff(coeff_str) + result = np.polyval(coeff, raw.values) + raw = pd.Series(result, index=df.index, name=name) + + raw.name = name + return raw + + def calculate_many(self, names: List[str], df: pd.DataFrame) -> pd.DataFrame: + """ + 批量计算多个水质指数。 + + Args: + names: 公式名称列表 + df: 光谱反射率 DataFrame + + Returns: + pd.DataFrame,每列对应一个公式的计算结果 + """ + results = {} + for name in names: + try: + results[name] = self.calculate_one(name, df) + except Exception as e: + print(f"⚠️ 计算 {name} 失败: {e}") + results[name] = pd.Series(np.nan, index=df.index, name=name) + + return pd.DataFrame(results) + # ========================================================================= - # 叶绿素算法 + # 向后兼容:保留原有外部调用接口 # ========================================================================= - - def chl_Al10SABI(self, df: pd.DataFrame) -> pd.Series: - """ - Surface Algal Bloom Index (SABI) for chlorophyll detection - 参考文献: Alawadi, F. Detection of surface algal blooms using the newly - developed algorithm surface algal bloom index (SABI). Proc. SPIE 2010, 7825. - """ - w857 = df[self.find_closest_wavelength(df.columns, 857)] - w644 = df[self.find_closest_wavelength(df.columns, 644)] - w458 = df[self.find_closest_wavelength(df.columns, 458)] - w529 = df[self.find_closest_wavelength(df.columns, 529)] - - result = (w857 - w644) / (w458 + w529) - return result - - def chl_Am092Bsub(self, df: pd.DataFrame) -> pd.Series: - """ - Baseline subtraction algorithm for chlorophyll - 参考文献: Amin, R.; Zhou, J.; Gilerson, A.; Gross, B.; Moshary, F.; Ahmed, S. - Novel optical techniques for detecting and classifying toxic dinoflagellate - Karenia brevis blooms using satellite imagery. Opt. Express 2009, 17, 9126–9144. - """ - w681 = df[self.find_closest_wavelength(df.columns, 681)] - w665 = df[self.find_closest_wavelength(df.columns, 665)] - - result = w681 - w665 - return result - - def chl_Be16FLHblue(self, df: pd.DataFrame) -> pd.Series: - """ - Fluorescence Line Height algorithm with blue baseline for chlorophyll - 参考文献: Beck, R.A. and 22 others; Comparison of satellite reflectance - algorithms for estimating chlorophyll-a in a temperate reservoir using - coincident hyperspectral aircraft imagery and dense coincident surface - observations, Remote Sens. Environ., 2016, 178, 15-30. - """ - w529 = df[self.find_closest_wavelength(df.columns, 529)] - w644 = df[self.find_closest_wavelength(df.columns, 644)] - w458 = df[self.find_closest_wavelength(df.columns, 458)] - - result = w529 - (w644 + (w458 - w644)) - return result - - def chl_Be16FLHviolet(self, df: pd.DataFrame) -> pd.Series: - """ - Fluorescence Line Height algorithm with violet baseline for chlorophyll - 参考文献: Beck, R.A. and 22 others; Comparison of satellite reflectance - algorithms for estimating chlorophyll-a in a temperate reservoir using - coincident hyperspectral aircraft imagery and dense coincident surface - observations, Remote Sens. Environ., 2016, 178, 15-30. - """ - w529 = df[self.find_closest_wavelength(df.columns, 529)] - w644 = df[self.find_closest_wavelength(df.columns, 644)] - w429 = df[self.find_closest_wavelength(df.columns, 429)] - - result = w529 - (w644 + (w429 - w644)) - return result - - def chl_Be16NDTIblue(self, df: pd.DataFrame) -> pd.Series: - """ - Normalized Difference Turbidity Index with blue band for chlorophyll - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 543. - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w458 = df[self.find_closest_wavelength(df.columns, 458)] - - result = (w658 - w458) / (w658 + w458) - return result - - def chl_Be16NDTIviolet(self, df: pd.DataFrame) -> pd.Series: - """ - Normalized Difference Turbidity Index with violet band for chlorophyll - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 544. - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w444 = df[self.find_closest_wavelength(df.columns, 444)] - - result = (w658 - w444) / (w658 + w444) - return result - - def chl_De933BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Band difference algorithm for chlorophyll - 参考文献: Dekker, A.; Detection of the optical water quality parameters for - eutrophic waters by high resolution remote sensing, Ph.D. thesis, 1993, - Free University, Amsterdam. - """ - w600 = df[self.find_closest_wavelength(df.columns, 600)] - w648 = df[self.find_closest_wavelength(df.columns, 648)] - w625 = df[self.find_closest_wavelength(df.columns, 625)] - - result = w600 - w648 - w625 - return result - - def chl_Gi033BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Gitelson algorithm for chlorophyll estimation - 参考文献: Gitelson, A.A.; U. Gritz, and M. N. Merzlyak.; Relationships between - leaf chlorophyll content and spectral reflectance and algorithms for - non-destructive chlorophyll assessment in higher plant leaves. J. Plant Phys. 2003, 160, 271-282. - """ - w672 = df[self.find_closest_wavelength(df.columns, 672)] - w715 = df[self.find_closest_wavelength(df.columns, 715)] - w757 = df[self.find_closest_wavelength(df.columns, 757)] - - result = ((1 / w672) - (1 / w715)) * w757 - return result - - def chl_Kn07KIVU(self, df: pd.DataFrame) -> pd.Series: - """ - Kneubuhler algorithm for chlorophyll in Lake Kivu - 参考文献: Kneubuhler, M.; Frank T.; Kellenberger, T.W; Pasche N.; Schmid M.; - Mapping chlorophyll-a in Lake Kivu with remote sensing methods. 2007, - Proceedings of the Envisat Symposium 2007, Montreux, Switzerland 23–27 April 2007 (ESA SP-636, July 2007). - """ - w458 = df[self.find_closest_wavelength(df.columns, 458)] - w644 = df[self.find_closest_wavelength(df.columns, 644)] - w529 = df[self.find_closest_wavelength(df.columns, 529)] - - result = (w458 - w644) / w529 - return result - - def chl_MM12NDCI(self, df: pd.DataFrame) -> pd.Series: - """ - Normalized Difference Chlorophyll Index - 参考文献: Mishra, S.; and Mishra, D.R. Normalized difference chlorophyll - index: A novel model for remote estimation of chlorophyll-a concentration - in turbid productive waters, Remote Sens. Environ., 2012, 117, 394-406 - """ - w715 = df[self.find_closest_wavelength(df.columns, 715)] - w686 = df[self.find_closest_wavelength(df.columns, 686)] - - result = (w715 - w686) / (w715 + w686) - return result - - def chl_Zh10FLH(self, df: pd.DataFrame) -> pd.Series: - """ - Zhao fluorescence line height algorithm for chlorophyll - 参考文献: Zhao, D.Z.; Xing, X.G.; Liu, Y.G.; Yang, J.H.; Wang, L. The relation of - chlorophyll-a concentration with the reflectance peak near 700 nm in - algae-dominated waters and sensitivity of fluorescence algorithms for - detecting algal bloom. Int. J. Remote Sens. 2010, 31, 39-48 - """ - w686 = df[self.find_closest_wavelength(df.columns, 686)] - w715 = df[self.find_closest_wavelength(df.columns, 715)] - w672 = df[self.find_closest_wavelength(df.columns, 672)] - w751 = df[self.find_closest_wavelength(df.columns, 751)] - - result = w686 - (w715 + (w672 - w751)) - return result - - # ========================================================================= - # 蓝藻/藻蓝蛋白算法 (BGA/PC) - # ========================================================================= - - def BGA_Am09KBBI(self, df: pd.DataFrame) -> pd.Series: - """ - Karenia Brevis Bloom Index for cyanobacteria/phycocyanin - 参考文献: Amin, R.; Zhou, J.; Gilerson, A.; Gross, B.; Moshary, F.; Ahmed, S.; - Novel optical techniques for detecting and classifying toxic dinoflagellate - Karenia brevis blooms using satellite imagery, Optics Express, 2009, 17, 11, 1-13. - """ - w686 = df[self.find_closest_wavelength(df.columns, 686)] - w658 = df[self.find_closest_wavelength(df.columns, 658)] - - result = (w686 - w658) / (w686 + w658) - return result - - def BGA_Be162B643sub629(self, df: pd.DataFrame) -> pd.Series: - """ - Band subtraction algorithm for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538. - """ - w644 = df[self.find_closest_wavelength(df.columns, 644)] - w629 = df[self.find_closest_wavelength(df.columns, 629)] - - result = w644 - w629 - return result - - def BGA_Be162B700sub601(self, df: pd.DataFrame) -> pd.Series: - """ - Band subtraction algorithm for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539. - """ - w700 = df[self.find_closest_wavelength(df.columns, 700)] - w601 = df[self.find_closest_wavelength(df.columns, 601)] - - result = w700 - w601 - return result - - def BGA_Be162BsubPhy(self, df: pd.DataFrame) -> pd.Series: - """ - Band subtraction algorithm for phytoplankton/phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 540. - """ - w715 = df[self.find_closest_wavelength(df.columns, 715)] - w615 = df[self.find_closest_wavelength(df.columns, 615)] - - result = w715 - w615 - return result - - def BGA_Be16FLHBlueRedNIR(self, df: pd.DataFrame) -> pd.Series: - """ - Fluorescence Line Height with Blue-Red-NIR baseline for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538. - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w857 = df[self.find_closest_wavelength(df.columns, 857)] - w458 = df[self.find_closest_wavelength(df.columns, 458)] - - result = w658 - (w857 + (w458 - w857)) - return result - - def BGA_Be16FLHGreenRedNIR(self, df: pd.DataFrame) -> pd.Series: - """ - Fluorescence Line Height with Green-Red-NIR baseline for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539. - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w857 = df[self.find_closest_wavelength(df.columns, 857)] - w558 = df[self.find_closest_wavelength(df.columns, 558)] - - result = w658 - (w857 + (w558 - w857)) - return result - - def BGA_Be16FLHVioletRedNIR(self, df: pd.DataFrame) -> pd.Series: - """ - Fluorescence Line Height with Violet-Red-NIR baseline for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538. - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w857 = df[self.find_closest_wavelength(df.columns, 857)] - w444 = df[self.find_closest_wavelength(df.columns, 444)] - - result = w658 - (w857 + (w444 - w857)) - return result - - def BGA_Be16MPI(self, df: pd.DataFrame) -> pd.Series: - """ - Maximum Peak Index for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539. - """ - w615 = df[self.find_closest_wavelength(df.columns, 615)] - w601 = df[self.find_closest_wavelength(df.columns, 601)] - w644 = df[self.find_closest_wavelength(df.columns, 644)] - - result = (w615 - w601) - (w644 - w601) - return result - - def BGA_Be16NDPhyI(self, df: pd.DataFrame) -> pd.Series: - """ - Normalized Difference Phytoplankton Index for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 540. - """ - w700 = df[self.find_closest_wavelength(df.columns, 700)] - w622 = df[self.find_closest_wavelength(df.columns, 622)] - - result = (w700 - w622) / (w700 + w622) - return result - - def BGA_Be16NDPhyI644over615(self, df: pd.DataFrame) -> pd.Series: - """ - Normalized Difference Phytoplankton Index (644/615) for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 541. - """ - w644 = df[self.find_closest_wavelength(df.columns, 644)] - w615 = df[self.find_closest_wavelength(df.columns, 615)] - - result = (w644 - w615) / (w644 + w615) - return result - - def BGA_Be16NDPhyI644over629(self, df: pd.DataFrame) -> pd.Series: - """ - Normalized Difference Phytoplankton Index (644/629) for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 542. - """ - w644 = df[self.find_closest_wavelength(df.columns, 644)] - w629 = df[self.find_closest_wavelength(df.columns, 629)] - - result = (w644 - w629) / (w644 + w629) - return result - - def BGA_Be16Phy2BDA644over629(self, df: pd.DataFrame) -> pd.Series: - """ - Band ratio algorithm (644/629) for phycocyanin - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 545. - """ - w644 = df[self.find_closest_wavelength(df.columns, 644)] - w629 = df[self.find_closest_wavelength(df.columns, 629)] - - result = w644 / w629 - return result - - def BGA_Da052BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Band ratio algorithm (714/672) for phycocyanin - 参考文献: Wynne, T. T., Stumpf, R. P., Tomlinson, M. C., Warner, R. A., - Tester, P. A., Dyble, J.; Relating spectral shape to cyanobacterial - blooms in the Laurentian Great Lakes. Int. J. Remote Sens., 2008, 29, 3665-3672. - """ - w714 = df[self.find_closest_wavelength(df.columns, 714)] - w672 = df[self.find_closest_wavelength(df.columns, 672)] - - result = w714 / w672 - return result - - def BGA_Go04MCI(self, df: pd.DataFrame) -> pd.Series: - """ - Maximum Chlorophyll Index for phycocyanin - 参考文献: Gower, J.F.R.; Brown,L.; Borstad, G.A.; Observation of chlorophyll - fluorescence in west coast waters of Canada using the MODIS satellite sensor. - Can. J. Remote Sens., 2004, 30 (1), 17–25. - """ - w709 = df[self.find_closest_wavelength(df.columns, 709)] - w681 = df[self.find_closest_wavelength(df.columns, 681)] - w753 = df[self.find_closest_wavelength(df.columns, 753)] - - result = w709 - w681 - (w753 - w681) - return result - - def BGA_HU103BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Hunter algorithm for phycocyanin - 参考文献: Hunter, P.D.; Tyler, A.N.; Willby, N.J.; Gilvear, D.J.; The spatial - dynamics of vertical migration by Microcystis aeruginosa in a eutrophic - shallow lake: A case study using high spatial resolution time-series - airborne remote sensing. Limn. Oceanogr. 2008, 53, 2391-2406 - """ - w615 = df[self.find_closest_wavelength(df.columns, 615)] - w600 = df[self.find_closest_wavelength(df.columns, 600)] - w725 = df[self.find_closest_wavelength(df.columns, 725)] - - result = (((1 / w615) - (1 / w600)) - w725) - return result - - def BGA_Ku15PhyCI(self, df: pd.DataFrame) -> pd.Series: - """ - Kudela Phytoplankton Community Index for phycocyanin - 参考文献: Kudela, R.M., Palacios, S.L., Austerberry, D.C., Accorsi, E.K., - Guild, L.S.; Application of hyperspectral remote sensing to cyanobacterial - blooms in inland waters, Torres-Perez, J., 2015, Remote Sens. Environ., 2015, 167, 1-10. - """ - w681 = df[self.find_closest_wavelength(df.columns, 681)] - w665 = df[self.find_closest_wavelength(df.columns, 665)] - w709 = df[self.find_closest_wavelength(df.columns, 709)] - - result = -1 * (w681 - w665 - (w709 - w665)) - return result - - def BGA_Ku15SLH(self, df: pd.DataFrame) -> pd.Series: - """ - Kudela Scattering Line Height for phycocyanin - 参考文献: Kudela, R.M., Palacios, S.L., Austerberry, D.C., Accorsi, E.K., - Guild, L.S.; Application of hyperspectral remote sensing to cyanobacterial - blooms in inland waters, Torres-Perez, J., 2015, Remote Sens. Environ., 2015, 167, 1-11. - """ - w715 = df[self.find_closest_wavelength(df.columns, 715)] - w658 = df[self.find_closest_wavelength(df.columns, 658)] - - result = (w715 - w658) + (w715 - w658) - return result - - def BGA_MI092BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Mishra band ratio algorithm (700/600) for phycocyanin - 参考文献: Mishra, S.; Mishra, D.R.; Schluchter, W. M., A novel algorithm for - predicting PC concentrations in cyanobacteria: A proximal hyperspectral - remote sensing approach. Remote Sens., 2009, 1, 758–775. - """ - w700 = df[self.find_closest_wavelength(df.columns, 700)] - w600 = df[self.find_closest_wavelength(df.columns, 600)] - - result = w700 / w600 - return result - - def BGA_MM092BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Mishra band ratio algorithm (724/600) for phycocyanin - 参考文献: Mishra, S.; Mishra, D.R.; Schluchter, W. M., A novel algorithm for - predicting PC concentrations in cyanobacteria: A proximal hyperspectral - remote sensing approach. Remote Sens., 2009, 1, 758–776. - """ - w724 = df[self.find_closest_wavelength(df.columns, 724)] - w600 = df[self.find_closest_wavelength(df.columns, 600)] - - result = w724 / w600 - return result - - def BGA_MM12NDCIalt(self, df: pd.DataFrame) -> pd.Series: - """ - Alternative Normalized Difference Chlorophyll Index for phycocyanin - 参考文献: Mishra, S.; Mishra, D.R.; A novel remote sensing algorithm to - quantify phycocyanin in cyanobacterial algal blooms, Env. Res. Lett., - 2014, 9 (11), DOI:10.1088/1748-9326/9/11/114003 - """ - w700 = df[self.find_closest_wavelength(df.columns, 700)] - w658 = df[self.find_closest_wavelength(df.columns, 658)] - - result = (w700 - w658) / (w700 + w658) - return result - - def BGA_MM143BDAopt(self, df: pd.DataFrame) -> pd.Series: - """ - Optimized band algorithm for phycocyanin - 参考文献: Mishra, S.; Mishra, D.R.; A novel remote sensing algorithm to - quantify phycocyanin in cyanobacterial algal blooms, Env. Res. Lett., - 2014, 9 (11), DOI:10.1088/1748-9326/9/11/114004 - """ - w629 = df[self.find_closest_wavelength(df.columns, 629)] - w659 = df[self.find_closest_wavelength(df.columns, 659)] - w724 = df[self.find_closest_wavelength(df.columns, 724)] - - result = ((1 / w629) - (1 / w659)) * w724 - return result - - def BGA_SI052BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Simis band ratio algorithm (709/620) for phycocyanin - 参考文献: Simis, S. G. H.; Peters, S.W. M.; Gons, H. J.; Remote sensing of - the cyanobacteria pigment phycocyanin in turbid inland water. Limn. Oceanogr., 2005, 50, 237–245 - """ - w709 = df[self.find_closest_wavelength(df.columns, 709)] - w620 = df[self.find_closest_wavelength(df.columns, 620)] - - result = w709 / w620 - return result - - def BGA_SM122BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Mishra band ratio algorithm (709/600) for phycocyanin - 参考文献: Mishra, S. Remote sensing of cyanobacteria in turbid productive - waters, PhD Dissertation. Mississippi State University, USA. 2012. - """ - w709 = df[self.find_closest_wavelength(df.columns, 709)] - w600 = df[self.find_closest_wavelength(df.columns, 600)] - - result = w709 / w600 - return result - - def BGA_SY002BDA(self, df: pd.DataFrame) -> pd.Series: - """ - Schalles-Yacobi band ratio algorithm (650/625) for phycocyanin - 参考文献: Schalles, J.; Yacobi, Y. Remote detection and seasonal patterns of - phycocyanin, carotenoid and chlorophyll-a pigments in eutrophic waters. - Archiv fur Hydrobiologie, Special Issues Advances in Limnology, 2000, 55,153–168 - """ - w650 = df[self.find_closest_wavelength(df.columns, 650)] - w625 = df[self.find_closest_wavelength(df.columns, 625)] - - result = w650 / w625 - return result - - def BGA_Wy08CI(self, df: pd.DataFrame) -> pd.Series: - """ - Wynne Cyanobacteria Index for phycocyanin - 参考文献: Wynne, T. T., Stumpf, R. P., Tomlinson, M. C., Warner, R. A., - Tester, P. A., Dyble, J.; Relating spectral shape to cyanobacterial - blooms in the Laurentian Great Lakes. Int. J. Remote Sens., 2008, 29, 3665-3672. - """ - w686 = df[self.find_closest_wavelength(df.columns, 686)] - w672 = df[self.find_closest_wavelength(df.columns, 672)] - w715 = df[self.find_closest_wavelength(df.columns, 715)] - - result = -1 * (w686 - w672 - (w715 - w672)) - return result - - # ========================================================================= - # 浊度算法 - # ========================================================================= - - def Turb_Be16GreenPlusRedBothOverViolet(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: (Green + Red) / Violet - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 538 - """ - w558 = df[self.find_closest_wavelength(df.columns, 558)] - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w444 = df[self.find_closest_wavelength(df.columns, 444)] - - result = (w558 + w658) / w444 - return result - - def Turb_Be16RedOverViolet(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: Red / Violet - 参考文献: Beck, R.; Xu, M.; Zhan, S.; Liu, H.; Johansen, R.A.; Tong, S.; - Yang, B.; Shu, S.; Wu, Q.; Wang, S.; Berling, K.; Murray, A.; Emery, E.; - Reif, M.; Harwood, J.; Young, J.; Martin, M.; Stillings, G.; Stumpf, R.; - Su, H.; Ye, Z.; Huang, Y. Comparison of Satellite Reflectance Algorithms - for Estimating Phycocyanin Values and Cyanobacterial Total Biovolume in - a Temperate Reservoir Using Coincident Hyperspectral Aircraft Imagery - and Dense Coincident Surface Observations. Remote Sens. 2017, 9, 539 - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w444 = df[self.find_closest_wavelength(df.columns, 444)] - - result = w658 / w444 - return result - - def Turb_Bow06RedOverGreen(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: Red / Green - 参考文献: Bowers, D. G., and C. E. Binding. 2006. "The Optical Properties of - Mineral Suspended Particles: A Review and Synthesis." Estuarine Coastal - and Shelf Science 67 (1–2): 219–230. doi:10.1016/j.ecss.2005.11.010 - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w558 = df[self.find_closest_wavelength(df.columns, 558)] - - result = w658 / w558 - return result - - def Turb_Chip09NIROverGreen(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: NIR / Green - 参考文献: Chipman, J. W.; Olmanson, L.G.; Gitelson, A.A.; Remote sensing - methods for lake management: A guide for resource managers and decision-makers. 2009. - """ - w857 = df[self.find_closest_wavelength(df.columns, 857)] - w558 = df[self.find_closest_wavelength(df.columns, 558)] - - result = w857 / w558 - return result - - def Turb_Dox02NIRoverRed(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: NIR / Red - 参考文献: Doxaran, D., Froidefond, J.-M.; Castaing, P. ; A reflectance band - ratio used to estimate suspended matter concentrations in sediment-dominated - coastal waters, Remote Sens., 2002, 23, 5079-5085 - """ - w857 = df[self.find_closest_wavelength(df.columns, 857)] - w658 = df[self.find_closest_wavelength(df.columns, 658)] - - result = w857 / w658 - return result - - def Turb_Frohn09GreenPlusRedBothOverBlue(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: (Green + Red) / Blue - 参考文献: Frohn, R. C., & Autrey, B. C. (2009). Water quality assessment in - the Ohio River using new indices for turbidity and chlorophyll-a with - Landsat-7 Imagery. Draft Internal Report, US Environmental Protection Agency. - """ - w558 = df[self.find_closest_wavelength(df.columns, 558)] - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w458 = df[self.find_closest_wavelength(df.columns, 458)] - - result = (w558 + w658) / w458 - return result - - def Turb_Harr92NIR(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: NIR reflectance - 参考文献: Schiebe F.R., Harrington J.A., Ritchie J.C. Remote-Sensing of - Suspended Sediments—the Lake Chicot, Arkansas Project. Int. J. Remote Sens. 1992;13:1487–1509 - """ - w857 = df[self.find_closest_wavelength(df.columns, 857)] - - result = w857 - return result - - def Turb_Lath91RedOverBlue(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: Red / Blue - 参考文献: Lathrop, R. G., Jr., T. M. Lillesand, and B. S. Yandell, 1991. - Testing the utility of simple multi-date Thematic Mapper calibration - algorithms for monitoring turbid inland waters. International Journal of Remote Sensing - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - w458 = df[self.find_closest_wavelength(df.columns, 458)] - - result = w658 / w458 - return result - - def Turb_Moore80Red(self, df: pd.DataFrame) -> pd.Series: - """ - Turbidity algorithm: Red reflectance - 参考文献: Moore, G.K., Satellite remote sensing of water turbidity, - Hydrological Sciences, 1980, 25, 4, 407-422 - """ - w658 = df[self.find_closest_wavelength(df.columns, 658)] - - result = w658 - return result - + def calculate_all_indices( self, input_file: str, - output_file: str = None, - selected_indices: Optional[List[str]] = None + output_file: Optional[str] = None, + selected_indices: Optional[List[str]] = None, ) -> pd.DataFrame: """ - 计算所有水质指数 - + 计算水质指数(向后兼容原有 API)。 + Args: - input_file: 输入CSV文件路径 - output_file: 输出CSV文件路径(可选) - selected_indices: 可选的算法列表,仅计算指定的指数 - + input_file: 输入 CSV 路径(光谱反射率数据) + output_file: 输出 CSV 路径(可选) + selected_indices: 要计算的公式名称列表(可选,默认全部) + Returns: - 包含计算结果的数据框 + 包含计算结果与原始数据的 DataFrame """ - # 读取数据 df = pd.read_csv(input_file) - print(f"成功读取数据,形状: {df.shape}") - print(f"数据列: {list(df.columns)}") - - results = df.copy() - - # 获取所有算法方法 - algorithm_methods = [ - method for method in dir(self) - if not method.startswith('_') and method not in ['find_closest_wavelength', 'calculate_all_indices'] - ] + print(f"读取光谱数据: {df.shape}") - print(f"\n找到 {len(algorithm_methods)} 个算法") + if selected_indices is None: + names = list(self._formula_cache.keys()) + else: + names = selected_indices - if selected_indices is not None: - filtered = [] - missing = [] - for name in selected_indices: - if name in algorithm_methods: - filtered.append(name) - else: - missing.append(name) + print(f"计算 {len(names)} 个公式...") + results_df = self.calculate_many(names, df) - if missing: - print(f"警告: 以下算法未找到,将被忽略: {', '.join(missing)}") + out = pd.concat([df, results_df], axis=1) - algorithm_methods = filtered - - if not algorithm_methods: - raise ValueError("未找到可用算法,请检查 selected_indices 参数") - - # 按算法类型分类计算 - algorithm_categories = { - 'chlorophyll': [], - 'BGA/PC': [], - 'turbidity': [] - } - - for method_name in algorithm_methods: - if method_name.startswith('Turb'): - algorithm_categories['turbidity'].append(method_name) - elif any(keyword in method_name for keyword in ['BDA', 'FLH', 'ND', 'sub', 'CI', 'SLH', 'MPI', 'Phy']): - if method_name not in algorithm_categories['turbidity']: - algorithm_categories['BGA/PC'].append(method_name) - else: - algorithm_categories['chlorophyll'].append(method_name) - - # 计算每个类别的算法 - for category, algorithms in algorithm_categories.items(): - print(f"\n=== 计算 {category} 相关指数 ({len(algorithms)}个算法) ===") - - for algo_name in algorithms: - try: - print(f"计算: {algo_name}") - method = getattr(self, algo_name) - results[algo_name] = method(df) - print(f"✓ 成功计算 {algo_name}") - - except Exception as e: - print(f"✗ 计算 {algo_name} 时出错: {str(e)}") - results[algo_name] = np.nan - - # 保存结果 if output_file: - results.to_csv(output_file, index=False) - print(f"\n结果已保存到: {output_file}") - - return results + out.to_csv(output_file, index=False) + print(f"结果已保存: {output_file}") + + return out + + def list_available(self) -> List[str]: + """返回所有可用公式名称列表。""" + return list(self._formula_cache.keys()) + + def get_formula_info(self, name: str) -> Dict: + """返回指定公式的配置信息。""" + return dict(self._formula_cache[name]) def main(): - """主函数""" - calculator = WaterQualityIndexCalculator() - - print("=" * 80) - print("水质光谱指数计算器") - print("=" * 80) - - # 计算指数 - input_file = r"E:\code\WQ\pipeline_result\work_dir\5_training_spectra\training_spectra.csv" # 修改为您的输入文件路径 - output_file = r"E:\code\WQ\pipeline_result\work_dir\5_training_spectra\water_quality_results.csv" - - try: - # 设置为 None 时默认计算所有已实现的算法;也可以设置为算法名称列表,例如 ['Al10SABI', 'TurbBe16RedOverViolet'] - selected_algorithms = None - results = calculator.calculate_all_indices(input_file, output_file, selected_algorithms) - - # 显示结果统计 - print("\n" + "=" * 80) - print("计算结果统计:") - print("=" * 80) - - # 只显示计算出的指数列的统计信息 - original_columns = pd.read_csv(input_file).columns - calculated_columns = [col for col in results.columns if col not in original_columns] - - if calculated_columns: - stats = results[calculated_columns].describe() - print(stats) - - # 按类别显示统计 - categories = { - '叶绿素算法': [col for col in calculated_columns if not col.startswith('Turb') and not any(x in col for x in ['BDA', 'FLH', 'ND', 'sub', 'CI', 'SLH', 'MPI', 'Phy']) or col in ['Al10SABI', 'Am092Bsub', 'Be16FLHblue', 'Be16FLHviolet', 'Be16NDTIblue', 'Be16NDTIviolet', 'De933BDA', 'Gi033BDA', 'Kn07KIVU', 'MM12NDCI', 'Zh10FLH']], - '蓝藻/藻蓝蛋白算法': [col for col in calculated_columns if col not in ['Al10SABI', 'Am092Bsub', 'Be16FLHblue', 'Be16FLHviolet', 'Be16NDTIblue', 'Be16NDTIviolet', 'De933BDA', 'Gi033BDA', 'Kn07KIVU', 'MM12NDCI', 'Zh10FLH'] and not col.startswith('Turb')], - '浊度算法': [col for col in calculated_columns if col.startswith('Turb')] - } - - for category, algo_list in categories.items(): - if algo_list: - print(f"\n{category}统计:") - print(results[algo_list].describe()) - else: - print("没有成功计算任何指数") - - except FileNotFoundError: - print(f"\n错误: 找不到输入文件 {input_file}") - print("请确保文件存在,或修改 input_file 变量为正确的文件路径") - except Exception as e: - print(f"\n计算过程中发生错误: {str(e)}") + """简单测试入口。""" + calc = WaterQualityIndexCalculator() + print(f"已加载 {len(calc.list_available())} 个公式") + + example_cfg = calc.get_formula_info("Chl_MM12NDCI") + print("示例配置:", example_cfg) if __name__ == "__main__":