[ncl-talk] adjusting tension of a smooth overlaid on xyplot
Mary Haley
haley at ucar.edu
Thu Sep 10 15:34:19 MDT 2015
Hi Sam,
This is a very delayed response, but I wanted to let you know that we've
added a ticket (NCL-2276) for looking into adding a "lowess" function. We
found some C and Fortran versions that we can probably wrap quickly, if
they are not too complicated.
--Mary
On Wed, Aug 12, 2015 at 10:48 AM, Mary Haley <haley at ucar.edu> wrote:
> Hi Sam,
>
> I'm not familiar with the "lowess" function in R. Perhaps if you find
> this useful, and we can get at the source code, we can add an interface to
> in NCL?
>
> I did try the same example using the lspoly function, but I think this
> would be too smooth for your purposes. See example interp1d_3.ncl at:
>
> http://www.ncl.ucar.edu/Applications/interp1d.shtml#ex3
>
> --Mary
>
>
> On Fri, Aug 7, 2015 at 3:29 PM, Sam McClatchie (NOAA Federal) <
> sam.mcclatchie at noaa.gov> wrote:
>
>> 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> 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>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> <Sam.McClatchie at noaa.gov>
>>>> Office: 858 546 7083 <858%20546%207083>, Cellular: 858 752 8495
>>>> <858%20752%208495>
>>>> Research home page < <http://www.fishocean.info>www.fishocean.info>
>>>> [image: CalCOFI 66 years]
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>>
>>>
>>
>> --
>> 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> <Sam.McClatchie at noaa.gov>
>> Office: 858 546 7083, Cellular: 858 752 8495
>> Research home page <www.fishocean.info>
>> [image: CalCOFI 66 years]
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150910/f3c5d50c/attachment.html
-------------- 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/20150910/f3c5d50c/attachment.png
-------------- 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/20150910/f3c5d50c/attachment-0001.png
More information about the ncl-talk
mailing list