Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Unsupported operand error

$
0
0
Hello,

I'm getting an error in my script that I cannot quite understand (I'm pretty new to python).

Please see below code (simplified version) and error (image).

The error comes from the "Calculation of Parameter 5". I've tested the Conditional statement in raster calculator and it works fine.
I've actually used even more complex Conditional statements within the same script (I'm showing a simplified version here) with no problems at all.

The other thing I'm not sure about is how to use the "OutLocation" variable (Parameter 0) within the save Method for the output of Parameter 5 (CDF). In the Help they only mention the use of the full path for the output.
I've tried with this: CDF.save(OutLocation) + "CDF3" but there is obviously something wrong. Using ArcView 10.0

ERROR:

Attachment 30072

CODE:

Code:

import arcpy
import string
from arcpy import env
arcpy.env.overwriteOutput=True
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")


# Set the output location and extent

OutLocation = arcpy.GetParameterAsText(0)

arcpy.env.extent = arcpy.Extent(-180.0, -90.0, 180.0, 90.0)


# Input strings, variables and mask

StageAge = str(arcpy.GetParameterAsText(1))

BSS = arcpy.Raster(arcpy.GetParameterAsText(2))

InputLatitude = arcpy.Raster(arcpy.GetParameterAsText(3))

InputZ = arcpy.GetParameterAsText(4)

InputCountrylines = arcpy.GetParameterAsText(5)

NPPEquation = str(arcpy.GetParameterAsText(6))

CDFEquation = str(arcpy.GetParameterAsText(7))

env.mask = InputZ

# Calculate latitude North/South, offshore distance and Z for CDF Equations; also set the "0" values from Offshoredistance and Bathymetry to "1"

LatNorth = Con((InputLatitude > 0),(InputLatitude))
LatSouth = Con((InputLatitude < 0),(InputLatitude))
Offshoredistancemin0 = EucDistance(InputCountrylines, "", 0.5, "")
Offshoredistance = Con((Offshoredistancemin0 == 0),1,(Offshoredistancemin0))
InputZ = Con((InputZ == 0),1,(InputZ))
ZforCDF = Con((InputZ) >50, (InputZ))


# Calculation of Parameter 4 - Net Primary Productivity (NPP). Check the NPP Equation Name and follow the appropiate branch

if NPPEquation == "Min NPP":

    rasterNorth = (-1.9875 * (LatNorth) + 194)
    rasterSouth = (2.3377 * (LatSouth) + 200)

    NPP = arcpy.MosaicToNewRaster_management([(rasterNorth), (rasterSouth)], OutLocation, (StageAge) + "_MinNPP", "", "32_BIT_FLOAT", "", "1", "LAST", "FIRST")

elif NPPEquation == "Max NPP":

    rasterNorth = (-8.0488 * (LatNorth) + 840)
    rasterSouth = (9.6104 * (LatSouth) + 840)

    NPP = arcpy.MosaicToNewRaster_management([(rasterNorth), (rasterSouth)], OutLocation, (StageAge) + "_MaxNPP", "", "32_BIT_FLOAT", "", "1", "LAST", "FIRST")


# Calculation of Parameter 5 - Carbon Delivery Flux (CDF). Check the CDF Equation Name and follow the appropiate branch

if CDFEquation == "1. Suess 1980":

    CDF = Con((ZforCDF >= 50) & (ZforCDF < 100), ((0.049 * (Power((NPP), 1.41)) + (NPP) / ((0.0238 * 50) + (0.212))) / 2) - ((((0.049 * (Power((NPP), 1.41)) +
    (NPP) / ((0.0238 * 50) + (0.212))) / 2) - ((NPP) / ((0.0238 * 100) + (0.212)))) / 50)  * ((ZforCDF) - 50), (NPP) / ((0.0238 * (ZforCDF)) + (0.212)))

    CDF.save(OutLocation)

elif CDFEquation == "2. Suess 1980 mod":

    CDF = Con((ZforCDF >= 50) & (ZforCDF < 100),  (0.049 * (Power((NPP), 1.41))) - ((((0.049 * (Power((NPP),1.41))) - (27.1 * (Power((NPP) / 100,0.935)))) / 50) *
    ((ZforCDF) - 50)), 27.1 * (Power((NPP) / (ZforCDF),0.935)))

    CDF.save(OutLocation)



Many thanks for your help

Toni
Attached Thumbnails
Click image for larger version

Name:	error.JPG‎
Views:	N/A
Size:	69.5 KB
ID:	30072  

Viewing all articles
Browse latest Browse all 2485