Re: Question on the longitude coordinates transform?

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 28 2011 - 16:54:43 MST

Sorry, a correction to this message:

There is no problem with lonPivot: I was using the wrong value to go from -180-180 to 0-360. I should simply have done:

lon = lonPivot(lon,0)

It works very well.
 -dave

On Nov 28, 2011, at 4:45 PM, David Brown wrote:

> Hi Lin,
> It looks like what you are doing is correct, but if you are passing in the complete global dataset to a plotting routine like 'gsn_csm_contour_map', then you do not need to reorder the data. You just need to express the min/max longitudes in values that work with the map resources. Just add 360 to make the maximum bigger than the minimum (these values do not need to be present in the lon coordinate array):
>
> res@mpMinLonF = 30
> res@mpMaxLonF = -150 + 360
>
> If you are doing a lat/lon projection you also need to set
> mpCenterLonF to a value within the longitude range you are plotting, in your case, between 30 and 210.
>
> It is not really true that lonFlip and lonPivot cannot be used to go from -180-180 to 0-360. I had no problem using lonFlip to do just that. There does seem to be a problem with lonPivot pivoting properly on a lower endpoint of -180:
>
> printVarSummary(lon)
>
> Variable: lon
> Type: float
> Total Size: 512 bytes
> 128 values
> Number of Dimensions: 1
> Dimensions and sizes: [lon | 128]
> Coordinates:
> lon: [-180..177.1875]
> Number Of Attributes: 3
> units : degrees_east
> long_name : longitude
> short_name : lon
>
> lon = lonPivot(lon,-180)
> fatal:Subscript out of range, error in subscript #0
> fatal:An error occurred reading x
> fatal:Execute: Error occurred at or near line 6119 in file $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl
>
> fatal:Execute: Error occurred at or near line 12
>
> -----
> However, I think this may just be a bug, because it is possible to do it in 2 steps as follows:
>
> ncl 14> lon = lonPivot(lon,30)
> ncl 15> lon = lonPivot(lon,360)
> printVarSummary(lon)
> Variable: lon
> Type: float
> Total Size: 512 bytes
> 128 values
> Number of Dimensions: 1
> Dimensions and sizes: [lon | 128]
> Coordinates:
> lon: [ 0..357.1875]
> Number Of Attributes: 4
> units : degrees_east
> long_name : longitude
> short_name : lon
> lonPivot : reordered via lonPivot [NCL]: pivotLon=360
>
> Note that the coordinate variable (lon&lon) will be adjusted to be monotonically increasing, but the variable itself (lon) does not get the adjustment (because lonPivot is thinking of it as the data)
>
> print(lon(127))
>
>
> Variable: lon (subsection)
> Type: float
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> Number Of Attributes: 5
> lon : 357.1875
> lonPivot : reordered via lonPivot [NCL]: pivotLon=360
> short_name : lon
> long_name : longitude
> units : degrees_east
> (0) -2.8125
>
> If you ever use lonFlip or lonPivot on coordinate variables you should be aware of this fact. A simple assignment would take care of the problem;
>
> lon = (/lon&lon/)
>
> Hope this helps.
> -dave
>
>
>
>
>
> On Nov 26, 2011, at 8:44 PM, xiang lin wrote:
>
>> I resolve the problem using the following scripts. Anyone can take a look at it?
>>
>> 23 data = asciiread("/Work/smi/Hadslp2_185001-200412.dat",-1,"float")
>> 24 x = onedtond(data,(/72,37,12,155/))
>> 25 x!0 = "lon"
>> 26 x!1 = "lat"
>> 27 x!2 = "month"
>> 28 x!3 = "year"
>> 29 x&lon = fspan(-180.,175.,72) ; see more details in the hadslpr2's data read instruction
>> 30 x&lon@units = "degree_east"
>> 31 x&lat = fspan(90.,-90.,37)
>> 32 x&lat@units = "degree_north"
>> 33 x&month = ispan(1,12,1)
>> 34 x&year = ispan(1850,2004,1)
>> 35 printVarSummary(x)
>> 36 ; Longitude coordinates transform
>> 37 xx = x
>> 38 xx(0:35,:,:,:) = x(36:71,:,:,:)
>> 39 xx(36:71,:,:,:) = x(0:35,:,:,:)
>> 40 xx&lon = fspan(0.,355.,72)
>> 41 xx&lon@units = "degree_east"
>> 42 printVarSummary(xx)
>>
>>
>>
>>
>> 2011/11/25 xiang lin <leo.aries.g@gmail.com>
>> Thanks for the reply!
>>
>> However, I guess you didn't understand my problem. I want to draw the plot in the region of (30E, 150W),
>> the west boundary locate at the 30E and the east boundary is at 150W. If I just set the resource as below:
>> res@mpMinLonF = -150
>> res@mpMaxLonF = 30
>> then what I got is opposite to what I want.
>>
>> The lonFlip or lonPivot function can transform the coordinates of (0E,360E) to (-180E,180E), and what I want
>> to do is just the reverse.
>>
>> Thanks!
>>
>>
>> Lin
>>
>>
>>
>>
>>
>> 2011/11/25 Dennis Shea <shea@ucar.edu>
>> PLEASE ... do *not* repeat post to ncl-talk.
>> This is a 4-day national holiday.
>>
>> You have your settings incorrect. They are reversed
>>
>> res@mpMinLonF = -150
>> res@mpMaxLonF = 30
>>
>>
>> On 11/24/11 9:54 AM, xiang lin wrote:
>> Hi,all
>>
>> I am fluent with the longitude coordinates of (0E, 360E), but now
>> was a little puzzled when dealing with the coordinates of (-180E,175E) .
>>
>> Here below is parts of my scripts :
>>
>> ; read the hadslp data
>> data = asciiread("/Work/smi/Hadslp2_185001-200412.dat",-1,"float")
>> x = onedtond(data,(/72,37,12,155/))
>> x!0 = "lon"
>> x!1 = "lat"
>> x!2 = "month"
>> x!3 = "year"
>> x&lon = fspan(-180.,175.,72) ; see more details in the
>> hadslpr2's data read instruction
>> x&lon@units = "degrees_east"
>> x&lat = fspan(90.,-90.,37)
>> x&lat@units = "degree_north"
>> x&month = ispan(1,12,1)
>> x&year = ispan(1850,2004,1)
>> printVarSummary(x)
>> ......
>> res@mpMinLonF = 30
>> res@mpMaxLonF = -150
>>
>> I want to pick out the sub-region eastward extending from 30E to 150W,
>> but of course the above resource would cause errors for the reason that
>> mpMinLonF must be less than
>> mpMaxLonF.
>>
>> How could I set the region correctly for plot? Is there a way to
>> transform the coordinates such as (-180E, 175E) to the ones such as
>> (0E,360E)? I know the lonFlip and lonPivot,
>> However, I don't find a corresponding function to the opposite job.
>>
>> Thanks!
>>
>> best wish!
>>
>>
>> Lin
>>
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Nov 28 16:54:50 2011

This archive was generated by hypermail 2.1.8 : Wed Nov 30 2011 - 19:52:47 MST