Datasets:

ArXiv:
paren8esis commited on
Commit
3d2c944
1 Parent(s): 7d06657

Add configurations (cat_2019, cat_2020, fr_2019)

Browse files
Files changed (1) hide show
  1. S4A.py +35 -26
S4A.py CHANGED
@@ -16,7 +16,6 @@
16
  from itertools import product
17
  import numpy as np
18
  import xarray as xr
19
- import dask
20
  import netCDF4
21
  import datasets
22
  from pathlib import Path
@@ -88,8 +87,9 @@ class S4A(datasets.GeneratorBasedBuilder):
88
 
89
  BUILDER_CONFIGS = [
90
  datasets.BuilderConfig(name="complete", version=VERSION, description="All Sen4AgriNet data."),
91
- datasets.BuilderConfig(name="tiny", version=VERSION, description="Just three samples for testing."),
92
  datasets.BuilderConfig(name="cat_2019", version=VERSION, description="Sen4AgriNet data for Catalonia 2019."),
 
 
93
  ]
94
 
95
  DEFAULT_CONFIG_NAME = "complete"
@@ -141,27 +141,36 @@ class S4A(datasets.GeneratorBasedBuilder):
141
  downloaded_paths = dl_manager.download(_URL + f'/{year}' + f'/{tile}' + f'/{year}_{tile}_patch_{str(x_i).zfill(2)}_{str(y_i).zfill(2)}.nc')
142
  root_paths.append(downloaded_paths)
143
 
144
- return [
145
- datasets.SplitGenerator(
146
- name='complete',
147
- # These kwargs will be passed to _generate_examples
148
- gen_kwargs={
149
- "root_paths": root_paths,
150
- },
151
- ),
152
- ]
153
- elif self.config.name == 'tiny':
154
- selected_files = ['2019_31TCF_patch_00_11.nc', '2019_31UCP_patch_01_19.nc', '2020_31TDG_patch_11_17.nc']
155
 
156
- for file in selected_files:
157
- year, tile = file.split('_')[:2]
 
 
 
 
 
 
158
 
159
- downloaded_paths = dl_manager.download(_URL + f'/{year}' + f'/{tile}' + f'/{file}')
160
- root_paths.append(downloaded_paths)
 
 
 
 
 
 
161
 
162
- return [
163
  datasets.SplitGenerator(
164
- name='tiny',
165
  # These kwargs will be passed to _generate_examples
166
  gen_kwargs={
167
  "root_paths": root_paths,
@@ -173,20 +182,20 @@ class S4A(datasets.GeneratorBasedBuilder):
173
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
174
  def _generate_examples(self, root_paths):
175
  for file in root_paths:
176
- data = xr.open_dataset(file, chunks=-1, engine='netcdf4')
177
 
178
  res = {
179
- "patch_full_name": data.patch_full_name,
180
- "patch_year": data.patch_year,
181
- "patch_name": data.patch_name,
182
- "patch_country_code": data.patch_country_code,
183
- "patch_tile": data.patch_tile
184
  }
185
 
186
  time_recorded = False
187
 
188
  for variable in ['B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B09', 'B10', 'B11', 'B12', 'B8A', 'labels', 'parcels']:
189
- v = xr.open_dataset(file, chunks=-1, engine='netcdf4', group=variable)
190
  if not time_recorded:
191
  res['timestamp'] = (v.time.values.astype(np.int64) // 10 ** 9).tolist()
192
  time_recorded = True
 
16
  from itertools import product
17
  import numpy as np
18
  import xarray as xr
 
19
  import netCDF4
20
  import datasets
21
  from pathlib import Path
 
87
 
88
  BUILDER_CONFIGS = [
89
  datasets.BuilderConfig(name="complete", version=VERSION, description="All Sen4AgriNet data."),
 
90
  datasets.BuilderConfig(name="cat_2019", version=VERSION, description="Sen4AgriNet data for Catalonia 2019."),
91
+ datasets.BuilderConfig(name="cat_2020", version=VERSION, description="Sen4AgriNet data for Catalonia 2020."),
92
+ datasets.BuilderConfig(name="fr_2019", version=VERSION, description="Sen4AgriNet data for France 2019."),
93
  ]
94
 
95
  DEFAULT_CONFIG_NAME = "complete"
 
141
  downloaded_paths = dl_manager.download(_URL + f'/{year}' + f'/{tile}' + f'/{year}_{tile}_patch_{str(x_i).zfill(2)}_{str(y_i).zfill(2)}.nc')
142
  root_paths.append(downloaded_paths)
143
 
144
+ elif self.config.name == 'cat_2019':
145
+ year = '2019'
146
+ for tile in CAT_TILES:
147
+ x, y = PATCH_IDX[year][tile]
148
+ for x_i in range(x + 1):
149
+ for y_i in range(y + 1):
150
+ downloaded_paths = dl_manager.download(_URL + f'/{year}' + f'/{tile}' + f'/{year}_{tile}_patch_{str(x_i).zfill(2)}_{str(y_i).zfill(2)}.nc')
151
+ root_paths.append(downloaded_paths)
 
 
 
152
 
153
+ elif self.config.name == 'cat_2020':
154
+ year = '2020'
155
+ for tile in CAT_TILES:
156
+ x, y = PATCH_IDX[year][tile]
157
+ for x_i in range(x + 1):
158
+ for y_i in range(y + 1):
159
+ downloaded_paths = dl_manager.download(_URL + f'/{year}' + f'/{tile}' + f'/{year}_{tile}_patch_{str(x_i).zfill(2)}_{str(y_i).zfill(2)}.nc')
160
+ root_paths.append(downloaded_paths):
161
 
162
+ elif self.config.name == 'fr_2019':
163
+ year = '2019'
164
+ for tile in FR_TILES:
165
+ x, y = PATCH_IDX[year][tile]
166
+ for x_i in range(x + 1):
167
+ for y_i in range(y + 1):
168
+ downloaded_paths = dl_manager.download(_URL + f'/{year}' + f'/{tile}' + f'/{year}_{tile}_patch_{str(x_i).zfill(2)}_{str(y_i).zfill(2)}.nc')
169
+ root_paths.append(downloaded_paths):
170
 
171
+ return [
172
  datasets.SplitGenerator(
173
+ name='self.config.name',
174
  # These kwargs will be passed to _generate_examples
175
  gen_kwargs={
176
  "root_paths": root_paths,
 
182
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
183
  def _generate_examples(self, root_paths):
184
  for file in root_paths:
185
+ netcdf = netCDF4.Dataset(file)
186
 
187
  res = {
188
+ "patch_full_name": netcdf.patch_full_name,
189
+ "patch_year": netcdf.patch_year,
190
+ "patch_name": netcdf.patch_name,
191
+ "patch_country_code": netcdf.patch_country_code,
192
+ "patch_tile": netcdf.patch_tile
193
  }
194
 
195
  time_recorded = False
196
 
197
  for variable in ['B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B09', 'B10', 'B11', 'B12', 'B8A', 'labels', 'parcels']:
198
+ v = xr.open_dataset(xr.backends.NetCDF4DataStore(netcdf[variable]))
199
  if not time_recorded:
200
  res['timestamp'] = (v.time.values.astype(np.int64) // 10 ** 9).tolist()
201
  time_recorded = True