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
373fabe6
Commit
373fabe6
authored
1 year ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
648d92b5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/util/util.py
+75
-75
75 additions, 75 deletions
modules/util/util.py
with
75 additions
and
75 deletions
modules/util/util.py
+
75
−
75
View file @
373fabe6
...
...
@@ -333,6 +333,81 @@ def get_median(tile_2d):
return
np
.
nanmedian
(
tile
)
def
get_grid_values
(
h5f
,
grid_name
,
j_c
,
i_c
,
half_width
,
num_j
=
None
,
num_i
=
None
,
scale_factor_name
=
'
scale_factor
'
,
add_offset_name
=
'
add_offset
'
,
fill_value_name
=
'
_FillValue
'
,
valid_range_name
=
'
valid_range
'
,
actual_range_name
=
'
actual_range
'
,
fill_value
=
None
):
hfds
=
h5f
[
grid_name
]
attrs
=
hfds
.
attrs
if
attrs
is
None
:
raise
GenericException
(
'
No attributes object for:
'
+
grid_name
)
ylen
,
xlen
=
hfds
.
shape
if
half_width
is
not
None
:
j_l
=
j_c
-
half_width
i_l
=
i_c
-
half_width
if
j_l
<
0
or
i_l
<
0
:
return
None
j_r
=
j_c
+
half_width
+
1
i_r
=
i_c
+
half_width
+
1
if
j_r
>=
ylen
or
i_r
>=
xlen
:
return
None
else
:
j_l
=
j_c
j_r
=
j_c
+
num_j
+
1
i_l
=
i_c
i_r
=
i_c
+
num_i
+
1
grd_vals
=
hfds
[
j_l
:
j_r
,
i_l
:
i_r
]
if
fill_value_name
is
not
None
:
attr
=
attrs
.
get
(
fill_value_name
)
if
attr
is
not
None
:
if
np
.
isscalar
(
attr
):
fill_value
=
attr
else
:
fill_value
=
attr
[
0
]
grd_vals
=
np
.
where
(
grd_vals
==
fill_value
,
np
.
nan
,
grd_vals
)
elif
fill_value
is
not
None
:
grd_vals
=
np
.
where
(
grd_vals
==
fill_value
,
np
.
nan
,
grd_vals
)
if
valid_range_name
is
not
None
:
attr
=
attrs
.
get
(
valid_range_name
)
if
attr
is
not
None
:
low
=
attr
[
0
]
high
=
attr
[
1
]
grd_vals
=
np
.
where
(
grd_vals
<
low
,
np
.
nan
,
grd_vals
)
grd_vals
=
np
.
where
(
grd_vals
>
high
,
np
.
nan
,
grd_vals
)
if
scale_factor_name
is
not
None
:
attr
=
attrs
.
get
(
scale_factor_name
)
if
attr
is
not
None
:
if
np
.
isscalar
(
attr
):
scale_factor
=
attr
else
:
scale_factor
=
attr
[
0
]
grd_vals
=
grd_vals
*
scale_factor
if
add_offset_name
is
not
None
:
attr
=
attrs
.
get
(
add_offset_name
)
if
attr
is
not
None
:
if
np
.
isscalar
(
attr
):
add_offset
=
attr
else
:
add_offset
=
attr
[
0
]
grd_vals
=
grd_vals
+
add_offset
if
actual_range_name
is
not
None
:
attr
=
attrs
.
get
(
actual_range_name
)
if
attr
is
not
None
:
low
=
attr
[
0
]
high
=
attr
[
1
]
grd_vals
=
np
.
where
(
grd_vals
<
low
,
np
.
nan
,
grd_vals
)
grd_vals
=
np
.
where
(
grd_vals
>
high
,
np
.
nan
,
grd_vals
)
return
grd_vals
def
get_grid_values_all
(
h5f
,
grid_name
,
scale_factor_name
=
'
scale_factor
'
,
add_offset_name
=
'
add_offset
'
,
fill_value_name
=
'
_FillValue
'
,
valid_range_name
=
'
valid_range
'
,
actual_range_name
=
'
actual_range
'
,
fill_value
=
None
,
stride
=
None
):
hfds
=
h5f
[
grid_name
]
...
...
@@ -588,81 +663,6 @@ def get_cartopy_crs(satellite, domain):
return
geos
,
xlen
,
xmin
,
xmax
,
ylen
,
ymin
,
ymax
def
get_grid_values
(
h5f
,
grid_name
,
j_c
,
i_c
,
half_width
,
num_j
=
None
,
num_i
=
None
,
scale_factor_name
=
'
scale_factor
'
,
add_offset_name
=
'
add_offset
'
,
fill_value_name
=
'
_FillValue
'
,
valid_range_name
=
'
valid_range
'
,
actual_range_name
=
'
actual_range
'
,
fill_value
=
None
):
hfds
=
h5f
[
grid_name
]
attrs
=
hfds
.
attrs
if
attrs
is
None
:
raise
GenericException
(
'
No attributes object for:
'
+
grid_name
)
ylen
,
xlen
=
hfds
.
shape
if
half_width
is
not
None
:
j_l
=
j_c
-
half_width
i_l
=
i_c
-
half_width
if
j_l
<
0
or
i_l
<
0
:
return
None
j_r
=
j_c
+
half_width
+
1
i_r
=
i_c
+
half_width
+
1
if
j_r
>=
ylen
or
i_r
>=
xlen
:
return
None
else
:
j_l
=
j_c
j_r
=
j_c
+
num_j
+
1
i_l
=
i_c
i_r
=
i_c
+
num_i
+
1
grd_vals
=
hfds
[
j_l
:
j_r
,
i_l
:
i_r
]
if
fill_value_name
is
not
None
:
attr
=
attrs
.
get
(
fill_value_name
)
if
attr
is
not
None
:
if
np
.
isscalar
(
attr
):
fill_value
=
attr
else
:
fill_value
=
attr
[
0
]
grd_vals
=
np
.
where
(
grd_vals
==
fill_value
,
np
.
nan
,
grd_vals
)
elif
fill_value
is
not
None
:
grd_vals
=
np
.
where
(
grd_vals
==
fill_value
,
np
.
nan
,
grd_vals
)
if
valid_range_name
is
not
None
:
attr
=
attrs
.
get
(
valid_range_name
)
if
attr
is
not
None
:
low
=
attr
[
0
]
high
=
attr
[
1
]
grd_vals
=
np
.
where
(
grd_vals
<
low
,
np
.
nan
,
grd_vals
)
grd_vals
=
np
.
where
(
grd_vals
>
high
,
np
.
nan
,
grd_vals
)
if
scale_factor_name
is
not
None
:
attr
=
attrs
.
get
(
scale_factor_name
)
if
attr
is
not
None
:
if
np
.
isscalar
(
attr
):
scale_factor
=
attr
else
:
scale_factor
=
attr
[
0
]
grd_vals
=
grd_vals
*
scale_factor
if
add_offset_name
is
not
None
:
attr
=
attrs
.
get
(
add_offset_name
)
if
attr
is
not
None
:
if
np
.
isscalar
(
attr
):
add_offset
=
attr
else
:
add_offset
=
attr
[
0
]
grd_vals
=
grd_vals
+
add_offset
if
actual_range_name
is
not
None
:
attr
=
attrs
.
get
(
actual_range_name
)
if
attr
is
not
None
:
low
=
attr
[
0
]
high
=
attr
[
1
]
grd_vals
=
np
.
where
(
grd_vals
<
low
,
np
.
nan
,
grd_vals
)
grd_vals
=
np
.
where
(
grd_vals
>
high
,
np
.
nan
,
grd_vals
)
return
grd_vals
def
concat_dict_s
(
t_dct_0
,
t_dct_1
):
keys_0
=
list
(
t_dct_0
.
keys
())
nda_0
=
np
.
array
(
keys_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