0

I am trying to execute this equation through multi raster, but i am getting error massage in TScalar2 function, error message shown here

Message File Name   Line    Position    
Traceback               
    <module>    D:\Arc-GIS-Python-Script\T_SCALAR.py    23      
RuntimeError: ERROR 000732: Input Raster: Dataset Mean_Temp_010.tif does not exist or is not supported

). Below i have attached my code.

import arcpy, os, calendar
from arcpy.sa import *
arcpy.env.overwriteOutput = True
arcpy.CheckOutExtension("Spatial")
arcpy.env.parallelProcessingFactor = "100%"
topWorkspace = r'D:\SWAT-WEATHER-DATA2'
ws_out = r'D:\SWAT-WEATHER-DATA2\TScalar' ### Output folder!!!
arcpy.env.workspace = topWorkspace

# Get dict of months and month-number (i.e. January = 001, March = 003 etc.)
months = {calendar.month_name[i].upper(): str(i).zfill(3) for i in range(1, 13)} # Get dict of months and month number (i.e. January = 001, March = 003 etc.)


# Step through list of all folders
for folderPath in arcpy.ListWorkspaces():
    baseName = os.path.basename(folderPath).upper()
    if baseName in months: # Test that subfolder is a month name
        monthNumber = months[baseName] # Get month-number for use in output filename
        arcpy.env.workspace = folderPath

        # Raster1 take Mean_Temp raster from all month folder(e.g for january: 001_Mean_temp.tif) and Raster 2 is constant month of october raster
        rasterList1 = arcpy.ListRasters('*Mean_Temp.tif')
        rasterList2 = arcpy.Raster('*Mean_Temp_010.tif')

        # combine list raster into equation
        TScalar1 = 1.1814 / (1+Exp(0.2 * (rasterList2 - 10 - rasterList1)))
        TScalar2 = 1 / (1+Exp(0.3 * (- rasterList2 - 10 + rasterList1)))

        if len(rasterList) > 1:

        #Print raster list
         #print rasterList

        # Multiply of TScalar1 and TScalar2 rasters 
         TScalar = (TScalar1 * TScalar2)

        #Save the output
        outRasterName = os.path.join(ws_out, "T_SCALAR_{}.tif".format(monthNumber))
        TScalar.save(outRasterName)
        print outRasterName


#print done
print 'done' 

Updated code shown here along with error massage

Message File Name   Line    Position
        Traceback
            <module>    D:\Arc-GIS-Python-Script\T_SCALAR.py    27
            Minus   C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Functions.py 3840
            swapper C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Utils.py 47
            wrapper C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy\sa\Functions.py 3837
        TypeError: expected a raster or layer name

    import arcpy, os, calendar
    from arcpy.sa import *
    from arcpy import env
    arcpy.env.overwriteOutput = True
    arcpy.CheckOutExtension("Spatial")
    arcpy.env.parallelProcessingFactor = "100%"
    topWorkspace = r'D:\SWAT-WEATHER-DATA2'
    ws_out = r'D:\SWAT-WEATHER-DATA2\TScalar' ### Output folder!!!
    arcpy.env.workspace = topWorkspace
    # Get dict of months and month-number (i.e. January = 001, March = 003 etc.)
    months = {calendar.month_name[i].upper(): str(i).zfill(3) for i in range(1, 13)} # Get dict of months and month number (i.e. January = 001, March = 003 etc.)


    # Step through list of all folders
    for folderPath in arcpy.ListWorkspaces():
        baseName = os.path.basename(folderPath).upper()
        if baseName in months: # Test that subfolder is a month name
            monthNumber = months[baseName] # Get month-number for use in output filename
            arcpy.env.workspace = folderPath

            # Raster1 take Mean_Temp raster from all month folder(e.g for january: Mean_temp_001.tif) and Raster 2 is constant month of october raster
            rasterList1 = arcpy.ListRasters(r'Mean_Temp*.tif')
            rasterList2 = arcpy.Raster(r'D:\SWAT-WEATHER-DATA2\OCTOBER\Mean_Temp_010.tif')


            # combine list raster into equation
            TScalar1 = 1.1814 / ((1 + Exp(0.2 * (rasterList2 - 10 - rasterList1))))
            TScalar2 = 1 / (1 + Exp(0.3 * (- rasterList2 - 10 - rasterList1)))

            #Print raster list
             #print rasterList

            # Execute CellStatistics
            TScalar = (TScalar1 * TScalar2)

            #Save the output
            outRasterName = os.path.join(ws_out, "T_SCALAR_{}.tif".format(monthNumber))
            TScalar.save(outRasterName)
            #print outRasterName

    if __name__ == '__main__':
        main()


    #print done
    #print 'done'
  • error-000732 is pretty common so have you reviewed the past Q&As on it? – PolyGeo Aug 25 '16 at 7:24
  • I have tried but could no able to fix the error. – Shouvik Jha Aug 25 '16 at 7:34
1

You need to fix this line rasterList2 = arcpy.Raster('*Mean_Temp_010.tif')

It should probably be

rasterList2 = arcpy.Raster('*Mean_Temp_{}.tif'.format(monthNumber))

It's looping through each folder and can't find *Mean_Temp_010.tif in any of them as that file is only in your OCTOBER folder (as per your other questions).

If you specifically need the October images, then you either need to make the 010 images available to all folders (include the path to the October image) or copy that image into each folder, something like:

rasterList2 = arcpy.Raster(r'D:\SWAT-WEATHER-DATA2\OCTOBER\*Mean_Temp_010.tif')
  • Thank you. i have ran the modified line rasterList2, but still i am getting the same error, file not exist or not supported – Shouvik Jha Aug 25 '16 at 8:16
  • Does it exist? What is the path to that file? – Midavalo Aug 25 '16 at 8:18
  • same path, which you mentioned in your command line – Shouvik Jha Aug 25 '16 at 8:19
  • i copied the path of raster2 direct from folder D:\SWAT-WEATHER-DATA2\OCTOBER\Mean_Temp_010.tif – Shouvik Jha Aug 25 '16 at 8:22
  • please suggest me, how do i fix the following error. – Shouvik Jha Aug 25 '16 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.