File size: 1,315 Bytes
4023dde
c8b078c
4023dde
 
 
c8b078c
 
 
 
 
 
8b10e6e
c8b078c
 
4023dde
c8b078c
 
 
 
 
 
 
 
 
 
4023dde
 
 
c8b078c
 
4023dde
 
8b10e6e
4023dde
 
 
 
 
 
 
 
 
 
c8b078c
4023dde
 
 
8b10e6e
4023dde
 
 
 
 
 
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
# %%
import datasets
import numpy as np
from torch.utils.data import DataLoader

quakeflow_nc = datasets.load_dataset(
    "AI4EPS/quakeflow_nc",
    name="station",
    split="train",
    # name="station_test",
    # split="test",
    # download_mode="force_redownload",
    trust_remote_code=True,
    num_proc=36,
)
# quakeflow_nc = datasets.load_dataset(
#     "./quakeflow_nc.py",
#     name="station",
#     split="train",
#     # name="statoin_test",
#     # split="test",
#     num_proc=36,
# )

print(quakeflow_nc)

# print the first sample of the iterable dataset
for example in quakeflow_nc:
    print("\nIterable dataset\n")
    print(example)
    print(example.keys())
    for key in example.keys():
        if key == "waveform":
            print(key, np.array(example[key]).shape)
        else:
            print(key, example[key])
    break

# %%
quakeflow_nc = quakeflow_nc.with_format("torch")
dataloader = DataLoader(quakeflow_nc, batch_size=8, num_workers=0, collate_fn=lambda x: x)

for batch in dataloader:
    print("\nDataloader dataset\n")
    print(f"Batch size: {len(batch)}")
    print(batch[0].keys())
    for key in batch[0].keys():
        if key == "waveform":
            print(key, np.array(batch[0][key]).shape)
        else:
            print(key, batch[0][key])
    break

# %%