Re: [Matplotlib-users] creating mesh data from xyz data
Hi list, I have some files with data stored in columns: x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4 x5 y5 z5 ... and I need to make a contour plot of this data using matplotlib. The problem is that contour plot functions usually handle a different kind of input: X=[[x1,x2,x3,x4,x5,x6], [x1,x2,x3,x4,x5,x6], [x1,x2,x3,x4,x5,x6],... Y=[[y1,y1,y1,y1,y1,y1], [y2,y2,y2,y2,y2,y2], [y3,y3,y3,y3,y3,y3],. Z=[[z1,z2,z3,z4,z5,z6], [z7,z8,zz9,z10,z11,z12], I usually load data using 3 lists: x, y and z; I wonder if there is any function which is able to take these 3 lists and return the right input for matplotlib functions. cheers giuseppe -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] creating mesh data from xyz data
Hi Giuseppe
you can load your datafile with pylab... see my little function which
i'm using
import pylab as pl
def readXY(filename):
x,y,z = pl.load(filename, unpack=True)
return x,y,z
(X, Y, Z) = readXY("datafile.dat")
after that you have your values in the arrays X;Y;Z
kind regards
Giuseppe Aprea wrote:
> Hi list,
>
> I have some files with data stored in columns:
>
> x1 y1 z1
> x2 y2 z2
> x3 y3 z3
> x4 y4 z4
> x5 y5 z5
> ...
>
> and I need to make a contour plot of this data using matplotlib. The
> problem is that contour plot functions usually handle a different kind
> of input:
>
> X=[[x1,x2,x3,x4,x5,x6],
> [x1,x2,x3,x4,x5,x6],
> [x1,x2,x3,x4,x5,x6],...
>
> Y=[[y1,y1,y1,y1,y1,y1],
> [y2,y2,y2,y2,y2,y2],
> [y3,y3,y3,y3,y3,y3],.
>
> Z=[[z1,z2,z3,z4,z5,z6],
> [z7,z8,zz9,z10,z11,z12],
>
> I usually load data using 3 lists: x, y and z; I wonder if there is
> any function which is able to take these 3 lists and return the right
> input for matplotlib functions.
>
> cheers
>
> giuseppe
>
> --
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> ___
> Matplotlib-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] mpl 0.99 and py2exe
I have run into a bit of problem using 0.99 and py2exe. I am getting errors "TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'" in mlab.pyo after py2exe'd my application. This is caused by this type of code, as one normally uses the optimize option with py2exe which means that the docs are stripped from the .pyo files. "psd.__doc__ = psd.__doc__ % kwdocd" I changed it to: if psd.__doc__ is not None: psd.__doc__ = psd.__doc__ % kwdocd else: psd.__doc__ = "" Above is a bit of a hack, if someone can suggest how to correct this in a way which would get accepted as a patch I would search all modules correct them. Werner -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] grid on log-plots
I can not try your revision but I will do it as soon as it is released.
Nervertheless I try your snippet with an AxesZero. I get the gridlines
and the axis but the first was over the second. It is not what I expected.
As far as I am concerned, I can wait until matplotlib next release.
Thanks,
Yann
On 09/08/2009 08:13 PM, Jae-Joon Lee wrote:
> On Tue, Sep 8, 2009 at 11:51 AM, Yann
> Goudard wrote:
>
>> Hi,
>>
>> I have the same behaviour with LocatableAxes. HostAxes, ParasiteAxes and
>> LocatableAxes depend on 'mpl_toolkits.axes_grid.axislines.Axes'. It must
>> be the matter origin.
>>
> Yes, and this was because I forgot to implement some necessary methods.
> This is now fixed in the svn trunk. So if you can,please give it a try.
>
>
>> This another example should draw a grid but does not:
>>
>> import wx
>> from wx import Frame
>> from matplotlib.backends.backend_wxagg import FigureFrameWxAgg,
>> FigureCanvasWxAgg
>> from matplotlib.figure import Figure
>> from mpl_toolkits.axes_grid.axes_divider import LocatableAxes
>>
>> fig = Figure((1, 1), 50)
>> axes = LocatableAxes(fig, [0, 0, 1, 1])
>> # axes.toggle_axisline(False)
>> axes.grid(True)
>> fig.add_axes(axes)
>>
>> app = wx.PySimpleApp()
>> my_viewer = FigureFrameWxAgg(-1, fig)
>> my_viewer.Show()
>> app.MainLoop()
>>
>> If you uncomment axes.toggle_axisline(False), it works cause it uses
>> normal 'matplolib.axes.Axes' behaviour. It is not a matter for common
>> use but if you need 'AxesZero', this trick does not work.
>>
> What the toggle_axisline does is simply to make the xaxis and yaxis
> (which are responsible for drawing ticks, ticklabels, etc in the
> mainline mpl) visible again, and make axis["bottom"] and etc
> invisible.
> One workaround is to make xaxis and yaxis visible but pnly to draw the
> gridlines. Something like below.
>
> ax.toggle_axisline(True)
> ax.grid(True)
> ax.gridlines.set_visible(False) # this is just to make the code not to
> draw gridlines twice in future release of mpl.
> ax.xaxis.set_visible(True)
> ax.yaxis.set_visible(True)
> for t in ax.xaxis.majorTicks + ax.yaxis.majorTicks:
> t.gridOn = True
> t.tick1On = False
> t.tick2On = False
> t.label1On = False
> t.label2On = False
>
> Let me know if this does not work, or there is a case that this cannot be
> used.
> Regards,
>
> -JJ
>
>
>
>> Yann
>>
>>
>> On 09/07/2009 10:37 PM, Andreas Fromm wrote:
>>
>>> thanks Sebastian,
>>>
>>> you are right, your code works here too. But i don't get it work in my
>>> multi y-axes plot from the matplotlib examples
>>> (http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
>>> Even with linear plots, i get no gridlines.
>>>
>>> Any idea, whats wrong here?
>>>
>>> minimal code example:
>>> ###
>>> import matplotlib.pyplot as plt
>>> from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes
>>>
>>> fig = plt.figure(1)
>>> fig.clf()
>>> #plt.grid(True)
>>> host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])
>>> fig.add_axes(host)
>>>
>>> host.plot([0, 10, 100], [0, 10, 100], label='host')
>>>
>>> host.grid(True) #?
>>> host.yaxis.grid(True) #?
>>>
>>> host.yaxis.set_scale('log') #?
>>>
>>> plt.draw()
>>> plt.show()
>>> ###
>>>
>>> Greets,
>>> Andreas
>>>
>>>
>>> Sebastian Busch schrieb:
>>>
>>>
from matplotlib.pyplot import *
plot([1,10,100],[1,10,100])
grid()
yscale('log')
xscale('log')
works here.
best,
sebastian.
>>> --
>>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
>>> trial. Simplify your report design, integration and deployment - and focus
>>> on
>>> what you do best, core application coding. Discover what's new with
>>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>>> ___
>>> Matplotlib-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>
>>>
>>
>>
>>
>> --
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
>> trial. Simplify your report design, integration and deployment - and focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> ___
>> Matplotlib-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, cor
Re: [Matplotlib-users] download
This change has gone into effect (for me at least on a Liux box). Can anyone test Windows and Mac and report back? Cheers, Mike Michael Droettboom wrote: > I just went in and changed the default file downloads back to correct > values, but alas, it appears to have no effect. There is some hints in > the (many) related SF bugs that there may be a delay associated with > these settings, so I will check back again at the end of the day. > > Mike > > On 09/04/2009 05:46 AM, Fabrice Silva wrote: > >> Le jeudi 03 septembre 2009 à 20:16 -0500, John Hunter a écrit : >> >> >>> On Thu, Sep 3, 2009 at 8:04 PM, Alan G Isaac wrote: >>> >>> The default download from the Matplotlib page link to http://sourceforge.net/projects/matplotlib/ which once again highlights basemap. (I think this was fixed at one point.) >>> I'm not seeng this, nor am I seeing basemap settings in the File >>> Manager which would trigger this. Of course, the default download is >>> platform specific, which may be why I am not seeing this, so please >>> give us as much info as possible about your platform (mainly the OS) >>> >>> When I click on the green download button at >>> http://sourceforge.net/projects/matplotlib using mac OSX 10.5, I get >>> redirected to the mpl 0.99 OSX download:: >>> >>> >>> https://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-0.99/matplotlib-0.99.0-py2.5-macosx10.5.dmg/download >>> >>> >> Strangely, the green button points to >> http://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-0.99/matplotlib-0.99.0-py2.5-macosx-10.3-i386.egg/download >> when I browse on a linux (debian) machine with epiphany (which uses >> gecko, the firefox engine). Why macosx ? >> >> >> > > > -- > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > ___ > Matplotlib-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] mpl 0.99 and py2exe
Werner F. Bruhin wrote: > I have run into a bit of problem using 0.99 and py2exe. > > I am getting errors "TypeError: unsupported operand type(s) for +=: > 'NoneType' and 'str'" in mlab.pyo after py2exe'd my application. > > This is caused by this type of code, as one normally uses the optimize > option with py2exe which means that the docs are stripped from the .pyo > files. > "psd.__doc__ = psd.__doc__ % kwdocd" > > I changed it to: > if psd.__doc__ is not None: > psd.__doc__ = psd.__doc__ % kwdocd > else: > psd.__doc__ = "" > > Above is a bit of a hack, if someone can suggest how to correct this in > a way which would get accepted as a patch I would search all modules > correct them. > Maybe a nicer solution would be: if __debug__: psd.__doc__ = psd.__doc__ % kwdocd Also that would mean that above is not run when running Python as "python -O script.py or python -OO script.py where the first solution means that with -O the it would still be executed. Werner -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] download
Michael Droettboom writes: > This change has gone into effect (for me at least on a Liux box). Can > anyone test Windows and Mac and report back? Using Firefox 3.5.2 on Mac OS X 10.5, the green download link points to matplotlib-0.99.0-py2.6-macosx10.5.dmg, and when I change my user agent header to Internet Explorer, to matplotlib-0.99.0.win32-py2.6.exe. -- Jouni K. Seppänen http://www.iki.fi/jks -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] mpl 0.99 and py2exe
"Werner F. Bruhin" writes: >> I am getting errors "TypeError: unsupported operand type(s) for +=: >> 'NoneType' and 'str'" in mlab.pyo after py2exe'd my application. I think this has been fixed on the trunk for good, by changing all docstring modifications to use decorators (defined in docstring.py) that check for nonexistent docstrings. The changes are perhaps too big to apply on the 0.99 branch. >> I changed it to: >> if psd.__doc__ is not None: >> psd.__doc__ = psd.__doc__ % kwdocd >> else: >> psd.__doc__ = "" >> >> Above is a bit of a hack, if someone can suggest how to correct this in >> a way which would get accepted as a patch I would search all modules >> correct them. I think either this or something like psd.__doc__ = psd.__doc__ and (psd.__doc__ % kwdocd) should be acceptable as a bugfix. -- Jouni K. Seppänen http://www.iki.fi/jks -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Error in doc?
Hi, I think I found a bug, but I am not sure if it's in the doc or in a method name. In the doc, there is reference to a method *suptitle* in class mpl.figure.Figure. The name sounds strange, but the method exists and works. The example given, though, makes reference to *subtitle*, so either the example or the method name are wrong. Here's the link to the doc: http://matplotlib.sourceforge.net/api/figure_api.html?highlight=legend#matplotlib.figure.Figure.suptitle jorge -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] grid on log-plots
On Wed, Sep 9, 2009 at 4:30 AM, Yann wrote:
> I can not try your revision but I will do it as soon as it is released.
> Nervertheless I try your snippet with an AxesZero. I get the gridlines
> and the axis but the first was over the second. It is not what I expected.
You can rearrange the order of artists by setting the zorder.
> As far as I am concerned, I can wait until matplotlib next release.
Just to clarify, the patch will be included in the 1.0 release, not
the maintenance release of 0.99 version.
Regards,
-JJ
>
> Thanks,
>
> Yann
>
> On 09/08/2009 08:13 PM, Jae-Joon Lee wrote:
>> On Tue, Sep 8, 2009 at 11:51 AM, Yann
>> Goudard wrote:
>>
>>> Hi,
>>>
>>> I have the same behaviour with LocatableAxes. HostAxes, ParasiteAxes and
>>> LocatableAxes depend on 'mpl_toolkits.axes_grid.axislines.Axes'. It must
>>> be the matter origin.
>>>
>> Yes, and this was because I forgot to implement some necessary methods.
>> This is now fixed in the svn trunk. So if you can,please give it a try.
>>
>>
>>> This another example should draw a grid but does not:
>>>
>>> import wx
>>> from wx import Frame
>>> from matplotlib.backends.backend_wxagg import FigureFrameWxAgg,
>>> FigureCanvasWxAgg
>>> from matplotlib.figure import Figure
>>> from mpl_toolkits.axes_grid.axes_divider import LocatableAxes
>>>
>>> fig = Figure((1, 1), 50)
>>> axes = LocatableAxes(fig, [0, 0, 1, 1])
>>> # axes.toggle_axisline(False)
>>> axes.grid(True)
>>> fig.add_axes(axes)
>>>
>>> app = wx.PySimpleApp()
>>> my_viewer = FigureFrameWxAgg(-1, fig)
>>> my_viewer.Show()
>>> app.MainLoop()
>>>
>>> If you uncomment axes.toggle_axisline(False), it works cause it uses
>>> normal 'matplolib.axes.Axes' behaviour. It is not a matter for common
>>> use but if you need 'AxesZero', this trick does not work.
>>>
>> What the toggle_axisline does is simply to make the xaxis and yaxis
>> (which are responsible for drawing ticks, ticklabels, etc in the
>> mainline mpl) visible again, and make axis["bottom"] and etc
>> invisible.
>> One workaround is to make xaxis and yaxis visible but pnly to draw the
>> gridlines. Something like below.
>>
>> ax.toggle_axisline(True)
>> ax.grid(True)
>> ax.gridlines.set_visible(False) # this is just to make the code not to
>> draw gridlines twice in future release of mpl.
>> ax.xaxis.set_visible(True)
>> ax.yaxis.set_visible(True)
>> for t in ax.xaxis.majorTicks + ax.yaxis.majorTicks:
>> t.gridOn = True
>> t.tick1On = False
>> t.tick2On = False
>> t.label1On = False
>> t.label2On = False
>>
>> Let me know if this does not work, or there is a case that this cannot be
>> used.
>> Regards,
>>
>> -JJ
>>
>>
>>
>>> Yann
>>>
>>>
>>> On 09/07/2009 10:37 PM, Andreas Fromm wrote:
>>>
thanks Sebastian,
you are right, your code works here too. But i don't get it work in my
multi y-axes plot from the matplotlib examples
(http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
Even with linear plots, i get no gridlines.
Any idea, whats wrong here?
minimal code example:
###
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes
fig = plt.figure(1)
fig.clf()
#plt.grid(True)
host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])
fig.add_axes(host)
host.plot([0, 10, 100], [0, 10, 100], label='host')
host.grid(True) #?
host.yaxis.grid(True) #?
host.yaxis.set_scale('log') #?
plt.draw()
plt.show()
###
Greets,
Andreas
Sebastian Busch schrieb:
> from matplotlib.pyplot import *
>
> plot([1,10,100],[1,10,100])
> grid()
>
> yscale('log')
> xscale('log')
>
> works here.
>
> best,
> sebastian.
>
>
>
--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus
on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>
>>>
>>>
>>> --
>>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
>>> trial. Simplify your report design, integration and deployment - and focus
>>> on
>>> what you do best, core application coding. Discover what's new with
>>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>>> ___
>>> Matplotlib-users mailing list
>>> [email protected]
Re: [Matplotlib-users] Fetching a data slab with NetCDFFile
Thanks much for the quick response. I updated both matplotlib and
basemap (now at 0.99.5) via svn and noticed the new netcdftime.py.
First, from within site-packages/mpl_toolkits/basemap,
$ grep date2index *.py
__init__.py::func:`date2index`: compute a time variable index
corresponding to a date.
__init__.py:def date2index(dates, nctime, calendar='proleptic_gregorian'):
__init__.py:return netcdftime.date2index(dates, nctime, calendar=None)
netcdftime.py:def date2index(dates, nctime, calendar=None, select='exact'):
netcdftime.py:date2index(dates, nctime, calendar=None, select='exact')
so there seems to be some disagreement between __init__.py and
netcdftime.py concerning the presence of the "select" argument. When I
call date2index with the "select" keyword arg I get
In [24]: ix0 = date2index(date0,timedata,timedata.calendar,select='nearest')
---
TypeError Traceback (most recent call last)
/home/amg/work/nhmm/ in ()
TypeError: date2index() got an unexpected keyword argument 'select'
---
This detail aside, I am still having difficulty with date2index, but
annoyingly, I seem to get different error messages with different
datasets. I'll illustrate two here, starting with the one I initially
posted about. (See note below regarding this data.)
In [3]: from mpl_toolkits.basemap import date2index,num2date,NetCDFFile
as ncf
In [10]: from mpl_toolkits import basemap
In [11]: print basemap.__version__
0.99.5
In [24]: fname0 = 'http://esgcet.llnl.gov/dap/'
In [25]: fname1 =
'ipcc4/20c3m/gfdl_cm2_1/pcmdi.ipcc4.gfdl_cm2_1.20c3m.run1.atm.mo.xml'
In [26]: fname = fname0+fname1
In [28]: datobj = ncf(fname)
In [33]: datobj.variables['tas'].shape
Out[33]: (1680, 90, 144)
In [34]: timedata = datobj.variables['time']
In [35]: from datetime import datetime as dt
In [36]: date0 = dt(1951,1,16,12,0,0)
In [37]: print date0
1951-01-16 12:00:00
In [38]: nt0 = date2index(date0,timedata)
---
ClientError Traceback (most recent call last)
/home/amg/work/nhmm/ in ()
/home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/mpl_toolkits/basemap/__init__.pyc
in date2index(dates, nctime, calendar)
3931 Returns an index or a sequence of indices.
3932 """
-> 3933 return netcdftime.date2index(dates, nctime, calendar=None)
3934
3935 def maskoceans(lonsin,latsin,datain,inlands=False):
/home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/mpl_toolkits/basemap/netcdftime.pyc
in date2index(dates, nctime, calendar, select)
1006 # If the times do not correspond, then it means that the times
1007 # are not increasing uniformly and we try the bisection method.
-> 1008 if not _check_index(index, dates, nctime, calendar):
1009
1010 # Use the bisection method. Assumes the dates are ordered.
/home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/mpl_toolkits/basemap/netcdftime.pyc
in _check_index(indices, dates, nctime, calendar)
959 return False
960
--> 961 t = nctime[indices]
962 return numpy.all( num2date(t, nctime.units, calendar) == dates)
963
/home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/mpl_toolkits/basemap/netcdf.pyc
in __getitem__(self, index)
65
66 def __getitem__(self, index):
---> 67 datout = squeeze(self._var.__getitem__(index))
68 # automatically
69 # - remove singleton dimensions
/home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/dap/dtypes.pyc
in __getitem__(self, key)
409 def __getitem__(self, key):
410 # Return data from the array.
--> 411 return self.data[key]
412
413 def __setitem__(self, key, item):
/home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/dap/proxy.pyc
in __getitem__(self, index)
112
113 # Fetch data.
--> 114 resp, data = openurl(url, self.cache, self.username,
self.password)
115
116 # First lines are ASCII information that end with
'Data:\n'.
/home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/dap/util/http.pyc
in openurl(url, cache, username, password)
19 m = re.search('code = (?P\d+);\s*message =
"(?P.*)"', data, re.DOTALL | re.MULTILINE)
20 msg = 'Server error %(code)s: "%(msg)s"' % m.groupdict()
---> 21 raise ClientError(msg)
22
23 return resp, data
ClientError: 'Server error 0: "invalid literal for int(): [1113"'
-
Note that this is a different error than previously reported. Also, the
correct time index is still 1080:
In [40]: taxvals = datobj.variables['time'][:]
In [41]: num2date(taxvals[1080],timedata.units,timedata.calendar)
Out[41]: 1951-01-16 12:00:00
-
This dataset, ge
Re: [Matplotlib-users] Fetching a data slab with NetCDFFile
Arthur M. Greene wrote: > Thanks much for the quick response. I updated both matplotlib and > basemap (now at 0.99.5) via svn and noticed the new netcdftime.py. > First, from within site-packages/mpl_toolkits/basemap, > > $ grep date2index *.py > __init__.py::func:`date2index`: compute a time variable index > corresponding to a date. > __init__.py:def date2index(dates, nctime, > calendar='proleptic_gregorian'): > __init__.py:return netcdftime.date2index(dates, nctime, > calendar=None) > netcdftime.py:def date2index(dates, nctime, calendar=None, > select='exact'): > netcdftime.py:date2index(dates, nctime, calendar=None, > select='exact') > > so there seems to be some disagreement between __init__.py and > netcdftime.py concerning the presence of the "select" argument. When I > call date2index with the "select" keyword arg I get > > In [24]: ix0 = > date2index(date0,timedata,timedata.calendar,select='nearest') > --- > > TypeError Traceback (most recent call > last) > > /home/amg/work/nhmm/ in () > > TypeError: date2index() got an unexpected keyword argument 'select' Arthur: I forgot to update the wrapper function in __init__.py - that's fixed now if you do an svn update. Concerning your other problems below, using your test case exposed a couple of other bugs, but it still doesn't work. The basic problem is that the date2index function was designed to work with netCDF4 variable objects (http://code.google.com/p/netcdf4-python), and the netcdf file/variable objects that are produced by pupynere/pydap (the pure python netcdf /dap reader included in basemap) don't quite behave the same way. Using netCDF4, I can get your gfdl_test.nc case to work with > cat testdate2index.py #from mpl_toolkits.basemap import date2index,num2date,NetCDFFile as ncf from netCDF4 import Dataset as ncf from netCDF4 import date2index, num2date from mpl_toolkits import basemap fname0 = 'http://esgcet.llnl.gov/dap/' fname1 =\ 'ipcc4/20c3m/gfdl_cm2_1/pcmdi.ipcc4.gfdl_cm2_1.20c3m.run1.atm.mo.xml' fname = fname0+fname1 #fname = 'gfdl_test.nc' print fname datobj = ncf(fname) print datobj.variables['tas'].shape timedata = datobj.variables['time'] from datetime import datetime as dt date0 = dt(1951,1,16,12,0,0) print num2date(timedata[:],timedata.units,calendar=timedata.calendar) print date0 nt0 = date2index(date0,timedata,select='nearest') print nt0 print \ timedata[nt0],num2date(timedata[nt0],timedata.units,calendar=timedata.calendar) > python testdate2index.py gfdl_test.nc (13, 31, 29) [1950-08-16 12:00:00 1950-09-16 00:00:00 1950-10-16 12:00:00 1950-11-16 00:00:00 1950-12-16 12:00:00 1951-01-16 12:00:00 1951-02-15 00:00:00 1951-03-16 12:00:00 1951-04-16 00:00:00 1951-05-16 12:00:00 1951-06-16 00:00:00 1951-07-16 12:00:00 1951-08-16 12:00:00] 1951-01-16 12:00:00 5 [ 32865.5] [1951-01-16 12:00:00] Your original example doesn't work because the URL is not an opendap server, it's some kind of CDAT xml file that presumably only CDAT understands. We will see if we can fix the date2index function included in basemap (if not I will remove it), but for now I recommend using netcdf4-python. It's really a much more robust and feature-rich solution for netcdf reading and writing. -Jeff > > --- > > This detail aside, I am still having difficulty with date2index, but > annoyingly, I seem to get different error messages with different > datasets. I'll illustrate two here, starting with the one I initially > posted about. (See note below regarding this data.) > > In [3]: from mpl_toolkits.basemap import > date2index,num2date,NetCDFFile as ncf > In [10]: from mpl_toolkits import basemap > In [11]: print basemap.__version__ > 0.99.5 > In [24]: fname0 = 'http://esgcet.llnl.gov/dap/' > In [25]: fname1 = > 'ipcc4/20c3m/gfdl_cm2_1/pcmdi.ipcc4.gfdl_cm2_1.20c3m.run1.atm.mo.xml' > In [26]: fname = fname0+fname1 > In [28]: datobj = ncf(fname) > In [33]: datobj.variables['tas'].shape > Out[33]: (1680, 90, 144) > In [34]: timedata = datobj.variables['time'] > In [35]: from datetime import datetime as dt > In [36]: date0 = dt(1951,1,16,12,0,0) > In [37]: print date0 > 1951-01-16 12:00:00 > In [38]: nt0 = date2index(date0,timedata) > --- > > ClientError Traceback (most recent call > last) > > /home/amg/work/nhmm/ in () > > /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/mpl_toolkits/basemap/__init__.pyc > > in date2index(dates, nctime, calendar) >3931 Returns an index or a sequence of indices. >3932 """ > -> 3933 return netcdftime.date2index(dates, nctime, calendar=None) >3934 >3935 def maskoceans(lonsin,latsin,datain,inlands=False): > > /home/amg/usr/local/cdat/trunk/lib
Re: [Matplotlib-users] grid on log-plots
Hi,
is it enough to overwrite the axesgrid.py file in my matplotlib 0.99
installation with the file from svn? I tried that, but i see no effects.
Are there anywhere precompiled matplotlib releases for 1.0_win32_pre?
Andreas
Jae-Joon Lee schrieb:
> On Tue, Sep 8, 2009 at 11:51 AM, Yann
> Goudard wrote:
>
>> Hi,
>>
>> I have the same behaviour with LocatableAxes. HostAxes, ParasiteAxes and
>> LocatableAxes depend on 'mpl_toolkits.axes_grid.axislines.Axes'. It must
>> be the matter origin.
>>
>
> Yes, and this was because I forgot to implement some necessary methods.
> This is now fixed in the svn trunk. So if you can,please give it a try.
>
>
>> This another example should draw a grid but does not:
>>
>> import wx
>> from wx import Frame
>> from matplotlib.backends.backend_wxagg import FigureFrameWxAgg,
>> FigureCanvasWxAgg
>> from matplotlib.figure import Figure
>> from mpl_toolkits.axes_grid.axes_divider import LocatableAxes
>>
>> fig = Figure((1, 1), 50)
>> axes = LocatableAxes(fig, [0, 0, 1, 1])
>> # axes.toggle_axisline(False)
>> axes.grid(True)
>> fig.add_axes(axes)
>>
>> app = wx.PySimpleApp()
>> my_viewer = FigureFrameWxAgg(-1, fig)
>> my_viewer.Show()
>> app.MainLoop()
>>
>> If you uncomment axes.toggle_axisline(False), it works cause it uses
>> normal 'matplolib.axes.Axes' behaviour. It is not a matter for common
>> use but if you need 'AxesZero', this trick does not work.
>>
>
> What the toggle_axisline does is simply to make the xaxis and yaxis
> (which are responsible for drawing ticks, ticklabels, etc in the
> mainline mpl) visible again, and make axis["bottom"] and etc
> invisible.
> One workaround is to make xaxis and yaxis visible but pnly to draw the
> gridlines. Something like below.
>
> ax.toggle_axisline(True)
> ax.grid(True)
> ax.gridlines.set_visible(False) # this is just to make the code not to
> draw gridlines twice in future release of mpl.
> ax.xaxis.set_visible(True)
> ax.yaxis.set_visible(True)
> for t in ax.xaxis.majorTicks + ax.yaxis.majorTicks:
> t.gridOn = True
> t.tick1On = False
> t.tick2On = False
> t.label1On = False
> t.label2On = False
>
> Let me know if this does not work, or there is a case that this cannot be
> used.
> Regards,
>
> -JJ
>
>
>
>> Yann
>>
>>
>> On 09/07/2009 10:37 PM, Andreas Fromm wrote:
>>
>>> thanks Sebastian,
>>>
>>> you are right, your code works here too. But i don't get it work in my
>>> multi y-axes plot from the matplotlib examples
>>> (http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes.html).
>>> Even with linear plots, i get no gridlines.
>>>
>>> Any idea, whats wrong here?
>>>
>>> minimal code example:
>>> ###
>>> import matplotlib.pyplot as plt
>>> from mpl_toolkits.axes_grid.parasite_axes import HostAxes, ParasiteAxes
>>>
>>> fig = plt.figure(1)
>>> fig.clf()
>>> #plt.grid(True)
>>> host = HostAxes(fig, [0.15, 0.1, 0.65, 0.8])
>>> fig.add_axes(host)
>>>
>>> host.plot([0, 10, 100], [0, 10, 100], label='host')
>>>
>>> host.grid(True) #?
>>> host.yaxis.grid(True) #?
>>>
>>> host.yaxis.set_scale('log') #?
>>>
>>> plt.draw()
>>> plt.show()
>>> ###
>>>
>>> Greets,
>>> Andreas
>>>
>>>
>>> Sebastian Busch schrieb:
>>>
>>>
from matplotlib.pyplot import *
plot([1,10,100],[1,10,100])
grid()
yscale('log')
xscale('log')
works here.
best,
sebastian.
>>> --
>>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
>>> trial. Simplify your report design, integration and deployment - and focus
>>> on
>>> what you do best, core application coding. Discover what's new with
>>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>>> ___
>>> Matplotlib-users mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>
>>>
>>
>>
>> --
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
>> trial. Simplify your report design, integration and deployment - and focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> ___
>> Matplotlib-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
> --
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
Re: [Matplotlib-users] download
> From: Michael Droettboom [mailto:[email protected]] > Sent: Wednesday, September 09, 2009 08:17 > > This change has gone into effect (for me at least on a Liux > box). Can anyone test Windows and Mac and report back? On Windows 7RC, Firefox 3.5.2 and IE 8.0 see matplotlib-0.99.0.win32-py2.6.exe. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] python make.py html
Hi all, python make.py html failed with /home/nwagner/svn/matplotlib/doc/faq/environment_variables_faq.rst:: WARNING: document isn't included in any toctree /home/nwagner/svn/matplotlib/doc/mpl_toolkits/axes_grid/index.rst:: WARNING: document isn't included in any toctree /home/nwagner/svn/matplotlib/doc/mpl_toolkits/mplot3d/index.rst:: WARNING: document isn't included in any toctree /home/nwagner/svn/matplotlib/doc/users/arraydata.rst:: WARNING: document isn't included in any toctree /home/nwagner/svn/matplotlib/doc/users/plotting.rst:: WARNING: document isn't included in any toctree done preparing documents... done Exception occurred while building, starting debugger: Traceback (most recent call last): File "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/cmdline.py", line 172, in main app.build(all_files, filenames) File "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/application.py", line 129, in build self.builder.build_update() File "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/__init__.py", line 255, in build_update 'out of date' % len(to_build)) File "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/__init__.py", line 310,in build self.write(docnames, list(updated_docnames), method) File "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/__init__.py", line 349,in write self.write_doc(docname, doctree) File "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/html.py", line 349, in write_doc ctx = self.get_doc_context(docname, body, metatags) File "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/html.py", line 319, in get_doc_context toc = self.render_partial(self.env.get_toc_for(docname))['fragment'] File "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/environment.py", line 921, in get_toc_for toc = self.tocs[docname].deepcopy() KeyError: 'users/annotations' > /home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/environment.py(921)get_toc_for() -> toc = self.tocs[docname].deepcopy() (Pdb) I am using >>> matplotlib.__version__ '1.0.svn' Python 2.6 (r26:66714, Feb 3 2009, 20:49:49) [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] python make.py html
I'm not seeing that, but I'm running Sphinx 0.6.3. It also looks like the kind of thing where removing the build directory may help. Mike Nils Wagner wrote: > Hi all, > > python make.py html failed with > > /home/nwagner/svn/matplotlib/doc/faq/environment_variables_faq.rst:: > WARNING: document isn't included in any toctree > /home/nwagner/svn/matplotlib/doc/mpl_toolkits/axes_grid/index.rst:: > WARNING: document isn't included in any toctree > /home/nwagner/svn/matplotlib/doc/mpl_toolkits/mplot3d/index.rst:: > WARNING: document isn't included in any toctree > /home/nwagner/svn/matplotlib/doc/users/arraydata.rst:: > WARNING: document isn't included in any toctree > /home/nwagner/svn/matplotlib/doc/users/plotting.rst:: > WARNING: document isn't included in any toctree > done > preparing documents... done > Exception occurred while building, starting debugger: > Traceback (most recent call last): >File > "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/cmdline.py", > > line 172, in main > app.build(all_files, filenames) >File > "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/application.py", > > line 129, in build > self.builder.build_update() >File > "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/__init__.py", > > line 255, in build_update > 'out of date' % len(to_build)) >File > "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/__init__.py", > > line 310,in build > self.write(docnames, list(updated_docnames), method) >File > "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/__init__.py", > > line 349,in write > self.write_doc(docname, doctree) >File > "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/html.py", > > line 349, in write_doc > ctx = self.get_doc_context(docname, body, metatags) >File > "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/builders/html.py", > > line 319, in get_doc_context > toc = > self.render_partial(self.env.get_toc_for(docname))['fragment'] >File > "/home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/environment.py", > > line 921, in get_toc_for > toc = self.tocs[docname].deepcopy() > KeyError: 'users/annotations' > >> /home/nwagner/local/lib64/python2.6/site-packages/Sphinx-0.6.1-py2.6.egg/sphinx/environment.py(921)get_toc_for() >> > -> toc = self.tocs[docname].deepcopy() > (Pdb) > > I am using > > matplotlib.__version__ > '1.0.svn' > > Python 2.6 (r26:66714, Feb 3 2009, 20:49:49) > [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2 > > > -- > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > ___ > Matplotlib-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Fetching a data slab with NetCDFFile
Thanks much. I am able to replicate your results using netcdf4. FYI, I don't believe the xml file is a CDAT creation; rather, it is probably written using CMOR (http://www2-pcmdi.llnl.gov/cmor), which was used to standardize the IPCC model output files, presumably so they could be accessed by a variety of applications via OpenDAP. H... At any rate, I can access the remote data object with netcdf4, but no luck retrieving either data or a time index. In [94]: datobj = ncf(fname) In [95]: timedata = datobj.variables['time'] In [97]: taxvals = timedata[1070:1090] In [99]: print taxvals [ 32559.5 32590. 32620.5 32651. 32681.5 32712.5 32743. 32773.5 32804. 32834.5 32865.5 32895. 32924.5 32955. 32985.5 33016. 33046.5 33077.5 33108. 33138.5] In [100]: print date2index(date0,timedata.units,timedata.calendar,select='nearest') --- AttributeErrorTraceback (most recent call last) /home/amg/work/nhmm/ in () /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so in netCDF4.Variable.__getattr__ (netCDF4.c:13593)() /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so in netCDF4._get_att (netCDF4.c:1806)() AttributeError: NetCDF: Attribute not found In [96]: print datobj.variables['tas'].shape (1680, 90, 144) In [101]: testdat = datobj.variables['tas'][0,:,:] --- RuntimeError Traceback (most recent call last) /home/amg/work/nhmm/ in () /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so in netCDF4.Variable.__getitem__ (netCDF4.c:14286)() /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so in netCDF4.Variable._get (netCDF4.c:18945)() RuntimeError: NetCDF: Variable has no data in DAP request -- Well, at least the error messages are different... Thanks again for all the assistance. It would be useful to access the IPCC output with OpenDap at some point. Best, Arthur Jeff Whitaker wrote: Arthur M. Greene wrote: Thanks much for the quick response. I updated both matplotlib and basemap (now at 0.99.5) via svn and noticed the new netcdftime.py. First, from within site-packages/mpl_toolkits/basemap, $ grep date2index *.py __init__.py::func:`date2index`: compute a time variable index corresponding to a date. __init__.py:def date2index(dates, nctime, calendar='proleptic_gregorian'): __init__.py:return netcdftime.date2index(dates, nctime, calendar=None) netcdftime.py:def date2index(dates, nctime, calendar=None, select='exact'): netcdftime.py:date2index(dates, nctime, calendar=None, select='exact') so there seems to be some disagreement between __init__.py and netcdftime.py concerning the presence of the "select" argument. When I call date2index with the "select" keyword arg I get In [24]: ix0 = date2index(date0,timedata,timedata.calendar,select='nearest') --- TypeError Traceback (most recent call last) /home/amg/work/nhmm/ in () TypeError: date2index() got an unexpected keyword argument 'select' Arthur: I forgot to update the wrapper function in __init__.py - that's fixed now if you do an svn update. Concerning your other problems below, using your test case exposed a couple of other bugs, but it still doesn't work. The basic problem is that the date2index function was designed to work with netCDF4 variable objects (http://code.google.com/p/netcdf4-python), and the netcdf file/variable objects that are produced by pupynere/pydap (the pure python netcdf /dap reader included in basemap) don't quite behave the same way. Using netCDF4, I can get your gfdl_test.nc case to work with > cat testdate2index.py #from mpl_toolkits.basemap import date2index,num2date,NetCDFFile as ncf from netCDF4 import Dataset as ncf from netCDF4 import date2index, num2date from mpl_toolkits import basemap fname0 = 'http://esgcet.llnl.gov/dap/' fname1 =\ 'ipcc4/20c3m/gfdl_cm2_1/pcmdi.ipcc4.gfdl_cm2_1.20c3m.run1.atm.mo.xml' fname = fname0+fname1 #fname = 'gfdl_test.nc' print fname datobj = ncf(fname) print datobj.variables['tas'].shape timedata = datobj.variables['time'] from datetime import datetime as dt date0 = dt(1951,1,16,12,0,0) print num2date(timedata[:],timedata.units,calendar=timedata.calendar) print date0 nt0 = date2index(date0,timedata,select='nearest') print nt0 print \ timedata[nt0],num2date(timedata[nt0],timedata.units,calendar=timedata.calendar) > python testdate2index.py gfdl_test.nc (13, 31, 29) [1950-08-16 12:00:00 1950-09-16 00:00:00 1950-10-16 12:00:00 1950-11-16 00:00:00 1950-12-16 12:00:00 1951-01-16 12:00:00 1951-02-15 00:00:00 1951-03-16 12:00:00 1951-04-16 00:00:00 1951-05-16 12:00:00 1951-06-16 00:00:00 1951-07-16 12:00:00 1951-0
Re: [Matplotlib-users] Fetching a data slab with NetCDFFile
Arthur M. Greene wrote: > Thanks much. I am able to replicate your results using netcdf4. > > FYI, I don't believe the xml file is a CDAT creation; rather, it is > probably written using CMOR (http://www2-pcmdi.llnl.gov/cmor), which > was used to standardize the IPCC model output files, presumably so > they could be accessed by a variety of applications via OpenDAP. H... > > At any rate, I can access the remote data object with netcdf4, but no > luck retrieving either data or a time index. > > In [94]: datobj = ncf(fname) > In [95]: timedata = datobj.variables['time'] > In [97]: taxvals = timedata[1070:1090] > In [99]: print taxvals > [ 32559.5 32590. 32620.5 32651. 32681.5 32712.5 32743. 32773.5 > 32804. 32834.5 32865.5 32895. 32924.5 32955. 32985.5 33016. > 33046.5 33077.5 33108. 33138.5] > In [100]: print > date2index(date0,timedata.units,timedata.calendar,select='nearest') Arthur: That's because the timedata variable has no attributes (no calendar or units), and the date2index function looks for these attributes. That's weird though, since that dataset is supposed to be CF compliant. I wonder if openDAP is not handling that xml file correctly. -Jeff > --- > > AttributeErrorTraceback (most recent call > last) > > /home/amg/work/nhmm/ in () > > /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so > in netCDF4.Variable.__getattr__ (netCDF4.c:13593)() > > /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so > in netCDF4._get_att (netCDF4.c:1806)() > > AttributeError: NetCDF: Attribute not found > > > In [96]: print datobj.variables['tas'].shape > (1680, 90, 144) > In [101]: testdat = datobj.variables['tas'][0,:,:] > --- > > RuntimeError Traceback (most recent call > last) > > /home/amg/work/nhmm/ in () > > /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so > in netCDF4.Variable.__getitem__ (netCDF4.c:14286)() > > /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so > in netCDF4.Variable._get (netCDF4.c:18945)() > > RuntimeError: NetCDF: Variable has no data in DAP request > > -- > > Well, at least the error messages are different... > > Thanks again for all the assistance. It would be useful to access the > IPCC output with OpenDap at some point. > > Best, > > Arthur > > > Jeff Whitaker wrote: >> Arthur M. Greene wrote: >>> Thanks much for the quick response. I updated both matplotlib and >>> basemap (now at 0.99.5) via svn and noticed the new netcdftime.py. >>> First, from within site-packages/mpl_toolkits/basemap, >>> >>> $ grep date2index *.py >>> __init__.py::func:`date2index`: compute a time variable index >>> corresponding to a date. >>> __init__.py:def date2index(dates, nctime, >>> calendar='proleptic_gregorian'): >>> __init__.py:return netcdftime.date2index(dates, nctime, >>> calendar=None) >>> netcdftime.py:def date2index(dates, nctime, calendar=None, >>> select='exact'): >>> netcdftime.py:date2index(dates, nctime, calendar=None, >>> select='exact') >>> >>> so there seems to be some disagreement between __init__.py and >>> netcdftime.py concerning the presence of the "select" argument. When I >>> call date2index with the "select" keyword arg I get >>> >>> In [24]: ix0 = >>> date2index(date0,timedata,timedata.calendar,select='nearest') >>> --- >>> >>> TypeError Traceback (most recent >>> call last) >>> >>> /home/amg/work/nhmm/ in () >>> >>> TypeError: date2index() got an unexpected keyword argument 'select' >> >> Arthur: I forgot to update the wrapper function in __init__.py - >> that's fixed now if you do an svn update. Concerning your other >> problems below, using your test case exposed a couple of other bugs, >> but it still doesn't work. The basic problem is that the date2index >> function was designed to work with netCDF4 variable objects >> (http://code.google.com/p/netcdf4-python), and the netcdf >> file/variable objects that are produced by pupynere/pydap (the pure >> python netcdf /dap reader included in basemap) don't quite behave the >> same way. Using netCDF4, I can get your gfdl_test.nc case to work with >> >> > cat testdate2index.py >> >> #from mpl_toolkits.basemap import date2index,num2date,NetCDFFile as ncf >> from netCDF4 import Dataset as ncf >> from netCDF4 import date2index, num2date >> from mpl_toolkits import basemap >> fname0 = 'http://esgcet.llnl.gov/dap/' >> fname1 =\ >> 'ipcc4/20c3m/gfdl_cm2_1/pcmdi.ipcc4.gfdl_cm2_1.20c3m.run1.atm.mo.xml' >> fname = fname0+fname1 >> #fname = 'gfdl_test.nc' >> print fname >> datobj = ncf(fname) >> print datobj.variables['tas'].shape >> timedata = datobj.variables['ti
[Matplotlib-users] rate of change for a splice of data
I have a large array that looks like this: vals=[0,0,1,3,2,1,0,4,2,4,2...] dates = [datetime.date(...), datetime.date(...)...] which then is transformed into a cumsum: acc_vals = np.cumsum(vals) and then that is sent to maplotlib to be graphed. The resultant graph looks like this: http://img171.imageshack.us/img171/8589/linetotal.png The blue line is the cumsum data, and the red line is the raw values (just for illustrative purposes). What I want is the red line to represent the rate of change for the previous month. That is to say at each point in the graph, the value on the red line represents the total number of flight time that has occurred over the previous 30 days. Is this something that matplotlib can handles on it's own? Or am I going to have to write my own number crunching method to get it working? -- View this message in context: http://www.nabble.com/rate-of-change-for-a-splice-of-data-tp25376306p25376306.html Sent from the matplotlib - users mailing list archive at Nabble.com. -- Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Fetching a data slab with NetCDFFile
Just to add a little info: I've been poking around various OPeNDAP servers looking for files to try and open (and read), and have had a little success, so the module does seem to work, if not all the time for my purposes. At the moment I'm on a 64-bit machine (Fedora 10), so this is encouraging. Some details: I tried several of the IPCC AR4 models at PCMDI, with results similar to what I reported earlier. The time object appears with neither units nor a calendar. Looking at the metadata shows this not to be correct, for at least the three models I investigated (gfdl_cm2_1, mpi_echam5, ncar_ccsm3_0). I believe the inclusion of units and a calendar are standard procedure for all of these models, and would probably cause the dataset to be flagged if they weren't present. Many users (like hundreds) have downloaded and analyzed these files. The IRI data library (http://iridl.ldeo.columbia.edu/) has a large collection of datasets, all available using opendap. But I had problems with the ones I tried because the calendars seem all to be given as "360", rather than "360_day". (Perhaps someone is cutting corners with the typing, I can't say...) I couldn't correct this by setting timedata.calendar='360_day' because the files are opened read-only. There must be files on this server with differently-defined calendars, since the data come from many different sources. I'll have to root around some more to turn some up. Similarly, the time units in http://test.opendap.org/opendap/data/nc/data.nc are given simply as 'hour', so num2date can't figure out what dates the time values refer to. I wouldn't have expected this at this URL, but maybe it's a test? Aside from the fact that "... since" was missing, netcdf4 also complained that 'hour' was not an acceptable unit. Only 'hours' will do. (No 'months' or 'years' either, it seems.) http://test.opendap.org/opendap/data/nc/coads_climatology.nc seems to download OK, and there are units, but it's a 12-month climatology, so calendar is irrelevant. I could plot the data, although it appeared reversed left-to-right. (I didn't add axes, but just plotted it raw.) The conclusion seems to be that (1) there may be a lot of non-conforming datasets out there (and netcdf4 may be a little fussy about what time units it will accept, too), but (2) since there seems to be some discordance w.r.t. the IPCC data (where we believe the units and calendar must actually be present) one cannot be absolutely sure that all of the problems experienced are solely due to malformed data descriptions. Evidently more detective work will be required to sort everything out... Best, thanks again for the assistance. I've been up too late chasing around the web... Arthur Jeff Whitaker wrote: > Arthur M. Greene wrote: >> Thanks much. I am able to replicate your results using netcdf4. >> >> FYI, I don't believe the xml file is a CDAT creation; rather, it is >> probably written using CMOR (http://www2-pcmdi.llnl.gov/cmor), which >> was used to standardize the IPCC model output files, presumably so >> they could be accessed by a variety of applications via OpenDAP. H... >> >> At any rate, I can access the remote data object with netcdf4, but no >> luck retrieving either data or a time index. >> >> In [94]: datobj = ncf(fname) >> In [95]: timedata = datobj.variables['time'] >> In [97]: taxvals = timedata[1070:1090] >> In [99]: print taxvals >> [ 32559.5 32590. 32620.5 32651. 32681.5 32712.5 32743. 32773.5 >> 32804. 32834.5 32865.5 32895. 32924.5 32955. 32985.5 33016. >> 33046.5 33077.5 33108. 33138.5] >> In [100]: print >> date2index(date0,timedata.units,timedata.calendar,select='nearest') > > Arthur: That's because the timedata variable has no attributes (no > calendar or units), and the date2index function looks for these > attributes. That's weird though, since that dataset is supposed to be > CF compliant. I wonder if openDAP is not handling that xml file correctly. > > -Jeff >> --- >> >> AttributeErrorTraceback (most recent call >> last) >> >> /home/amg/work/nhmm/ in () >> >> /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so >> in netCDF4.Variable.__getattr__ (netCDF4.c:13593)() >> >> /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so >> in netCDF4._get_att (netCDF4.c:1806)() >> >> AttributeError: NetCDF: Attribute not found >> >> >> In [96]: print datobj.variables['tas'].shape >> (1680, 90, 144) >> In [101]: testdat = datobj.variables['tas'][0,:,:] >> --- >> >> RuntimeError Traceback (most recent call >> last) >> >> /home/amg/work/nhmm/ in () >> >> /home/amg/usr/local/cdat/trunk/lib/python2.5/site-packages/netCDF4.so >> in netCDF4.Variable.__getitem__ (netCDF4.c:14286)() >> >> /home
