Datasets:

ArXiv:
paren8esis commited on
Commit
d1d8c4b
1 Parent(s): c0a94a4

Open netcdf file with dask

Browse files
Files changed (1) hide show
  1. S4A.py +8 -7
S4A.py CHANGED
@@ -16,6 +16,7 @@
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
@@ -172,20 +173,20 @@ class S4A(datasets.GeneratorBasedBuilder):
172
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
173
  def _generate_examples(self, root_paths):
174
  for file in root_paths:
175
- netcdf = netCDF4.Dataset(file)
176
 
177
  res = {
178
- "patch_full_name": netcdf.patch_full_name,
179
- "patch_year": netcdf.patch_year,
180
- "patch_name": netcdf.patch_name,
181
- "patch_country_code": netcdf.patch_country_code,
182
- "patch_tile": netcdf.patch_tile
183
  }
184
 
185
  time_recorded = False
186
 
187
  for variable in ['B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B09', 'B10', 'B11', 'B12', 'B8A', 'labels', 'parcels']:
188
- v = xr.open_dataset(xr.backends.NetCDF4DataStore(netcdf[variable]))
189
  if not time_recorded:
190
  res['timestamp'] = (v.time.values.astype(np.int64) // 10 ** 9).tolist()
191
  time_recorded = True
 
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
 
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', groups=variable)
190
  if not time_recorded:
191
  res['timestamp'] = (v.time.values.astype(np.int64) // 10 ** 9).tolist()
192
  time_recorded = True