Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Sen2Chain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
ESPACE-DEV
Sen2Chain
Commits
69aa6e1a
Commit
69aa6e1a
authored
2 years ago
by
pascal.mouquet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
add new ql functions
parent
2addd67e
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
sen2chain/colormap.py
+119
-1
119 additions, 1 deletion
sen2chain/colormap.py
sen2chain/library.py
+34
-16
34 additions, 16 deletions
sen2chain/library.py
sen2chain/products.py
+19
-10
19 additions, 10 deletions
sen2chain/products.py
sen2chain/tiles.py
+24
-0
24 additions, 0 deletions
sen2chain/tiles.py
with
196 additions
and
27 deletions
sen2chain/colormap.py
+
119
−
1
View file @
69aa6e1a
...
...
@@ -373,7 +373,7 @@ def create_l1c_ql(tci: Union[str, pathlib.PosixPath],
with
rasterio
.
open
(
str
(
tci
))
as
src
:
profile
=
src
.
profile
fact
=
int
(
1000
//
out_resolution
[
0
])
dst_transform
,
dst_width
,
dst_height
=
calculate_default_transform
(
...
...
@@ -417,3 +417,121 @@ def create_l1c_ql(tci: Union[str, pathlib.PosixPath],
#~ raster_band = raster_band.astype(np.uint8)
dst
.
write_band
(
band_id
,
raster_band
)
return
str
(
Path
(
str
(
out_path
)).
absolute
)
def
create_l1c_ql_v2
(
tci
:
Union
[
str
,
pathlib
.
PosixPath
],
out_path
:
Union
[
str
,
pathlib
.
PosixPath
]
=
"
./L1C_QL.tif
"
,
out_resolution
:
Tuple
[
int
,
int
]
=
(
100
,
100
),
jpg
=
False
,
)
->
str
:
"""
Creating a color RVB quicklook from tci 3 bands file passed as argument
:param tci: path to tci raster
:param out_path: path to the output.
:param out_resolution: output resolution, default 100mx100m .
"""
with
rasterio
.
open
(
str
(
tci
))
as
src
:
profile
=
src
.
profile
fact
=
int
(
out_resolution
[
0
]
//
10
)
dst_transform
,
dst_width
,
dst_height
=
calculate_default_transform
(
src
.
crs
,
src
.
crs
,
src
.
width
,
src
.
height
,
*
src
.
bounds
,
resolution
=
out_resolution
)
logger
.
info
(
"
creating L1C QL - {}m/px - {}px
"
.
format
(
out_resolution
[
0
],
dst_width
))
if
out_path
.
suffix
==
"
.jpg
"
or
jpg
:
profile
.
update
(
nodata
=
0
,
driver
=
"
JPEG
"
,
dtype
=
np
.
uint8
,
transform
=
dst_transform
,
width
=
dst_width
,
height
=
dst_height
,
tiled
=
False
,
count
=
3
)
profile
.
pop
(
'
tiled
'
,
None
)
profile
.
pop
(
'
blockxsize
'
,
None
)
profile
.
pop
(
'
blockysize
'
,
None
)
profile
.
pop
(
'
interleave
'
,
None
)
else
:
profile
.
update
(
nodata
=
0
,
driver
=
"
Gtiff
"
,
dtype
=
np
.
uint8
,
transform
=
dst_transform
,
width
=
dst_width
,
height
=
dst_height
,
tiled
=
False
,
count
=
3
)
with
rasterio
.
open
(
str
(
out_path
),
'
w
'
,
**
profile
)
as
dst
:
raster_band
=
src
.
read
(
out_shape
=
(
src
.
count
,
dst_width
,
dst_height
,
),
resampling
=
Resampling
.
nearest
).
astype
(
np
.
uint8
)
dst
.
write
(
raster_band
)
return
str
(
Path
(
str
(
out_path
)).
absolute
)
def
create_l2a_ql_v2
(
tci
:
Union
[
str
,
pathlib
.
PosixPath
],
out_path
:
Union
[
str
,
pathlib
.
PosixPath
]
=
"
./L2A_QL.tif
"
,
out_resolution
:
Tuple
[
int
,
int
]
=
(
100
,
100
),
jpg
=
False
,
)
->
str
:
"""
Creating a color RVB quicklook from tci 3 bands file passed as argument
:param tci: path to tci raster
:param out_path: path to the output.
:param out_resolution: output resolution, default 100mx100m .
"""
with
rasterio
.
open
(
str
(
tci
))
as
src
:
profile
=
src
.
profile
fact
=
int
(
out_resolution
[
0
]
//
10
)
dst_transform
,
dst_width
,
dst_height
=
calculate_default_transform
(
src
.
crs
,
src
.
crs
,
src
.
width
,
src
.
height
,
*
src
.
bounds
,
resolution
=
out_resolution
)
logger
.
info
(
"
creating L2A QL - {}m/px - {}px
"
.
format
(
out_resolution
[
0
],
dst_width
))
if
out_path
.
suffix
==
"
.jpg
"
or
jpg
:
profile
.
update
(
nodata
=
0
,
driver
=
"
JPEG
"
,
dtype
=
np
.
uint8
,
transform
=
dst_transform
,
width
=
dst_width
,
height
=
dst_height
,
tiled
=
False
,
count
=
3
)
profile
.
pop
(
'
tiled
'
,
None
)
profile
.
pop
(
'
blockxsize
'
,
None
)
profile
.
pop
(
'
blockysize
'
,
None
)
profile
.
pop
(
'
interleave
'
,
None
)
else
:
profile
.
update
(
nodata
=
0
,
driver
=
"
Gtiff
"
,
dtype
=
np
.
uint8
,
transform
=
dst_transform
,
width
=
dst_width
,
height
=
dst_height
,
tiled
=
False
,
count
=
3
)
with
rasterio
.
open
(
str
(
out_path
),
'
w
'
,
**
profile
)
as
dst
:
raster_band
=
src
.
read
(
out_shape
=
(
src
.
count
,
dst_width
,
dst_height
,
),
resampling
=
Resampling
.
nearest
).
astype
(
np
.
uint8
)
dst
.
write
(
raster_band
)
return
str
(
Path
(
str
(
out_path
)).
absolute
)
This diff is collapsed.
Click to expand it.
sen2chain/library.py
+
34
−
16
View file @
69aa6e1a
...
...
@@ -115,15 +115,7 @@ class Library:
pass
logger
.
info
(
"
Total l1c size to move: {}
"
.
format
(
human_size_decimal
(
total_size
)))
def
update_latest_ql
(
self
):
"""
Produce or update the latest quicklook for the L2A library tiles
"""
try
:
for
tile
in
self
.
l2a
:
Tile
(
tile
).
update_latest_ql
()
except
:
pass
def
archive_l2a
(
self
,
tile_list
:
list
=
[],
...
...
@@ -170,20 +162,46 @@ class Library:
pass
logger
.
info
(
"
Total size to move: {}
"
.
format
(
human_size_decimal
(
total_size
)))
def
create_all_ql
(
self
,
product_list
:
list
=
[],
def
compute_all_ql
(
self
,
tile_list
:
list
=
[],
product_list
:
list
=
[],
):
toto
=
52
"""
Produce or update quicklooks for all the library tiles
"""
if
not
product_list
:
# l1c
if
not
tile_list
:
for
tile
in
self
.
l1c
:
try
:
toto
=
52
except
:
pass
for
tile
in
self
.
l2a
:
try
:
#Tile(tile).compute_ql(product = "l2a")
toto
=
12
except
:
pass
def
update_latest_ql
(
self
):
"""
Produce or update the latest quicklook for the L2A library tiles
"""
for
tile
in
self
.
l2a
:
Tile
(
tile
).
update_latest_ql
()
try
:
for
tile
in
self
.
l2a
:
Tile
(
tile
).
update_latest_ql
()
except
:
pass
#~ def update_latest_ql(self):
#~ """
#~ Produce or update the latest quicklook for the L2A library tiles
#~ """
#~ for tile in self.l2a:
#~ Tile(tile).update_latest_ql()
def
update_old_cloudmasks
(
self
):
"""
...
...
This diff is collapsed.
Click to expand it.
sen2chain/products.py
+
19
−
10
View file @
69aa6e1a
...
...
@@ -19,8 +19,7 @@ from .xmlparser import MetadataParser, Sen2ChainMetadataParser
from
.sen2cor
import
process_sen2cor
from
.cloud_mask
import
create_cloud_mask
,
create_cloud_mask_v2
,
create_cloud_mask_b11
,
create_cloud_mask_v003
,
create_cloud_mask_v004
from
.indices
import
IndicesCollection
from
.colormap
import
create_l2a_ql
,
create_l1c_ql
from
.colormap
import
create_l2a_ql
,
create_l1c_ql
,
create_l1c_ql_v2
,
create_l2a_ql_v2
s2_tiles_index
=
SHARED_DATA
.
get
(
"
tiles_index
"
)
...
...
@@ -226,9 +225,9 @@ class L1cProduct(Product):
logger
.
info
(
"
{}: processing L1C Quicklook
"
.
format
(
self
.
identifier
))
if
jpg
:
ql_filename
=
self
.
identifier
+
"
_QL.jpg
"
ql_filename
=
self
.
identifier
+
"
_QL
-
"
+
str
(
out_resolution
[
0
])
+
"
m
.jpg
"
else
:
ql_filename
=
self
.
identifier
+
"
_QL.tif
"
ql_filename
=
self
.
identifier
+
"
_QL
-
"
+
str
(
out_resolution
[
0
])
+
"
m
.tif
"
if
out_path
is
None
:
ql_folder
=
self
.
library_path
.
parent
/
"
QL
"
...
...
@@ -240,7 +239,11 @@ class L1cProduct(Product):
if
ql_path
.
exists
()
and
not
reprocess
:
logger
.
info
(
"
{} Quicklook already exists
"
.
format
(
self
.
identifier
))
else
:
create_l1c_ql
(
tci
=
self
.
tci
,
#~ create_l1c_ql(tci = self.tci,
#~ out_path = ql_path,
#~ out_resolution = out_resolution,
#~ jpg = jpg)
create_l1c_ql_v2
(
tci
=
self
.
tci
,
out_path
=
ql_path
,
out_resolution
=
out_resolution
,
jpg
=
jpg
)
...
...
@@ -411,9 +414,9 @@ class L2aProduct(Product):
logger
.
info
(
"
{}: processing L2A Quicklook
"
.
format
(
self
.
identifier
))
if
jpg
:
ql_filename
=
self
.
identifier
+
"
_QL.jpg
"
ql_filename
=
self
.
identifier
+
"
_QL
-
"
+
str
(
out_resolution
[
0
])
+
"
m
.jpg
"
else
:
ql_filename
=
self
.
identifier
+
"
_QL.tif
"
ql_filename
=
self
.
identifier
+
"
_QL
-
"
+
str
(
out_resolution
[
0
])
+
"
m
.tif
"
if
out_path
is
None
:
ql_folder
=
self
.
library_path
.
parent
/
"
QL
"
...
...
@@ -425,12 +428,18 @@ class L2aProduct(Product):
if
ql_path
.
exists
()
and
not
reprocess
:
logger
.
info
(
"
{} Quicklook already exists
"
.
format
(
self
.
identifier
))
else
:
create_l2a_ql
(
b02
=
self
.
b02_10m
,
b03
=
self
.
b03_10m
,
b04
=
self
.
b04_10m
,
#~ create_l2a_ql(b02 = self.b02_10m,
#~ b03 = self.b03_10m,
#~ b04 = self.b04_10m,
#~ out_path = ql_path,
#~ out_resolution = out_resolution,
#~ jpg = jpg)
create_l2a_ql_v2
(
tci
=
self
.
tci_10m
,
out_path
=
ql_path
,
out_resolution
=
out_resolution
,
jpg
=
jpg
)
self
.
user_ql
=
ql_path
return
self
...
...
This diff is collapsed.
Click to expand it.
sen2chain/tiles.py
+
24
−
0
View file @
69aa6e1a
...
...
@@ -995,6 +995,30 @@ class Tile:
l2a_size
=
self
.
archive_l2a
(
size_only
=
size_only
)
return
l1c_size
+
l2a_size
def
compute_ql
(
self
,
product_list
:
list
=
[],
resolution
:
int
=
750
,
jpg
:
bool
=
True
,
):
"""
Produce or update the latest l2a quicklook for the tile
And remove previous ones
"""
for
product
in
product_list
:
# l1c
if
"
l1c
"
in
[
item
.
lower
()
for
item
in
product_list
]:
for
p
in
self
.
l1c
:
l1c
=
L1cProduct
(
p
.
identifier
)
l1c
.
process_ql
(
out_resolution
=
(
resolution
,
resolution
),
jpg
=
jpg
)
# l2a
if
"
l2a
"
in
[
item
.
lower
()
for
item
in
product_list
]:
for
p
in
self
.
l2a
:
l2a
=
L2aProduct
(
p
.
identifier
)
l2a
.
process_ql
(
out_resolution
=
(
resolution
,
resolution
),
jpg
=
True
)
# indices
def
update_latest_ql
(
self
):
"""
Produce or update the latest l2a quicklook for the tile
...
...
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