-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
101 lines (70 loc) · 3.38 KB
/
Copy pathutils.py
File metadata and controls
101 lines (70 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# ========Import Packages======###
import numpy as np
from scipy import spatial as sp
##=======Functions=======####
"""Below these two functions work like if there is any click
in an image(Image 1) then it returns the closest point
of another image's (Image 2) index"""
def _clickedImageIndex(clickedPixel, imageArray):
array = np.array(imageArray)
array = np.squeeze(array)
val = np.array(clickedPixel)
tree = sp.KDTree(array)
point = array[tree.query(val)[1]]
res = __convertToIndex(point, array)
return res
def __convertToIndex(rgb, dat):
indx = []
rgb = rgb.tolist()
dat = dat.tolist()
for x in range(0, len(rgb)):
ix = dat.index(rgb[x])
indx.append(ix)
return indx
"""This function converts an image (Image 1)
into a range of values with respect to another image(Image 2)"""
def _convertValues(clickedImageIndex, pixelIndexDiff, minInputVal, maxInputVal):
tmp = (float(clickedImageIndex) / float(pixelIndexDiff)) * (float(maxInputVal) -
float(minInputVal)) + float(minInputVal)
# temporary variable to return result
return tmp
"""This function is used to make the final execution whole convertion
it takes 5 args: Image1 clicked rgb data's index
Image2 first click rgb data's index
Image2 second click rgb data's index
Image2 rgb data's index differences
input Value from the Text Input field
then it converts all the value pixel wise into scale value with help of other function
and returns the values"""
def _final_exec(clickedImageIndex, scaleClick1Indexes, scaleClick2Indexes, indexesDiffernce, InputValues):
# intialize Vairables
result = []
oddInput = []
evenInput = []
for i in range(0, len(InputValues)): # iterate through text input values
if i % 2: # if any length is even then store it in evenInput
evenInput.append(InputValues[i])
else:
oddInput.append(InputValues[i]) # else store it in oddInput
for i in range(0, len(clickedImageIndex)): # iterate through main Image indexes
for j in range(0, len(scaleClick1Indexes)): # iterate through scale clickIndexes
# if any clicked Image index is found in the range of first click and second click of scale then run
# the conversion function
if clickedImageIndex[i] >= scaleClick1Indexes[j] and clickedImageIndex[i] <= scaleClick2Indexes[j]:
tmp = _convertValues(clickedImageIndex[i], indexesDiffernce[j], oddInput[j], evenInput[j])
tmp = round(tmp, 6)
result.append(abs(tmp))
return result
"""This function returns the wave power in terms of
kW/m if the wave height in meter , timeperiod in seconds """
def wavePower(waveHeight, timePeriod, waterDensity):
power = [] # variable to return
while len(waveHeight) < len(timePeriod):
waveHeight.append(0)
while len(timePeriod) < len(waveHeight):
timePeriod.append(0)
for x in range(0, len(waveHeight)): # iterate through every input wave height
res = (waterDensity * 9.81 * 9.81 * waveHeight[x] * waveHeight[x] * timePeriod[x]) / (
64 * np.pi) # formula applied to find wave power
power.append(abs(res / 1000)) # append the results to an array
return power # return the array