Skip to content

Fix Time Formatting in NetCDF output #14

@larantt

Description

@larantt

Hi devs!

I noticed a small bug in the time units that make them non-cf compliant and therefore unreadable by xarray.

The time units use all underscores as can be seen here:

netcdf hydro_2021-09-01_13_00_00 {
dimensions:
        LinkID = 6531 ;
        time = 288 ;
variables:
        int LinkID(LinkID) ;
                LinkID:long_name = "ID associated with each stream link" ;
        int time(time) ;
                time:long_name = "Time" ;
                time:units = "minutes since 2021-09-01_13_00_00" ;
                time:calendar = "julian" ;
        float outputs(time, LinkID) ;
                outputs:long_name = "Discharge" ;
                outputs:units = "m^3/s" ;
}

but xarray is unable to decode this properly and it drops the hours. I was able to fix it in xarray with the following line, but I was wondering if it would be easy to fix in the code?

ds['time'] = pd.to_timedelta(ds['time'].values, unit='m') + pd.Timestamp('2021-09-01 13:00:00')

Thanks for your help and for this awesome model!
Lara

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