[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #FBV-147683]: netCDF4-python date issue



Greetings!

Sorry for the delayed response, it took a little bit for your ticket to reach 
the right department. The support address you're looking for is support-python. 
You might also consider in the future opening a ticket at:

https://github.com/Unidata/netcdf4-python/issues/new

So that Jeff Whitaker, the maintainer of netcdf4-python might chime in.

Onto your problem...that's a real head-scratcher. The date unit is a little 
odd, but should be legal. I tried reproducing manually with the num2date 
function and some quick generated values and the unit string you gave, but it 
worked fine for me. Can you point me to the file so I can dig in further?

Thanks,

Ryan

> Hi folks,
> 
> First, I know, I know.  I'm probably going to screw up the entire support 
> tracking system at Unidata, but there is not (yet) a specific netCDF4-python 
> support email address that I could find, so I used both netCDF and python 
> instead. Tom Y. always tells me that everyone sees the support tickets and 
> passes them on to the correct person, if it's in the wrong place, but 
> sometimes I feel like a belts-and-suspenders approach is warranted.
> 
> Okay, so here's the real issue. I'm trying to convert netCDF dates to 
> something I can deal with. However, I am getting the following error (I added 
> in the 2 lines preceding the one python returned, so you could see the entire 
> statement):
> Traceback (most recent call last):
> File "CORDEX_CI.py", line 522, in <module>
> dates = netCDF4.num2date(CORDEX_pr.variables['time'][:],
> CORDEX_pr.variables['time'].units,
> calendar=CORDEX_pr.variables['time'].calendar)
> File "cftime/_cftime.pyx", line 290, in cftime._cftime.num2date
> File "cftime/_cftime.pyx", line 1211, in cftime._cftime.utime.num2date
> File "/opt/anaconda3/lib/python3.5/site-packages/numpy/core/fromnumeric.py", 
> line 257, in reshape
> return _wrapfunc(a, 'reshape', newshape, order=order)
> File "/opt/anaconda3/lib/python3.5/site-packages/numpy/core/fromnumeric.py", 
> line 52, in _wrapfunc
> return getattr(obj, method)(*args, **kwds)
> ValueError: cannot reshape array of size 1 into shape (20819,)
> 
> Since I had just run the same code on a different file from the same source, 
> I was perplexed, as ncdump had no problem reading either file and spitting 
> out the time variable in human-readable format. I finally realized that the 
> units were
> "days since 1949-12-1 00:00:00"
> but the first time was 1949-01-01 (stored "correctly" as -333.5 in the file). 
>  I confirmed that this was the cause of the error, as I was able to read the 
> file if I simply added 334 to the values and changed the units to "days since 
> 1949-01-01 00:00:00". Even easier, since I don't really want data from before 
> 1950-01-01, I can simply read starting at index 365.
> 
> So, the question remains, why would anyone want to have units starting after 
> the beginning of the dataset?  I can't answer that question, as I didn't 
> create the dataset, but perhaps it would be a good idea for netCDF4-python to 
> allow for the possibility that one or more datasets have been compiled in 
> this way.


Ticket Details
===================
Ticket ID: FBV-147683
Department: Support Python
Priority: High
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.