[Thread Prev][Thread Next][Index]
Re: [ferret_users] dynamic_height.jnl (and @iin, @rsum in general)
- To: Andrew Wittenberg <andrew.wittenberg@xxxxxxxx>
- Subject: Re: [ferret_users] dynamic_height.jnl (and @iin, @rsum in general)
- From: William Kessler <william.s.kessler@xxxxxxxx>
- Date: Sun, 6 Feb 2022 11:19:13 -0800
- Arc-authentication-results: i=2; mx.google.com; dkim=pass header.i=@noaa.gov header.s=google header.b=nWp0XLkL; spf=pass (google.com: domain of william.s.kessler@xxxxxxxx designates 209.85.220.41 as permitted sender) smtp.mailfrom=william.s.kessler@xxxxxxxx; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=noaa.gov
- Arc-authentication-results: i=1; mx.google.com; dkim=pass header.i=@noaa.gov header.s=google header.b=nWp0XLkL; spf=pass (google.com: domain of william.s.kessler@xxxxxxxx designates 209.85.220.41 as permitted sender) smtp.mailfrom=william.s.kessler@xxxxxxxx; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=noaa.gov
- Arc-message-signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-archive:list-help:list-post:list-id:mailing-list:precedence:to :references:message-id:content-transfer-encoding:cc:date:in-reply-to :from:subject:mime-version:dkim-signature; bh=nzfESmH7PWFWYO8NyEkIgl9GwyFg1x4sePYgjATrreg=; b=ddSVoS+EOAD/UeVvvXtEpXKEw1s5PdLUc/aVbeUyvxMPPwJRQCNDnftwI7NEkyt/N8 EqpSXWXy59Q3KPiqiLR/Abk1VfC4aLqAVscP+vn1TkeCAEgRWQ+A9LGwbLQ99WcAd7y7 fu4gBlP5j49xcKh6a5Nc1wFN6m2rUT9nuG5hJYW/Br1nuedPkcwvX/ybPLpD2FEzgXg6 tpj6+womTfXNhLIifHmzwX3gHKAuRFQ1gXBuM/b/lEOrfcurJ0GyVpHD+SSPFgFHUXnF bvwLpLsixYzz6OFCarA/wgL8kcjCVEea7asb4rmVF0nphVBF/vi+2QvHrk5cZFarcBtk 6cxg==
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:dkim-signature; bh=nzfESmH7PWFWYO8NyEkIgl9GwyFg1x4sePYgjATrreg=; b=FHsToP0RRV/Fvbd95e9SPkIgO6/MgdqKU4WLb2AEQ25M8zkXk2jRB3yjVW0iBlNo1Z qkosDKq+1W2AFyx5IUHB9U6FxsZZaRnPb69+zTfd5PRX2fWUzRpHigs0XQ+NcDs9up/Y Lx5tzInn8T0ghlbtEfE3BV530Vuo2nqF6CODc61ICxf9bAlRStAT3X9W/H4Gj/qWCIee eZcpDPx5vYbym+ZRuS8yGsXg41ylTuC2j7lcfiSowZI7m4twuf+LpZBR9RWML/Jv/xTi +6Wpl251KzHQAdnMWVvOn7Qw1DLLbzC2PsBOvpBDQnp7CB8WtpF6piaL0grbCG7edSYC MQig==
- Arc-seal: i=2; a=rsa-sha256; t=1644175156; cv=pass; d=google.com; s=arc-20160816; b=oXMUyDg+n+N33iRRc62dVK+DrTv9X2+4p5AuAJqbBbscTlhsMFdy2mr1fGIVQo1DJO GxMDuM0edQ/WjhlUGcDfLgIEW0aogueOsdAZnfghMlzW8A44RPKhs+aNc78fx1Os3NSA 5cxgGpE35JOyH4W6M9sd1vmqdsB/PoO581bgFxl8M6T3KHfkpdNBB4s1Vg0UsYFVrqEc Ut0Jj7eu4EZDfyieSGlbido4XybfghHbEFa9f9mqxHwt7Ry7tmbz5xwAfoZcj9rjOSFi Y5YohQM9EVAKye7iO/5mxbasRktVh+hstJx1X7bJTyKlnWek8nSKp9bEzWKMF+gJ38l3 uzlQ==
- Arc-seal: i=1; a=rsa-sha256; t=1644175155; cv=none; d=google.com; s=arc-20160816; b=vGcDW8lxWpfDK356InHYwlzW1II8FS7Kty+xPeBb79+Fx1p4XR+0vdrAy95jVR9j++ vYl+/2HdQktMoxa5f4pEvYQPEEhY4ZZIv02f1REx6viXmGyR9BtSz3TheDHmsfh+tv75 pAQ18JV3/CUPRTeE1vN8z1VUxS3qwGlmBybL2n2bbexlQcz5snTtSuHnN7RX7j83nyFS plE/HewcKkBTi9goyYeRaBPiEFK/8Or9nFIaGZvhAal98oHad4sH0rkUvRbqPT4a5V8J tlNOiMgbYcX/zGRhPRLHjAGFgqyyUN0qaD90x+xo8ml5n35PEBcqqPdpGPwR+K77wjDU 6Zlw==
- Cc: "William S. Kessler" <william.s.kessler@xxxxxxxx>, Ferret <ferret_users@xxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noaa.gov; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive; bh=nzfESmH7PWFWYO8NyEkIgl9GwyFg1x4sePYgjATrreg=; b=YA97j+M7rkXO1fo852xi9nlk0sfJLAoiVWB/Z2Ymy34cGKYkO+gIDttgbbBYCj0Sn+ 2u2pGHaawVR7mk9xtlzMg0a0IN33mi1zgzUjv1Vp6DFmcFJ+5dERKM4z3ZZ3oP3mSbXJ YT+YE6FGBsM0qt8YDnGeM3yRBdZm3fi0Ch1J54Cxjp2jSRPIWXXbMFKQ+nUAWLp/8/lI AyZ0UWevsdQg3XUGNjKfXBTITj+45WZyaTfGnn4mL//56m9eUc1rfWY8QVo4zYx7XLgD D589xxMi4S2l6DhX1KacRRaRwj7JQcWHzq3SNbRwmUiQnAVptj6zw2nHEbueDSERnIj1 yfsg==
- In-reply-to: <CAKoe08Swi-Ffr43ZeU3540h9AT7g7RabT=yomoE8yK+Qv-v1Wg@mail.gmail.com>
- List-archive: <https://groups.google.com/a/noaa.gov/group/ferret_users/>
- List-help: <https://support.google.com/a/noaa.gov/bin/topic.py?topic=25838>, <mailto:ferret_users+help@noaa.gov>
- List-id: <ferret_users.noaa.gov>
- List-post: <https://groups.google.com/a/noaa.gov/group/ferret_users/post>, <mailto:ferret_users@noaa.gov>
- Mailing-list: list ferret_users@xxxxxxxx; contact ferret_users+owners@xxxxxxxx
- References: <CAK0Qe2OH-O-ezGndAMFVT0sGRHZPnMjZ7mvfs9NjjFq9DaXJaA@mail.gmail.com> <CAKoe08Swi-Ffr43ZeU3540h9AT7g7RabT=yomoE8yK+Qv-v1Wg@mail.gmail.com>
- Sender: owner-ferret_users@xxxxxxxx
Thanks!
This illustrates the hard problem of informing even daily users of the long and expanding list of features. I would have told you that I read the release notes but this one slipped by, probably because I saw no immediate use for it and kept scrolling.
So when I happened on the dynamic height problem I didn't realize that it had been solved ... very nicely and cleanly, too. But rereading the 7.4.2 release notes, I can see why I missed the significance without an example that you only see by clicking the link to @iin.
That's one of the values of a user group like this one. Thanks!
Billy
> On Feb 6, 2022, at 10:09 AM, Andrew Wittenberg - NOAA Federal <andrew.wittenberg@xxxxxxxx> wrote:
>
> Hi Billy,
>
> Thanks very much for your post!
>
> Relevant to this, check out Chapter 3, Section 2.4.5 of the User's Guide, "Method 3" toward the end of that subsection, for a description of the new @IIN "regridding transformation" (rather than the older "regular transformation" form that the script currently uses). The regridding form was introduced in Ferret v7.4.2 (summer 2018?), largely to address the half-cell shift that you mentioned in the regular form -- namely that the integral-to-edge values were placed at the cell centers of the original axis. It's better to either have the integral-to-center values placed at the cell centers, or the integral-to-edge values placed at the cell edges.
>
> This can now be done very easily, using the "regridding form" of @IIN, which allows one to obtain the indefinite integral at arbitrary points. These points can be the grid cell centers (e.g. if you regrid to the original axis, Z[GZ=my_variable]), the grid cell edges (if you regrid to the cell edges at, say, ZBOXHI[GZ=my_variable] or ZBOXLO[GZ=my_variable]), or any other set of target points defined with DEFINE AXIS. Simply regrid to that target axis using: integrand[GZ=target_z_axis@IIN].
>
> Andrew
>
>
> On Sat, Feb 5, 2022 at 2:40 PM William Kessler - NOAA Federal <william.s.kessler@xxxxxxxx> wrote:
> Hi Ferreters -
>
> I happened to look at our standard dynamic height script today.
> (On my system it is .../opt/miniconda3/pkgs/pyferret-7.6.3-py37hfb0c5.1/go/dynamic_height.jnl)
> (comments say "updated in 10/93" ... before some of you were even born ...)
> (the script is also attached FYI)
>
> I think there's a subtle error in this script, due to the upward indefinite integral.
> Beyond dynamic height, the issue occurs anytime where @iin (or @rsum) is used.
>
> The relevant parts of the dynamic_height.jnl algorithm are:
>
> ! Standard expression for specific volume anomaly
> let SVanom = 1/rho_UN(dyn_s,dyn_t,dyn_p) - 1/rho_UN(35,0,dyn_p) ! dyn_[s,t,p] are temp,salinity,pressure
>
> ! The expression for the top-to-bottom integral is straightforward:
> let/title="Dynamic Height(dyn-cm)" DYN_HT = 1E5 * dyn_mask * SVanom[z=@din] ! (dyn_mask excludes incomplete profiles)
>
> ! But for a z-dependent result, the direction of the z-axis and of integration must be considered.
> ! The z-axis is typically DOWNWARD (/DEPTH in the axis definition), but the intended integration is UPWARD.
> ! Thus the indefinite integral @iin needs to be reversed using @din minus @iin.
> ! In the script this is:
>
> let/title="Dynamic Height(dyn-cm)" DYN_HTz = 1E5 * dyn_mask * (SVanom[z=@din]-SVanom[z=@iin])
>
> ! However, the user probably expects the value to be at the same depths as the density data, namely at the center of each grid cell.
>
> ! But the script's expression integrates completely through each grid cell, giving the value of the integral at the TOP of the cell.
>
> ! - - - - - - - - -
> ! A simple way to see what's happening is with a simple example of the results of @din - @iin, defining an example that can be followed in your head:
>
> define axis/z/depth zdep={1,2,3,4,5} ! simple downward z-axis
> let zvals = 2*z[gz=zdep] ! variable on this axis with values twice the axis value
>
> ! plot ZVALS, its downward integral and two versions of its upward integral (attached png file)
> ! (also include a downward @iin integration: red and brown lines)
> plot/line/sym=27/thick=2/vli=0:5.5/hli=0:31:5 zvals,zvals[z=@iin],zvals[z=@din]-zvals[z=@iin],zvals[z=@din]-(zvals[z=@iin]-zvals*zbox/2),zvals[z=@iin]-zvals*zbox/2
>
> ! list the relevant pieces, including the grid cell size and limits:
> list z[gz=zdep],zbox[gz=zdep],zboxlo[gz=zdep],zboxhi[gz=zdep],zvals,zvals[z=@iin],zvals[z=@din]-zvals[z=@iin],zvals[z=@din]-(zvals[z=@iin]-zvals*zbox/2),zvals[z=@iin]-zvals*zbox/2
> Z: 0.5 to 5.5
> Column 1: Z is Z (axis ZDEP)
> Column 2: ZBOX is ZBOX (axis ZDEP)
> Column 3: ZBOXLO is ZBOXLO (axis ZDEP)
> Column 4: ZBOXHI is ZBOXHI (axis ZDEP)
> Column 5: ZVALS is 2*Z[GZ=ZDEP]
> Column 6: ZVALS[Z=@IIN] is 2*Z[GZ=ZDEP] (indef. integ. on Z) ! simple downward @iin
> Column 7: EX#7 is ZVALS[Z=@DIN]-ZVALS[Z=@IIN] ! integration as in dynamic_height.jnl
> Column 8: EX#8 is ZVALS[Z=@DIN]-(ZVALS[Z=@IIN]-ZVALS*ZBOX/2) ! I think this is correct for DH
> Column 9: EX#9 is ZVALS[Z=@IIN]-ZVALS*ZBOX/2 ! correct downward integration
> Z ZBOX ZBOXLO ZBOXHI ZVALS ZVALS EX#7 EX#8 EX#9
> 1 / 1: 1.000 1.000 0.500 1.500 2.00 2.00 28.00 29.00 1.00
> 2 / 2: 2.000 1.000 1.500 2.500 4.00 6.00 24.00 26.00 4.00
> 3 / 3: 3.000 1.000 2.500 3.500 6.00 12.00 18.00 21.00 9.00
> 4 / 4: 4.000 1.000 3.500 4.500 8.00 20.00 10.00 14.00 16.00
> 5 / 5: 5.000 1.000 4.500 5.500 10.00 30.00 0.00 5.00 25.00
>
> We're comparing EX#7 (as in dynamic_height.jnl, green line on plot) and EX#8 (I think is correct, blue line).
> Which is correct?
>
> The issue is that the value of the integral is understood as being at the grid cell centers.
>
> Starting at a value of 30 at the bottom of the deepest cell (z=5.5), the first value is halfway up that cell, thus half of ZVALS[z=5], namely 5. An expression like in dynamic_height.jnl gives 0.
>
> Following the blue line, the value of the integral at the highest gridcell (z=1) is 29 (not 30 because this integration is not to the top of the cell at z=0.5). Nor is is 28, which is what an integration like in dynamic_height.jnl would give.
> ! - - - - - - - - -
>
> Thus I think the correct expression for the dynamic height integration should be like EX#8:
>
> let/title="Dynamic Height(dyn-cm)" DYN_HTz = 1E5 * dyn_mask * (SVanom[z=@din]-(SVanom[z=@iin]-SVanom*ZBOX/2))
>
> The same issue occurs in any @iin integration.
> Consider the red line in the attached plot (ZVALS[z=@iin], EX#9 in the listing above).
> At the first grid cell (z=1) the value is 2, the whole value of ZVALS[k=1], as if the integration had been carried through the whole cell (thus to z=1.5).
>
> A corrected version is the brown line: zvals[z=@iin]-zvals*zbox/2, namely to the center of each cell.
>
> => Bottom line is that the results of @iin and @rsum need to be considered with care.
> Where exactly do you expect the result to apply?
>
> Billy K
>
>
>
> <zvals_test2.png>
>
(Still) working at home: +1 206-228-7330 (m)
[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce /
NOAA /
OAR /
PMEL /
Ferret
Privacy Policy | Disclaimer | Accessibility Statement