|
1 |
| -""" |
2 |
| -Simplical dataset, downloads the processed data from Zenodo into torch geometric |
3 |
| -dataset that can be used in conjunction to dataloaders. |
4 |
| -
|
5 |
| -NOTE: Code untested until we have the zenodo database running or another place |
6 |
| -retrieve the data from. |
7 |
| -""" |
8 |
| - |
9 |
| -import os |
10 |
| -import json |
11 |
| - |
12 |
| -from torch_geometric.data import ( |
13 |
| - Data, |
14 |
| - InMemoryDataset, |
15 |
| - download_url, |
16 |
| - extract_zip, |
17 |
| -) |
18 |
| - |
19 |
| - |
20 |
| -class SimplicialDataset(InMemoryDataset): |
21 |
| - url = "my.cool.url.com" |
22 |
| - |
23 |
| - def __init__( |
24 |
| - self, |
25 |
| - root, |
26 |
| - transform=None, |
27 |
| - pre_transform=None, |
28 |
| - pre_filter=None, |
29 |
| - ): |
30 |
| - self.manifold = "2" |
31 |
| - root += f"/simplicial" |
32 |
| - super().__init__(root, transform, pre_transform, pre_filter) |
33 |
| - self.load(self.processed_paths[0]) |
34 |
| - |
35 |
| - @property |
36 |
| - def raw_file_names(self): |
37 |
| - return [ |
38 |
| - f"{self.manifold}_manifold.json", |
39 |
| - ] |
40 |
| - |
41 |
| - @property |
42 |
| - def processed_file_names(self): |
43 |
| - return [f"{self.manifold}_manifold.pt"] |
44 |
| - |
45 |
| - def download(self) -> None: |
46 |
| - path = download_url(self.url, self.raw_dir) |
47 |
| - extract_zip(path, self.raw_dir) |
48 |
| - os.unlink(path) |
49 |
| - |
50 |
| - def process(self): |
51 |
| - |
52 |
| - # After download and extraction, we expect a json file with |
53 |
| - # a list of json objects. |
54 |
| - inputs = json.load(self.raw_paths[0]) |
55 |
| - |
56 |
| - data_list = [Data(**el) for el in inputs] |
57 |
| - |
58 |
| - if self.pre_filter is not None: |
59 |
| - data_list = [data for data in data_list if self.pre_filter(data)] |
60 |
| - |
61 |
| - if self.pre_transform is not None: |
62 |
| - data_list = [self.pre_transform(data) for data in data_list] |
63 |
| - |
64 |
| - self.save(data_list, self.processed_paths[0]) |
0 commit comments