jbloom
commited on
Commit
·
8a3abc3
1
Parent(s):
21bb2fa
updated dataloader and README config section
Browse files- GBI-16-4D.py +51 -34
- README.md +8 -5
GBI-16-4D.py
CHANGED
|
@@ -3,9 +3,12 @@ import random
|
|
| 3 |
from glob import glob
|
| 4 |
import json
|
| 5 |
|
|
|
|
|
|
|
| 6 |
from astropy.io import fits
|
| 7 |
import datasets
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
_DESCRIPTION = (
|
| 11 |
"GBI-16-4D is a dataset which is part of the AstroCompress project. It contains data "
|
|
@@ -62,53 +65,67 @@ class GBI_16_4D(datasets.GeneratorBasedBuilder):
|
|
| 62 |
def _info(self):
|
| 63 |
return datasets.DatasetInfo(
|
| 64 |
description=_DESCRIPTION,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
homepage=_HOMEPAGE,
|
| 66 |
license=_LICENSE,
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
-
def _split_generators(self, dl_manager):
|
| 70 |
|
| 71 |
-
urls = _URLS[self.config.name]
|
| 72 |
-
|
| 73 |
-
data_dir = dl_manager.download_and_extract(urls)
|
| 74 |
ret = []
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
)
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
ret.append(
|
| 85 |
datasets.SplitGenerator(
|
| 86 |
-
name=datasets.Split.TEST,
|
| 87 |
-
gen_kwargs={"
|
| 88 |
-
"
|
|
|
|
|
|
|
| 89 |
),
|
| 90 |
)
|
| 91 |
return ret
|
| 92 |
|
| 93 |
-
def _generate_examples(self,
|
| 94 |
"""Generate GBI-16-4D examples"""
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
image_path = os.path.join(base_url, item["image"].split("./")[-1])
|
| 102 |
-
with fits.open(image_path, memmap=False) as hdul:
|
| 103 |
-
image_data = hdul[0].data
|
| 104 |
-
yield task_instance_key, {"image": image_data,
|
| 105 |
-
"ra": item["ra"],
|
| 106 |
-
"dec": item["dec"],
|
| 107 |
-
"pixscale": item["pixscale"],
|
| 108 |
-
"ntimes": item["ntimes"],
|
| 109 |
-
"nbands": item["nbands"]}
|
| 110 |
-
idx += 1
|
| 111 |
-
|
| 112 |
|
| 113 |
def make_split_jsonl_files(config_type="tiny", data_dir="./data",
|
| 114 |
outdir="./splits", seed=42):
|
|
|
|
| 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 DatasetInfo, DownloadManager
|
| 11 |
+
from fsspec.core import url_to_fs
|
| 12 |
|
| 13 |
_DESCRIPTION = (
|
| 14 |
"GBI-16-4D is a dataset which is part of the AstroCompress project. It contains data "
|
|
|
|
| 65 |
def _info(self):
|
| 66 |
return datasets.DatasetInfo(
|
| 67 |
description=_DESCRIPTION,
|
| 68 |
+
features=datasets.Features(
|
| 69 |
+
{
|
| 70 |
+
"image": datasets.Array4D(shape=(None, 5, 800, 800), dtype="uint16"),
|
| 71 |
+
"ra": datasets.Value("float64"),
|
| 72 |
+
"dec": datasets.Value("float64"),
|
| 73 |
+
"pixscale": datasets.Value("float64"),
|
| 74 |
+
"ntimes": datasets.Value("int64"),
|
| 75 |
+
"nbands": datasets.Value("int64"),
|
| 76 |
+
}
|
| 77 |
+
),
|
| 78 |
+
supervised_keys=None,
|
| 79 |
homepage=_HOMEPAGE,
|
| 80 |
license=_LICENSE,
|
| 81 |
+
citation="TBD",
|
| 82 |
)
|
| 83 |
|
| 84 |
+
def _split_generators(self, dl_manager: DownloadManager):
|
| 85 |
|
|
|
|
|
|
|
|
|
|
| 86 |
ret = []
|
| 87 |
+
base_path = dl_manager._base_path
|
| 88 |
+
if base_path.startswith(datasets.config.HF_ENDPOINT):
|
| 89 |
+
base_path = base_path[len(datasets.config.HF_ENDPOINT):].replace("/resolve/", "@", 1)
|
| 90 |
+
base_path = "hf://" + base_path.lstrip("/")
|
| 91 |
+
_, path = url_to_fs(base_path)
|
| 92 |
+
|
| 93 |
+
for split in ["train", "test"]:
|
| 94 |
+
split_file_location = os.path.normpath(os.path.join(path, _URLS[self.config.name][split]))
|
| 95 |
+
split_file = dl_manager.download(split_file_location)
|
| 96 |
+
with open(split_file, encoding="utf-8") as f:
|
| 97 |
+
data_filenames = []
|
| 98 |
+
data_metadata = []
|
| 99 |
+
for line in f:
|
| 100 |
+
item = json.loads(line)
|
| 101 |
+
data_filenames.append(item["image"])
|
| 102 |
+
data_metadata.append({"ra": item["ra"],
|
| 103 |
+
"dec": item["dec"],
|
| 104 |
+
"pixscale": item["pixscale"],
|
| 105 |
+
"ntimes": item["ntimes"],
|
| 106 |
+
"nbands": item["nbands"]})
|
| 107 |
+
|
| 108 |
+
data_urls = [os.path.normpath(os.path.join(path,data_filename)) for data_filename in data_filenames]
|
| 109 |
+
data_files = [dl_manager.download(data_url) for data_url in data_urls]
|
| 110 |
ret.append(
|
| 111 |
datasets.SplitGenerator(
|
| 112 |
+
name=datasets.Split.TRAIN if split == "train" else datasets.Split.TEST,
|
| 113 |
+
gen_kwargs={"filepaths": data_files,
|
| 114 |
+
"split_file": split_file,
|
| 115 |
+
"split": split,
|
| 116 |
+
"data_metadata": data_metadata},
|
| 117 |
),
|
| 118 |
)
|
| 119 |
return ret
|
| 120 |
|
| 121 |
+
def _generate_examples(self, filepaths, split_file, split, data_metadata):
|
| 122 |
"""Generate GBI-16-4D examples"""
|
| 123 |
|
| 124 |
+
for idx, (filepath, item) in enumerate(zip(filepaths, data_metadata)):
|
| 125 |
+
task_instance_key = f"{self.config.name}-{split}-{idx}"
|
| 126 |
+
with fits.open(filepath, memmap=False) as hdul:
|
| 127 |
+
image_data = hdul[0].data.tolist()
|
| 128 |
+
yield task_instance_key, {**{"image": image_data}, **item}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
def make_split_jsonl_files(config_type="tiny", data_dir="./data",
|
| 131 |
outdir="./splits", seed=42):
|
README.md
CHANGED
|
@@ -9,10 +9,13 @@ dataset_info:
|
|
| 9 |
config_name: tiny
|
| 10 |
features:
|
| 11 |
- name: image
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
| 16 |
- name: ra
|
| 17 |
dtype: float64
|
| 18 |
- name: dec
|
|
@@ -30,7 +33,7 @@ dataset_info:
|
|
| 30 |
- name: test
|
| 31 |
num_bytes: 352881364
|
| 32 |
num_examples: 1
|
| 33 |
-
download_size:
|
| 34 |
dataset_size: 911075540
|
| 35 |
---
|
| 36 |
GBI-16-4D Dataset
|
|
|
|
| 9 |
config_name: tiny
|
| 10 |
features:
|
| 11 |
- name: image
|
| 12 |
+
dtype:
|
| 13 |
+
array4_d:
|
| 14 |
+
shape:
|
| 15 |
+
- 5
|
| 16 |
+
- 800
|
| 17 |
+
- 800
|
| 18 |
+
dtype: uint16
|
| 19 |
- name: ra
|
| 20 |
dtype: float64
|
| 21 |
- name: dec
|
|
|
|
| 33 |
- name: test
|
| 34 |
num_bytes: 352881364
|
| 35 |
num_examples: 1
|
| 36 |
+
download_size: 908845172
|
| 37 |
dataset_size: 911075540
|
| 38 |
---
|
| 39 |
GBI-16-4D Dataset
|