Before this: From series to embeddings

From a cube to labelled samples

How does a place in a cube become a sample whose label we know?

Open a labelled sample from the book. Then follow one place through a cube, and compare the optical series and embeddings of the Cerrado's labelled samples.

Step 01 of 5

What is in a labelled sample?

The book reads the labelled samples of Mato Grosso from Hugging Face.

The book's code

samples_matogrosso_mod13q1 <- sits_from_hf(
  repo = "e-sensing/samples_book",
  file = "samples_matogrosso_mod13q1.parquet",
  type = "dataset"
)

Where the sits book writes this call: ts_basics.qmd, lines 61–65

The book begins with 1,837 samples of Mato Grosso. A sample names a place, a period and a label.

The last cell holds the measurements through that period: a time series.

Many places carry this label. Drawn together, their series show what they share and how much they differ.

sits_patterns() fits one curve to each class. It summarizes what these samples share.

Choose a band or a class. These are the book’s MODIS samples, collected in different years.

Published MODIS · 1,837 recorded samples

longitude
-57.794
latitude
-9.7573
label
Pasture
cube
bdc_cube
start_date
2006-09-14
end_date
2007-08-29
time_series
closed
Aligned by day within each period. The book's MODIS samples were collected in different years.

The dates of this sample

The book's first sample carries the supplied label Pasture, valid from 2006-09-14 to 2007-08-29.

These are its original calendar dates. The chart aligns each sample, class summary and fitted pattern by elapsed days within its own reference period; the observations can belong to different years.

Actual dateElapsed dayNDVIEVINIRMIR
2006-09-1400.49950.26280.22980.1392
2006-09-30160.48530.32990.35850.1608
2006-10-16320.71610.39680.26420.0757
2006-11-01480.65360.41500.33210.1239
2006-11-17640.59110.43320.40010.1722
2006-12-03800.66230.43880.34750.1253
2006-12-19960.73360.44450.29480.0784
2007-01-011090.73900.50150.34780.0887
2007-01-171250.76790.52560.35120.0761
2007-02-021410.79680.54980.35470.0634
2007-02-181570.79820.53340.36370.0707
2007-03-061730.77630.51420.34860.0732
2007-03-221890.75430.49490.33350.0758
2007-04-072050.50250.36670.45400.1130
2007-04-232210.74580.39040.23840.0437
2007-05-092370.72910.54420.37930.0947
2007-05-252530.68060.44950.32940.0918
2007-06-102690.59380.37010.30920.1136
2007-06-262850.50180.30190.28250.1339
2007-07-123010.53890.31720.27570.1293
2007-07-283170.46450.24900.23660.1493
2007-08-133330.44010.23700.23410.1529
2007-08-293490.31010.18980.24880.1774

Try it: Patterns of labelled samples

Step 02 of 5

How does one place become a time series?

Here sits reads one place through the months of the Cerrado cube.

The book's code

series <- sits_get_data(cube    = raster_cube,
                        samples = sample_latlong)

Where the sits book writes this call: ts_basics.qmd, lines 490–491

The book’s call uses Sinop. Here we ran it on one point in the cached Cerrado window.

Now the Cerrado, with Landsat images. The marked place lies inside the small window.

The same pixel is present in every month’s image.

Read down the column: 24 months in 6 bands.

sits_get_data() returned this row. Its label is NoClass because we supplied only a location.

Cached Cerrado window · BDC · LANDSAT-OLI-16D

2017-05-01

Loading rgb-months.png (1.4 MB).

One sits_get_data() call, run by this site's pipeline on the cached Cerrado window. The regional samples shown next are a separate dataset.

Try it: Any pixel of the Sinop cube, as a time series

Step 03 of 5

Do all places behave the same?

The book reads recorded optical series for labelled places across the Cerrado.

The book's code

labelled_samples <- sits_from_hf(
    repo = "e-sensing/samples_cerrado",
    file = "labelled_samples_cerrado.parquet",
    type = "dataset"
)

Where the sits book writes this call: emb_example.qmd, lines 551–555

sits_from_hf() reads series that were already extracted; their original extraction is undocumented.

These places lie across the Cerrado. They are outside the small window; the map shows both footprints.

This is one place’s recorded NIR08 series. We read it from the published sample file.

Another place, another curve. Their Euclidean distance in NIR08 measures the difference.

Choose a place or a band. A shape alone is not a supplied label.

Study window (step 2)

Loading labelled-sample-points.bin (80 kB).

Longitude/latitude, equirectangular, no basemap · Study window drawn larger than its true 7.7 km

Recorded optical series from the published sample file; their original extraction is undocumented. The map is drawn in geographic coordinates, with no basemap; a square marks the study window at its true place, drawn larger than the window.

Step 04 of 5

Where does a sample's label come from?

A label belongs to a place for a stated period.

The published sample already carries this label. The curve did not assign it.

These regional records carry 11 labels. The comparison keeps the same 4,443 samples.

The label holds for this period. Open the Sinop example to compare other years.

Study window (step 2)

Loading labelled-sample-points.bin (80 kB).

A · Place 5

Longitude/latitude, equirectangular, no basemap · Study window drawn larger than its true 7.7 km

Loading labelled-samples-NIR08.bin (853 kB).

Recorded series and supplied labels from the published sample file; their original extraction is undocumented. The map is drawn in geographic coordinates, with no basemap; a square marks the study window at its true place, drawn larger than the window.

Other years: the separate Sinop example

The book's Sinop example is a separate dataset, with its own places in Mato Grosso, read from its own CSV file. It is not part of the Cerrado samples of this step: no Sinop value is drawn on this curve or this map.

A label holds for the period written in its sample. Setting the same place's series in another year beside it gives a distance between the two series. A distance, or a threshold on it, is a measure of how much they differ, never a new label.

To compare a Sinop place across its years, open the interactive image of the Sinop years.

The Sinop CSV example is in the sits book: Time series from data cubes.

Try it: One labelled Sinop place, every year

Step 05 of 5

What changes when a sample is encoded?

The book passes the samples’ optical series to the encoder.

The book's code

samples_lejepa <- sits_encode(
    data = labelled_samples_red,
    encoder = lejepa_encoder,
    multicores = 8,
    gpu_memory = 16,
    batch_size = 512,
    verbose = TRUE
)

Where the sits book writes this call: emb_example.qmd, lines 601–608

The book encodes a random fraction of its samples. Here the pipeline encoded the 4,443 samples valid from 2017-01-01, drawn per class with a fixed seed.

This is the sample’s recorded NIR08 series, one of the 6 bands the encoder reads.

sits_encode() reads all 6 bands over 24 months. The encoder connection here is a diagram.

64 values come back. The location, valid period and supplied label stay with the sample.

Switch forms for the same samples. One axis follows months; the other follows dimensions.

Compare one class in either form. Embedding dimensions do not mark seasons.

Study window (step 2)

Loading labelled-sample-points.bin (80 kB).

Longitude/latitude, equirectangular, no basemap · Study window drawn larger than its true 7.7 km

Optical form: the recorded NIR08 series of A, Place 5, over its monthly dates.

Loading labelled-samples-NIR08.bin (853 kB).

Recorded optical series from the published sample file; their original extraction is undocumented. Their embeddings come from this site's pipeline running sits_encode() with the book's encoder. The encoder is drawn as a diagram. The map is drawn in geographic coordinates, with no basemap; a square marks the study window at its true place, drawn larger than the window.

A's 6 bands on every date

A's recorded value in every input band, one row per date. The step's chosen band is NIR08. These 6 files load only when asked:

  • labelled-samples-BLUE.bin (853 kB)
  • labelled-samples-GREEN.bin (853 kB)
  • labelled-samples-RED.bin (853 kB)
  • labelled-samples-NIR08.bin (853 kB)
  • labelled-samples-SWIR16.bin (853 kB)
  • labelled-samples-SWIR22.bin (853 kB)