File size: 2,230 Bytes
0cc7afc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Loading example for the AVIRIS-C California multilabel dataset.

Usage:
    python load_example.py [DATASET]     # DATASET = local folder of the release or "musmb/aviris-ca-multilabel" on the Hub

Requires: datasets, numpy, pandas (torch optional).
"""
import os
import sys

import numpy as np
from datasets import load_dataset

src = sys.argv[1] if len(sys.argv) > 1 else "."
if os.path.isdir(src):
    src = os.path.abspath(src)  # local release folder

# 1. Metadata only (fast: no cubes) -----------------------------------------------------
windows = load_dataset(src, "windows", split="train").to_pandas()
print(windows[["window_id", "lat", "lon", "zone", "fold", "n_ok_dates", "n_labels"]].head())
classes = [c[len("label_"):] for c in windows.columns if c.startswith("label_")]
print("classes:", classes)

# 2. One fold, streamed (no full download) ---------------------------------------------------
stream = load_dataset(src, split="fold_0", streaming=True)
s = next(iter(stream))
cube = np.asarray(s["cube"], dtype=np.float32)  # (14, B, 32, 32), NaN = no data
ok = np.asarray(s["qc_ok"], dtype=bool)
print("window", s["window_id"], "cube", cube.shape, "QC-ok dates", ok.sum(), "dates", [d for d in s["dates"] if d][:3], "...")
print("window labels:", [c for c, y in zip(classes, s["labels_window"]) if y == 1])

# 3. Training array for one fold: valid dates only, NaN -> 0, mask kept ----------------------
ds = load_dataset(src, split="fold_1").with_format("numpy")
sub = ds.select(range(min(8, len(ds))))
X = np.stack(sub["cube"]).astype(np.float32)          # (n, 14, B, 32, 32)
M = np.stack(sub["qc_ok"]).astype(bool)                # (n, 14)
Y = np.stack(sub["labels_window"]).astype(np.int64)    # (n, 13) window multilabel
Yt = np.stack(sub["labels_date"]).astype(np.int64)     # (n, 14, 13), -1 = padded date
X = np.clip(np.nan_to_num(X, nan=0.0), -0.05, 1.5)     # recommended clipping of rare outliers
X[~M] = 0.0
print("batch", X.shape, M.shape, Y.shape, Yt.shape)

try:  # optional: PyTorch tensors
    import torch

    xb, mb, yb = torch.from_numpy(X), torch.from_numpy(M), torch.from_numpy(Y).float()
    print("torch", tuple(xb.shape), tuple(mb.shape), tuple(yb.shape))
except ImportError:
    pass