Skip to content

Cliimatology bounds are not read as datetime #36

@rafaqz

Description

@rafaqz

Seems we just need to use the units of the variable linked with the "climatology" attribute.

Here is an ncgen that demonstrates the problem. climatology_bounds variable will be read in as Float64 rather than DateTime

netcdf climatological_seasons {
dimensions:
  time=4;
  nv=2;
  lat=10; // added
  lon=10; // added
variables:
  float temperature(time,lat,lon);
    temperature:long_name="surface air temperature";
    temperature:cell_methods="time: minimum within years time: mean over years";
    temperature:units="K";
  double time(time);
    time:climatology="climatology_bounds";
    time:units="days since 1960-1-1";
  double climatology_bounds(time,nv);
data:  // time coordinates translated to datetime format
  time="1960-4-16", "1960-7-16", "1960-10-16", "1961-1-16" ;
  climatology_bounds="1960-3-1",  "1990-6-1",
                     "1960-6-1",  "1990-9-1",
                     "1960-9-1",  "1990-12-1",
                     "1960-12-1", "1991-3-1" ;    
}

If you save that as climatological_seasons.ncgen and run:

using NCDatasets
using NCDatasets.NetCDF_jll

NetCDF_jll.ncgen() do exe
    run(`$exe -k nc4 -b -o clim.nc climatological_seasons.ncgen`)
end

Then load the file with NCDataset, you get a Float64 eltype for "climatology_bounds"

julia> NCDataset("clim.nc")
Dataset: clim.nc
Group: /

Dimensions
   time = 4
   nv = 2
   lat = 10
   lon = 10

Variables
  temperature   (10 × 10 × 4)
    Datatype:    Float32 (Float32)
    Dimensions:  lon × lat × time
    Attributes:
     long_name            = surface air temperature
     cell_methods         = time: minimum within years time: mean over years
     units                = K

  time   (4)
    Datatype:    DateTime (Float64)
    Dimensions:  time
    Attributes:
     climatology          = climatology_bounds
     units                = days since 1960-1-1

  climatology_bounds   (2 × 4)
    Datatype:    Float64 (Float64)
    Dimensions:  nv × time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions