<div dir="ltr"><div>I created the function. based upon a Matlab function. Also, the documentation .</div><div>--------------------------------</div><div>As noted, the function follows the approach described by Eric Weisstein: <br></div><div> <a href="http://mathworld.wolfram.com/LeastSquaresFittingExponential.html"><b>Least Squares Fitting--Exponential</b></a>: MathWorld--A Wolfram Web Resource <br></div><div>-------------------------------</div><div>There is an error in the documentation. Missing values (_FillValue) are not allowed ... <br></div><div>and, (of course) values <= to 0.0 Within the next day or two, I will look at the issue(s) offline. <br></div><div><br></div><div>D<br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 8, 2021 at 4:06 AM Giorgio Graffino via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p style="font-size:12pt;font-family:Arial">Dear NCL folks,</p><p style="font-size:12pt;font-family:Arial"><br></p><p style="font-size:12pt;font-family:Arial">I'm using e<span style="color:inherit;font-size:12pt;font-family:Arial">xponential_curve_fit on </span><span style="font-family:arial,sans-serif;font-size:12pt">NCL 6.6.2 </span><span style="color:inherit;font-size:12pt;font-family:Arial">to fit vertical density profiles all over the global domain. I thought it was an esay task, but it's turning out to be harder than expected.</span></p><p style="font-size:12pt;font-family:Arial"><span style="color:inherit;font-size:12pt;font-family:Arial"><br></span></p><p style="font-size:12pt;font-family:Arial"><span style="color:inherit;font-size:12pt;font-family:Arial">First, despite what said in the documentation page (</span><span style="font-family:arial,sans-serif;font-size:12pt"><a href="https://www.ncl.ucar.edu/Document/Functions/Contributed/exponential_curve_fit.shtml" target="_blank">https://www.ncl.ucar.edu/Document/Functions/Contributed/exponential_curve_fit.shtml</a></span><span style="color:inherit;font-size:12pt;font-family:Arial">), the function doesn't handle missing values. I created a new function </span><span style="font-family:arial,sans-serif;font-size:12pt">exponential_curve_fit_FillValue by simply commenting out the relevant part from the original function and make it return the </span><span style="font-family:arial,sans-serif;font-size:12pt">y = A*exp(B*x) array.</span></p><p style="font-size:12pt;font-family:Arial"><span style="font-family:arial,sans-serif;font-size:12pt"><br></span></p><p><span style="font-family:Arial;font-size:12pt">Second, I'm trying to get the exponential fit of each vertical vertical density profile over the global domain. So I'm looping over all longitudes, latitudes, and time steps to compute the fit of density (</span><span style="font-size:12pt;font-family:Arial">ctrl_dens</span><span style="font-family:Arial;font-size:12pt">) over depth (levs). However, the resulting fit doesn't look like fitting the profile very much (see the globally-averaged profiles on the attached plot). See below the relevant bit of code.</span></p><p style="font-size:12pt;font-family:Arial"><span style="font-family:Arial;font-size:12pt"><br></span></p><p><span style="font-family:Arial;font-size:12pt">ctrl_densexpfit = new(dimsizes(ctrl_dens),typeof(ctrl_dens),ctrl_dens@_FillValue)</span></p><p><span style="font-family:Arial;font-size:12pt">do i = 0, nlon-1</span></p><p><span style="font-family:Arial;font-size:12pt">do j = 0, nlat-1</span></p><p><span style="font-family:Arial;font-size:12pt">do l = 0, ntim-1</span></p><p><span style="font-family:Arial;font-size:12pt"> ctrl_densexpfit(l,:,j,i) = exponential_curve_fit_FillValue(tofloat(levs),ctrl_dens(l,:,j,i),0,False)</span><br></p><p><span style="font-family:Arial;font-size:12pt">end do</span></p><p><span style="font-family:Arial;font-size:12pt">end do</span></p><p><span style="font-family:Arial;font-size:12pt">end do</span></p><p style="font-size:12pt;font-family:Arial"><span style="font-family:Arial;font-size:12pt"><br></span></p><p style="font-size:12pt;font-family:Arial"><span style="font-family:Arial;font-size:12pt">Can you please help me on this? Is there anything I'm doing wrong or missing?</span></p><p style="font-size:12pt;font-family:Arial"><span style="font-family:Arial;font-size:12pt"><br></span></p><p style="font-size:12pt;font-family:Arial"><span style="font-family:Arial;font-size:12pt">Cheers,</span></p><p style="font-size:12pt;font-family:Arial"><span style="font-family:Arial;font-size:12pt">Giorgio</span></p>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></blockquote></div>