{"id":156,"date":"2014-12-11T21:26:06","date_gmt":"2014-12-11T21:26:06","guid":{"rendered":"https:\/\/existencia.org\/pro\/?p=156"},"modified":"2014-12-11T21:26:36","modified_gmt":"2014-12-11T21:26:36","slug":"growing-degree-day-calculations","status":"publish","type":"post","link":"https:\/\/existencia.org\/pro\/?p=156","title":{"rendered":"Growing Degree-Day Calculations"},"content":{"rendered":"<p><a href=\"http:\/\/www.pnas.org\/content\/106\/37\/15594.short\">Schlenker and Roberts (2009)<\/a> use daily minimum and maximum temperatures to calculate growing degrees, rather than daily mean temperatures.  This is important when the effect of extreme temperatures is an issue, since these often will not show up in mean temperatures.<\/p>\n<p>Growing degree days form a useful model of crop productivity.  DMAS has examples of these for <a href=\"http:\/\/dmas.berkeley.edu\/collection\/view?id=52d9b752434fd715591829c7\">maize<\/a>, <a href=\"http:\/\/dmas.berkeley.edu\/collection\/view?id=52d9b7e7434fd7155a1829c8\">soybeans<\/a>, and <a href=\"http:\/\/dmas.berkeley.edu\/collection\/view?id=52d9b919434fd715591829db\">cotton<\/a>.<\/p>\n<p>To do this, they use a sinusoidal approximation, integrating the area of a curve through the minimum and maximum temperatures:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/existencia.org\/pro\/wp-content\/uploads\/2014\/12\/thresholds.png\" alt=\"thresholds\" width=\"514\" height=\"135\" class=\"alignnone size-full wp-image-157\" srcset=\"https:\/\/existencia.org\/pro\/wp-content\/uploads\/2014\/12\/thresholds.png 514w, https:\/\/existencia.org\/pro\/wp-content\/uploads\/2014\/12\/thresholds-300x78.png 300w\" sizes=\"auto, (max-width: 514px) 100vw, 514px\" \/><br \/>\n(adapted from <a href=\"https:\/\/ipm.illinois.edu\/degreedays\/calculation.html\">here<\/a>&#8212; but don&#8217;t use their calculations!)<\/p>\n<p>The calculations aren&#8217;t very difficult, but require some careful math.  I had a need to write them in python and translate them to R, so I&#8217;m providing them here for anyone&#8217;s benefit.<\/p>\n<pre class=\"brush: python; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nimport numpy as np\r\nimport warnings\r\n\r\nwarnings.simplefilter(&quot;ignore&quot;, RuntimeWarning)\r\n\r\ndef above_threshold(mins, maxs, threshold):\r\n    &quot;&quot;&quot;Use a sinusoidal approximation to estimate the number of Growing\r\nDegree-Days above a given threshold, using daily minimum and maximum\r\ntemperatures.\r\n\r\nmins and maxs are numpy arrays; threshold is in the same units.&quot;&quot;&quot;\r\n\r\n    # Determine crossing points, as a fraction of the day\r\n    plus_over_2 = (mins + maxs)\/2\r\n    minus_over_2 = (maxs - mins)\/2\r\n    two_pi = 2*np.pi\r\n    # d0s is the times of crossing above; d1s is when cross below\r\n    d0s = np.arcsin((threshold - plus_over_2) \/ minus_over_2) \/ two_pi\r\n    d1s = .5 - d0s\r\n\r\n    # If always above or below threshold, set crossings accordingly\r\n    aboves = mins &gt;= threshold\r\n    belows = maxs &lt;= threshold\r\n\r\n    d0s&#x5B;aboves] = 0\r\n    d1s&#x5B;aboves] = 1\r\n    d0s&#x5B;belows] = 0\r\n    d1s&#x5B;belows] = 0\r\n\r\n    # Calculate integral\r\n    F1s = -minus_over_2 * np.cos(2*np.pi*d1s) \/ two_pi + plus_over_2 * d1s\r\n    F0s = -minus_over_2 * np.cos(2*np.pi*d0s) \/ two_pi + plus_over_2 * d0s\r\n    return np.sum(F1s - F0s - threshold * (d1s - d0s))\r\n\r\ndef get_gddkdd(mins, maxs, gdd_start, kdd_start):\r\n    &quot;&quot;&quot;Get the Growing Degree-Days, as degree-days between gdd_start and\r\nkdd_start, and Killing Degree-Days, as the degree-days above\r\nkdd_start.\r\n\r\nmins and maxs are numpy arrays; threshold is in the same units.&quot;&quot;&quot;\r\n\r\n    dd_lowup = above_threshold(mins, maxs, gdd_start)\r\n    dd_above = above_threshold(mins, maxs, kdd_start)\r\n    dd_lower = dd_lowup - dd_above\r\n\r\n    return (dd_lower, dd_above)\r\n<\/pre>\n<p>Download the code for <a href=\"https:\/\/github.com\/jrising\/research-common\/blob\/master\/R\/gdd.R\">R<\/a> or <a href=\"https:\/\/github.com\/jrising\/research-common\/blob\/master\/python\/gdd.py\">python<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Schlenker and Roberts (2009) use daily minimum and maximum temperatures to calculate growing degrees, rather than daily mean temperatures. This is important when the effect of extreme temperatures is an issue, since these often will not show up in mean temperatures. Growing degree days form a useful model of crop productivity. DMAS has examples of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3,4],"tags":[],"class_list":["post-156","post","type-post","status-publish","format-standard","hentry","category-research","category-software"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4Zh9E-2w","_links":{"self":[{"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=156"}],"version-history":[{"count":0,"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=\/wp\/v2\/posts\/156\/revisions"}],"wp:attachment":[{"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/existencia.org\/pro\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}