TransWikia.com

Time encoding for xarray to netCDF

Geographic Information Systems Asked on June 17, 2021

While looking at this webpage, it seems there is an inconsistency for the time units handling.

Copying and pasting from the webpage:

from cftime import date2num
time_units = 'hours since {:%Y-%m-%d 00:00}'.format(times[0])
time_vals = date2num(times, time_units)

ds = xr.Dataset({'temperature': (['time', 'z', 'y', 'x'], temps, {'units':'Kelvin'})},
                 coords={'x_dist': (['x'], x, {'units':'km'}),
                         'y_dist': (['y'], y, {'units':'km'}),
                         'pressure': (['z'], press, {'units':'hPa'}),
                         'forecast_time': (['time'], times)
                })

ds.forecast_time.encoding['units'] = time_units

hence it seems that time_vals and not times should be assigned to forecast_time.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP