<?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 Re: Creating a list of raster lists in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68102#M5564</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gerry and Neil,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for looking into my issue. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Either I was unclear in my explanation or I am not understanding your explanation. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure how this will help me make a separate list for each year's winter in the dataset. There are 11 years worth of data in the same folder. The only months I downloaded for each year are 11,12,1,2 and 3 so I don't need to separate out winter months. What I need to separate are the years(e.g., winter of '03-'04). This is a challenge because months 1, 2, and 3 need to be assigned to the previous calendar year. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 24 Oct 2014 19:57:46 GMT</pubDate>
    <dc:creator>JamesKelly2</dc:creator>
    <dc:date>2014-10-24T19:57:46Z</dc:date>
    <item>
      <title>Creating a list of raster lists</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68099#M5561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am a beginner at python programming, and this is my first post to GeoNet. So here it goes!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a huge list of rasters downloaded from the &lt;A href="http://nsidc.org/data/docs/noaa/g02158_snodas_snow_cover_model/"&gt;SNODAS &lt;/A&gt;website for years 2003 - present (intra-annual range of 11/1-3/31). I have a .tif file for everyday during this period which contains the snow depth data for that day. The metadata for each raster is stored in the tif file's name(e.g., us_ssmv11036tS__T0001TTNATS2013111305HP001.dat.reproj.tif ). However, I am only interested in the date (Nov. 13, 2013 in this case). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My objective is to split this huge list of rasters into winter-years (i.e., rasters from Jan-Mar of a given year belong to the winter-year of the previous calendar year) so that I can pass each winter-year list of rasters through the greaterThanFrequency tool with a simple loop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is a script that works if I download one year of data at a time. I'd appreciate any feedback on how get a list of rasters for each winter-year. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1413993913034842 jive_text_macro" jivemacro_uid="_1413993913034842"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;from arcpy import env&lt;/P&gt;
&lt;P&gt;from arcpy.sa import *&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;env.workspace = "E:\DECGIS\snow\NSIDC\projects" \&lt;/P&gt;
&lt;P&gt;"\Searchlight\production\data\NSIDC_Data_1021063617170" \&lt;/P&gt;
&lt;P&gt;"\Snow_Data_Assimilation_System_(SNODAS)_Data_Products_at_NSIDC"&lt;/P&gt;
&lt;P&gt;env.overwriteOutput = True&lt;/P&gt;
&lt;P&gt;arcpy.env.snapRaster = "us_ssmv11036tS__T0001TTNATS2013111305HP001.dat.reproj.tif"&lt;/P&gt;
&lt;P&gt;arcpy.env.outputCoordinateSystem = "us_ssmv11036tS__T0001TTNATS2013111305HP001.dat.reproj.tif"&lt;/P&gt;
&lt;P&gt;arcpy.env.nodata = "-9999"&lt;/P&gt;
&lt;P&gt;inRasters = arcpy.ListRasters("*", "TIF")&lt;/P&gt;
&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#create raster of constant values for greaterThanFrequency tool&lt;/P&gt;
&lt;P&gt;constantValue = "381"&lt;/P&gt;
&lt;P&gt;outpath3 = str(env.workspace+"\\threshold4.tif")&lt;/P&gt;
&lt;P&gt;cellSize = '8.33333333813986E-03'&lt;/P&gt;
&lt;P&gt;outConstRaster = CreateConstantRaster(constantValue, 'INTEGER', cellSize,"us_ssmv11036tS__T0001TTNATS2013111305HP001.dat.reproj.tif")&lt;/P&gt;
&lt;P&gt;outConstRaster.save(outpath3)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#run greater than frequency analysis&lt;/P&gt;
&lt;P&gt;inValueRaster = "threshold4.tif"&lt;/P&gt;
&lt;P&gt;outGTF = GreaterThanFrequency(inValueRaster, inRasters)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Save the output &lt;/P&gt;
&lt;P&gt;outGTF.save(r"E:\DECGIS\snow\output\2013daysGt15.tif")&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Oct 2014 16:10:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68099#M5561</guid>
      <dc:creator>JamesKelly2</dc:creator>
      <dc:date>2014-10-22T16:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of raster lists</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68100#M5562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;James,&lt;/P&gt;&lt;P&gt;Assuming you have all the tiffs in one directory, and assuming the tiff file names are of the same length, you could sift through all the files in the folder, find which files were winter months, create a list of those file names, and then execute you code after the list of file names is complete.&amp;nbsp; This gets the file names, splits and slices out the month, and writes the file name to a new list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14142984031179782 jive_text_macro" jivemacro_uid="_14142984031179782"&gt;
&lt;P&gt;import&amp;nbsp; os&lt;/P&gt;
&lt;P&gt;indir = ""#YOUR DIRECTORY OF TIFFS&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#Create an empty list to store all the file names for winter months....&lt;/P&gt;
&lt;P&gt;listofdatatoprocess = []&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#Get the files in the directory....&lt;/P&gt;
&lt;P&gt;for root, directories, files in os.walk(indir):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in files:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filenamesplit = filename.split(".")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #extract the month...&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; month = filenamesplit[0][31:33]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if month == '11' or month == '12' or month == '01' or month == '02' or month == '03':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listofdatatoprocess.append(filename)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;for item in listofdatatoprocess:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #YOUR CODE HERE&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Oct 2014 20:33:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68100#M5562</guid>
      <dc:creator>GerryGabrisch</dc:creator>
      <dc:date>2014-10-22T20:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of raster lists</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68101#M5563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And you could replace that if month == ...&lt;/P&gt;&lt;P&gt;With&lt;/P&gt;&lt;P&gt;if month in ['11','12','01','02','03'] :&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Oct 2014 11:50:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68101#M5563</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2014-10-23T11:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of raster lists</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68102#M5564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gerry and Neil,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for looking into my issue. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Either I was unclear in my explanation or I am not understanding your explanation. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure how this will help me make a separate list for each year's winter in the dataset. There are 11 years worth of data in the same folder. The only months I downloaded for each year are 11,12,1,2 and 3 so I don't need to separate out winter months. What I need to separate are the years(e.g., winter of '03-'04). This is a challenge because months 1, 2, and 3 need to be assigned to the previous calendar year. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2014 19:57:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68102#M5564</guid>
      <dc:creator>JamesKelly2</dc:creator>
      <dc:date>2014-10-24T19:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of raster lists</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68103#M5565</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Here's a simple approach, generate a list of year/month/days, and then convert the list into raster paths. &lt;/SPAN&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;We could get fancier with the datetime module but I think this should work fine. I set this up for 2003 / 2004 but you could nest this inside a loop to process each year at a time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_1414299736213948" jivemacro_uid="_1414299736213948"&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;# us_ssmv11036tS__T0001TTNATS2013111305HP001.dat.reproj.tif&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;daylist = []&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;year = 2003&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;for mon in [11, 12]:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for day in range(1,32):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; daylist.append("{:04d}{:02d}{:02d}".format(year,mon,day))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;year += 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;for mon in [1,2,3]:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for day in range(1,32):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; daylist.append("{:04d}{:02d}{:02d}".format(year,mon,day))&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;# convert the day list into tif pathnames&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;tpath = "&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;us_ssmv11036tS__T0001TTNATS{}05HP001.dat.reproj.tif"&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;rpaths = [tpath.format(d) for d in daylist]&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;# if the raster exists, create a raster object and add to the list&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;# this raster list is the one you can pass to your tool&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;rasters = [Raster(rpath) for rpath in rpaths if arcpy.Exists(rpath)]&lt;/SPAN&gt;&lt;/P&gt;





&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 26 Oct 2014 05:04:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68103#M5565</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-10-26T05:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a list of raster lists</title>
      <link>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68104#M5566</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Curtis! This is exactly what I need!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Oct 2014 17:52:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-a-list-of-raster-lists/m-p/68104#M5566</guid>
      <dc:creator>JamesKelly2</dc:creator>
      <dc:date>2014-10-27T17:52:56Z</dc:date>
    </item>
  </channel>
</rss>

