The problem I am having is in putting data I have created into a 2D mesh (list of lists) I am creating the data properly, however in trying to put it into the list of lists format the previous lists seems to be overwritten. in my function 'getDistnRechargeGrid', there is a check line, that highlights the problem.
DDgrid[x][y] = DD # <---------------- THIS DOES NOT STORE THE UNIQUE VALUES ????? The last calculate value replaces the previous for x
I would be very grateful to understand why the above does not place the unique values into the list of lists ???
How to you place the correctly calculated value in the list of list and create a unique 2D grid ? The focus here is how to get the value in form where it can plot a 2D grid.
"""
------------------------------- PYTHON 3.xx ------------------------------------------
This script aims to plot the results of pumping at a location on the draw down of the ground water surface
The script initially set up the data of the ground water surface
Then based on Pump & Soil Data, calculates the radial draw down over a grid.
Input parameters:
Transmissivity T = 119 m2/day
Storativity S = 0.002
Pumping rate Q = 1000m3/day
Initial head in aquifer (LHS)* =100 m
Initial head (RHS)* ==90 m
delta t =1day
delta x =50 m
delta y =50 m
Alpha = 1
"""
#-------------------------------------------------------------------------------
def getDistnRechargeGrid(xn,yn,PumpCellX,PumpCellY,Cell_Size,Q,DDgrid,RRgrid):
"""
This calculates a 2D grid of the distance from each cell to a target cell
Based on that distance a DrawDown/Recharge Surface is Created as a 2D mesh
"""
chkx = 5
chky = 5
for x in range(0,xn+1,1):
for y in range(0,yn+1,1):
Xd = abs(x-PumpCellX)*Cell_Size
Yd = abs(y-PumpCellY)*Cell_Size
DD = (Xd**2+Yd**2)**0.5
if DD == 0: DD = 1.0
RR = Q/DD**2
if x == chkx and y == chky: chkVal = DD
# ------- Here is my problem,
"""
When i print out the calaculted values below they are correct...
However when I check the values in the list os lists... all the lists have been replaced with the last list created
How is this occurring ??
How do I ensure the lists are ALL retained as I produced them ?
"""
DDgrid[x][y] = DD # <---------------- THIS DOES NOT STORE THE UNIQUE VALUES ????? The last calculate value replaces the previous for x
RRgrid[x][y] = RR
print ('x,y:%i,%i:Xd,Yd:D; %.2f,%.2f;%.2f:RR=%.2f'%(x,y,Xd,Yd,DD,RR))
#input ('Check')
print ('Compare Calc Val to Value placed in the grid')
print ('Location: %i,%i: CalcVal: %.2f, Value in Grid: %.2f' %(chkx,chky,chkVal,DDgrid[chkx][chky]))
input ('Check')
# Put it into a numpy array ?? array(DDgrid)
#print (DDgrid)
print (len(DDgrid))
return(DDgrid,RRgrid)
#------------------------------------------------------------------------------------------
def setupGroundwaterSurface(xn,yn,LeftH,RighH,PumpCellX,PumpCellY,Q):
"""
"""
XL =[]
Data = []
R = []
RR = []
DDrow = []
RRrow = []
DDgrid = []
RRgrid = []
for x in range(0,xn+1,1): # This will be i
Value = LeftH - (LeftH-RighH)/xn*x
print (Value)
XL.append(Value) # Level of Ground water Surface
DDrow.append(0.0) #--- Create Gridrow of Zero for Dist
RRrow.append(0.0) #--- Create Gridrow of Zero for RR
if x == PumpCellX:
R.append(Q) # Set the Pump Rate
else: R.append(0.0)
for y in range(0,yn+1,1): # This will be j
Data.append(XL)
DDgrid.append(DDrow) #Create the 2D grid as Zeroes
RRgrid.append(RRrow) #Create the 2D grid as Zeroes
if y == PumpCellY:
RR.append(R) # Leave only the 1 Specific Cell as the Pump/Recharge Rate
else: RR.append([0.0 if wd == Q else wd for wd in R]) # Set the Rest to Zero
print (Data)
return(Data,RR,DDgrid,RRgrid)
#-------------------------------------------------------------------------------
def plot2D_data(data,Suptitle):
"""
https://matplotlib.org/stable/tutorials/colors/colormaps.html
"""
import matplotlib.pyplot as plt
im = plt.imshow(data, cmap="rainbow")
#ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='hot') # 3D Meshed Surface
plt.colorbar(im)
plt.suptitle(Suptitle)
plt.show()
return()
#-----------------------------------------------
#------------------ SET UP DATA -------------------
T = 119.0 #m2/day
S = 0.002
Q = -10000.0 # m3/day
PumpCellX = 8
PumpCellY = 8
xn = 15
yn = 15
Cell_Size = 50.0 #(m)
LeftH = 100.0
RighH = 85.0
TimeSteps = 20
alpha = 1
dt = 1.0
dx = 50.0
#--------------- SET UP 2D Grid in LISTS -------------------------
#----- First Create the Water Table Surface based on Levels -------------
Data,RR,DDgrid,RRgrid = setupGroundwaterSurface(xn,yn,LeftH,RighH,PumpCellX,PumpCellY,Q)
plot2D_data(Data,'GroundWater Surface')
print (RR)
plot2D_data(RR,'Well Location Drawdown Rate')
#------- Now Create the Distance Grid and the Recharge Grid----------------
DDgrid,RRgrid = getDistnRechargeGrid(xn,yn,PumpCellX,PumpCellY,Cell_Size,Q,DDgrid,RRgrid)
plot2D_data(DDgrid,'Distance Grid to Well Location')
#print (RRgrid)
plot2D_data(RRgrid,'DrawDown Surface based on Distance to Well')
print (RR)