open ascii grid data and plot

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()

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 <questions.anon@…287…> 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()

How did you install numpy? Which version are you using? What are your imports at the top of this script?

Ben Root

···

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()

You should have a look on ATpy package : http://atpy.github.com/

Cheers

JB

···

Le 29 févr. 2012 à 23:29, questions anon a écrit :

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?

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 <ben.root@…1304…> 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

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 <questions.anon@…287…> 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 <ben.root@…1836…304…> 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

In my GIS experience, rasters don't have prj files. That's something
that seems to be pretty specific to ESRI shapefiles. Point is, I don't
think that's going to help you.

All of the basemap examples use netcdf files. I think your path of
least resistance right now is to figure out how to convert your text
file to a numpy array (check?), and then that array to a netcdf that
is structured such that you can follow the basemap examples:
http://matplotlib.github.com/basemap/users/examples.html

Hope that helps,
-paul

···

On Wed, Mar 7, 2012 at 8:21 PM, questions anon <questions.anon@...287...> 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?
Thanks

On Fri, Mar 2, 2012 at 11:49 AM, questions anon <questions.anon@...287...> > 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 <ben.root@...1304...> 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 <module>
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

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

···

On Wednesday, March 7, 2012, questions anon <questions.anon@…287…> 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?

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 -9999
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 <ben.root@…1304…> wrote:

On Wednesday, March 7, 2012, questions anon <questions.anon@…287…> 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

[...]

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 <module>
    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

···

El día 12 de marzo de 2012 23:25, questions anon <questions.anon@...287...> escribió:

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 <goyodiaz@…287…> wrote:

El día 12 de marzo de 2012 23:25, questions anon > > <questions.anon@…287…> 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

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.anon@…287…> 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 <goyodiaz@…1003…7…> wrote:

El día 12 de marzo de 2012 23:25, questions anon > > > > <questions.anon@…287…> 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

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

···

On Tue, Mar 13, 2012 at 4:23 PM, questions anon <questions.anon@…287…> 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.anon@…287…> 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.

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 <ben.root@…3146…4…> wrote:

On Tue, Mar 13, 2012 at 4:23 PM, questions anon <questions.anon@…287…> 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.anon@…287…> 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