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

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Wed, 10 Jun 2009 11:39:03 -0600

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

_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Wed Jun 10 2009 - 11:39:03 MDT

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