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)Solved! Go to Solution.
NPP = arcpy.Raster(arcpy.MosaicToNewRaster_management([(rasterNorth), (rasterSouth)], OutLocation, (StageAge) + "_MinNPP", "", "32_BIT_FLOAT", "", "1", "LAST", "FIRST"))
NPPEquation = str(arcpy.GetParameterAsText(6))
NPPEquation = arcpy.GetParameterAsText(6)
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)NPP = arcpy.Raster(r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL_MODEL\LFP_GLOBAL_Python\OUTPUT.gdb\NPP")
If NPP and ZforCDF are rasters on disk, shouldn't they be referenced to Raster objects before all that long calculation?
Like :NPP = arcpy.Raster(r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL_MODEL\LFP_GLOBAL_Python\OUTPUT.gdb\NPP")
etc
folder = 'C:\\' file = 'a_file.txt' full_path = folder + file
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 = arcpy.GetParameterAsText(1)
BSS = arcpy.Raster(arcpy.GetParameterAsText(2))
InputLatitude = arcpy.Raster(arcpy.GetParameterAsText(3))
InputZ = arcpy.GetParameterAsText(4)
InputCountrylines = arcpy.GetParameterAsText(5)
NPPEquation = arcpy.GetParameterAsText(6)
CDFEquation = arcpy.GetParameterAsText(7)
env.mask = InputZ
# Calculate latitude North/South and offshore distance; 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))
InputZ1 = Con((InputZ == 0),1,(InputZ))
ZforCDF = Con((InputZ1) >50, (InputZ1))
# Calculation of Parameter 3 - Background Total Organic Carbon (TOC)
range1 = Con(((BSS) < 0.0378), (BSS))
range1phi = Con((range1), 6.11)
range2 = Con(((BSS) >= 0.0378) & ((BSS) <= 0.47), (BSS))
range2mm = 0.0593-(1.7714*(range2))+(18.7109*Power((range2),2))-(22.7289*Power((range2),3))
range2phi = -3.3219*Log10((range2mm))
range3 = Con(((BSS) > 0.47), (BSS))
range3mm = 0.8381 + (1.2188*(range3)) - (0.0007*Power((range3),2))
range3phi = -3.3219*Log10((range3mm))
GrainSizephi = arcpy.MosaicToNewRaster_management([(range1phi), (range2phi), (range3phi)], OutLocation, (StageAge) + "_Grain_Size_phi", "", "32_BIT_FLOAT", "", "1", "LAST", "FIRST")
# Calculation of Parameter 4 - Net Primary Productivity (NPP).
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")
# Calculation of Parameter 5 - Carbon Delivery Flux (CDF).
if CDFEquation == "1. Suess 1980":
CDF = (NPP * ZforCDF / 100) * 4
CDF.save(r"Q:\LFP_GLOBAL_Python\OUTPUT.gdb\CDF")
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 = arcpy.GetParameterAsText(1)
BSS = arcpy.Raster(arcpy.GetParameterAsText(2))
InputLatitude = arcpy.Raster(arcpy.GetParameterAsText(3))
InputZ = arcpy.GetParameterAsText(4)
InputCountrylines = arcpy.GetParameterAsText(5)
NPPEquation = arcpy.GetParameterAsText(6)
CDFEquation = arcpy.GetParameterAsText(7)
env.mask = InputZ
# Calculate latitude North/South and offshore distance; 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))
InputZ1 = Con((InputZ == 0),1,(InputZ))
ZforCDF = Con((InputZ1) >50, (InputZ1))
# Calculation of Parameter 3 - Background Total Organic Carbon (TOC)
range1 = Con(((BSS) < 0.0378), (BSS))
range1phi = Con((range1), 6.11)
range2 = Con(((BSS) >= 0.0378) & ((BSS) <= 0.47), (BSS))
range2mm = 0.0593-(1.7714*(range2))+(18.7109*Power((range2),2))-(22.7289*Power((range2),3))
range2phi = -3.3219*Log10((range2mm))
range3 = Con(((BSS) > 0.47), (BSS))
range3mm = 0.8381 + (1.2188*(range3)) - (0.0007*Power((range3),2))
range3phi = -3.3219*Log10((range3mm))
GrainSizephi = arcpy.MosaicToNewRaster_management([(range1phi), (range2phi), (range3phi)], OutLocation, (StageAge) + "_Grain_Size_phi", "", "32_BIT_FLOAT", "", "1", "LAST", "FIRST")
# 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")
# 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), NPP * 2, NPP * 4)
CDF.save(r"Q:\LFP_GLOBAL_Python\OUTPUT.gdb\CDF")
NPP = arcpy.Raster(arcpy.MosaicToNewRaster_management([(rasterNorth), (rasterSouth)], OutLocation, (StageAge) + "_MinNPP", "", "32_BIT_FLOAT", "", "1", "LAST", "FIRST"))