Datasets:
fixed image generation
Browse files- ark_example.py +36 -38
ark_example.py
CHANGED
@@ -24,6 +24,8 @@ import datasets
|
|
24 |
import pathlib
|
25 |
import glob
|
26 |
import tifffile
|
|
|
|
|
27 |
|
28 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
29 |
_CITATION = """\
|
@@ -61,7 +63,7 @@ https://huggingface.co/docs/datasets/repository_structure
|
|
61 |
|
62 |
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
63 |
class ArkExample(datasets.GeneratorBasedBuilder):
|
64 |
-
"""The Dataset consists of
|
65 |
|
66 |
VERSION = datasets.Version("0.0.1")
|
67 |
|
@@ -90,16 +92,17 @@ class ArkExample(datasets.GeneratorBasedBuilder):
|
|
90 |
),
|
91 |
]
|
92 |
|
93 |
-
DEFAULT_CONFIG_NAME =
|
|
|
|
|
94 |
|
95 |
def _info(self):
|
96 |
-
#
|
97 |
-
if
|
98 |
-
self.config.name == "base_dataset"
|
99 |
-
): # This is the name of the configuration selected in BUILDER_CONFIGS above
|
100 |
features = datasets.Features(
|
101 |
{
|
102 |
-
"
|
|
|
103 |
}
|
104 |
)
|
105 |
else: # This is an example to show how to have different features for "first_domain" and "second_domain"
|
@@ -140,40 +143,35 @@ class ArkExample(datasets.GeneratorBasedBuilder):
|
|
140 |
datasets.SplitGenerator(
|
141 |
name="base_dataset",
|
142 |
# These kwargs will be passed to _generate_examples
|
143 |
-
gen_kwargs={
|
144 |
-
"filepath": pathlib.Path(data_dir)
|
145 |
-
},
|
146 |
),
|
147 |
]
|
148 |
|
149 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
150 |
def _generate_examples(self, filepath: pathlib.Path):
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
153 |
for fp in file_paths:
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
# "sentence": data["sentence"],
|
175 |
-
# "option2": data["option2"],
|
176 |
-
# "second_domain_answer": ""
|
177 |
-
# if split == "test"
|
178 |
-
# else data["second_domain_answer"],
|
179 |
-
# }
|
|
|
24 |
import pathlib
|
25 |
import glob
|
26 |
import tifffile
|
27 |
+
import xarray as xr
|
28 |
+
import numpy as np
|
29 |
|
30 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
31 |
_CITATION = """\
|
|
|
63 |
|
64 |
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
65 |
class ArkExample(datasets.GeneratorBasedBuilder):
|
66 |
+
"""The Dataset consists of 11 FOVs"""
|
67 |
|
68 |
VERSION = datasets.Version("0.0.1")
|
69 |
|
|
|
92 |
),
|
93 |
]
|
94 |
|
95 |
+
DEFAULT_CONFIG_NAME = (
|
96 |
+
"base_dataset" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
97 |
+
)
|
98 |
|
99 |
def _info(self):
|
100 |
+
# This is the name of the configuration selected in BUILDER_CONFIGS above
|
101 |
+
if self.config.name == "base_dataset":
|
|
|
|
|
102 |
features = datasets.Features(
|
103 |
{
|
104 |
+
"Channel Data": datasets.Sequence(datasets.Image()),
|
105 |
+
"Channel Names": datasets.Sequence(datasets.Value("string")),
|
106 |
}
|
107 |
)
|
108 |
else: # This is an example to show how to have different features for "first_domain" and "second_domain"
|
|
|
143 |
datasets.SplitGenerator(
|
144 |
name="base_dataset",
|
145 |
# These kwargs will be passed to _generate_examples
|
146 |
+
gen_kwargs={"filepath": pathlib.Path(data_dir)},
|
|
|
|
|
147 |
),
|
148 |
]
|
149 |
|
150 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
151 |
def _generate_examples(self, filepath: pathlib.Path):
|
152 |
+
|
153 |
+
# Get all TMA paths
|
154 |
+
file_paths = list(pathlib.Path(filepath / "fovs").glob("*"))
|
155 |
+
|
156 |
+
# Loop over all the TMAs
|
157 |
for fp in file_paths:
|
158 |
+
|
159 |
+
# Get the TMA FOV Name
|
160 |
+
fov_name = fp.stem
|
161 |
+
|
162 |
+
|
163 |
+
# Get all channels per TMA FOV
|
164 |
+
channel_paths = fp.glob("*.tiff")
|
165 |
+
|
166 |
+
chan_data = []
|
167 |
+
chan_names = []
|
168 |
+
for chan in channel_paths:
|
169 |
+
chan_name = chan.stem
|
170 |
+
chan_image: np.ndarray = tifffile.imread(chan)
|
171 |
+
|
172 |
+
chan_data.append(chan_image)
|
173 |
+
chan_names.append(chan_name)
|
174 |
+
|
175 |
+
|
176 |
+
if self.config.name == "base_dataset":
|
177 |
+
yield fov_name, {"Channel Data": chan_data, "Channel Names": chan_names}
|
|
|
|
|
|
|
|
|
|
|
|