jbloom
commited on
Commit
·
48ee9d4
1
Parent(s):
a4bd7d7
update README and remote usage
Browse files- GBI-16-4D.py +16 -10
- README.md +59 -1
GBI-16-4D.py
CHANGED
@@ -2,12 +2,12 @@ import os
|
|
2 |
import random
|
3 |
from glob import glob
|
4 |
import json
|
|
|
5 |
|
6 |
|
7 |
-
import pyarrow as pa
|
8 |
from astropy.io import fits
|
9 |
import datasets
|
10 |
-
from datasets import
|
11 |
from fsspec.core import url_to_fs
|
12 |
|
13 |
_DESCRIPTION = (
|
@@ -39,6 +39,8 @@ _URLS = {
|
|
39 |
}
|
40 |
}
|
41 |
|
|
|
|
|
42 |
class GBI_16_4D(datasets.GeneratorBasedBuilder):
|
43 |
"""GBI-16-4D Dataset"""
|
44 |
|
@@ -86,14 +88,15 @@ class GBI_16_4D(datasets.GeneratorBasedBuilder):
|
|
86 |
|
87 |
ret = []
|
88 |
base_path = dl_manager._base_path
|
89 |
-
|
90 |
-
# base_path = base_path[len(datasets.config.HF_ENDPOINT):].replace("/resolve/", "@", 1)
|
91 |
-
# base_path = "hf://" + base_path.lstrip("/")
|
92 |
_, path = url_to_fs(base_path)
|
93 |
|
94 |
for split in ["train", "test"]:
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
97 |
with open(split_file, encoding="utf-8") as f:
|
98 |
data_filenames = []
|
99 |
data_metadata = []
|
@@ -106,9 +109,12 @@ class GBI_16_4D(datasets.GeneratorBasedBuilder):
|
|
106 |
"ntimes": item["ntimes"],
|
107 |
"nbands": item["nbands"],
|
108 |
"image_id": item["image_id"]})
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
112 |
ret.append(
|
113 |
datasets.SplitGenerator(
|
114 |
name=datasets.Split.TRAIN if split == "train" else datasets.Split.TEST,
|
|
|
2 |
import random
|
3 |
from glob import glob
|
4 |
import json
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
|
7 |
|
|
|
8 |
from astropy.io import fits
|
9 |
import datasets
|
10 |
+
from datasets import DownloadManager
|
11 |
from fsspec.core import url_to_fs
|
12 |
|
13 |
_DESCRIPTION = (
|
|
|
39 |
}
|
40 |
}
|
41 |
|
42 |
+
_REPO_ID = "AstroCompress/GBI-16-4D"
|
43 |
+
|
44 |
class GBI_16_4D(datasets.GeneratorBasedBuilder):
|
45 |
"""GBI-16-4D Dataset"""
|
46 |
|
|
|
88 |
|
89 |
ret = []
|
90 |
base_path = dl_manager._base_path
|
91 |
+
locally_run = not base_path.startswith(datasets.config.HF_ENDPOINT)
|
|
|
|
|
92 |
_, path = url_to_fs(base_path)
|
93 |
|
94 |
for split in ["train", "test"]:
|
95 |
+
if locally_run:
|
96 |
+
split_file_location = os.path.normpath(os.path.join(path, _URLS[self.config.name][split]))
|
97 |
+
split_file = dl_manager.download_and_extract(split_file_location)
|
98 |
+
else:
|
99 |
+
split_file = hf_hub_download(repo_id=_REPO_ID, filename=_URLS[self.config.name][split], repo_type="dataset")
|
100 |
with open(split_file, encoding="utf-8") as f:
|
101 |
data_filenames = []
|
102 |
data_metadata = []
|
|
|
109 |
"ntimes": item["ntimes"],
|
110 |
"nbands": item["nbands"],
|
111 |
"image_id": item["image_id"]})
|
112 |
+
if locally_run:
|
113 |
+
data_urls = [os.path.normpath(os.path.join(path,data_filename)) for data_filename in data_filenames]
|
114 |
+
data_files = [dl_manager.download(data_url) for data_url in data_urls]
|
115 |
+
else:
|
116 |
+
data_urls = data_filenames
|
117 |
+
data_files = [hf_hub_download(repo_id=_REPO_ID, filename=data_url, repo_type="dataset") for data_url in data_urls]
|
118 |
ret.append(
|
119 |
datasets.SplitGenerator(
|
120 |
name=datasets.Split.TRAIN if split == "train" else datasets.Split.TEST,
|
README.md
CHANGED
@@ -36,4 +36,62 @@ dataset_info:
|
|
36 |
download_size: 908845172
|
37 |
dataset_size: 911075540
|
38 |
---
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
download_size: 908845172
|
37 |
dataset_size: 911075540
|
38 |
---
|
39 |
+
|
40 |
+
# GBI-16-4D Dataset
|
41 |
+
|
42 |
+
GBI-16-4D is a dataset which is part of the AstroCompress project. It contains data assembled from the Sloan Digital SkySurvey (SDSS). Each FITS file contains a series of 800x800 pixel uint16 observations of the same portion of the Stripe82 field, taken in 5 bandpass filters (u, g, r, i, z) over time. The filenames give the
|
43 |
+
starting run, field, camcol of the observations, the number of filtered images per timestep, and the number of timesteps. For example:
|
44 |
+
|
45 |
+
```cube_center_run4203_camcol6_f44_35-5-800-800.fits```
|
46 |
+
|
47 |
+
contains 35 frames of 800x800 pixel images in 5 bandpasses starting with run 4203, field 44, and camcol 6. The images are stored in the FITS standard.
|
48 |
+
|
49 |
+
# Usage
|
50 |
+
|
51 |
+
You first need to install the `datasets` and `astropy` packages:
|
52 |
+
|
53 |
+
```bash
|
54 |
+
pip install datasets satrapy
|
55 |
+
```
|
56 |
+
|
57 |
+
There are two datasets: `tiny` and `full`, each with `train` and `test` splits. The `tiny` dataset has 2 4D images in the `train` and 1 in the `test`. The `full` dataset contains all the images in the `data/` directory.
|
58 |
+
|
59 |
+
## Use from Huggingface Directly
|
60 |
+
|
61 |
+
To directly use from this data from Huggingface, you'll want to log in on the command line before starting python:
|
62 |
+
|
63 |
+
```bash
|
64 |
+
huggingface-cli login
|
65 |
+
```
|
66 |
+
|
67 |
+
Then in your python script:
|
68 |
+
|
69 |
+
```python
|
70 |
+
from datasets import load_dataset
|
71 |
+
dataset = load_dataset('AstroCompress/GBI-16-4D', 'tiny')
|
72 |
+
ds = dataset.with_format("np")
|
73 |
+
```
|
74 |
+
|
75 |
+
## Local Use
|
76 |
+
|
77 |
+
Alternatively, you can clone this repo and use directly without connecting to hf:
|
78 |
+
|
79 |
+
```bash
|
80 |
+
git clone https://huggingface.co/datasets/AstroCompress/GBI-16-4D
|
81 |
+
```
|
82 |
+
|
83 |
+
Then `cd GBI-16-4D` and start python like:
|
84 |
+
|
85 |
+
```python
|
86 |
+
from datasets import load_dataset
|
87 |
+
dataset = load_dataset('./GBI-16-4D.py', 'tiny', data_dir="./data/")
|
88 |
+
ds = dataset.with_format("np")
|
89 |
+
```
|
90 |
+
|
91 |
+
Now you should be able to use the `ds` variable like:
|
92 |
+
|
93 |
+
```python
|
94 |
+
ds["test"][0]["image"].shape # -> (55, 5, 800, 800)
|
95 |
+
```
|
96 |
+
|
97 |
+
Note of course that it will take a long time to download and convert the images in the local cache for the `full` dataset. Afterward, the usage should be quick as the files are memory-mapped from disk.
|