# Patterns of labelled samples

The book's recorded MODIS samples of Mato Grosso, their class medians and quartiles, and the fitted sits_patterns() curves, aligned within each reference period.

[From step 1 of From a cube to labelled samples](/time-series.md).

In the sits book: [Basic operations on image time series](https://e-sensing.github.io/sitsbook/ts_basics.html).

Choose a band or a class to compare the original sample with the named class summary and fitted pattern.

## The figure

Aligned by day within each period. The book's MODIS samples were collected in different years.

The book's published MODIS set contains 1,837 samples. The original first row carries the supplied label Pasture. The figure opens with band NDVI and the Pasture class summary (344 samples). The class and band choices change the named summary; the original exemplar stays named separately. Aligned by day within each period. Source dates from different years are retained below; the fitted pattern has its own source calendar. No common observation year is implied.

| Field          | Recorded value |
| -------------- | -------------- |
| Longitude      | -57.794        |
| Latitude       | -9.7573        |
| Start date     | 2006-09-14     |
| End date       | 2007-08-29     |
| Supplied label | Pasture        |
| Cube           | bdc_cube       |

| Class      | Samples | Reference first date | Reference last date |
| ---------- | ------- | -------------------- | ------------------- |
| Cerrado    | 379     | 2000-09-13           | 2001-08-29          |
| Forest     | 131     | 2008-09-13           | 2009-08-29          |
| Pasture    | 344     | 2006-09-14           | 2007-08-29          |
| Soy corn   | 364     | 2014-09-14           | 2015-08-29          |
| Soy cotton | 352     | 2015-09-14           | 2016-08-28          |
| Soy fallow | 87      | 2006-09-14           | 2007-08-29          |
| Soy millet | 180     | 2014-09-14           | 2015-08-29          |

| Actual sample date | Elapsed day | NDVI                | EVI                 | NIR                 | MIR                 |
| ------------------ | ----------- | ------------------- | ------------------- | ------------------- | ------------------- |
| 2006-09-14         | 0           | 0.4995              | 0.26280000000000003 | 0.2298              | 0.13920000000000002 |
| 2006-09-30         | 16          | 0.4853              | 0.3299              | 0.35850000000000004 | 0.1608              |
| 2006-10-16         | 32          | 0.7161000000000001  | 0.39680000000000004 | 0.2642              | 0.0757              |
| 2006-11-01         | 48          | 0.6536000000000001  | 0.41500000000000004 | 0.3321              | 0.12390000000000001 |
| 2006-11-17         | 64          | 0.5911000000000001  | 0.43320000000000003 | 0.4001              | 0.17220000000000002 |
| 2006-12-03         | 80          | 0.6623              | 0.4388              | 0.34750000000000003 | 0.1253              |
| 2006-12-19         | 96          | 0.7336              | 0.4445              | 0.2948              | 0.0784              |
| 2007-01-01         | 109         | 0.739               | 0.5015000000000001  | 0.3478              | 0.0887              |
| 2007-01-17         | 125         | 0.7679              | 0.5256000000000001  | 0.3512              | 0.0761              |
| 2007-02-02         | 141         | 0.7968000000000001  | 0.5498000000000001  | 0.3547              | 0.0634              |
| 2007-02-18         | 157         | 0.7982              | 0.5334              | 0.3637              | 0.0707              |
| 2007-03-06         | 173         | 0.7763              | 0.5142              | 0.3486              | 0.0732              |
| 2007-03-22         | 189         | 0.7543000000000001  | 0.4949              | 0.3335              | 0.0758              |
| 2007-04-07         | 205         | 0.5025000000000001  | 0.3667              | 0.454               | 0.113               |
| 2007-04-23         | 221         | 0.7458              | 0.3904              | 0.2384              | 0.0437              |
| 2007-05-09         | 237         | 0.7291000000000001  | 0.5442              | 0.3793              | 0.0947              |
| 2007-05-25         | 253         | 0.6806              | 0.4495              | 0.3294              | 0.0918              |
| 2007-06-10         | 269         | 0.5938              | 0.37010000000000004 | 0.30920000000000003 | 0.1136              |
| 2007-06-26         | 285         | 0.5018              | 0.3019              | 0.28250000000000003 | 0.13390000000000002 |
| 2007-07-12         | 301         | 0.5389              | 0.31720000000000004 | 0.2757              | 0.1293              |
| 2007-07-28         | 317         | 0.4645              | 0.249               | 0.2366              | 0.14930000000000002 |
| 2007-08-13         | 333         | 0.44010000000000005 | 0.23700000000000002 | 0.2341              | 0.1529              |
| 2007-08-29         | 349         | 0.31010000000000004 | 0.1898              | 0.24880000000000002 | 0.1774              |

| Source date | Day within period | Median | Quartile 25 | Quartile 75 |
| ----------- | ----------------- | ------ | ----------- | ----------- |
| 2006-09-14  | 0                 | 0.3565 | 0.3167      | 0.4209      |
| 2006-09-30  | 16                | 0.4119 | 0.3444      | 0.4896      |
| 2006-10-16  | 32                | 0.47   | 0.3969      | 0.5428      |
| 2006-11-01  | 48                | 0.553  | 0.4754      | 0.6327      |
| 2006-11-17  | 64                | 0.583  | 0.5218      | 0.659       |
| 2006-12-03  | 80                | 0.6178 | 0.5581      | 0.6924      |
| 2006-12-19  | 96                | 0.6546 | 0.5926      | 0.7016      |
| 2007-01-01  | 109               | 0.6608 | 0.6077      | 0.7114      |
| 2007-01-17  | 125               | 0.663  | 0.6018      | 0.7144      |
| 2007-02-02  | 141               | 0.665  | 0.5956      | 0.7255      |
| 2007-02-18  | 157               | 0.6741 | 0.6075      | 0.7238      |
| 2007-03-06  | 173               | 0.6931 | 0.6336      | 0.7381      |
| 2007-03-22  | 189               | 0.686  | 0.6224      | 0.7316      |
| 2007-04-07  | 205               | 0.6792 | 0.6252      | 0.727       |
| 2007-04-23  | 221               | 0.672  | 0.6092      | 0.7194      |
| 2007-05-09  | 237               | 0.6332 | 0.5719      | 0.6904      |
| 2007-05-25  | 253               | 0.6013 | 0.5319      | 0.664       |
| 2007-06-10  | 269               | 0.542  | 0.4692      | 0.608       |
| 2007-06-26  | 285               | 0.4722 | 0.4136      | 0.5389      |
| 2007-07-12  | 301               | 0.4171 | 0.3636      | 0.4845      |
| 2007-07-28  | 317               | 0.3852 | 0.3387      | 0.436       |
| 2007-08-13  | 333               | 0.3496 | 0.3171      | 0.397       |
| 2007-08-29  | 349               | 0.3484 | 0.3148      | 0.3898      |

| Pattern source date | Day within period | sits_patterns() value |
| ------------------- | ----------------- | --------------------- |
| 2006-09-14          | 0                 | 0.3726                |
| 2006-09-22          | 8                 | 0.4004                |
| 2006-09-30          | 16                | 0.4282                |
| 2006-10-08          | 24                | 0.4561                |
| 2006-10-16          | 32                | 0.4839                |
| 2006-10-24          | 40                | 0.5113                |
| 2006-11-01          | 48                | 0.5376                |
| 2006-11-09          | 56                | 0.5622                |
| 2006-11-17          | 64                | 0.5845                |
| 2006-11-25          | 72                | 0.6037                |
| 2006-12-03          | 80                | 0.6195                |
| 2006-12-11          | 88                | 0.6317                |
| 2006-12-19          | 96                | 0.6405                |
| 2006-12-27          | 104               | 0.6465                |
| 2007-01-04          | 112               | 0.6502                |
| 2007-01-12          | 120               | 0.6526                |
| 2007-01-20          | 128               | 0.6545                |
| 2007-01-28          | 136               | 0.6566                |
| 2007-02-05          | 144               | 0.6594                |
| 2007-02-13          | 152               | 0.6629                |
| 2007-02-21          | 160               | 0.6668                |
| 2007-03-01          | 168               | 0.6707                |
| 2007-03-09          | 176               | 0.674                 |
| 2007-03-17          | 184               | 0.676                 |
| 2007-03-25          | 192               | 0.6762                |
| 2007-04-02          | 200               | 0.6741                |
| 2007-04-10          | 208               | 0.6695                |
| 2007-04-18          | 216               | 0.6623                |
| 2007-04-26          | 224               | 0.6522                |
| 2007-05-04          | 232               | 0.6392                |
| 2007-05-12          | 240               | 0.6231                |
| 2007-05-20          | 248               | 0.604                 |
| 2007-05-28          | 256               | 0.5818                |
| 2007-06-05          | 264               | 0.5568                |
| 2007-06-13          | 272               | 0.5296                |
| 2007-06-21          | 280               | 0.5011                |
| 2007-06-29          | 288               | 0.4726                |
| 2007-07-07          | 296               | 0.4454                |
| 2007-07-15          | 304               | 0.4209                |
| 2007-07-23          | 312               | 0.4001                |
| 2007-07-31          | 320               | 0.3836                |
| 2007-08-08          | 328               | 0.3712                |
| 2007-08-16          | 336               | 0.3622                |
| 2007-08-24          | 344               | 0.3554                |

Pinned source: e-sensing/samples_book, revision 4945eb700f902f63963a84f2265ec789e2ebc3de. This site's pipeline reads the verified local Parquet with sits_from_parquet(). It computes the class summaries and sits_patterns() curves.

### How it was made

1. Read the book's samples: The pipeline verifies the pinned Mato Grosso Parquet, reads its supplied labels, and computes aligned summaries and sits_patterns() curves.
2. Write the files: The pipeline writes the files the website reads, each with a record of its sources and of how closely a rerun repeats it.

### Reproducibility details

- A rerun on aarch64-apple-darwin23 gave the same files, byte for byte.

Every step of the pipeline:

1. Verifies the pinned book Parquet's bytes. `hf_pinned_file(list(repo = "e-sensing/samples_book", type = "dataset", revision = "4945eb700f902f63963a84f2265ec789e2ebc3de", file = "samples_matogrosso_mod13q1.parquet", bytes = 481117, sha256 = "d303ca01bc556a23c3f9da10532f17effbac08b3ae74fb8b23ef619f7331a21e"))`
2. Reads the book's supplied labelled samples. `samples_book_read(samples_book_file)`
3. Computes the book samples' sits_patterns() curves. `samples_book_pattern_data(samples_book)`
4. Keeps the book sample axes and exact decimal grid. `samples_book_values(samples_book)`
5. Aligns each class and computes medians and quartiles. `samples_book_class_curves(samples_book)`
6. Writes the pinned book samples and computed curves. `site_write_json(samples_book_json(samples_book_record, list(together = samples_book_together, patterns = samples_book_patterns), list(source = list(repo = "e-sensing/samples_book", type = "dataset", revision = "4945eb700f902f63963a84f2265ec789e2ebc3de", file = "samples_matogrosso_mod13q1.parquet", bytes = 481117, sha256 = "d303ca01bc556a23c3f9da10532f17effbac08b3ae74fb8b23ef619f7331a21e"), titles = list(Cerradao = "Cerradão", Nat_NonVeg = "Natural non-vegetated"))), "../web/src/data/series-book.json")`
7. Writes the exact book sample/band/date integer array. `samples_book_write_values(samples_book_record, "../web/public/data/series-samples.bin")`

The files:

- `series-book.json`: SHA-256 `c6f8d0f8a3b0529c6e59701c1bb711b1539818ab2a97bbd03719ea59d41a774e`. A rerun on aarch64-apple-darwin23 gave the same file, byte for byte.
- `series-samples.bin`: SHA-256 `c82a15efc85654c86c2538919c3b9d24b410a4045c5900b2b56bd2abb23947d3`. A rerun on aarch64-apple-darwin23 gave the same file, byte for byte.

To make them again: `cd pipeline && Rscript make.R`.

## What to try

1. **Switch the band.** Choose another *Band*: the first row's line, the class's median and quartiles and its fitted sits_patterns() curve all change, and the row above names the band its series is drawn in.
2. **Look behind a curve.** Choose a class under *Class summary*: the shaded band runs between the quartiles of its samples around their median. Where the band is wide, the samples of the class do not agree, and the one fitted curve hides that.
3. **Hold one sample to its class.** The thin line is the first row of the samples. Choose its own class, then another, and see where it follows the median and where it leaves the quartiles.
