Datasets:

ArXiv:
License:
PeterTor commited on
Commit
1b4ab5c
·
verified ·
1 Parent(s): ef169c1

Update BioMap.py

Browse files
Files changed (1) hide show
  1. BioMap.py +25 -7
BioMap.py CHANGED
@@ -52,6 +52,7 @@ _URLS = {
52
  "default": "https://huggingface.co/great-new-dataset-first_domain.zip",
53
  }
54
 
 
55
 
56
  # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
57
  class NewDataset(datasets.GeneratorBasedBuilder):
@@ -73,6 +74,7 @@ class NewDataset(datasets.GeneratorBasedBuilder):
73
 
74
  BUILDER_CONFIGS = [
75
  datasets.BuilderConfig(name="default", version=VERSION, description="This part of my dataset covers a first domain"),
 
76
  ]
77
 
78
  DEFAULT_CONFIG_NAME = "default" # It's not mandatory to have a default configuration. Just use one if it make sense.
@@ -101,6 +103,16 @@ class NewDataset(datasets.GeneratorBasedBuilder):
101
  citation=_CITATION,
102
  )
103
 
 
 
 
 
 
 
 
 
 
 
104
  def _split_generators(self, dl_manager):
105
  # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
106
  # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
@@ -140,11 +152,17 @@ class NewDataset(datasets.GeneratorBasedBuilder):
140
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
141
  def _generate_examples(self, filepath, split):
142
  for i,d in enumerate(self.ds[split]):
143
- yield i, {
144
- 'input': d["input"],
145
- 'label': d["label"]
146
- }
147
-
148
-
149
-
 
 
 
 
 
 
150
 
 
52
  "default": "https://huggingface.co/great-new-dataset-first_domain.zip",
53
  }
54
 
55
+ norm_values = {'B01': {'mean': 0.12478869, 'std': 0.024433358, 'min': 1e-04, 'max': 1.8808, 'p1': 0.0787, 'p99': 0.1946}, 'B02': {'mean': 0.13480005, 'std': 0.02822557, 'min': 1e-04, 'max': 2.1776, 'p1': 0.0925, 'p99': 0.2216}, 'B03': {'mean': 0.16031432, 'std': 0.032037303, 'min': 1e-04, 'max': 2.12, 'p1': 0.1035, 'p99': 0.2556}, 'B04': {'mean': 0.1532097, 'std': 0.038628064, 'min': 1e-04, 'max': 2.0032, 'p1': 0.1023, 'p99': 0.2816}, 'B05': {'mean': 0.20312776, 'std': 0.04205057, 'min': 0.0422, 'max': 1.7502, 'p1': 0.1178, 'p99': 0.319}, 'B06': {'mean': 0.32636437, 'std': 0.07139242, 'min': 0.0502, 'max': 1.7245, 'p1': 0.1633, 'p99': 0.519}, 'B07': {'mean': 0.36605212, 'std': 0.08555025, 'min': 0.0616, 'max': 1.7149, 'p1': 0.1776, 'p99': 0.6076}, 'B08': {'mean': 0.3811653, 'std': 0.092815965, 'min': 1e-04, 'max': 1.7488, 'p1': 0.1691, 'p99': 0.646}, 'B8A': {'mean': 0.3910436, 'std': 0.0896364, 'min': 0.055, 'max': 1.688, 'p1': 0.1871, 'p99': 0.6386}, 'B09': {'mean': 0.3910644, 'std': 0.0836445, 'min': 0.0012, 'max': 1.7915, 'p1': 0.2124, 'p99': 0.6241}, 'B11': {'mean': 0.2917373, 'std': 0.07472579, 'min': 0.0953, 'max': 1.648, 'p1': 0.1334, 'p99': 0.4827}, 'B12': {'mean': 0.21169408, 'std': 0.05880649, 'min': 0.0975, 'max': 1.6775, 'p1': 0.115, 'p99': 0.3872}}
56
 
57
  # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
58
  class NewDataset(datasets.GeneratorBasedBuilder):
 
74
 
75
  BUILDER_CONFIGS = [
76
  datasets.BuilderConfig(name="default", version=VERSION, description="This part of my dataset covers a first domain"),
77
+ datasets.BuilderConfig(name="unnormalized", version=VERSION, description="This part of my dataset covers a first domain"),
78
  ]
79
 
80
  DEFAULT_CONFIG_NAME = "default" # It's not mandatory to have a default configuration. Just use one if it make sense.
 
103
  citation=_CITATION,
104
  )
105
 
106
+ def denormalize_s2(self,patch):
107
+ r,g,b = patch[3],patch[2],patch[1]
108
+ res = []
109
+ for band, band_value in zip(['B04','B03','B02'],[r,g,b]) :
110
+ p1, p99 = norm_values[band]['p1'], norm_values[band]['p99']
111
+ band_value = (p99 - p1) * band_value + p1
112
+ res.append(band_value)
113
+ patch[3],patch[2],patch[1] = res
114
+ return patch
115
+
116
  def _split_generators(self, dl_manager):
117
  # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
118
  # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
 
152
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
153
  def _generate_examples(self, filepath, split):
154
  for i,d in enumerate(self.ds[split]):
155
+ if self.config.name == "default":
156
+ yield i, {
157
+ 'input': d["input"],
158
+ 'label': d["label"]
159
+ }
160
+
161
+ elif self.config.name == "unnormalized":
162
+ yield i, {
163
+ 'input': self.denormalize_s2(d["input"]),
164
+ 'label': d["label"]
165
+ }
166
+
167
+
168