7

Our use case is to make a time-stacked NetCDF file accessible via Open Data Cube.

Each NetCDF file (CMEMS data) has a time coordinate variable, with 8 time points evenly distributed over a range of one day. When trying to datacube.Datacube().load() such a NetCDF file, the following error arises:

Error opening source dataset: NETCDF:"C:\CMEMS\mfwamglocep_2021013000_R20210122_mini.nc":VHM0
Traceback (most recent call last):
...
DeprecationWarning: Stacked netcdf without explicit time index is not supported anymore

How to achieve such an "explicit time index"?

Regarding indexing, it seems that such a time-stacked NetCDF file has to be covered by 8 time-specific dataset definition files (according to an issue discussion), but how to provide the specific time index?


Used resources:

• Open Data Cube version:

(cubeenv) C:\> datacube --version
Open Data Cube core, version 1.8.3

• Product definition:

name: mfwamglocep_mini
description: GLOBAL_ANALYSIS_FORECAST_WAV_001_027
metadata_type: eo

metadata:
  format:
    name: NETCDF
  instrument:
    name: NA
  platform:
    code: NA
  product_type: mfwamglocep_mini

storage:
  crs: EPSG:4326
  resolution:
          longitude: 0.08332825
          latitude: -0.08333588

measurements:
- name: VHM0
  dtype: float32
  units: m
  nodata: -32767
  add_offset: 0.0
  scale_factor: 0.01
- name: VMDR
  dtype: float32
  units: degree
  nodata: -32767
  add_offset: 180.0
  scale_factor: 0.01

• Dataset definition:

creation_dt: '2021-01-22T08:19:00Z'
extent:
  center_dt: '2021-01-30T13:30:00Z'
  coord:
    ll: {lon: -180, lat: -80}
    lr: {lon: 179.9167, lat: -80}
    ul: {lon: -180, lat: 90}
    ur: {lon: 179.9167, lat: 90}
  from_dt: '2021-01-30T03:00:00Z'
  to_dt: '2021-01-31T00:00:00Z'
format: {name: NETCDF}
grid_spatial:
  projection:
    geo_ref_points:
      ll: {x: -180, y: -80}
      lr: {x: 179.9167, y: -80}
      ul: {x: -180, y: 90}
      ur: {x: 179.9167, y: 90}
    spatial_reference: EPSG:4326
id: 272302c9-1449-4a33-8166-4b6083a8a711
image:
  bands:
    VHM0: {path: mfwamglocep_2021013000_R20210122_mini.nc, layer: VHM0}
    VMDR: {path: mfwamglocep_2021013000_R20210122_mini.nc, layer: VMDR}
instrument: {name: NA}
lineage:
  source_datasets: {}
product_type: mfwamglocep_mini
platform: {code: NA}

Original NetCDF file, reduced to a publicly downloadable small subset (86 MB):

import xarray
ds = xarray.open_dataset("mfwamglocep_2021013000_R20210122.nc")
to_drop = []
for name in ds.data_vars:
  if name!="VHM0" and name!="VMDR": to_drop.append(name)
mini = ds.drop_vars(to_drop)
mini.to_netcdf("mfwamglocep_2021013000_R20210122_mini.nc")

1 Answer 1

2

An explicit time index can be achieved by appending a fragment (#part=<index>) to the uri in the path attribute of the metadata document. It starts from 0. The uri also needs to start with file://. In your case

image:
  bands:
    VHM0: {path: file://mfwamglocep_2021013000_R20210122_mini.nc#part=0, layer: VHM0}
    VMDR: {path: file://mfwamglocep_2021013000_R20210122_mini.nc#part=0, layer: VMDR}

should work for the first time slice. As far as I know you need to create a separate dataset document for each time slice (updating also the time stamps in the extent attribute).

The approach was extracted from here https://github.com/opendatacube/datacube-core/commit/5723c040fc5aeacc638756ea21e395d491202bf8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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