[ncl-talk] FW: changing tick marks
Mary Haley
haley at ucar.edu
Wed Jul 30 09:22:49 MDT 2014
Michael,
Thanks for including the script and data offline.
It turns out that you *do* have coordinate arrays attached to your original
data, but they were getting stripped off when you did the variables. To
see the coordinate arrays, do a "printVarSummary" on the "tho" variable,
for example:
Variable: tho
Type: float
Total Size: 409920 bytes
102480 values
Number of Dimensions: 4
Dimensions and sizes: [time | 1] x [depth | 20] x [lat | 122] x [lon | 42]
Coordinates:
time: [8760..8760]
depth: [ 7..2435]
lat: [45.375..-45.375]
lon: [-51.375..-20.625]
Number Of Attributes: 6
standard_name : sea_water_potential_temperature
long_name : Sea water potential temperature
units : C
code : 2
_FillValue : -9e+33
missing_value : -9e+33
Note the list of variables under the "Coordinates:" section. These
variables are called "coordinate arrays", and make it easier to plot your
data.
However, when you do calculations on these variables, like:
Tavg = dim_avg_n(tho,0)
this causes all the metadata to be stripped off, and thus "Tavg" will have
no metadata. This makes plotting "Tavg" over a map difficult.
Fortunately, we have versions of these functions that will reattach the
metadata for you:
Tavg = dim_avg_n_Wrap(tho,0) ; Use "_Wrap" to maintain metadata
Now, when you do a "printVarSummary(tavg)", you will see that "tavg" also
has metadata:
Variable: Tavg
Type: float
Total Size: 409920 bytes
102480 values
Number of Dimensions: 3
Dimensions and sizes: [depth | 20] x [lat | 122] x [lon | 42]
Coordinates:
depth: [ 7..2435]
lat: [45.375..-45.375]
lon: [-51.375..-20.625]
Number Of Attributes: 7
_FillValue : -9e+33
standard_name : sea_water_potential_temperature
long_name : Sea water potential temperature
units : C
code : 2
missing_value : -9e+33
average_op_ncl : dim_avg_n over dimension(s): time
One other issue is that your "pot" variable has coordinate arrays, but the
"lon" values go from 308 to 342. I had to subtract 360 from your longitude
values so that it would plot correctly.
I cleaned up your script quite a bit, but I'm not sure the plot is correct.
I will send you the script and image offline, since I'm not sure you want
to share it with ncl-talk.
--Mary
On Tue, Jul 29, 2014 at 9:18 AM, Hemming, Michael <
michael.hemming at mpimet.mpg.de> wrote:
>
> Here is my code, I have attached some data, thanks for your help! This
> is only 1 year of the data as the file size was too large.
>
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>
> data12 = addfile ("
> sector_icon_lr_12_mpiom_tho_ym_0000-0099.nc", "r")
> tho = data12->tho
> noshupw = addfile ("con.ym.atlbox.nosh.upw.100y.nc", "r")
> potT = noshupw->t_acc
>
>
> ;----------Surface plot MPIOM
>
>
> wks = gsn_open_wks("pdf", "T_Surface_MPIOM")
> gsn_define_colormap(wks,"gui_default")
>
> res = True
> res at tiMainString = "Surface T averaged for years 01-99"
> res at gsnSpreadColors = True
> res at pmLegendDisplayMode = False
> res at cnFillOn = True
>
>
>
> Tavg = dim_avg_n(tho,0)
>
> ;plot = gsn_csm_contour(wks,Tavg(1,:,:),res)
>
> ;----------Surface plot ICON
>
> ; Does not work when including all the other plot code....try in new file
> and works fine (e.g. tester, copy data and plot code parts)
>
> wks = gsn_open_wks("x11", "T_Surface_ICON")
> gsn_define_colormap(wks,"gui_default")
>
> res = True
> res at tiMainString = "Surface T averaged for years 01-99 (ICON)"
> res at gsnSpreadColors = True
> res at pmLegendDisplayMode = False
> res at cnFillOn = True
>
>
>
> potTavg = dim_avg_n(potT,0)
>
> ;plot = gsn_csm_contour(wks,potTavg(1,:,:),res)
>
>
>
> ;----------MPIOM vs. ICON comparison plots
>
>
>
> wks = gsn_open_wks("pdf","MPIOM_vs_ICON_panelplot_surface")
>
> gsn_define_colormap(wks,"gui_default")
>
>
> plot1 = new(2,graphic)
>
> res at gsnDraw = False ; don't draw
> res at gsnFrame = False ; don't
> advance frame
> resP = True
> res at tiYAxisString = "Latitude"
> res at tiXAxisString = "Longitude"
> resP at txString = "Surface T averaged for years 01-99"
> res at lbOrientation = "vertical" ; vertical label bar
>
> res at trXMinF = 0 ; set minimum X-axis
> value
> res at trXMaxF = 40 ; set maximum X-axis
> value
> res at trYMinF = 0 ; set minimum Y-axis
> value
> res at trYMaxF = 120 ; set maximum Y-axis
> value
> res at tiMainString = "MPIOM exp 12"
>
>
> plot1(0) = gsn_csm_contour_map(wks,Tavg(1,:,:),res)
>
>
>
> res at tiMainString = "ICON NOSH.UPW"
>
> ;res at tmXBMode = "Explicit"
> ;res at tmXBValues = (/-44.5,-27.5,-5.5,14.5,34.5/)
> ;res at tmXBLabels = "" + res at tmXBValues
> ;res at tmXBMinorValues = ispan(0,30,1)
>
>
>
>
> plot1(1) = gsn_csm_contour_map(wks,potTavg(1,:,:),res)
>
>
> gsn_panel(wks,plot1,(/1,2/),resP)
> ------------------------------
> *From:* Mary Haley [haley at ucar.edu]
> *Sent:* 29 July 2014 05:46
> *To:* Hemming, Michael
> *Cc:* ncl-talk at ucar.edu
> *Subject:* Re: [ncl-talk] changing tick marks
>
> Hi Michael,
>
> It looks like you have a curvilinear grid. The information I gave you
> was assuming you had a rectilinear grid, which means your data contains 1D
> lat/lon coordinate arrays attached to it.
>
> With a curvilinear grid, you have to read the 2D lat/lon coordinate
> values off the file separately and attach them to your data.
>
> Can you do a "printVarSummary" on the two variables you are trying to
> plot, so I can see what kind of metadata they have:
>
> printVarSummary(potTavg)
> printVarsummary(Tavg)
>
> This will help me determine what kind of grid you have, and hopefully
> what the lat/lon arrays associated with it are.
>
> Better yet, if you can provide me with your full script and data (you
> can do this offline), then I can probably quickly provide you with an NCL
> script that will plot it.
>
> Thanks,
>
> --Mary
>
>
> On Mon, Jul 28, 2014 at 1:14 AM, Michael Hemming <
> michael.hemming at mpimet.mpg.de> wrote:
>
>> Hi Mary,
>>
>> Thanks for replying but it doesn't seem to work, it complains:
>>
>> 'check_for_y_lat_coord: Warning: data does not contain a valid latitude
>> coordinate array or doesn't contain one at all..'
>>
>> and the same for the lon_coord
>>
>> I'm confused as Ferret plots the data with the correct lat and lon.
>>
>> Is there something else I am missing? the only thing I changed within the
>> code was the removal of the two lines you stated below and the addition of
>> '_map' to the gsn command.
>>
>> thanks,
>> Michael
>>
>>
>> On 27/07/2014 19:48, Mary Haley wrote:
>>
>> Hi Michael,
>>
>> Part of the problem is that you've set the minimum of your X axis (the
>> longitude axis to 0):
>>
>> res at trXMinF = 0 ; set minimum X-axis
>> value
>> res at trXMaxF = 30 ; set maximum X-axis
>> value
>>
>> This is causing your longitudes to only go from 0 to 30, and hence you
>> are not going to see any labels or tickmarks at negative longitude values.
>>
>> I suggest not setting the tr*M**F resources at all, unless you need to
>> zoom in on the plot for some reason.
>>
>> Also, if you are indeed plotting lat/lon data, you should be calling
>> "gsn_csm_contour_map" and not "gsn_csm_contour". The former will put draw
>> contours over a map, whereas the latter only draws a contour plot. For
>> examples of using gsn_csm_contour_map, see:
>>
>> http://www.ncl.ucar.edu/Applications/cylineq.shtml
>>
>> Note that some of these examples are using "gsn_csm_contour_map_ce",
>> which is the same thing. gsn_csm_contour_map will draw a cylindrical
>> equidistant map plot by default, unless you change the map projection.
>>
>> --Mary
>>
>>
>>
>> On Sat, Jul 26, 2014 at 7:44 AM, Hemming, Michael <
>> michael.hemming at mpimet.mpg.de> wrote:
>>
>>> Hey everyone,
>>>
>>> I am having trouble understanding how to alter tickmarks on a contour
>>> plot. I want to change my index numbers on the x and y axis to lat and lon
>>> values. I have been trying to use the example given here:
>>> http://www.ncl.ucar.edu/Applications/Scripts/tm_2.ncl
>>>
>>> Here is my code ( I have only tried altering the second plot out of the
>>> 2 e.g. for plot1(1)..):
>>>
>>> ;----------MPIOM vs. ICON comparison plots
>>>
>>>
>>>
>>> wks = gsn_open_wks("x11","MPIOM_vs_ICON_panelplot_surface")
>>> gsn_define_colormap(wks,"gui_default")
>>>
>>>
>>> plot1 = new(2,graphic)
>>>
>>> res at gsnDraw = False ; don't draw
>>> res at gsnFrame = False ; don't
>>> advance frame
>>> resP = True
>>> res at tiYAxisString = "Latitude"
>>> res at tiXAxisString = "Longitude"
>>> resP at txString = "Surface T averaged for years 01-99"
>>> res at lbOrientation = "vertical" ; vertical label
>>> bar
>>>
>>> res at trXMinF = 0 ; set minimum
>>> X-axis value
>>> res at trXMaxF = 40 ; set maximum
>>> X-axis value
>>> res at trYMinF = 0 ; set minimum Y-axis
>>> value
>>> res at trYMaxF = 120 ; set maximum
>>> Y-axis value
>>> res at tiMainString = "MPIOM exp 12"
>>>
>>>
>>> plot1(0) = gsn_csm_contour(wks,Tavg(1,:,:),res)
>>>
>>>
>>> res at trXMinF = 0 ; set minimum X-axis
>>> value
>>> res at trXMaxF = 30 ; set maximum X-axis
>>> value
>>> res at trYMinF = 0 ; set minimum Y-axis
>>> value
>>> res at trYMaxF = 80 ; set maximum
>>> Y-axis value
>>> res at tiMainString = "ICON NOSH.UPW"
>>>
>>> res at tmXBMode = "Explicit"
>>> res at tmXBValues = (/-44.5,-27.5,-5.5,14.5,34.5/)
>>> res at tmXBLabels = "" + res at tmXBValues
>>> res at tmXBMinorValues = ispan(0,30,1)
>>>
>>>
>>>
>>>
>>> plot1(1) = gsn_csm_contour(wks,potTavg(1,:,:),res)
>>>
>>>
>>> gsn_panel(wks,plot1,(/1,2/),resP)
>>>
>>>
>>> I want longitude from -44.5 E to 34.5 W, once I know how to do it for
>>> longitude, I can then apply the code to the lat.
>>>
>>> thanks in advance!
>>>
>>> Michael
>>>
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140730/86e95350/attachment.html
More information about the ncl-talk
mailing list