Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python
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
Tom Rink
python
Commits
44654e9d
Commit
44654e9d
authored
2 years ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
initial commit...
parent
7d580df5
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/util/viirs_l1b_l2.py
+156
-0
156 additions, 0 deletions
modules/util/viirs_l1b_l2.py
with
156 additions
and
0 deletions
modules/util/viirs_l1b_l2.py
0 → 100644
+
156
−
0
View file @
44654e9d
import
numpy
as
np
import
h5py
from
util.util
import
get_grid_values
,
get_grid_values_all
import
glob
import
os
from
pathlib
import
Path
emis_params
=
[
'
temp_10_4um_nom
'
,
'
temp_11_0um_nom
'
,
'
temp_12_0um_nom
'
,
'
temp_13_3um_nom
'
,
'
temp_3_75um_nom
'
,
'
temp_6_2um_nom
'
,
'
temp_6_7um_nom
'
,
'
temp_7_3um_nom
'
,
'
temp_8_5um_nom
'
,
'
temp_9_7um_nom
'
]
l2_params
=
[
'
cld_opd_acha
'
,
'
cloud_fraction
'
]
def
run_all
(
directory
):
cnt
=
0
for
p
in
os
.
scandir
(
directory
):
if
not
p
.
is_dir
():
continue
cnt
+=
1
l1b_files
=
glob
.
glob
(
directory
+
p
.
name
+
'
/
'
+
'
clavrx_snpp_viirs*.uwssec.nc
'
)
l1b_tiles
=
[]
l2_tiles
=
[]
for
idx
,
l1b_f
in
enumerate
(
l1b_files
):
if
idx
%
8
==
0
:
w_o_ext
,
ext
=
os
.
path
.
splitext
(
l1b_f
)
l2_f
=
w_o_ext
+
'
.highres
'
+
ext
if
not
os
.
path
.
exists
(
l2_f
):
continue
print
(
l1b_f
)
try
:
l1b_h5f
=
h5py
.
File
(
l1b_f
,
'
r
'
)
except
:
print
(
'
cant open file:
'
,
l1b_f
)
continue
try
:
l2_h5f
=
h5py
.
File
(
l2_f
,
'
r
'
)
except
:
print
(
'
cant open file:
'
,
l2_f
)
l1b_h5f
.
close
()
continue
try
:
run
(
l1b_h5f
,
l2_h5f
,
l1b_tiles
,
l2_tiles
)
except
:
l1b_h5f
.
close
()
l2_h5f
.
close
()
continue
l1b_h5f
.
close
()
l2_h5f
.
close
()
if
len
(
l1b_tiles
)
or
len
(
l2_tiles
)
==
0
:
continue
l1b_nda
=
np
.
stack
(
l1b_tiles
)
l2_nda
=
np
.
stack
(
l2_tiles
)
np
.
save
(
'
/data/Personal/rink/viirs_clavrx/l1b_
'
+
str
(
cnt
),
l1b_nda
)
np
.
save
(
'
/data/Personal/rink/viirs_clavrx/l2_
'
+
str
(
cnt
),
l2_nda
)
def
run
(
l1b_h5f
,
l2_h5f
,
l1b_tiles
,
l2_tiles
,
factor
=
2
):
if
l2_h5f
is
None
:
l2_h5f
=
l1b_h5f
l1b_param_name
=
emis_params
[
0
]
l2_param_name
=
l2_params
[
0
]
mod_tile_width
=
64
img_tile_width
=
mod_tile_width
*
factor
mod_num_lines
=
l1b_h5f
[
l1b_param_name
].
shape
[
0
]
mod_num_pixels
=
l1b_h5f
[
l1b_param_name
].
shape
[
1
]
img_num_lines
=
l2_h5f
[
l2_param_name
].
shape
[
0
]
img_num_pixels
=
l2_h5f
[
l2_param_name
].
shape
[
1
]
mod_num_y_tiles
=
int
(
mod_num_lines
/
mod_tile_width
)
mod_num_x_tiles
=
int
(
mod_num_pixels
/
mod_tile_width
)
l1b_grd_s
=
[]
l2_grd_s
=
[]
for
param
in
emis_params
:
l1b_grd_s
.
append
(
get_grid_values
(
l1b_h5f
,
param
,
0
,
0
,
None
,
mod_num_lines
,
mod_num_pixels
,
range_name
=
None
))
for
param
in
l2_params
:
l2_grd_s
.
append
(
get_grid_values
(
l2_h5f
,
param
,
0
,
0
,
None
,
img_num_lines
,
img_num_pixels
,
range_name
=
None
))
mod_data
=
np
.
stack
(
l1b_grd_s
)
img_data
=
np
.
stack
(
l2_grd_s
)
num_cntr_tiles
=
10
i_c
=
int
(
mod_num_pixels
/
num_cntr_tiles
)
# center
j_skip
=
int
(
mod_num_y_tiles
/
num_cntr_tiles
)
*
mod_tile_width
for
k
in
range
(
num_cntr_tiles
):
j_c
=
k
*
j_skip
j_m
=
j_c
j_i
=
j_m
*
factor
i_m
=
i_c
i_i
=
i_m
*
factor
nda
=
mod_data
[:,
j_m
:
j_m
+
mod_tile_width
,
i_m
:
i_m
+
mod_tile_width
]
l1b_tiles
.
append
(
nda
)
nda
=
img_data
[:,
j_i
:
j_i
+
img_tile_width
,
i_i
:
i_i
+
img_tile_width
]
l2_tiles
.
append
(
nda
)
# for j in range(mod_num_y_tiles):
# j_m = j * mod_tile_width
# j_i = j_m * 2
# for i in range(mod_num_x_tiles):
# i_m = i * mod_tile_width
# i_i = i_m * 2
#
# nda = mod_data[j_m:j_m+mod_tile_width, i_m:i_m+mod_tile_width]
# mod_tiles.append(nda)
# nda = img_data[j_i:j_i+img_tile_width, i_i:i_i+img_tile_width]
# img_tiles.append(nda)
# def run_mean_std(directory):
#
# data_dct = {name: [] for name in mod_res_params}
# mean_dct = {name: 0 for name in mod_res_params}
# std_dct = {name: 0 for name in mod_res_params}
#
# for p in os.scandir(directory):
# if not p.is_dir():
# continue
# mod_files = glob.glob(directory+p.name+'/'+'VNP02MOD*.uwssec.nc')
#
# for idx, mfile in enumerate(mod_files):
# if idx % 8 == 0:
# h5f = h5py.File(mfile, 'r')
# for param in mod_res_params:
# name = 'observation_data/'+param
# gvals = get_grid_values_all(h5f, name, range_name=None, stride=10)
# data_dct[param].append(gvals.flatten())
# print(mfile)
# h5f.close()
#
# for param in mod_res_params:
# data = data_dct[param]
# data = np.concatenate(data)
#
# mean_dct[param] = np.nanmean(data)
# std_dct[param] = np.nanstd(data)
#
# print(mean_dct)
# print(std_dct)
\ No newline at end of file
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