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
68c953e2
Commit
68c953e2
authored
9 months ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
3defb60d
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/gfs_reader.py
+19
-26
19 additions, 26 deletions
modules/util/gfs_reader.py
with
19 additions
and
26 deletions
modules/util/gfs_reader.py
+
19
−
26
View file @
68c953e2
...
@@ -5,6 +5,7 @@ import os
...
@@ -5,6 +5,7 @@ import os
import
numpy
as
np
import
numpy
as
np
import
xarray
as
xr
import
xarray
as
xr
# from util.util import value_to_index, homedir
# from util.util import value_to_index, homedir
from
metpy.units
import
units
# gfs_directory = '/ships22/cloud/Ancil_Data/clavrx_ancil_data/dynamic/gfs/'
# gfs_directory = '/ships22/cloud/Ancil_Data/clavrx_ancil_data/dynamic/gfs/'
homedir
=
os
.
path
.
expanduser
(
'
~
'
)
+
'
/
'
homedir
=
os
.
path
.
expanduser
(
'
~
'
)
+
'
/
'
...
@@ -102,12 +103,9 @@ def get_bounding_gfs_files(timestamp):
...
@@ -102,12 +103,9 @@ def get_bounding_gfs_files(timestamp):
def
get_horz_layer
(
xr_dataset
,
fld_name
,
press
,
lon_range
=
None
,
lat_range
=
None
):
def
get_horz_layer
(
xr_dataset
,
fld_name
,
press
,
lon_range
=
None
,
lat_range
=
None
):
p_idx
=
value_to_index
(
plevs
,
press
)
p_idx
=
value_to_index
(
plevs
,
press
)
fld
=
xr_dataset
[
fld_name
]
x_lo
=
0
x_lo
,
x_hi
=
0
,
NX
x_hi
=
NX
y_lo
,
y_hi
=
0
,
NY
y_lo
=
0
y_hi
=
NY
if
lon_range
is
not
None
:
if
lon_range
is
not
None
:
lon_lo
=
lon_range
[
0
]
lon_lo
=
lon_range
[
0
]
...
@@ -125,12 +123,13 @@ def get_horz_layer(xr_dataset, fld_name, press, lon_range=None, lat_range=None):
...
@@ -125,12 +123,13 @@ def get_horz_layer(xr_dataset, fld_name, press, lon_range=None, lat_range=None):
y_lo
=
value_to_index
(
lat_coords
,
lat_lo
)
y_lo
=
value_to_index
(
lat_coords
,
lat_lo
)
y_hi
=
value_to_index
(
lat_coords
,
lat_hi
)
y_hi
=
value_to_index
(
lat_coords
,
lat_hi
)
sub_fld
=
fld
[
y_lo
:
y_hi
,
x_lo
:
x_hi
,
p_idx
]
nda
=
xr_dataset
[
fld_name
].
values
sub_fld
=
sub_fld
.
expand_dims
(
'
channel
'
)
sub_nda
=
nda
[
y_lo
:
y_hi
,
x_lo
:
x_hi
,
p_idx
]
xra
=
xr
.
DataArray
(
sub_nda
,
dims
=
[
'
latitude
'
,
'
longitude
'
],
sub_fld
=
sub_fld
.
assign_coords
(
channel
=
[
fld_name
],
fakeDim2
=
lon_coords
[
x_lo
:
x_hi
],
fakeDim1
=
lat_coords
[
y_lo
:
y_hi
])
coords
=
{
"
latitude
"
:
lat_coords
[
y_lo
:
y_hi
],
"
longitude
"
:
lon_coords
[
x_lo
:
x_hi
]},
attrs
=
{
"
description
"
:
fld_name
,
"
units
"
:
'
m/s
'
})
return
sub_fld
return
xra
def
get_horz_layer_s
(
xr_dataset
,
fld_names
,
press
,
lon_range
=
None
,
lat_range
=
None
):
def
get_horz_layer_s
(
xr_dataset
,
fld_names
,
press
,
lon_range
=
None
,
lat_range
=
None
):
...
@@ -444,14 +443,11 @@ def get_voxel_s(xr_dataset, fld_name_s, lon, lat, press, x_width=3, y_width=3, z
...
@@ -444,14 +443,11 @@ def get_voxel_s(xr_dataset, fld_name_s, lon, lat, press, x_width=3, y_width=3, z
return
sub_fld
return
sub_fld
def
get_volume
(
xr_dataset
,
fld_name
_s
,
press_range
=
None
,
lon_range
=
None
,
lat_range
=
None
):
def
get_volume
(
xr_dataset
,
fld_name
,
press_range
=
None
,
lon_range
=
None
,
lat_range
=
None
):
x_lo
=
0
x_lo
,
x_hi
=
0
,
NX
x_hi
=
NX
y_lo
,
y_hi
=
0
,
NY
y_lo
=
0
z_lo
,
z_hi
=
0
,
NZ
y_hi
=
NY
z_lo
=
0
z_hi
=
NZ
if
lon_range
is
not
None
:
if
lon_range
is
not
None
:
lon_lo
=
lon_range
[
0
]
lon_lo
=
lon_range
[
0
]
...
@@ -477,13 +473,10 @@ def get_volume(xr_dataset, fld_name_s, press_range=None, lon_range=None, lat_ran
...
@@ -477,13 +473,10 @@ def get_volume(xr_dataset, fld_name_s, press_range=None, lon_range=None, lat_ran
z_lo
=
value_to_index
(
plevs
,
press_range
[
0
])
z_lo
=
value_to_index
(
plevs
,
press_range
[
0
])
z_hi
=
value_to_index
(
plevs
,
press_range
[
1
])
z_hi
=
value_to_index
(
plevs
,
press_range
[
1
])
sub_fld_s
=
[]
nda
=
xr_dataset
[
fld_name
].
values
for
name
in
fld_name_s
:
sub_nda
=
nda
[
y_lo
:
y_hi
,
x_lo
:
x_hi
,
z_lo
:
z_hi
]
fld
=
xr_dataset
[
name
]
xra
=
xr
.
DataArray
(
sub_nda
,
dims
=
[
'
Latitude
'
,
'
Longitude
'
,
'
Pressure
'
],
sub_fld
=
fld
[
y_lo
:
y_hi
,
x_lo
:
x_hi
,
z_lo
:
z_hi
]
coords
=
{
"
Latitude
"
:
lat_coords
[
y_lo
:
y_hi
],
"
Longitude
"
:
lon_coords
[
x_lo
:
x_hi
],
"
Pressure
"
:
plevs
[
z_lo
:
z_hi
]},
sub_fld_s
.
append
(
sub_fld
)
attrs
=
{
"
description
"
:
fld_name
,
"
units
"
:
'
m s-1
'
})
sub_fld
=
xr
.
concat
(
sub_fld_s
,
'
channel
'
)
sub_fld
=
sub_fld
.
assign_coords
(
channel
=
fld_name_s
,
fakeDim2
=
lon_coords
[
x_lo
:
x_hi
],
fakeDim1
=
lat_coords
[
y_lo
:
y_hi
],
fakeDim0
=
plevs
[
z_lo
:
z_hi
])
return
xra
return
sub_fld
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