|
From: Jeff W. <jef...@no...> - 2008-09-10 13:41:47
|
Antoine De Pauw wrote: > Sir, > > I'm sorry, as english is not my mothertongue and it is sometimes difficult to be understandable. > > All is in the script I gave to you initially, except the point drawing code which would be useless as it is proven not to work (I dont know the method to do it). > > What I have is a map, and a set of pixels I have to put on it with geographic coordinates. > > I cannot find the right method to put colour pixels on the map, that's the problem. > > I have that map in miller projection, and three arrays containing respectively latitude, longitude and satellite measured value. > > What I need to obtain is something approximately like this: http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703_00_lr.gif but with the basemap toolkit. > > So, my question is: how could I do to plot a coloured pixel at coordinates lat:lon on that map? If I have just the method to project a geographic coordinate on the map and put a coloured pixel at the right place, all is done and I just have to loop my arrays... Also, I would have to implement some antialiasing on the map. > Antoine: Are the pixels arranged on a regular grid - or are they randomly distributed? If they are on a grid, it's easy (using pcolor or imshow). If you could send me your data I may be able to get you started. (I'm cc'ing the matplotlib list so others can join in the discussion). -Jeff > If this is not possible to do it in a simple and explainable way, please tell me and I'll continue using matlab or searching for the bit of code which will save me > > Anyway, I have to thank you for your interest to help me.. > > Many thanks, > > Antoine De Pauw > > >> Antoine De Pauw wrote: >> >>> Hi, and thanks for the answer >>> >>> In fact, what I do is reading a binary file to obtain 3 arrays (Lat,Lon,Val) describing geographic points which are associated by index (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>> >>> What I need to do is to plot some points on the map (miller projection for most) based on latitude and longitude, to obtain a colour map (points are unordered, it is from IASI satellite computations) >>> >>> I'm able to create a map, draw simple things on it, etc but the problem I have is any method I try for plotting points is failing, either pcolor, pcolormesh, imshow, etc. >>> >>> When I found your post on that mailing list, I figured out that you might have the experience and skills to easily explain to me how to manipulate these points and plot them on the map, as there's like no help on the web except standard examples... >>> >>> Please tell me if this is possible for you to give me some tips, or if it takes too much of your time just advice me some lectures >>> >>> Best regards, >>> >>> De Pauw Antoine >>> >>> >> Antoine: It would really help to have a script demonstrating your >> problem. It sounds to me like you want to plot markers representing a >> set of points - for that you should use the scatter method. pcolor, >> pcolormesh and friends are for plotting gridded data. >> >> -Jeff >> >>> >>> >>>> De Pauw Antoine wrote: >>>> >>>> >>>>> Dear sir, >>>>> >>>>> >>>>> >>>>> I’m currently trying to improve our plotting tools here at the “Quantum >>>>> Chemistry and Photophysics” section of the Université Libre de >>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>> solution, on an explanation from you here: >>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>> >>>>> >>>>> >>>>> It seems that you could help me find a solution, as I cannot plot any >>>>> points on maps. >>>>> >>>>> >>>>> >>>>> Could you please tell me what I could do to plot data in a simple way, >>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>> longitude and values to plot? >>>>> >>>>> >>>>> >>>>> Some tips would be very nice from you as any method I have tried so far >>>>> give me some errors… >>>>> >>>>> >>>>> >>>>> Thank you very much in advance, >>>>> >>>>> >>>>> >>>>> Best regards, >>>>> >>>>> >>>>> >>>>> PS: I give you the code I’m using currently, missing the plotting part >>>>> >>>>> >>>>> >>>>> from mpl_toolkits.basemap import Basemap >>>>> >>>>> from numpy import * >>>>> >>>>> from scipy.io.numpyio import fread >>>>> >>>>> import matplotlib.pyplot as plt >>>>> >>>>> import numpy as np >>>>> >>>>> import os >>>>> >>>>> import sys >>>>> >>>>> import array >>>>> >>>>> >>>>> >>>>> fileName="c:/20080821.b56" >>>>> >>>>> >>>>> >>>>> print('preparing map') >>>>> >>>>> map = >>>>> Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) >>>>> >>>>> map.drawcoastlines(0.5,antialiased=1) >>>>> >>>>> map.drawmapboundary() >>>>> >>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>> >>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>> >>>>> print('reading binary data') >>>>> >>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>> >>>>> Lat=zeros(nbreligne) >>>>> >>>>> Lon=zeros(nbreligne) >>>>> >>>>> Val=zeros(nbreligne) >>>>> >>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>> >>>>> Lat=rawfile[0:nbreligne] >>>>> >>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>> >>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>> >>>>> print('shifting latitudes and projecting to map') >>>>> >>>>> i=0 >>>>> >>>>> while i < nbreligne: >>>>> >>>>> if(Lon[i]>180): >>>>> >>>>> print(Lon[i]) >>>>> >>>>> Lon[i]-=360 >>>>> >>>>> print(Lon[i]) >>>>> >>>>> i+=1 >>>>> >>>>> print('plotting data') >>>>> >>>>> >>>>> >>>>> #plotting code comes here >>>>> >>>>> >>>> Antoine: If you send me a self-contained script that produces the >>>> problem you see, I can help you debug it. As it stands now, I have very >>>> little to work with - it could be your plotting commands, or it could be >>>> your data. >>>> >>>> -Jeff >>>> >>>> >>>>> >>>>> >>>>> print('saving map') >>>>> >>>>> plt.savefig("testfig.png",dpi=600) >>>>> >>>>> print('done') >>>>> >>>>> >>>>> >>>>> *Antoine De Pauw* >>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>>> photophysics laboratory >>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>> >>>>> >>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> Meteorologist FAX : (303)497-6449 >>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>> >>>> >>>> >>>> >>> >>> >> -- >> Jeffrey S. Whitaker Phone : (303)497-6313 >> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >> 325 Broadway Boulder, CO, USA 80305-3328 >> >> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: Jeff W. <Jef...@no...> - 2008-09-10 14:44:51
|
Antoine De Pauw wrote: > Thanks Jeff, > > In fact my points are arranged in three unsorted arrays, with a simple scheme (thats why I couldn't plot them with imshow and others) > > arrays: > > [lat][lon][val] > [-10][ 17][0.3] > [ 37][ 23][3.7] > ... ... ... > > and so for many rows... > > what I have to do is looping through my arrays like that > > while i < rowcount: > plot_to_map(lat[i],lon[i],val[i]) > > it is evidently an idea of how it could be done easily but my knowledge of these libraries is too weak for me to figure out how to do it > > my data comes from huge binary files but is extremely simple, so it would be really easy for anyone to help me as the problem itself is how to put unsorted points on the map with latitude and longitude coordinates > Antoine: You haven't said if your data forms a rectangular array. If so, you can build a 2-d array from the input file and plot it with imshow. If not, you can still plug the elements into a 2-d masked array, leaving the missing pixels masked. You say the points are 'unsorted', does that mean they are randomly distributed and do not form a rectangular grid? It would really be much easier to help if you gave us more information, such as how the data is structured, what the pixel footprint is, etc. Perhaps you could post the binary file on an ftp site somewhere with code to read it. Also, please hit 'reply all' when replying, so the matplotlib users mailing list is CC'ed. -Jeff >> Antoine De Pauw wrote: >>> Sir, >>> >>> I'm sorry, as english is not my mothertongue and it is sometimes difficult to be understandable. >>> >>> All is in the script I gave to you initially, except the point drawing code which would be useless as it is proven not to work (I dont know the method to do it). >>> >>> What I have is a map, and a set of pixels I have to put on it with geographic coordinates. >>> >>> I cannot find the right method to put colour pixels on the map, that's the problem. >>> >>> I have that map in miller projection, and three arrays containing respectively latitude, longitude and satellite measured value. >>> >>> What I need to obtain is something approximately like this: http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703_00_lr.gif but with the basemap toolkit. >>> >>> So, my question is: how could I do to plot a coloured pixel at coordinates lat:lon on that map? If I have just the method to project a geographic coordinate on the map and put a coloured pixel at the right place, all is done and I just have to loop my arrays... Also, I would have to implement some antialiasing on the map. >>> >> Antoine: >> >> Are the pixels arranged on a regular grid - or are they randomly >> distributed? If they are on a grid, it's easy (using pcolor or imshow). >> >> If you could send me your data I may be able to get you started. >> >> (I'm cc'ing the matplotlib list so others can join in the discussion). >> >> >> -Jeff >>> If this is not possible to do it in a simple and explainable way, please tell me and I'll continue using matlab or searching for the bit of code which will save me >>> >>> Anyway, I have to thank you for your interest to help me.. >>> >>> Many thanks, >>> >>> Antoine De Pauw >>> >>> >>>> Antoine De Pauw wrote: >>>> >>>>> Hi, and thanks for the answer >>>>> >>>>> In fact, what I do is reading a binary file to obtain 3 arrays (Lat,Lon,Val) describing geographic points which are associated by index (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>>> >>>>> What I need to do is to plot some points on the map (miller projection for most) based on latitude and longitude, to obtain a colour map (points are unordered, it is from IASI satellite computations) >>>>> >>>>> I'm able to create a map, draw simple things on it, etc but the problem I have is any method I try for plotting points is failing, either pcolor, pcolormesh, imshow, etc. >>>>> >>>>> When I found your post on that mailing list, I figured out that you might have the experience and skills to easily explain to me how to manipulate these points and plot them on the map, as there's like no help on the web except standard examples... >>>>> >>>>> Please tell me if this is possible for you to give me some tips, or if it takes too much of your time just advice me some lectures >>>>> >>>>> Best regards, >>>>> >>>>> De Pauw Antoine >>>>> >>>>> >>>> Antoine: It would really help to have a script demonstrating your >>>> problem. It sounds to me like you want to plot markers representing a >>>> set of points - for that you should use the scatter method. pcolor, >>>> pcolormesh and friends are for plotting gridded data. >>>> >>>> -Jeff >>>> >>>>> >>>>> >>>>>> De Pauw Antoine wrote: >>>>>> >>>>>> >>>>>>> Dear sir, >>>>>>> >>>>>>> >>>>>>> >>>>>>> I’m currently trying to improve our plotting tools here at the “Quantum >>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>> solution, on an explanation from you here: >>>>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>>>> >>>>>>> >>>>>>> >>>>>>> It seems that you could help me find a solution, as I cannot plot any >>>>>>> points on maps. >>>>>>> >>>>>>> >>>>>>> >>>>>>> Could you please tell me what I could do to plot data in a simple way, >>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>> longitude and values to plot? >>>>>>> >>>>>>> >>>>>>> >>>>>>> Some tips would be very nice from you as any method I have tried so far >>>>>>> give me some errors… >>>>>>> >>>>>>> >>>>>>> >>>>>>> Thank you very much in advance, >>>>>>> >>>>>>> >>>>>>> >>>>>>> Best regards, >>>>>>> >>>>>>> >>>>>>> >>>>>>> PS: I give you the code I’m using currently, missing the plotting part >>>>>>> >>>>>>> >>>>>>> >>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>> >>>>>>> from numpy import * >>>>>>> >>>>>>> from scipy.io.numpyio import fread >>>>>>> >>>>>>> import matplotlib.pyplot as plt >>>>>>> >>>>>>> import numpy as np >>>>>>> >>>>>>> import os >>>>>>> >>>>>>> import sys >>>>>>> >>>>>>> import array >>>>>>> >>>>>>> >>>>>>> >>>>>>> fileName="c:/20080821.b56" >>>>>>> >>>>>>> >>>>>>> >>>>>>> print('preparing map') >>>>>>> >>>>>>> map = >>>>>>> Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) >>>>>>> >>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>> >>>>>>> map.drawmapboundary() >>>>>>> >>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>> >>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>> >>>>>>> print('reading binary data') >>>>>>> >>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>> >>>>>>> Lat=zeros(nbreligne) >>>>>>> >>>>>>> Lon=zeros(nbreligne) >>>>>>> >>>>>>> Val=zeros(nbreligne) >>>>>>> >>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>> >>>>>>> Lat=rawfile[0:nbreligne] >>>>>>> >>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>> >>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>> >>>>>>> print('shifting latitudes and projecting to map') >>>>>>> >>>>>>> i=0 >>>>>>> >>>>>>> while i < nbreligne: >>>>>>> >>>>>>> if(Lon[i]>180): >>>>>>> >>>>>>> print(Lon[i]) >>>>>>> >>>>>>> Lon[i]-=360 >>>>>>> >>>>>>> print(Lon[i]) >>>>>>> >>>>>>> i+=1 >>>>>>> >>>>>>> print('plotting data') >>>>>>> >>>>>>> >>>>>>> >>>>>>> #plotting code comes here >>>>>>> >>>>>>> >>>>>> Antoine: If you send me a self-contained script that produces the >>>>>> problem you see, I can help you debug it. As it stands now, I have very >>>>>> little to work with - it could be your plotting commands, or it could be >>>>>> your data. >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>>> >>>>>>> >>>>>>> print('saving map') >>>>>>> >>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>> >>>>>>> print('done') >>>>>>> >>>>>>> >>>>>>> >>>>>>> *Antoine De Pauw* >>>>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>>>>> photophysics laboratory >>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> Meteorologist FAX : (303)497-6449 >>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>> >>>> >>>> >>>> >>> >>> >> >> -- >> Jeffrey S. Whitaker Phone : (303)497-6313 >> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >> 325 Broadway Boulder, CO, USA 80305-3328 >> >> >> > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |
|
From: De P. A. <and...@ul...> - 2008-09-11 09:16:25
|
Hi Jeff, I have put the code online with a sample of the data here: http://snipplr.com/view/8307/map-plotting-python-code-temporary/ I hope you'll be able to give me some advice as it is quite difficult for someone new in python and scientific computation Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:Jef...@no...] Sent: mercredi 10 septembre 2008 16:45 To: Antoine De Pauw Cc: Matplotlib Users Subject: Re: Information request Antoine De Pauw wrote: > Thanks Jeff, > > In fact my points are arranged in three unsorted arrays, with a simple scheme (thats why I couldn't plot them with imshow and others) > > arrays: > > [lat][lon][val] > [-10][ 17][0.3] > [ 37][ 23][3.7] > ... ... ... > > and so for many rows... > > what I have to do is looping through my arrays like that > > while i < rowcount: > plot_to_map(lat[i],lon[i],val[i]) > > it is evidently an idea of how it could be done easily but my knowledge of these libraries is too weak for me to figure out how to do it > > my data comes from huge binary files but is extremely simple, so it would be really easy for anyone to help me as the problem itself is how to put unsorted points on the map with latitude and longitude coordinates > Antoine: You haven't said if your data forms a rectangular array. If so, you can build a 2-d array from the input file and plot it with imshow. If not, you can still plug the elements into a 2-d masked array, leaving the missing pixels masked. You say the points are 'unsorted', does that mean they are randomly distributed and do not form a rectangular grid? It would really be much easier to help if you gave us more information, such as how the data is structured, what the pixel footprint is, etc. Perhaps you could post the binary file on an ftp site somewhere with code to read it. Also, please hit 'reply all' when replying, so the matplotlib users mailing list is CC'ed. -Jeff >> Antoine De Pauw wrote: >>> Sir, >>> >>> I'm sorry, as english is not my mothertongue and it is sometimes difficult to be understandable. >>> >>> All is in the script I gave to you initially, except the point drawing code which would be useless as it is proven not to work (I dont know the method to do it). >>> >>> What I have is a map, and a set of pixels I have to put on it with geographic coordinates. >>> >>> I cannot find the right method to put colour pixels on the map, that's the problem. >>> >>> I have that map in miller projection, and three arrays containing respectively latitude, longitude and satellite measured value. >>> >>> What I need to obtain is something approximately like this: http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 _00_lr.gif but with the basemap toolkit. >>> >>> So, my question is: how could I do to plot a coloured pixel at coordinates lat:lon on that map? If I have just the method to project a geographic coordinate on the map and put a coloured pixel at the right place, all is done and I just have to loop my arrays... Also, I would have to implement some antialiasing on the map. >>> >> Antoine: >> >> Are the pixels arranged on a regular grid - or are they randomly >> distributed? If they are on a grid, it's easy (using pcolor or imshow). >> >> If you could send me your data I may be able to get you started. >> >> (I'm cc'ing the matplotlib list so others can join in the discussion). >> >> >> -Jeff >>> If this is not possible to do it in a simple and explainable way, please tell me and I'll continue using matlab or searching for the bit of code which will save me >>> >>> Anyway, I have to thank you for your interest to help me.. >>> >>> Many thanks, >>> >>> Antoine De Pauw >>> >>> >>>> Antoine De Pauw wrote: >>>> >>>>> Hi, and thanks for the answer >>>>> >>>>> In fact, what I do is reading a binary file to obtain 3 arrays (Lat,Lon,Val) describing geographic points which are associated by index (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>>> >>>>> What I need to do is to plot some points on the map (miller projection for most) based on latitude and longitude, to obtain a colour map (points are unordered, it is from IASI satellite computations) >>>>> >>>>> I'm able to create a map, draw simple things on it, etc but the problem I have is any method I try for plotting points is failing, either pcolor, pcolormesh, imshow, etc. >>>>> >>>>> When I found your post on that mailing list, I figured out that you might have the experience and skills to easily explain to me how to manipulate these points and plot them on the map, as there's like no help on the web except standard examples... >>>>> >>>>> Please tell me if this is possible for you to give me some tips, or if it takes too much of your time just advice me some lectures >>>>> >>>>> Best regards, >>>>> >>>>> De Pauw Antoine >>>>> >>>>> >>>> Antoine: It would really help to have a script demonstrating your >>>> problem. It sounds to me like you want to plot markers representing a >>>> set of points - for that you should use the scatter method. pcolor, >>>> pcolormesh and friends are for plotting gridded data. >>>> >>>> -Jeff >>>> >>>>> >>>>> >>>>>> De Pauw Antoine wrote: >>>>>> >>>>>> >>>>>>> Dear sir, >>>>>>> >>>>>>> >>>>>>> >>>>>>> I’m currently trying to improve our plotting tools here at the “Quantum >>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>> solution, on an explanation from you here: >>>>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>>>> >>>>>>> >>>>>>> >>>>>>> It seems that you could help me find a solution, as I cannot plot any >>>>>>> points on maps. >>>>>>> >>>>>>> >>>>>>> >>>>>>> Could you please tell me what I could do to plot data in a simple way, >>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>> longitude and values to plot? >>>>>>> >>>>>>> >>>>>>> >>>>>>> Some tips would be very nice from you as any method I have tried so far >>>>>>> give me some errors… >>>>>>> >>>>>>> >>>>>>> >>>>>>> Thank you very much in advance, >>>>>>> >>>>>>> >>>>>>> >>>>>>> Best regards, >>>>>>> >>>>>>> >>>>>>> >>>>>>> PS: I give you the code I’m using currently, missing the plotting part >>>>>>> >>>>>>> >>>>>>> >>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>> >>>>>>> from numpy import * >>>>>>> >>>>>>> from scipy.io.numpyio import fread >>>>>>> >>>>>>> import matplotlib.pyplot as plt >>>>>>> >>>>>>> import numpy as np >>>>>>> >>>>>>> import os >>>>>>> >>>>>>> import sys >>>>>>> >>>>>>> import array >>>>>>> >>>>>>> >>>>>>> >>>>>>> fileName="c:/20080821.b56" >>>>>>> >>>>>>> >>>>>>> >>>>>>> print('preparing map') >>>>>>> >>>>>>> map = >>>>>>> Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) >>>>>>> >>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>> >>>>>>> map.drawmapboundary() >>>>>>> >>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>> >>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>> >>>>>>> print('reading binary data') >>>>>>> >>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>> >>>>>>> Lat=zeros(nbreligne) >>>>>>> >>>>>>> Lon=zeros(nbreligne) >>>>>>> >>>>>>> Val=zeros(nbreligne) >>>>>>> >>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>> >>>>>>> Lat=rawfile[0:nbreligne] >>>>>>> >>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>> >>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>> >>>>>>> print('shifting latitudes and projecting to map') >>>>>>> >>>>>>> i=0 >>>>>>> >>>>>>> while i < nbreligne: >>>>>>> >>>>>>> if(Lon[i]>180): >>>>>>> >>>>>>> print(Lon[i]) >>>>>>> >>>>>>> Lon[i]-=360 >>>>>>> >>>>>>> print(Lon[i]) >>>>>>> >>>>>>> i+=1 >>>>>>> >>>>>>> print('plotting data') >>>>>>> >>>>>>> >>>>>>> >>>>>>> #plotting code comes here >>>>>>> >>>>>>> >>>>>> Antoine: If you send me a self-contained script that produces the >>>>>> problem you see, I can help you debug it. As it stands now, I have very >>>>>> little to work with - it could be your plotting commands, or it could be >>>>>> your data. >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>>> >>>>>>> >>>>>>> print('saving map') >>>>>>> >>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>> >>>>>>> print('done') >>>>>>> >>>>>>> >>>>>>> >>>>>>> *Antoine De Pauw* >>>>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>>>>> photophysics laboratory >>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> Meteorologist FAX : (303)497-6449 >>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>> >>>> >>>> >>>> >>> >>> >> >> -- >> Jeffrey S. Whitaker Phone : (303)497-6313 >> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >> 325 Broadway Boulder, CO, USA 80305-3328 >> >> >> > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |
|
From: Jeff W. <js...@fa...> - 2008-09-11 11:50:15
|
De Pauw Antoine wrote: > Hi Jeff, > > I have put the code online with a sample of the data here: > > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > I hope you'll be able to give me some advice as it is quite difficult for > someone new in python and scientific computation > Antoine: How big are the pixels? Is the text file lon,lat,data or lat,lon,data? -Jeff > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > -----Original Message----- > From: Jeff Whitaker [mailto:Jef...@no...] > Sent: mercredi 10 septembre 2008 16:45 > To: Antoine De Pauw > Cc: Matplotlib Users > Subject: Re: Information request > > Antoine De Pauw wrote: > >> Thanks Jeff, >> >> In fact my points are arranged in three unsorted arrays, with a simple >> > scheme (thats why I couldn't plot them with imshow and others) > >> arrays: >> >> [lat][lon][val] >> [-10][ 17][0.3] >> [ 37][ 23][3.7] >> ... ... ... >> >> and so for many rows... >> >> what I have to do is looping through my arrays like that >> >> while i < rowcount: >> plot_to_map(lat[i],lon[i],val[i]) >> >> it is evidently an idea of how it could be done easily but my knowledge of >> > these libraries is too weak for me to figure out how to do it > >> my data comes from huge binary files but is extremely simple, so it would >> > be really easy for anyone to help me as the problem itself is how to put > unsorted points on the map with latitude and longitude coordinates > > > Antoine: You haven't said if your data forms a rectangular array. If > so, you can build a 2-d array from the input file and plot it with > imshow. If not, you can still plug the elements into a 2-d masked > array, leaving the missing pixels masked. You say the points are > 'unsorted', does that mean they are randomly distributed and do not form > a rectangular grid? > > It would really be much easier to help if you gave us more information, > such as how the data is structured, what the pixel footprint is, etc. > Perhaps you could post the binary file on an ftp site somewhere with > code to read it. > > Also, please hit 'reply all' when replying, so the matplotlib users > mailing list is CC'ed. > > -Jeff > >>> Antoine De Pauw wrote: >>> >>>> Sir, >>>> >>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>> > difficult to be understandable. > >>>> All is in the script I gave to you initially, except the point drawing >>>> > code which would be useless as it is proven not to work (I dont know the > method to do it). > >>>> What I have is a map, and a set of pixels I have to put on it with >>>> > geographic coordinates. > >>>> I cannot find the right method to put colour pixels on the map, that's >>>> > the problem. > >>>> I have that map in miller projection, and three arrays containing >>>> > respectively latitude, longitude and satellite measured value. > >>>> What I need to obtain is something approximately like this: >>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > _00_lr.gif but with the basemap toolkit. > >>>> So, my question is: how could I do to plot a coloured pixel at >>>> > coordinates lat:lon on that map? If I have just the method to project a > geographic coordinate on the map and put a coloured pixel at the right > place, all is done and I just have to loop my arrays... Also, I would have > to implement some antialiasing on the map. > >>>> >>>> >>> Antoine: >>> >>> Are the pixels arranged on a regular grid - or are they randomly >>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>> >>> If you could send me your data I may be able to get you started. >>> >>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>> >>> >>> -Jeff >>> >>>> If this is not possible to do it in a simple and explainable way, please >>>> > tell me and I'll continue using matlab or searching for the bit of code > which will save me > >>>> Anyway, I have to thank you for your interest to help me.. >>>> >>>> Many thanks, >>>> >>>> Antoine De Pauw >>>> >>>> >>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>>> Hi, and thanks for the answer >>>>>> >>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>> > (Lat,Lon,Val) describing geographic points which are associated by index > (like point 1 is Lat[0]:Lon[0] with value Val[0]) > >>>>>> What I need to do is to plot some points on the map (miller projection >>>>>> > for most) based on latitude and longitude, to obtain a colour map (points > are unordered, it is from IASI satellite computations) > >>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>> > problem I have is any method I try for plotting points is failing, either > pcolor, pcolormesh, imshow, etc. > >>>>>> When I found your post on that mailing list, I figured out that you >>>>>> > might have the experience and skills to easily explain to me how to > manipulate these points and plot them on the map, as there's like no help on > the web except standard examples... > >>>>>> Please tell me if this is possible for you to give me some tips, or if >>>>>> > it takes too much of your time just advice me some lectures > >>>>>> Best regards, >>>>>> >>>>>> De Pauw Antoine >>>>>> >>>>>> >>>>>> >>>>> Antoine: It would really help to have a script demonstrating your >>>>> problem. It sounds to me like you want to plot markers representing a >>>>> set of points - for that you should use the scatter method. pcolor, >>>>> pcolormesh and friends are for plotting gridded data. >>>>> >>>>> -Jeff >>>>> >>>>> >>>>>> >>>>>> >>>>>> >>>>>>> De Pauw Antoine wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Dear sir, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I’m currently trying to improve our plotting tools here at the >>>>>>>> > “Quantum > >>>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>>> > > >>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>> solution, on an explanation from you here: >>>>>>>> >>>>>>>> > http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html > >>>>>>>> >>>>>>>> >>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>> > any > >>>>>>>> points on maps. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>> > way, > >>>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>>> > > >>>>>>>> longitude and values to plot? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>> > far > >>>>>>>> give me some errors… >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Thank you very much in advance, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>> > plotting part > >>>>>>>> >>>>>>>> >>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>> >>>>>>>> from numpy import * >>>>>>>> >>>>>>>> from scipy.io.numpyio import fread >>>>>>>> >>>>>>>> import matplotlib.pyplot as plt >>>>>>>> >>>>>>>> import numpy as np >>>>>>>> >>>>>>>> import os >>>>>>>> >>>>>>>> import sys >>>>>>>> >>>>>>>> import array >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> fileName="c:/20080821.b56" >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('preparing map') >>>>>>>> >>>>>>>> map = >>>>>>>> >>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>> >>>>>>>> map.drawmapboundary() >>>>>>>> >>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>> >>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>> >>>>>>>> print('reading binary data') >>>>>>>> >>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>> >>>>>>>> Lat=zeros(nbreligne) >>>>>>>> >>>>>>>> Lon=zeros(nbreligne) >>>>>>>> >>>>>>>> Val=zeros(nbreligne) >>>>>>>> >>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>> >>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>> >>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>> >>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>> >>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>> >>>>>>>> i=0 >>>>>>>> >>>>>>>> while i < nbreligne: >>>>>>>> >>>>>>>> if(Lon[i]>180): >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> Lon[i]-=360 >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> i+=1 >>>>>>>> >>>>>>>> print('plotting data') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> #plotting code comes here >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>> > very > >>>>>>> little to work with - it could be your plotting commands, or it could >>>>>>> > be > >>>>>>> your data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('saving map') >>>>>>>> >>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>> >>>>>>>> print('done') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> *Antoine De Pauw* >>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>> > IT > >>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry >>>>>>>> > and > >>>>>>>> photophysics laboratory >>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> -- >>> Jeffrey S. Whitaker Phone : (303)497-6313 >>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>> 325 Broadway Boulder, CO, USA 80305-3328 >>> >>> >>> >>> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: Jeff W. <js...@fa...> - 2008-09-11 12:10:55
|
De Pauw Antoine wrote: > Hi Jeff, > > I have put the code online with a sample of the data here: > > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > I hope you'll be able to give me some advice as it is quite difficult for > someone new in python and scientific computation > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: I may have the size of the pixels wrong, and lat/lon transposed, but this is the general idea: from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np lats = []; lons = []; data = [] for line in open('pixels.dat'): linesplit = line.split(',') lons.append(float(linesplit[1])) lats.append(float(linesplit[0])) data.append(float(linesplit[2])) map = Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') x,y = map(lons,lats) plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) plt.colorbar(shrink=0.6) map.drawcoastlines() plt.show() -Jeff > -----Original Message----- > From: Jeff Whitaker [mailto:Jef...@no...] > Sent: mercredi 10 septembre 2008 16:45 > To: Antoine De Pauw > Cc: Matplotlib Users > Subject: Re: Information request > > Antoine De Pauw wrote: > >> Thanks Jeff, >> >> In fact my points are arranged in three unsorted arrays, with a simple >> > scheme (thats why I couldn't plot them with imshow and others) > >> arrays: >> >> [lat][lon][val] >> [-10][ 17][0.3] >> [ 37][ 23][3.7] >> ... ... ... >> >> and so for many rows... >> >> what I have to do is looping through my arrays like that >> >> while i < rowcount: >> plot_to_map(lat[i],lon[i],val[i]) >> >> it is evidently an idea of how it could be done easily but my knowledge of >> > these libraries is too weak for me to figure out how to do it > >> my data comes from huge binary files but is extremely simple, so it would >> > be really easy for anyone to help me as the problem itself is how to put > unsorted points on the map with latitude and longitude coordinates > > > Antoine: You haven't said if your data forms a rectangular array. If > so, you can build a 2-d array from the input file and plot it with > imshow. If not, you can still plug the elements into a 2-d masked > array, leaving the missing pixels masked. You say the points are > 'unsorted', does that mean they are randomly distributed and do not form > a rectangular grid? > > It would really be much easier to help if you gave us more information, > such as how the data is structured, what the pixel footprint is, etc. > Perhaps you could post the binary file on an ftp site somewhere with > code to read it. > > Also, please hit 'reply all' when replying, so the matplotlib users > mailing list is CC'ed. > > -Jeff > >>> Antoine De Pauw wrote: >>> >>>> Sir, >>>> >>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>> > difficult to be understandable. > >>>> All is in the script I gave to you initially, except the point drawing >>>> > code which would be useless as it is proven not to work (I dont know the > method to do it). > >>>> What I have is a map, and a set of pixels I have to put on it with >>>> > geographic coordinates. > >>>> I cannot find the right method to put colour pixels on the map, that's >>>> > the problem. > >>>> I have that map in miller projection, and three arrays containing >>>> > respectively latitude, longitude and satellite measured value. > >>>> What I need to obtain is something approximately like this: >>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > _00_lr.gif but with the basemap toolkit. > >>>> So, my question is: how could I do to plot a coloured pixel at >>>> > coordinates lat:lon on that map? If I have just the method to project a > geographic coordinate on the map and put a coloured pixel at the right > place, all is done and I just have to loop my arrays... Also, I would have > to implement some antialiasing on the map. > >>>> >>>> >>> Antoine: >>> >>> Are the pixels arranged on a regular grid - or are they randomly >>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>> >>> If you could send me your data I may be able to get you started. >>> >>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>> >>> >>> -Jeff >>> >>>> If this is not possible to do it in a simple and explainable way, please >>>> > tell me and I'll continue using matlab or searching for the bit of code > which will save me > >>>> Anyway, I have to thank you for your interest to help me.. >>>> >>>> Many thanks, >>>> >>>> Antoine De Pauw >>>> >>>> >>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>>> Hi, and thanks for the answer >>>>>> >>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>> > (Lat,Lon,Val) describing geographic points which are associated by index > (like point 1 is Lat[0]:Lon[0] with value Val[0]) > >>>>>> What I need to do is to plot some points on the map (miller projection >>>>>> > for most) based on latitude and longitude, to obtain a colour map (points > are unordered, it is from IASI satellite computations) > >>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>> > problem I have is any method I try for plotting points is failing, either > pcolor, pcolormesh, imshow, etc. > >>>>>> When I found your post on that mailing list, I figured out that you >>>>>> > might have the experience and skills to easily explain to me how to > manipulate these points and plot them on the map, as there's like no help on > the web except standard examples... > >>>>>> Please tell me if this is possible for you to give me some tips, or if >>>>>> > it takes too much of your time just advice me some lectures > >>>>>> Best regards, >>>>>> >>>>>> De Pauw Antoine >>>>>> >>>>>> >>>>>> >>>>> Antoine: It would really help to have a script demonstrating your >>>>> problem. It sounds to me like you want to plot markers representing a >>>>> set of points - for that you should use the scatter method. pcolor, >>>>> pcolormesh and friends are for plotting gridded data. >>>>> >>>>> -Jeff >>>>> >>>>> >>>>>> >>>>>> >>>>>> >>>>>>> De Pauw Antoine wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Dear sir, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I’m currently trying to improve our plotting tools here at the >>>>>>>> > “Quantum > >>>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>>> > > >>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>> solution, on an explanation from you here: >>>>>>>> >>>>>>>> > http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html > >>>>>>>> >>>>>>>> >>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>> > any > >>>>>>>> points on maps. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>> > way, > >>>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>>> > > >>>>>>>> longitude and values to plot? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>> > far > >>>>>>>> give me some errors… >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Thank you very much in advance, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>> > plotting part > >>>>>>>> >>>>>>>> >>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>> >>>>>>>> from numpy import * >>>>>>>> >>>>>>>> from scipy.io.numpyio import fread >>>>>>>> >>>>>>>> import matplotlib.pyplot as plt >>>>>>>> >>>>>>>> import numpy as np >>>>>>>> >>>>>>>> import os >>>>>>>> >>>>>>>> import sys >>>>>>>> >>>>>>>> import array >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> fileName="c:/20080821.b56" >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('preparing map') >>>>>>>> >>>>>>>> map = >>>>>>>> >>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>> >>>>>>>> map.drawmapboundary() >>>>>>>> >>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>> >>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>> >>>>>>>> print('reading binary data') >>>>>>>> >>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>> >>>>>>>> Lat=zeros(nbreligne) >>>>>>>> >>>>>>>> Lon=zeros(nbreligne) >>>>>>>> >>>>>>>> Val=zeros(nbreligne) >>>>>>>> >>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>> >>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>> >>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>> >>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>> >>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>> >>>>>>>> i=0 >>>>>>>> >>>>>>>> while i < nbreligne: >>>>>>>> >>>>>>>> if(Lon[i]>180): >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> Lon[i]-=360 >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> i+=1 >>>>>>>> >>>>>>>> print('plotting data') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> #plotting code comes here >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>> > very > >>>>>>> little to work with - it could be your plotting commands, or it could >>>>>>> > be > >>>>>>> your data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('saving map') >>>>>>>> >>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>> >>>>>>>> print('done') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> *Antoine De Pauw* >>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>> > IT > >>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry >>>>>>>> > and > >>>>>>>> photophysics laboratory >>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> -- >>> Jeffrey S. Whitaker Phone : (303)497-6313 >>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>> 325 Broadway Boulder, CO, USA 80305-3328 >>> >>> >>> >>> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: De P. A. <and...@ul...> - 2008-09-11 13:07:43
|
Thanks Jeff,
This seems to work with csv file types, and I've been experimenting a bit
with it
However, when I try to implement this with my original code (with binary
files), I get an error like that one:
Traceback (most recent call last):
File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module>
x,y = map(Lon,Lat)
TypeError: 'numpy.ndarray' object is not callable
I think this is coming from the fact I use array objects to store values...
could you confirm it?
Also, I'll see if it is possible to invert color scale and mask everything
under a certain value
Thanks very much for your help!
Antoine De Pauw
Collaborateur de recherches, Informatique - Research collaborator, IT
Laboratoire de chimie quantique et photophysique - Quantum chemistry and
photophysics laboratory
Université Libre de Bruxelles - ULB
-----Original Message-----
From: Jeff Whitaker [mailto:js...@fa...]
Sent: jeudi 11 septembre 2008 14:10
To: De Pauw Antoine
Cc: 'Matplotlib Users'
Subject: Re: [Matplotlib-users] Information request
De Pauw Antoine wrote:
> Hi Jeff,
>
> I have put the code online with a sample of the data here:
>
> http://snipplr.com/view/8307/map-plotting-python-code-temporary/
>
> I hope you'll be able to give me some advice as it is quite difficult for
> someone new in python and scientific computation
>
> Antoine De Pauw
> Collaborateur de recherches, Informatique - Research collaborator, IT
> Laboratoire de chimie quantique et photophysique - Quantum chemistry and
> photophysics laboratory
> Université Libre de Bruxelles - ULB
>
Antoine: I may have the size of the pixels wrong, and lat/lon
transposed, but this is the general idea:
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np
lats = []; lons = []; data = []
for line in open('pixels.dat'):
linesplit = line.split(',')
lons.append(float(linesplit[1]))
lats.append(float(linesplit[0]))
data.append(float(linesplit[2]))
map =
Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\
urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l')
x,y = map(lons,lats)
plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet)
plt.colorbar(shrink=0.6)
map.drawcoastlines()
plt.show()
-Jeff
> -----Original Message-----
> From: Jeff Whitaker [mailto:Jef...@no...]
> Sent: mercredi 10 septembre 2008 16:45
> To: Antoine De Pauw
> Cc: Matplotlib Users
> Subject: Re: Information request
>
> Antoine De Pauw wrote:
>
>> Thanks Jeff,
>>
>> In fact my points are arranged in three unsorted arrays, with a simple
>>
> scheme (thats why I couldn't plot them with imshow and others)
>
>> arrays:
>>
>> [lat][lon][val]
>> [-10][ 17][0.3]
>> [ 37][ 23][3.7]
>> ... ... ...
>>
>> and so for many rows...
>>
>> what I have to do is looping through my arrays like that
>>
>> while i < rowcount:
>> plot_to_map(lat[i],lon[i],val[i])
>>
>> it is evidently an idea of how it could be done easily but my knowledge
of
>>
> these libraries is too weak for me to figure out how to do it
>
>> my data comes from huge binary files but is extremely simple, so it would
>>
> be really easy for anyone to help me as the problem itself is how to put
> unsorted points on the map with latitude and longitude coordinates
>
>
> Antoine: You haven't said if your data forms a rectangular array. If
> so, you can build a 2-d array from the input file and plot it with
> imshow. If not, you can still plug the elements into a 2-d masked
> array, leaving the missing pixels masked. You say the points are
> 'unsorted', does that mean they are randomly distributed and do not form
> a rectangular grid?
>
> It would really be much easier to help if you gave us more information,
> such as how the data is structured, what the pixel footprint is, etc.
> Perhaps you could post the binary file on an ftp site somewhere with
> code to read it.
>
> Also, please hit 'reply all' when replying, so the matplotlib users
> mailing list is CC'ed.
>
> -Jeff
>
>>> Antoine De Pauw wrote:
>>>
>>>> Sir,
>>>>
>>>> I'm sorry, as english is not my mothertongue and it is sometimes
>>>>
> difficult to be understandable.
>
>>>> All is in the script I gave to you initially, except the point drawing
>>>>
> code which would be useless as it is proven not to work (I dont know the
> method to do it).
>
>>>> What I have is a map, and a set of pixels I have to put on it with
>>>>
> geographic coordinates.
>
>>>> I cannot find the right method to put colour pixels on the map, that's
>>>>
> the problem.
>
>>>> I have that map in miller projection, and three arrays containing
>>>>
> respectively latitude, longitude and satellite measured value.
>
>>>> What I need to obtain is something approximately like this:
>>>>
>
http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703
> _00_lr.gif but with the basemap toolkit.
>
>>>> So, my question is: how could I do to plot a coloured pixel at
>>>>
> coordinates lat:lon on that map? If I have just the method to project a
> geographic coordinate on the map and put a coloured pixel at the right
> place, all is done and I just have to loop my arrays... Also, I would have
> to implement some antialiasing on the map.
>
>>>>
>>>>
>>> Antoine:
>>>
>>> Are the pixels arranged on a regular grid - or are they randomly
>>> distributed? If they are on a grid, it's easy (using pcolor or imshow).
>>>
>>> If you could send me your data I may be able to get you started.
>>>
>>> (I'm cc'ing the matplotlib list so others can join in the discussion).
>>>
>>>
>>> -Jeff
>>>
>>>> If this is not possible to do it in a simple and explainable way,
please
>>>>
> tell me and I'll continue using matlab or searching for the bit of code
> which will save me
>
>>>> Anyway, I have to thank you for your interest to help me..
>>>>
>>>> Many thanks,
>>>>
>>>> Antoine De Pauw
>>>>
>>>>
>>>>
>>>>> Antoine De Pauw wrote:
>>>>>
>>>>>
>>>>>> Hi, and thanks for the answer
>>>>>>
>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays
>>>>>>
> (Lat,Lon,Val) describing geographic points which are associated by index
> (like point 1 is Lat[0]:Lon[0] with value Val[0])
>
>>>>>> What I need to do is to plot some points on the map (miller
projection
>>>>>>
> for most) based on latitude and longitude, to obtain a colour map (points
> are unordered, it is from IASI satellite computations)
>
>>>>>> I'm able to create a map, draw simple things on it, etc but the
>>>>>>
> problem I have is any method I try for plotting points is failing, either
> pcolor, pcolormesh, imshow, etc.
>
>>>>>> When I found your post on that mailing list, I figured out that you
>>>>>>
> might have the experience and skills to easily explain to me how to
> manipulate these points and plot them on the map, as there's like no help
on
> the web except standard examples...
>
>>>>>> Please tell me if this is possible for you to give me some tips, or
if
>>>>>>
> it takes too much of your time just advice me some lectures
>
>>>>>> Best regards,
>>>>>>
>>>>>> De Pauw Antoine
>>>>>>
>>>>>>
>>>>>>
>>>>> Antoine: It would really help to have a script demonstrating your
>>>>> problem. It sounds to me like you want to plot markers representing a
>>>>> set of points - for that you should use the scatter method. pcolor,
>>>>> pcolormesh and friends are for plotting gridded data.
>>>>>
>>>>> -Jeff
>>>>>
>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>> De Pauw Antoine wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> Dear sir,
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> I’m currently trying to improve our plotting tools here at
the
>>>>>>>>
> “Quantum
>
>>>>>>>> Chemistry and Photophysics” section of the Université Libre
de
>>>>>>>>
>
>
>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a
>>>>>>>> solution, on an explanation from you here:
>>>>>>>>
>>>>>>>>
> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html
>
>>>>>>>>
>>>>>>>>
>>>>>>>> It seems that you could help me find a solution, as I cannot plot
>>>>>>>>
> any
>
>>>>>>>> points on maps.
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Could you please tell me what I could do to plot data in a simple
>>>>>>>>
> way,
>
>>>>>>>> assuming I have 3 unordered arrays containing respectively
latitude,
>>>>>>>>
>
>
>>>>>>>> longitude and values to plot?
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Some tips would be very nice from you as any method I have tried so
>>>>>>>>
> far
>
>>>>>>>> give me some errors…
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Thank you very much in advance,
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Best regards,
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> PS: I give you the code I’m using currently, missing the
>>>>>>>>
> plotting part
>
>>>>>>>>
>>>>>>>>
>>>>>>>> from mpl_toolkits.basemap import Basemap
>>>>>>>>
>>>>>>>> from numpy import *
>>>>>>>>
>>>>>>>> from scipy.io.numpyio import fread
>>>>>>>>
>>>>>>>> import matplotlib.pyplot as plt
>>>>>>>>
>>>>>>>> import numpy as np
>>>>>>>>
>>>>>>>> import os
>>>>>>>>
>>>>>>>> import sys
>>>>>>>>
>>>>>>>> import array
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> fileName="c:/20080821.b56"
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> print('preparing map')
>>>>>>>>
>>>>>>>> map =
>>>>>>>>
>>>>>>>>
>
Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.)
>
>>>>>>>> map.drawcoastlines(0.5,antialiased=1)
>>>>>>>>
>>>>>>>> map.drawmapboundary()
>>>>>>>>
>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5,
>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-")
>>>>>>>>
>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5,
>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-")
>>>>>>>>
>>>>>>>> print('reading binary data')
>>>>>>>>
>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:]))
>>>>>>>>
>>>>>>>> Lat=zeros(nbreligne)
>>>>>>>>
>>>>>>>> Lon=zeros(nbreligne)
>>>>>>>>
>>>>>>>> Val=zeros(nbreligne)
>>>>>>>>
>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1)
>>>>>>>>
>>>>>>>> Lat=rawfile[0:nbreligne]
>>>>>>>>
>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2]
>>>>>>>>
>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22]
>>>>>>>>
>>>>>>>> print('shifting latitudes and projecting to map')
>>>>>>>>
>>>>>>>> i=0
>>>>>>>>
>>>>>>>> while i < nbreligne:
>>>>>>>>
>>>>>>>> if(Lon[i]>180):
>>>>>>>>
>>>>>>>> print(Lon[i])
>>>>>>>>
>>>>>>>> Lon[i]-=360
>>>>>>>>
>>>>>>>> print(Lon[i])
>>>>>>>>
>>>>>>>> i+=1
>>>>>>>>
>>>>>>>> print('plotting data')
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> #plotting code comes here
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>> Antoine: If you send me a self-contained script that produces the
>>>>>>> problem you see, I can help you debug it. As it stands now, I have
>>>>>>>
> very
>
>>>>>>> little to work with - it could be your plotting commands, or it
could
>>>>>>>
> be
>
>>>>>>> your data.
>>>>>>>
>>>>>>> -Jeff
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> print('saving map')
>>>>>>>>
>>>>>>>> plt.savefig("testfig.png",dpi=600)
>>>>>>>>
>>>>>>>> print('done')
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> *Antoine De Pauw*
>>>>>>>> Collaborateur de recherches, Informatique - Research collaborator,
>>>>>>>>
> IT
>
>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum
chemistry
>>>>>>>>
> and
>
>>>>>>>> photophysics laboratory
>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>*
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>> --
>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313
>>>>>>> Meteorologist FAX : (303)497-6449
>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no...
>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113
>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>>> Jeffrey S. Whitaker Phone : (303)497-6313
>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
>>>>> 325 Broadway Boulder, CO, USA 80305-3328
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>> --
>>> Jeffrey S. Whitaker Phone : (303)497-6313
>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
>>> 325 Broadway Boulder, CO, USA 80305-3328
>>>
>>>
>>>
>>>
>>
>
>
>
--
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
325 Broadway Boulder, CO, USA 80305-3328
|
|
From: Jeff W. <js...@fa...> - 2008-09-11 13:29:37
|
De Pauw Antoine wrote: > Thanks Jeff, > > This seems to work with csv file types, and I've been experimenting a bit > with it > > However, when I try to implement this with my original code (with binary > files), I get an error like that one: > > Traceback (most recent call last): > File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> > x,y = map(Lon,Lat) > TypeError: 'numpy.ndarray' object is not callable > > I think this is coming from the fact I use array objects to store values... > could you confirm it? > Antoine: It looks like you the object map is not a Basemap instance, but a numpy array. Try putting 'print type(map)' just ahead of this statement to verify this. I suspect your re-using the name 'map' in your code, overwriting the Basemap class instance. -Jeff > Also, I'll see if it is possible to invert color scale and mask everything > under a certain value > > Thanks very much for your help! > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 14:10 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Hi Jeff, >> >> I have put the code online with a sample of the data here: >> >> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >> >> I hope you'll be able to give me some advice as it is quite difficult for >> someone new in python and scientific computation >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: I may have the size of the pixels wrong, and lat/lon > transposed, but this is the general idea: > > from mpl_toolkits.basemap import Basemap > import matplotlib.pyplot as plt > import numpy as np > lats = []; lons = []; data = [] > for line in open('pixels.dat'): > linesplit = line.split(',') > lons.append(float(linesplit[1])) > lats.append(float(linesplit[0])) > data.append(float(linesplit[2])) > map = > Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ > > urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') > x,y = map(lons,lats) > plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) > plt.colorbar(shrink=0.6) > map.drawcoastlines() > plt.show() > > -Jeff > > >> -----Original Message----- >> From: Jeff Whitaker [mailto:Jef...@no...] >> Sent: mercredi 10 septembre 2008 16:45 >> To: Antoine De Pauw >> Cc: Matplotlib Users >> Subject: Re: Information request >> >> Antoine De Pauw wrote: >> >> >>> Thanks Jeff, >>> >>> In fact my points are arranged in three unsorted arrays, with a simple >>> >>> >> scheme (thats why I couldn't plot them with imshow and others) >> >> >>> arrays: >>> >>> [lat][lon][val] >>> [-10][ 17][0.3] >>> [ 37][ 23][3.7] >>> ... ... ... >>> >>> and so for many rows... >>> >>> what I have to do is looping through my arrays like that >>> >>> while i < rowcount: >>> plot_to_map(lat[i],lon[i],val[i]) >>> >>> it is evidently an idea of how it could be done easily but my knowledge >>> > of > >>> >>> >> these libraries is too weak for me to figure out how to do it >> >> >>> my data comes from huge binary files but is extremely simple, so it would >>> >>> >> be really easy for anyone to help me as the problem itself is how to put >> unsorted points on the map with latitude and longitude coordinates >> >> >> Antoine: You haven't said if your data forms a rectangular array. If >> so, you can build a 2-d array from the input file and plot it with >> imshow. If not, you can still plug the elements into a 2-d masked >> array, leaving the missing pixels masked. You say the points are >> 'unsorted', does that mean they are randomly distributed and do not form >> a rectangular grid? >> >> It would really be much easier to help if you gave us more information, >> such as how the data is structured, what the pixel footprint is, etc. >> Perhaps you could post the binary file on an ftp site somewhere with >> code to read it. >> >> Also, please hit 'reply all' when replying, so the matplotlib users >> mailing list is CC'ed. >> >> -Jeff >> >> >>>> Antoine De Pauw wrote: >>>> >>>> >>>>> Sir, >>>>> >>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>> >>>>> >> difficult to be understandable. >> >> >>>>> All is in the script I gave to you initially, except the point drawing >>>>> >>>>> >> code which would be useless as it is proven not to work (I dont know the >> method to do it). >> >> >>>>> What I have is a map, and a set of pixels I have to put on it with >>>>> >>>>> >> geographic coordinates. >> >> >>>>> I cannot find the right method to put colour pixels on the map, that's >>>>> >>>>> >> the problem. >> >> >>>>> I have that map in miller projection, and three arrays containing >>>>> >>>>> >> respectively latitude, longitude and satellite measured value. >> >> >>>>> What I need to obtain is something approximately like this: >>>>> >>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> _00_lr.gif but with the basemap toolkit. >> >> >>>>> So, my question is: how could I do to plot a coloured pixel at >>>>> >>>>> >> coordinates lat:lon on that map? If I have just the method to project a >> geographic coordinate on the map and put a coloured pixel at the right >> place, all is done and I just have to loop my arrays... Also, I would have >> to implement some antialiasing on the map. >> >> >>>>> >>>>> >>>>> >>>> Antoine: >>>> >>>> Are the pixels arranged on a regular grid - or are they randomly >>>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>>> > > >>>> If you could send me your data I may be able to get you started. >>>> >>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>> >>>> >>>> -Jeff >>>> >>>> >>>>> If this is not possible to do it in a simple and explainable way, >>>>> > please > >>>>> >>>>> >> tell me and I'll continue using matlab or searching for the bit of code >> which will save me >> >> >>>>> Anyway, I have to thank you for your interest to help me.. >>>>> >>>>> Many thanks, >>>>> >>>>> Antoine De Pauw >>>>> >>>>> >>>>> >>>>> >>>>>> Antoine De Pauw wrote: >>>>>> >>>>>> >>>>>> >>>>>>> Hi, and thanks for the answer >>>>>>> >>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>> >>>>>>> >> (Lat,Lon,Val) describing geographic points which are associated by index >> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >> >> >>>>>>> What I need to do is to plot some points on the map (miller >>>>>>> > projection > >>>>>>> >>>>>>> >> for most) based on latitude and longitude, to obtain a colour map (points >> are unordered, it is from IASI satellite computations) >> >> >>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>> >>>>>>> >> problem I have is any method I try for plotting points is failing, either >> pcolor, pcolormesh, imshow, etc. >> >> >>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>> >>>>>>> >> might have the experience and skills to easily explain to me how to >> manipulate these points and plot them on the map, as there's like no help >> > on > >> the web except standard examples... >> >> >>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>> > if > >>>>>>> >>>>>>> >> it takes too much of your time just advice me some lectures >> >> >>>>>>> Best regards, >>>>>>> >>>>>>> De Pauw Antoine >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> Antoine: It would really help to have a script demonstrating your >>>>>> problem. It sounds to me like you want to plot markers representing a >>>>>> > > >>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>> pcolormesh and friends are for plotting gridded data. >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> De Pauw Antoine wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Dear sir, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>> > the > >>>>>>>>> >>>>>>>>> >> “Quantum >> >> >>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>> > de > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>> solution, on an explanation from you here: >>>>>>>>> >>>>>>>>> >>>>>>>>> >> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>> >>>>>>>>> >> any >> >> >>>>>>>>> points on maps. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>> >>>>>>>>> >> way, >> >> >>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>> > latitude, > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> longitude and values to plot? >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>>> >>>>>>>>> >> far >> >> >>>>>>>>> give me some errors… >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Thank you very much in advance, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Best regards, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>> >>>>>>>>> >> plotting part >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>> >>>>>>>>> from numpy import * >>>>>>>>> >>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>> >>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>> >>>>>>>>> import numpy as np >>>>>>>>> >>>>>>>>> import os >>>>>>>>> >>>>>>>>> import sys >>>>>>>>> >>>>>>>>> import array >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> print('preparing map') >>>>>>>>> >>>>>>>>> map = >>>>>>>>> >>>>>>>>> >>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>> >>>>>>>>> map.drawmapboundary() >>>>>>>>> >>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>> >>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>> >>>>>>>>> print('reading binary data') >>>>>>>>> >>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>> >>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>> >>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>> >>>>>>>>> Val=zeros(nbreligne) >>>>>>>>> >>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>> >>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>> >>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>> >>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>> >>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>> >>>>>>>>> i=0 >>>>>>>>> >>>>>>>>> while i < nbreligne: >>>>>>>>> >>>>>>>>> if(Lon[i]>180): >>>>>>>>> >>>>>>>>> print(Lon[i]) >>>>>>>>> >>>>>>>>> Lon[i]-=360 >>>>>>>>> >>>>>>>>> print(Lon[i]) >>>>>>>>> >>>>>>>>> i+=1 >>>>>>>>> >>>>>>>>> print('plotting data') >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> #plotting code comes here >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>>> >>>>>>>> >> very >> >> >>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>> > could > >>>>>>>> >>>>>>>> >> be >> >> >>>>>>>> your data. >>>>>>>> >>>>>>>> -Jeff >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> print('saving map') >>>>>>>>> >>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>> >>>>>>>>> print('done') >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> *Antoine De Pauw* >>>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>>> >>>>>>>>> >> IT >> >> >>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>> > chemistry > >>>>>>>>> >>>>>>>>> >> and >> >> >>>>>>>>> photophysics laboratory >>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> -- >>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>> >>>> >>>> >>>> >>>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: De P. A. <and...@ul...> - 2008-09-11 14:29:25
|
Jeff, The map object is from the Basemap type, the only different thing is the Lon,Lat and Val objects which are from the type array instead of lists Anyway, solutions are slowly showing themselves and I thank you all Have a nice day Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: jeudi 11 septembre 2008 15:29 To: De Pauw Antoine Cc: 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Thanks Jeff, > > This seems to work with csv file types, and I've been experimenting a bit > with it > > However, when I try to implement this with my original code (with binary > files), I get an error like that one: > > Traceback (most recent call last): > File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> > x,y = map(Lon,Lat) > TypeError: 'numpy.ndarray' object is not callable > > I think this is coming from the fact I use array objects to store values... > could you confirm it? > Antoine: It looks like you the object map is not a Basemap instance, but a numpy array. Try putting 'print type(map)' just ahead of this statement to verify this. I suspect your re-using the name 'map' in your code, overwriting the Basemap class instance. -Jeff > Also, I'll see if it is possible to invert color scale and mask everything > under a certain value > > Thanks very much for your help! > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 14:10 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Hi Jeff, >> >> I have put the code online with a sample of the data here: >> >> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >> >> I hope you'll be able to give me some advice as it is quite difficult for >> someone new in python and scientific computation >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: I may have the size of the pixels wrong, and lat/lon > transposed, but this is the general idea: > > from mpl_toolkits.basemap import Basemap > import matplotlib.pyplot as plt > import numpy as np > lats = []; lons = []; data = [] > for line in open('pixels.dat'): > linesplit = line.split(',') > lons.append(float(linesplit[1])) > lats.append(float(linesplit[0])) > data.append(float(linesplit[2])) > map = > Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ > > urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') > x,y = map(lons,lats) > plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) > plt.colorbar(shrink=0.6) > map.drawcoastlines() > plt.show() > > -Jeff > > >> -----Original Message----- >> From: Jeff Whitaker [mailto:Jef...@no...] >> Sent: mercredi 10 septembre 2008 16:45 >> To: Antoine De Pauw >> Cc: Matplotlib Users >> Subject: Re: Information request >> >> Antoine De Pauw wrote: >> >> >>> Thanks Jeff, >>> >>> In fact my points are arranged in three unsorted arrays, with a simple >>> >>> >> scheme (thats why I couldn't plot them with imshow and others) >> >> >>> arrays: >>> >>> [lat][lon][val] >>> [-10][ 17][0.3] >>> [ 37][ 23][3.7] >>> ... ... ... >>> >>> and so for many rows... >>> >>> what I have to do is looping through my arrays like that >>> >>> while i < rowcount: >>> plot_to_map(lat[i],lon[i],val[i]) >>> >>> it is evidently an idea of how it could be done easily but my knowledge >>> > of > >>> >>> >> these libraries is too weak for me to figure out how to do it >> >> >>> my data comes from huge binary files but is extremely simple, so it would >>> >>> >> be really easy for anyone to help me as the problem itself is how to put >> unsorted points on the map with latitude and longitude coordinates >> >> >> Antoine: You haven't said if your data forms a rectangular array. If >> so, you can build a 2-d array from the input file and plot it with >> imshow. If not, you can still plug the elements into a 2-d masked >> array, leaving the missing pixels masked. You say the points are >> 'unsorted', does that mean they are randomly distributed and do not form >> a rectangular grid? >> >> It would really be much easier to help if you gave us more information, >> such as how the data is structured, what the pixel footprint is, etc. >> Perhaps you could post the binary file on an ftp site somewhere with >> code to read it. >> >> Also, please hit 'reply all' when replying, so the matplotlib users >> mailing list is CC'ed. >> >> -Jeff >> >> >>>> Antoine De Pauw wrote: >>>> >>>> >>>>> Sir, >>>>> >>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>> >>>>> >> difficult to be understandable. >> >> >>>>> All is in the script I gave to you initially, except the point drawing >>>>> >>>>> >> code which would be useless as it is proven not to work (I dont know the >> method to do it). >> >> >>>>> What I have is a map, and a set of pixels I have to put on it with >>>>> >>>>> >> geographic coordinates. >> >> >>>>> I cannot find the right method to put colour pixels on the map, that's >>>>> >>>>> >> the problem. >> >> >>>>> I have that map in miller projection, and three arrays containing >>>>> >>>>> >> respectively latitude, longitude and satellite measured value. >> >> >>>>> What I need to obtain is something approximately like this: >>>>> >>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> _00_lr.gif but with the basemap toolkit. >> >> >>>>> So, my question is: how could I do to plot a coloured pixel at >>>>> >>>>> >> coordinates lat:lon on that map? If I have just the method to project a >> geographic coordinate on the map and put a coloured pixel at the right >> place, all is done and I just have to loop my arrays... Also, I would have >> to implement some antialiasing on the map. >> >> >>>>> >>>>> >>>>> >>>> Antoine: >>>> >>>> Are the pixels arranged on a regular grid - or are they randomly >>>> distributed? If they are on a grid, it's easy (using pcolor or imshow). >>>> > > >>>> If you could send me your data I may be able to get you started. >>>> >>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>> >>>> >>>> -Jeff >>>> >>>> >>>>> If this is not possible to do it in a simple and explainable way, >>>>> > please > >>>>> >>>>> >> tell me and I'll continue using matlab or searching for the bit of code >> which will save me >> >> >>>>> Anyway, I have to thank you for your interest to help me.. >>>>> >>>>> Many thanks, >>>>> >>>>> Antoine De Pauw >>>>> >>>>> >>>>> >>>>> >>>>>> Antoine De Pauw wrote: >>>>>> >>>>>> >>>>>> >>>>>>> Hi, and thanks for the answer >>>>>>> >>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>> >>>>>>> >> (Lat,Lon,Val) describing geographic points which are associated by index >> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >> >> >>>>>>> What I need to do is to plot some points on the map (miller >>>>>>> > projection > >>>>>>> >>>>>>> >> for most) based on latitude and longitude, to obtain a colour map (points >> are unordered, it is from IASI satellite computations) >> >> >>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>> >>>>>>> >> problem I have is any method I try for plotting points is failing, either >> pcolor, pcolormesh, imshow, etc. >> >> >>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>> >>>>>>> >> might have the experience and skills to easily explain to me how to >> manipulate these points and plot them on the map, as there's like no help >> > on > >> the web except standard examples... >> >> >>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>> > if > >>>>>>> >>>>>>> >> it takes too much of your time just advice me some lectures >> >> >>>>>>> Best regards, >>>>>>> >>>>>>> De Pauw Antoine >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> Antoine: It would really help to have a script demonstrating your >>>>>> problem. It sounds to me like you want to plot markers representing a >>>>>> > > >>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>> pcolormesh and friends are for plotting gridded data. >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> De Pauw Antoine wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Dear sir, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>> > the > >>>>>>>>> >>>>>>>>> >> “Quantum >> >> >>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>> > de > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>> solution, on an explanation from you here: >>>>>>>>> >>>>>>>>> >>>>>>>>> >> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>> >>>>>>>>> >> any >> >> >>>>>>>>> points on maps. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>> >>>>>>>>> >> way, >> >> >>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>> > latitude, > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> longitude and values to plot? >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Some tips would be very nice from you as any method I have tried so >>>>>>>>> >>>>>>>>> >> far >> >> >>>>>>>>> give me some errors… >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Thank you very much in advance, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Best regards, >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>> >>>>>>>>> >> plotting part >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>> >>>>>>>>> from numpy import * >>>>>>>>> >>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>> >>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>> >>>>>>>>> import numpy as np >>>>>>>>> >>>>>>>>> import os >>>>>>>>> >>>>>>>>> import sys >>>>>>>>> >>>>>>>>> import array >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> print('preparing map') >>>>>>>>> >>>>>>>>> map = >>>>>>>>> >>>>>>>>> >>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>> >>>>>>>>> map.drawmapboundary() >>>>>>>>> >>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>> >>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>> >>>>>>>>> print('reading binary data') >>>>>>>>> >>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>> >>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>> >>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>> >>>>>>>>> Val=zeros(nbreligne) >>>>>>>>> >>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>> >>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>> >>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>> >>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>> >>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>> >>>>>>>>> i=0 >>>>>>>>> >>>>>>>>> while i < nbreligne: >>>>>>>>> >>>>>>>>> if(Lon[i]>180): >>>>>>>>> >>>>>>>>> print(Lon[i]) >>>>>>>>> >>>>>>>>> Lon[i]-=360 >>>>>>>>> >>>>>>>>> print(Lon[i]) >>>>>>>>> >>>>>>>>> i+=1 >>>>>>>>> >>>>>>>>> print('plotting data') >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> #plotting code comes here >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>>> >>>>>>>> >> very >> >> >>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>> > could > >>>>>>>> >>>>>>>> >> be >> >> >>>>>>>> your data. >>>>>>>> >>>>>>>> -Jeff >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> print('saving map') >>>>>>>>> >>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>> >>>>>>>>> print('done') >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> *Antoine De Pauw* >>>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>>> >>>>>>>>> >> IT >> >> >>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>> > chemistry > >>>>>>>>> >>>>>>>>> >> and >> >> >>>>>>>>> photophysics laboratory >>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> -- >>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>> -- >>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>> >>>> >>>> >>>> >>>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: Jeff W. <js...@fa...> - 2008-09-11 14:47:54
|
De Pauw Antoine wrote: > Jeff, > > The map object is from the Basemap type, the only different thing is the > Lon,Lat and Val objects which are from the type array instead of lists > > Anyway, solutions are slowly showing themselves and I thank you all > > Have a nice day > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: It should not matter if Lon and Lat are python arrays, lists or numpy arrays. The Basemap instance __call__ method handles them all. There must be something else going on. It is always better to post actual code so we can see what is happening and test it ourselves. -Jeff > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 15:29 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Thanks Jeff, >> >> This seems to work with csv file types, and I've been experimenting a bit >> with it >> >> However, when I try to implement this with my original code (with binary >> files), I get an error like that one: >> >> Traceback (most recent call last): >> File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> >> x,y = map(Lon,Lat) >> TypeError: 'numpy.ndarray' object is not callable >> >> I think this is coming from the fact I use array objects to store >> > values... > >> could you confirm it? >> >> > > Antoine: It looks like you the object map is not a Basemap instance, > but a numpy array. Try putting 'print type(map)' just ahead of this > statement to verify this. I suspect your re-using the name 'map' in your > code, overwriting the Basemap class instance. > > -Jeff > >> Also, I'll see if it is possible to invert color scale and mask everything >> under a certain value >> >> Thanks very much for your help! >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> >> -----Original Message----- >> From: Jeff Whitaker [mailto:js...@fa...] >> Sent: jeudi 11 septembre 2008 14:10 >> To: De Pauw Antoine >> Cc: 'Matplotlib Users' >> Subject: Re: [Matplotlib-users] Information request >> >> De Pauw Antoine wrote: >> >> >>> Hi Jeff, >>> >>> I have put the code online with a sample of the data here: >>> >>> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >>> >>> I hope you'll be able to give me some advice as it is quite difficult for >>> someone new in python and scientific computation >>> >>> Antoine De Pauw >>> Collaborateur de recherches, Informatique - Research collaborator, IT >>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>> photophysics laboratory >>> Université Libre de Bruxelles - ULB >>> >>> >>> >> Antoine: I may have the size of the pixels wrong, and lat/lon >> transposed, but this is the general idea: >> >> from mpl_toolkits.basemap import Basemap >> import matplotlib.pyplot as plt >> import numpy as np >> lats = []; lons = []; data = [] >> for line in open('pixels.dat'): >> linesplit = line.split(',') >> lons.append(float(linesplit[1])) >> lats.append(float(linesplit[0])) >> data.append(float(linesplit[2])) >> map = >> Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ >> >> urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') >> x,y = map(lons,lats) >> plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) >> plt.colorbar(shrink=0.6) >> map.drawcoastlines() >> plt.show() >> >> -Jeff >> >> >> >>> -----Original Message----- >>> From: Jeff Whitaker [mailto:Jef...@no...] >>> Sent: mercredi 10 septembre 2008 16:45 >>> To: Antoine De Pauw >>> Cc: Matplotlib Users >>> Subject: Re: Information request >>> >>> Antoine De Pauw wrote: >>> >>> >>> >>>> Thanks Jeff, >>>> >>>> In fact my points are arranged in three unsorted arrays, with a simple >>>> >>>> >>>> >>> scheme (thats why I couldn't plot them with imshow and others) >>> >>> >>> >>>> arrays: >>>> >>>> [lat][lon][val] >>>> [-10][ 17][0.3] >>>> [ 37][ 23][3.7] >>>> ... ... ... >>>> >>>> and so for many rows... >>>> >>>> what I have to do is looping through my arrays like that >>>> >>>> while i < rowcount: >>>> plot_to_map(lat[i],lon[i],val[i]) >>>> >>>> it is evidently an idea of how it could be done easily but my knowledge >>>> >>>> >> of >> >> >>>> >>>> >>>> >>> these libraries is too weak for me to figure out how to do it >>> >>> >>> >>>> my data comes from huge binary files but is extremely simple, so it >>>> > would > >>>> >>>> >>>> >>> be really easy for anyone to help me as the problem itself is how to put >>> unsorted points on the map with latitude and longitude coordinates >>> >>> >>> Antoine: You haven't said if your data forms a rectangular array. If >>> so, you can build a 2-d array from the input file and plot it with >>> imshow. If not, you can still plug the elements into a 2-d masked >>> array, leaving the missing pixels masked. You say the points are >>> 'unsorted', does that mean they are randomly distributed and do not form >>> a rectangular grid? >>> >>> It would really be much easier to help if you gave us more information, >>> such as how the data is structured, what the pixel footprint is, etc. >>> Perhaps you could post the binary file on an ftp site somewhere with >>> code to read it. >>> >>> Also, please hit 'reply all' when replying, so the matplotlib users >>> mailing list is CC'ed. >>> >>> -Jeff >>> >>> >>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>> >>>>>> Sir, >>>>>> >>>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>>> >>>>>> >>>>>> >>> difficult to be understandable. >>> >>> >>> >>>>>> All is in the script I gave to you initially, except the point drawing >>>>>> >>>>>> >>>>>> >>> code which would be useless as it is proven not to work (I dont know the >>> method to do it). >>> >>> >>> >>>>>> What I have is a map, and a set of pixels I have to put on it with >>>>>> >>>>>> >>>>>> >>> geographic coordinates. >>> >>> >>> >>>>>> I cannot find the right method to put colour pixels on the map, that's >>>>>> >>>>>> >>>>>> >>> the problem. >>> >>> >>> >>>>>> I have that map in miller projection, and three arrays containing >>>>>> >>>>>> >>>>>> >>> respectively latitude, longitude and satellite measured value. >>> >>> >>> >>>>>> What I need to obtain is something approximately like this: >>>>>> >>>>>> >>>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> >> >>> _00_lr.gif but with the basemap toolkit. >>> >>> >>> >>>>>> So, my question is: how could I do to plot a coloured pixel at >>>>>> >>>>>> >>>>>> >>> coordinates lat:lon on that map? If I have just the method to project a >>> geographic coordinate on the map and put a coloured pixel at the right >>> place, all is done and I just have to loop my arrays... Also, I would >>> > have > >>> to implement some antialiasing on the map. >>> >>> >>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> Antoine: >>>>> >>>>> Are the pixels arranged on a regular grid - or are they randomly >>>>> distributed? If they are on a grid, it's easy (using pcolor or >>>>> > imshow). > >>>>> >>>>> >> >> >>>>> If you could send me your data I may be able to get you started. >>>>> >>>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>>> >>>>> >>>>> -Jeff >>>>> >>>>> >>>>> >>>>>> If this is not possible to do it in a simple and explainable way, >>>>>> >>>>>> >> please >> >> >>>>>> >>>>>> >>>>>> >>> tell me and I'll continue using matlab or searching for the bit of code >>> which will save me >>> >>> >>> >>>>>> Anyway, I have to thank you for your interest to help me.. >>>>>> >>>>>> Many thanks, >>>>>> >>>>>> Antoine De Pauw >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> Antoine De Pauw wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Hi, and thanks for the answer >>>>>>>> >>>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>>> >>>>>>>> >>>>>>>> >>> (Lat,Lon,Val) describing geographic points which are associated by index >>> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>> >>> >>> >>>>>>>> What I need to do is to plot some points on the map (miller >>>>>>>> >>>>>>>> >> projection >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> for most) based on latitude and longitude, to obtain a colour map (points >>> are unordered, it is from IASI satellite computations) >>> >>> >>> >>>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>>> >>>>>>>> >>>>>>>> >>> problem I have is any method I try for plotting points is failing, either >>> pcolor, pcolormesh, imshow, etc. >>> >>> >>> >>>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>>> >>>>>>>> >>>>>>>> >>> might have the experience and skills to easily explain to me how to >>> manipulate these points and plot them on the map, as there's like no help >>> >>> >> on >> >> >>> the web except standard examples... >>> >>> >>> >>>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>>> >>>>>>>> >> if >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> it takes too much of your time just advice me some lectures >>> >>> >>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> De Pauw Antoine >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: It would really help to have a script demonstrating your >>>>>>> problem. It sounds to me like you want to plot markers representing >>>>>>> > a > >>>>>>> >>>>>>> >> >> >>>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>>> pcolormesh and friends are for plotting gridded data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> De Pauw Antoine wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> Dear sir, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>>> >>>>>>>>>> >> the >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> “Quantum >>> >>> >>> >>>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>>> >>>>>>>>>> >> de >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> >>> >>> >>>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>>> solution, on an explanation from you here: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> any >>> >>> >>> >>>>>>>>>> points on maps. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> way, >>> >>> >>> >>>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>>> >>>>>>>>>> >> latitude, >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> >>> >>> >>>>>>>>>> longitude and values to plot? >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Some tips would be very nice from you as any method I have tried >>>>>>>>>> > so > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> far >>> >>> >>> >>>>>>>>>> give me some errors… >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Thank you very much in advance, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Best regards, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> plotting part >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>>> >>>>>>>>>> from numpy import * >>>>>>>>>> >>>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>>> >>>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>>> >>>>>>>>>> import numpy as np >>>>>>>>>> >>>>>>>>>> import os >>>>>>>>>> >>>>>>>>>> import sys >>>>>>>>>> >>>>>>>>>> import array >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> print('preparing map') >>>>>>>>>> >>>>>>>>>> map = >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>> >>> >>> >>>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>>> >>>>>>>>>> map.drawmapboundary() >>>>>>>>>> >>>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>>> >>>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>>> >>>>>>>>>> print('reading binary data') >>>>>>>>>> >>>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>>> >>>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> Val=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>>> >>>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>>> >>>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>>> >>>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>>> >>>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>>> >>>>>>>>>> i=0 >>>>>>>>>> >>>>>>>>>> while i < nbreligne: >>>>>>>>>> >>>>>>>>>> if(Lon[i]>180): >>>>>>>>>> >>>>>>>>>> print(Lon[i]) >>>>>>>>>> >>>>>>>>>> Lon[i]-=360 >>>>>>>>>> >>>>>>>>>> print(Lon[i]) >>>>>>>>>> >>>>>>>>>> i+=1 >>>>>>>>>> >>>>>>>>>> print('plotting data') >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> #plotting code comes here >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> very >>> >>> >>> >>>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>>> >>>>>>>>> >> could >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> be >>> >>> >>> >>>>>>>>> your data. >>>>>>>>> >>>>>>>>> -Jeff >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> print('saving map') >>>>>>>>>> >>>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>>> >>>>>>>>>> print('done') >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> *Antoine De Pauw* >>>>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> IT >>> >>> >>> >>>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>>> >>>>>>>>>> >> chemistry >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> and >>> >>> >>> >>>>>>>>>> photophysics laboratory >>>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> -- >>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |
|
From: De P. A. <and...@ul...> - 2008-09-12 09:00:49
|
Hi Jeff, I updated my code snippet and uploaded the image I created with a complete set of data: http://snipplr.com/view/8307/map-plotting-python-code-temporary/ And here's the picture generated: http://www.kirikoo.net/images/5shrad-20080912-105759.png I now understand the process and I'm able to reproduce it for other datasets, but I need to implement some antialiasing for it.. Is it possible to do? Many thanks for your precious help! Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: jeudi 11 septembre 2008 16:48 To: De Pauw Antoine Cc: 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Jeff, > > The map object is from the Basemap type, the only different thing is the > Lon,Lat and Val objects which are from the type array instead of lists > > Anyway, solutions are slowly showing themselves and I thank you all > > Have a nice day > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: It should not matter if Lon and Lat are python arrays, lists or numpy arrays. The Basemap instance __call__ method handles them all. There must be something else going on. It is always better to post actual code so we can see what is happening and test it ourselves. -Jeff > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 15:29 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Thanks Jeff, >> >> This seems to work with csv file types, and I've been experimenting a bit >> with it >> >> However, when I try to implement this with my original code (with binary >> files), I get an error like that one: >> >> Traceback (most recent call last): >> File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> >> x,y = map(Lon,Lat) >> TypeError: 'numpy.ndarray' object is not callable >> >> I think this is coming from the fact I use array objects to store >> > values... > >> could you confirm it? >> >> > > Antoine: It looks like you the object map is not a Basemap instance, > but a numpy array. Try putting 'print type(map)' just ahead of this > statement to verify this. I suspect your re-using the name 'map' in your > code, overwriting the Basemap class instance. > > -Jeff > >> Also, I'll see if it is possible to invert color scale and mask everything >> under a certain value >> >> Thanks very much for your help! >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> >> -----Original Message----- >> From: Jeff Whitaker [mailto:js...@fa...] >> Sent: jeudi 11 septembre 2008 14:10 >> To: De Pauw Antoine >> Cc: 'Matplotlib Users' >> Subject: Re: [Matplotlib-users] Information request >> >> De Pauw Antoine wrote: >> >> >>> Hi Jeff, >>> >>> I have put the code online with a sample of the data here: >>> >>> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >>> >>> I hope you'll be able to give me some advice as it is quite difficult for >>> someone new in python and scientific computation >>> >>> Antoine De Pauw >>> Collaborateur de recherches, Informatique - Research collaborator, IT >>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>> photophysics laboratory >>> Université Libre de Bruxelles - ULB >>> >>> >>> >> Antoine: I may have the size of the pixels wrong, and lat/lon >> transposed, but this is the general idea: >> >> from mpl_toolkits.basemap import Basemap >> import matplotlib.pyplot as plt >> import numpy as np >> lats = []; lons = []; data = [] >> for line in open('pixels.dat'): >> linesplit = line.split(',') >> lons.append(float(linesplit[1])) >> lats.append(float(linesplit[0])) >> data.append(float(linesplit[2])) >> map = >> Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ >> >> urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') >> x,y = map(lons,lats) >> plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) >> plt.colorbar(shrink=0.6) >> map.drawcoastlines() >> plt.show() >> >> -Jeff >> >> >> >>> -----Original Message----- >>> From: Jeff Whitaker [mailto:Jef...@no...] >>> Sent: mercredi 10 septembre 2008 16:45 >>> To: Antoine De Pauw >>> Cc: Matplotlib Users >>> Subject: Re: Information request >>> >>> Antoine De Pauw wrote: >>> >>> >>> >>>> Thanks Jeff, >>>> >>>> In fact my points are arranged in three unsorted arrays, with a simple >>>> >>>> >>>> >>> scheme (thats why I couldn't plot them with imshow and others) >>> >>> >>> >>>> arrays: >>>> >>>> [lat][lon][val] >>>> [-10][ 17][0.3] >>>> [ 37][ 23][3.7] >>>> ... ... ... >>>> >>>> and so for many rows... >>>> >>>> what I have to do is looping through my arrays like that >>>> >>>> while i < rowcount: >>>> plot_to_map(lat[i],lon[i],val[i]) >>>> >>>> it is evidently an idea of how it could be done easily but my knowledge >>>> >>>> >> of >> >> >>>> >>>> >>>> >>> these libraries is too weak for me to figure out how to do it >>> >>> >>> >>>> my data comes from huge binary files but is extremely simple, so it >>>> > would > >>>> >>>> >>>> >>> be really easy for anyone to help me as the problem itself is how to put >>> unsorted points on the map with latitude and longitude coordinates >>> >>> >>> Antoine: You haven't said if your data forms a rectangular array. If >>> so, you can build a 2-d array from the input file and plot it with >>> imshow. If not, you can still plug the elements into a 2-d masked >>> array, leaving the missing pixels masked. You say the points are >>> 'unsorted', does that mean they are randomly distributed and do not form >>> a rectangular grid? >>> >>> It would really be much easier to help if you gave us more information, >>> such as how the data is structured, what the pixel footprint is, etc. >>> Perhaps you could post the binary file on an ftp site somewhere with >>> code to read it. >>> >>> Also, please hit 'reply all' when replying, so the matplotlib users >>> mailing list is CC'ed. >>> >>> -Jeff >>> >>> >>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>> >>>>>> Sir, >>>>>> >>>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>>> >>>>>> >>>>>> >>> difficult to be understandable. >>> >>> >>> >>>>>> All is in the script I gave to you initially, except the point drawing >>>>>> >>>>>> >>>>>> >>> code which would be useless as it is proven not to work (I dont know the >>> method to do it). >>> >>> >>> >>>>>> What I have is a map, and a set of pixels I have to put on it with >>>>>> >>>>>> >>>>>> >>> geographic coordinates. >>> >>> >>> >>>>>> I cannot find the right method to put colour pixels on the map, that's >>>>>> >>>>>> >>>>>> >>> the problem. >>> >>> >>> >>>>>> I have that map in miller projection, and three arrays containing >>>>>> >>>>>> >>>>>> >>> respectively latitude, longitude and satellite measured value. >>> >>> >>> >>>>>> What I need to obtain is something approximately like this: >>>>>> >>>>>> >>>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> >> >>> _00_lr.gif but with the basemap toolkit. >>> >>> >>> >>>>>> So, my question is: how could I do to plot a coloured pixel at >>>>>> >>>>>> >>>>>> >>> coordinates lat:lon on that map? If I have just the method to project a >>> geographic coordinate on the map and put a coloured pixel at the right >>> place, all is done and I just have to loop my arrays... Also, I would >>> > have > >>> to implement some antialiasing on the map. >>> >>> >>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> Antoine: >>>>> >>>>> Are the pixels arranged on a regular grid - or are they randomly >>>>> distributed? If they are on a grid, it's easy (using pcolor or >>>>> > imshow). > >>>>> >>>>> >> >> >>>>> If you could send me your data I may be able to get you started. >>>>> >>>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>>> >>>>> >>>>> -Jeff >>>>> >>>>> >>>>> >>>>>> If this is not possible to do it in a simple and explainable way, >>>>>> >>>>>> >> please >> >> >>>>>> >>>>>> >>>>>> >>> tell me and I'll continue using matlab or searching for the bit of code >>> which will save me >>> >>> >>> >>>>>> Anyway, I have to thank you for your interest to help me.. >>>>>> >>>>>> Many thanks, >>>>>> >>>>>> Antoine De Pauw >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> Antoine De Pauw wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Hi, and thanks for the answer >>>>>>>> >>>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>>> >>>>>>>> >>>>>>>> >>> (Lat,Lon,Val) describing geographic points which are associated by index >>> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>> >>> >>> >>>>>>>> What I need to do is to plot some points on the map (miller >>>>>>>> >>>>>>>> >> projection >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> for most) based on latitude and longitude, to obtain a colour map (points >>> are unordered, it is from IASI satellite computations) >>> >>> >>> >>>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>>> >>>>>>>> >>>>>>>> >>> problem I have is any method I try for plotting points is failing, either >>> pcolor, pcolormesh, imshow, etc. >>> >>> >>> >>>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>>> >>>>>>>> >>>>>>>> >>> might have the experience and skills to easily explain to me how to >>> manipulate these points and plot them on the map, as there's like no help >>> >>> >> on >> >> >>> the web except standard examples... >>> >>> >>> >>>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>>> >>>>>>>> >> if >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> it takes too much of your time just advice me some lectures >>> >>> >>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> De Pauw Antoine >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: It would really help to have a script demonstrating your >>>>>>> problem. It sounds to me like you want to plot markers representing >>>>>>> > a > >>>>>>> >>>>>>> >> >> >>>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>>> pcolormesh and friends are for plotting gridded data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> De Pauw Antoine wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> Dear sir, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>>> >>>>>>>>>> >> the >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> “Quantum >>> >>> >>> >>>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>>> >>>>>>>>>> >> de >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> >>> >>> >>>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>>> solution, on an explanation from you here: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> any >>> >>> >>> >>>>>>>>>> points on maps. >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> way, >>> >>> >>> >>>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>>> >>>>>>>>>> >> latitude, >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> >>> >>> >>>>>>>>>> longitude and values to plot? >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Some tips would be very nice from you as any method I have tried >>>>>>>>>> > so > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> far >>> >>> >>> >>>>>>>>>> give me some errors… >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Thank you very much in advance, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> Best regards, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> plotting part >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>>> >>>>>>>>>> from numpy import * >>>>>>>>>> >>>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>>> >>>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>>> >>>>>>>>>> import numpy as np >>>>>>>>>> >>>>>>>>>> import os >>>>>>>>>> >>>>>>>>>> import sys >>>>>>>>>> >>>>>>>>>> import array >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> print('preparing map') >>>>>>>>>> >>>>>>>>>> map = >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>> >>> >>> >>>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>>> >>>>>>>>>> map.drawmapboundary() >>>>>>>>>> >>>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>>> >>>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>>> >>>>>>>>>> print('reading binary data') >>>>>>>>>> >>>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>>> >>>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> Val=zeros(nbreligne) >>>>>>>>>> >>>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>>> >>>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>>> >>>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>>> >>>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>>> >>>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>>> >>>>>>>>>> i=0 >>>>>>>>>> >>>>>>>>>> while i < nbreligne: >>>>>>>>>> >>>>>>>>>> if(Lon[i]>180): >>>>>>>>>> >>>>>>>>>> print(Lon[i]) >>>>>>>>>> >>>>>>>>>> Lon[i]-=360 >>>>>>>>>> >>>>>>>>>> print(Lon[i]) >>>>>>>>>> >>>>>>>>>> i+=1 >>>>>>>>>> >>>>>>>>>> print('plotting data') >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> #plotting code comes here >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>>> problem you see, I can help you debug it. As it stands now, I have >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> very >>> >>> >>> >>>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>>> >>>>>>>>> >> could >> >> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> be >>> >>> >>> >>>>>>>>> your data. >>>>>>>>> >>>>>>>>> -Jeff >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> print('saving map') >>>>>>>>>> >>>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>>> >>>>>>>>>> print('done') >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> *Antoine De Pauw* >>>>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> IT >>> >>> >>> >>>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>>> >>>>>>>>>> >> chemistry >> >> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> and >>> >>> >>> >>>>>>>>>> photophysics laboratory >>>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> -- >>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |
|
From: Jeff W. <js...@fa...> - 2008-09-12 11:26:33
|
De Pauw Antoine wrote: > Hi Jeff, > > I updated my code snippet and uploaded the image I created with a complete > set of data: > > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > And here's the picture generated: > > http://www.kirikoo.net/images/5shrad-20080912-105759.png > > I now understand the process and I'm able to reproduce it for other > datasets, but I need to implement some antialiasing for it.. > > Is it possible to do? > > Many thanks for your precious help! > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: If you do >>> from pylab import scatter >>> help(scatter) you will see that scatter takes an antialised keyword antialiased Boolean or sequence of booleans -Jeff > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 16:48 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Jeff, >> >> The map object is from the Basemap type, the only different thing is the >> Lon,Lat and Val objects which are from the type array instead of lists >> >> Anyway, solutions are slowly showing themselves and I thank you all >> >> Have a nice day >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: It should not matter if Lon and Lat are python arrays, lists > or numpy arrays. The Basemap instance __call__ method handles them all. > There must be something else going on. It is always better to post > actual code so we can see what is happening and test it ourselves. > > -Jeff > >> -----Original Message----- >> From: Jeff Whitaker [mailto:js...@fa...] >> Sent: jeudi 11 septembre 2008 15:29 >> To: De Pauw Antoine >> Cc: 'Matplotlib Users' >> Subject: Re: [Matplotlib-users] Information request >> >> De Pauw Antoine wrote: >> >> >>> Thanks Jeff, >>> >>> This seems to work with csv file types, and I've been experimenting a bit >>> with it >>> >>> However, when I try to implement this with my original code (with binary >>> files), I get an error like that one: >>> >>> Traceback (most recent call last): >>> File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> >>> x,y = map(Lon,Lat) >>> TypeError: 'numpy.ndarray' object is not callable >>> >>> I think this is coming from the fact I use array objects to store >>> >>> >> values... >> >> >>> could you confirm it? >>> >>> >>> >> Antoine: It looks like you the object map is not a Basemap instance, >> but a numpy array. Try putting 'print type(map)' just ahead of this >> statement to verify this. I suspect your re-using the name 'map' in your >> code, overwriting the Basemap class instance. >> >> -Jeff >> >> >>> Also, I'll see if it is possible to invert color scale and mask >>> > everything > >>> under a certain value >>> >>> Thanks very much for your help! >>> >>> Antoine De Pauw >>> Collaborateur de recherches, Informatique - Research collaborator, IT >>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>> photophysics laboratory >>> Université Libre de Bruxelles - ULB >>> >>> >>> -----Original Message----- >>> From: Jeff Whitaker [mailto:js...@fa...] >>> Sent: jeudi 11 septembre 2008 14:10 >>> To: De Pauw Antoine >>> Cc: 'Matplotlib Users' >>> Subject: Re: [Matplotlib-users] Information request >>> >>> De Pauw Antoine wrote: >>> >>> >>> >>>> Hi Jeff, >>>> >>>> I have put the code online with a sample of the data here: >>>> >>>> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >>>> >>>> I hope you'll be able to give me some advice as it is quite difficult >>>> > for > >>>> someone new in python and scientific computation >>>> >>>> Antoine De Pauw >>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>> photophysics laboratory >>>> Université Libre de Bruxelles - ULB >>>> >>>> >>>> >>>> >>> Antoine: I may have the size of the pixels wrong, and lat/lon >>> transposed, but this is the general idea: >>> >>> from mpl_toolkits.basemap import Basemap >>> import matplotlib.pyplot as plt >>> import numpy as np >>> lats = []; lons = []; data = [] >>> for line in open('pixels.dat'): >>> linesplit = line.split(',') >>> lons.append(float(linesplit[1])) >>> lats.append(float(linesplit[0])) >>> data.append(float(linesplit[2])) >>> map = >>> Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ >>> >>> urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') >>> x,y = map(lons,lats) >>> plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) >>> plt.colorbar(shrink=0.6) >>> map.drawcoastlines() >>> plt.show() >>> >>> -Jeff >>> >>> >>> >>> >>>> -----Original Message----- >>>> From: Jeff Whitaker [mailto:Jef...@no...] >>>> Sent: mercredi 10 septembre 2008 16:45 >>>> To: Antoine De Pauw >>>> Cc: Matplotlib Users >>>> Subject: Re: Information request >>>> >>>> Antoine De Pauw wrote: >>>> >>>> >>>> >>>> >>>>> Thanks Jeff, >>>>> >>>>> In fact my points are arranged in three unsorted arrays, with a simple >>>>> >>>>> >>>>> >>>>> >>>> scheme (thats why I couldn't plot them with imshow and others) >>>> >>>> >>>> >>>> >>>>> arrays: >>>>> >>>>> [lat][lon][val] >>>>> [-10][ 17][0.3] >>>>> [ 37][ 23][3.7] >>>>> ... ... ... >>>>> >>>>> and so for many rows... >>>>> >>>>> what I have to do is looping through my arrays like that >>>>> >>>>> while i < rowcount: >>>>> plot_to_map(lat[i],lon[i],val[i]) >>>>> >>>>> it is evidently an idea of how it could be done easily but my knowledge >>>>> >>>>> >>>>> >>> of >>> >>> >>> >>>>> >>>>> >>>>> >>>>> >>>> these libraries is too weak for me to figure out how to do it >>>> >>>> >>>> >>>> >>>>> my data comes from huge binary files but is extremely simple, so it >>>>> >>>>> >> would >> >> >>>>> >>>>> >>>>> >>>>> >>>> be really easy for anyone to help me as the problem itself is how to put >>>> unsorted points on the map with latitude and longitude coordinates >>>> >>>> >>>> Antoine: You haven't said if your data forms a rectangular array. If >>>> so, you can build a 2-d array from the input file and plot it with >>>> imshow. If not, you can still plug the elements into a 2-d masked >>>> array, leaving the missing pixels masked. You say the points are >>>> 'unsorted', does that mean they are randomly distributed and do not form >>>> > > >>>> a rectangular grid? >>>> >>>> It would really be much easier to help if you gave us more information, >>>> such as how the data is structured, what the pixel footprint is, etc. >>>> Perhaps you could post the binary file on an ftp site somewhere with >>>> code to read it. >>>> >>>> Also, please hit 'reply all' when replying, so the matplotlib users >>>> mailing list is CC'ed. >>>> >>>> -Jeff >>>> >>>> >>>> >>>> >>>>>> Antoine De Pauw wrote: >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> Sir, >>>>>>> >>>>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> difficult to be understandable. >>>> >>>> >>>> >>>> >>>>>>> All is in the script I gave to you initially, except the point >>>>>>> > drawing > >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> code which would be useless as it is proven not to work (I dont know the >>>> method to do it). >>>> >>>> >>>> >>>> >>>>>>> What I have is a map, and a set of pixels I have to put on it with >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> geographic coordinates. >>>> >>>> >>>> >>>> >>>>>>> I cannot find the right method to put colour pixels on the map, >>>>>>> > that's > >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> the problem. >>>> >>>> >>>> >>>> >>>>>>> I have that map in miller projection, and three arrays containing >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> respectively latitude, longitude and satellite measured value. >>>> >>>> >>>> >>>> >>>>>>> What I need to obtain is something approximately like this: >>>>>>> >>>>>>> >>>>>>> >>>>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> >> >>> >>> >>> >>>> _00_lr.gif but with the basemap toolkit. >>>> >>>> >>>> >>>> >>>>>>> So, my question is: how could I do to plot a coloured pixel at >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> coordinates lat:lon on that map? If I have just the method to project a >>>> geographic coordinate on the map and put a coloured pixel at the right >>>> place, all is done and I just have to loop my arrays... Also, I would >>>> >>>> >> have >> >> >>>> to implement some antialiasing on the map. >>>> >>>> >>>> >>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> Antoine: >>>>>> >>>>>> Are the pixels arranged on a regular grid - or are they randomly >>>>>> distributed? If they are on a grid, it's easy (using pcolor or >>>>>> >>>>>> >> imshow). >> >> >>>>>> >>>>>> >>>>>> >>> >>> >>> >>>>>> If you could send me your data I may be able to get you started. >>>>>> >>>>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>>>> >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> If this is not possible to do it in a simple and explainable way, >>>>>>> >>>>>>> >>>>>>> >>> please >>> >>> >>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> tell me and I'll continue using matlab or searching for the bit of code >>>> which will save me >>>> >>>> >>>> >>>> >>>>>>> Anyway, I have to thank you for your interest to help me.. >>>>>>> >>>>>>> Many thanks, >>>>>>> >>>>>>> Antoine De Pauw >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Antoine De Pauw wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Hi, and thanks for the answer >>>>>>>>> >>>>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> (Lat,Lon,Val) describing geographic points which are associated by index >>>> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>> >>>> >>>> >>>> >>>>>>>>> What I need to do is to plot some points on the map (miller >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> projection >>> >>> >>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> for most) based on latitude and longitude, to obtain a colour map >>>> > (points > >>>> are unordered, it is from IASI satellite computations) >>>> >>>> >>>> >>>> >>>>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> problem I have is any method I try for plotting points is failing, >>>> > either > >>>> pcolor, pcolormesh, imshow, etc. >>>> >>>> >>>> >>>> >>>>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> might have the experience and skills to easily explain to me how to >>>> manipulate these points and plot them on the map, as there's like no >>>> > help > >>>> >>>> >>>> >>> on >>> >>> >>> >>>> the web except standard examples... >>>> >>>> >>>> >>>> >>>>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> if >>> >>> >>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> it takes too much of your time just advice me some lectures >>>> >>>> >>>> >>>> >>>>>>>>> Best regards, >>>>>>>>> >>>>>>>>> De Pauw Antoine >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> Antoine: It would really help to have a script demonstrating your >>>>>>>> problem. It sounds to me like you want to plot markers representing >>>>>>>> >>>>>>>> >> a >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> >>> >>> >>>>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>>>> > > >>>>>>>> pcolormesh and friends are for plotting gridded data. >>>>>>>> >>>>>>>> -Jeff >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> De Pauw Antoine wrote: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> Dear sir, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> the >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> “Quantum >>>> >>>> >>>> >>>> >>>>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> de >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> >>>> >>>> >>>> >>>>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>>>> solution, on an explanation from you here: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>> >>>> >>>> >>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> any >>>> >>>> >>>> >>>> >>>>>>>>>>> points on maps. >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> way, >>>> >>>> >>>> >>>> >>>>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> latitude, >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> >>>> >>>> >>>> >>>>>>>>>>> longitude and values to plot? >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Some tips would be very nice from you as any method I have tried >>>>>>>>>>> >>>>>>>>>>> >> so >> >> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> far >>>> >>>> >>>> >>>> >>>>>>>>>>> give me some errors… >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Thank you very much in advance, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Best regards, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> plotting part >>>> >>>> >>>> >>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>>>> >>>>>>>>>>> from numpy import * >>>>>>>>>>> >>>>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>>>> >>>>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>>>> >>>>>>>>>>> import numpy as np >>>>>>>>>>> >>>>>>>>>>> import os >>>>>>>>>>> >>>>>>>>>>> import sys >>>>>>>>>>> >>>>>>>>>>> import array >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> print('preparing map') >>>>>>>>>>> >>>>>>>>>>> map = >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>> >>> >>> >>>> >>>> >>>> >>>> >>>>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>>>> >>>>>>>>>>> map.drawmapboundary() >>>>>>>>>>> >>>>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>>>> >>>>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>>>> >>>>>>>>>>> print('reading binary data') >>>>>>>>>>> >>>>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>>>> >>>>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> Val=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>>>> >>>>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>>>> >>>>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>>>> >>>>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>>>> >>>>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>>>> >>>>>>>>>>> i=0 >>>>>>>>>>> >>>>>>>>>>> while i < nbreligne: >>>>>>>>>>> >>>>>>>>>>> if(Lon[i]>180): >>>>>>>>>>> >>>>>>>>>>> print(Lon[i]) >>>>>>>>>>> >>>>>>>>>>> Lon[i]-=360 >>>>>>>>>>> >>>>>>>>>>> print(Lon[i]) >>>>>>>>>>> >>>>>>>>>>> i+=1 >>>>>>>>>>> >>>>>>>>>>> print('plotting data') >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> #plotting code comes here >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>>>> > > >>>>>>>>>> problem you see, I can help you debug it. As it stands now, I >>>>>>>>>> > have > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> very >>>> >>>> >>>> >>>> >>>>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> could >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> be >>>> >>>> >>>> >>>> >>>>>>>>>> your data. >>>>>>>>>> >>>>>>>>>> -Jeff >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> print('saving map') >>>>>>>>>>> >>>>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>>>> >>>>>>>>>>> print('done') >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> *Antoine De Pauw* >>>>>>>>>>> Collaborateur de recherches, Informatique - Research >>>>>>>>>>> > collaborator, > >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> IT >>>> >>>> >>>> >>>> >>>>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> chemistry >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> and >>>> >>>> >>>> >>>> >>>>>>>>>>> photophysics laboratory >>>>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> -- >>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> >>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: De P. A. <and...@ul...> - 2008-09-12 13:00:06
|
Thanks Jeff, Antialiasing is not very useful as my pixel size is small... also, I used octagon shapes to have a smoother picture Now I'm looking for suppressing pixels under (or over) a certain value, but a couple hours of searching and testing didn't help... I'll see Monday if I find some tips Have a nice weekend Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: vendredi 12 septembre 2008 13:26 To: De Pauw Antoine Cc: 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Hi Jeff, > > I updated my code snippet and uploaded the image I created with a complete > set of data: > > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > And here's the picture generated: > > http://www.kirikoo.net/images/5shrad-20080912-105759.png > > I now understand the process and I'm able to reproduce it for other > datasets, but I need to implement some antialiasing for it.. > > Is it possible to do? > > Many thanks for your precious help! > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: If you do >>> from pylab import scatter >>> help(scatter) you will see that scatter takes an antialised keyword antialiased Boolean or sequence of booleans -Jeff > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 16:48 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Jeff, >> >> The map object is from the Basemap type, the only different thing is the >> Lon,Lat and Val objects which are from the type array instead of lists >> >> Anyway, solutions are slowly showing themselves and I thank you all >> >> Have a nice day >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: It should not matter if Lon and Lat are python arrays, lists > or numpy arrays. The Basemap instance __call__ method handles them all. > There must be something else going on. It is always better to post > actual code so we can see what is happening and test it ourselves. > > -Jeff > >> -----Original Message----- >> From: Jeff Whitaker [mailto:js...@fa...] >> Sent: jeudi 11 septembre 2008 15:29 >> To: De Pauw Antoine >> Cc: 'Matplotlib Users' >> Subject: Re: [Matplotlib-users] Information request >> >> De Pauw Antoine wrote: >> >> >>> Thanks Jeff, >>> >>> This seems to work with csv file types, and I've been experimenting a bit >>> with it >>> >>> However, when I try to implement this with my original code (with binary >>> files), I get an error like that one: >>> >>> Traceback (most recent call last): >>> File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> >>> x,y = map(Lon,Lat) >>> TypeError: 'numpy.ndarray' object is not callable >>> >>> I think this is coming from the fact I use array objects to store >>> >>> >> values... >> >> >>> could you confirm it? >>> >>> >>> >> Antoine: It looks like you the object map is not a Basemap instance, >> but a numpy array. Try putting 'print type(map)' just ahead of this >> statement to verify this. I suspect your re-using the name 'map' in your >> code, overwriting the Basemap class instance. >> >> -Jeff >> >> >>> Also, I'll see if it is possible to invert color scale and mask >>> > everything > >>> under a certain value >>> >>> Thanks very much for your help! >>> >>> Antoine De Pauw >>> Collaborateur de recherches, Informatique - Research collaborator, IT >>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>> photophysics laboratory >>> Université Libre de Bruxelles - ULB >>> >>> >>> -----Original Message----- >>> From: Jeff Whitaker [mailto:js...@fa...] >>> Sent: jeudi 11 septembre 2008 14:10 >>> To: De Pauw Antoine >>> Cc: 'Matplotlib Users' >>> Subject: Re: [Matplotlib-users] Information request >>> >>> De Pauw Antoine wrote: >>> >>> >>> >>>> Hi Jeff, >>>> >>>> I have put the code online with a sample of the data here: >>>> >>>> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >>>> >>>> I hope you'll be able to give me some advice as it is quite difficult >>>> > for > >>>> someone new in python and scientific computation >>>> >>>> Antoine De Pauw >>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>> photophysics laboratory >>>> Université Libre de Bruxelles - ULB >>>> >>>> >>>> >>>> >>> Antoine: I may have the size of the pixels wrong, and lat/lon >>> transposed, but this is the general idea: >>> >>> from mpl_toolkits.basemap import Basemap >>> import matplotlib.pyplot as plt >>> import numpy as np >>> lats = []; lons = []; data = [] >>> for line in open('pixels.dat'): >>> linesplit = line.split(',') >>> lons.append(float(linesplit[1])) >>> lats.append(float(linesplit[0])) >>> data.append(float(linesplit[2])) >>> map = >>> Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ >>> >>> urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') >>> x,y = map(lons,lats) >>> plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) >>> plt.colorbar(shrink=0.6) >>> map.drawcoastlines() >>> plt.show() >>> >>> -Jeff >>> >>> >>> >>> >>>> -----Original Message----- >>>> From: Jeff Whitaker [mailto:Jef...@no...] >>>> Sent: mercredi 10 septembre 2008 16:45 >>>> To: Antoine De Pauw >>>> Cc: Matplotlib Users >>>> Subject: Re: Information request >>>> >>>> Antoine De Pauw wrote: >>>> >>>> >>>> >>>> >>>>> Thanks Jeff, >>>>> >>>>> In fact my points are arranged in three unsorted arrays, with a simple >>>>> >>>>> >>>>> >>>>> >>>> scheme (thats why I couldn't plot them with imshow and others) >>>> >>>> >>>> >>>> >>>>> arrays: >>>>> >>>>> [lat][lon][val] >>>>> [-10][ 17][0.3] >>>>> [ 37][ 23][3.7] >>>>> ... ... ... >>>>> >>>>> and so for many rows... >>>>> >>>>> what I have to do is looping through my arrays like that >>>>> >>>>> while i < rowcount: >>>>> plot_to_map(lat[i],lon[i],val[i]) >>>>> >>>>> it is evidently an idea of how it could be done easily but my knowledge >>>>> >>>>> >>>>> >>> of >>> >>> >>> >>>>> >>>>> >>>>> >>>>> >>>> these libraries is too weak for me to figure out how to do it >>>> >>>> >>>> >>>> >>>>> my data comes from huge binary files but is extremely simple, so it >>>>> >>>>> >> would >> >> >>>>> >>>>> >>>>> >>>>> >>>> be really easy for anyone to help me as the problem itself is how to put >>>> unsorted points on the map with latitude and longitude coordinates >>>> >>>> >>>> Antoine: You haven't said if your data forms a rectangular array. If >>>> so, you can build a 2-d array from the input file and plot it with >>>> imshow. If not, you can still plug the elements into a 2-d masked >>>> array, leaving the missing pixels masked. You say the points are >>>> 'unsorted', does that mean they are randomly distributed and do not form >>>> > > >>>> a rectangular grid? >>>> >>>> It would really be much easier to help if you gave us more information, >>>> such as how the data is structured, what the pixel footprint is, etc. >>>> Perhaps you could post the binary file on an ftp site somewhere with >>>> code to read it. >>>> >>>> Also, please hit 'reply all' when replying, so the matplotlib users >>>> mailing list is CC'ed. >>>> >>>> -Jeff >>>> >>>> >>>> >>>> >>>>>> Antoine De Pauw wrote: >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> Sir, >>>>>>> >>>>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> difficult to be understandable. >>>> >>>> >>>> >>>> >>>>>>> All is in the script I gave to you initially, except the point >>>>>>> > drawing > >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> code which would be useless as it is proven not to work (I dont know the >>>> method to do it). >>>> >>>> >>>> >>>> >>>>>>> What I have is a map, and a set of pixels I have to put on it with >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> geographic coordinates. >>>> >>>> >>>> >>>> >>>>>>> I cannot find the right method to put colour pixels on the map, >>>>>>> > that's > >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> the problem. >>>> >>>> >>>> >>>> >>>>>>> I have that map in miller projection, and three arrays containing >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> respectively latitude, longitude and satellite measured value. >>>> >>>> >>>> >>>> >>>>>>> What I need to obtain is something approximately like this: >>>>>>> >>>>>>> >>>>>>> >>>>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> >> >>> >>> >>> >>>> _00_lr.gif but with the basemap toolkit. >>>> >>>> >>>> >>>> >>>>>>> So, my question is: how could I do to plot a coloured pixel at >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> coordinates lat:lon on that map? If I have just the method to project a >>>> geographic coordinate on the map and put a coloured pixel at the right >>>> place, all is done and I just have to loop my arrays... Also, I would >>>> >>>> >> have >> >> >>>> to implement some antialiasing on the map. >>>> >>>> >>>> >>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> Antoine: >>>>>> >>>>>> Are the pixels arranged on a regular grid - or are they randomly >>>>>> distributed? If they are on a grid, it's easy (using pcolor or >>>>>> >>>>>> >> imshow). >> >> >>>>>> >>>>>> >>>>>> >>> >>> >>> >>>>>> If you could send me your data I may be able to get you started. >>>>>> >>>>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>>>> >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> If this is not possible to do it in a simple and explainable way, >>>>>>> >>>>>>> >>>>>>> >>> please >>> >>> >>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> tell me and I'll continue using matlab or searching for the bit of code >>>> which will save me >>>> >>>> >>>> >>>> >>>>>>> Anyway, I have to thank you for your interest to help me.. >>>>>>> >>>>>>> Many thanks, >>>>>>> >>>>>>> Antoine De Pauw >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Antoine De Pauw wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Hi, and thanks for the answer >>>>>>>>> >>>>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> (Lat,Lon,Val) describing geographic points which are associated by index >>>> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>> >>>> >>>> >>>> >>>>>>>>> What I need to do is to plot some points on the map (miller >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> projection >>> >>> >>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> for most) based on latitude and longitude, to obtain a colour map >>>> > (points > >>>> are unordered, it is from IASI satellite computations) >>>> >>>> >>>> >>>> >>>>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> problem I have is any method I try for plotting points is failing, >>>> > either > >>>> pcolor, pcolormesh, imshow, etc. >>>> >>>> >>>> >>>> >>>>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> might have the experience and skills to easily explain to me how to >>>> manipulate these points and plot them on the map, as there's like no >>>> > help > >>>> >>>> >>>> >>> on >>> >>> >>> >>>> the web except standard examples... >>>> >>>> >>>> >>>> >>>>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> if >>> >>> >>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> it takes too much of your time just advice me some lectures >>>> >>>> >>>> >>>> >>>>>>>>> Best regards, >>>>>>>>> >>>>>>>>> De Pauw Antoine >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> Antoine: It would really help to have a script demonstrating your >>>>>>>> problem. It sounds to me like you want to plot markers representing >>>>>>>> >>>>>>>> >> a >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> >>> >>> >>>>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>>>> > > >>>>>>>> pcolormesh and friends are for plotting gridded data. >>>>>>>> >>>>>>>> -Jeff >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> De Pauw Antoine wrote: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> Dear sir, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> the >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> “Quantum >>>> >>>> >>>> >>>> >>>>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> de >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> >>>> >>>> >>>> >>>>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>>>> solution, on an explanation from you here: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>> >>>> >>>> >>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> any >>>> >>>> >>>> >>>> >>>>>>>>>>> points on maps. >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> way, >>>> >>>> >>>> >>>> >>>>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> latitude, >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> >>>> >>>> >>>> >>>>>>>>>>> longitude and values to plot? >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Some tips would be very nice from you as any method I have tried >>>>>>>>>>> >>>>>>>>>>> >> so >> >> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> far >>>> >>>> >>>> >>>> >>>>>>>>>>> give me some errors… >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Thank you very much in advance, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Best regards, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> plotting part >>>> >>>> >>>> >>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>>>> >>>>>>>>>>> from numpy import * >>>>>>>>>>> >>>>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>>>> >>>>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>>>> >>>>>>>>>>> import numpy as np >>>>>>>>>>> >>>>>>>>>>> import os >>>>>>>>>>> >>>>>>>>>>> import sys >>>>>>>>>>> >>>>>>>>>>> import array >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> print('preparing map') >>>>>>>>>>> >>>>>>>>>>> map = >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>> >>> >>> >>>> >>>> >>>> >>>> >>>>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>>>> >>>>>>>>>>> map.drawmapboundary() >>>>>>>>>>> >>>>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>>>> >>>>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>>>> >>>>>>>>>>> print('reading binary data') >>>>>>>>>>> >>>>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>>>> >>>>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> Val=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>>>> >>>>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>>>> >>>>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>>>> >>>>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>>>> >>>>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>>>> >>>>>>>>>>> i=0 >>>>>>>>>>> >>>>>>>>>>> while i < nbreligne: >>>>>>>>>>> >>>>>>>>>>> if(Lon[i]>180): >>>>>>>>>>> >>>>>>>>>>> print(Lon[i]) >>>>>>>>>>> >>>>>>>>>>> Lon[i]-=360 >>>>>>>>>>> >>>>>>>>>>> print(Lon[i]) >>>>>>>>>>> >>>>>>>>>>> i+=1 >>>>>>>>>>> >>>>>>>>>>> print('plotting data') >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> #plotting code comes here >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>>>> > > >>>>>>>>>> problem you see, I can help you debug it. As it stands now, I >>>>>>>>>> > have > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> very >>>> >>>> >>>> >>>> >>>>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> could >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> be >>>> >>>> >>>> >>>> >>>>>>>>>> your data. >>>>>>>>>> >>>>>>>>>> -Jeff >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> print('saving map') >>>>>>>>>>> >>>>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>>>> >>>>>>>>>>> print('done') >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> *Antoine De Pauw* >>>>>>>>>>> Collaborateur de recherches, Informatique - Research >>>>>>>>>>> > collaborator, > >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> IT >>>> >>>> >>>> >>>> >>>>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> chemistry >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> and >>>> >>>> >>>> >>>> >>>>>>>>>>> photophysics laboratory >>>>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> -- >>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> >>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: De P. A. <and...@ul...> - 2008-09-16 03:21:35
|
Hi Jeff, I have played a bit with Matplotlib since last week, and I may still have some questions for you I have masked my value array so it doesn't draw points under a certain value, but doing this causes the colormap to rescale for the new values I have tried to set a custom colormap but it isn't the thing to do as data is varying in time So is it possible to avoid the colormap to rescale itself? Also, I had a look at imshow and the interpolation process is really interesting for smooth maps.. does a way to interpolate scattered data exist? The code I use didn't change since last time, all I did is adding a bit, testing and deleting.. Best regards, Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: vendredi 12 septembre 2008 13:26 To: De Pauw Antoine Cc: 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Hi Jeff, > > I updated my code snippet and uploaded the image I created with a complete > set of data: > > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > And here's the picture generated: > > http://www.kirikoo.net/images/5shrad-20080912-105759.png > > I now understand the process and I'm able to reproduce it for other > datasets, but I need to implement some antialiasing for it.. > > Is it possible to do? > > Many thanks for your precious help! > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: If you do >>> from pylab import scatter >>> help(scatter) you will see that scatter takes an antialised keyword antialiased Boolean or sequence of booleans -Jeff > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: jeudi 11 septembre 2008 16:48 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Jeff, >> >> The map object is from the Basemap type, the only different thing is the >> Lon,Lat and Val objects which are from the type array instead of lists >> >> Anyway, solutions are slowly showing themselves and I thank you all >> >> Have a nice day >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: It should not matter if Lon and Lat are python arrays, lists > or numpy arrays. The Basemap instance __call__ method handles them all. > There must be something else going on. It is always better to post > actual code so we can see what is happening and test it ourselves. > > -Jeff > >> -----Original Message----- >> From: Jeff Whitaker [mailto:js...@fa...] >> Sent: jeudi 11 septembre 2008 15:29 >> To: De Pauw Antoine >> Cc: 'Matplotlib Users' >> Subject: Re: [Matplotlib-users] Information request >> >> De Pauw Antoine wrote: >> >> >>> Thanks Jeff, >>> >>> This seems to work with csv file types, and I've been experimenting a bit >>> with it >>> >>> However, when I try to implement this with my original code (with binary >>> files), I get an error like that one: >>> >>> Traceback (most recent call last): >>> File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> >>> x,y = map(Lon,Lat) >>> TypeError: 'numpy.ndarray' object is not callable >>> >>> I think this is coming from the fact I use array objects to store >>> >>> >> values... >> >> >>> could you confirm it? >>> >>> >>> >> Antoine: It looks like you the object map is not a Basemap instance, >> but a numpy array. Try putting 'print type(map)' just ahead of this >> statement to verify this. I suspect your re-using the name 'map' in your >> code, overwriting the Basemap class instance. >> >> -Jeff >> >> >>> Also, I'll see if it is possible to invert color scale and mask >>> > everything > >>> under a certain value >>> >>> Thanks very much for your help! >>> >>> Antoine De Pauw >>> Collaborateur de recherches, Informatique - Research collaborator, IT >>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>> photophysics laboratory >>> Université Libre de Bruxelles - ULB >>> >>> >>> -----Original Message----- >>> From: Jeff Whitaker [mailto:js...@fa...] >>> Sent: jeudi 11 septembre 2008 14:10 >>> To: De Pauw Antoine >>> Cc: 'Matplotlib Users' >>> Subject: Re: [Matplotlib-users] Information request >>> >>> De Pauw Antoine wrote: >>> >>> >>> >>>> Hi Jeff, >>>> >>>> I have put the code online with a sample of the data here: >>>> >>>> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >>>> >>>> I hope you'll be able to give me some advice as it is quite difficult >>>> > for > >>>> someone new in python and scientific computation >>>> >>>> Antoine De Pauw >>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>> photophysics laboratory >>>> Université Libre de Bruxelles - ULB >>>> >>>> >>>> >>>> >>> Antoine: I may have the size of the pixels wrong, and lat/lon >>> transposed, but this is the general idea: >>> >>> from mpl_toolkits.basemap import Basemap >>> import matplotlib.pyplot as plt >>> import numpy as np >>> lats = []; lons = []; data = [] >>> for line in open('pixels.dat'): >>> linesplit = line.split(',') >>> lons.append(float(linesplit[1])) >>> lats.append(float(linesplit[0])) >>> data.append(float(linesplit[2])) >>> map = >>> Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ >>> >>> urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') >>> x,y = map(lons,lats) >>> plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) >>> plt.colorbar(shrink=0.6) >>> map.drawcoastlines() >>> plt.show() >>> >>> -Jeff >>> >>> >>> >>> >>>> -----Original Message----- >>>> From: Jeff Whitaker [mailto:Jef...@no...] >>>> Sent: mercredi 10 septembre 2008 16:45 >>>> To: Antoine De Pauw >>>> Cc: Matplotlib Users >>>> Subject: Re: Information request >>>> >>>> Antoine De Pauw wrote: >>>> >>>> >>>> >>>> >>>>> Thanks Jeff, >>>>> >>>>> In fact my points are arranged in three unsorted arrays, with a simple >>>>> >>>>> >>>>> >>>>> >>>> scheme (thats why I couldn't plot them with imshow and others) >>>> >>>> >>>> >>>> >>>>> arrays: >>>>> >>>>> [lat][lon][val] >>>>> [-10][ 17][0.3] >>>>> [ 37][ 23][3.7] >>>>> ... ... ... >>>>> >>>>> and so for many rows... >>>>> >>>>> what I have to do is looping through my arrays like that >>>>> >>>>> while i < rowcount: >>>>> plot_to_map(lat[i],lon[i],val[i]) >>>>> >>>>> it is evidently an idea of how it could be done easily but my knowledge >>>>> >>>>> >>>>> >>> of >>> >>> >>> >>>>> >>>>> >>>>> >>>>> >>>> these libraries is too weak for me to figure out how to do it >>>> >>>> >>>> >>>> >>>>> my data comes from huge binary files but is extremely simple, so it >>>>> >>>>> >> would >> >> >>>>> >>>>> >>>>> >>>>> >>>> be really easy for anyone to help me as the problem itself is how to put >>>> unsorted points on the map with latitude and longitude coordinates >>>> >>>> >>>> Antoine: You haven't said if your data forms a rectangular array. If >>>> so, you can build a 2-d array from the input file and plot it with >>>> imshow. If not, you can still plug the elements into a 2-d masked >>>> array, leaving the missing pixels masked. You say the points are >>>> 'unsorted', does that mean they are randomly distributed and do not form >>>> > > >>>> a rectangular grid? >>>> >>>> It would really be much easier to help if you gave us more information, >>>> such as how the data is structured, what the pixel footprint is, etc. >>>> Perhaps you could post the binary file on an ftp site somewhere with >>>> code to read it. >>>> >>>> Also, please hit 'reply all' when replying, so the matplotlib users >>>> mailing list is CC'ed. >>>> >>>> -Jeff >>>> >>>> >>>> >>>> >>>>>> Antoine De Pauw wrote: >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> Sir, >>>>>>> >>>>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> difficult to be understandable. >>>> >>>> >>>> >>>> >>>>>>> All is in the script I gave to you initially, except the point >>>>>>> > drawing > >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> code which would be useless as it is proven not to work (I dont know the >>>> method to do it). >>>> >>>> >>>> >>>> >>>>>>> What I have is a map, and a set of pixels I have to put on it with >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> geographic coordinates. >>>> >>>> >>>> >>>> >>>>>>> I cannot find the right method to put colour pixels on the map, >>>>>>> > that's > >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> the problem. >>>> >>>> >>>> >>>> >>>>>>> I have that map in miller projection, and three arrays containing >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> respectively latitude, longitude and satellite measured value. >>>> >>>> >>>> >>>> >>>>>>> What I need to obtain is something approximately like this: >>>>>>> >>>>>>> >>>>>>> >>>>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> >> >>> >>> >>> >>>> _00_lr.gif but with the basemap toolkit. >>>> >>>> >>>> >>>> >>>>>>> So, my question is: how could I do to plot a coloured pixel at >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> coordinates lat:lon on that map? If I have just the method to project a >>>> geographic coordinate on the map and put a coloured pixel at the right >>>> place, all is done and I just have to loop my arrays... Also, I would >>>> >>>> >> have >> >> >>>> to implement some antialiasing on the map. >>>> >>>> >>>> >>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> Antoine: >>>>>> >>>>>> Are the pixels arranged on a regular grid - or are they randomly >>>>>> distributed? If they are on a grid, it's easy (using pcolor or >>>>>> >>>>>> >> imshow). >> >> >>>>>> >>>>>> >>>>>> >>> >>> >>> >>>>>> If you could send me your data I may be able to get you started. >>>>>> >>>>>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>>>>> >>>>>> >>>>>> -Jeff >>>>>> >>>>>> >>>>>> >>>>>> >>>>>>> If this is not possible to do it in a simple and explainable way, >>>>>>> >>>>>>> >>>>>>> >>> please >>> >>> >>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> tell me and I'll continue using matlab or searching for the bit of code >>>> which will save me >>>> >>>> >>>> >>>> >>>>>>> Anyway, I have to thank you for your interest to help me.. >>>>>>> >>>>>>> Many thanks, >>>>>>> >>>>>>> Antoine De Pauw >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Antoine De Pauw wrote: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Hi, and thanks for the answer >>>>>>>>> >>>>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> (Lat,Lon,Val) describing geographic points which are associated by index >>>> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>> >>>> >>>> >>>> >>>>>>>>> What I need to do is to plot some points on the map (miller >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> projection >>> >>> >>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> for most) based on latitude and longitude, to obtain a colour map >>>> > (points > >>>> are unordered, it is from IASI satellite computations) >>>> >>>> >>>> >>>> >>>>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> problem I have is any method I try for plotting points is failing, >>>> > either > >>>> pcolor, pcolormesh, imshow, etc. >>>> >>>> >>>> >>>> >>>>>>>>> When I found your post on that mailing list, I figured out that you >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> might have the experience and skills to easily explain to me how to >>>> manipulate these points and plot them on the map, as there's like no >>>> > help > >>>> >>>> >>>> >>> on >>> >>> >>> >>>> the web except standard examples... >>>> >>>> >>>> >>>> >>>>>>>>> Please tell me if this is possible for you to give me some tips, or >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> if >>> >>> >>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> it takes too much of your time just advice me some lectures >>>> >>>> >>>> >>>> >>>>>>>>> Best regards, >>>>>>>>> >>>>>>>>> De Pauw Antoine >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> Antoine: It would really help to have a script demonstrating your >>>>>>>> problem. It sounds to me like you want to plot markers representing >>>>>>>> >>>>>>>> >> a >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>> >>> >>> >>>>>>>> set of points - for that you should use the scatter method. pcolor, >>>>>>>> > > >>>>>>>> pcolormesh and friends are for plotting gridded data. >>>>>>>> >>>>>>>> -Jeff >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> De Pauw Antoine wrote: >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> Dear sir, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> the >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> “Quantum >>>> >>>> >>>> >>>> >>>>>>>>>>> Chemistry and Photophysics” section of the Université Libre >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> de >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> >>>> >>>> >>>> >>>>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>>>> solution, on an explanation from you here: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>> >>>> >>>> >>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> It seems that you could help me find a solution, as I cannot plot >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> any >>>> >>>> >>>> >>>> >>>>>>>>>>> points on maps. >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Could you please tell me what I could do to plot data in a simple >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> way, >>>> >>>> >>>> >>>> >>>>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> latitude, >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> >>>> >>>> >>>> >>>>>>>>>>> longitude and values to plot? >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Some tips would be very nice from you as any method I have tried >>>>>>>>>>> >>>>>>>>>>> >> so >> >> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> far >>>> >>>> >>>> >>>> >>>>>>>>>>> give me some errors… >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Thank you very much in advance, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> Best regards, >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> plotting part >>>> >>>> >>>> >>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>>>> >>>>>>>>>>> from numpy import * >>>>>>>>>>> >>>>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>>>> >>>>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>>>> >>>>>>>>>>> import numpy as np >>>>>>>>>>> >>>>>>>>>>> import os >>>>>>>>>>> >>>>>>>>>>> import sys >>>>>>>>>>> >>>>>>>>>>> import array >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> print('preparing map') >>>>>>>>>>> >>>>>>>>>>> map = >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>> >>> >>> >>>> >>>> >>>> >>>> >>>>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>>>> >>>>>>>>>>> map.drawmapboundary() >>>>>>>>>>> >>>>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>>>> >>>>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>>>> >>>>>>>>>>> print('reading binary data') >>>>>>>>>>> >>>>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>>>> >>>>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> Val=zeros(nbreligne) >>>>>>>>>>> >>>>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>>>> >>>>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>>>> >>>>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>>>> >>>>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>>>> >>>>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>>>> >>>>>>>>>>> i=0 >>>>>>>>>>> >>>>>>>>>>> while i < nbreligne: >>>>>>>>>>> >>>>>>>>>>> if(Lon[i]>180): >>>>>>>>>>> >>>>>>>>>>> print(Lon[i]) >>>>>>>>>>> >>>>>>>>>>> Lon[i]-=360 >>>>>>>>>>> >>>>>>>>>>> print(Lon[i]) >>>>>>>>>>> >>>>>>>>>>> i+=1 >>>>>>>>>>> >>>>>>>>>>> print('plotting data') >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> #plotting code comes here >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>>>>> > > >>>>>>>>>> problem you see, I can help you debug it. As it stands now, I >>>>>>>>>> > have > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> very >>>> >>>> >>>> >>>> >>>>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>> could >>> >>> >>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> be >>>> >>>> >>>> >>>> >>>>>>>>>> your data. >>>>>>>>>> >>>>>>>>>> -Jeff >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> print('saving map') >>>>>>>>>>> >>>>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>>>> >>>>>>>>>>> print('done') >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> *Antoine De Pauw* >>>>>>>>>>> Collaborateur de recherches, Informatique - Research >>>>>>>>>>> > collaborator, > >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> IT >>>> >>>> >>>> >>>> >>>>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>> chemistry >>> >>> >>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> and >>>> >>>> >>>> >>>> >>>>>>>>>>> photophysics laboratory >>>>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> -- >>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> -- >>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> >>> >>> >>> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: Jeff W. <js...@fa...> - 2008-09-16 04:16:40
|
De Pauw Antoine wrote: > Hi Jeff, > > I have played a bit with Matplotlib since last week, and I may still have > some questions for you > > I have masked my value array so it doesn't draw points under a certain > value, but doing this causes the colormap to rescale for the new values > Antoine: Don't quite know what you're trying to accomplish, but you can use the vmin/vmax keywords to imshow, pcolor or scatter to scale the colormap to a certain range. Also, take a look at the image_masked.py example to see how to set the 'over/under' color in a colormap. > I have tried to set a custom colormap but it isn't the thing to do as data > is varying in time > > So is it possible to avoid the colormap to rescale itself? > > Also, I had a look at imshow and the interpolation process is really > interesting for smooth maps.. does a way to interpolate scattered data > exist? > If you have the most recent version of matplotlib you can use the griddata function to interpolate scattered data to a regular grid. -Jeff > The code I use didn't change since last time, all I did is adding a bit, > testing and deleting.. > > Best regards, > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: vendredi 12 septembre 2008 13:26 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Hi Jeff, >> >> I updated my code snippet and uploaded the image I created with a complete >> set of data: >> >> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >> >> And here's the picture generated: >> >> http://www.kirikoo.net/images/5shrad-20080912-105759.png >> >> I now understand the process and I'm able to reproduce it for other >> datasets, but I need to implement some antialiasing for it.. >> >> Is it possible to do? >> >> Many thanks for your precious help! >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: If you do > > >>> from pylab import scatter > >>> help(scatter) > > you will see that scatter takes an antialised keyword > > antialiased Boolean or sequence of booleans > > -Jeff > > >> -----Original Message----- >> From: Jeff Whitaker [mailto:js...@fa...] >> Sent: jeudi 11 septembre 2008 16:48 >> To: De Pauw Antoine >> Cc: 'Matplotlib Users' >> Subject: Re: [Matplotlib-users] Information request >> >> De Pauw Antoine wrote: >> >> >>> Jeff, >>> >>> The map object is from the Basemap type, the only different thing is the >>> Lon,Lat and Val objects which are from the type array instead of lists >>> >>> Anyway, solutions are slowly showing themselves and I thank you all >>> >>> Have a nice day >>> >>> Antoine De Pauw >>> Collaborateur de recherches, Informatique - Research collaborator, IT >>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>> photophysics laboratory >>> Université Libre de Bruxelles - ULB >>> >>> >>> >> Antoine: It should not matter if Lon and Lat are python arrays, lists >> or numpy arrays. The Basemap instance __call__ method handles them all. >> There must be something else going on. It is always better to post >> actual code so we can see what is happening and test it ourselves. >> >> -Jeff >> >> >>> -----Original Message----- >>> From: Jeff Whitaker [mailto:js...@fa...] >>> Sent: jeudi 11 septembre 2008 15:29 >>> To: De Pauw Antoine >>> Cc: 'Matplotlib Users' >>> Subject: Re: [Matplotlib-users] Information request >>> >>> De Pauw Antoine wrote: >>> >>> >>> >>>> Thanks Jeff, >>>> >>>> This seems to work with csv file types, and I've been experimenting a >>>> > bit > >>>> with it >>>> >>>> However, when I try to implement this with my original code (with binary >>>> files), I get an error like that one: >>>> >>>> Traceback (most recent call last): >>>> File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> >>>> x,y = map(Lon,Lat) >>>> TypeError: 'numpy.ndarray' object is not callable >>>> >>>> I think this is coming from the fact I use array objects to store >>>> >>>> >>>> >>> values... >>> >>> >>> >>>> could you confirm it? >>>> >>>> >>>> >>>> >>> Antoine: It looks like you the object map is not a Basemap instance, >>> but a numpy array. Try putting 'print type(map)' just ahead of this >>> statement to verify this. I suspect your re-using the name 'map' in your >>> code, overwriting the Basemap class instance. >>> >>> -Jeff >>> >>> >>> >>>> Also, I'll see if it is possible to invert color scale and mask >>>> >>>> >> everything >> >> >>>> under a certain value >>>> >>>> Thanks very much for your help! >>>> >>>> Antoine De Pauw >>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>> photophysics laboratory >>>> Université Libre de Bruxelles - ULB >>>> >>>> >>>> -----Original Message----- >>>> From: Jeff Whitaker [mailto:js...@fa...] >>>> Sent: jeudi 11 septembre 2008 14:10 >>>> To: De Pauw Antoine >>>> Cc: 'Matplotlib Users' >>>> Subject: Re: [Matplotlib-users] Information request >>>> >>>> De Pauw Antoine wrote: >>>> >>>> >>>> >>>> >>>>> Hi Jeff, >>>>> >>>>> I have put the code online with a sample of the data here: >>>>> >>>>> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >>>>> >>>>> I hope you'll be able to give me some advice as it is quite difficult >>>>> >>>>> >> for >> >> >>>>> someone new in python and scientific computation >>>>> >>>>> Antoine De Pauw >>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry >>>>> > and > >>>>> photophysics laboratory >>>>> Université Libre de Bruxelles - ULB >>>>> >>>>> >>>>> >>>>> >>>>> >>>> Antoine: I may have the size of the pixels wrong, and lat/lon >>>> transposed, but this is the general idea: >>>> >>>> from mpl_toolkits.basemap import Basemap >>>> import matplotlib.pyplot as plt >>>> import numpy as np >>>> lats = []; lons = []; data = [] >>>> for line in open('pixels.dat'): >>>> linesplit = line.split(',') >>>> lons.append(float(linesplit[1])) >>>> lats.append(float(linesplit[0])) >>>> data.append(float(linesplit[2])) >>>> map = >>>> Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ >>>> >>>> urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') >>>> x,y = map(lons,lats) >>>> plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) >>>> plt.colorbar(shrink=0.6) >>>> map.drawcoastlines() >>>> plt.show() >>>> >>>> -Jeff >>>> >>>> >>>> >>>> >>>> >>>>> -----Original Message----- >>>>> From: Jeff Whitaker [mailto:Jef...@no...] >>>>> Sent: mercredi 10 septembre 2008 16:45 >>>>> To: Antoine De Pauw >>>>> Cc: Matplotlib Users >>>>> Subject: Re: Information request >>>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> Thanks Jeff, >>>>>> >>>>>> In fact my points are arranged in three unsorted arrays, with a simple >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> scheme (thats why I couldn't plot them with imshow and others) >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> arrays: >>>>>> >>>>>> [lat][lon][val] >>>>>> [-10][ 17][0.3] >>>>>> [ 37][ 23][3.7] >>>>>> ... ... ... >>>>>> >>>>>> and so for many rows... >>>>>> >>>>>> what I have to do is looping through my arrays like that >>>>>> >>>>>> while i < rowcount: >>>>>> plot_to_map(lat[i],lon[i],val[i]) >>>>>> >>>>>> it is evidently an idea of how it could be done easily but my >>>>>> > knowledge > >>>>>> >>>>>> >>>>>> >>>>>> >>>> of >>>> >>>> >>>> >>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> these libraries is too weak for me to figure out how to do it >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> my data comes from huge binary files but is extremely simple, so it >>>>>> >>>>>> >>>>>> >>> would >>> >>> >>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> be really easy for anyone to help me as the problem itself is how to >>>>> > put > >>>>> unsorted points on the map with latitude and longitude coordinates >>>>> >>>>> >>>>> Antoine: You haven't said if your data forms a rectangular array. If >>>>> so, you can build a 2-d array from the input file and plot it with >>>>> imshow. If not, you can still plug the elements into a 2-d masked >>>>> array, leaving the missing pixels masked. You say the points are >>>>> 'unsorted', does that mean they are randomly distributed and do not >>>>> > form > >>>>> >>>>> >> >> >>>>> a rectangular grid? >>>>> >>>>> It would really be much easier to help if you gave us more information, >>>>> > > >>>>> such as how the data is structured, what the pixel footprint is, etc. >>>>> Perhaps you could post the binary file on an ftp site somewhere with >>>>> code to read it. >>>>> >>>>> Also, please hit 'reply all' when replying, so the matplotlib users >>>>> mailing list is CC'ed. >>>>> >>>>> -Jeff >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>> Antoine De Pauw wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Sir, >>>>>>>> >>>>>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> difficult to be understandable. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> All is in the script I gave to you initially, except the point >>>>>>>> >>>>>>>> >> drawing >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> code which would be useless as it is proven not to work (I dont know >>>>> > the > >>>>> method to do it). >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> What I have is a map, and a set of pixels I have to put on it with >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> geographic coordinates. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> I cannot find the right method to put colour pixels on the map, >>>>>>>> >>>>>>>> >> that's >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> the problem. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> I have that map in miller projection, and three arrays containing >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> respectively latitude, longitude and satellite measured value. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> What I need to obtain is something approximately like this: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> >> >>> >>> >>> >>>> >>>> >>>> >>>> >>>>> _00_lr.gif but with the basemap toolkit. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> So, my question is: how could I do to plot a coloured pixel at >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> coordinates lat:lon on that map? If I have just the method to project a >>>>> geographic coordinate on the map and put a coloured pixel at the right >>>>> place, all is done and I just have to loop my arrays... Also, I would >>>>> >>>>> >>>>> >>> have >>> >>> >>> >>>>> to implement some antialiasing on the map. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: >>>>>>> >>>>>>> Are the pixels arranged on a regular grid - or are they randomly >>>>>>> distributed? If they are on a grid, it's easy (using pcolor or >>>>>>> >>>>>>> >>>>>>> >>> imshow). >>> >>> >>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> >>>> >>>> >>>> >>>>>>> If you could send me your data I may be able to get you started. >>>>>>> >>>>>>> (I'm cc'ing the matplotlib list so others can join in the >>>>>>> > discussion). > >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> If this is not possible to do it in a simple and explainable way, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>> please >>>> >>>> >>>> >>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> tell me and I'll continue using matlab or searching for the bit of code >>>>> which will save me >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> Anyway, I have to thank you for your interest to help me.. >>>>>>>> >>>>>>>> Many thanks, >>>>>>>> >>>>>>>> Antoine De Pauw >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Antoine De Pauw wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> Hi, and thanks for the answer >>>>>>>>>> >>>>>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> (Lat,Lon,Val) describing geographic points which are associated by >>>>> > index > >>>>> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> What I need to do is to plot some points on the map (miller >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> projection >>>> >>>> >>>> >>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> for most) based on latitude and longitude, to obtain a colour map >>>>> >>>>> >> (points >> >> >>>>> are unordered, it is from IASI satellite computations) >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> problem I have is any method I try for plotting points is failing, >>>>> >>>>> >> either >> >> >>>>> pcolor, pcolormesh, imshow, etc. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> When I found your post on that mailing list, I figured out that >>>>>>>>>> > you > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> might have the experience and skills to easily explain to me how to >>>>> manipulate these points and plot them on the map, as there's like no >>>>> >>>>> >> help >> >> >>>>> >>>>> >>>>> >>>>> >>>> on >>>> >>>> >>>> >>>> >>>>> the web except standard examples... >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> Please tell me if this is possible for you to give me some tips, >>>>>>>>>> > or > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> if >>>> >>>> >>>> >>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> it takes too much of your time just advice me some lectures >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> Best regards, >>>>>>>>>> >>>>>>>>>> De Pauw Antoine >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> Antoine: It would really help to have a script demonstrating your >>>>>>>>> problem. It sounds to me like you want to plot markers >>>>>>>>> > representing > >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> a >>> >>> >>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> >>>> >>>> >>>> >>>>>>>>> set of points - for that you should use the scatter method. >>>>>>>>> > pcolor, > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> pcolormesh and friends are for plotting gridded data. >>>>>>>>> >>>>>>>>> -Jeff >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> De Pauw Antoine wrote: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>>> Dear sir, >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> the >>>> >>>> >>>> >>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> “Quantum >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> Chemistry and Photophysics” section of the Université >>>>>>>>>>>> > Libre > >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> de >>>> >>>> >>>> >>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>>>>> solution, on an explanation from you here: >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> It seems that you could help me find a solution, as I cannot >>>>>>>>>>>> > plot > >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> any >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> points on maps. >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Could you please tell me what I could do to plot data in a >>>>>>>>>>>> > simple > >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> way, >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> latitude, >>>> >>>> >>>> >>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> longitude and values to plot? >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Some tips would be very nice from you as any method I have tried >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>> so >>> >>> >>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> far >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> give me some errors… >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Thank you very much in advance, >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Best regards, >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> plotting part >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>>>>> >>>>>>>>>>>> from numpy import * >>>>>>>>>>>> >>>>>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>>>>> >>>>>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>>>>> >>>>>>>>>>>> import numpy as np >>>>>>>>>>>> >>>>>>>>>>>> import os >>>>>>>>>>>> >>>>>>>>>>>> import sys >>>>>>>>>>>> >>>>>>>>>>>> import array >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> print('preparing map') >>>>>>>>>>>> >>>>>>>>>>>> map = >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>> >>> >>> >>>> >>>> >>>> >>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>>>>> >>>>>>>>>>>> map.drawmapboundary() >>>>>>>>>>>> >>>>>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>>>>> >>>>>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>>>>> >>>>>>>>>>>> print('reading binary data') >>>>>>>>>>>> >>>>>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>>>>> >>>>>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>>>>> >>>>>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>>>>> >>>>>>>>>>>> Val=zeros(nbreligne) >>>>>>>>>>>> >>>>>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>>>>> >>>>>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>>>>> >>>>>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>>>>> >>>>>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>>>>> >>>>>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>>>>> >>>>>>>>>>>> i=0 >>>>>>>>>>>> >>>>>>>>>>>> while i < nbreligne: >>>>>>>>>>>> >>>>>>>>>>>> if(Lon[i]>180): >>>>>>>>>>>> >>>>>>>>>>>> print(Lon[i]) >>>>>>>>>>>> >>>>>>>>>>>> Lon[i]-=360 >>>>>>>>>>>> >>>>>>>>>>>> print(Lon[i]) >>>>>>>>>>>> >>>>>>>>>>>> i+=1 >>>>>>>>>>>> >>>>>>>>>>>> print('plotting data') >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> #plotting code comes here >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> Antoine: If you send me a self-contained script that produces >>>>>>>>>>> > the > >>>>>>>>>>> >>>>>>>>>>> >> >> >>>>>>>>>>> problem you see, I can help you debug it. As it stands now, I >>>>>>>>>>> >>>>>>>>>>> >> have >> >> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>> very >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> could >>>> >>>> >>>> >>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>> be >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>> your data. >>>>>>>>>>> >>>>>>>>>>> -Jeff >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> print('saving map') >>>>>>>>>>>> >>>>>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>>>>> >>>>>>>>>>>> print('done') >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> *Antoine De Pauw* >>>>>>>>>>>> Collaborateur de recherches, Informatique - Research >>>>>>>>>>>> >>>>>>>>>>>> >> collaborator, >> >> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> IT >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> chemistry >>>> >>>> >>>> >>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> and >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> photophysics laboratory >>>>>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> -- >>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> ... [truncated message content] |
|
From: De P. A. <and...@ul...> - 2008-09-16 06:04:50
|
Jeff, In fact my satellite data is displaying clouds of various gases, and I dont like the fact that "empty" places are left dark blue (I use jet reversed cmap) By masking data under a certain value, I isolate the clouds and then they are in evidence When I use vmin and vmax I'm able to avoid the colormap rescaling and I keep the cloud's original colour, but then it is the colorbar which poses problems, as there's a part of the bar that is useless I guess what I should do is setting a new colorbar myself, but there again, it is not very easy to understand... that kind of libraries are really occult for a non-scientific IT graduate like me Now for the antialiasing and interpolation, the thing I try to do is making it look less pixeled, I don't need all the points to be interpolated, but just make the existing points smoother to have a smooth, quality figure You have helped me a lot, and I know my questions were beginners ones, so I'll understand if you prefer giving some time to something more interesting Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: mardi 16 septembre 2008 13:16 To: De Pauw Antoine Cc: 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Hi Jeff, > > I have played a bit with Matplotlib since last week, and I may still have > some questions for you > > I have masked my value array so it doesn't draw points under a certain > value, but doing this causes the colormap to rescale for the new values > Antoine: Don't quite know what you're trying to accomplish, but you can use the vmin/vmax keywords to imshow, pcolor or scatter to scale the colormap to a certain range. Also, take a look at the image_masked.py example to see how to set the 'over/under' color in a colormap. > I have tried to set a custom colormap but it isn't the thing to do as data > is varying in time > > So is it possible to avoid the colormap to rescale itself? > > Also, I had a look at imshow and the interpolation process is really > interesting for smooth maps.. does a way to interpolate scattered data > exist? > If you have the most recent version of matplotlib you can use the griddata function to interpolate scattered data to a regular grid. -Jeff > The code I use didn't change since last time, all I did is adding a bit, > testing and deleting.. > > Best regards, > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: vendredi 12 septembre 2008 13:26 > To: De Pauw Antoine > Cc: 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Hi Jeff, >> >> I updated my code snippet and uploaded the image I created with a complete >> set of data: >> >> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >> >> And here's the picture generated: >> >> http://www.kirikoo.net/images/5shrad-20080912-105759.png >> >> I now understand the process and I'm able to reproduce it for other >> datasets, but I need to implement some antialiasing for it.. >> >> Is it possible to do? >> >> Many thanks for your precious help! >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: If you do > > >>> from pylab import scatter > >>> help(scatter) > > you will see that scatter takes an antialised keyword > > antialiased Boolean or sequence of booleans > > -Jeff > > >> -----Original Message----- >> From: Jeff Whitaker [mailto:js...@fa...] >> Sent: jeudi 11 septembre 2008 16:48 >> To: De Pauw Antoine >> Cc: 'Matplotlib Users' >> Subject: Re: [Matplotlib-users] Information request >> >> De Pauw Antoine wrote: >> >> >>> Jeff, >>> >>> The map object is from the Basemap type, the only different thing is the >>> Lon,Lat and Val objects which are from the type array instead of lists >>> >>> Anyway, solutions are slowly showing themselves and I thank you all >>> >>> Have a nice day >>> >>> Antoine De Pauw >>> Collaborateur de recherches, Informatique - Research collaborator, IT >>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>> photophysics laboratory >>> Université Libre de Bruxelles - ULB >>> >>> >>> >> Antoine: It should not matter if Lon and Lat are python arrays, lists >> or numpy arrays. The Basemap instance __call__ method handles them all. >> There must be something else going on. It is always better to post >> actual code so we can see what is happening and test it ourselves. >> >> -Jeff >> >> >>> -----Original Message----- >>> From: Jeff Whitaker [mailto:js...@fa...] >>> Sent: jeudi 11 septembre 2008 15:29 >>> To: De Pauw Antoine >>> Cc: 'Matplotlib Users' >>> Subject: Re: [Matplotlib-users] Information request >>> >>> De Pauw Antoine wrote: >>> >>> >>> >>>> Thanks Jeff, >>>> >>>> This seems to work with csv file types, and I've been experimenting a >>>> > bit > >>>> with it >>>> >>>> However, when I try to implement this with my original code (with binary >>>> files), I get an error like that one: >>>> >>>> Traceback (most recent call last): >>>> File "C:\Python25\Projects\FigPlot\FigPlot.py", line 39, in <module> >>>> x,y = map(Lon,Lat) >>>> TypeError: 'numpy.ndarray' object is not callable >>>> >>>> I think this is coming from the fact I use array objects to store >>>> >>>> >>>> >>> values... >>> >>> >>> >>>> could you confirm it? >>>> >>>> >>>> >>>> >>> Antoine: It looks like you the object map is not a Basemap instance, >>> but a numpy array. Try putting 'print type(map)' just ahead of this >>> statement to verify this. I suspect your re-using the name 'map' in your >>> code, overwriting the Basemap class instance. >>> >>> -Jeff >>> >>> >>> >>>> Also, I'll see if it is possible to invert color scale and mask >>>> >>>> >> everything >> >> >>>> under a certain value >>>> >>>> Thanks very much for your help! >>>> >>>> Antoine De Pauw >>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>> photophysics laboratory >>>> Université Libre de Bruxelles - ULB >>>> >>>> >>>> -----Original Message----- >>>> From: Jeff Whitaker [mailto:js...@fa...] >>>> Sent: jeudi 11 septembre 2008 14:10 >>>> To: De Pauw Antoine >>>> Cc: 'Matplotlib Users' >>>> Subject: Re: [Matplotlib-users] Information request >>>> >>>> De Pauw Antoine wrote: >>>> >>>> >>>> >>>> >>>>> Hi Jeff, >>>>> >>>>> I have put the code online with a sample of the data here: >>>>> >>>>> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >>>>> >>>>> I hope you'll be able to give me some advice as it is quite difficult >>>>> >>>>> >> for >> >> >>>>> someone new in python and scientific computation >>>>> >>>>> Antoine De Pauw >>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry >>>>> > and > >>>>> photophysics laboratory >>>>> Université Libre de Bruxelles - ULB >>>>> >>>>> >>>>> >>>>> >>>>> >>>> Antoine: I may have the size of the pixels wrong, and lat/lon >>>> transposed, but this is the general idea: >>>> >>>> from mpl_toolkits.basemap import Basemap >>>> import matplotlib.pyplot as plt >>>> import numpy as np >>>> lats = []; lons = []; data = [] >>>> for line in open('pixels.dat'): >>>> linesplit = line.split(',') >>>> lons.append(float(linesplit[1])) >>>> lats.append(float(linesplit[0])) >>>> data.append(float(linesplit[2])) >>>> map = >>>> Basemap(projection='mill',llcrnrlat=min(lats)-5,urcrnrlat=max(lats)+5,\ >>>> >>>> urcrnrlon=max(lons)+5,llcrnrlon=min(lons)-5,resolution='l') >>>> x,y = map(lons,lats) >>>> plt.scatter(x,y,s=25,c=data,marker='s',edgecolor="None",cmap=plt.cm.jet) >>>> plt.colorbar(shrink=0.6) >>>> map.drawcoastlines() >>>> plt.show() >>>> >>>> -Jeff >>>> >>>> >>>> >>>> >>>> >>>>> -----Original Message----- >>>>> From: Jeff Whitaker [mailto:Jef...@no...] >>>>> Sent: mercredi 10 septembre 2008 16:45 >>>>> To: Antoine De Pauw >>>>> Cc: Matplotlib Users >>>>> Subject: Re: Information request >>>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> Thanks Jeff, >>>>>> >>>>>> In fact my points are arranged in three unsorted arrays, with a simple >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> scheme (thats why I couldn't plot them with imshow and others) >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> arrays: >>>>>> >>>>>> [lat][lon][val] >>>>>> [-10][ 17][0.3] >>>>>> [ 37][ 23][3.7] >>>>>> ... ... ... >>>>>> >>>>>> and so for many rows... >>>>>> >>>>>> what I have to do is looping through my arrays like that >>>>>> >>>>>> while i < rowcount: >>>>>> plot_to_map(lat[i],lon[i],val[i]) >>>>>> >>>>>> it is evidently an idea of how it could be done easily but my >>>>>> > knowledge > >>>>>> >>>>>> >>>>>> >>>>>> >>>> of >>>> >>>> >>>> >>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> these libraries is too weak for me to figure out how to do it >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> my data comes from huge binary files but is extremely simple, so it >>>>>> >>>>>> >>>>>> >>> would >>> >>> >>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>> be really easy for anyone to help me as the problem itself is how to >>>>> > put > >>>>> unsorted points on the map with latitude and longitude coordinates >>>>> >>>>> >>>>> Antoine: You haven't said if your data forms a rectangular array. If >>>>> so, you can build a 2-d array from the input file and plot it with >>>>> imshow. If not, you can still plug the elements into a 2-d masked >>>>> array, leaving the missing pixels masked. You say the points are >>>>> 'unsorted', does that mean they are randomly distributed and do not >>>>> > form > >>>>> >>>>> >> >> >>>>> a rectangular grid? >>>>> >>>>> It would really be much easier to help if you gave us more information, >>>>> > > >>>>> such as how the data is structured, what the pixel footprint is, etc. >>>>> Perhaps you could post the binary file on an ftp site somewhere with >>>>> code to read it. >>>>> >>>>> Also, please hit 'reply all' when replying, so the matplotlib users >>>>> mailing list is CC'ed. >>>>> >>>>> -Jeff >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>> Antoine De Pauw wrote: >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Sir, >>>>>>>> >>>>>>>> I'm sorry, as english is not my mothertongue and it is sometimes >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> difficult to be understandable. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> All is in the script I gave to you initially, except the point >>>>>>>> >>>>>>>> >> drawing >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> code which would be useless as it is proven not to work (I dont know >>>>> > the > >>>>> method to do it). >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> What I have is a map, and a set of pixels I have to put on it with >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> geographic coordinates. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> I cannot find the right method to put colour pixels on the map, >>>>>>>> >>>>>>>> >> that's >> >> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> the problem. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> I have that map in miller projection, and three arrays containing >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> respectively latitude, longitude and satellite measured value. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> What I need to obtain is something approximately like this: >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> > http://www.oma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703 > >> >> >>> >>> >>> >>>> >>>> >>>> >>>> >>>>> _00_lr.gif but with the basemap toolkit. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> So, my question is: how could I do to plot a coloured pixel at >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> coordinates lat:lon on that map? If I have just the method to project a >>>>> geographic coordinate on the map and put a coloured pixel at the right >>>>> place, all is done and I just have to loop my arrays... Also, I would >>>>> >>>>> >>>>> >>> have >>> >>> >>> >>>>> to implement some antialiasing on the map. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> Antoine: >>>>>>> >>>>>>> Are the pixels arranged on a regular grid - or are they randomly >>>>>>> distributed? If they are on a grid, it's easy (using pcolor or >>>>>>> >>>>>>> >>>>>>> >>> imshow). >>> >>> >>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>> >>>> >>>> >>>> >>>>>>> If you could send me your data I may be able to get you started. >>>>>>> >>>>>>> (I'm cc'ing the matplotlib list so others can join in the >>>>>>> > discussion). > >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>>> If this is not possible to do it in a simple and explainable way, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>> please >>>> >>>> >>>> >>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>> tell me and I'll continue using matlab or searching for the bit of code >>>>> which will save me >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>> Anyway, I have to thank you for your interest to help me.. >>>>>>>> >>>>>>>> Many thanks, >>>>>>>> >>>>>>>> Antoine De Pauw >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Antoine De Pauw wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> Hi, and thanks for the answer >>>>>>>>>> >>>>>>>>>> In fact, what I do is reading a binary file to obtain 3 arrays >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> (Lat,Lon,Val) describing geographic points which are associated by >>>>> > index > >>>>> (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> What I need to do is to plot some points on the map (miller >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> projection >>>> >>>> >>>> >>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> for most) based on latitude and longitude, to obtain a colour map >>>>> >>>>> >> (points >> >> >>>>> are unordered, it is from IASI satellite computations) >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> I'm able to create a map, draw simple things on it, etc but the >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> problem I have is any method I try for plotting points is failing, >>>>> >>>>> >> either >> >> >>>>> pcolor, pcolormesh, imshow, etc. >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> When I found your post on that mailing list, I figured out that >>>>>>>>>> > you > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> might have the experience and skills to easily explain to me how to >>>>> manipulate these points and plot them on the map, as there's like no >>>>> >>>>> >> help >> >> >>>>> >>>>> >>>>> >>>>> >>>> on >>>> >>>> >>>> >>>> >>>>> the web except standard examples... >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> Please tell me if this is possible for you to give me some tips, >>>>>>>>>> > or > >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>> if >>>> >>>> >>>> >>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>> it takes too much of your time just advice me some lectures >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>> Best regards, >>>>>>>>>> >>>>>>>>>> De Pauw Antoine >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>> Antoine: It would really help to have a script demonstrating your >>>>>>>>> problem. It sounds to me like you want to plot markers >>>>>>>>> > representing > >>>>>>>>> >>>>>>>>> >>>>>>>>> >>> a >>> >>> >>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>> >>>> >>>> >>>> >>>>>>>>> set of points - for that you should use the scatter method. >>>>>>>>> > pcolor, > >>>>>>>>> >>>>>>>>> >> >> >>>>>>>>> pcolormesh and friends are for plotting gridded data. >>>>>>>>> >>>>>>>>> -Jeff >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> De Pauw Antoine wrote: >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>>> Dear sir, >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> I’m currently trying to improve our plotting tools here at >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> the >>>> >>>> >>>> >>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> “Quantum >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> Chemistry and Photophysics” section of the Université >>>>>>>>>>>> > Libre > >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> de >>>> >>>> >>>> >>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>>>>>> solution, on an explanation from you here: >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> It seems that you could help me find a solution, as I cannot >>>>>>>>>>>> > plot > >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> any >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> points on maps. >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Could you please tell me what I could do to plot data in a >>>>>>>>>>>> > simple > >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> way, >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> assuming I have 3 unordered arrays containing respectively >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> latitude, >>>> >>>> >>>> >>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> longitude and values to plot? >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Some tips would be very nice from you as any method I have tried >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>> so >>> >>> >>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> far >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> give me some errors… >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Thank you very much in advance, >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> Best regards, >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> PS: I give you the code I’m using currently, missing the >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> plotting part >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>>>>>> >>>>>>>>>>>> from numpy import * >>>>>>>>>>>> >>>>>>>>>>>> from scipy.io.numpyio import fread >>>>>>>>>>>> >>>>>>>>>>>> import matplotlib.pyplot as plt >>>>>>>>>>>> >>>>>>>>>>>> import numpy as np >>>>>>>>>>>> >>>>>>>>>>>> import os >>>>>>>>>>>> >>>>>>>>>>>> import sys >>>>>>>>>>>> >>>>>>>>>>>> import array >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> fileName="c:/20080821.b56" >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> print('preparing map') >>>>>>>>>>>> >>>>>>>>>>>> map = >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> > Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) > >> >> >>> >>> >>> >>>> >>>> >>>> >>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>>>>>> >>>>>>>>>>>> map.drawmapboundary() >>>>>>>>>>>> >>>>>>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>>>>>> >>>>>>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>>>>>> >>>>>>>>>>>> print('reading binary data') >>>>>>>>>>>> >>>>>>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>>>>>> >>>>>>>>>>>> Lat=zeros(nbreligne) >>>>>>>>>>>> >>>>>>>>>>>> Lon=zeros(nbreligne) >>>>>>>>>>>> >>>>>>>>>>>> Val=zeros(nbreligne) >>>>>>>>>>>> >>>>>>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>>>>>> >>>>>>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>>>>>> >>>>>>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>>>>>> >>>>>>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>>>>>> >>>>>>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>>>>>> >>>>>>>>>>>> i=0 >>>>>>>>>>>> >>>>>>>>>>>> while i < nbreligne: >>>>>>>>>>>> >>>>>>>>>>>> if(Lon[i]>180): >>>>>>>>>>>> >>>>>>>>>>>> print(Lon[i]) >>>>>>>>>>>> >>>>>>>>>>>> Lon[i]-=360 >>>>>>>>>>>> >>>>>>>>>>>> print(Lon[i]) >>>>>>>>>>>> >>>>>>>>>>>> i+=1 >>>>>>>>>>>> >>>>>>>>>>>> print('plotting data') >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> #plotting code comes here >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> Antoine: If you send me a self-contained script that produces >>>>>>>>>>> > the > >>>>>>>>>>> >>>>>>>>>>> >> >> >>>>>>>>>>> problem you see, I can help you debug it. As it stands now, I >>>>>>>>>>> >>>>>>>>>>> >> have >> >> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>> very >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>> little to work with - it could be your plotting commands, or it >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>> could >>>> >>>> >>>> >>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>> be >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>> your data. >>>>>>>>>>> >>>>>>>>>>> -Jeff >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> print('saving map') >>>>>>>>>>>> >>>>>>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>>>>>> >>>>>>>>>>>> print('done') >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> *Antoine De Pauw* >>>>>>>>>>>> Collaborateur de recherches, Informatique - Research >>>>>>>>>>>> >>>>>>>>>>>> >> collaborator, >> >> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> IT >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>> chemistry >>>> >>>> >>>> >>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>> and >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>>>>>>>> photophysics laboratory >>>>>>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>>>>>> NOAA/OAR/PSD R/PSD1 ... [truncated message content] |
|
From: Eric F. <ef...@ha...> - 2008-09-16 12:58:03
|
De Pauw Antoine wrote: > Jeff, > > In fact my satellite data is displaying clouds of various gases, and I don’t > like the fact that "empty" places are left dark blue (I use jet reversed > cmap) > > By masking data under a certain value, I isolate the clouds and then they > are in evidence > > When I use vmin and vmax I'm able to avoid the colormap rescaling and I keep > the cloud's original colour, but then it is the colorbar which poses > problems, as there's a part of the bar that is useless Can you provide a compact example script, completely self-contained, that illustrates the problem with the colorbar? Perhaps by modifying one of the standard mpl examples, such as image_masked.py? From what you have said, I would expect that some combination of masking, using vmin and vmax, and using the special value colors, would work adequately with the present colorbar. Eric |
|
From: Antoine De P. <and...@ul...> - 2008-09-10 15:01:50
|
in fact the points are not in a rectangular array and pixels are missing, like you said I'll put the code and binary file online tomorrow as I have not access to it today, but reading it is not the problem when read, the values are in three arrays of same size, which I will have to convert to a 2D masked array... we'll see tomorrow if I have succeeded many thanks >Antoine De Pauw wrote: >> Thanks Jeff, >> >> In fact my points are arranged in three unsorted arrays, with a simple scheme (thats why I couldn't plot them with imshow and others) >> >> arrays: >> >> [lat][lon][val] >> [-10][ 17][0.3] >> [ 37][ 23][3.7] >> ... ... ... >> >> and so for many rows... >> >> what I have to do is looping through my arrays like that >> >> while i < rowcount: >> plot_to_map(lat[i],lon[i],val[i]) >> >> it is evidently an idea of how it could be done easily but my knowledge of these libraries is too weak for me to figure out how to do it >> >> my data comes from huge binary files but is extremely simple, so it would be really easy for anyone to help me as the problem itself is how to put unsorted points on the map with latitude and longitude coordinates >> > >Antoine: You haven't said if your data forms a rectangular array. If >so, you can build a 2-d array from the input file and plot it with >imshow. If not, you can still plug the elements into a 2-d masked >array, leaving the missing pixels masked. You say the points are >'unsorted', does that mean they are randomly distributed and do not form >a rectangular grid? > >It would really be much easier to help if you gave us more information, >such as how the data is structured, what the pixel footprint is, etc. >Perhaps you could post the binary file on an ftp site somewhere with >code to read it. > >Also, please hit 'reply all' when replying, so the matplotlib users >mailing list is CC'ed. > >-Jeff >>> Antoine De Pauw wrote: >>>> Sir, >>>> >>>> I'm sorry, as english is not my mothertongue and it is sometimes difficult to be understandable. >>>> >>>> All is in the script I gave to you initially, except the point drawing code which would be useless as it is proven not to work (I dont know the method to do it). >>>> >>>> What I have is a map, and a set of pixels I have to put on it with geographic coordinates. >>>> >>>> I cannot find the right method to put colour pixels on the map, that's the problem. >>>> >>>> I have that map in miller projection, and three arrays containing respectively latitude, longitude and satellite measured value. >>>> >>>> What I need to obtain is something approximately like this: http://wwwoma.be/BIRA-IASB/Molecules/SO2archive/info/background/so2sc200703_00_lr.gif but with the basemap toolkit. >>>> >>>> So, my question is: how could I do to plot a coloured pixel at coordinates lat:lon on that map? If I have just the method to project a geographic coordinate on the map and put a coloured pixel at the right place, all is done and I just have to loop my arrays... Also, I would have to implement some antialiasing on the map. >>>> >>> Antoine: >>> >>> Are the pixels arranged on a regular grid - or are they randomly >>> distributed? If they are on a grid, it's easy (using pcolor or imshow) >>> >>> If you could send me your data I may be able to get you started. >>> >>> (I'm cc'ing the matplotlib list so others can join in the discussion). >>> >>> >>> -Jeff >>>> If this is not possible to do it in a simple and explainable way, please tell me and I'll continue using matlab or searching for the bit of code which will save me >>>> >>>> Anyway, I have to thank you for your interest to help me.. >>>> >>>> Many thanks, >>>> >>>> Antoine De Pauw >>>> >>>> >>>>> Antoine De Pauw wrote: >>>>> >>>>>> Hi, and thanks for the answer >>>>>> >>>>>> In fact, what I do is reading a binary file to obtain 3 arrays (Lat,Lon,Val) describing geographic points which are associated by index (like point 1 is Lat[0]:Lon[0] with value Val[0]) >>>>>> >>>>>> What I need to do is to plot some points on the map (miller projection for most) based on latitude and longitude, to obtain a colour map (points are unordered, it is from IASI satellite computations) >>>>>> >>>>>> I'm able to create a map, draw simple things on it, etc but the problem I have is any method I try for plotting points is failing, either pcolor, pcolormesh, imshow, etc. >>>>>> >>>>>> When I found your post on that mailing list, I figured out that you might have the experience and skills to easily explain to me how to manipulate these points and plot them on the map, as there's like no help on the web except standard examples... >>>>>> >>>>>> Please tell me if this is possible for you to give me some tips, or if it takes too much of your time just advice me some lectures >>>>>> >>>>>> Best regards, >>>>>> >>>>>> De Pauw Antoine >>>>>> >>>>>> >>>>> Antoine: It would really help to have a script demonstrating your >>>>> problem. It sounds to me like you want to plot markers representing a >>>>> set of points - for that you should use the scatter method. pcolor, >>>>> pcolormesh and friends are for plotting gridded data. >>>>> >>>>> -Jeff >>>>> >>>>>> >>>>>> >>>>>>> De Pauw Antoine wrote: >>>>>>> >>>>>>> >>>>>>>> Dear sir, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> I’m currently trying to improve our plotting tools here at the “Quantum >>>>>>>> Chemistry and Photophysics” section of the Université Libre de >>>>>>>> Bruxelles, and I ran, after many time passed at searching for a >>>>>>>> solution, on an explanation from you here: >>>>>>>> http://www.nabble.com/Re:-matplotlib-basemap-question-tt17759370.html >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> It seems that you could help me find a solution, as I cannot plot any >>>>>>>> points on maps. >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Could you please tell me what I could do to plot data in a simple way, >>>>>>>> assuming I have 3 unordered arrays containing respectively latitude, >>>>>>>> longitude and values to plot? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Some tips would be very nice from you as any method I have tried so far >>>>>>>> give me some errors… >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Thank you very much in advance, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Best regards, >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> PS: I give you the code I’m using currently, missing the plotting part >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> from mpl_toolkits.basemap import Basemap >>>>>>>> >>>>>>>> from numpy import * >>>>>>>> >>>>>>>> from scipy.io.numpyio import fread >>>>>>>> >>>>>>>> import matplotlib.pyplot as plt >>>>>>>> >>>>>>>> import numpy as np >>>>>>>> >>>>>>>> import os >>>>>>>> >>>>>>>> import sys >>>>>>>> >>>>>>>> import array >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> fileName="c:/20080821.b56" >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('preparing map') >>>>>>>> >>>>>>>> map = >>>>>>>> Basemap(projection='mill',lat_0=0,lon_0=0,resolution='i',area_thresh=30000.) >>>>>>>> >>>>>>>> map.drawcoastlines(0.5,antialiased=1) >>>>>>>> >>>>>>>> map.drawmapboundary() >>>>>>>> >>>>>>>> #map.drawmeridians(np.arange(-180,180,60),linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,60), labelstyle="+/-") >>>>>>>> >>>>>>>> #map.drawparallels(np.arange(-90,90,30), linewidth=0.5, >>>>>>>> labels=np.arange(-180,180,30), labelstyle="+/-") >>>>>>>> >>>>>>>> print('reading binary data') >>>>>>>> >>>>>>>> nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:])) >>>>>>>> >>>>>>>> Lat=zeros(nbreligne) >>>>>>>> >>>>>>>> Lon=zeros(nbreligne) >>>>>>>> >>>>>>>> Val=zeros(nbreligne) >>>>>>>> >>>>>>>> rawfile=fromfile(open(fileName,'rb'),'d',-1) >>>>>>>> >>>>>>>> Lat=rawfile[0:nbreligne] >>>>>>>> >>>>>>>> Lon=rawfile[nbreligne:nbreligne*2] >>>>>>>> >>>>>>>> Val=rawfile[nbreligne*21:nbreligne*22] >>>>>>>> >>>>>>>> print('shifting latitudes and projecting to map') >>>>>>>> >>>>>>>> i=0 >>>>>>>> >>>>>>>> while i < nbreligne: >>>>>>>> >>>>>>>> if(Lon[i]>180): >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> Lon[i]-=360 >>>>>>>> >>>>>>>> print(Lon[i]) >>>>>>>> >>>>>>>> i+=1 >>>>>>>> >>>>>>>> print('plotting data') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> #plotting code comes here >>>>>>>> >>>>>>>> >>>>>>> Antoine: If you send me a self-contained script that produces the >>>>>>> problem you see, I can help you debug it. As it stands now, I have very >>>>>>> little to work with - it could be your plotting commands, or it could be >>>>>>> your data. >>>>>>> >>>>>>> -Jeff >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> print('saving map') >>>>>>>> >>>>>>>> plt.savefig("testfig.png",dpi=600) >>>>>>>> >>>>>>>> print('done') >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> *Antoine De Pauw* >>>>>>>> Collaborateur de recherches, Informatique - Research collaborator, IT >>>>>>>> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >>>>>>>> photophysics laboratory >>>>>>>> *Université Libre de Bruxelles - ULB <http://ww.ulb.ac.be/>* >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>>>> Meteorologist FAX : (303)497-6449 >>>>>>> NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >>>>>>> 325 Broadway Office : Skaggs Research Cntr 1D-113 >>>>>>> Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>> -- >>>>> Jeffrey S. Whitaker Phone : (303)497-6313 >>>>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>>>> 325 Broadway Boulder, CO, USA 80305-3328 >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>> >>> -- >>> Jeffrey S. Whitaker Phone : (303)497-6313 >>> NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 >>> 325 Broadway Boulder, CO, USA 80305-3328 >>> >>> >>> >> >> > > >-- >Jeffrey S. Whitaker Phone : (303)497-6313 >Meteorologist FAX : (303)497-6449 >NOAA/OAR/PSD R/PSD1 Email : Jef...@no... >325 Broadway Office : Skaggs Research Cntr 1D-113 >Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg > > |
|
From: De P. A. <and...@ul...> - 2008-09-17 01:28:54
|
Eric, I solved the problem by using vmin/vmax, masking and the heat colorbar That choice is then "self-masking" for undesired pixels left after masking and vmin/vmax Now the thing I still have to do is smoothing scattered data, after that I'll implement it with GTK or any other windowing system and when it is finished I'll provide it to the community for example purpose In fact I'm not demanding for code or so, but for method names which could help me do what I need, with code examples for instance The source code is the same as the one posted initially in that mail, except the masked array which is, I think, straightforward for most of you Now I have scattered data on my map, antialiased and so, but it still needs some smoothing as it still looks very pixelated (that is due to the satellite coverage) The image generated is here: http://www.kirikoo.net/images/5shrad-20080917-102544.png Also, I couldn't find any way to reduce the colorbar font size Do you know of any ways to achieve these goals? Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Eric Firing [mailto:ef...@ha...] Sent: mardi 16 septembre 2008 21:58 To: De Pauw Antoine Cc: 'Jeff Whitaker'; 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Jeff, > > In fact my satellite data is displaying clouds of various gases, and I dont > like the fact that "empty" places are left dark blue (I use jet reversed > cmap) > > By masking data under a certain value, I isolate the clouds and then they > are in evidence > > When I use vmin and vmax I'm able to avoid the colormap rescaling and I keep > the cloud's original colour, but then it is the colorbar which poses > problems, as there's a part of the bar that is useless Can you provide a compact example script, completely self-contained, that illustrates the problem with the colorbar? Perhaps by modifying one of the standard mpl examples, such as image_masked.py? From what you have said, I would expect that some combination of masking, using vmin and vmax, and using the special value colors, would work adequately with the present colorbar. Eric |
|
From: John H. <jd...@gm...> - 2008-09-17 04:00:00
|
On Wed, Sep 17, 2008 at 3:28 AM, De Pauw Antoine <and...@ul...> wrote: > The image generated is here: > http://www.kirikoo.net/images/5shrad-20080917-102544.png > > Also, I couldn't find any way to reduce the colorbar font size The colorbar method returns a matplotlib.colorbar.Colorbar instance, which has matplotlib.axes.Axes instance stored as an attribute. Thus you can do: cb = colorbar(something....) for t in cb.get_yticklabels(): t.set_fontsize(10) Eric: when you get some time, could you add docstrings to colorbar which document the publicly accessible attributes? JDH |
|
From: De P. A. <and...@ul...> - 2008-09-17 04:21:27
|
Hi John, I used your example with the missing .ax to modify these font sizes and it works nicely Anyway, by investigation, I found that there is no way of interpolation using scattered data I tried to figure out how to grid my values and use imshow or pcolor, but with no success yet.. Could you explain me how I could do to grid, for example, that data: Lat[] (double array containing latitudes) Lon[] (double array containing longitudes) Val[] (double array containing values) Each of the arrays having the same size, and Val[1] has latitude Lat[1] and longitude Lon[1], and so on, and the coordinates are completely unordered When I try to use griddata and use imshow or pcolor with the output array, my figure is blank A simple example or guideline would do, I guess, as I've already gained a good knowledge of the language Thanks in advance PS: Here's the code snippet: http://snipplr.com/view/8307/map-plotting-python-code-temporary/ Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: John Hunter [mailto:jd...@gm...] Sent: mercredi 17 septembre 2008 13:00 To: De Pauw Antoine Cc: Eric Firing; Jeff Whitaker; Matplotlib Users Subject: Re: [Matplotlib-users] Information request On Wed, Sep 17, 2008 at 3:28 AM, De Pauw Antoine <and...@ul...> wrote: > The image generated is here: > http://www.kirikoo.net/images/5shrad-20080917-102544.png > > Also, I couldn't find any way to reduce the colorbar font size The colorbar method returns a matplotlib.colorbar.Colorbar instance, which has matplotlib.axes.Axes instance stored as an attribute. Thus you can do: cb = colorbar(something....) for t in cb.get_yticklabels(): t.set_fontsize(10) Eric: when you get some time, could you add docstrings to colorbar which document the publicly accessible attributes? JDH |
|
From: Jeff W. <js...@fa...> - 2008-09-17 04:39:50
|
De Pauw Antoine wrote: > Hi John, > > I used your example with the missing .ax to modify these font sizes and it > works nicely > > Anyway, by investigation, I found that there is no way of interpolation > using scattered data > > I tried to figure out how to grid my values and use imshow or pcolor, but > with no success yet.. > > Could you explain me how I could do to grid, for example, that data: > > Lat[] (double array containing latitudes) > Lon[] (double array containing longitudes) > Val[] (double array containing values) > > Each of the arrays having the same size, and Val[1] has latitude Lat[1] and > longitude Lon[1], and so on, and the coordinates are completely unordered > > When I try to use griddata and use imshow or pcolor with the output array, > my figure is blank > > A simple example or guideline would do, I guess, as I've already gained a > good knowledge of the language > > Thanks in advance > > PS: Here's the code snippet: > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: Griddata should work fine. Your code snippet does not try to use griddata, so I can't guess what is wrong. Let me suggest again - please post complete, self-contained examples that demonstrate your problem. Did you look at the griddata_demo.py example? -Jeff > > -----Original Message----- > From: John Hunter [mailto:jd...@gm...] > Sent: mercredi 17 septembre 2008 13:00 > To: De Pauw Antoine > Cc: Eric Firing; Jeff Whitaker; Matplotlib Users > Subject: Re: [Matplotlib-users] Information request > > On Wed, Sep 17, 2008 at 3:28 AM, De Pauw Antoine <and...@ul...> wrote: > > >> The image generated is here: >> http://www.kirikoo.net/images/5shrad-20080917-102544.png >> >> Also, I couldn't find any way to reduce the colorbar font size >> > > The colorbar method returns a matplotlib.colorbar.Colorbar instance, > which has matplotlib.axes.Axes instance stored as an attribute. Thus > you can do: > > cb = colorbar(something....) > > for t in cb.get_yticklabels(): > t.set_fontsize(10) > > Eric: when you get some time, could you add docstrings to colorbar > which document the publicly accessible attributes? > > JDH > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: De P. A. <and...@ul...> - 2008-09-17 04:54:11
|
Jeff, Sorry, I have forgotten to add this piece of code since I'm continually adding/removing bits This code comes instead of the scatter method and colorbar things: xi=np.linspace(-180,180,360) yi=np.linspace(-90,90,180) zi=griddata(Lon,Lat,Val_masked,xi,yi) Is it done the good way? If it is, what's the best method to display it with interpolation? Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: mercredi 17 septembre 2008 13:40 To: De Pauw Antoine Cc: 'John Hunter'; 'Eric Firing'; 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Hi John, > > I used your example with the missing .ax to modify these font sizes and it > works nicely > > Anyway, by investigation, I found that there is no way of interpolation > using scattered data > > I tried to figure out how to grid my values and use imshow or pcolor, but > with no success yet.. > > Could you explain me how I could do to grid, for example, that data: > > Lat[] (double array containing latitudes) > Lon[] (double array containing longitudes) > Val[] (double array containing values) > > Each of the arrays having the same size, and Val[1] has latitude Lat[1] and > longitude Lon[1], and so on, and the coordinates are completely unordered > > When I try to use griddata and use imshow or pcolor with the output array, > my figure is blank > > A simple example or guideline would do, I guess, as I've already gained a > good knowledge of the language > > Thanks in advance > > PS: Here's the code snippet: > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: Griddata should work fine. Your code snippet does not try to use griddata, so I can't guess what is wrong. Let me suggest again - please post complete, self-contained examples that demonstrate your problem. Did you look at the griddata_demo.py example? -Jeff > > -----Original Message----- > From: John Hunter [mailto:jd...@gm...] > Sent: mercredi 17 septembre 2008 13:00 > To: De Pauw Antoine > Cc: Eric Firing; Jeff Whitaker; Matplotlib Users > Subject: Re: [Matplotlib-users] Information request > > On Wed, Sep 17, 2008 at 3:28 AM, De Pauw Antoine <and...@ul...> wrote: > > >> The image generated is here: >> http://www.kirikoo.net/images/5shrad-20080917-102544.png >> >> Also, I couldn't find any way to reduce the colorbar font size >> > > The colorbar method returns a matplotlib.colorbar.Colorbar instance, > which has matplotlib.axes.Axes instance stored as an attribute. Thus > you can do: > > cb = colorbar(something....) > > for t in cb.get_yticklabels(): > t.set_fontsize(10) > > Eric: when you get some time, could you add docstrings to colorbar > which document the publicly accessible attributes? > > JDH > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: De P. A. <and...@ul...> - 2008-09-17 06:15:57
|
Jeff, I finally managed to obtain a neat image with imshow and griddata The code snippet is here: http://snipplr.com/view/8307/map-plotting-python-code-temporary/ The only problem I have is now a grey line surrounding the plot, as you can see in this low-res sample: http://www.kirikoo.net/images/5shrad-20080917-151205.png I have added zero-value points at the corners of the map, thinking that interpolation simply didn't do its job between the points because of a lack of data, but it's still the same The masked array has been replaced with a "replace by zero if superior to -1.2" thing as the border was surrounding masked zone as well Is there a border to imshow? If yes, how to remove it? Also, I tried with aspect='auto' as it seemed to be there for that, but still no progress Thanks for the tips and have a nice evening! Antoine De Pauw Collaborateur de recherches, Informatique - Research collaborator, IT Laboratoire de chimie quantique et photophysique - Quantum chemistry and photophysics laboratory Université Libre de Bruxelles - ULB -----Original Message----- From: Jeff Whitaker [mailto:js...@fa...] Sent: mercredi 17 septembre 2008 13:40 To: De Pauw Antoine Cc: 'John Hunter'; 'Eric Firing'; 'Matplotlib Users' Subject: Re: [Matplotlib-users] Information request De Pauw Antoine wrote: > Hi John, > > I used your example with the missing .ax to modify these font sizes and it > works nicely > > Anyway, by investigation, I found that there is no way of interpolation > using scattered data > > I tried to figure out how to grid my values and use imshow or pcolor, but > with no success yet.. > > Could you explain me how I could do to grid, for example, that data: > > Lat[] (double array containing latitudes) > Lon[] (double array containing longitudes) > Val[] (double array containing values) > > Each of the arrays having the same size, and Val[1] has latitude Lat[1] and > longitude Lon[1], and so on, and the coordinates are completely unordered > > When I try to use griddata and use imshow or pcolor with the output array, > my figure is blank > > A simple example or guideline would do, I guess, as I've already gained a > good knowledge of the language > > Thanks in advance > > PS: Here's the code snippet: > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > Antoine: Griddata should work fine. Your code snippet does not try to use griddata, so I can't guess what is wrong. Let me suggest again - please post complete, self-contained examples that demonstrate your problem. Did you look at the griddata_demo.py example? -Jeff > > -----Original Message----- > From: John Hunter [mailto:jd...@gm...] > Sent: mercredi 17 septembre 2008 13:00 > To: De Pauw Antoine > Cc: Eric Firing; Jeff Whitaker; Matplotlib Users > Subject: Re: [Matplotlib-users] Information request > > On Wed, Sep 17, 2008 at 3:28 AM, De Pauw Antoine <and...@ul...> wrote: > > >> The image generated is here: >> http://www.kirikoo.net/images/5shrad-20080917-102544.png >> >> Also, I couldn't find any way to reduce the colorbar font size >> > > The colorbar method returns a matplotlib.colorbar.Colorbar instance, > which has matplotlib.axes.Axes instance stored as an attribute. Thus > you can do: > > cb = colorbar(something....) > > for t in cb.get_yticklabels(): > t.set_fontsize(10) > > Eric: when you get some time, could you add docstrings to colorbar > which document the publicly accessible attributes? > > JDH > > -- Jeffrey S. Whitaker Phone : (303)497-6313 NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449 325 Broadway Boulder, CO, USA 80305-3328 |
|
From: Jeff W. <js...@fa...> - 2008-09-17 09:09:08
|
De Pauw Antoine wrote: > Jeff, > > I finally managed to obtain a neat image with imshow and griddata > > The code snippet is here: > http://snipplr.com/view/8307/map-plotting-python-code-temporary/ > > The only problem I have is now a grey line surrounding the plot, as you can > see in this low-res sample: > http://www.kirikoo.net/images/5shrad-20080917-151205.png > Antoine: Sorry, but I don't see it. > I have added zero-value points at the corners of the map, thinking that > interpolation simply didn't do its job between the points because of a lack > of data, but it's still the same > > The masked array has been replaced with a "replace by zero if superior to > -1.2" thing as the border was surrounding masked zone as well > > Is there a border to imshow? No. -Jeff > If yes, how to remove it? > > Also, I tried with aspect='auto' as it seemed to be there for that, but > still no progress > > Thanks for the tips and have a nice evening! > > Antoine De Pauw > Collaborateur de recherches, Informatique - Research collaborator, IT > Laboratoire de chimie quantique et photophysique - Quantum chemistry and > photophysics laboratory > Université Libre de Bruxelles - ULB > > > -----Original Message----- > From: Jeff Whitaker [mailto:js...@fa...] > Sent: mercredi 17 septembre 2008 13:40 > To: De Pauw Antoine > Cc: 'John Hunter'; 'Eric Firing'; 'Matplotlib Users' > Subject: Re: [Matplotlib-users] Information request > > De Pauw Antoine wrote: > >> Hi John, >> >> I used your example with the missing .ax to modify these font sizes and it >> works nicely >> >> Anyway, by investigation, I found that there is no way of interpolation >> using scattered data >> >> I tried to figure out how to grid my values and use imshow or pcolor, but >> with no success yet.. >> >> Could you explain me how I could do to grid, for example, that data: >> >> Lat[] (double array containing latitudes) >> Lon[] (double array containing longitudes) >> Val[] (double array containing values) >> >> Each of the arrays having the same size, and Val[1] has latitude Lat[1] >> > and > >> longitude Lon[1], and so on, and the coordinates are completely unordered >> >> When I try to use griddata and use imshow or pcolor with the output array, >> my figure is blank >> >> A simple example or guideline would do, I guess, as I've already gained a >> good knowledge of the language >> >> Thanks in advance >> >> PS: Here's the code snippet: >> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >> >> >> Antoine De Pauw >> Collaborateur de recherches, Informatique - Research collaborator, IT >> Laboratoire de chimie quantique et photophysique - Quantum chemistry and >> photophysics laboratory >> Université Libre de Bruxelles - ULB >> >> > > Antoine: Griddata should work fine. Your code snippet does not try to > use griddata, so I can't guess what is wrong. Let me suggest again - > please post complete, self-contained examples that demonstrate your > problem. > > Did you look at the griddata_demo.py example? > > -Jeff > > >> -----Original Message----- >> From: John Hunter [mailto:jd...@gm...] >> Sent: mercredi 17 septembre 2008 13:00 >> To: De Pauw Antoine >> Cc: Eric Firing; Jeff Whitaker; Matplotlib Users >> Subject: Re: [Matplotlib-users] Information request >> >> On Wed, Sep 17, 2008 at 3:28 AM, De Pauw Antoine <and...@ul...> >> > wrote: > >> >> >>> The image generated is here: >>> http://www.kirikoo.net/images/5shrad-20080917-102544.png >>> >>> Also, I couldn't find any way to reduce the colorbar font size >>> >>> >> The colorbar method returns a matplotlib.colorbar.Colorbar instance, >> which has matplotlib.axes.Axes instance stored as an attribute. Thus >> you can do: >> >> cb = colorbar(something....) >> >> for t in cb.get_yticklabels(): >> t.set_fontsize(10) >> >> Eric: when you get some time, could you add docstrings to colorbar >> which document the publicly accessible attributes? >> >> JDH >> >> >> > > > -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |
|
From: John H. <jd...@gm...> - 2008-09-17 09:44:26
|
On Wed, Sep 17, 2008 at 11:08 AM, Jeff Whitaker <js...@fa...> wrote: > De Pauw Antoine wrote: >> Jeff, >> >> I finally managed to obtain a neat image with imshow and griddata >> >> The code snippet is here: >> http://snipplr.com/view/8307/map-plotting-python-code-temporary/ >> >> The only problem I have is now a grey line surrounding the plot, as you can >> see in this low-res sample: >> http://www.kirikoo.net/images/5shrad-20080917-151205.png >> > > Antoine: Sorry, but I don't see it. There is a very faint horizontal grey line at the top and bottom of the plot, just inside the axes border. I think this is what he is referring to. JDH |