Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2824 closed defect (fixed)

g.gui.timeline throws exception when trying to display temporal dataset.

Reported by: pmav99 Owned by: grass-dev@…
Priority: normal Milestone: 7.0.3
Component: wxGUI Version: 7.0.1
Keywords: g.gui.timeline Cc:
CPU: Unspecified Platform: Unspecified

Description

I was trying to follow the temporal workshop and I am getting the following exception:

GRASS 7.0.1 (NC_spm_temporal_workshop):~/repo > g.gui.timeline tempmean
Traceback (most recent call last):
  File "/usr/lib/grass70/scripts/g.gui.timeline", line 64, in <module>
    main()
  File "/usr/lib/grass70/scripts/g.gui.timeline", line 57, in main
    frame.SetDatasets(datasets)
  File "/usr/lib/grass70/gui/wxpython/timeline/frame.py", line 444, in SetDatasets
    self._redraw()
  File "/usr/lib/grass70/gui/wxpython/timeline/frame.py", line 364, in _redraw
    self._draw2dFigure()
  File "/usr/lib/grass70/gui/wxpython/timeline/frame.py", line 316, in _draw2dFigure
    facecolors=color, alpha=ALPHA))
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 1811, in inner
    return func(ax, *args, **kwargs)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 2339, in broken_barh
    xranges = self.convert_xunits(xranges)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/matplotlib/artist.py", line 189, in convert_xunits
    return ax.xaxis.convert_units(x)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/matplotlib/axis.py", line 1442, in convert_units
    ret = self.converter.convert(x, self.units, self)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/matplotlib/dates.py", line 1553, in convert
    return date2num(value)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/matplotlib/dates.py", line 380, in date2num
    return _to_ordinalf_np_vectorized(d)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/numpy/lib/function_base.py", line 1573, in __call__
    return self._vectorize_call(func=func, args=vargs)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/numpy/lib/function_base.py", line 1633, in _vectorize_call
    ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/numpy/lib/function_base.py", line 1597, in _get_ufunc_and_otypes
    outputs = func(*inputs)
  File "/home/grassuser/venv/local/lib/python2.7/site-packages/matplotlib/dates.py", line 221, in _to_ordinalf
    base = float(dt.toordinal())
AttributeError: 'numpy.float64' object has no attribute 'toordinal'

workshop link: http://ncsu-osgeorel.github.io/grass-temporal-workshop/

Change History (16)

comment:1 by wenzeslaus, 9 years ago

Comment on a SO answer says:

It sounds like you're calling date2num on a float. date2num expects datetime objects. ...appears to already be in exactly the format that date2num would be converting it do. Replace date2num(time) with just time...

But I'm not sure if this applies in this case. That one was related to some particular NetCDF file.

comment:2 by wenzeslaus, 9 years ago

I'm not getting this error when I try on the full NC sample dataset:

g.region raster=elev_lid792_1m res=4
r.sun.hourly elevation=elev_lid792_1m glob_rad_basename=rad \
  start_time=5 end_time=10 year=2005 day=255 time_step=1 -t
g.gui.timeline rad

(year=2005 is there to create dataset with absolute time.)

Tested on 64bit Linux machine. My versions of numpy and matplotlib are the following:

>>> import numpy
>>> numpy.__version__
'1.8.2'
>>> import matplotlib
>>> matplotlib.__version__
'1.4.2'

Please run python in GRASS session and get the versions as well. Check also that the Python version is 2.7.

comment:3 by annakrat, 9 years ago

Something changed in 1.5 matplotlib version. I tried to fix it in r67069. It would be great if we can get it tested with more versions of matplotlib.

comment:4 by veroandreo, 9 years ago

g.gui.timeline works without errors for me with:

>>> import numpy
>>> numpy.__version__
'1.9.2'
>>> import matplotlib
>>> matplotlib.__version__
'1.4.3'

Python is 2.7.10 and I'm using grass 7.1 r67001

comment:5 by annakrat, 9 years ago

Waiting for testing to get it backported.

comment:6 by neteler, 9 years ago

Just tried trunk, with the original dataset:

Invalid input data

Reason: Space time dataset <tempmean> not found.

Traceback (most recent call last):
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/gui/wxpython/timeline/frame.py", line 444, in SetDatasets
    datasets = self._checkDatasets(datasets)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/gui/wxpython/timeline/frame.py", line 414, in _checkDatasets
    raise GException(errorMsg)
GException: Space time dataset <tempmean> not found.

Maybe a try - except could be still added for beautification.

in reply to:  6 ; comment:7 by annakrat, 9 years ago

Replying to neteler:

Just tried trunk, with the original dataset:

Invalid input data

Reason: Space time dataset <tempmean> not found.

Traceback (most recent call last):
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/gui/wxpython/timeline/frame.py", line 444, in SetDatasets
    datasets = self._checkDatasets(datasets)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/gui/wxpython/timeline/frame.py", line 414, in _checkDatasets
    raise GException(errorMsg)
GException: Space time dataset <tempmean> not found.

Maybe a try - except could be still added for beautification.

There is already try except, do you want to hide the traceback? But this is unrelated to the problem, is it working if you specify a correct dataset?

in reply to:  7 ; comment:8 by neteler, 9 years ago

Replying to annakrat:

There is already try except, do you want to hide the traceback?

Yes.

But this is unrelated to the problem, is it working if you specify a correct dataset?

Ok, if the dataset was created but is yet empty (simulating a new user or so here):

GRASS 7.1.svn (NC_spm_temporal_workshop):~ > g.gui.timeline tempmean
Traceback (most recent call last):
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/scripts/g.gui.timeline", line 64, in <module>
    main()
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/scripts/g.gui.timeline", line 57, in main
    frame.SetDatasets(datasets)
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/gui/wxpython/timeline/frame.py", line 452, in SetDatasets
    self._redraw()
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/gui/wxpython/timeline/frame.py", line 366, in _redraw
    self._draw2dFigure()
  File "/home/neteler/software/grass71/dist.x86_64-pc-linux-gnu/gui/wxpython/timeline/frame.py", line 322, in _draw2dFigure
    self.fig.autofmt_xdate()
  File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 447, in autofmt_xdate
    for label in self.axes[0].get_xticklabels():
  File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_base.py", line 2661, in get_xticklabels
    which=which))
  File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1214, in get_ticklabels
    return self.get_majorticklabels()
  File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1168, in get_majorticklabels
    ticks = self.get_major_ticks()
  File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1297, in get_major_ticks
    numticks = len(self.get_major_locator()())
  File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 866, in __call__
    self.refresh()
  File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 883, in refresh
    dmin, dmax = self.viewlim_to_dt()
  File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 627, in viewlim_to_dt
    return num2date(vmin, self.tz), num2date(vmax, self.tz)
  File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 345, in num2date
    return _from_ordinalf(x, tz)
  File "/usr/lib64/python2.7/site-packages/matplotlib/dates.py", line 225, in _from_ordinalf
    dt = datetime.datetime.fromordinal(ix)
ValueError: ordinal must be >= 1

... sure, a user error but perhaps worthwhile catching it, too.

Then I filled "tempmean" with content, i.e. I used t.register. Now

g.gui.timeline tempmean

works fine.

in reply to:  8 ; comment:9 by annakrat, 9 years ago

Replying to neteler:

Then I filled "tempmean" with content, i.e. I used t.register. Now

g.gui.timeline tempmean

works fine.

Just for the record, your version of matplotlib is?

in reply to:  9 comment:10 by neteler, 9 years ago

Replying to annakrat:

Just for the record, your version of matplotlib is?

It is

python-matplotlib-wx-1.4.3-6.fc23.x86_64

in reply to:  8 comment:11 by annakrat, 9 years ago

Replying to neteler:

Replying to annakrat:

There is already try except, do you want to hide the traceback?

Yes.

Done in r67324.

Ok, if the dataset was created but is yet empty (simulating a new user or so here):

... sure, a user error but perhaps worthwhile catching it, too.

Done in r67325. It's probably safe but if you could test it before backporitng, that would be helpful.

comment:12 by neteler, 9 years ago

Tested in trunk, now all good.

comment:13 by annakrat, 9 years ago

Resolution: fixed
Status: newclosed

All backported in r67346. Nobody except for me tested the change with new matplotlib version, so please reopen if needed.

comment:14 by pmav99, 9 years ago

Sorry for not providing feedback earlier but i was working on non-GRASS related things. I just tested 7.0.3svn (r67414) with both matplotlib 1.3.1 (from ubuntu repositories) and matplotlib 1.5.0 (from pypi) and everything seems to work fine.

in reply to:  14 ; comment:15 by annakrat, 9 years ago

Replying to pmav99:

Sorry for not providing feedback earlier but i was working on non-GRASS related things. I just tested 7.0.3svn (r67414) with both matplotlib 1.3.1 (from ubuntu repositories) and matplotlib 1.5.0 (from pypi) and everything seems to work fine.

Thanks! I wonder if g.gui.tplot needs to be fixed as well? Have you tried that?

in reply to:  15 comment:16 by pmav99, 9 years ago

Replying to annakrat:

Thanks! I wonder if g.gui.tplot needs to be fixed as well? Have you tried that?

Just tried g.gui.tplot and it works fine with both matplotlib==1.3.1 and matplotlib==1.5.0

Note: See TracTickets for help on using tickets.