[GRASS-dev] [GRASS GIS] #2824: g.gui.timeline throws exception when trying to display temporal dataset.

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
----------------------------+-------------------------
Reporter: pmav99 | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Keywords: g.gui.timeline | CPU: Unspecified
Platform: Unspecified |
----------------------------+-------------------------
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/

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by wenzeslaus):

[http://stackoverflow.com/questions/32788554/plotting-with-date-times-and-
matplotlib 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by wenzeslaus):

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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by annakrat):

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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by veroandreo):

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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by annakrat):

Waiting for testing to get it backported.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:6&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by annakrat):

Replying to [comment:6 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?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:7&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by neteler):

Replying to [comment:7 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:8&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by annakrat):

Replying to [comment:8 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?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:9&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by neteler):

Replying to [comment:9 annakrat]:
> Just for the record, your version of matplotlib is?

It is

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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:10&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by annakrat):

Replying to [comment:8 neteler]:
> Replying to [comment:7 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.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2824#comment:11&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by neteler):

Tested in trunk, now all good.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:12&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: fixed | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------
Changes (by annakrat):

* status: new => closed
* resolution: => fixed

Comment:

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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:13&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: fixed | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:14&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: fixed | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by annakrat):

Replying to [comment:14 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?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:15&gt;
GRASS GIS <https://grass.osgeo.org>

#2824: g.gui.timeline throws exception when trying to display temporal dataset.
--------------------------+----------------------------
  Reporter: pmav99 | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.0.3
Component: wxGUI | Version: 7.0.1
Resolution: fixed | Keywords: g.gui.timeline
       CPU: Unspecified | Platform: Unspecified
--------------------------+----------------------------

Comment (by pmav99):

Replying to [comment:15 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`

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2824#comment:16&gt;
GRASS GIS <https://grass.osgeo.org>