Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoSentinel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoSentinel
Commits
dd5ee94a
Commit
dd5ee94a
authored
Sep 24, 2019
by
Mario Chirinos Colunga
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
L3A
parent
6f4b168c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
L2AtoL3A.py
geosentinel/L2AtoL3A.py
+74
-0
No files found.
geosentinel/L2AtoL3A.py
0 → 100755
View file @
dd5ee94a
#!/usr/bin/python
# -*- coding: utf-8 -*-
import
os
import
sys
import
gdal
import
numpy
as
np
from
collections
import
Counter
CLOUDS
=
[
8
,
9
,
10
]
#-------------------------------------------------------------------------------
def
imageCountSCLData
(
filename
,
classlist
):
inputImage
=
gdal
.
Open
(
filename
)
rows
,
cols
,
geotransform
=
inputImage
.
RasterYSize
,
inputImage
.
RasterXSize
,
inputImage
.
GetGeoTransform
()
data
=
inputImage
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
inputImage
=
None
return
(
np
.
isin
(
data
,
classlist
)
>
0
)
.
sum
()
/
float
((
rows
*
cols
))
#-------------------------------------------------------------------------------
def
getNewSCLpixel
(
row
,
col
,
fileList
):
clist
=
[
filelist
[
i
][
"SCL"
][
row
,
col
]
for
i
in
range
(
0
,
len
(
fileList
))
]
newClass
=
Counter
(
clist
)
.
most_common
(
1
)[
0
]
for
i
in
range
(
len
(
fileList
):
fileList
return
(
newClass
,
newPixel
)
#-------------------------------------------------------------------------------
def
L2AtoL3A
(
directory
):
os
.
chdir
(
directory
+
"SCL/"
)
files
=
{
f
:{
"path"
:
os
.
path
.
abspath
(
f
)}
for
f
in
os
.
listdir
(
"."
)}
print
(
files
)
for
f
in
files
:
files
[
f
][
"score"
]
=
imageCountSCLData
(
files
[
f
][
"path"
],
CLOUDS
)
filesList
=
sorted
(
files
.
items
(),
key
=
lambda
(
k
,
v
):
v
[
"score"
],
reverse
=
False
)
for
f
in
files
:
inputImage
=
gdal
.
Open
(
files
[
f
][
"path"
])
rows
,
cols
,
geotransform
=
inputImage
.
RasterYSize
,
inputImage
.
RasterXSize
,
inputImage
.
GetGeoTransform
()
files
[
f
][
"SCL"
]
=
inputImage
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
inputImage
=
None
tci
=
files
[
f
][
"path"
]
.
replace
(
"SCL"
,
"TCI"
)
inputImage
=
gdal
.
Open
(
tci
)
rows
,
cols
,
geotransform
=
inputImage
.
RasterYSize
,
inputImage
.
RasterXSize
,
inputImage
.
GetGeoTransform
()
files
[
f
][
"TCI"
]
=
[
inputImage
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
),
inputImage
.
GetRasterBand
(
2
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
),
inputImage
.
GetRasterBand
(
3
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)]
inputImage
=
None
newSCL
=
files
[
filesList
[
0
][
0
]][
"SCL"
]
newTCI
=
files
[
filesList
[
0
][
0
]][
"TCI"
]
newMASK
=
np
.
isin
(
newSCL
,
CLOUDS
)
for
row
in
range
(
len
(
newSCL
)):
for
col
in
range
(
len
(
row
)):
if
newMASK
[
row
][
col
]:
newSCL
[
row
][
col
]
=
print
(
"file"
,
filesList
)
#-------------------------------------------------------------------------------
def
main
(
argv
):
if
len
(
sys
.
argv
)
!=
2
:
print
(
"Usage: "
+
argv
[
0
]
+
"<directory>"
)
else
:
L2AtoL3A
(
argv
[
1
])
#-------------------------------------------------------------------------------
if
__name__
==
"__main__"
:
main
(
sys
.
argv
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment