0

I'm trying to index and load a time-stacked NetCDF file with OpenDataCube . Product Definition and Dataset.yaml files get from the link: How to index and load a time-stacked NetCDF file with Open Data Cube? . When query with the data get this error :


query = {
    "latitude": (-35.45, -35.44),
    "longitude": (149.0, 149.01),
    "output_crs": "EPSG:4326",
    "resolution": (0.00027778, -0.00027778),
}

data = dc.load(product='mfwamglocep_mini', **query)
print(data)
Error opening source dataset: NETCDF:"/localdata/mfwamglocep_2021013000_R20210122_mini.nc":VHM0


----------
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[15], line 8
      1 query = {
      2     "latitude": (-35.45, -35.44),
      3     "longitude": (149.0, 149.01),
      4     "output_crs": "EPSG:4326",
      5     "resolution": (0.00027778, -0.00027778),
      6 }
----> 8 data = dc.load(product='mfwamglocep_mini', **query)
      9 print(data)

File /usr/local/lib/python3.10/dist-packages/datacube/api/core.py:456, in Datacube.load(self, product, measurements, output_crs, resolution, resampling, skip_broken_datasets, dask_chunks, like, fuse_func, align, datasets, dataset_predicate, progress_cbk, patch_url, **query)
    452 measurement_dicts = datacube_product.lookup_measurements(measurements)
    454 # `extra_dims` put last for backwards compability, but should really be the second position
    455 # betwween `grouped` and `geobox`
--> 456 result = self.load_data(grouped, geobox,
    457                         measurement_dicts,
    458                         resampling=resampling,
    459                         fuse_func=fuse_func,
    460                         dask_chunks=dask_chunks,
    461                         skip_broken_datasets=skip_broken_datasets,
    462                         progress_cbk=progress_cbk,
    463                         extra_dims=extra_dims,
    464                         patch_url=patch_url)
    466 return result

File /usr/local/lib/python3.10/dist-packages/datacube/api/core.py:814, in Datacube.load_data(sources, geobox, measurements, resampling, fuse_func, dask_chunks, skip_broken_datasets, progress_cbk, extra_dims, patch_url, **extra)
    809     return Datacube._dask_load(sources, geobox, measurements, dask_chunks,
    810                                skip_broken_datasets=skip_broken_datasets,
    811                                extra_dims=extra_dims,
    812                                patch_url=patch_url)
    813 else:
--> 814     return Datacube._xr_load(sources, geobox, measurements,
    815                              skip_broken_datasets=skip_broken_datasets,
    816                              progress_cbk=progress_cbk,
    817                              extra_dims=extra_dims,
    818                              patch_url=patch_url)

File /usr/local/lib/python3.10/dist-packages/datacube/api/core.py:742, in Datacube._xr_load(sources, geobox, measurements, skip_broken_datasets, progress_cbk, extra_dims, patch_url)
    740 data_slice = data[m.name].values[index]
    741 try:
--> 742     _fuse_measurement(data_slice, datasets, geobox, m,
    743                       skip_broken_datasets=skip_broken_datasets,
    744                       progress_cbk=_cbk, extra_dim_index=extra_dim_index,
    745                       patch_url=patch_url)
    746 except (TerminateCurrentLoad, KeyboardInterrupt):
    747     data.attrs['dc_partial_load'] = True

File /usr/local/lib/python3.10/dist-packages/datacube/api/core.py:972, in _fuse_measurement(dest, datasets, geobox, measurement, skip_broken_datasets, progress_cbk, extra_dim_index, patch_url)
    969     else:
    970         srcs.append(src)
--> 972 reproject_and_fuse(srcs,
    973                    dest,
    974                    geobox,
    975                    dest.dtype.type(measurement.nodata),
    976                    resampling=measurement.get('resampling_method', 'nearest'),
    977                    fuse_func=measurement.get('fuser', None),
    978                    skip_broken_datasets=skip_broken_datasets,
    979                    progress_cbk=progress_cbk,
    980                    extra_dim_index=extra_dim_index)

File /usr/local/lib/python3.10/dist-packages/datacube/storage/_load.py:77, in reproject_and_fuse(datasources, destination, dst_gbox, dst_nodata, resampling, fuse_func, skip_broken_datasets, progress_cbk, extra_dim_index)
     75 elif len(datasources) == 1:
     76     with ignore_exceptions_if(skip_broken_datasets):
---> 77         with datasources[0].open() as rdr:
     78             read_time_slice(rdr, destination, dst_gbox, resampling, dst_nodata, extra_dim_index)
     80     if progress_cbk:

File /usr/lib/python3.10/contextlib.py:135, in _GeneratorContextManager.__enter__(self)
    133 del self.args, self.kwds, self.func
    134 try:
--> 135     return next(self.gen)
    136 except StopIteration:
    137     raise RuntimeError("generator didn't yield") from None

File /usr/local/lib/python3.10/dist-packages/datacube/storage/_rio.py:146, in RasterioDataSource.open(self)
    144 except Exception as e:
    145     _LOG.error("Error opening source dataset: %s", self.filename)
--> 146     raise e
    147 finally:
    148     if locked:

File /usr/local/lib/python3.10/dist-packages/datacube/storage/_rio.py:141, in RasterioDataSource.open(self)
    138             lock.release()
    140         if override:
--> 141             raise RuntimeError(f'Broken/missing geospatial data was found in file "{self.filename}"')
    142         yield BandDataSource(band, nodata=nodata, lock=lock)
    144 except Exception as e:

RuntimeError: Broken/missing geospatial data was found in file "NETCDF:"/localdata/mfwamglocep_2021013000_R20210122_mini.nc":VHM0"

2 Answers 2

0

You can check if your NetCDF file has the necessary CRS information by using gdalinfo or ncdump:

gdalinfo /localdata/mfwamglocep_2021013000_R20210122_mini.nc

ncdump -h /localdata/mfwamglocep_2021013000_R20210122_mini.nc

If it doesn't, you can write it, e.g., using Python packages xarray and rioxarray:

import xarray

dataset = xarray.open_dataset("/localdata/mfwamglocep_2021013000_R20210122_mini.nc")
dataset.rio.write_crs(4326, inplace=True)
dataset.to_netcdf("/localdata/mfwamglocep_2021013000_R20210122_mini_with_crs.nc")
1
  • thank you so much , you made my day , this is a final project for me (as a student) before graduation. once again thank you so much . have a great day sir .
    – Thành Duy
    Commented Aug 28 at 15:19
0

Looking at the source code, this error means one of two things:

a) Rasterio could not extract a spatial transform from the file, or b) Rasterio could not extract a CRS from the file.

1
  • maybe the file dataset.yaml is wrong , i'm new to opendatacube (cube-in-the-box) ., do you have an example for writing and indexing netcdf data ? Thankyou
    – Thành Duy
    Commented Aug 28 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.