An implementation of the Composite 2 Change (C2C) algorithm. This algorithm segments a time series using a piecewise linear fit with the minimum number of segments required to fit the data within the given maximum root mean squared error (RMSE). For each input band, the algorithm returns the following output bands:

- **changeDate** (Array\[Double\]): The dates at which changes are detected. The date format is determined by the dateFormat argument.
- **value** (Array\[Double\]): Value of the band at each changeDate.
- **magnitude** (Array\[Double\]): The difference between the values before and after a change date. The first magnitude is always NaN.
- **duration** (Array\[Double\]): The duration of the segment preceding the change date. The first duration is always NaN.
- **rate** (Array\[Double\]): Rate of change of the data preceding the change date. The first rate is always NaN.

If **includePostMetrics** is true the following variables are included per-band.

- **postMagnitude** (Array\[Double\]): The absolute difference between the value at the start of the next segment and the value at the change date. The last postMagnitude is always NaN.
- **postDuration** (Array\[Double\]): The duration of the segment following the change date. The last postDuration is always NaN.
- **postRate** (Array\[Double\]): The rate of change of the data following the change date. The last postRate is always NaN.

If **includeRegrowth** is true the following variables are included per-band.

- **indexRegrowth** (Array\[Double\]): The difference between the value at the change date and the value five data points after.
- **recoveryIndicator** (Array\[Double\]): The ratio of indexRegrowth to magnitude.
- **regrowth60** (Array\[Double\]): Time difference between the change date and the data point where the series value is 60% of the pre-disturbance value.
- **regrowth80** (Array\[Double\]): Time difference between the change date and the data point where the series value is 80% of the pre-disturbance value.
- **regrowth100** (Array\[Double\]): Time difference between the change date and the data point where the series value is 100% of the pre-disturbance value.

See: Hermosilla et al. (2015) https://doi.org/10.1016/j.rse.2014.11.005 for further details on the original algorithm. Algorithm implementation can be found on GitHub: https://github.com/saveriofrancini/C2C-GEE Acknowledgements: FORWARDS and NextGenCarbon.

Citation: Txomin Hermosilla, Michael A. Wulder, Joanne C. White, Nicholas C. Coops, Daniel Coelho, Giovanni Ciatto, Noel Gorelick, and Saverio Francini. In preparation. Image compositing, time-series change detection and temporal metrics: Implementation of the Composite2Change (C2C) algorithm on Google Earth Engine.

This algorithm is in preview and is subject to change.

| Usage | Returns |
|---|---|
| `ee.Algorithms.TemporalSegmentation.C2c(collection, *dateFormat*, *maxErrorList*, *spikesToleranceList*, *spikeRemovalMagnitudeList*, *maxError*, *maxSegments*, *infill*, *spikesTolerance*, *spikeRemovalMagnitude*, *includePostMetrics*, *includeRegrowth*, *interpolateRegrowth*, *useRelativeRegrowth*, *negativeMagnitudeOnly*)` | Image |

| Argument | Type | Details |
|---|---|---|
| `collection` | ImageCollection | Collection of images on which to run C2C. |
| `dateFormat` | Integer, default: 0 | The time representation to use during fitting: 0 = jDays, 1 = fractional years, 2 = unix time in milliseconds. The start, end and break times for each temporal segment will be encoded this way. |
| `maxErrorList` | List, default: {} | List of maximum error (RMSE) values to be used for each band. If not provided, the maxError value will be used for all bands. |
| `spikesToleranceList` | List, default: {} | List of spike tolerance values to be used for each band. A value of 1 indicates no spike removal. If not provided, the spikesTolerance value will be used for all bands. |
| `spikeRemovalMagnitudeList` | List, default: {} | List of spike removal magnitude values to be used for each band. Spikes with a magnitude above this value are removed. If not provided, the spikeRemovalMagnitude value will be used for all bands. |
| `maxError` | Float, default: 0.075 | Maximum allowed RMSE of the piecewise linear fit; controls segmentation sensitivity. |
| `maxSegments` | Integer, default: 6 | Maximum number of segments permitted in the fitted tajectory. |
| `infill` | Boolean, default: true | Enables gap infilling within the time series to support stable fitting in the presence of missing values (i.e., values equal to 0). |
| `spikesTolerance` | Float, default: 0.85 | Controls tolerance of spikes in the time series. Ranges from 0 to 1. A value of 1 indicates no spike removal, lower values are more aggressive. |
| `spikeRemovalMagnitude` | Float, default: 0.1 | Spike removal magnitude threshold. Spikes with a magnitude (absolute difference from the average of neighbors) above this value are removed. |
| `includePostMetrics` | Boolean, default: true | Returns post-change descriptors (postMagnitude, postDuration, postRate). |
| `includeRegrowth` | Boolean, default: false | Returns recovery/regrowth metrics (indexRegrowth, recoveryIndicator, regrowth60/80/100). |
| `interpolateRegrowth` | Boolean, default: true | Linearly interpolate the time series using the detected changes before calculating the regrowth metrics. |
| `useRelativeRegrowth` | Boolean, default: false | Computes regrowth thresholds in relative terms to pre-disturbance conditions. |
| `negativeMagnitudeOnly` | Boolean, default: false | Retains only breakpoints associated with negative changes (directional filtering). |