|
POST
|
Hi, I've hard coded and simplified the script to facilitate readability. I'm still getting the same kind of errors with the Con calculation. This calculation works in raster calculator. In fact, it works also as a separate script that I had been using within Model Builder. Consequently, I'm lost!! Please see below images and code. IMAGES: Image "errorA": Apparently the error may seem to be related to the operand "/" Image "errorB": If I change that "/" operand by "*" (just to try something) I get this error Image "errorC": If I change that "/" operand by "+" the error goes to the next line until encounters the next "/" operand [ATTACH=CONFIG]30093[/ATTACH] [ATTACH=CONFIG]30094[/ATTACH] [ATTACH=CONFIG]30095[/ATTACH] CODE: import arcpy
import string
from arcpy import env
arcpy.env.overwriteOutput=True
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
# Inputs / Output
NPP = r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL_MODEL\LFP_GLOBAL_Python\OUTPUT.gdb\NPP"
ZforCDF = r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL_MODEL\LFP_GLOBAL_Python\OUTPUT.gdb\ZforCDF"
OutRasterlayer = r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL_MODEL\LFP_GLOBAL_Python\OUTPUT.gdb\CDF_NEW"
# Calculate CDF
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(OutRasterlayer) Any help will be greatly appreciated Thanks
... View more
12-24-2013
12:58 AM
|
0
|
0
|
2309
|
|
POST
|
Hi Doug, Thanks a lot for your comments, I'm taking note. The code I'm showing is simplified in terms of not including all the "elif" statements (different NPP and CDF equations) so there is nothing "extra" that may cause the error in the rest of the code (I should think). I'm getting the error in the line AFTER "if CDFEquation == "1. Suess 1980":", that is in the first Con calculation. ZforCDF and NPP have been previously defined so I don't quite understand this error. I'm not sure either how to use the OutLocation variable to define the output path and name of that Con calculation. I'll hard code the variables and see what happen. Thanks a lot. Toni
... View more
12-23-2013
12:15 PM
|
0
|
0
|
2309
|
|
POST
|
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: [ATTACH=CONFIG]30072[/ATTACH] 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
... View more
12-23-2013
04:45 AM
|
0
|
7
|
2766
|
|
POST
|
Thanks a lot guys. I tried the print NPPEquation and it works fine. "Min NPP1" is one of the values in the filter list. The thing is that I've set the output raster dataset to include the name of the NPPEquation ("Min NPP" for example). So I guess is not the right approach to have spaces in the string variable names. Not sure if there is a way round that... Cheers Toni
... View more
12-20-2013
06:03 AM
|
0
|
0
|
971
|
|
POST
|
Hi, I have an issue with my script related to the space in the string variable (see below). If "MinNPP" is used instead it works fine. I've also tried setting the variable as str(arcpy.GetParameterAsText(6)) but it doesn't work either. The variable is set as String data type in the tool; Filter = Value list. Version used is 10.0 Variable: NPPEquation = arcpy.GetParameterAsText(6) Process: if NPPEquation == "Min NPP1": Thank you Toni
... View more
12-20-2013
05:15 AM
|
0
|
6
|
1239
|
|
POST
|
Thanks a lot Jake. Really useful indeed. I actually have another issue with the same script related to strings. I'll explain that in a new post. Many thanks
... View more
12-20-2013
05:04 AM
|
0
|
0
|
1374
|
|
POST
|
Hi Jake, It does work your way also. I did remove the "arcpy.Raster". In my toolbox I set the data as "Raster Layer". I guess it doesn't make any difference compared to"Raster Dataset" in this case (I've tried and both work). When I tried when you first suggested I had env.mask = InputZ written before InputZ = arcpy.GetParameterAsText(0) when it should go after. It works also like this: env.mask = str(InputZ) Many thanks Toni
... View more
12-20-2013
03:55 AM
|
0
|
0
|
1374
|
|
POST
|
Hi again Jake, It works like this: arcpy.env.mask = str(InputZ) Many thanks again Toni
... View more
12-20-2013
02:31 AM
|
0
|
0
|
1374
|
|
POST
|
Thanks Jake, I just tried that with and without parentheses for the env.mask but I'm getting the message "InputZ is not defined" Cannot find the way really... Many thanks Toni
... View more
12-20-2013
02:04 AM
|
0
|
0
|
1374
|
|
POST
|
Hi everyone, This may seem like an easy one but I cannot quite find the way: When setting the environments, I want to use one of the parameters ("InputZ") as a mask for the different processes within the script. It works fine like this: arcpy.env.mask = r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL_MODEL\INPUT.gdb\Maas_Bathymetry" but I want this: arcpy.env.mask = (InputZ) using ArcView 10.0 here is the beginning of the code: import arcpy import string from arcpy import env arcpy.env.overwriteOutput=True from arcpy.sa import * arcpy.CheckOutExtension("Spatial") # Set the output location, extent and Mask OutLocation = arcpy.GetParameterAsText(0) arcpy.env.extent = arcpy.Extent(-180.0, -90.0, 180.0, 90.0) arcpy.env.mask = (InputZ) # Input strings and variables StageAge = str(arcpy.GetParameterAsText(1)) BSS = arcpy.Raster(arcpy.GetParameterAsText(2)) InputLatitude = arcpy.Raster(arcpy.GetParameterAsText(3)) InputZ = arcpy.Raster(arcpy.GetParameterAsText(4)) InputCountrylines = arcpy.GetParameterAsText(5) NPPEquation = str(arcpy.GetParameterAsText(6)) Any help will be greatly appreciated. Many thanks
... View more
12-19-2013
11:34 PM
|
0
|
7
|
1907
|
|
POST
|
Thanks a lot Duncan. That is exactly what happened...silly enough... The outputs of Raster Calculator are made Intermediate by the model (if I'm not wrong) even though there are not connected to a further process. I made sure (but not entirely) that all those outputs where unticked for the Intermediate option but I overlooked that one. Many thanks Toni
... View more
10-10-2013
07:59 AM
|
0
|
0
|
1135
|
|
POST
|
Hi all, I'm running a model that produces 34 different raster outputs. When I run the model from within the model window I can see all 34 outputs in the corresponding database. However, when I run the model from the toolbox only 33 outputs appear in the database. It is always the same raster dataset that is missing. After checking the processing window (see attached) I can see that the raster dataset in question is produced, it just doesn't show in the database. Obviously, I've checked workspaces, paths, etc... I'm running the model in 10.0. Any ideas about why this may happen would be greatly appreciated. Many thanks Toni
... View more
10-10-2013
04:41 AM
|
0
|
3
|
4563
|
|
POST
|
Thanks a lot James. I had already considered this option. Problem is that when I convert from raster to polygon some cells get merged together so I would lose the true area of several cells and I do need to get the area right for each cell prior to calculating volume. Thanks toni
... View more
08-27-2013
01:50 AM
|
0
|
0
|
1179
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-06-2015 05:13 AM | |
| 1 | 11-09-2015 01:25 AM | |
| 1 | 11-12-2014 05:27 AM |
| Online Status |
Offline
|
| Date Last Visited |
07-12-2022
09:52 AM
|