Re: How to access right lon, lat information of curvilinear grids?

From: Mario Krapp <mario.krapp_at_nyahnyahspammersnyahnyah>
Date: Thu, 11 Jun 2009 09:56:10 +0200

Hi Dave,

you are absolutely right, ncdump -h gives:

float lon(y, x) ;
...
float lat(y, x) ;
...
float var2(time, lev, y, x) ;
     var2:coordinates = "lon lat" ;

So the netCDF standard is followed within my data at least regarding the grid description.

Also helpful is the shape method for arrays.
> print temp.shape
> print lon.shape
> print lat.shape

I figured out that I have to use the *same* dimension for the lon, lat as for the variable to plot.
Because in the plot command I used
---cut---
velres.vfXArray = lon[:,:]
velres.vfYArray = lat[:,:]
vc = Ngl.vector_map(wks,uvel[0,0,::-inc,::inc],vvel[0,0,::-inc,::inc],velres)
---cut---

for plotting the vectors lighter distributed but it has to be:
---cut---
velres.vfXArray = lon[::-inc,::inc]
velres.vfYArray = lat[::-inc,::inc]
---cut---

So everything is fine except this warning
warning:tmEqualizeXYSizes is not a valid resource in vector.PlotManager at this time
or
warning:tmEqualizeXYSizes is not a valid resource in contour.PlotManager at this time

So thank you both, Mary and Dave

Mario

David Brown wrote:
> Hi Mario,
>
> I will just add that from your description the NetCDF file you are using
> does not appear to follow the usual NetCDF conventions. If you have
> dimensions named "lat" and "lon" and coordinate variables also named
> "lat" and "lon", then the coordinate variables should be 1D and also
> have dimensions named "lat" and "lon". The usual way to specify 2D
> coordinate variables is for the dimensions of the data variable and the
> coordinate variables by named something like "x" and "y". You would have:
>
> temp(time,lev,y,x) along with
> lat(y,x) and
> lon(y,x)
>
>
> This would guarantee the correct dimensionality for the coordinates.
> However, it is also possible that the coordinates specify cell edges
> rather than cell centers. In this case the coordinate should have 1 more
> element along each horizontal axis than the data variable. This should
> also work using the sfXArray and sfYArray resources.
>
> It seems that there must be some other difference in the size of the
> coordinates vs the size of the data variable. If this is the case
> converting the data to 1D using the ravel method will not help. If it is
> not the case then we should know about it.
> -dave
>
>
> On Jun 10, 2009, at 10:31 AM, Mary Haley wrote:
>
>>
>> Hi Mario,
>>
>> This should work, if lat, lon are the same size as the rightmost two
>> dimensions of temp.
>>
>> What does:
>>
>> print temp.shape
>> print lon.shape
>> print lat.shape
>>
>> report?
>>
>> Also, you might try:
>>
>> tempres.trGridType = "TriangularMesh"
>>
>> Finally, and I'm not sure why this would make a different (Dave Brown
>> might be able to elaborate), you can try this:
>>
>> temp = numpy.ravel(ncfile_sst.variables["var2"])
>> lon = numpy.ravel(ncfile_vel.variables["lon"])
>> lat = numpy.ravel(ncfile_vel.variables["lat"])
>>
>> and keep everything else the same. This will force the contouring
>> algorithm to use the triangular mesh internally, but I'm not sure
>> if it will be appropriate for your data.
>>
>> See the attached "seam.py" for a similar example.
>>
>> --Mary
>>
>>
>> On Wed, 10 Jun 2009, Mario Krapp wrote:
>>
>>> Hi,
>>>
>>> I could not find out, how to make a contour_map/vector_map plot with
>>> data on a curvilinear grid.
>>> The data I wanted to plot is the scalar temp(time,lev,lon,lat)
>>> I read the data as follows:
>>> ---cut---
>>> ncfile_sst = Nio.open_file("sst.elnino3.nc","r")
>>> temp = ncfile_sst.variables["var2"]
>>> lon = ncfile_vel.variables["lon"]
>>> lat = ncfile_vel.variables["lat"]
>>> ---cut---
>>> while lon = lon(x,y) and lat = lat(x,y) are 2D arrays
>>>
>>> I tried using
>>> ---cut---
>>> tempres.sfXArray = lon[:,:]
>>> tempres.sfYArray = lat[:,:]
>>> ...
>>> co = Ngl.contour_map(wks,temp[0,0,:,:],tempres)
>>> ---cut---
>>>
>>> but I get this error message:
>>> warning:ScalarFieldInitialize: 2d coordinate array sfXArray has an
>>> incorrect dimension size: defaulting sfXArray
>>> warning:ScalarFieldInitialize: 2d coordinate array sfYArray has an
>>> incorrect dimension size: defaulting sfYArray
>>>
>>> This data is plotted on the map, but the locations correspond to the
>>> x-y coordinates temp(x,y) instead of temp(lon,lat).
>>>
>>> Cheers Mario
>>> _______________________________________________
>>> pyngl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk<seam.py>
>> _______________________________________________
>> pyngl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
>

-- 
Mario Krapp
Max Planck Institute for Meteorology
Bundesstra├če 53
20146 Hamburg
Germany
tel. +49 40 41173 168
email mario.krapp_at_zmaw.de
www http://www.mpimet.mpg.de
_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Thu Jun 11 2009 - 01:56:10 MDT

This archive was generated by hypermail 2.2.0 : Tue Jun 16 2009 - 10:06:42 MDT