srivarra commited on
Commit
1691e35
1 Parent(s): b7dea26

fixed image generation

Browse files
Files changed (1) hide show
  1. 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 12 FOVs"""
65
 
66
  VERSION = datasets.Version("0.0.1")
67
 
@@ -90,16 +92,17 @@ class ArkExample(datasets.GeneratorBasedBuilder):
90
  ),
91
  ]
92
 
93
- DEFAULT_CONFIG_NAME = "base_dataset" # It's not mandatory to have a default configuration. Just use one if it make sense.
 
 
94
 
95
  def _info(self):
96
- # TODO: This method specifies the datasets.DatasetInfo object which contains information and typings for the dataset
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
- "fov": datasets.Sequence({"channel": datasets.Image()}),
 
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
- file_paths = list(filepath.rglob("*"))
152
-
 
 
 
153
  for fp in file_paths:
154
- if fp.suffix in [".tiff", ".tif"]:
155
- image_data = tifffile.imread(fp, key=0)
156
- if self.config.name == "base_dataset":
157
- yield fp, {
158
- "chan": image_data,
159
- "path": fp
160
- }
161
-
162
- # with open(filepath, encoding="utf-8") as f:
163
- # for key, row in enumerate(f):
164
- # data = json.loads(row)
165
- # if self.config.name == "first_domain":
166
- # # Yields examples as (key, example) tuples
167
- # yield key, {
168
- # "sentence": data["sentence"],
169
- # "option1": data["option1"],
170
- # "answer": "" if split == "test" else data["answer"],
171
- # }
172
- # else:
173
- # yield key, {
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}