POST
|
Maybe it is easier if I give a piece of the code, here I added the smallest piece of code that gives a problem. If I run this, the program will crash, giving a runtime error, Pure virtual function call. However, if I uncomment the intermediate saves, there is no problem anymore and the progam will work fine. I get the feeling it has something to do with the memory use of the Con statements... Sometimes I nest 3 Con-statements into each other, within the Con statements there are functions containing again 3 Con-statements themself... If someone is willing to test this piece of code, for the first 6 rasters I use random rasters (values between 0 and 1) of 10 by 10 cells. The ZeroRaster is a 10 by 10 raster containing only zero's. Thank you! Mattias [PHP] # Import moduls import arcpy from arcpy import * from arcpy.sa import * # Set environment settings env.workspace = "C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb" # Check out the ArcGIS Spatial Analyst extension license arcpy.CheckOutExtension("Spatial") # Set variables K_sat_L1 = Raster('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/K_sat_L1xx') theta_C1 = Raster('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/theta_C1xx') theta_fc_L1 = Raster('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/theta_fc_L1xx') theta_sat_L1 = Raster('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/theta_sat_L1xx') thickness_C1 = Raster('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/thickness_C1xx') tau_L1 = Raster('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/tau_L1xx') ZeroRaster = Raster('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/ZeroRasterxx') #----soil compartments----# # class for soil compartments class SoilCompartment: def __init__(self, theta, thickness,theta_sat,theta_fc,K_sat,tau): self.theta = theta self.thickness = thickness self.theta_sat = theta_sat self.theta_fc = theta_fc self.K_sat = K_sat self.tau = tau # create array of SoilCompartment objects Compartment = [] Compartment.append(SoilCompartment(theta_C1,thickness_C1,theta_sat_L1,theta_fc_L1,K_sat_L1,tau_L1)) # first compartment #given theta -> calculate the corresponding delta theta/ delta t def calculate_delta_theta(theta, theta_sat, theta_fc, tau): # theta > theta_sat: delta_theta = Con(theta > theta_sat, theta_sat, # theta < theta_fc: Con(theta <= theta_fc, 0, # theta_fc < theta < theta_sat: tau*(theta_sat - theta_fc)*(Exp(theta-theta_fc)-1)/(Exp(theta_sat - theta_fc)-1))) return delta_theta #given delta theta/ delta t -> calculate the corresponding theta def calculate_theta(delta_theta, theta_sat, theta_fc, tau): #delta_theta <= 0 theta = Con(delta_theta <= 0,theta_fc, #tau > 0 Con(tau > 0, theta_fc + Log2(1 + delta_theta*(Exp(theta_sat - theta_fc) - 1))/(tau*(theta_sat - theta_fc)), #else, to stop draining: theta_sat + 0.1)) return theta #----calculation Procedure for drainage----# drainsum = ZeroRaster delta_theta = ZeroRaster drain_comp = ZeroRaster drainmax = ZeroRaster theta_x = ZeroRaster excess = ZeroRaster pre_thick = ZeroRaster #calculate drainage #Drainsum cannot exceed the K_sat of the soil layer def CheckExcess(drainsum, excess, K_sat): excess = Con(drainsum > K_sat, excess + drainsum - K_sat, excess) return excess def CheckDrainsum(drainsum, K_sat): drainsum = Con(drainsum > K_sat, K_sat, drainsum) return drainsum for compi in range (1): # 1* calculate drainage of compartment delta_theta = Con(Compartment[compi].theta > Compartment[compi].theta_fc, calculate_delta_theta(Compartment[compi].theta, Compartment[compi].theta_sat, Compartment[compi].theta_fc, Compartment[compi].tau), 0) delta_theta.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/adt') #drain_comp = delta_theta*Compartment[compi].thickness # 2* check drainability excess = ZeroRaster pre_thick = ZeroRaster for i in range (compi): pre_thick = pre_thick + Compartment.thickness drainmax = delta_theta*pre_thick #drainmax.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/adm') # 3* drain compartment # 3.1: if drainsum <= drainmax drainsum_save = Con(drainsum<=drainmax,1,0) Compartment[compi].theta = Con(drainsum_save == 1, Compartment[compi].theta - delta_theta, Compartment[compi].theta) #Compartment[compi].theta.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/at') drainsum = Con(drainsum_save == 1, drainsum + drain_comp, drainsum) #drainsum.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/ads') excess = Con(drainsum_save == 1, CheckExcess(drainsum, excess,Compartment[compi].K_sat), excess) #excess.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/aex') drainsum = Con(drainsum_save == 1, CheckDrainsum(drainsum, Compartment[compi].K_sat), drainsum) #drainsum.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/ads1') #3.2: if drainsum > drainmax delta_theta = Con(drainsum_save == 0, drainsum/pre_thick, delta_theta) #delta_theta.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/adt1') theta_x = Con(drainsum_save == 0, calculate_theta(delta_theta, Compartment[compi].theta_sat, Compartment[compi].theta_fc, Compartment[compi].tau), theta_x) #theta_x.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/atx') #3.2.1: if theta_x <= theta_sat theta_x_save = Con(theta_x <= Compartment[compi].theta_sat,1, 0) Compartment[compi].theta = Con(drainsum_save == 0, Con(theta_x_save==1, Compartment[compi].theta + drainsum/Compartment[compi].thickness), Compartment[compi].theta) #Compartment[compi].theta.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/at1') #3.2.1.1: if theta > theta_x theta_save = Con(Compartment[compi].theta > theta_x,1,0) drainsum = Con(drainsum_save == 0, Con(theta_x_save==1,Con(theta_save==1, ((Compartment[compi].theta - theta_x) + delta_theta)*Compartment[compi].thickness)), drainsum) #drainsum.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/ads2') excess = Con(drainsum_save == 0, Con(theta_x_save==1,Con(theta_save==1, CheckExcess(drainsum,excess,Compartment[compi].K_sat))), excess) #excess.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/aex1') drainsum = Con(drainsum_save == 0, Con(theta_x_save==1,Con(theta_save==1, CheckDrainsum(drainsum,Compartment[compi].K_sat))), drainsum) #drainsum.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/ads3') Compartment[compi].theta = Con(drainsum_save == 0, Con(theta_x_save==1,Con(theta_save==1, theta_x - delta_theta)), Compartment[compi].theta) #Compartment[compi].theta.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/at2') drainsum.save('C:/Users/MattiasVO/Documents/ArcGIS/Default.gdb/at3') [/PHP]
... View more
01-26-2012
04:03 AM
|
0
|
0
|
482
|
POST
|
I am using the correct pathing. I also don't think it has something to do with the size of the rasters, the problem stays the same when I work with small rasters. What I found out now, is that when I step trough with the debugger in PythonWin, I don't get an errormessage (I can check the locations of the intermediate rasters in the command window while stepping trough, all goes fine). If I do it like this, the output raster will be saved at the end of the program without a problem. When I run the program without debugging, it crashes (virtual function call) at the moment I try to save the raster (before all goes fine) In the program, I do around 50 calculations (most of them containing complex Con() statements) on different rasters that are placed in 2 different classes
... View more
01-22-2012
10:44 PM
|
0
|
0
|
482
|
POST
|
Thank you for the reply, but I still have the problem, is it possible that the problem only occurs on larger rasters/with more calculations? What I also have (for this example) is that the intermediate rasters are found in my geodatabase after I ran the code (times_ras and divid_ras), any way to avoid this?
... View more
01-18-2012
10:41 PM
|
0
|
0
|
482
|
POST
|
Hi everyone, I want to write a program, in which I do calculations on several rasters. In the program, I use some rasters that I calculated earlier in (the same) program. The problem is now that this doesn't seem to work. The program crashes and in my geodatabase a 'timesras, ifthe_ras,... are found after the crash. Here follows a small piece of code with the same logic as what I do in my program, what do I do wrong here? I hope I don't have to save each raster (here: a and b) before I can use them in a new calculation? Are there other sollutions? Kind Regards, Mattias import arcpy from arcpy import * from arcpy.sa import * env.workspace = "C:/..." arcpy.CheckOutExtension("Spatial") InRas1 = Raster('C:/...') InRas2 = Raster('C:/...') a = InRas1*InRas2 b = InRas1/InRas2 OutRas = a*b OutRas.save('C:/...')
... View more
01-18-2012
04:44 AM
|
0
|
6
|
3203
|
POST
|
thanks! I'll try, looks like it will work. Thank you!
... View more
01-09-2012
05:43 AM
|
0
|
0
|
317
|
POST
|
Sorry for the confusion, what I want to do is: "While" (as long as...) the cell values of Ras1>0: Ras2= do something Ras3= do something Ras1= Ras1 - 1
... View more
01-09-2012
05:25 AM
|
0
|
0
|
317
|
POST
|
Oké, but I want this Con() statement to be repeated until every value of the raster has reached 0. Similar to the traditional "while-loop" in python...
... View more
01-09-2012
04:54 AM
|
0
|
0
|
317
|
POST
|
A beginners question: I am looking for the right syntax to perform a while loop on a raster "x", I want to do something like while cell (in raster x) > 0: value of cell= value of cell-1 How can I do this? Probably something easy but I can't find it anywhere. Thank you
... View more
01-09-2012
01:37 AM
|
0
|
6
|
582
|
POST
|
Thank you! The code will look little bit messy now, a lot of times the same condition in a condition in a condition,... for each output raster. But thank you anyway. Mattias
... View more
01-02-2012
11:45 PM
|
0
|
0
|
131
|
POST
|
Hi everyone! Does anyone know if it is possible to change several rasters with one Con statement? I am currently doing something like this: x = Con(statement, x*2) y = Con(statement, y*3) But since I work on very large rasters I guess it would be more efficient if I could do something like this: x,y = Con(statement,x*2 & y*3) Is this possible? Kind Regards, Mattias
... View more
01-02-2012
04:51 AM
|
0
|
2
|
343
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|