Any views expressed within media held on this service are those of the contributors, should not be taken as approved or endorsed by the University, and do not necessarily reflect the views of the University in respect of any particular issue.

Space: weather or not

Space: weather or not

Concerning the quest to predict space weather more accurately

Unrelated fun!

In my spare time, I completed a pretty cool erosion function which I would like to keep. It looks like this:

     

 

It features a wind/elements based approach which acts to smooth the surface, alongside a rivers-based approach which creates the channels. together they create very realistic models of different features!

This is the river model, and the terrain it is acting on;

These are some examples of erosion creating flat:

and the rest are all images with different random seeds. Very happy with it!

 

def depo_func(J):
##takes an array of terrain heights and returns the deposition rate
J=np.array(J)
x1=[]
X0=[]
for i in range(len(J)):
for j in range(len(J[0])):
x=[]
if i==0:
x.append(0)
if j==0:
x.append(0)
x.append(J[1,0])
x.append(J[0,1])
elif j==len(J)-1:
x.append(0)
x.append(J[0,j-1])
x.append(J[1,j])
else:
x.append(J[0,j-1])
x.append(J[0,j+1])
x.append(J[1,j])
elif i==len(J)-1:
x.append(0)
if j==0:
x.append(0)
x.append(J[i-1,0])
x.append(J[i,1])
elif j==len(J)-1:
x.append(0)
x.append(J[i,j-1])
x.append(J[i-1,j])
else:
x.append(J[i,j-1])
x.append(J[i,j+1])
x.append(J[i-1,j])
elif j==0:
x.append(0)
x.append(J[i-1,0])
x.append(J[i+1,0])
x.append(J[i,1])
elif j==len(J)-1:
x.append(0)
x.append(J[i-1,j])
x.append(J[i+1,j])
x.append(J[i,j-1])
else:
x.append(J[i,j+1])
x.append(J[i+1,j])
x.append(J[i,j-1])
x.append(J[i-1,j])
X=np.mean(x)
X= X-J[i,j]
X0.append(X)
x1.append(X0)
X0=[]
return(x1)

 

def erosion_func(J,erosion_rate):
##takes an array of terrain heights and returns the eroded landscape
x1=depo_func(J)
x1=np.array(x1)
J=np.array(J)

o=[]
O=[]

for i in range(len(J)):
for j in range(len(J[0])):
o.append(J[i,j]+x1[i,j]*erosion_rate)
O.append(o)
o=[]
return(O)

 

def whichdirectionislowest(J,coordinate_storage):
###takes in location in array, and calculates coordinates of lowest neighbour
###returns new coordinates
J=np.array(J)
currentheight=J[coordinate_storage[0],coordinate_storage[1]]
if coordinate_storage[0]==0 or coordinate_storage[1]==0 or coordinate_storage[0]==len(J)-1 or coordinate_storage[1]==len(J)-1:
c=0
else:

removal=0#ticker as to whether we are on the bottom edge
##x is coordinate storage 0, y is coordinate storage 1

##choose the lowest number nearby
lowest=[]

#add 100*X1 to make sure it doesn’t refill places already full

row_1=J[coordinate_storage[0]-1]
row_2=J[coordinate_storage[0]]
row_3=J[coordinate_storage[0]+1]

lowest.append(row_1[coordinate_storage[1]])
lowest.append(row_2[coordinate_storage[1]+1])
lowest.append(row_2[coordinate_storage[1]-1])
lowest.append(row_3[coordinate_storage[1]])

if min(lowest)>currentheight:
c=0
elif lowest[0]==min(lowest):
coordinate_storage=[coordinate_storage[0]-1,coordinate_storage[1]]
elif lowest[1]==min(lowest):
coordinate_storage=[coordinate_storage[0],coordinate_storage[1]+1]
elif lowest[2]==min(lowest):
coordinate_storage=[coordinate_storage[0],coordinate_storage[1]-1]
elif lowest[3]==min(lowest):
coordinate_storage=[coordinate_storage[0]+1,coordinate_storage[1]]
lowest.append(currentheight)
currentheight=min(lowest)

return(coordinate_storage)

 

def rivertracer1(J,coordinate_storage,addition=0,steepness=True):
    #traces the line of a river from coordinate in 2D array. Addition is for accumulation (later in river path is stronger)
    J=np.array(J)
    accumulator=0
    size=len(J)
    currentheight=J[coordinate_storage[0],coordinate_storage[1]]
    X1=np.zeros((size,size))
    X1=np.array(X1)
    multiplier=1
    while multiplier>0 and currentheight>0:
        accumulator+=addition
        currentheight=J[coordinate_storage[0],coordinate_storage[1]]
        coordinate_storage2=whichdirectionislowest(J,coordinate_storage)
        newheight=J[coordinate_storage2[0],coordinate_storage2[1]]
        if steepness:
            multiplier=currentheight-newheight
            X1[coordinate_storage[0],coordinate_storage[1]]=(1+accumulator)*(multiplier+1)
        else:
            X1[coordinate_storage[0],coordinate_storage[1]]=(1+accumulator)
        coordinate_storage=coordinate_storage2
    ##stops erosion at end of river path
    X1[coordinate_storage[0],coordinate_storage[1]]=0
    return(X1)
def rivererosion(J,rivererosionrate,addition1=0):
    ###returns a completed, RIVER eroded version of J with erosion rate. addition parameter means more erosion
    ##’further down’; might not be needed, set to 0
    J=np.array(J)
    X=np.zeros((100,100))
    for i in range(len(J)):
        for j in range(len(J[i])):
            XD=rivertracer1(J,[i,j],addition=addition1)
            X+=XD
    D=J-X*rivererosionrate
    return(D)
###
##Seed creation
J=np.random.randint (0,10000,(100,100))
J=np.array(J)

 

##execution

for i in range(100):
print(i)
J=erosion_func(J,0.2)
J=rivererosion(J,0.02)

 

plt.imshow(J)

plt.contourf(J)

from mpl_toolkits.mplot3d import Axes3D
xx,yy=np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100))
fig = plt.figure(figsize=(30, 20))
ax = plt.axes(projection = ‘3d’)
ax.contourf(xx,yy,J,levels=np.linspace(0,6000,1000))

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

css.php

Report this page

To report inappropriate content on this page, please use the form below. Upon receiving your report, we will be in touch as per the Take Down Policy of the service.

Please note that personal data collected through this form is used and stored for the purposes of processing this report and communication with you.

If you are unable to report a concern about content via this form please contact the Service Owner.

Please enter an email address you wish to be contacted on. Please describe the unacceptable content in sufficient detail to allow us to locate it, and why you consider it to be unacceptable.
By submitting this report, you accept that it is accurate and that fraudulent or nuisance complaints may result in action by the University.

  Cancel