question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Choose time units in output netcdf

See original GitHub issue

Is there any way to define the units in output netcdf created from to_netcdf method without having to manually convert the time objects into floats for example? It could maybe be handy if the units attribute of time coordinate could be modified and the modified value (if CF-compliant) used for encoding time in the output netcdf. Currently, to_netcdf raises ValueError: Failed hard to prevent overwriting key 'units' if the attribute is modified.

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rvalenzuelarcommented, Dec 4, 2017

Hello,

I’m having similar issues. However, I’m creating a dataset from a dict (data are packed in Matlab file).

The dataset is ds_ivt and I have tried:

ds_ivt.time.encode['units'] = 'days since 1900-01-01'

and

ds_ivt.to_netcdf('ds_ivt.nc',encoding={'time':{'units':'days since 1900-01-01'}})

The .info() method retrieves:

ds_ivt.info()
xarray.Dataset {
dimensions:
	lat = 161 ;
	lon = 291 ;
	time = 1460 ;
variables:
	float32 lat(lat) ;
		lat:units = degrees ;
	float32 lon(lon) ;
		lon:units = degrees ;
	datetime64[ns] time(time) ;
		time:units = days since 1900-01-01 ;
	float32 iqu(time, lat, lon) ;
		iqu:units = kg m-1 s-1 ;
	float32 iqv(time, lat, lon) ;
		iqv:units = kg m-1 s-1 ;
// global attributes:
}
0reactions
stale[bot]commented, Nov 4, 2019

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

Read more comments on GitHub >

github_iconTop Results From Across the Web

need help setting time units correctly - SourceForge
Hi all,. I'm a newbie at NCO and netcdf. What i'm trying to do seemed fairly simple. I have to pacth together a...
Read more >
how to change the unit of time variable in NetCdf files using ...
I usually have a code like this: import numpy as np import os, subprocess from netCDF4 import num2date,date2num,Dataset ...
Read more >
Date and time manipulations with CDO - Declan Valters
I have a netcdf file that contains a time variable. The values in the variable's data array represent time units since date time...
Read more >
The Components of a NetCDF Data Set
The first three are assigned fixed lengths; time is assigned the length UNLIMITED, which means it is the unlimited dimension. The basic unit...
Read more >
Working with NetCDF data - Chad A. Greene
Select times 00:00:00, 12 step, and the fields 2 m temperature, ... variable in the NetCDF file, and also includes notes about the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found