Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
InSAR_forest_height
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Narayanarao Bhogapurapu
InSAR_forest_height
Commits
321a0f0b
Commit
321a0f0b
authored
10 months ago
by
Narayanarao Bhogapurapu
Browse files
Options
Downloads
Patches
Plain Diff
dynamic window & min 3 lidar shots per window
parent
5dff6fe7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ich/algo.py
+85
-2
85 additions, 2 deletions
src/ich/algo.py
with
85 additions
and
2 deletions
src/ich/algo.py
+
85
−
2
View file @
321a0f0b
...
...
@@ -97,6 +97,89 @@ def arc_sinc(x, c_param):
y
[(
y
<
0
)]
=
0
# return y
return
y
def
dynamicWindow
(
cohArray
,
lidarArray
,
initial_ws
,
htl
,
htg
):
rows
,
cols
=
cohArray
.
shape
c_parm
=
np
.
zeros
((
rows
,
cols
))
# Initialize output array to store results
s_parm
=
np
.
zeros
((
rows
,
cols
))
rmse_parm
=
np
.
zeros
((
rows
,
cols
))
count
=
np
.
zeros
((
rows
,
cols
))
ht_
=
np
.
zeros
((
rows
,
cols
))
result
=
[]
i
=
0
while
i
<
rows
:
# print("%0.1f /100 "%((i/rows)*100),end="\r")
j
=
0
while
j
<
cols
:
# Reset to the initial block size for each block
S
=
initial_ws
# start_i = max(i - S // 2, 0)
# end_i = min(i + S // 2 + 1, rows)
# start_j = max(j - S // 2, 0)
# end_j = min(j + S // 2 + 1, cols)
start_i
=
max
(
i
-
S
//
2
,
0
)
end_i
=
min
(
i
+
S
//
2
,
rows
)
start_j
=
max
(
j
-
S
//
2
,
0
)
end_j
=
min
(
j
+
S
//
2
,
cols
)
while
True
:
lidarBlock
=
lidarArray
[
start_i
:
end_i
,
start_j
:
end_j
]
cohBlock
=
cohArray
[
start_i
:
end_i
,
start_j
:
end_j
]
# Check if the block if there are 3 or more lidar samples
if
np
.
isfinite
(
lidarBlock
).
any
()
and
(
np
.
count_nonzero
(
~
np
.
isnan
(
lidarBlock
))
>
3
):
parm
=
cal_
(
cohBlock
,
lidarBlock
,
htl
,
htg
)
mask
=
lidarBlock
.
copy
()
mask
[
~
np
.
isnan
(
mask
)]
=
1
# mask[mask!=1] = 0
if
np
.
all
(
np
.
array
(
parm
)
==
0
):
parm
=
parm_
.
copy
()
if
lidarBlock
.
shape
[
0
]
*
lidarBlock
.
shape
[
1
]
>
initial_ws
*
initial_ws
:
# mask[np.shape(mask)[0]//2,np.shape(mask)[1]//2]=1
np
.
fill_diagonal
(
mask
,
1
)
mask
=
np
.
flipud
(
mask
)
np
.
fill_diagonal
(
mask
,
1
)
s_parm
[
start_i
:
end_i
,
start_j
:
end_j
]
=
np
.
full
(
lidarBlock
.
shape
,
parm
[
1
])
*
mask
c_parm
[
start_i
:
end_i
,
start_j
:
end_j
]
=
np
.
full
(
lidarBlock
.
shape
,
parm
[
2
])
*
mask
rmse_parm
[
start_i
:
end_i
,
start_j
:
end_j
]
=
np
.
full
(
lidarBlock
.
shape
,
parm
[
4
])
count
[
start_i
:
end_i
,
start_j
:
end_j
]
=
np
.
full
(
lidarBlock
.
shape
,
np
.
count_nonzero
(
~
np
.
isnan
(
lidarBlock
)))
gama
=
cohBlock
/
parm
[
1
]
ht_
[
start_i
:
end_i
,
start_j
:
end_j
]
=
arc_sinc
(
gama
,
parm
[
2
])
*
mask
parm_
=
parm
.
copy
()
# print(f"Block at ({i}, {j}) with size {lidarBlock.shape} : Result = {parm}")
break
else
:
# Increase the block size equally in all four directions
S
+=
2
# Update block boundaries while staying within the array limits
# start_i = max(i - S // 2, 0)
# end_i = min(i + S // 2 + 1, rows)
# start_j = max(j - S // 2, 0)
# end_j = min(j + S // 2 + 1, cols)
start_i
=
max
(
i
-
S
//
2
,
0
)
end_i
=
min
(
i
+
S
//
2
,
rows
)
start_j
=
max
(
j
-
S
//
2
,
0
)
end_j
=
min
(
j
+
S
//
2
,
cols
)
# If block size exceeds array dimensions, stop expanding
if
start_i
==
0
and
end_i
==
rows
and
start_j
==
0
and
end_j
==
cols
:
print
(
f
"
Unable to find finite block at position (
{
i
}
,
{
j
}
).
"
)
break
# Move to the next block position in the row
j
+=
initial_ws
# Move to the next block position in the column
i
+=
initial_ws
return
s_parm
,
c_parm
,
rmse_parm
,
ht_
,
count
def
cal_
(
cor
,
gedi
,
htl
,
htg
):
# scale = 1
...
...
@@ -144,7 +227,7 @@ def cal_(cor,gedi,htl,htg):
'
r
'
:
result
[:,
3
],
'
rmse
'
:
result
[:,
4
]})
tempdf
.
dropna
(
subset
=
[
'
rmse
'
],
inplace
=
True
)
# tempdf.drop(tempdf[tempdf.N < nn*0.1].index, inplace=True)
#
tempdf.drop(tempdf[tempdf.N <
100
].index, inplace=True)
tempdf
.
drop
(
tempdf
[
tempdf
.
N
<
=
3
].
index
,
inplace
=
True
)
tempdf
=
tempdf
.
sort_values
(
by
=
[
'
rmse
'
],
ascending
=
True
)
# print(tid,', %.1f, N=%d,nn=%d, %0.2f, %.2f, %0.2f, %0.2f'%(u['class'].iloc[ii],
...
...
@@ -199,7 +282,7 @@ def cal_(cor,gedi,htl,htg):
tempdf
.
dropna
(
subset
=
[
'
rmse
'
],
inplace
=
True
)
tempdf
=
tempdf
.
sort_values
(
by
=
[
'
rmse
'
],
ascending
=
True
)
# tempdf.drop(tempdf[tempdf.N < nn*0.1].index, inplace=True)
#
tempdf.drop(tempdf[tempdf.N <
100
].index, inplace=True)
tempdf
.
drop
(
tempdf
[
tempdf
.
N
<
=
3
].
index
,
inplace
=
True
)
if
tempdf
.
empty
:
tempdf
=
pd
.
DataFrame
(
data
=
{
'
N
'
:
0
,
'
S
'
:
0
,
'
C
'
:
0
,
'
r
'
:
0
,
'
rmse
'
:
0
},
index
=
[
0
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment