<div dir="ltr">Guigma,<div><br></div><div>Here is another idea. Instead of filtering precipitation, consider filtering log precipitation, then get the antilog. The Lanczos or other similar filter should be okay. Depending on the rest of your application, you may want to apply a proportional correction so that the mean output is the same as the mean input over time.</div><div><br></div><div>I have not tested this filter method. However, it is guaranteed to not produce negative output values. It may also be more mathematically valid for the one-sided and spiky behavior of precipitation.</div><div><br></div><div>However, be careful of changes in certain derived statistics. I suspect that number of days with non-zero precip will probably increase dramatically, and this would be an artificial and meaningless side effect of filter application. Similarly I would distrust any derivations of statistics related to extreme values. This leads me back to something I said before, search to see how others have dealt with filtering precipitation.</div><div><br></div><div>--Dave</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 5, 2017 at 1:41 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Some negative weights are normal for Lanczos filters and similar digital filters. Filters with sharp cutoffs (narrow transition bands) will produce overshoot or "ringing" as a normal side effect. Please see this article about overshoot.</div><div><br></div><div> <a href="https://en.wikipedia.org/wiki/Overshoot_(signal)" target="_blank">https://en.wikipedia.org/wiki/<wbr>Overshoot_(signal)</a><br></div><div><br></div><div>Precipitation is badly behaved for the purpose of filtering because (1) it has a one sided distribution around and including zero, and (2) it is naturally extremely spiky. These two factors conspire to create lots of overshoot and small negative values when you apply ordinary weighted average filters.</div><div><br></div><div>I do not have a simple remedy for your precip filtering application. Try some simple searches such as "filter precipitation time series" to see how others may have approached this. As Dennis said, good luck. ;-)</div><div><br></div><div>--Dave</div><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 5, 2017 at 1:19 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-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>Likely, you have zero or near-zero values in the original time series.<br><br></div>This make filtering problematical. If you have any negatives weights you may have filtered values less than 0,0.<br><br></div><div>The reason I pointed you to Example 8 was so you could see the response function of your parameters you set..<br><br></div><div>Run the attached script. It produces 2 plots one for each 'sigma' factor. <br><br></div><div>You may have to resort to<br><br></div><div> prc_filt = where(prc_filt.lt.0.0, 0.0, prc_filt)<br><br></div><div>Good luck<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 5, 2017 at 12:37 PM, Kiswendsida Hyacinthe GUIGMA <span dir="ltr"><<a href="mailto:karongseba@gmail.com" target="_blank">karongseba@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:verdana,helvetica,sans-serif;font-size:16px"><div id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yui_3_16_0_ym19_1_1512501861679_9557"><span></span>Thank you dear Dennis for your help. I am sorry if my questions look too basic. I already read the filtering examples. <br></div><div dir="ltr" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yui_3_16_0_ym19_1_1512501861679_9602">The fact is that using their method (you can see my code in my previous post), from daily rainfall data I got negative values after filtering, what is abnormal. <br></div><div id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yui_3_16_0_ym19_1_1512501861679_9582" class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306signature">-----------------------------<br>GUIGMA</div><div><div class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789h5"> <div class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306qtdSeparateBR"><br><br></div><div style="display:block" class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yahoo_quoted"> <div style="font-family:verdana,helvetica,sans-serif;font-size:16px"> <div style="font-family:HelveticaNeue,"Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-size:16px"> <div dir="ltr"><font size="2" face="Arial"> On Tuesday, 5 December 2017, 19:03, Dennis Shea <<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>> wrote:<br></font></div> <br> <div class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306y_msg_container"><div id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329"><div><div dir="ltr"><div><div><div><div><div>Please look at the filtering examples:<br clear="none"> <a rel="nofollow" shape="rect" href="https://www.ncl.ucar.edu/Applications/filter.shtml" target="_blank">https://www.ncl.ucar.edu/Appli<wbr>cations/filter.shtml</a><br clear="none"><br clear="none"></div> In particular, run Example 8<br clear="none"><br clear="none"></div>[1] yes, of course ... more weights can create a sharper cutoff but there is a larger loass od data at the beginning and end.<br clear="none"><br clear="none"></div>[2] re: <span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329gmail-m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866">practical criterion .... That is up to you as a scientist.<br clear="none"><br clear="none">--<br clear="none"></span></div><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329gmail-m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866">Note ncl-talk is not the place to learn about filtering.<br clear="none"><br clear="none"></span></div><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329gmail-m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866">Good luck</span><div><div><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329gmail-m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866"><br clear="none"></span></div></div></div><div class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329gmail_extra"><br clear="none"><div class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329gmail_quote">On Tue, Dec 5, 2017 at 9:14 AM, Kiswendsida Hyacinthe GUIGMA <span dir="ltr"><<a rel="nofollow" shape="rect" href="mailto:karongseba@gmail.com" target="_blank">karongseba@gmail.com</a>></span> wrote:<br clear="none"><blockquote class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329yqt0581134612" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329yqt42637"><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:verdana,helvetica,sans-serif;font-size:16px"><div id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3785"><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3864">Dear NCL users,</span></div><div dir="ltr" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3823"><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866">I am very new on NCL and I am trying to filter my rainfall data using Lanczos Filter (bandpass 10-90 day filtering). My question concerns the processing of the weights. I would like to know <br clear="none"></span></div><div dir="ltr" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3884"><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866">1-is there any relationship between the number of weights to choose and the cutoff frequencies?</span></div><div dir="ltr" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3929"><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866">2-is there any practical criterion to choose the number of weights? I know that this number influences the loss of data.</span></div><div dir="ltr" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4139"><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866">Below is my code:</span></div><div dir="ltr" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4147"><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866"><br clear="none">------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------------------ ----------------</span></div><div dir="ltr" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3965"><span id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3866">;import the file<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4027" clear="none">gpcp=addfile("gpcp_Sahel.nc"," r")<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4028" clear="none">rr=gpcp->precip<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4029" clear="none">;filter parameters<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4030" clear="none">ihp=2 ;bandpass<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4031" clear="none">sigma=1.0 ; Lanczos sigma<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4032" clear="none">nWgt = 81 ; number of weights -> means 40 data lost at the beginning and 40 data lost at the end. <br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4033" clear="none">fca = 1./90. ; start freq ;highpass= 90 days<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4034" clear="none">fcb = 1./10. ; last freq; lowpass= 10 days<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4035" clear="none">wgt = filwgts_lanczos (nWgt, ihp, fca, fcb, sigma )<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4036" clear="none">printVarSummary(wgt)<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4037" clear="none">xBPF = wgt_runave_n_Wrap ( rr, wgt, 0, 0) ; 10-90 day bp performed across time dimension(0) of rr (meaning the time dimension)<br id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4038" clear="none"></span></div><div id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3786"><div id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4166"> ----------------------------- ------------------------------ ------------------------------ ------------------------------ ------------------------------ ----------------</div><div id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4167"><br></div><div id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_4170">Cheers,<br clear="none"></div></div><div class="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592signature" id="m_-4393356187518197777m_8992142958663675068m_405862702495245256gmail-m_5391763519357284789m_8392780780582619306yiv8018064329m_-6632467413770190592yui_3_16_0_ym19_1_1512489722799_3869"><br clear="none">GUIGMA</div></div></div></div></blockquote></div></div></div></div></div></div></div></div></div></div></div></div></blockquote></div></div></blockquote></div></div></div>
</blockquote></div><br></div></div></div>