Skip to content
Snippets Groups Projects
Commit 7e233748 authored by Marc Schikowski's avatar Marc Schikowski
Browse files

Merge branch 'master' of gitlab.uni-koblenz.de:bkraus/trees

parents 8d7db971 2d7c0c7b
No related branches found
No related tags found
No related merge requests found
Pipeline #12236 failed
.idea/
\ No newline at end of file
import numpy as np
import TreeSpecies as ts
class Tree:
position = np.array([0.0, 0.0]) # position of tree in cartesian coordinates
truncDiameter = 0.0 # tree diameter in centimeter
truncRadius = 0.0 # tree diameter in centimeter
leafRadus = 0.0
height = 0.0 # height of the tree
species = ts.null # tree species
#%%
import numpy as np
from mpl_toolkits.mplot3d import axes3d
import scipy
from collections import defaultdict
from PIL import Image
import threading
import time
from scipy.interpolate import griddata
import random
import networkx as nx
import math
import plotly.plotly as py
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import init_notebook_mode, iplot, plot
from plotly.graph_objs import Scatter
import ipywidgets as gui
from ipywidgets import interact
############################################ PLOTTING #####################################################
init_notebook_mode(connected=True)
def plotPath(paths, gridPoints, weights, routData):
steps = []
######################################### Define Path Plots ##################################################
data = []
for path in paths:
data.append(
go.Scatter3d(
visible = False,
x=path[0], y=path[1], z=path[2],
marker=dict(
size=4,
color=path[2],
colorscale='Viridis',
),
line=dict(
color='#1f77b4',
width=1
)
)
)
data.append(go.Surface(x = gridPoints[0]*meterScalingLongitute/stepSize, y = gridPoints[1]*meterScalingLatitute/stepSize, z=gridPoints[2]))
########################################### Define Bar Plots #################################################
x,y,z = zip(*routData)
trace0 = go.Bar(
x=['0.0', '0.1', '0.2', '0.3', '0.4', '0.5',
'0.6', '0.7', '0.8', '0.9', '1.0'],
y = x,
name='Cost',
marker=dict(
color='rgb(49,130,189)'
)
)
data.append(trace0)
trace1 = go.Bar(
x=['0.0', '0.1', '0.2', '0.3', '0.4', '0.5',
'0.6', '0.7', '0.8', '0.9', '1.0'],
y=y,
name='Distance',
marker=dict(
color='rgb(204,204,204)',
)
)
data.append(trace1)
trace2 = go.Bar(
x=['0.0', '0.1', '0.2', '0.3', '0.4', '0.5',
'0.6', '0.7', '0.8', '0.9', '1.0'],
y=z,
name='Energy',
marker=dict(
color='rgb(120,130,100)',
)
)
data.append(trace2)
############################################# Define Camps Plot ################################################
campsPositions = []
campTitles = []
for camp in everestCamps:
campPosition = (camp[0]*meterScalingLongitute, camp[1]*meterScalingLatitute, gridPoints[2][camp[1]][camp[0]])
campTitles.append(camp[2])
campsPositions.append(campPosition)
x,y,z = zip(*campsPositions)
campsPlot = go.Scatter3d(
visible = False,
x=x, y=y, z=z,
marker=dict(
size=4,
color= 'red'
),
#title = campTitles
)
data.append(campsPlot)
############################################# Define Slider ########################################################
steps = []
for i in range(len(paths)):
step = dict(
method = 'restyle',
args = ['visible', [False] * len(data)],
label = str(weights[i])[:3],
)
step['args'][1][-1] = True
step['args'][1][-2] = True
step['args'][1][-3] = True
step['args'][1][-4] = True
step['args'][1][-5] = True
step['args'][1][i] = True
steps.append(step)
sliders = [dict(
active = 0,
currentvalue = {"prefix": "Weight, Energy, Distance: "},
pad = {"t": 10},
steps = steps
)]
data[0]['visible'] = True
data[-1]['visible'] = True
layout = dict(sliders=sliders, scene = dict(aspectmode = 'data'), legend=dict(
x=0,
y=1.0,
bgcolor='rgba(255, 255, 255, 0)',
bordercolor='rgba(255, 255, 255, 0)'
))
fig = go.Figure(data= data, layout=layout)
plot(fig)
####################################################################################################################
################################################ SUBPLOTTING WIP ###################################################
def plotSubPlots (paths,gridPoints, weights, routeData):
steps = []
######################################### Define Path Plots ##################################################
Surface_Plot_Data = []
for path in paths:
Surface_Plot_Data.append(
go.Scatter3d(
visible = False,
x=path[0], y=path[1], z=path[2],
marker=dict(
size=4,
color=path[2],
colorscale='Viridis',
),
line=dict(
color='#1f77b4',
width=1
)
)
)
Surface_Plot_Data.append(go.Surface(x = gridPoints[0]*meterScalingLongitute/stepSize, y = gridPoints[1]*meterScalingLatitute/stepSize, z=gridPoints[2]))
########################################### Define Bar Plots #################################################
Bar_Plot_Data = []
x,y,z = zip(*routeData)
trace0 = go.Bar(
x=['0.0', '0.1', '0.2', '0.3', '0.4', '0.5',
'0.6', '0.7', '0.8', '0.9', '1.0'],
y = x,
name='Cost',
marker=dict(
color='rgb(49,130,189)'
)
)
Bar_Plot_Data.append(trace0)
trace1 = go.Bar(
x=['0.0', '0.1', '0.2', '0.3', '0.4', '0.5',
'0.6', '0.7', '0.8', '0.9', '1.0'],
y=y,
name='Distance',
marker=dict(
color='rgb(204,204,204)',
)
)
Bar_Plot_Data.append(trace1)
trace2 = go.Bar(
x=['0.0', '0.1', '0.2', '0.3', '0.4', '0.5',
'0.6', '0.7', '0.8', '0.9', '1.0'],
y=z,
name='Energy',
marker=dict(
color='rgb(120,130,100)',
)
)
Bar_Plot_Data.append(trace2)
############################################# Define Slider ########################################################
steps = []
for i in range(len(paths)):
step = dict(
method = 'restyle',
args = ['visible', [False] * len(Surface_Plot_Data)],
label = str(weights[i])[:3],
)
step['args'][1][-1] = True
step['args'][1][i] = True
steps.append(step)
sliders = [dict(
active = 0,
currentvalue = {"prefix": "Weight, Energy, Distance: "},
pad = {"t": 10},
steps = steps
)]
Surface_Plot_Data[0]['visible'] = True
layout = dict(sliders=sliders, scene = dict(aspectmode = 'data'), legend=dict(
x=0,
y=1.0,
bgcolor='rgba(255, 255, 255, 0)',
bordercolor='rgba(255, 255, 255, 0)'
))
########################################### Define Height Plot #############################################
Height_Plot_X = np.arange(0, len(paths[0][2]), 1)
Height_Plot_X = Height_Plot_X.tolist()
Height_Plot_Data = go.Scatter(
#visible = True,
x=Height_Plot_X, y=paths[0][2]
# marker=dict(
# size=4,
# color=path[2],
# colorscale='Viridis',
# ),
# line=dict(
# color='#1f77b4',
# width=2
# )
)
Surface_Plot_Data[0]['visible'] = True
data = [Bar_Plot_Data[0], Height_Plot_Data, Surface_Plot_Data[0]]
layout = {
"plot_bgcolor": 'black',
"paper_bgcolor": 'black',
"titlefont": {
"size": 20,
"family": "Raleway"
},
"font": {
"color": 'white'
},
"dragmode": "zoom",
"scene": {
"domain": {
"x": [0, 0.55],
"y": [0, 0.9]
},
"xaxis": {"gridcolor": 'white'},
"yaxis": {"gridcolor": 'white'},
"zaxis": {"gridcolor": 'white'}
},
"margin": {
"r": 10,
"t": 25,
"b": 40,
"l": 60
},
"scene": {"domain": {
"x": [0.5, 1],
"y": [0, 0.55]
},
"xaxis": {"gridcolor": 'white'},
"yaxis": {"gridcolor": 'white'},
"zaxis": {"gridcolor": 'white'}
},
"showlegend": False,
"title": "<br>Volcano Database",
"xaxis": {
"anchor": "y",
"domain": [0.6, 0.95]
},
"yaxis": {
"anchor": "x",
"domain": [0.65, 0.95],
"showgrid": False
}
}
annotations = { "text": "Source: NOAA",
"showarrow": False,
"xref": "paper",
"yref": "paper",
"x": 0,
"y": 0}
layout['annotations'] = [annotations]
fig = go.Figure(data=data, layout=layout)
plot(fig, filename = "Mixed Subplots Volcano")
#fig.append_trace(trace2, 1, 2)
#fig = tools.make_subplots(rows = 2, cols=2, subplot_titles=('3D Path', 'Path Parameters', 'Path Height','test'))
#fig.append_trace(Surface_Plot_Data, 1, 1)
#fig.append_trace(Height_Plot_Data, 1, 2)
#fig['layout'].update(height=600, width=800, title='i <3 annotations and subplots')
#fig.append_trace(Bar_Plot_Data, 2, 1)
#fig = go.Figure(data= data, layout=layout)
#py.iplot(fig, filename='Path')
###############################################################################################################################
###############################################################################################################################
#%%
######################################## MAIN ###########################################
highest = highestPoint(gridPoints[2])
lowest = lowestPoint(gridPoints[2])
weights = np.arange(0, 1.1, 0.1)
routeData = generateRouteData(weights, highest, lowest)
paths = routeData[0]
pathParameters = routeData[1]
print(routeData[1])
#plotSubPlots(paths,gridPoints, weights, routeData[1])
plotPath(paths,gridPoints, weights, routeData[1])
# collection of functions for modelling trees
import numpy as np
def getHeight(diameter, max_height, max_dia):
"calculate tree high from diameter and species maximum values"
b2 = (2 * max_height)/max_dia - 274/max_dia
b3 = (max_height - 137) / pow(max_dia,2)
height = 137 + b2*diameter - b3*pow(diameter,2)
return height
def getBoleVolume(height, diameter):
"calculate the bole volume of a tree"
return height*diameter*diameter
def getLeafArea(c,diameter):
"calculate the leaf area of a tree"
return c*diameter*diameter
def getDeathProbability(age_max):
"calcuate the probability for a tree to die after one year"
return (1 - 0.02**(1.0/age_max))
def diamteterGrowthRate(currentDiameter, G, hmax, dmax):
"derivitive of the diameter with respect to time"
d = currentDiameter
h = getHeight(d, hmax, dmax)
return G * (1 / (2 * h)) * d * (1 - h * d / (hmax * dmax))
def willTreeDie(eps,t):
"check if a tree is dead after t amount of years"
if np.random.uniform(0,1) > (1-eps)**t: # using the probability that a tree survives
return True
return False
\ No newline at end of file
import numpy as np
import TreeModel as tm
class TreeSpecies:
hmax = 0
dmax = 0
eps = 0
G = 0
c = 0
R = 0
ageMax = 0
def __init__(self, hmax, dmax, G, c, ageMax):
self.hmax = hmax
self.dmax = dmax
self.eps = tm.getDeathProbability(ageMax)
self.ageMax = ageMax
self.G = G
self.c = c
self.R = G / c
null = TreeSpecies(0,0,0,0,0)
maple = TreeSpecies(3011, 152.5, 170, 1.57, 200)
beech = TreeSpecies(2660, 122, 150, 2.2, 300)
fir = TreeSpecies(1830, 50, 200, 2.5, 80)
spruce = TreeSpecies(1830, 50, 100, 2.5, 350)
birch = TreeSpecies(1830, 46, 240, 0.486, 80)
species = np.array([maple, beech, fir, spruce, birch])
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment