<div dir="ltr"><div>Mary and Dennis,<br></div><div><br></div><div>Mary showed several advantages of the use of the lat2d/lon2d special attributes for 2-D coordinates. I would like to retract my suggestion for changing existing examples.</div><div><br></div><div>It seems to me that it is best to use <span style="font-size:14px">sfXArray and </span><span style="font-size:14px">sfYArray attributes only in special cases when </span>lat2d and lon2d are not sufficient. Also, lat2d and lon2d seem more understandable to me. Perhaps the decision process for which method could be enhanced on the "Overlaying data" documentation page:</div><div><br></div><div><a href="http://www.ncl.ucar.edu/Document/Graphics/overlays_on_map.shtml" target="_blank">http://www.ncl.ucar.edu/Document/Graphics/overlays_on_map.shtml</a><br></div><div><br></div><div>Dennis mentioned a performance problem: "Each variable having an associated @lat2d, @lon2d takes up memory." Technically, I agree. However, modern workstations have many Gbytes of RAM, so carrying around a few extra medium size 2-D arrays is not noticeable unless you are repeating full variable assignments within major processing loops. So I think this is not a significant problem for retaining lat2d/lon2d.</div><div><br></div><div>--Dave</div><div><br></div><div><br></div><div class="gmail_extra"><div class="gmail_quote">On Fri, Sep 11, 2015 at 11:15 AM, Mary Haley <span dir="ltr"><<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-size:small">Hi Dave,</div><div style="font-size:small"><br>I'm a bit torn about what to do with the examples, because ideally, we (NCL) would come up with a way to represent all types of "coordinate values" (true 1D coordinate arrays, 2D coordinate arrays, 1D arrays for "random" arrays, and something else for unstructured grids, like hexagonal or triangular meshes) through the NCL variable model. We've always tried to model the NetCDF way of handling these variables, and it doesn't yet have a way to recognize all types of coordinates.<br></div><div style="font-size:small"><br></div><div style="font-size:small">We have kept the use of lat2d/lon2d attributes in the examples partly because we have advertised them for so long. Because of our strict backwards compatibility rule, we hope to always support this feature unless it becomes unreasonable to do so (which I don't foresee).</div><div style="font-size:small"><br></div><div style="font-size:small">We also use this method in our ESMF regridding, because it's the only way to "sneak" in these special coordinate arrays to the "ESMF_regrid" routine. ESMF_regrid will look for "lat2d/lon2d" attached to the variable, and it will also return lat2d/lon2d if regridding to a curvilinear grid. The same is true for "lon1d/lat1d", which is a quick-and-dirty way to pass in 1D arrays of lat/lon for a 1D variable that is potentially "random".<br></div><div style="font-size:small"><br></div><div style="font-size:small">There's one minor correction to what Dennis said about using one method over the other for plotting: if you have lat2d/lon2d attributes attached to your data when plotting, and you set res@gsnAddCyclic = True, then the gsn_csm_xxxx plotting routines will know how to properly add the cyclic point. However, if you use sfXArray and sfYArray resources, gsnAddCyclic doesn't know anything about these. </div><div style="font-size:small"><br></div><div style="font-size:small">We have it on our list to modernize many of our aging NCL scripts, and we will add more examples that show the two ways of doing things.</div><div style="font-size:small"><br></div><div style="font-size:small">--Mary</div><div style="font-size:small"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 28, 2015 at 4:15 PM, Dave Allured - NOAA Affiliate <span dir="ltr"><<a href="mailto:dave.allured@noaa.gov" target="_blank">dave.allured@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Dennis,<div><br></div><div>Thank you for the information about preferred resources <span style="font-size:14px">sfXArray and </span><span style="font-size:14px">sfYArray for 2-D coordinates, and the reason why this is optimal. I learned something new here.</span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">Several NCL examples and at least one documentation page are advocating the less optimal method using lat2d and lon2d attributes. Perhaps these examples and pages could eventually be updated to use </span><span style="font-size:14px">sfXArray and </span><span style="font-size:14px">sfYArray instead.</span></div><span><font color="#888888"><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">--Dave</span></div></font></span><div><div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 28, 2015 at 3:54 PM, Dennis Shea <span dir="ltr"><<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Will's suggestion is correct.<br>
<br>
-----<br>
<br>
FYI: The ***only*** time you should assign the reserved attributes:<br>
@lat2d, @lon2d is for plotting.<br>
<br>
In fact, the NCL-team would prefer that people use the following<br>
rather than the reserved attributes.<br>
<br>
res@sfXArraya = lon2d<br>
res@sfYArray = lat2d<br>
res@trGridType = "TriangularMesh"<br>
<br>
---<br>
<br>
Each variable having an associated @lat2d, @lon2d takes up memory.<br>
If 5 variables a, a@lat2d, a@lon2d, ... b, c, d, e then each will<br>
require the necessary memory.<br>
Firther, if you write to netCDF via<br>
<br>
fnc->A = a<br>
fnc->B = b<br>
fnc->C = c<br>
fnc->D = d<br>
fnc->E = e<br>
<br>
Then the lat2d/lon2d arrays will be written 5 times (one for each variable).<br>
<br>
fnc->LAT2D = lat2d<br>
fnc->LON2D = lon2d<br>
<br>
Will write each variable only once!<br>
<br>
Cheers<br><br>
<br>
On Fri, Aug 28, 2015 at 3:38 PM, Will Hobbs <<a href="mailto:Will.Hobbs@utas.edu.au" target="_blank">Will.Hobbs@utas.edu.au</a>> wrote:<br>
> Mira<br>
><br>
> To keep all the attributes from 'sf'....<br>
><br>
>> sf_total = sf(0,:,:) ;sf_total is now a 2-da array with all the<br>
>>attributes and rightmost dimensions of sf<br>
>> sf_total = dim_sum_n(sf,0)<br>
><br>
> Will<br>
><br>
><br>
> On 29/08/15 5:26 AM, "<a href="mailto:mberdahl@envsci.rutgers.edu" target="_blank">mberdahl@envsci.rutgers.edu</a>"<br>
> <<a href="mailto:mberdahl@envsci.rutgers.edu" target="_blank">mberdahl@envsci.rutgers.edu</a>> wrote:<br>
><br>
>>Excellent, this worked! Thank you!<br>
>>I just have a quick follow-up question. Once I assign the lat and lon to<br>
>>my variables (for example: sf@lon2d = lon2d, sf@lat2d = lat2d), and then<br>
>>I would like to do a calculation with sf (eg. sf_total = dim_sum_n(sf,0)),<br>
>>it seems I have to assign the the new variable the lat and lon again. Is<br>
>>there a way to keep the lat and lon following through the calculations<br>
>>without always reassigning them?<br>
>>I hope that makes sense.<br>
>>Thanks,<br>
>>Mira<br>
>><br>
>><br>
>>> Here is more information about dat with 2-D coordinates. I was typing<br>
>>> this<br>
>>> up when I saw Will's reply. Some of the other examples indicate<br>
>>> that trGridTrype may not be needed with some data sets.<br>
>>><br>
>>> Please see section #2 on this documentation page, for a basic<br>
>>>description.<br>
>>> Notice the several different working examples:<br>
>>> <a href="https://www.ncl.ucar.edu/Document/Graphics/overlays_on_map.shtml" rel="noreferrer" target="_blank">https://www.ncl.ucar.edu/Document/Graphics/overlays_on_map.shtml</a><br>
>>><br>
>>> (Please ignore the link "2D vertical coordinates", that is not about<br>
>>> geographic surface maps, and can be confusing.)<br>
>>><br>
>>> The simplest example for making map plots with 2-D coordinates is<br>
>>>example<br>
>>> 3<br>
>>> on this page:<br>
>>> <a href="https://www.ncl.ucar.edu/Applications/ice.shtml" rel="noreferrer" target="_blank">https://www.ncl.ucar.edu/Applications/ice.shtml</a><br>
>>><br>
>>> I also like NARR example 4 because it shows how the 2-D coordinate<br>
>>>method<br>
>>> can be used with different map projections:<br>
>>> <a href="http://www.ncl.ucar.edu/Applications/narr.shtml" rel="noreferrer" target="_blank">http://www.ncl.ucar.edu/Applications/narr.shtml</a><br>
>>><br>
>>> --Dave<br>
>>><br>
>>><br>
>>> On Thu, Aug 27, 2015 at 9:35 PM, Will Hobbs <<a href="mailto:Will.Hobbs@utas.edu.au" target="_blank">Will.Hobbs@utas.edu.au</a>><br>
>>> wrote:<br>
>>><br>
>>>> Mira<br>
>>>><br>
>>>> It looks like you have 2-d lat and lon arrays associated with your<br>
>>>>data,<br>
>>>> as is often the case with models (especially ocean models).<br>
>>>><br>
>>>> This can be plotted by NCL without regridding, see the examples here:<br>
>>>> <a href="http://www.ncl.ucar.edu/Applications/ease.shtml" rel="noreferrer" target="_blank">http://www.ncl.ucar.edu/Applications/ease.shtml</a><br>
>>>> Although you are not using the EASE grid, the principal is exactly the<br>
>>>> same:<br>
>>>><br>
>>>> 1. Set your map plot grid type resource<br>
>>>> >res@trGridTrype = "TriangularMesh"<br>
>>>><br>
>>>> 2. Set the lat and lon arrays as attributes of the array you are<br>
>>>> plotting,<br>
>>>> so if your array is 'x'<br>
>>>> > x@lat2d = LAT<br>
>>>> > x@lon2d = LON<br>
>>>><br>
>>>> The just use one of the gsn_csm contour map plotting functions as<br>
>>>> normal.<br>
>>>><br>
>>>> I hope that's clear.<br>
>>>><br>
>>>> Will<br>
>>>><br>
>>>><br>
>>>> On 28/08/15 1:27 PM, "Yuqiang Zhang" <<a href="mailto:yuqiangzhang.thu@gmail.com" target="_blank">yuqiangzhang.thu@gmail.com</a>><br>
>>>>wrote:<br>
>>>><br>
>>>> >Hi Mira,<br>
>>>> ><br>
>>>> >Check the link here<br>
>>>> ><a href="http://www.ncl.ucar.edu/FAQ/" rel="noreferrer" target="_blank">http://www.ncl.ucar.edu/FAQ/</a><br>
>>>> >For Q 27:<br>
>>>> ><br>
>>>> >When I call one of the gsn_csm_xxxx_map plotting scripts, I get an<br>
>>>> error<br>
>>>> >message about a units attribute not being correct.<br>
>>>> >If you are using one of the gsn_csm_xxx_map functions to overlay data<br>
>>>> on a<br>
>>>> >map, and seeing one or both of the following error messages:<br>
>>>> ><br>
>>>> > (0) is_valid_lat_ycoord: Warning: The units attribute of<br>
>>>> > the Y coordinate array is not set to one of the allowable<br>
>>>> > units values (i.e. 'degrees_north'). Your latitude labels<br>
>>>> > may not be correct.<br>
>>>> ><br>
>>>> > (0) is_valid_lat_xcoord: Warning: The units attribute of<br>
>>>> > the X coordinate array is not set to one of the allowable<br>
>>>> > units values (i.e. 'degrees_east'). Your longitude labels<br>
>>>> > may not be correct.<br>
>>>> >then this means that your data contains coordinate arrays, but the<br>
>>>> >coordinate arrays either don't have the necessary "units" attribute,<br>
>>>>or<br>
>>>> >it's<br>
>>>> >not set to one of the allowable values ("degrees_east" for longitude<br>
>>>> >values<br>
>>>> >and "degrees_north" for latitude values).<br>
>>>> >If your coordinate arrays are indeed degrees east and degrees north,<br>
>>>> then<br>
>>>> >you can set the units attribute as follows (this code snippet assumes<br>
>>>> your<br>
>>>> >data array is called "data" and that the coordinate arrays are called<br>
>>>> >"lat"<br>
>>>> >and "lon"):<br>
>>>> ><br>
>>>> > data&lat@units = "degrees_north"<br>
>>>> > data&lon@units = "degrees_east"<br>
>>>> ><br>
>>>> >Regards,<br>
>>>> >Yuqiang<br>
>>>> ><br>
>>>> >-----Original Message-----<br>
>>>> >From: <a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a> [mailto:<a href="mailto:ncl-talk-bounces@ucar.edu" target="_blank">ncl-talk-bounces@ucar.edu</a>] On<br>
>>>> >Behalf<br>
>>>> >Of <a href="mailto:mberdahl@envsci.rutgers.edu" target="_blank">mberdahl@envsci.rutgers.edu</a><br>
>>>> >Sent: Thursday, August 27, 2015 10:21 PM<br>
>>>> >To: <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
>>>> >Subject: [ncl-talk] plotting model output where x/y are not lat/lon<br>
>>>> ><br>
>>>> >Hi all,<br>
>>>> ><br>
>>>> >I'm trying to make a simple plot of cumulative snowfall with data from<br>
>>>> a<br>
>>>> >model I did not run. When I try to make a simple plot, I receive the<br>
>>>> >following error:<br>
>>>> ><br>
>>>> >(0) check_for_y_lat_coord: Warning: Data either does not contain a<br>
>>>> >valid latitude coordinate array or doesn't contain one at all.<br>
>>>> >(0) A valid latitude coordinate array should have a 'units'<br>
>>>> attribute<br>
>>>> >equal to one of the following values:<br>
>>>> >(0) 'degrees_north' 'degrees-north' 'degree_north' 'degrees<br>
>>>> north'<br>
>>>> >'degrees_N' 'Degrees_north' 'degree_N' 'degreeN' 'degreesN' 'deg<br>
>>>>north'<br>
>>>> >(0) check_for_lon_coord: Warning: Data either does not contain a<br>
>>>> valid<br>
>>>> >longitude coordinate array or doesn't contain one at all.<br>
>>>> >(0) A valid longitude coordinate array should have a 'units'<br>
>>>> attribute<br>
>>>> >equal to one of the following values:<br>
>>>> >(0) 'degrees_east' 'degrees-east' 'degree_east' 'degrees east'<br>
>>>> >'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE' 'deg east'<br>
>>>> ><br>
>>>> ><br>
>>>><br>
>>>>>%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%<br>
>>>> ><br>
>>>> >When I dump the file it looks like this:<br>
>>>> ><br>
>>>> >netcdf ICE.1983.01-12.f77 {<br>
>>>> >dimensions:<br>
>>>> > TIME = UNLIMITED ; // (365 currently)<br>
>>>> > X10_69 = 60 ;<br>
>>>> > Y18_127 = 110 ;<br>
>>>> > SECTOR = 2 ;<br>
>>>> > SECTOR1_1 = 1 ;<br>
>>>> > ATMLAY14_23 = 10 ;<br>
>>>> > bnds = 2 ;<br>
>>>> > ATMLAY23_23 = 1 ;<br>
>>>> > ATM6H3_3 = 1 ;<br>
>>>> > OUTLAY = 20 ;<br>
>>>> > OUTLAY1_1 = 1 ;<br>
>>>> ><br>
>>>> >variables:<br>
>>>> > double TIME(TIME) ;<br>
>>>> > TIME:units = "HOURS since 1901-01-15 00:00:00" ;<br>
>>>> > TIME:long_name = "time" ;<br>
>>>> > TIME:time_origin = "15-JAN-1901 00:00:00" ;<br>
>>>> > TIME:axis = "T" ;<br>
>>>> > float DATE(TIME) ;<br>
>>>> > DATE:units = "YYYYMMDDHH" ;<br>
>>>> > DATE:long_name = "Date(YYYY MM DD HH)" ;<br>
>>>> > DATE:history = "From ICE.f77.1983.01.01-15" ;<br>
>>>> > double X10_69(X10_69) ;<br>
>>>> > X10_69:units = "km" ;<br>
>>>> > X10_69:long_name = "x" ;<br>
>>>> > X10_69:point_spacing = "even" ;<br>
>>>> > X10_69:axis = "X" ;<br>
>>>> ><br>
>>>> > double Y18_127(Y18_127) ;<br>
>>>> > Y18_127:units = "km" ;<br>
>>>> > Y18_127:long_name = "y" ;<br>
>>>> > Y18_127:point_spacing = "even" ;<br>
>>>> > Y18_127:axis = "Y" ;<br>
>>>> > float LON(Y18_127, X10_69) ;<br>
>>>> > LON:units = "degrees" ;<br>
>>>> > LON:long_name = "Longitude" ;<br>
>>>> > LON:history = "From ICE.f77.1983.01.01-15" ;<br>
>>>> > float LAT(Y18_127, X10_69) ;<br>
>>>> > LAT:units = "degrees" ;<br>
>>>> > LAT:long_name = "Latitude" ;<br>
>>>> > LAT:history = "From ICE.f77.1983.01.01-15" ;<br>
>>>> ><br>
>>>> >Clearly there are lats and lons associated with the x and y spacing,<br>
>>>> but<br>
>>>> >I'm<br>
>>>> >not sure how to tell NCL how to use those. Does anyone have advice on<br>
>>>> >this?<br>
>>>> ><br>
>>>> >Thanks in advance,<br>
>>>> >Mira</blockquote></div></div></div></div></div></blockquote></div></div></div></blockquote></div></div></div>