<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Loop conditional in raster calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-conditional-in-raster-calculator/m-p/95738#M7441</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have daily rainfall data in milimeters in GeoTIFF format with naming convention chirps_YYYYMMDD.tif (example chirps_20100101.tif), and I also have 1 raster of dry-spell with name dslr_chirps_20091231.tif and both raster have same spatial resolution and extent.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I would like to calculate dry-spell for 1 Jan 2010, IF(rainfall&amp;gt;1,dslr=0,dslr+1). Using raster calculator I can use this formula: Con("chirps_20100101.tif" &amp;gt; 1, "dslr_chirps_20091231.tif" == 0, "dslr_chirps_20101231.tif" + 1)&lt;/P&gt;&lt;P&gt;The raster output will be dslr_chirps_20180101.tif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem:&lt;BR /&gt;I have 10 years daily rainfall data and would like to calculate daily dry-spell for all the available data period.&lt;/P&gt;&lt;P&gt;How to loop the above calculation using model builder, when the output for each calculation will use as input for the next calculation?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Dec 2019 03:23:46 GMT</pubDate>
    <dc:creator>BennyIstanto</dc:creator>
    <dc:date>2019-12-05T03:23:46Z</dc:date>
    <item>
      <title>Loop conditional in raster calculator</title>
      <link>https://community.esri.com/t5/python-questions/loop-conditional-in-raster-calculator/m-p/95738#M7441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have daily rainfall data in milimeters in GeoTIFF format with naming convention chirps_YYYYMMDD.tif (example chirps_20100101.tif), and I also have 1 raster of dry-spell with name dslr_chirps_20091231.tif and both raster have same spatial resolution and extent.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I would like to calculate dry-spell for 1 Jan 2010, IF(rainfall&amp;gt;1,dslr=0,dslr+1). Using raster calculator I can use this formula: Con("chirps_20100101.tif" &amp;gt; 1, "dslr_chirps_20091231.tif" == 0, "dslr_chirps_20101231.tif" + 1)&lt;/P&gt;&lt;P&gt;The raster output will be dslr_chirps_20180101.tif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem:&lt;BR /&gt;I have 10 years daily rainfall data and would like to calculate daily dry-spell for all the available data period.&lt;/P&gt;&lt;P&gt;How to loop the above calculation using model builder, when the output for each calculation will use as input for the next calculation?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2019 03:23:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-conditional-in-raster-calculator/m-p/95738#M7441</guid>
      <dc:creator>BennyIstanto</dc:creator>
      <dc:date>2019-12-05T03:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Loop conditional in raster calculator</title>
      <link>https://community.esri.com/t5/python-questions/loop-conditional-in-raster-calculator/m-p/95739#M7442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know how to do this in the model builder - but with python maybe you could define your input data and output with the following code?&lt;/P&gt;&lt;P&gt;It's from: &lt;A class="link-titled" href="https://stackoverflow.com/questions/1060279/iterating-through-a-range-of-dates-in-python" title="https://stackoverflow.com/questions/1060279/iterating-through-a-range-of-dates-in-python" rel="nofollow noopener noreferrer" target="_blank"&gt;datetime - Iterating through a range of dates in Python - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; datetime &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; timedelta&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; date

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;daterange&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;start_date&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; end_date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; n &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; range&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;int &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;end_date &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt; start_date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;days&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;yield&lt;/SPAN&gt; start_date &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; timedelta&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;n&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

start_date &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2009&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;12&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;31&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
end_date &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2010&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;12&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;31&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; single_date &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; daterange&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;start_date&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; end_date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    
    d &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; single_date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%Y%m%d"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    
    d1 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; single_date&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;timedelta&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;days&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    d2 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; d1&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%Y%m%d"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    
    input1 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"DSLR_CHIRPS_{}.tif"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;d&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    input2 &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"CHIRPS_{}.tif"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;d2&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    output &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"DSLR_CHIRPS_{}.tif"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;d2&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

    &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"{} - {} - {}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;input1&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; input2&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; output&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:39:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-conditional-in-raster-calculator/m-p/95739#M7442</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2021-12-10T23:39:19Z</dc:date>
    </item>
    <item>
      <title>Re: Loop conditional in raster calculator</title>
      <link>https://community.esri.com/t5/python-questions/loop-conditional-in-raster-calculator/m-p/95740#M7443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your reply, I will try it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2019 10:45:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-conditional-in-raster-calculator/m-p/95740#M7443</guid>
      <dc:creator>BennyIstanto</dc:creator>
      <dc:date>2019-12-05T10:45:38Z</dc:date>
    </item>
  </channel>
</rss>

