<div dir="ltr"><div class="gmail_default" style="font-size:small">I echo Dennis' recommendation about not using lat2d/lon2d for writing NetCDF. This should *never* be done for production files.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The lat2d/lon2d usage was adopted for plotting purposes, and, as Dave pointed out, because it is more understandable than "sfXArray" and "sfYArray". Note that lat2d/lon2d also work for vector and streamline plotting routines, where you would normally have to set "vfXArray" and "vfYArray".<br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--Mary</div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 13, 2015 at 7:04 AM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">A bit more ...<br>
<br>
Another issue is that if someone writes one or more variables (eg, x,<br>
y, z) containing lat2d/lon2d attributes to a netCDF (or HDF) file,<br>
*each* variable would have the same set of coordinates associated with<br>
it. This results in a bloated file size. The lat2d/lon2d attributes<br>
for each variable should be deleted prior to netCDF creation and<br>
separate variables created to contain the associated coordinate<br>
information.<br>
<br>
delete( x@lat2d )<br>
delete( x@lon2d )<br>
delete(y@lat2d)<br>
delete(y@lon2d)<br>
delete(z@lat2d)<br>
delete(z@lon2d)<br>
<br>
or,<br>
<br>
delete( [/ x@lat2d, x@loned, y@lat2d, y@loned, z@lat2d, z@loned /] )<br>
<br>
and, not required, but recommended<br>
<br>
x@coordinates = "LAT2D LON2D" ; variable names are arbitrary<br>
y@coordinates = "LAT2D LON2D"<br>
z@coordinates = "LAT2D LON2D"<br>
<br>
...<br>
<br>
fcn = addfile9"...","c")<br>
X = f->x<br>
Y = f->y<br>
Z = f->z<br>
<br>
LAT2D = lat2d<br>
LON2D = lon2d<br>
<br>
On Fri, Sep 11, 2015 at 5:56 PM, Dave Allured - NOAA Affiliate<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:dave.allured@noaa.gov">dave.allured@noaa.gov</a>> wrote:<br>
> Mary and Dennis,<br>
><br>
> Mary showed several advantages of the use of the lat2d/lon2d special<br>
> attributes for 2-D coordinates. I would like to retract my suggestion for<br>
> changing existing examples.<br>
><br>
> It seems to me that it is best to use sfXArray and sfYArray attributes only<br>
> in special cases when lat2d and lon2d are not sufficient. Also, lat2d and<br>
> lon2d seem more understandable to me. Perhaps the decision process for<br>
> which method could be enhanced on the "Overlaying data" documentation page:<br>
><br>
> <a href="http://www.ncl.ucar.edu/Document/Graphics/overlays_on_map.shtml" rel="noreferrer" target="_blank">http://www.ncl.ucar.edu/Document/Graphics/overlays_on_map.shtml</a><br>
><br>
> Dennis mentioned a performance problem: "Each variable having an associated<br>
> @lat2d, @lon2d takes up memory." Technically, I agree. However, modern<br>
> workstations have many Gbytes of RAM, so carrying around a few extra medium<br>
> size 2-D arrays is not noticeable unless you are repeating full variable<br>
> assignments within major processing loops. So I think this is not a<br>
> significant problem for retaining lat2d/lon2d.<br>
><br>
> --Dave<br>
><br>
><br>
> On Fri, Sep 11, 2015 at 11:15 AM, Mary Haley <<a href="mailto:haley@ucar.edu">haley@ucar.edu</a>> wrote:<br>
>><br>
>> Hi Dave,<br>
>><br>
>> I'm a bit torn about what to do with the examples, because ideally, we<br>
>> (NCL) would come up with a way to represent all types of "coordinate values"<br>
>> (true 1D coordinate arrays, 2D coordinate arrays, 1D arrays for "random"<br>
>> arrays, and something else for unstructured grids, like hexagonal or<br>
>> triangular meshes) through the NCL variable model. We've always tried to<br>
>> model the NetCDF way of handling these variables, and it doesn't yet have a<br>
>> way to recognize all types of coordinates.<br>
>><br>
>> We have kept the use of lat2d/lon2d attributes in the examples partly<br>
>> because we have advertised them for so long. Because of our strict backwards<br>
>> compatibility rule, we hope to always support this feature unless it becomes<br>
>> unreasonable to do so (which I don't foresee).<br>
>><br>
>> We also use this method in our ESMF regridding, because it's the only way<br>
>> to "sneak" in these special coordinate arrays to the "ESMF_regrid" routine.<br>
>> ESMF_regrid will look for "lat2d/lon2d" attached to the variable, and it<br>
>> will also return lat2d/lon2d if regridding to a curvilinear grid. The same<br>
>> is true for "lon1d/lat1d", which is a quick-and-dirty way to pass in 1D<br>
>> arrays of lat/lon for a 1D variable that is potentially "random".<br>
>><br>
>> There's one minor correction to what Dennis said about using one method<br>
>> over the other for plotting: if you have lat2d/lon2d attributes attached to<br>
>> your data when plotting, and you set res@gsnAddCyclic = True, then the<br>
>> gsn_csm_xxxx plotting routines will know how to properly add the cyclic<br>
>> point. However, if you use sfXArray and sfYArray resources, gsnAddCyclic<br>
>> doesn't know anything about these.<br>
>><br>
>> We have it on our list to modernize many of our aging NCL scripts, and we<br>
>> will add more examples that show the two ways of doing things.<br>
>><br>
>> --Mary<br>
>><br>
>><br>
>> On Fri, Aug 28, 2015 at 4:15 PM, Dave Allured - NOAA Affiliate<br>
>> <<a href="mailto:dave.allured@noaa.gov">dave.allured@noaa.gov</a>> wrote:<br>
>>><br>
>>> Dennis,<br>
>>><br>
>>> Thank you for the information about preferred resources sfXArray and<br>
>>> sfYArray for 2-D coordinates, and the reason why this is optimal. I learned<br>
>>> something new here.<br>
>>><br>
>>> Several NCL examples and at least one documentation page are advocating<br>
>>> the less optimal method using lat2d and lon2d attributes. Perhaps these<br>
>>> examples and pages could eventually be updated to use sfXArray and sfYArray<br>
>>> instead.<br>
>>><br>
>>> --Dave<br>
>>><br>
>>><br>
>>> On Fri, Aug 28, 2015 at 3:54 PM, Dennis Shea <<a href="mailto:shea@ucar.edu">shea@ucar.edu</a>> wrote:<br>
>>>><br>
>>>> 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<br>
>>>> 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">Will.Hobbs@utas.edu.au</a>><br>
>>>> 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">mberdahl@envsci.rutgers.edu</a>"<br>
>>>> > <<a href="mailto:mberdahl@envsci.rutgers.edu">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<br>
>>>> >> to<br>
>>>> >>my variables (for example: sf@lon2d = lon2d, sf@lat2d = lat2d), and<br>
>>>> >> then<br>
>>>> >>I would like to do a calculation with sf (eg. sf_total =<br>
>>>> >> dim_sum_n(sf,0)),<br>
>>>> >>it seems I have to assign the the new variable the lat and lon again.<br>
>>>> >> 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<br>
>>>> >>> 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">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<br>
>>>> >>>> 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<br>
>>>> >>>> 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">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<br>
>>>> >>>> > 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"<br>
>>>> >>>> > attribute,<br>
>>>> >>>>or<br>
>>>> >>>> >it's<br>
>>>> >>>> >not set to one of the allowable values ("degrees_east" for<br>
>>>> >>>> > longitude<br>
>>>> >>>> >values<br>
>>>> >>>> >and "degrees_north" for latitude values).<br>
>>>> >>>> >If your coordinate arrays are indeed degrees east and degrees<br>
>>>> >>>> > north,<br>
>>>> >>>> then<br>
>>>> >>>> >you can set the units attribute as follows (this code snippet<br>
>>>> >>>> > assumes<br>
>>>> >>>> your<br>
>>>> >>>> >data array is called "data" and that the coordinate arrays are<br>
>>>> >>>> > 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">ncl-talk-bounces@ucar.edu</a> [mailto:<a href="mailto:ncl-talk-bounces@ucar.edu">ncl-talk-bounces@ucar.edu</a>]<br>
>>>> >>>> > On<br>
>>>> >>>> >Behalf<br>
>>>> >>>> >Of <a href="mailto:mberdahl@envsci.rutgers.edu">mberdahl@envsci.rutgers.edu</a><br>
>>>> >>>> >Sent: Thursday, August 27, 2015 10:21 PM<br>
>>>> >>>> >To: <a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
>>>> >>>> >Subject: [ncl-talk] plotting model output where x/y are not<br>
>>>> >>>> > lat/lon<br>
>>>> >>>> ><br>
>>>> >>>> >Hi all,<br>
>>>> >>>> ><br>
>>>> >>>> >I'm trying to make a simple plot of cumulative snowfall with data<br>
>>>> >>>> > from<br>
>>>> >>>> a<br>
>>>> >>>> >model I did not run. When I try to make a simple plot, I receive<br>
>>>> >>>> > the<br>
>>>> >>>> >following error:<br>
>>>> >>>> ><br>
>>>> >>>> >(0) check_for_y_lat_coord: Warning: Data either does not<br>
>>>> >>>> > 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'<br>
>>>> >>>> > '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<br>
>>>> >>>> > 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<br>
>>>> >>>> > east'<br>
>>>> >>>> >'degrees_E' 'Degrees_east' 'degree_E' 'degreeE' 'degreesE' 'deg<br>
>>>> >>>> > east'<br>
>>>> >>>> ><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<br>
>>>> >>>> > spacing,<br>
>>>> >>>> but<br>
>>>> >>>> >I'm<br>
>>>> >>>> >not sure how to tell NCL how to use those. Does anyone have<br>
>>>> >>>> > advice on<br>
>>>> >>>> >this?<br>
>>>> >>>> ><br>
>>>> >>>> >Thanks in advance,<br>
>>>> >>>> >Mira<br>
><br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _______________________________________________<br>
> ncl-talk mailing list<br>
> <a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
> List instructions, subscriber options, unsubscribe:<br>
> <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
><br>
</div></div></blockquote></div><br></div>