-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchange_detection.py
More file actions
68 lines (57 loc) · 1.77 KB
/
Copy pathchange_detection.py
File metadata and controls
68 lines (57 loc) · 1.77 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import io
import numpy as np
from pydantic import BaseModel
import taco
class Acquisition(BaseModel):
year: int
def encode(array: np.ndarray) -> bytes:
buffer = io.BytesIO()
np.save(buffer, array)
return buffer.getvalue()
contract = taco.Contract(
structure=[
"before/B02.npy",
"before/B03.npy",
"after/B02.npy",
"after/B03.npy",
"change.npy",
],
metadata=taco.MetadataSchema(
taco.Level("sample", ml=taco.metadata.sample.Split),
taco.Level("children", acquisition=Acquisition | None),
),
)
collection = taco.Collection(
contract=contract,
id="change-detection",
dataset_version="1.0.0",
description="Paired observations and their change mask",
licenses=["MIT"],
providers=["Asterisk Labs"],
tasks=["change-detection"],
)
before = np.arange(2 * 16 * 16, dtype=np.uint16).reshape(2, 16, 16)
after = before.copy()
after[:, 5:11, 7:13] += 100
paths = {
"before/B02.npy": before[0],
"before/B03.npy": before[1],
"after/B02.npy": after[0],
"after/B03.npy": after[1],
"change.npy": np.any(before != after, axis=0),
}
assets = [taco.Asset(encode(array), path=path) for path, array in paths.items()]
sample = taco.Sample(
assets=assets,
metadata=taco.Metadata(ml=taco.metadata.sample.Split(split="train")),
folders=[
taco.Folder("before", metadata=taco.Metadata(acquisition=Acquisition(year=2020))),
taco.Folder("after", metadata=taco.Metadata(acquisition=Acquisition(year=2024))),
],
)
with taco.open_writer(collection, "change-detection", overwrite=True) as writer:
writer.add(sample)
writer.run()
dataset = taco.open_dataset("change-detection")
assert taco.read(dataset).num_rows == 1
assert taco.validate("change-detection").ok