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
648d92b5
Commit
648d92b5
authored
2 years ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
a19cc702
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
+64
-90
64 additions, 90 deletions
modules/util/util.py
with
64 additions
and
90 deletions
modules/util/util.py
+
64
−
90
View file @
648d92b5
...
@@ -432,11 +432,6 @@ def make_times(dt_str_0, dt_str_1=None, format_code='%Y-%m-%d_%H:%M', num_steps=
...
@@ -432,11 +432,6 @@ def make_times(dt_str_0, dt_str_1=None, format_code='%Y-%m-%d_%H:%M', num_steps=
return
dt_obj_s
,
ts_s
return
dt_obj_s
,
ts_s
def
make_histogram
(
values
,
edges
):
h
=
np
.
histogram
(
values
,
bins
=
edges
)
return
h
def
normalize
(
data
,
param
,
mean_std_dict
,
copy
=
True
):
def
normalize
(
data
,
param
,
mean_std_dict
,
copy
=
True
):
if
mean_std_dict
.
get
(
param
)
is
None
:
if
mean_std_dict
.
get
(
param
)
is
None
:
...
@@ -460,23 +455,6 @@ def normalize(data, param, mean_std_dict, copy=True):
...
@@ -460,23 +455,6 @@ def normalize(data, param, mean_std_dict, copy=True):
return
data
return
data
def
add_noise
(
data
,
noise_scale
=
0.01
,
seed
=
None
,
copy
=
True
):
if
copy
:
data
=
data
.
copy
()
shape
=
data
.
shape
data
=
data
.
flatten
()
if
seed
is
not
None
:
np
.
random
.
seed
(
seed
)
rnd
=
np
.
random
.
normal
(
loc
=
0
,
scale
=
noise_scale
,
size
=
data
.
size
)
data
+=
rnd
data
=
np
.
reshape
(
data
,
shape
)
return
data
def
denormalize
(
data
,
param
,
mean_std_dict
,
copy
=
True
):
def
denormalize
(
data
,
param
,
mean_std_dict
,
copy
=
True
):
if
copy
:
if
copy
:
data
=
data
.
copy
()
data
=
data
.
copy
()
...
@@ -542,18 +520,17 @@ def descale(data, param, mean_std_dict, copy=True):
...
@@ -542,18 +520,17 @@ def descale(data, param, mean_std_dict, copy=True):
return
data
return
data
def
scale2
(
data
,
lo
,
hi
,
copy
=
True
):
def
add_noise
(
data
,
noise_scale
=
0.01
,
seed
=
None
,
copy
=
True
):
if
copy
:
if
copy
:
data
=
data
.
copy
()
data
=
data
.
copy
()
shape
=
data
.
shape
shape
=
data
.
shape
data
=
data
.
flatten
()
data
=
data
.
flatten
()
data
-=
lo
if
seed
is
not
None
:
data
/=
(
hi
-
lo
)
np
.
random
.
seed
(
seed
)
rnd
=
np
.
random
.
normal
(
loc
=
0
,
scale
=
noise_scale
,
size
=
data
.
size
)
not_valid
=
np
.
isnan
(
data
)
data
+=
rnd
data
[
not_valid
]
=
0
data
=
np
.
reshape
(
data
,
shape
)
data
=
np
.
reshape
(
data
,
shape
)
...
@@ -704,6 +681,65 @@ def concat_dict_s(t_dct_0, t_dct_1):
...
@@ -704,6 +681,65 @@ def concat_dict_s(t_dct_0, t_dct_1):
return
t_dct_0
return
t_dct_0
rho_water
=
1000000.0
# g m^-3
rho_ice
=
917000.0
# g m^-3
# real(kind=real4), parameter:: Rho_Water = 1.0 !g / m ^ 3
# real(kind=real4), parameter:: Rho_Ice = 0.917 !g / m ^ 3
#
# !--- compute
# cloud
# water
# path
# if (Iphase == 0) then
# Cwp_Dcomp(Elem_Idx, Line_Idx) = 0.55 * Tau * Reff * Rho_Water
# Lwp_Dcomp(Elem_Idx, Line_Idx) = 0.55 * Tau * Reff * Rho_Water
# else
# Cwp_Dcomp(Elem_Idx, Line_Idx) = 0.667 * Tau * Reff * Rho_Ice
# Iwp_Dcomp(Elem_Idx, Line_Idx) = 0.667 * Tau * Reff * Rho_Ice
# endif
def
compute_lwc_iwc
(
iphase
,
reff
,
opd
,
geo_dz
):
xy_shape
=
iphase
.
shape
iphase
=
iphase
.
flatten
()
keep_0
=
np
.
invert
(
np
.
isnan
(
iphase
))
reff
=
reff
.
flatten
()
keep_1
=
np
.
invert
(
np
.
isnan
(
reff
))
opd
=
opd
.
flatten
()
keep_2
=
np
.
invert
(
np
.
isnan
(
opd
))
geo_dz
=
geo_dz
.
flatten
()
keep_3
=
np
.
logical_and
(
np
.
invert
(
np
.
isnan
(
geo_dz
)),
geo_dz
>
1.0
)
keep
=
keep_0
&
keep_1
&
keep_2
&
keep_3
lwp_dcomp
=
np
.
zeros
(
reff
.
shape
[
0
])
iwp_dcomp
=
np
.
zeros
(
reff
.
shape
[
0
])
lwp_dcomp
[:]
=
np
.
nan
iwp_dcomp
[:]
=
np
.
nan
ice
=
iphase
==
1
&
keep
no_ice
=
iphase
!=
1
&
keep
# compute ice/liquid water path, g m-2
reff
*=
1.0e-06
# convert microns to meters
iwp_dcomp
[
ice
]
=
0.667
*
opd
[
ice
]
*
rho_ice
*
reff
[
ice
]
lwp_dcomp
[
no_ice
]
=
0.55
*
opd
[
no_ice
]
*
rho_water
*
reff
[
no_ice
]
iwp_dcomp
/=
geo_dz
lwp_dcomp
/=
geo_dz
lwp_dcomp
=
lwp_dcomp
.
reshape
(
xy_shape
)
iwp_dcomp
=
iwp_dcomp
.
reshape
(
xy_shape
)
return
lwp_dcomp
,
iwp_dcomp
# Example GOES file to retrieve GEOS parameters in MetPy form (CONUS)
# Example GOES file to retrieve GEOS parameters in MetPy form (CONUS)
exmp_file_conus
=
'
/Users/tomrink/data/OR_ABI-L1b-RadC-M6C14_G16_s20193140811215_e20193140813588_c20193140814070.nc
'
exmp_file_conus
=
'
/Users/tomrink/data/OR_ABI-L1b-RadC-M6C14_G16_s20193140811215_e20193140813588_c20193140814070.nc
'
# Full Disk
# Full Disk
...
@@ -802,68 +838,6 @@ def make_for_full_domain_predict(h5f, name_list=None, satellite='GOES16', domain
...
@@ -802,68 +838,6 @@ def make_for_full_domain_predict(h5f, name_list=None, satellite='GOES16', domain
return
grd_dct
,
ll
,
cc
return
grd_dct
,
ll
,
cc
# rho_water = 1.
# rho_ice = 0.917
rho_water
=
1000000.0
# g m^-3
rho_ice
=
917000.0
# g m^-3
# real(kind=real4), parameter:: Rho_Water = 1.0 !g / m ^ 3
# real(kind=real4), parameter:: Rho_Ice = 0.917 !g / m ^ 3
#
# !--- compute
# cloud
# water
# path
# if (Iphase == 0) then
# Cwp_Dcomp(Elem_Idx, Line_Idx) = 0.55 * Tau * Reff * Rho_Water
# Lwp_Dcomp(Elem_Idx, Line_Idx) = 0.55 * Tau * Reff * Rho_Water
# else
# Cwp_Dcomp(Elem_Idx, Line_Idx) = 0.667 * Tau * Reff * Rho_Ice
# Iwp_Dcomp(Elem_Idx, Line_Idx) = 0.667 * Tau * Reff * Rho_Ice
# endif
def
compute_lwc_iwc
(
iphase
,
reff
,
opd
,
geo_dz
):
xy_shape
=
iphase
.
shape
iphase
=
iphase
.
flatten
()
keep_0
=
np
.
invert
(
np
.
isnan
(
iphase
))
reff
=
reff
.
flatten
()
keep_1
=
np
.
invert
(
np
.
isnan
(
reff
))
opd
=
opd
.
flatten
()
keep_2
=
np
.
invert
(
np
.
isnan
(
opd
))
geo_dz
=
geo_dz
.
flatten
()
keep_3
=
np
.
logical_and
(
np
.
invert
(
np
.
isnan
(
geo_dz
)),
geo_dz
>
1.0
)
keep
=
keep_0
&
keep_1
&
keep_2
&
keep_3
lwp_dcomp
=
np
.
zeros
(
reff
.
shape
[
0
])
iwp_dcomp
=
np
.
zeros
(
reff
.
shape
[
0
])
lwp_dcomp
[:]
=
np
.
nan
iwp_dcomp
[:]
=
np
.
nan
ice
=
iphase
==
1
&
keep
no_ice
=
iphase
!=
1
&
keep
# compute ice/liquid water path, g m-2
reff
*=
1.0e-06
# convert microns to meters
iwp_dcomp
[
ice
]
=
0.667
*
opd
[
ice
]
*
rho_ice
*
reff
[
ice
]
lwp_dcomp
[
no_ice
]
=
0.55
*
opd
[
no_ice
]
*
rho_water
*
reff
[
no_ice
]
iwp_dcomp
/=
geo_dz
lwp_dcomp
/=
geo_dz
lwp_dcomp
=
lwp_dcomp
.
reshape
(
xy_shape
)
iwp_dcomp
=
iwp_dcomp
.
reshape
(
xy_shape
)
return
lwp_dcomp
,
iwp_dcomp
def
make_for_full_domain_predict_viirs_clavrx
(
h5f
,
name_list
=
None
,
res_fac
=
1
,
day_night
=
'
DAY
'
,
use_dnb
=
False
):
def
make_for_full_domain_predict_viirs_clavrx
(
h5f
,
name_list
=
None
,
res_fac
=
1
,
day_night
=
'
DAY
'
,
use_dnb
=
False
):
w_x
=
16
w_x
=
16
w_y
=
16
w_y
=
16
...
...
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