Skip to content

Repository files navigation

Collocation Analysis Package

Python VersionVersionLicense

A Python library for collocation-based error analysis of remote sensing and geophysical datasets — quantifying errors in multiple products without ground truth.

For the full architecture guide (bilingual 中/EN), see ARCHITECTURE.md.


What's New in v2.0

FeatureDescription
Sklearn-style APITC().fit(data).metrics_ — uniform interface across all methods
Smart RecommenderCollocationConsultant diagnoses your data and suggests the best method
Interactive DashboardPlotly 3-panel HTML dashboard with time-series slider and stability heatmap
ELI PipelineOne-click parallel ELI analysis with auto-generated HTML report

Installation

git clone https://github.com/licm13/Collocation-Analysis.git
cd Collocation-Analysis
pip install -e .# Optional: interactive dashboard
pip install plotly
# Optional: xarray support
pip install xarray
# Optional: Bayesian methods
pip install "pymc3==3.11.5" theano-pymc

Quick Start

1. Let the consultant choose your method

importnumpyasnpfromcollocationimportCollocationConsultantdata=np.column_stack([product1, product2, product3]) # (n, 3)report=CollocationConsultant(data, product_names=['ERA5', 'GLEAM', 'GLDAS']).consult()
print(report)
# ★ PRIMARY RECOMMENDATION → EIVD# Reason: High cross-correlation detected (GLEAM×GLDAS r=0.54)...

2. Fit with the sklearn-style API

fromcollocation.estimatorsimportTC, EIVD, IVD# Fit and inspectmodel=TC().fit(data)
print(model.metrics_['error_std']) # [0.20, 0.31, 0.39]print(model.summary())
# Compare methods in a loopresults= {name: cls().fit(data).metrics_forname, clsin [('TC', TC), ('EIVD', EIVD)]}

3. Interactive dashboard

fromcollocationimportInteractiveDashboardfromcollocation.estimatorsimportTC, EIVDfromcollocationimporttcmetrics= {'TC': TC().fit(data).metrics_, 'EIVD': EIVD().fit(data).metrics_}
InteractiveDashboard(data, metrics, method_fn=tc).save('dashboard.html')

4. ELI one-click pipeline

fromcollocationimportELIPipelineresult=ELIPipeline(
water=np.column_stack([swvl1, gleam_sm, gldas_sm]),
energy=np.column_stack([swd, era5_rn, gldas_rn]),
vegetation=et_obs,
product_names={
'water': ['ERA5-SM', 'GLEAM-SM', 'GLDAS-SM'],
'energy': ['ERA5-SW', 'ERA5-Rn', 'GLDAS-Rn'],
'vegetation': ['GLEAM-ET'],
},
).run()
print(result.summary()) # ELI ratio, per-method tableresult.save('eli_report.html')

5. Classic functional API (unchanged)

fromcollocationimporttc, eivd, ivd, ec, btch_he2020EeeT, SNR, rho2, fMSE=tc(data) # 3-wayEeeT, SNR, rho2, fMSE, L=eivd(data) # 3-way + cross-corrEeeT, rho2, weights=ivd(np.column_stack([p1, p2])) # 2-wayvariances, weights, fused=btch_he2020(data) # analytical BTCH

Implemented Methods

Classical

MethodProductsKey Use Case
IVD2Active + passive sensor fusion
IVS2Two-product with bootstrap CI
TC / TCH3Standard triple collocation
EIVD3Correlated-error products
EC4Quadruple over-determination
ETCC3Correlation-optimised merging (precipitation)
MTCHN≥3Multiplicative / positive-skew data

Bayesian

MethodUncertaintyDependencies
BTCH_He2020None (analytical)NumPy only
BayesianTCHFull MCMCPyMC3
BayesianTCFull MCMC + time-varyingPyMC3

Module Map

collocation/
├── base.py ← CollocationEstimator ABC
├── estimators.py ← TC / EIVD / IVD / EC sklearn wrappers
├── consultant.py ← CollocationConsultant smart recommender
├── plotting.py ← plot_error_comparison, InteractiveDashboard
├── eli_pipeline.py ← ELIPipeline, ELIResult
│
├── tc.py, eivd.py, ivd.py, ivs.py, ec.py ← classical methods
├── etcc.py, mtch.py ← advanced methods
├── btch_he2020.py, bayesian_tc.py, bayesian_tch.py
│
├── utils.py, covariance.py, fuse.py, simple_average.py, eli.py
└── fusion/ ← IVW / GLS / QP weights, robust, localization

Testing

pip install pytest
pytest tests/ -v
# New v2.0 tests only
pytest tests/test_upgrade.py -v # 48 tests

Dependencies

PackageRoleRequired?
numpy ≥ 1.18Core numericsYes
scipy ≥ 1.4Statistics, linear algebraYes
matplotlib ≥ 3.1Static plotsOptional
plotly ≥ 5.0Interactive dashboardOptional
xarray ≥ 0.18Native DataArray/Dataset inputOptional
pymc3 == 3.11.5Bayesian TC/TCHOptional

Documentation

FileContent
ARCHITECTURE.mdFull bilingual (EN/中) code architecture guide
ELI_README.mdEcosystem Limitation Index application guide
BAYESIAN_INTEGRATION_GUIDE.mdPyMC3 setup and Bayesian workflow
PERFORMANCE_SUMMARY.mdOptimisation history (98% speedups)
README_CN.md中文说明
CLAUDE.mdAI-assistant developer guide

Citation

If you use this package, please cite the underlying methods relevant to your analysis. Key references:

  • TC: Stoffelen (1998), JGR, 103(C4)
  • EIVD: Dong et al. (2019), J. Hydrology, 581
  • BTCH_He2020: He et al. (2020), HESS
  • ETCC: Wei et al. (2023)
  • ELI: Dong et al. (2022), Remote Sens. Environ.

License

MIT © Original MATLAB: licm_13@163.com | Python conversion & v2.0 upgrade: Claude

About

聚类配点分析(collocation analysis)的相关代码与研究

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages