0

I am trying to calculate Area solar radiation for rasters in a list.

It seems that the tool allows to create unique rasters for direct, diffuse and direct radiation duration, and calculates outGlobalRadiation as the final output.

But, when I define the names for the direct, diffuse and direct radiation duration rasters, I got back an error RuntimeError: ERROR 000732: Input Raster: Dataset dir_1 does not exist or is not supported meaning, that my optional output file is actually considered as Input Raster, and does not exist.

Do you understand this error? Or is there any logical error in my script?

import arcpy, os
from arcpy.sa import *

arcpy.CheckOutExtension("spatial")

# Get path
inWD = "C:/Users/2019_bioESS_coord"

# Set working environment
arcpy.env.workspace = os.path.join(inWD, "output/bufRastTwins.gdb")
arcpy.env.overwriteOutput = True

# List all rasters
rasters= arcpy.ListRasters("r_*")


# Calculate solar radiation with defined optional outputs
for raster in rasters:

    # Define names for output optional rasters
    outNameDirect = "dir_" + raster.replace("r_", "")
    outNameDiff = "diff_" + raster.replace("r_", "")
    outNameDirDur = "dirDur_" + raster.replace("r_", "")

    # Define parameters for solar radiation
    in_surface_raster = raster
    latitude = ""
    skySize = 200
    timeConfig = TimeMultipleDays(2018, 100, 150)
    dayInterval = 10    # default 14
    hourInterval = 12   # default 0.5
    each_interval = "NOINTERVAL"  # "INTERVAL"
    zFactor = ""
    calcDirections = 32
    zenithDivisions = 8
    azimuthDivisions = 8
    diffuseProp = 0.3
    transmittivity = 0.5

    # Set names for optional output rasters, seems not working???
    outDirectRad = arcpy.Raster(outNameDirect)  
    outDiffuseRad = arcpy.Raster(outNameDiff)
    outDirectDur =  arcpy.Raster(outNameDirDur) 


    # Execute AreaSolarRadiation
    outGlobalRad = arcpy.sa.AreaSolarRadiation(in_surface_raster, latitude, skySize, timeConfig,
                                               dayInterval, hourInterval, each_interval, zFactor, "FROM_DEM" ,
                                               calcDirections, zenithDivisions, azimuthDivisions, "UNIFORM_SKY",
                                               diffuseProp, transmittivity,
                                               outDirectRad, outDiffuseRad, outDirectDur)

    print("area radiation saving")
    # Save the output 
    outGlobalRad.save(raster.replace("r_", "globRad_"))
  • Does "dir_1" exist? you are giving it as input to arcpy.Raster apparently (in your line outDirectRad = arcpy.Raster(outNameDirect)) function which requires an input raster to be passed. If it does not exist, I guess it will simply fail. – umbe1987 Aug 26 '19 at 13:33
  • No, it does not exists. Instead, I would like to create it as optional output data and define its name. Neither assesing the name as outNameDirect = "dir_" + raster.replace("r_", "") or declaring it directly with the path works: os.path.join(inWD, "output", outNameDirect). How could I declare it, that it is not considered as Input but as and Output? Seems trivial, but I cannot find a solution. – maycca Aug 26 '19 at 13:41
1

I think to make your script work you should:

  1. remove all the arcpy.Raster() calls
# Set names for optional output rasters, seems not working???
outDirectRad = arcpy.Raster(outNameDirect)  
outDiffuseRad = arcpy.Raster(outNameDiff)
outDirectDur =  arcpy.Raster(outNameDirDur)
  1. change the call to arcpy.sa.AreaSolarRadiation like this:
# Execute AreaSolarRadiation
outGlobalRad = arcpy.sa.AreaSolarRadiation(in_surface_raster, latitude, skySize, timeConfig,
                                           dayInterval, hourInterval, each_interval, zFactor, "FROM_DEM" ,
                                           calcDirections, zenithDivisions, azimuthDivisions, "UNIFORM_SKY",
                                           diffuseProp, transmittivity,
                                           arcpy.Raster(outNameDirect), arcpy.Raster(outNameDiff), arcpy.Raster(outNameDirDur))

If it works, the reason is that arcpy.Raster documentation reads that:

A raster object can be created in two ways, by supplying the path to an existing raster on disk, or it can be the result of any Map Algebra statement that results in a raster output.

So, either you give an existent raster, or (as in your case) the input is generated by a function (internally I guess arcpy.sa.AreaSolarRadiation is doing this for you).

|improve this answer|||||
  • Thank you for your suggestion @umbe1987 but it still looks for raster dir_1. Also, I think that my script mimics ArcGIS help, where new rasters are created in the same way, and later included in AreaSolarRadiation tool: outDirectDur = Raster("C:/sapyexamples/output/dir_dur"), more here: desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/…. Do you maybe have another advices? – maycca Aug 27 '19 at 7:22
  • In the example in the link you provided I see they are referencing a full path, not just the name of the output raster. Try for instance calling Raster(os.path.join(inWD, "output/bufRastTwins.gdb",outNameDirect)) (also fot the other two optional rasters), and see if it works. – umbe1987 Aug 27 '19 at 7:40
  • Also, might be better to do inWD = r"C:/Users/2019_bioESS_coord" instead of inWD = "C:/Users/2019_bioESS_coord" (add the r in front of the path) – umbe1987 Aug 27 '19 at 7:42

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.