Re: [Matplotlib-users] Basemap plotting data on projection

2013-04-29 Thread ChaoYue
Hi all,

Indeed it's a bit strange, I can reproduce the problem. But when using
'cyl' projection I don't have this issue.
attahced two figures showed the difference.

the tested data is also attached.

complete code is below:

from mpl_toolkits.basemap import Basemap, cm, maskoceans
import matplotlib.pyplot as plt


# set up the Mercator projection
m = Basemap(projection='merc',llcrnrlat=9,urcrnrlat=54.5,\
llcrnrlon=74,urcrnrlon=142,lat_ts=20,resolution='l')

m.drawcountries()
m.drawcoastlines()
m.drawmapboundary(fill_color='aqua')
m.drawrivers()

pdata = np.genfromtxt('pdata.txt')
pdata = np.ma.masked_greater(pdata,1E20)
lonm,latm=m.makegrid(pdata.shape[1],pdata.shape[0])

latm=np.flipud(latm)
lonpro,latpro=m(lonm,latm)
cs = m.contourf(lonpro,latpro,pdata)
m.colorbar(cs)

cheers,

Chao

On Mon, Apr 29, 2013 at 12:53 PM, Ann [via matplotlib] <
ml-node+s1069221n40973...@n5.nabble.com> wrote:

> Dear All,
>
>
> I am encountering the following problem:
> I have some data which I want to plot on a map. Unfortunately, I do not
> manage to plot the data according to the shape of the projection! What it
> appears to do is to simply plot the data on top of the projection without
> taking the actual position (latitude and longitude) into account. However,
> this is crucial for my analysis.
> Could anybody spot the mistake in my code?
> Any suggestion would be of great help!!
> THANKS
>
>
>
> from mpl_toolkits.basemap import Basemap, cm, maskoceans
> import matplotlib.pyplot as plt
>
>
> # set up the Mercator projection
> m = Basemap(projection='merc',llcrnrlat=9,urcrnrlat=54.5,\
> llcrnrlon=74,urcrnrlon=142,lat_ts=20,resolution='l')
>
> m.drawcountries()
> m.drawcoastlines()
> m.drawmapboundary(fill_color='aqua')
> m.drawrivers()
>
>
> parallels = N.arange(0.,81,10.)
> labels = [left,right,top,bottom]
> m.drawparallels(parallels,labels=[1,0,0,0])
> meridians = N.arange(10.,351.,20.)
> m.drawmeridians(meridians,labels=[0,0,0,1])
>
>
> ny=resmat.shape[0] # resmat is the matrix containing the data which I want
> o plot.
> nx=resmat.shape[1]
>
> #get lat/lons of ny by nx evenly space grid
> lons, lats =m.makegrid(nx, ny)
>
>
> # compute map projection coordinates
> x, y= m(lons, lats)
>
> maskdata = maskoceans(lons, lats, resmat, inlands= True, resolution = 'l')
>
>
> cs = m.contourf(x,y,maskdata,150,cmap=cm.GMT_no_green_r)
>
> plt.show()
>
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://matplotlib.1069221.n5.nabble.com/Basemap-plotting-data-on-projection-tp40973.html
>  To start a new topic under matplotlib - users, email
> ml-node+s1069221n...@n5.nabble.com
> To unsubscribe from matplotlib, click 
> here
> .
> NAML
>



-- 
***
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16



pdata.txt (413K) 

cyl.jpg (540K) 

merc.jpg (435K) 





--
View this message in context: 
http://matplotlib.1069221.n5.nabble.com/Basemap-plotting-data-on-projection-tp40973p40975.html
Sent from the matplotlib - users mailing list archive at Nabble.com.--
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Projection Direction Distortion

2013-04-29 Thread Mathew Topper

Hi Jody,

Thanks for getting in touch. My reply in line also:

On 26/04/13 18:34, Jody Klymak wrote:
Not clear how a direction is given as a lon lat. Do you mean you have 
a set of vectors, each defined as lon/lat pairs? 


My usage is to examine boundary conditions for a spectral wave model. 
Thus, I have data points at locations given in**geographic coordinates 
with bearings to describe the wave directions.


It depends on what you want - if you want the arrow to point where the 
wind would go after X minutes, then you want the "distortion". If you 
want the viewer to be able to pick off the geographic heading by eye, 
then simply convert your lon lat pairs to heading/length pairs and 
plot them in the axis frame. See 
http://matplotlib.org/basemap/users/mapcoords.html for how to convert 
from basemap to the underlying axis frame.


To clarify, the wave model I am using demands wave directions in the 
projection of the grid which is being used, and I am trying to figure 
out if I need to change the inputs to the wave model, using basemap as 
an indicator, potentially a pre-processor.


In fact, I'm having a bit of a intellectual crisis trying to understand 
what an instantaneous wave direction is and whether such a thing should 
be effected by the projection it is in!


In an ideal world your projection would not be over such a large area 
that any of this matters - if your vector is off by 1 degree, who will 
be able to tell in a plot?


In the plots and also in the model, I think it will make very little 
difference to the outputs. However, I am very interested in 
quantification of uncertainty and therefore I want to demonstrate that 
it could (should the directions need adjustment) make a difference to 
the results, particularly if you were a bit slack with your choice of 
grid projection.


Thanks again for your help and I'm sorry if this is a little "off 
topic", but I know basemap users are a smart bunch to consult with. :)


All the best,

Mat

--
Dr. Mathew Topper
Institute for Energy Systems
School of Engineering
The University of Edinburgh
Faraday Building
The King's Buildings
Edinburgh EH9 3JL
Tel: +44 (0)131 650 5570
School fax: +44 (0)131 650 6554
mathew.top...@ed.ac.uk 
http://www.see.ed.ac.uk 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
--
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users