Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MVCM
Manage
Activity
Members
Labels
Plan
Issues
1
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
Paolo Veglio
MVCM
Commits
3ce76d86
Commit
3ce76d86
authored
10 months ago
by
Paolo Veglio
Browse files
Options
Downloads
Patches
Plain Diff
bump version
parent
869c5e84
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#51767
failed with stages
in 7 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+0
-1
0 additions, 1 deletion
.gitlab-ci.yml
mvcm/__init__.py
+1
-1
1 addition, 1 deletion
mvcm/__init__.py
mvcm/main.py
+11
-90
11 additions, 90 deletions
mvcm/main.py
mvcm/preprocess_thresholds.py
+5
-3
5 additions, 3 deletions
mvcm/preprocess_thresholds.py
with
17 additions
and
95 deletions
.gitlab-ci.yml
+
0
−
1
View file @
3ce76d86
...
...
@@ -10,7 +10,6 @@ ci:
services
:
-
docker:19.03.1-dind
script
:
-
docker --version
-
docker login --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD $CI_REGISTRY
-
cd ci
-
docker build --tag $CI_REGISTRY_IMAGE .
...
...
This diff is collapsed.
Click to expand it.
mvcm/__init__.py
+
1
−
1
View file @
3ce76d86
"""
Set up version.
"""
__version__
=
"
0.2.
3
"
__version__
=
"
0.2.
4
"
This diff is collapsed.
Click to expand it.
mvcm/main.py
+
11
−
90
View file @
3ce76d86
...
...
@@ -12,6 +12,7 @@ import time
import
numpy
as
np
import
xarray
as
xr
from
netCDF4
import
Dataset
from
pkg_resources
import
get_distribution
# type: ignore
from
rich.logging
import
RichHandler
...
...
@@ -217,7 +218,11 @@ def main(
return
logger
.
info
(
f
"
All bands found in file
{
file_names
[
'
IMG02
'
]
}
. The code will run.
"
)
# logger.info(f"Reading VNP02: {file_names['MOD02']}")
with
Dataset
(
file_names
[
"
MOD03
"
])
as
f
:
# time_coverage_start = f.getncattr("time_coverage_start")
# time_coverage_end = f.getncattr("time_coverage_end")
# orbit_number = f.getncattr("OrbitNumber")
attrs
=
{
attr
:
f
.
getncattr
(
attr
)
for
attr
in
f
.
ncattrs
()}
viirs_data
=
rd
.
get_data
(
satellite
,
sensor
,
file_names
,
hires
=
use_hires
)
...
...
@@ -483,33 +488,8 @@ def main(
# cmin,
# bits['r06'])[idx]
# cmin_3d[i, :, :] = cmin
# i += 1
# cmin_final = np.min(cmin_3d, axis=0)
# bit['15'] = np.max(temp_bit, axis=0)
cmin_final
=
cmin
"""
idx = np.nonzero((scene_flags[
'
day
'
] == 1) & (scene_flags[
'
water
'
] == 1) &
(scene_flags[
'
ice
'
] == 0))
cmin[idx] = restore.shallow_water(sh_water_bits, cmin)[idx]
idx = np.nonzero((scene_flags[
'
day
'
] == 1) & (scene_flags[
'
land
'
] == 1) &
(scene_flags[
'
snow
'
] == 0) & (scene_flags[
'
ice
'
] == 0) &
(cmin <= 0.95))
cmin[idx] = restore.land(land_bits, cmin)[idx]
idx = np.nonzero((scene_flags[
'
day
'
] == 1) & (scene_flags[
'
land
'
] == 1) &
(scene_flags[
'
snow
'
] == 0) & (scene_flags[
'
ice
'
] == 0) &
(scene_flags[
'
coast
'
] == 1))
cmin[idx] = restore.coast(coast_bits, cmin)[idx]
idx = np.nonzero((scene_flags[
'
night
'
] == 1) & (scene_flags[
'
land
'
] == 1) &
(scene_flags[
'
snow
'
] == 0) & (scene_flags[
'
ice
'
] == 0) &
(cmin <= 0.95))
cmin[idx] = restore.land_night(land_night_bits, cmin)[idx]
"""
# bits translation MVCM-python -> MVCM-C
# 01 13 test_11um
# 02 27 surface_temperature_test
...
...
@@ -523,29 +503,6 @@ def main(
# 15 16 test_1_38um_high_clouds
# 16 17 thin_cirrus_4_12um_BTD_test
# if scene_name in ['Ocean_Day']:
# # total_bit = np.full(viirs_data.M01.shape, 4)
# total_bit = bit1 + bit2 + bit4 + bit11
# sunglint_angle = thresholds['Sun_Glint']['bounds'][3]
# scene_flags = scn.find_scene(viirs_data, sunglint_angle)
#
# # idx = np.nonzero((scene_flags['water'] == 1) &
# (scene_flags['ice'] == 0) &
# # (scene_flags['uniform'] == 1) &
# (cmin <= 0.99) & (cmin >= 0.05))
# # cmin[idx] = restoral.spatial(viirs_data, thresholds['Sun_Glint'],
# scene_flags, cmin)[idx]
#
# idx = np.nonzero((scene_flags['water'] == 1) &
# (scene_flags['sunglint'] == 1) &
# (scene_flags['uniform'] == 1) & (cmin <= 0.95))
# cmin[idx] = restoral.sunglint(viirs_data, thresholds['Sun_Glint'],
# total_bit, cmin)[idx]
#
# # MVCM = tst.ComputeTests(viirs_data, scene_name, thresholds)
# # cmin = MVCM.clear_sky_restoral(cmin)
#
# # return cmin
csc
=
cmin_final
cloud_mask
=
np
.
zeros
(
csc
.
shape
)
cloud_mask
[
csc
>
0.99
]
=
3
...
...
@@ -560,6 +517,7 @@ def main(
"
longitude
"
:
{
"
dims
"
:
(
"
x
"
,
"
y
"
),
"
data
"
:
viirs_data
.
longitude
.
values
},
"
confidence
"
:
{
"
dims
"
:
(
"
x
"
,
"
y
"
),
"
data
"
:
cmin_final
},
"
cloud_mask
"
:
{
"
dims
"
:
(
"
x
"
,
"
y
"
),
"
data
"
:
cloud_mask
},
"
sensor_zenith
"
:
{
"
dims
"
:
(
"
x
"
,
"
y
"
),
"
data
"
:
viirs_data
.
sensor_zenith
.
values
},
}
d_debug
=
{
"
ndvi
"
:
{
"
dims
"
:
(
"
x
"
,
"
y
"
),
"
data
"
:
viirs_data
.
ndvi
.
values
},
...
...
@@ -632,54 +590,17 @@ def main(
ds_out
=
xr
.
Dataset
.
from_dict
(
out_dict
)
comp
=
dict
(
zlib
=
True
,
complevel
=
5
)
comp
=
{
"
zlib
"
:
True
,
"
complevel
"
:
5
}
if
type
(
ds_out
)
is
xr
.
Dataset
:
for
var
in
ds_out
:
ds_out
[
var
].
encoding
.
update
(
comp
)
if
type
(
ds_out
)
is
xr
.
DataArray
:
ds_out
.
encoding
.
update
(
comp
)
# if use_hires is False:
# ds_out.to_netcdf('test_w_restorals.nc')
# else:
# ds_out.to_netcdf('test_hires.nc')
ds_out
.
to_netcdf
(
out_file
)
"""
def test_main():
rad1 = [
[255, 260, 265, 248, 223],
[278, 285, 270, 268, 256],
[275, 273, 266, 254, 259],
]
rad2 = [
[270, 273, 271, 268, 265],
[277, 286, 275, 277, 269],
[280, 281, 272, 270, 267],
]
thresh_file = (
"
/home/pveglio/mvcm_leo/thresholds/new_thresholds.mvcm.snpp.v1.0.0.yaml
"
)
with open(thresh_file) as f:
text = f.read()
rad1 = np.array(rad1)
rad2 = np.array(rad2)
for
attr
in
attrs
:
ds_out
.
attrs
[
attr
]
=
attrs
[
attr
]
confidence = np.zeros((2, rad1.shape[0], rad1.shape[1]))
thresholds = yml.safe_load(text)
confidence[0, :, :] = tests.test_11um(rad1, thresholds[
"
Daytime_Ocean
"
])
confidence[1, :, :] = tests.test_11_4diff(rad1, rad2, thresholds[
"
Daytime_Ocean
"
])
print(f
"
Confidence[0,:,:]:
\n
{confidence[0, :, :]}
"
)
print(f
"
Confidence[1,:,:]:
\n
{confidence[1, :, :]}
"
)
return confidence
"""
ds_out
.
to_netcdf
(
out_file
)
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
mvcm/preprocess_thresholds.py
+
5
−
3
View file @
3ce76d86
...
...
@@ -16,7 +16,7 @@ _DTR = np.pi / 180
logger
=
logging
.
getLogger
(
__name__
)
def
prepare_11_12um_thresholds
(
thresholds
:
D
ict
,
dim1
:
int
)
->
D
ict
:
def
prepare_11_12um_thresholds
(
thresholds
:
d
ict
,
dim1
:
int
)
->
d
ict
:
"""
Prepare 11-12um test thresholds.
"""
coeff_values
=
np
.
empty
((
dim1
,
2
))
coeff_values
[:,
0
]
=
np
.
full
(
dim1
,
thresholds
[
"
coeffs
"
][
0
])
...
...
@@ -108,9 +108,11 @@ def thresholds_11_12um(
elif
scene
in
[
"
Day_Snow
"
]:
hicut
=
locut
-
(
thr_dict
[
"
cmult
"
]
*
locut
)
else
:
raise
ValueError
(
"
Scene name not valid
"
)
err_msg
=
"
Scene name not valid
"
raise
ValueError
(
err_msg
)
else
:
raise
ValueError
(
"
Scene name not valid
"
)
err_msg
=
"
Scene name not valid
"
raise
ValueError
(
err_msg
)
thr_out
=
np
.
dstack
((
locut
,
midpt
,
hicut
,
np
.
ones
(
locut
.
shape
),
np
.
ones
(
locut
.
shape
)))
return
np
.
squeeze
(
thr_out
.
T
)
...
...
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