[ncl-talk] adjusting tension of a smooth overlaid on xyplot

Sam McClatchie (NOAA Federal) sam.mcclatchie at noaa.gov
Fri Aug 7 15:29:41 MDT 2015


Hello Mary -- Thanks for checking this out. I ran your script and the 
your plots have the same problem that my own script had. Namely, 
changing the tension parameter, sig, has almost no effect on the smooth. 
Perhaps it is the difference between what a physicist and a biologist 
might think of as smoothing ... I've attached a plot where I use your 
data to create smooths with different "tension". Since these smooths 
were created with locally weighted robust regression the tension is 
actually the span, or the proportion of the data used for each locally 
weighted fit. But the effect is what I am after. When you adjust the 
span, or tension, the curve becomes more or less smooth.

Here is the R-code:
# test.smooth.with.Haley.data
library(RNetCDF, graphics)
# load Marys test data and plot a subsample
# ====================================
nc <- open.nc("TestData.xy3.nc")
dat <- read.nc(nc)
print(summary(dat))
yi <- dat$T[1:36]

# fit a lowess smooth with differing spans
# equivalent to tension on a smooth
# ========================================
pdf("test.smooth.pdf")
plot(yi, type="b", ylab="Temperature")
i <- seq(1,36,1)
d <- cbind(i,yi)
span <- seq(0.1,0.5,0.1)
c <- seq(1,5,1)
for(k in 1:length(span)) {
     lines(lowess(d, f=span[k]), col=c[k])
}
graphics.off()

Best fishes
Sam

On 08/07/2015 12:13 PM, Mary Haley wrote:
> Sam,
>
> Here's a slightly better example, that uses dummy data read off a 
> NetCDF file. The script is pretty much the same, except I changed the 
> data and added more tension factors to test. I also created a panel 
> plot for comparison.
>
> I've also added this example to our 1D interpolators page:
>
> http://www.ncl.ucar.edu/Applications/interp1d.shtml#ex3
>
> --Mary
>
> On Fri, Aug 7, 2015 at 12:43 PM, Mary Haley <haley at ucar.edu 
> <mailto:haley at ucar.edu>> wrote:
>
>     Hi Sam,
>
>     It appears you are using the parameter correctly.
>
>     Please try running the attached example, which shows a simple XY
>     plot, and different tension factors using the "sig" parameter with
>     ftcurv.
>
>     If this doesn't shine a light on the problem at your end, then can
>     you provide us with a script and the data?
>
>     --Mary
>
>
>     On Tue, Aug 4, 2015 at 5:07 PM, Sam McClatchie (NOAA Federal)
>     <sam.mcclatchie at noaa.gov <mailto:sam.mcclatchie at noaa.gov>> wrote:
>
>         Colleagues
>
>         I want to put a smooth line through a de-seasonalized time
>         series that shows a trend and residual variability. I'm having
>         trouble adjusting the tension of the smooth which I think
>         needs to be less than one. I would like the overlaid smooth
>         curve to be much more smooth than the data, but I'm basically
>         getting a high order polynomial smooth at present.
>
>         Here is a snip of code:
>
>         (Note: the xyplot tsplots(2) was previously defined)
>
>         xi = (/spice_ts_ss&time/)
>         yi = monthly_anom(:,0,0)
>         xo = fspan(1985., 2015., 200)
>         ftsetp("sig",0.5)
>         yo = ftcurv(xi,yi,xo)
>
>         colors = (/"red","green","blue"/)
>         resplot at xyLineColor   = colors(0)
>         tsplots(3)  = gsn_csm_xy (wks,xo,yo,resplot)
>         overlay(tsplots(2), tsplots(3))
>
>         Changing the value of the sig parameter in ftsetp between 0.1
>         to 40 seems to have no effect, which suggests that I am
>         misusing something?
>
>         Thanks in advance,
>         Sam
>         -- 
>         Sam McClatchie,
>         Supervisory oceanographer,
>         NOAA lead for the CalCOFI program
>         Southwest Fisheries Science Center, NOAA,
>         8901 La Jolla Shores Dr.
>         La Jolla, CA 92037-1509, U.S.A.
>         email <Sam.McClatchie at noaa.gov> <mailto:Sam.McClatchie at noaa.gov>
>         Office: 858 546 7083 <tel:858%20546%207083>, Cellular: 858 752
>         8495 <tel:858%20752%208495>
>         Research home page <www.fishocean.info
>         <http://www.fishocean.info>>
>         CalCOFI 66 years
>
>         _______________________________________________
>         ncl-talk mailing list
>         ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
>         List instructions, subscriber options, unsubscribe:
>         http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>

-- 
email signature Sam McClatchie,
Supervisory oceanographer,
NOAA lead for the CalCOFI program
Southwest Fisheries Science Center, NOAA,
8901 La Jolla Shores Dr.
La Jolla, CA 92037-1509, U.S.A.
email <Sam.McClatchie at noaa.gov>
Office: 858 546 7083, Cellular:  858 752 8495
Research home page <www.fishocean.info>
CalCOFI 66 years
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150807/1997b405/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 23689 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150807/1997b405/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CalCOFI_66_year_logo.png
Type: image/png
Size: 23689 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150807/1997b405/attachment-0001.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.smooth.pdf
Type: application/pdf
Size: 6308 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150807/1997b405/attachment.pdf 


More information about the ncl-talk mailing list