Re: [Matplotlib-users] Bar plot choose colours

2015-10-29 Thread questions anon
Wonderful! thank you!

On Fri, Oct 30, 2015 at 4:51 AM, Joshua Klein  wrote:

> My mistake, I thought you were using a DataFrame, not a Series. Instead do
> this
>
> colors = ['r' if row > 0 else 'b' for i, row in meantempanomaly.iteritems()]
> meantempanomaly.plot(kind='bar', color=colors)
>
> ​
>
> On Thu, Oct 29, 2015 at 5:43 AM, questions anon 
> wrote:
>
>> Thanks for taking the time to respond
>>
>> I am receiving the error:
>> AttributeError: 'Series' object has no attribute 'iterrow'
>>
>> I will look into this further.
>> thank you
>>
>>
>> On Thu, Oct 29, 2015 at 2:31 PM, Joshua Klein 
>> wrote:
>>
>>> The pandas plot function doesn’t take colors as it does ‘x’ or ‘y’, but
>>> it lets you pass color information just as you would with raw matplotlib
>>> code, which means you can pass it a sequence of colors which match the
>>> length of your sequence of drawn observations.
>>>
>>> # compute color codes using a ternary expression in a list comprehension 
>>> over the DataFrame
>>> colors = ['r' if row.anomaly > 0 else 'b' for i, row in 
>>> meantempanomaly.iterrows()]
>>> meantempanomaly.plot(kind='bar', color=colors)
>>>
>>> ​
>>>
>>> On Wed, Oct 28, 2015 at 9:54 PM, questions anon <
>>> questions.a...@gmail.com> wrote:
>>>
>>>> I have calculated annual temperature anomaly and I would like to plot
>>>> as a bar plot with all values positive make red and all values negative
>>>> make blue
>>>>
>>>> I am using pandas and the time series data in this example are called
>>>> 'anomaly'
>>>>
>>>> mybarplot=anomaly.plot(kind='bar')
>>>>
>>>> the data look like this:
>>>>
>>>> time
>>>> 2003-01-01   -0.370800
>>>> 2004-01-01   -0.498199
>>>> 2005-01-010.246118
>>>> 2006-01-01   -0.313321
>>>> 2007-01-010.585050
>>>> 2008-01-01   -0.227976
>>>> 2009-01-010.439337
>>>> 2010-01-010.135607
>>>> 2011-01-010.106105
>>>> 2012-01-01   -0.102002
>>>> Freq: AS-JAN, dtype: float64
>>>>
>>>> is there some simple way of writing:
>>>> meantempanomaly.plot(kind='bar', anomaly>0:'r', anomaly<0:'b' )
>>>>
>>>> Any feedback will be greatly appreciated
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> ___
>>>> Matplotlib-users mailing list
>>>> Matplotlib-users@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>>>
>>>>
>>>
>>
>
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Bar plot choose colours

2015-10-29 Thread questions anon
Thanks for taking the time to respond

I am receiving the error:
AttributeError: 'Series' object has no attribute 'iterrow'

I will look into this further.
thank you


On Thu, Oct 29, 2015 at 2:31 PM, Joshua Klein  wrote:

> The pandas plot function doesn’t take colors as it does ‘x’ or ‘y’, but it
> lets you pass color information just as you would with raw matplotlib code,
> which means you can pass it a sequence of colors which match the length of
> your sequence of drawn observations.
>
> # compute color codes using a ternary expression in a list comprehension over 
> the DataFrame
> colors = ['r' if row.anomaly > 0 else 'b' for i, row in 
> meantempanomaly.iterrows()]
> meantempanomaly.plot(kind='bar', color=colors)
>
> ​
>
> On Wed, Oct 28, 2015 at 9:54 PM, questions anon 
> wrote:
>
>> I have calculated annual temperature anomaly and I would like to plot as
>> a bar plot with all values positive make red and all values negative make
>> blue
>>
>> I am using pandas and the time series data in this example are called
>> 'anomaly'
>>
>> mybarplot=anomaly.plot(kind='bar')
>>
>> the data look like this:
>>
>> time
>> 2003-01-01   -0.370800
>> 2004-01-01   -0.498199
>> 2005-01-010.246118
>> 2006-01-01   -0.313321
>> 2007-01-010.585050
>> 2008-01-01   -0.227976
>> 2009-01-010.439337
>> 2010-01-010.135607
>> 2011-01-010.106105
>> 2012-01-01   -0.102002
>> Freq: AS-JAN, dtype: float64
>>
>> is there some simple way of writing:
>> meantempanomaly.plot(kind='bar', anomaly>0:'r', anomaly<0:'b' )
>>
>> Any feedback will be greatly appreciated
>>
>>
>>
>> --
>>
>> ___
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Bar plot choose colours

2015-10-28 Thread questions anon
I have calculated annual temperature anomaly and I would like to plot as a
bar plot with all values positive make red and all values negative make blue

I am using pandas and the time series data in this example are called
'anomaly'

mybarplot=anomaly.plot(kind='bar')

the data look like this:

time
2003-01-01   -0.370800
2004-01-01   -0.498199
2005-01-010.246118
2006-01-01   -0.313321
2007-01-010.585050
2008-01-01   -0.227976
2009-01-010.439337
2010-01-010.135607
2011-01-010.106105
2012-01-01   -0.102002
Freq: AS-JAN, dtype: float64

is there some simple way of writing:
meantempanomaly.plot(kind='bar', anomaly>0:'r', anomaly<0:'b' )

Any feedback will be greatly appreciated
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] dates for x-axis

2012-04-23 Thread questions anon
thanks for all the responses. still finding it very confusing!! but got it
to work (without having to import in the loop).
I used:
from datetime import datetime as dt

but I also had to call:
from datetime import timedelta

and now it seems to work nicely. thank you


On Fri, Apr 20, 2012 at 3:36 AM, Benjamin Root  wrote:

>
>
> On Thu, Apr 19, 2012 at 1:21 PM, Goyo  wrote:
>
>> El día 19 de abril de 2012 05:31, questions anon
>>  escribió:
>> > Thank you, I was able to get it to work but only if I imported datetime
>> > within the loop, otherwise I ended up with the
>> > AttributeError: type object 'datetime.datetime' has no attribute
>> 'datetime'
>> > and if I added 'import datetime' at the top of my script it had an error
>> > where I loop through combining each month
>> > "stop_month = datetime(2011, 03, 01)
>> > TypeError: 'module' object is not callable"
>>
>> If you can write a standalone, minimal executable script which
>> reproduces the problem I'll take a look. Send it as an attachement and
>> add sample data files if necessary.
>>
>> Goyo
>>
>>
> The issue is that there is a slight mixup in namespaces.  There is a
> module called datetime, and that module contains a class object called
> datetime.  So, if your imports at the top are "import datetime", then all
> your module-related stuff need to be prepended with "datetime.". But, if
> your imports at the top are "from datetime import datetime", then you can
> use the object freely, but you can't use anything else from the module
> unless you also import it.
>
> Here is the tricky part.  In your code, you did the following:
>
> from datetime import datetime
>
> If you then did:
>
> import datetime
>
> depending on the order the two were, one would overwrite the other.  You
> can only have one thing called "datetime".  Personally, I would do one of
> two things:
>
> import datetime as dt
>
> and use "dt.datetime()" to create datetime objects as well as call
> functions like "dt.strftime()". Or, do
>
> from datetime import datetime, date, timedelta, strftime
>
> and get replace calls like "datetime.datetime()" and "datetime.strftime()"
> with just "datetime()" and "strftime()".
>
> I hope that clears things up.  Namespaces are a honking good idea, but
> having objects be the same exact name as a module gets confusing very
> easily.
>
> Cheers!
> Ben Root
>
>
--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] dates for x-axis

2012-04-18 Thread questions anon
Thank you, I was able to get it to work but only if I imported datetime
within the loop, otherwise I ended up with the
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
and if I added 'import datetime' at the top of my script it had an error
where I loop through combining each month
"stop_month = datetime(2011, 03, 01)
TypeError: 'module' object is not callable"
It seems very messy with importing datetime everywhere but I am not sure
what the problem is. Below is the code I am using that works:


import numpy as np
import matplotlib.pyplot as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
from datetime import datetime
import os
from StringIO import StringIO
from osgeo import gdal, gdalnumeric, ogr, osr
import glob
from datetime import date, timedelta
import matplotlib.dates as mdates
import time

rainmax=[]
rainmin=[]
rainmean=[]
yearmonthlist=[]
yearmonth_int=[]

OutputFolder=r"E:/test_out/"
GLOBTEMPLATE = r"e:/Rainfall/rainfall-{year}/r{year}{month:02}??.txt"

def accumulate_month(year, month):
files = glob.glob(GLOBTEMPLATE.format(year=year, month=month))
monthlyrain=[]
for ifile in files:
f=np.genfromtxt(ifile,skip_header=6)
monthlyrain.append(f)

import datetime
yearmonth=datetime.datetime(year,month,1)
yearmonthlist.append(yearmonth)
yearmonthint=str(year)+str(month)
from datetime import date, datetime
d=datetime.strptime(yearmonthint, '%Y%m')
date_string=d.strftime('%Y%m')
yearmonthint=int(date_string)
yearmonth_int.append(yearmonthint)
r_max, r_mean, r_min=MA.max(monthlyrain), MA.mean(monthlyrain),
MA.min(monthlyrain)
rainmax.append(r_max)
rainmean.append(r_mean)
rainmin.append(r_min)


###loop through months and years
stop_month = datetime(2011, 12, 31)
month = datetime(2011, 01, 01)
while month < stop_month:
accumulate_month(month.year, month.month)
month += timedelta(days=32)
month = month.replace(day=01)


### Plot timeseries of max data
x=yearmonthlist
y=rainmax
x2=yearmonth_int

print x, y, x2

fig, ax=plt.subplots(1)

z=np.polyfit(x2,y,1)
p=np.poly1d(z)

plt.plot(x,y)
plt.plot(x,p(x2),'r--') #add trendline to plot
print "y=%.6fx+(%.6f)"%(z[0],z[1])

fig.autofmt_xdate()
ax.fmt_xdata=mdates.DateFormatter('%Y%m')
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y%m'))

plt.xlabel("year-month")
plt.ylabel("Precipitation (mm)")
plt.title("Max monthly precipition")
plt.savefig(OutputFolder+"MaxMonthlyPrecip.png")
plt.show()




On Thu, Apr 19, 2012 at 2:52 AM, Goyo  wrote:

> El día 18 de abril de 2012 07:59, questions anon
>  escribió:
> > I am not exactly sure how to use datetime objects instead of strings.
> > This is the code I am working with at the moment and the code works
> except
> > for the dates, they are just weird numbers along the x-axis.
>
> Seems like you're plotting yearmonthlist in the x axis, which is a
> list of strings and each string is the concatenation of the string
> representations of two numbers. So numbers in the x axis are to be
> expected.
>
> You can create datetime objects this way:
>
> d = datetime.datetime(year, month, 1)
>
> Then create an array of datetime objects and use it as the x parameter to
> plot.
>
> Goyo
>
--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] dates for x-axis

2012-04-17 Thread questions anon
I am not exactly sure how to use datetime objects instead of strings.
This is the code I am working with at the moment and the code works except
for the dates, they are just weird numbers along the x-axis.
Any help will be greatly appreciated.

import numpy as np
import matplotlib.pyplot as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
from datetime import datetime
import os
from osgeo import gdal, gdalnumeric, ogr, osr
import glob
from datetime import date, timedelta
import matplotlib.dates as mdates
import time

rainmax=[]
yearmonthlist=[]
yearmonth_int=[]

OutputFolder=r"E:/test_out/"
GLOBTEMPLATE = r"e:/Rainfall/rainfall-{year}/r{year}{month:02}??.txt"

def accumulate_month(year, month):
files = glob.glob(GLOBTEMPLATE.format(year=year, month=month))
monthlyrain=[]
monthlyrainaust=[]
for ifile in files:
f=np.genfromtxt(ifile,skip_header=6)
monthlyrain.append(f)
yearmonth=str(year)+str(month)
d=datetime.strptime(yearmonth, '%Y%m')
date_string=d.strftime('%Y%m')
yearmonthint=int(date_string)
yearmonth_int.append(yearmonthint)
yearmonthlist.append(yearmonth)
r_max=np.max(monthlyrain)
rainmax.append(r_max)


###loop through months and years
stop_month = datetime(2011, 04, 01)
month = datetime(2011, 01, 01)
while month < stop_month:
accumulate_month(month.year, month.month)
month += timedelta(days=32)
month = month.replace(day=01)


x=yearmonthlist
y=rainmax
x2=yearmonth_int

print x, y, x2

fig, ax=plt.subplots(1)

z=np.polyfit(x2,y,1)
p=np.poly1d(z)

plt.plot(x,y)
plt.plot(x,p(x2),'r--') #add trendline to plot
print "y=%.6fx+(%.6f)"%(z[0],z[1])

fig.autofmt_xdate()
ax.fmt_xdata=mdates.DateFormatter('%Y%m')
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y%m'))

plt.xlabel("year-month")
plt.ylabel("Precipitation (mm)")
plt.title("Max monthly Precipition")
plt.savefig(OutputFolder+"MaxMonthlyPrecip.png")
plt.show()





On Fri, Apr 13, 2012 at 2:31 AM, Goyo  wrote:

> El día 12 de abril de 2012 03:46, questions anon
>  escribió:
>
> > I am not sure how to recognise that x-axis are dates like 20110101,
> > 20110102, 20110103 etc.
>
> Use datetime objects instead of strings.
>
> Goyo
>
--
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] dates for x-axis

2012-04-11 Thread questions anon
Hi matplotlib list,
I am having trouble applying mdates in matplotlib.
I am not sure how to recognise that x-axis are dates like 20110101,
20110102, 20110103 etc.
Any feedback will be greatly appreciated!
below is the code I have so far:

import numpy as np
import matplotlib.pyplot as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os
import glob
import matplotlib.dates as mdates

MainFolder=r"E:/Rainfall/rainfall-2011/test/"
OutputFolder=r"E:/test_out/"

rmax=[]
monthyear=[]

for (path, dirs, files) in os.walk(MainFolder):
path=path+'/'
for fname in files:
if fname.endswith('.txt'):
filename=path+fname
fileName, fileExtension=os.path.splitext(fname)
test=fileName.strip('r')
test=str(test)
monthyear.append(test)
f=np.genfromtxt(filename, skip_header=6)
dailymax=f.max()
rmax.append(dailymax)
print rmax
print monthyear

x=monthyear
y=rmax

fig, ax=plt.subplots(1)

plt.plot(x,y)

fig.autofmt_xdate()
ax.fmt_xdata=mdates.DateFormatter('%Y%m%d')

plt.ylabel("Precipitation")
plt.title("Max daily Precipition Vic")
plt.savefig(OutputFolder+"MaxdailyPrecip.png")
plt.show()
--
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-25 Thread questions anon
excellent, thanks, that worked and was able to plot using matplotlib
without ending up with the logical_or error.
thanks everyone

On Thu, Mar 22, 2012 at 3:59 AM, Goyo  wrote:

> El día 21 de marzo de 2012 01:03, questions anon
>
> > f=np.genfromtxt(inputfile, skip_header=6, dtype=None, names=True)
>
> I don't think you should be using dtype=None if you wand a 2D array.
> Also the names=True thing makes no sense to me since there isn't a row
> with field names. Try just this and I guess you'll get a 2D array:
>
> f=np.genfromtxt(inputfile, skip_header=6)
>
> Goyo
>
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-20 Thread questions anon
, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)]
f shape:  (690,)
f dtype: [('0', '
print "f dtype: ", f.dtype[1:2]
ValueError: Field key must be an integer, string, or unicode.




On Wed, Mar 21, 2012 at 1:47 AM, Benjamin Root  wrote:

>
>
> On Mon, Mar 19, 2012 at 5:28 PM, questions anon 
> wrote:
>
>> So when I add "np.logical_or" to the beginning of the script it makes no
>> difference to the error message that I receive.
>>
>> I have tried reshaping the array but I receive an error message of:
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> f.reshape(691,886)
>> ValueError: total size of new array must be unchanged
>>
>> Is there a way to use np.genfromtxt and define the rows and columns on
>> import?
>>
>> Thanks
>>
>>
> I think you have two completely separate problems.  They are completely
> unrelated to each other.  The np.logical_or() issue happens within Basemap
> while your np.genfromtext() happens in your module.  For the
> np.logical_or() issue, I suspect that there is something wrong with your
> installation (maybe EPD is conflicting with a pre-existing python
> install?).  As for np.genfromtext(), I would put the code back to the way
> it was before (the original call looked right to me).
>
> Ben Root
>
>
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-19 Thread questions anon
So when I add "np.logical_or" to the beginning of the script it makes no
difference to the error message that I receive.

I have tried reshaping the array but I receive an error message of:
Traceback (most recent call last):
  File "", line 1, in 
f.reshape(691,886)
ValueError: total size of new array must be unchanged

Is there a way to use np.genfromtxt and define the rows and columns on
import?

Thanks

On Fri, Mar 16, 2012 at 7:10 AM, Goyo  wrote:

> El día 15 de marzo de 2012 05:14, questions anon
>  escribió:
> > I think my error is from the np.genfromtxt because I just checked the
> size
> > of my data and it appears in 1D rather than 2D.
>
> This is unsurprising since your file has just one row of data. I
> overlooked that because the weird error message drove all my attention
> to it. You can reshape the resulting array to (691, 886). Still that
> error message should not be there in any case.
>
> >> I don't really understand what np.logical_or is or how to use it?
> >> I have tried just calling it at the beginning of the script
>
> np.logical_or computes the logical out of two boolean arrays. It's
> called internally by countourf and that's triggering the exception:
>
> AttributeError: logical_or
>
> Which makes no sense at all because:
> 1. np is expected to be an alias for numpy and numpy *does* have an
> attribute called logical_or.
> 2. In case np didn't have an attribute called logical_or (for whatever
> reason) it would cause an exception but the error message should be
> something like "AttributeError: 'module' object has no attribute
> 'logical_or'".
>
> You where asked to call np.logical_or at the beginning of the script
> in order to know if it triggers the exception in that context.
>
> >> [...] but I still end up with the same error.
>
> So the call at the beginning didn't trigger the error?
>
> Regards
>
> Goyo
>
--
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-14 Thread questions anon
I think my error is from the np.genfromtxt because I just checked the size
of my data and it appears in 1D rather than 2D.
if I try taking out 'skip_header' I end up with this error:

Traceback (most recent call last):
  File "d:\BoMdata\plotrainfall.py", line 63, in 
f=np.genfromtxt(inputfile, dtype=None, names=True)
  File "C:\Python27\lib\site-packages\numpy\lib\npyio.py", line 1560, in
genfromtxt
raise ValueError(errmsg)
ValueError: Some errors were detected !
Line #7 (got 886 columns instead of 2)
Line #8 (got 886 columns instead of 2)
Line #9 (got 886 columns instead of 2)
Line #10 (got 886 columns instead of 2)
Line #11 (got 886 columns instead of 2)
Line #12 (got 886 columns instead of 2)
Line #13 (got 886 columns instead of 2)

my data as opened in notepad looks like:

ncols 886
nrows 691
xllcorner 111.975
yllcorner -44.525
cellsize  0.05
NODATA_value  -
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

how do I skip those first few rows but still end up with a 2D array?


On Thu, Mar 15, 2012 at 12:16 PM, questions anon
wrote:

> I don't really understand what np.logical_or is or how to use it?
> I have tried just calling it at the beginning of the script but I still
> end up with the same error.
>
>
> On Thu, Mar 15, 2012 at 10:59 AM, Pierre GM  wrote:
>
>> That's your whole log? You're sure you're not redefining np in the
>> background, via a variable or another module?
>> Have you tried to call np.logical_or at the very beginning of your
>> script, or in a brand new environment (after importing numpy as np)?
>> It's definitely not a matplotlib pb, but where is it coming on your side,
>> that's the question...
>> On Mar 14, 2012 11:35 PM, "questions anon" 
>> wrote:
>>
>>> Thanks for responding. It is 'sort of' good to know that it can't be
>>> explained as I just thought it was my incompetency!
>>> I tried the np rather than N but that made no differences.
>>> thanks again
>>>
>>>
>>> On Thu, Mar 15, 2012 at 7:48 AM, Benjamin Root  wrote:
>>>
>>>>
>>>>
>>>> On Tue, Mar 13, 2012 at 4:23 PM, questions anon <
>>>> questions.a...@gmail.com> wrote:
>>>>
>>>>> also I have tried running it on a different computer and the same
>>>>> error occurred
>>>>>
>>>>>
>>>>> On Wed, Mar 14, 2012 at 8:22 AM, questions anon <
>>>>> questions.a...@gmail.com> wrote:
>>>>>
>>>>>> thanks for looking into this Goyo.
>>>>>> The complete code:
>>>>>>
>>>>>>
>>>>>> import numpy as N
>>>>>> import matplotlib.pyplot as plt
>>>>>> from numpy import ma as MA
>>>>>> from mpl_toolkits.basemap import Basemap
>>>>>> import os
>>>>>>
>>>>>> shapefile="E:/GIS_layers/DSE_REGIONS"
>>>>>> inputfile=r"d:/BoMdata/r19000117.txt"
>>>>>> outputfolder=r"d:/BoMdata/outputfolder"
>>>>>>
>>>>>> f=N.genfromtxt(inputfile, skip_header=6,  dtype=float, names=True)
>>>>>> print f[0:5]
>>>>>>
>>>>>>
>>>>>> map = Basemap(projection='merc',llcrnrlat=-45,urcrnrlat=-9,
>>>>>>
>>>>>> llcrnrlon=111.975,urcrnrlon=156.525,lat_ts=0,resolution='i')
>>>>>> map.drawcoastlines()
>>>>>> map.drawstates()
>>>>>> map.readshapefile(shapefile, 'DSE_REGIONS')
>>>>>>
>>>>>> xi=N.linspace(111.975, 156.275, 886)
>>>>>> yi=N.linspace(-44.525, -9.975, 691)
>>>>>> x,y=map(*N.meshgrid(xi,yi))
>>>>>> plt.title('rainfall')
>>>>>> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>>>>>> l,b,w,h =0.1,0.1,0.8,0.8
>>>>>> cax = plt.axes([l+w+0.025, b, 0.025, h])
>>>>>> plt.colorbar(CS,cax=cax, drawedge

Re: [Matplotlib-users] open ascii grid data and plot

2012-03-14 Thread questions anon
Thanks for responding. It is 'sort of' good to know that it can't be
explained as I just thought it was my incompetency!
I tried the np rather than N but that made no differences.
thanks again


On Thu, Mar 15, 2012 at 7:48 AM, Benjamin Root  wrote:

>
>
> On Tue, Mar 13, 2012 at 4:23 PM, questions anon 
> wrote:
>
>> also I have tried running it on a different computer and the same error
>> occurred
>>
>>
>> On Wed, Mar 14, 2012 at 8:22 AM, questions anon > > wrote:
>>
>>> thanks for looking into this Goyo.
>>> The complete code:
>>>
>>>
>>> import numpy as N
>>> import matplotlib.pyplot as plt
>>> from numpy import ma as MA
>>> from mpl_toolkits.basemap import Basemap
>>> import os
>>>
>>> shapefile="E:/GIS_layers/DSE_REGIONS"
>>> inputfile=r"d:/BoMdata/r19000117.txt"
>>> outputfolder=r"d:/BoMdata/outputfolder"
>>>
>>> f=N.genfromtxt(inputfile, skip_header=6,  dtype=float, names=True)
>>> print f[0:5]
>>>
>>>
>>> map = Basemap(projection='merc',llcrnrlat=-45,urcrnrlat=-9,
>>>
>>> llcrnrlon=111.975,urcrnrlon=156.525,lat_ts=0,resolution='i')
>>> map.drawcoastlines()
>>> map.drawstates()
>>> map.readshapefile(shapefile, 'DSE_REGIONS')
>>>
>>> xi=N.linspace(111.975, 156.275, 886)
>>> yi=N.linspace(-44.525, -9.975, 691)
>>> x,y=map(*N.meshgrid(xi,yi))
>>> plt.title('rainfall')
>>> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>>> l,b,w,h =0.1,0.1,0.8,0.8
>>> cax = plt.axes([l+w+0.025, b, 0.025, h])
>>> plt.colorbar(CS,cax=cax, drawedges=True)
>>> plt.savefig((os.path.join(outputfolder, 'rainfall.png')))
>>> plt.show()
>>> plt.close()
>>>
>>>
>>> and the complete error:
>>>
>>>
>>> Traceback (most recent call last):
>>>   File "d:/BoMdata/plotrainfall_v2.py", line 23, in 
>>>
>>> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>>>   File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
>>> line 3072, in contourf
>>>
>>> np.logical_or(outsidemask,np.logical_or(ma.getmaskarray(data),xymask))
>>> AttributeError: logical_or
>>>
>>> Any feedback/ideas will be greatly appreciated.
>>>
>>>
>>>
> Your error is very strange and it just simply should not be happening.  On
> a completely wild guess, could you try replacing "import numpy as N" with
> "import numpy as np" and replace all instances of "N" with "np"?
>
> Ben Root
>
>
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-13 Thread questions anon
also I have tried running it on a different computer and the same error
occurred

On Wed, Mar 14, 2012 at 8:22 AM, questions anon wrote:

> thanks for looking into this Goyo.
> The complete code:
>
>
> import numpy as N
> import matplotlib.pyplot as plt
> from numpy import ma as MA
> from mpl_toolkits.basemap import Basemap
> import os
>
> shapefile="E:/GIS_layers/DSE_REGIONS"
> inputfile=r"d:/BoMdata/r19000117.txt"
> outputfolder=r"d:/BoMdata/outputfolder"
>
> f=N.genfromtxt(inputfile, skip_header=6,  dtype=float, names=True)
> print f[0:5]
>
>
> map = Basemap(projection='merc',llcrnrlat=-45,urcrnrlat=-9,
>   llcrnrlon=111.975,urcrnrlon=156.525,lat_ts=0,resolution='i')
> map.drawcoastlines()
> map.drawstates()
> map.readshapefile(shapefile, 'DSE_REGIONS')
>
> xi=N.linspace(111.975, 156.275, 886)
> yi=N.linspace(-44.525, -9.975, 691)
> x,y=map(*N.meshgrid(xi,yi))
> plt.title('rainfall')
> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
> l,b,w,h =0.1,0.1,0.8,0.8
> cax = plt.axes([l+w+0.025, b, 0.025, h])
> plt.colorbar(CS,cax=cax, drawedges=True)
> plt.savefig((os.path.join(outputfolder, 'rainfall.png')))
> plt.show()
> plt.close()
>
>
> and the complete error:
>
>
> Traceback (most recent call last):
>   File "d:/BoMdata/plotrainfall_v2.py", line 23, in 
>
> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>   File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
> line 3072, in contourf
> np.logical_or(outsidemask,np.logical_or(ma.getmaskarray(data),xymask))
> AttributeError: logical_or
>
> Any feedback/ideas will be greatly appreciated.
>
>
>
>
> On Wed, Mar 14, 2012 at 4:59 AM, Goyo  wrote:
>
>> El día 12 de marzo de 2012 23:25, questions anon
>>  escribió:
>> [...]
>> >
>> > Is this how the data should look when it has been imported from an
>> ascii to
>> > a numpy array?
>>
>> I can't see anything obiously wrong in your code or your data --I did
>> not dive too deep into it though. What is weird is the traceback:
>>
>> Traceback (most recent call last):
>>  File "d:\plotrainfall.py", line 40, in 
>>CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>>  File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
>> line 3072, in contourf
>>np.logical_or(outsidemask,np.logical_or(ma.getmaskarray(data),xymask))
>> AttributeError: logical_or
>>
>> Is that the complete traceback?
>>
>> Goyo
>>
>
>
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-13 Thread questions anon
thanks for looking into this Goyo.
The complete code:

import numpy as N
import matplotlib.pyplot as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os

shapefile="E:/GIS_layers/DSE_REGIONS"
inputfile=r"d:/BoMdata/r19000117.txt"
outputfolder=r"d:/BoMdata/outputfolder"

f=N.genfromtxt(inputfile, skip_header=6,  dtype=float, names=True)
print f[0:5]

map = Basemap(projection='merc',llcrnrlat=-45,urcrnrlat=-9,
  llcrnrlon=111.975,urcrnrlon=156.525,lat_ts=0,resolution='i')
map.drawcoastlines()
map.drawstates()
map.readshapefile(shapefile, 'DSE_REGIONS')
xi=N.linspace(111.975, 156.275, 886)
yi=N.linspace(-44.525, -9.975, 691)
x,y=map(*N.meshgrid(xi,yi))
plt.title('rainfall')
CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax, drawedges=True)
plt.savefig((os.path.join(outputfolder, 'rainfall.png')))
plt.show()
plt.close()


and the complete error:

Traceback (most recent call last):
  File "d:/BoMdata/plotrainfall_v2.py", line 23, in 
CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
  File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
line 3072, in contourf
np.logical_or(outsidemask,np.logical_or(ma.getmaskarray(data),xymask))
AttributeError: logical_or

Any feedback/ideas will be greatly appreciated.



On Wed, Mar 14, 2012 at 4:59 AM, Goyo  wrote:

> El día 12 de marzo de 2012 23:25, questions anon
>  escribió:
> [...]
> >
> > Is this how the data should look when it has been imported from an ascii
> to
> > a numpy array?
>
> I can't see anything obiously wrong in your code or your data --I did
> not dive too deep into it though. What is weird is the traceback:
>
> Traceback (most recent call last):
>  File "d:\plotrainfall.py", line 40, in 
>CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>  File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
> line 3072, in contourf
>np.logical_or(outsidemask,np.logical_or(ma.getmaskarray(data),xymask))
> AttributeError: logical_or
>
> Is that the complete traceback?
>
> Goyo
>
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-12 Thread questions anon
Thanks for responding. I do think the error is with how I prepare the data
(importing as a numpy array) because I have used matplotlib a million time
with no problems.
Maybe I should be taking this question elsewhere about importing the data
but thought I would add some more info.
The data in the txt file looks like this when I open it in notepad:
ncols 886
nrows 691
xllcorner 111.975
yllcorner -44.525
cellsize  0.05
NODATA_value  -
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0

and some of the info I received with it:
General Category:Gridded daily data
Geographic Bounding Box
See Below
North Bounding Latitude
-9.975
South Bounding Latitude
-44.525
East Bounding Longitude
156.275
West Bounding Longitude
111.975
Stored Data Format
Arc/Info grids–all Australia
Available Format Type
ASCII row major

I am currently using:
f=N.genfromtxt(inputfile, skip_header=6,  dtype=float, names=True)
with the output looking like:

[ (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.

Is this how the data should look when it has been imported from an ascii to
a numpy array?

thanks


On Fri, Mar 9, 2012 at 5:27 PM, Benjamin Root  wrote:

>
>
> On Wednesday, March 7, 2012, questions anon 
> wrote:
> > Hi all,
> > I am still having a problem with the same code. I am not sure if maybe
> the problem is how I read the data in as numpy.genfromtxt
> > Is there a step I need to take to convert the data to numpy array to
> then read into matplotlib?
>
> Sorry for the delay.
>
> As far as I can tell, you are doing everything correctly.  The error you
> are getting would seem to indicate something wrong with your EPD install,
> or perhaps a conflict with another install on numpy or mpl.
>
> I would suggest completely clearing out your python and EPD install and
> reinstalling it fresh.
>
> Ben Root
--
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-07 Thread questions anon
Hi all,
I am still having a problem with the same code. I am not sure if maybe the
problem is how I read the data in as numpy.genfromtxt
Is there a step I need to take to convert the data to numpy array to then
read into matplotlib?
Thanks


On Fri, Mar 2, 2012 at 11:49 AM, questions anon wrote:

> python, numpy through enthought -
> Python 2.7.2 |EPD 7.1-1 (32-bit)| (default, Jul  3 2011, 15:13:59) [MSC
> v.1500 32 bit (Intel)] on win32
> imports at the top of the script:
>
> import numpy as N
> import matplotlib.pyplot as plt
> from numpy import ma as MA
> from mpl_toolkits.basemap import Basemap
> import os
>
>
>
> On Thu, Mar 1, 2012 at 4:42 PM, Benjamin Root  wrote:
>
>>
>>
>> On Wednesday, February 29, 2012, questions anon wrote:
>>
>>> I have had some progress reading in the data but am unsure how to create
>>> lats and lons from the info I have (see above).
>>> the error I am receiving is:
>>>
>>> Traceback (most recent call last):
>>>   File "d:\plotrainfall.py", line 40, in 
>>> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>>>   File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
>>> line 3072, in contourf
>>>
>>> np.logical_or(outsidemask,np.logical_or(ma.getmaskarray(data),xymask))
>>> AttributeError: logical_or
>>>
>>>
>>> from the below code:
>>>
>>>
>>> onefile=r"E:/test_in/r19000117.txt"
>>>
>>> f=N.genfromtxt(onefile, skip_header=6,  dtype=float, names=True)
>>> print f
>>>
>>>
>>> map = Basemap(projection='merc',llcrnrlat=-45,urcrnrlat=-9,
>>>
>>> llcrnrlon=111.975,urcrnrlon=156.525,lat_ts=0,resolution='i')
>>> map.drawcoastlines()
>>> map.drawstates()
>>> xi=N.linspace(111.975, 156.275, 886)
>>> yi=N.linspace(-44.525, -9.975, 691)
>>> x,y=map(*N.meshgrid(xi,yi))
>>> plt.title('rainfall')
>>> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>>> l,b,w,h =0.1,0.1,0.8,0.8
>>> cax = plt.axes([l+w+0.025, b, 0.025, h])
>>> plt.colorbar(CS,cax=cax, drawedges=True)
>>> plt.savefig((os.path.join(OutputFolder, 'rainfall.png')))
>>> plt.show()
>>> plt.close()
>>>
>>>
>>>
>> How did you install numpy?  Which version are you using?  What are your
>> imports at the top of this script?
>>
>> Ben Root
>>
>
>
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-03-01 Thread questions anon
python, numpy through enthought -
Python 2.7.2 |EPD 7.1-1 (32-bit)| (default, Jul  3 2011, 15:13:59) [MSC
v.1500 32 bit (Intel)] on win32
imports at the top of the script:

import numpy as N
import matplotlib.pyplot as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os


On Thu, Mar 1, 2012 at 4:42 PM, Benjamin Root  wrote:

>
>
> On Wednesday, February 29, 2012, questions anon wrote:
>
>> I have had some progress reading in the data but am unsure how to create
>> lats and lons from the info I have (see above).
>> the error I am receiving is:
>>
>> Traceback (most recent call last):
>>   File "d:\plotrainfall.py", line 40, in 
>> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>>   File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
>> line 3072, in contourf
>> np.logical_or(outsidemask,np.logical_or(ma.getmaskarray(data),xymask))
>> AttributeError: logical_or
>>
>>
>> from the below code:
>>
>>
>> onefile=r"E:/test_in/r19000117.txt"
>>
>> f=N.genfromtxt(onefile, skip_header=6,  dtype=float, names=True)
>> print f
>>
>>
>> map = Basemap(projection='merc',llcrnrlat=-45,urcrnrlat=-9,
>>   llcrnrlon=111.975,urcrnrlon=156.525,lat_ts=0,resolution='i')
>> map.drawcoastlines()
>> map.drawstates()
>> xi=N.linspace(111.975, 156.275, 886)
>> yi=N.linspace(-44.525, -9.975, 691)
>> x,y=map(*N.meshgrid(xi,yi))
>> plt.title('rainfall')
>> CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
>> l,b,w,h =0.1,0.1,0.8,0.8
>> cax = plt.axes([l+w+0.025, b, 0.025, h])
>> plt.colorbar(CS,cax=cax, drawedges=True)
>> plt.savefig((os.path.join(OutputFolder, 'rainfall.png')))
>> plt.show()
>> plt.close()
>>
>>
>>
> How did you install numpy?  Which version are you using?  What are your
> imports at the top of this script?
>
> Ben Root
>
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] open ascii grid data and plot

2012-02-29 Thread questions anon
I have had some progress reading in the data but am unsure how to create
lats and lons from the info I have (see above).
the error I am receiving is:

Traceback (most recent call last):
  File "d:\plotrainfall.py", line 40, in 
CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
  File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
line 3072, in contourf
np.logical_or(outsidemask,np.logical_or(ma.getmaskarray(data),xymask))
AttributeError: logical_or


from the below code:


onefile=r"E:/test_in/r19000117.txt"

f=N.genfromtxt(onefile, skip_header=6,  dtype=float, names=True)
print f


map = Basemap(projection='merc',llcrnrlat=-45,urcrnrlat=-9,
  llcrnrlon=111.975,urcrnrlon=156.525,lat_ts=0,resolution='i')
map.drawcoastlines()
map.drawstates()
xi=N.linspace(111.975, 156.275, 886)
yi=N.linspace(-44.525, -9.975, 691)
x,y=map(*N.meshgrid(xi,yi))
plt.title('rainfall')
CS = map.contourf(x,y, f, 15,cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax, drawedges=True)
plt.savefig((os.path.join(OutputFolder, 'rainfall.png')))
plt.show()
plt.close()




On Thu, Mar 1, 2012 at 9:29 AM, questions anon wrote:

> I have a txt file (with an associated prj file) containing gridded weather
> data.
> Firstly how can I open this file and convert it to a numpy array?
> and then how to plot in matplotlib, paticularly how to use the lat, lon
> and nrows,ncols.
> ncols=886
> nrows=691
> longitude west=111.975, east=156.275
> latitude north=-9.975, south=-44.525
> cell size=0.05
>
> My attempt below:
> --
>
> onefile=open("E:/test_in/r19000117.txt", 'r')
>
> map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
>   llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> map.drawcoastlines()
> map.drawstates()
> xi=N.linspace(111.975, 156.275, 886)
> yi=N.linspace(-44.525, -9.975, 691)
> x,y=map(*N.meshgrid(xi,yi))
> plt.title('rainfall')
> CS = map.contourf(x,y, onefile, cmap=plt.cm.jet)
> l,b,w,h =0.1,0.1,0.8,0.8
> cax = plt.axes([l+w+0.025, b, 0.025, h])
> plt.colorbar(CS,cax=cax, drawedges=True)
> plt.savefig((os.path.join(OutputFolder, 'rainfall.png')))
> plt.show()
> plt.close()
>
>
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] open ascii grid data and plot

2012-02-29 Thread questions anon
I have a txt file (with an associated prj file) containing gridded weather
data.
Firstly how can I open this file and convert it to a numpy array?
and then how to plot in matplotlib, paticularly how to use the lat, lon and
nrows,ncols.
ncols=886
nrows=691
longitude west=111.975, east=156.275
latitude north=-9.975, south=-44.525
cell size=0.05

My attempt below:
--

onefile=open("E:/test_in/r19000117.txt", 'r')

map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
  llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
map.drawcoastlines()
map.drawstates()
xi=N.linspace(111.975, 156.275, 886)
yi=N.linspace(-44.525, -9.975, 691)
x,y=map(*N.meshgrid(xi,yi))
plt.title('rainfall')
CS = map.contourf(x,y, onefile, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax, drawedges=True)
plt.savefig((os.path.join(OutputFolder, 'rainfall.png')))
plt.show()
plt.close()
--
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] add cirlce around lat lon

2011-12-07 Thread questions anon
thanks for the responses.
Sebastians suggestion to use tissot function is exactly what I needed.
map.tissot(lon, lat, r, 96)
thanks again

On Wed, Dec 7, 2011 at 6:36 PM, Thomas Lecocq  wrote:

>  Dear,
>
> you can try my tutorial to achieve this properly :
> http://www.geophysique.be/2011/02/20/matplotlib-basemap-tutorial-09-drawing-circles/
>
> Cheers,
>
> Thom
>
> ps : on the "things to do when I have some time" list : commit a method to
> the default basemap package to do this...
>
>
> --
> Date: Tue, 6 Dec 2011 21:23:18 -0600
> From: ben.r...@ou.edu
> To: questions.a...@gmail.com
> CC: Matplotlib-users@lists.sourceforge.net
> Subject: Re: [Matplotlib-users] add cirlce around lat lon
>
>
>
>
> On Tuesday, December 6, 2011, questions anon 
> wrote:
> > I would like to draw a simple circle around a specified latitude and
> longitude but I cannot find an appropriate command.
> > I have tried using
> > map.drawgreatcircle(myLON, myLAT,myLON, myLAT, linewidth=20,color='k')
> > but this doesn't do anything
> > or even
> > map.drawgreatcircle(myLON+1, myLAT+1,myLON-1, myLAT-1,
> linewidth=2,color='k')
> > and this appears to draw a line.
> > Any other commands I could try for this?
> > thanks in advance
> >
>
> drawgreatcircle() doesn't actually draw a circle, but rather an arc that
> represents the shortest distance between two points on the globe.
>
> Maybe you would rather use a Circle object?
>
> Ben Root
> --
> Cloud Services Checklist: Pricing and Packaging Optimization This white
> paper is intended to serve as a reference, checklist and point of
> discussion for anyone considering optimizing the pricing and packaging
> model of a cloud services business. Read Now!
> http://www.accelacomm.com/jaw/sfnl/114/51491232/
> ___ Matplotlib-users mailing
> list Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
> --
> Cloud Services Checklist: Pricing and Packaging Optimization
> This white paper is intended to serve as a reference, checklist and point
> of
> discussion for anyone considering optimizing the pricing and packaging
> model
> of a cloud services business. Read Now!
> http://www.accelacomm.com/jaw/sfnl/114/51491232/
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] add cirlce around lat lon

2011-12-06 Thread questions anon
I would like to draw a simple circle around a specified latitude and
longitude but I cannot find an appropriate command.
I have tried using
map.drawgreatcircle(myLON, myLAT,myLON, myLAT, linewidth=20,color='k')
but this doesn't do anything
or even
map.drawgreatcircle(myLON+1, myLAT+1,myLON-1, myLAT-1,
linewidth=2,color='k')
and this appears to draw a line.
Any other commands I could try for this?
thanks in advance
--
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] use shapefile to create a mask?

2011-11-08 Thread questions anon
thanks, will look at these options.

On Fri, Nov 4, 2011 at 10:21 AM, Matt S.  wrote:

> I've used Pyshapelib and Polygon to do this type of analysis in the past.
>  Thuban may get ya what you need.
>
> On Thu, Nov 3, 2011 at 3:40 PM, questions anon 
> wrote:
>
>> Hi All,
>> Is there a way to select only the values within a particular shapefile to
>> analyse.
>> I would like to do something like:
>>
>> array=numpyarraycoveringtemperatureofwholestate
>> shapefile=forestedregions.shp
>>
>> newarray=ma.masked_values(array, shapefile)
>> meantemperatureofforestedregions=MA.mean(newarray)
>> print meantemperatureofforestedregions
>>
>>
>> Any ideas of functions I could use, examples I could follow?
>> thanks
>>
>>
>> --
>> RSA(R) Conference 2012
>> Save $700 by Nov 18
>> Register now
>> http://p.sf.net/sfu/rsa-sfdev2dev1
>> ___
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Warning: converting a masked element to nan

2011-11-06 Thread questions anon
no that didn't work and I am back to thinking it is not the dates fault,
this is because if I only choose a section of my array that I know doesn't
have any NANs it works fine. Is there a way to tell is to skip/ignore these?

On Sat, Nov 5, 2011 at 8:50 AM, Stan West  wrote:

> **
>
> *From:* questions anon [mailto:questions.a...@gmail.com]
> *Sent:* Wednesday, November 02, 2011 17:17
>
>  Thanks, I think you are right about the datetimes for the x axis causing
> the problem.
> Does anyone have any ideas how to resolve this?
>
>  Does it help to call ax.xaxis_date() before your calls to plt.plot()?
>
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] use shapefile to create a mask?

2011-11-03 Thread questions anon
Hi All,
Is there a way to select only the values within a particular shapefile to
analyse.
I would like to do something like:

array=numpyarraycoveringtemperatureofwholestate
shapefile=forestedregions.shp

newarray=ma.masked_values(array, shapefile)
meantemperatureofforestedregions=MA.mean(newarray)
print meantemperatureofforestedregions


Any ideas of functions I could use, examples I could follow?
thanks
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Warning: converting a masked element to nan

2011-11-02 Thread questions anon
Thanks, I think you are right about the datetimes for the x axis causing
the problem.
Does anyone have any ideas how to resolve this?

On Thu, Nov 3, 2011 at 4:11 AM, Benjamin Root  wrote:

> I have seen situations when using datetimes for the x axis where if all
> the data being viewed is masked (or nans, or whatever) then it errors out
> because the axis range can't be determined.  Maybe that is what is
> happening here?
>
> Ben Root
>
>
> On Wed, Nov 2, 2011 at 11:48 AM, Michael Droettboom wrote:
>
>>  matplotlib should handle both masked arrays and arrays with NaNs and
>> treat both the same.  Can you reduce the script to something that can be
>> run independently without data?  It's not clear to me yet why this is
>> failing.
>>
>> Mike
>>
>>
>> On 11/01/2011 05:24 PM, questions anon wrote:
>>
>> Hi All,
>> I am trying to plot time against mean daily temperature values. The
>> problem is temperature contains no data in a few areas. I want to be able
>> to ignore this and continue plotting.
>> When I run the below script on my data that has all normal numbers it
>> works fine but when I run the script on my data that has sections of 'no
>> data' I receive the below error and the graph will not plot the trendline.
>> Any suggestions on how I could fix this.
>> Thanks
>>
>> *Warning (from warnings module):
>>   File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 3785
>> warnings.warn("Warning: converting a masked element to nan.")
>> UserWarning: Warning: converting a masked element to nan.*
>>
>>
>> from netCDF4 import Dataset
>> import matplotlib.pyplot as plt
>> import numpy as N
>> from mpl_toolkits.basemap import Basemap
>> from netcdftime import utime
>> from datetime import datetime
>> import os
>> from numpy import *
>> import matplotlib.dates as mdates
>> from numpy import ma as MA
>>
>> TSFCmeanall=[]
>> timeall=[]
>> time_intall=[]
>>
>> MainFolder=r"E:/GriddedData/T_SFC/1987/"
>> for (path, dirs, files) in os.walk(MainFolder):
>> for dir in dirs:
>> print dir
>> path=path+'/'
>>
>> for ncfile in files:
>> if ncfile[-3:]=='.nc':
>> ncfile=os.path.join(path,ncfile)
>> ncfile=Dataset(ncfile, 'r+',
>> 'NETCDF4')
>> TSFC=ncfile.variables['T_SFC'][0:20]
>> TIME=ncfile.variables['time'][0:20]
>>
>> fillvalue=ncfile.variables['T_SFC']._FillValue
>> TSFC=MA.masked_values(TSFC, fillvalue)
>> ncfile.close()
>>
>> for TSFC, TIME in
>> zip((TSFC[:]),(TIME[:])):
>> cdftime=utime('seconds since
>> 1970-01-01 00:00:00')
>> ncfiletime=cdftime.num2date(TIME)
>> timestr=str(ncfiletime)
>> d = datetime.strptime(timestr,
>> '%Y-%m-%d %H:%M:%S')
>> date_string =
>> d.strftime('%Y%m%d%H')
>> time_int=int(date_string)
>>
>> TSFCmean=N.mean(TSFC)
>>
>> TSFCmeanall.append(TSFCmean)
>> timeall.append(ncfiletime)
>> time_intall.append(time_int)
>>
>> x=timeall
>> y=TSFCmeanall
>> x2=time_intall
>>
>> fig, ax=plt.subplots(1)
>>
>> z=N.polyfit(x2,y,1)
>> p=N.poly1d(z)
>>
>> plt.plot(x,y)
>> plt.plot(x,p(x2),'r--') #add trendline to plot
>>
>> fig.autofmt_xdate()
>> ax.fmt_xdata=mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
>> plt.ylabel("Temperature C")
>> plt.title("Mean Daily Temp")
>> plt.show()
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> RSA® Conference 2012
>> Save $700 by Nov 18
>> Register now!http://p.sf.net/sfu/rsa-sfdev2de

[Matplotlib-users] Warning: converting a masked element to nan

2011-11-01 Thread questions anon
Hi All,
I am trying to plot time against mean daily temperature values. The problem
is temperature contains no data in a few areas. I want to be able to ignore
this and continue plotting.
When I run the below script on my data that has all normal numbers it works
fine but when I run the script on my data that has sections of 'no data' I
receive the below error and the graph will not plot the trendline. Any
suggestions on how I could fix this.
Thanks

*Warning (from warnings module):
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 3785
warnings.warn("Warning: converting a masked element to nan.")
UserWarning: Warning: converting a masked element to nan.*


from netCDF4 import Dataset
import matplotlib.pyplot as plt
import numpy as N
from mpl_toolkits.basemap import Basemap
from netcdftime import utime
from datetime import datetime
import os
from numpy import *
import matplotlib.dates as mdates
from numpy import ma as MA

TSFCmeanall=[]
timeall=[]
time_intall=[]

MainFolder=r"E:/GriddedData/T_SFC/1987/"
for (path, dirs, files) in os.walk(MainFolder):
for dir in dirs:
print dir
path=path+'/'

for ncfile in files:
if ncfile[-3:]=='.nc':
ncfile=os.path.join(path,ncfile)
ncfile=Dataset(ncfile, 'r+', 'NETCDF4')
TSFC=ncfile.variables['T_SFC'][0:20]
TIME=ncfile.variables['time'][0:20]

fillvalue=ncfile.variables['T_SFC']._FillValue
TSFC=MA.masked_values(TSFC, fillvalue)
ncfile.close()

for TSFC, TIME in
zip((TSFC[:]),(TIME[:])):
cdftime=utime('seconds since
1970-01-01 00:00:00')
ncfiletime=cdftime.num2date(TIME)
timestr=str(ncfiletime)
d = datetime.strptime(timestr,
'%Y-%m-%d %H:%M:%S')
date_string = d.strftime('%Y%m%d%H')
time_int=int(date_string)

TSFCmean=N.mean(TSFC)

TSFCmeanall.append(TSFCmean)
timeall.append(ncfiletime)
time_intall.append(time_int)

x=timeall
y=TSFCmeanall
x2=time_intall

fig, ax=plt.subplots(1)

z=N.polyfit(x2,y,1)
p=N.poly1d(z)

plt.plot(x,y)
plt.plot(x,p(x2),'r--') #add trendline to plot

fig.autofmt_xdate()
ax.fmt_xdata=mdates.DateFormatter('%Y-%m-%d %H:%M:%S')
plt.ylabel("Temperature C")
plt.title("Mean Daily Temp")
plt.show()
--
RSA® Conference 2012
Save $700 by Nov 18
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] memory error - netcdf plots

2011-10-23 Thread questions anon
Thanks Jeff!

On Thu, Oct 20, 2011 at 1:16 PM, Jeff Whitaker  wrote:

>  On 10/19/11 4:37 PM, questions anon wrote:
>
> thank you, I am not quite sure how to 'draw' the shapefile
>
> from matplotlib.collections import LineCollection
> ax = plt.gca() # get current axes instance
> # 'DSE_REGIONS' instance variable created by readshapefile method call.
> lines = LineCollection(map.DSE_REGIONS)
> ax.add_collection(lines)
>
> -Jeff
>
>
>  but making those changes and removing the shapefile has sped the
> processing up considerably!
> Thank you for your help
>
> On Wed, Oct 19, 2011 at 11:42 PM, Jeff Whitaker wrote:
>
>>  On 10/18/11 8:55 PM, questions anon wrote:
>>
>> Thanks Jeff, that certainly speeds it up! But when I take them out of the
>> loop and place them elsewhere they are no longer added to the map.
>> Is there someway I can call them in the loop but still get it to run
>> quickly?
>> Thanks
>>
>>
>>  Just the Basemap instance creation and the transformation of coordinates
>> to projection space should be hoisted out of the loop
>>
>>
>> map =
>> Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
>>
>> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
>> x,y=map(*N.meshgrid(LON,LAT))
>>
>>  you can leave the other statements in.
>>
>> If you still have memory issues, bring the readshapefile call out, and
>> draw the shapes whose coordinates are stored in the instance variable
>> map.DSE_REGIONS manually in the loop.
>>
>> -Jeff
>>
>>
>> On Fri, Oct 14, 2011 at 10:54 PM, Jeff Whitaker wrote:
>>
>>   On 10/12/11 8:20 PM, questions anon wrote:
>>
>> Hi All,
>> I keep receiving a memory error when processing many netcdf files. I
>> assumed it had something to do with how I loop things and maybe needed to
>> close things off properly but I recently received an error that made me
>> think it might be because of matplotlib.
>>
>> In the code below I am looping through a bunch of netcdf files (each file
>> is hourly data for one month) and within each netcdf file I am outputting a
>> *png file every three hours. This works for one netcdf file (therefore one
>> month) but when it begins to process the next netcdf file I receive a memory
>> error (see below). Since I have tidied some of my code up it seems to
>> process partly into the second file but then I still receive the memory
>> error.
>> I have tried a few suggestions such as:
>> -Combining the dataset using MFDataset (using NETCDF4) is not an option
>> because the files do not have unlimited dimension.
>> - gc.collect() but that just results in a *GEOS_ERROR: bad allocation
>> error*.
>> -only open LAT and LON once (which worked)
>>
>> System Details:
>> Python 2.7.2 |EPD 7.1-2 (32-bit)| (default, Jul  3 2011, 15:13:59) [MSC
>> v.1500 32 bit (Intel)] on win32
>>
>> Any feedback will be greatly appreciated as I seem to keep ending up with
>> memory errors when working with netcdf files this even happens if I am using
>> a much better computer.
>>
>> *Most recent error: *
>> Traceback (most recent call last):
>>   File "C:\plot_netcdf_merc_multiplot_across_multifolders_TSFC.py", line
>> 78, in 
>> plt.savefig((os.path.join(outputfolder,
>> 'TSFC'+date_string+'UTC.png')))
>>   File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 363, in
>> savefig
>> return fig.savefig(*args, **kwargs)
>>   File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1084, in
>> savefig
>> self.canvas.print_figure(*args, **kwargs)
>>   File
>> "C:\Python27\lib\site-packages\matplotlib\backends\backend_wxagg.py", line
>> 100, in print_figure
>> FigureCanvasAgg.print_figure(self, filename, *args, **kwargs)
>>   File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line
>> 1923, in print_figure
>> **kwargs)
>>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
>> line 438, in print_png
>> FigureCanvasAgg.draw(self)
>>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
>> line 393, in draw
>> self.renderer = self.get_renderer()
>>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
>> line 404, in get_renderer
>> self.renderer = RendererAgg(

Re: [Matplotlib-users] memory error - netcdf plots

2011-10-19 Thread questions anon
thank you, I am not quite sure how to 'draw' the shapefile but making those
changes and removing the shapefile has sped the processing up considerably!
Thank you for your help

On Wed, Oct 19, 2011 at 11:42 PM, Jeff Whitaker  wrote:

>  On 10/18/11 8:55 PM, questions anon wrote:
>
> Thanks Jeff, that certainly speeds it up! But when I take them out of the
> loop and place them elsewhere they are no longer added to the map.
> Is there someway I can call them in the loop but still get it to run
> quickly?
> Thanks
>
>
> Just the Basemap instance creation and the transformation of coordinates to
> projection space should be hoisted out of the loop
>
>
> map =
> Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
>
> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> x,y=map(*N.meshgrid(LON,LAT))
>
> you can leave the other statements in.
>
> If you still have memory issues, bring the readshapefile call out, and draw
> the shapes whose coordinates are stored in the instance variable
> map.DSE_REGIONS manually in the loop.
>
> -Jeff
>
>
> On Fri, Oct 14, 2011 at 10:54 PM, Jeff Whitaker wrote:
>
>   On 10/12/11 8:20 PM, questions anon wrote:
>
> Hi All,
> I keep receiving a memory error when processing many netcdf files. I
> assumed it had something to do with how I loop things and maybe needed to
> close things off properly but I recently received an error that made me
> think it might be because of matplotlib.
>
> In the code below I am looping through a bunch of netcdf files (each file
> is hourly data for one month) and within each netcdf file I am outputting a
> *png file every three hours. This works for one netcdf file (therefore one
> month) but when it begins to process the next netcdf file I receive a memory
> error (see below). Since I have tidied some of my code up it seems to
> process partly into the second file but then I still receive the memory
> error.
> I have tried a few suggestions such as:
> -Combining the dataset using MFDataset (using NETCDF4) is not an option
> because the files do not have unlimited dimension.
> - gc.collect() but that just results in a *GEOS_ERROR: bad allocation
> error*.
> -only open LAT and LON once (which worked)
>
> System Details:
> Python 2.7.2 |EPD 7.1-2 (32-bit)| (default, Jul  3 2011, 15:13:59) [MSC
> v.1500 32 bit (Intel)] on win32
>
> Any feedback will be greatly appreciated as I seem to keep ending up with
> memory errors when working with netcdf files this even happens if I am using
> a much better computer.
>
> *Most recent error: *
> Traceback (most recent call last):
>   File "C:\plot_netcdf_merc_multiplot_across_multifolders_TSFC.py", line
> 78, in 
> plt.savefig((os.path.join(outputfolder, 'TSFC'+date_string+'UTC.png')))
>   File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 363, in
> savefig
> return fig.savefig(*args, **kwargs)
>   File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1084, in
> savefig
> self.canvas.print_figure(*args, **kwargs)
>   File
> "C:\Python27\lib\site-packages\matplotlib\backends\backend_wxagg.py", line
> 100, in print_figure
> FigureCanvasAgg.print_figure(self, filename, *args, **kwargs)
>   File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line
> 1923, in print_figure
> **kwargs)
>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 438, in print_png
> FigureCanvasAgg.draw(self)
>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 393, in draw
> self.renderer = self.get_renderer()
>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 404, in get_renderer
> self.renderer = RendererAgg(w, h, self.figure.dpi)
>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 59, in __init__
> self._renderer = _RendererAgg(int(width), int(height), dpi,
> debug=False)
> RuntimeError: Could not allocate memory for image
>
> *Error when I added gc.collect()*
> GEOS_ERROR: bad allocation
>
> *Old error (before adding gc.collect() )*
> *Traceback (most recent call last):
>   File "d:/plot_netcdf_merc_multiplot_across_multifolders__memoryerror.py",
> line 44, in 
> TSFC=ncfile.variables['T_SFC'][1::3]
>   File "netCDF4.pyx", line 2473, in netCDF4.Variable.__getitem__
> (netCDF4.c:23094)
> MemoryError*
>
>
>
> from netCDF4 import Dataset
> import numpy as N
> import matplotlib.pyplot as plt
> from mpl_too

Re: [Matplotlib-users] memory error - netcdf plots

2011-10-18 Thread questions anon
Thanks Jeff, that certainly speeds it up! But when I take them out of the
loop and place them elsewhere they are no longer added to the map.
Is there someway I can call them in the loop but still get it to run
quickly?
Thanks

On Fri, Oct 14, 2011 at 10:54 PM, Jeff Whitaker  wrote:

>  On 10/12/11 8:20 PM, questions anon wrote:
>
> Hi All,
> I keep receiving a memory error when processing many netcdf files. I
> assumed it had something to do with how I loop things and maybe needed to
> close things off properly but I recently received an error that made me
> think it might be because of matplotlib.
>
> In the code below I am looping through a bunch of netcdf files (each file
> is hourly data for one month) and within each netcdf file I am outputting a
> *png file every three hours. This works for one netcdf file (therefore one
> month) but when it begins to process the next netcdf file I receive a memory
> error (see below). Since I have tidied some of my code up it seems to
> process partly into the second file but then I still receive the memory
> error.
> I have tried a few suggestions such as:
> -Combining the dataset using MFDataset (using NETCDF4) is not an option
> because the files do not have unlimited dimension.
> - gc.collect() but that just results in a *GEOS_ERROR: bad allocation
> error*.
> -only open LAT and LON once (which worked)
>
> System Details:
> Python 2.7.2 |EPD 7.1-2 (32-bit)| (default, Jul  3 2011, 15:13:59) [MSC
> v.1500 32 bit (Intel)] on win32
>
> Any feedback will be greatly appreciated as I seem to keep ending up with
> memory errors when working with netcdf files this even happens if I am using
> a much better computer.
>
> *Most recent error: *
> Traceback (most recent call last):
>   File "C:\plot_netcdf_merc_multiplot_across_multifolders_TSFC.py", line
> 78, in 
> plt.savefig((os.path.join(outputfolder, 'TSFC'+date_string+'UTC.png')))
>   File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 363, in
> savefig
> return fig.savefig(*args, **kwargs)
>   File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1084, in
> savefig
> self.canvas.print_figure(*args, **kwargs)
>   File
> "C:\Python27\lib\site-packages\matplotlib\backends\backend_wxagg.py", line
> 100, in print_figure
> FigureCanvasAgg.print_figure(self, filename, *args, **kwargs)
>   File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line
> 1923, in print_figure
> **kwargs)
>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 438, in print_png
> FigureCanvasAgg.draw(self)
>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 393, in draw
> self.renderer = self.get_renderer()
>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 404, in get_renderer
> self.renderer = RendererAgg(w, h, self.figure.dpi)
>   File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 59, in __init__
> self._renderer = _RendererAgg(int(width), int(height), dpi,
> debug=False)
> RuntimeError: Could not allocate memory for image
>
> *Error when I added gc.collect()*
> GEOS_ERROR: bad allocation
>
> *Old error (before adding gc.collect() )*
> *Traceback (most recent call last):
>   File "d:/plot_netcdf_merc_multiplot_across_multifolders__memoryerror.py",
> line 44, in 
> TSFC=ncfile.variables['T_SFC'][1::3]
>   File "netCDF4.pyx", line 2473, in netCDF4.Variable.__getitem__
> (netCDF4.c:23094)
> MemoryError*
>
>
>
> from netCDF4 import Dataset
> import numpy as N
> import matplotlib.pyplot as plt
> from mpl_toolkits.basemap import Basemap
> from netcdftime import utime
> from datetime import datetime
> import os
> import gc
>
>
> shapefile1="E:/
>>
>> griddeddatasamples/GIS/DSE_REGIONS"
>> MainFolder=r"E:/griddeddatasamples/GriddedData/InputsforValidation/T_SFC/"
>> OutputFolder=r"E:/griddeddatasamples/GriddedData/OutputsforValidation"
>> fileforlatlon=Dataset("E:/griddeddatasamples/GriddedData/InputsforValidation/T_SFC/TSFC_1974_01/IDZ00026_VIC_ADFD_T_SFC.nc",
>> 'r+', 'NETCDF4')
>> LAT=fileforlatlon.variables['latitude'][:]
>> LON=fileforlatlon.variables['longitude'][:]
>>
>> for (path, dirs, files) in os.walk(MainFolder):
>> for dir in dirs:
>> print dir
>> path=path+'/'
>> for ncfile in files:
>> if ncfile[-3:]=='.nc':
>>

Re: [Matplotlib-users] plot arrows for wind direction (degrees)

2011-10-13 Thread questions anon
Thanks,
Ben, that makes sense although I think the angles I have can be considered
the direction 'to' and I want direction 'from' so adding a negative makes
them come from the direction I need.

I should add I don't really know what flip does so will ignore that.
thanks for the responses.



On Fri, Oct 14, 2011 at 9:32 AM, Eric Firing  wrote:

> On 10/13/2011 12:22 PM, Benjamin Root wrote:
>
>>
>>
>> On Thursday, October 13, 2011, questions anon > <mailto:questions.anon@gmail.**com >> wrote:
>>  > Another quick question,
>>  > I noticed that the wind direction appeared back-to-front so I have
>> added a negative  to my equation as I am in the southern hemisphere. It
>> now looks correct but I wanted to check if this is the right way to do
>> this? I saw something called 'flip' for barb but nothing for quiver.
>>
>> It probably nothing to do with southern hemisphere but rather that it is
>> typical for wind data to be recorded and displayed as direction "from",
>> instead of direction "to".  If you think "flip" should be available for
>> quiver(), file a feature request.
>>
>
> It looks to me like the barb "flip" is for something else entirely--it is a
> right-hand versus left-hand sort of flip.  This would be inappropriate for
> quiver, which makes symmetric arrows.  I would strongly oppose any proposal
> for a kwarg to reverse the direction of the arrows.
>
> Eric
>
>
>
>> Ben Root
>>
>
>
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot arrows for wind direction (degrees)

2011-10-13 Thread questions anon
Another quick question,
I noticed that the wind direction appeared back-to-front so I have added a
negative  to my equation as I am in the southern hemisphere. It now looks
correct but I wanted to check if this is the right way to do this? I saw
something called 'flip' for barb but nothing for quiver.
Thanks, see code below

   map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,

llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')

x,y=map(*N.meshgrid(LON,LAT))
u=-1*N.sin(WDIR*N.pi/180)# added negative to account for
southern hemisphere
v=-1*N.cos(WDIR*N.pi/180)
map.quiver(x,y,u, v)



On Wed, Oct 5, 2011 at 3:20 PM, questions anon wrote:

> thank you! of course!
>
>
> On Wed, Oct 5, 2011 at 3:08 PM, Eric Firing  wrote:
>
>> On 10/04/2011 05:40 PM, questions anon wrote:
>> > Excellent, thank you. That works for both quiver and barb.
>> > In regards to the shape that has to do with the netcdf file, wind
>> > direction variable also has lat and lon. I ended up needing to slice so
>> > I could skip a few points otherwise there was too many arrows on the
>> map.
>> > Below is the code that worked in case someone else needs help.
>>
>> Are you sure it worked correctly?  I don't think so.  See below.
>>
>> > Thanks again
>> >
>> > from netCDF4 import Dataset
>> > import numpy as N
>> > import pylab as plt
>> > from numpy import ma as MA
>> > from mpl_toolkits.basemap import Basemap
>> > import os
>> >
>> > ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc',
>> > 'r+', 'NETCDF4')
>> > WDIR=ncfile.variables['Wind_Dir_SFC'][20,0::5,0::5]
>>
>> Don't you need to convert from degrees to radians?  sin and cos (used
>> below) expect radians, not degrees.  You can use N.deg2rad(WDIR) to
>> convert.
>>
>> > LAT=ncfile.variables['latitude'][0::5]
>> > LON=ncfile.variables['longitude'][0::5]
>> > TIME=ncfile.variables['time'][20]
>> > ncfile.close()
>> >
>> > map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
>> >llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
>> > x,y=map(*N.meshgrid(LON,LAT))
>> > u=1*N.sin(WDIR)
>> > v=1*N.cos(WDIR)
>> > map.quiver(x,y,u, v)
>>
>> Assuming you do convert to radians the above will work for your mercator
>> projection but it will not align the vectors correctly with respect to
>> the parallels and meridians for other projections, so you should use
>> map.rotate_vector as in the basemap quiver demo.
>>
>> Eric
>>
>>
>> >
>> > #  otherwise use the barb tool - map.barbs(x,y,u, v)
>> >
>> > plt.title('Wind Direction')
>> > plt.show()
>>
>>
>> --
>> All the data continuously generated in your IT infrastructure contains a
>> definitive record of customers, application performance, security
>> threats, fraudulent activity and more. Splunk takes this data and makes
>> sense of it. Business sense. IT sense. Common sense.
>> http://p.sf.net/sfu/splunk-d2dcopy1
>> ___
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>
>
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] memory error - netcdf plots

2011-10-12 Thread questions anon
Hi All,
I keep receiving a memory error when processing many netcdf files. I assumed
it had something to do with how I loop things and maybe needed to close
things off properly but I recently received an error that made me think it
might be because of matplotlib.

In the code below I am looping through a bunch of netcdf files (each file is
hourly data for one month) and within each netcdf file I am outputting a
*png file every three hours. This works for one netcdf file (therefore one
month) but when it begins to process the next netcdf file I receive a memory
error (see below). Since I have tidied some of my code up it seems to
process partly into the second file but then I still receive the memory
error.
I have tried a few suggestions such as:
-Combining the dataset using MFDataset (using NETCDF4) is not an option
because the files do not have unlimited dimension.
- gc.collect() but that just results in a *GEOS_ERROR: bad allocation error*.

-only open LAT and LON once (which worked)

System Details:
Python 2.7.2 |EPD 7.1-2 (32-bit)| (default, Jul  3 2011, 15:13:59) [MSC
v.1500 32 bit (Intel)] on win32

Any feedback will be greatly appreciated as I seem to keep ending up with
memory errors when working with netcdf files this even happens if I am using
a much better computer.

*Most recent error: *
Traceback (most recent call last):
  File "C:\plot_netcdf_merc_multiplot_across_multifolders_TSFC.py", line 78,
in 
plt.savefig((os.path.join(outputfolder, 'TSFC'+date_string+'UTC.png')))
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 363, in
savefig
return fig.savefig(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1084, in
savefig
self.canvas.print_figure(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_wxagg.py",
line 100, in print_figure
FigureCanvasAgg.print_figure(self, filename, *args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line
1923, in print_figure
**kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
line 438, in print_png
FigureCanvasAgg.draw(self)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
line 393, in draw
self.renderer = self.get_renderer()
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
line 404, in get_renderer
self.renderer = RendererAgg(w, h, self.figure.dpi)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py",
line 59, in __init__
self._renderer = _RendererAgg(int(width), int(height), dpi, debug=False)
RuntimeError: Could not allocate memory for image

*Error when I added gc.collect()*
GEOS_ERROR: bad allocation

*Old error (before adding gc.collect() )*
*Traceback (most recent call last):
  File "d:/plot_netcdf_merc_multiplot_across_multifolders__memoryerror.py",
line 44, in 
TSFC=ncfile.variables['T_SFC'][1::3]
  File "netCDF4.pyx", line 2473, in netCDF4.Variable.__getitem__
(netCDF4.c:23094)
MemoryError*



from netCDF4 import Dataset
import numpy as N
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from netcdftime import utime
from datetime import datetime
import os
import gc


shapefile1="E:/
>
> griddeddatasamples/GIS/DSE_REGIONS"
> MainFolder=r"E:/griddeddatasamples/GriddedData/InputsforValidation/T_SFC/"
> OutputFolder=r"E:/griddeddatasamples/GriddedData/OutputsforValidation"
> fileforlatlon=Dataset("E:/griddeddatasamples/GriddedData/InputsforValidation/T_SFC/TSFC_1974_01/IDZ00026_VIC_ADFD_T_SFC.nc",
> 'r+', 'NETCDF4')
> LAT=fileforlatlon.variables['latitude'][:]
> LON=fileforlatlon.variables['longitude'][:]
>
> for (path, dirs, files) in os.walk(MainFolder):
> for dir in dirs:
> print dir
> path=path+'/'
> for ncfile in files:
> if ncfile[-3:]=='.nc':
> print "dealing with ncfiles:", ncfile
> ncfile=os.path.join(path,ncfile)
> ncfile=Dataset(ncfile, 'r+', 'NETCDF4')
> TSFC=ncfile.variables['T_SFC'][1::3]
> TIME=ncfile.variables['time'][1::3]
> ncfile.close()
> gc.collect()
>
> for TSFC, TIME in zip((TSFC[:]),(TIME[:])):
> cdftime=utime('seconds since 1970-01-01 00:00:00')
> ncfiletime=cdftime.num2date(TIME)
> print ncfiletime
> timestr=str(ncfiletime)
> d = datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S')
> date_string = d.strftime('%Y%m%d_%H%M')
>
> map =
> Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
>
> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> x,y=map(*N.meshgrid(LON,LAT))
> map.drawcoastlines(linewidth=0.5)
> map.readshapefile(shapefile1, 'DSE_REGIONS')
> map.drawstates()
>
> plt.title('Surface temperature at %s UTC'%ncfiletime)
>   

Re: [Matplotlib-users] plot arrows for wind direction (degrees)

2011-10-04 Thread questions anon
thank you! of course!

On Wed, Oct 5, 2011 at 3:08 PM, Eric Firing  wrote:

> On 10/04/2011 05:40 PM, questions anon wrote:
> > Excellent, thank you. That works for both quiver and barb.
> > In regards to the shape that has to do with the netcdf file, wind
> > direction variable also has lat and lon. I ended up needing to slice so
> > I could skip a few points otherwise there was too many arrows on the map.
> > Below is the code that worked in case someone else needs help.
>
> Are you sure it worked correctly?  I don't think so.  See below.
>
> > Thanks again
> >
> > from netCDF4 import Dataset
> > import numpy as N
> > import pylab as plt
> > from numpy import ma as MA
> > from mpl_toolkits.basemap import Basemap
> > import os
> >
> > ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc',
> > 'r+', 'NETCDF4')
> > WDIR=ncfile.variables['Wind_Dir_SFC'][20,0::5,0::5]
>
> Don't you need to convert from degrees to radians?  sin and cos (used
> below) expect radians, not degrees.  You can use N.deg2rad(WDIR) to
> convert.
>
> > LAT=ncfile.variables['latitude'][0::5]
> > LON=ncfile.variables['longitude'][0::5]
> > TIME=ncfile.variables['time'][20]
> > ncfile.close()
> >
> > map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> >llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> > x,y=map(*N.meshgrid(LON,LAT))
> > u=1*N.sin(WDIR)
> > v=1*N.cos(WDIR)
> > map.quiver(x,y,u, v)
>
> Assuming you do convert to radians the above will work for your mercator
> projection but it will not align the vectors correctly with respect to
> the parallels and meridians for other projections, so you should use
> map.rotate_vector as in the basemap quiver demo.
>
> Eric
>
>
> >
> > #  otherwise use the barb tool - map.barbs(x,y,u, v)
> >
> > plt.title('Wind Direction')
> > plt.show()
>
>
> --
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] plot arrows for wind direction (degrees)

2011-10-04 Thread questions anon
Excellent, thank you. That works for both quiver and barb.
In regards to the shape that has to do with the netcdf file, wind direction
variable also has lat and lon. I ended up needing to slice so I could skip a
few points otherwise there was too many arrows on the map.
Below is the code that worked in case someone else needs help.
Thanks again

from netCDF4 import Dataset
import numpy as N
import pylab as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os

ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][20,0::5,0::5]
LAT=ncfile.variables['latitude'][0::5]
LON=ncfile.variables['longitude'][0::5]
TIME=ncfile.variables['time'][20]
ncfile.close()

map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
  llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
x,y=map(*N.meshgrid(LON,LAT))
u=1*N.sin(WDIR)
v=1*N.cos(WDIR)
map.quiver(x,y,u, v)

#  otherwise use the barb tool - map.barbs(x,y,u, v)

plt.title('Wind Direction')
plt.show()


On Wed, Oct 5, 2011 at 2:00 PM, Ethan Gutmann wrote:

> Anon,
> I don't know the quiver routine, but u and v are usually vectors for the
> wind speed in the east-west and north south directions.  As such they should
> not be equal to lat and lon (*10), as you are doing, but rather should be
> windspeed * sin(direction)  and windspeed*cos(direction).  If you don't have
> windspeed or want them all to be the same size arrows, just substitute 1 for
> windspeed (or 10 if you want longer arrows)
>
> You shouldn't have to "set" north,south,east,west, etc.  generally North is
> 0, South is 180, etc, so that should all be assigned already.
>
> It also looks like you have an array size mis-match, can you print
> LAT.shape, LON.shape,TIME.shape,WDIR.shape it may be that your lat,lon
> variables also need to be subset to [-50]?
>
> hope this helps,
> Ethan
>
> On Oct 4, 2011, at 5:58 PM, questions anon wrote:
>
> Thanks for responding. I believe quiver is more appropriate because I am
> only using wind direction (at this stage) and this results in arrows.
> I have had a look at the demos and still do not understand how to plot my
> degrees in arrows. How do I define which angle is north, south, west, east,
> etc?
> Any suggestions? Thanks
>
> from netCDF4 import Dataset
> import numpy as N
> import pylab as plt
> from numpy import ma as MA
> from mpl_toolkits.basemap import Basemap
> import os
>
> ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
> 'NETCDF4')
> WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
> LAT=ncfile.variables['latitude'][:]
> LON=ncfile.variables['longitude'][:]
> TIME=ncfile.variables['time'][-50]
> ncfile.close()
>
> map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
>   llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> x,y=LON,LAT
> u=10*x
> v=10*y
> map.quiver(x,y,u, v, WDIR)
> plt.title('Wind Direction')
> plt.show()
>
>
> Traceback (most recent call last):
>   File "d:/plot_winddirection.py", line 22, in 
> map.quiver(x,y,u, v, WDIR)
>   File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
> line 3102, in quiver
> ret =  ax.quiver(x,y,u,v,*args,**kwargs)
>   File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 6320, in
> quiver
> q = mquiver.Quiver(self, *args, **kw)
>   File "C:\Python27\lib\site-packages\matplotlib\quiver.py", line 395, in
> __init__
> self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
>   File "C:\Python27\lib\site-packages\numpy\core\shape_base.py", line 270,
> in hstack
> return _nx.concatenate(map(atleast_1d,tup),1)
> ValueError: array dimensions must agree except for d_0
>
>
>
> On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing  wrote:
>
>> On 10/03/2011 03:00 PM, Benjamin Root wrote:
>> > On Mon, Oct 3, 2011 at 6:51 PM, questions anon <
>> questions.a...@gmail.com
>> > <mailto:questions.a...@gmail.com>> wrote:
>> >
>> > Hi All,
>> > Is there a simple way to plot a directional arrow to represent a
>> degree?
>> > I have a netcdf file containing wind direction as degrees and I
>> > would like to make a plot with all little arrows representing the
>> > wind direction.
>> > Below is the code I am using currently to plot wind direction but am
>> > not sure where/how to add directional arrows

Re: [Matplotlib-users] plot arrows for wind direction (degrees)

2011-10-04 Thread questions anon
Thanks for responding. I believe quiver is more appropriate because I am
only using wind direction (at this stage) and this results in arrows.
I have had a look at the demos and still do not understand how to plot my
degrees in arrows. How do I define which angle is north, south, west, east,
etc?
Any suggestions? Thanks

from netCDF4 import Dataset
import numpy as N
import pylab as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os

ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][-50]
ncfile.close()

map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
  llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
x,y=LON,LAT
u=10*x
v=10*y
map.quiver(x,y,u, v, WDIR)
plt.title('Wind Direction')
plt.show()


Traceback (most recent call last):
  File "d:/plot_winddirection.py", line 22, in 
map.quiver(x,y,u, v, WDIR)
  File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
line 3102, in quiver
ret =  ax.quiver(x,y,u,v,*args,**kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 6320, in
quiver
q = mquiver.Quiver(self, *args, **kw)
  File "C:\Python27\lib\site-packages\matplotlib\quiver.py", line 395, in
__init__
self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
  File "C:\Python27\lib\site-packages\numpy\core\shape_base.py", line 270,
in hstack
return _nx.concatenate(map(atleast_1d,tup),1)
ValueError: array dimensions must agree except for d_0



On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing  wrote:

> On 10/03/2011 03:00 PM, Benjamin Root wrote:
> > On Mon, Oct 3, 2011 at 6:51 PM, questions anon  > <mailto:questions.a...@gmail.com>> wrote:
> >
> > Hi All,
> > Is there a simple way to plot a directional arrow to represent a
> degree?
> > I have a netcdf file containing wind direction as degrees and I
> > would like to make a plot with all little arrows representing the
> > wind direction.
> > Below is the code I am using currently to plot wind direction but am
> > not sure where/how to add directional arrows.
> > Thanks
> >
> >
> > from netCDF4 import Dataset
> > import numpy as N
> > import pylab as plt
> > from numpy import ma as MA
> > from mpl_toolkits.basemap import Basemap
> > import os
> >
> > ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
> > 'NETCDF4')
> > WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
> > LAT=ncfile.variables['latitude'][:]
> > LON=ncfile.variables['longitude'][:]
> > TIME=ncfile.variables['time'][-50]
> > fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
> > WDIR=MA.masked_values(WDIR, fillvalue)
> > ncfile.close()
> >
> > map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> >
>  llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> > x,y=map(*N.meshgrid(LON,LAT))
> > map.drawstates()
> > map.drawcoastlines()
> > plt.title('Wind Direction')
> > CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
> > l,b,w,h =0.1,0.1,0.8,0.8
> > cax = plt.axes([l+w+0.025, b, 0.025, h])
> > plt.colorbar(CS,cax=cax,drawedges=True)
> > plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
> > plt.show()
> >
> >
> > Would the barb() command do what you want?
> >
> >
> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs
> > http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html
> >
> > They aren't arrows, but they are commonly used in meteorology to plot
> > windfields.
> >
> > Cheers,
> > Ben Root
>
> There is also quiver, both in matplotlib and in basemap.  See the
> quiver_demo.py and barb_demo.py in the basemap examples directory.
>
> Eric
>
> >
> >
> >
> >
> --
> > All the data continuously generated in your IT infrastructure contains a
> > definitive record of customers, application performance, security
> > threats, fraudulent activity and more. Splunk takes this data and makes
> > 

[Matplotlib-users] plot arrows for wind direction (degrees)

2011-10-03 Thread questions anon
Hi All,
Is there a simple way to plot a directional arrow to represent a degree?
I have a netcdf file containing wind direction as degrees and I would like
to make a plot with all little arrows representing the wind direction.
Below is the code I am using currently to plot wind direction but am not
sure where/how to add directional arrows.
Thanks


from netCDF4 import Dataset
import numpy as N
import pylab as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os

ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][-50]
fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
WDIR=MA.masked_values(WDIR, fillvalue)
ncfile.close()

map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
  llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
x,y=map(*N.meshgrid(LON,LAT))
map.drawstates()
map.drawcoastlines()
plt.title('Wind Direction')
CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
l,b,w,h =0.1,0.1,0.8,0.8
cax = plt.axes([l+w+0.025, b, 0.025, h])
plt.colorbar(CS,cax=cax,drawedges=True)
plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
plt.show()
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] histogram of mean & SD

2009-08-18 Thread questions anon
Can anyone explain how I could:

-Open two shapefiles

-Open a raster

-Plot a histogram of the values within each shapefile on the same plot and
display the mean and Standard Deviation of each plot.

Thanks
--
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
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users