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
54955f73
Commit
54955f73
authored
5 months ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
bb220565
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/resample.py
+25
-19
25 additions, 19 deletions
modules/util/resample.py
with
25 additions
and
19 deletions
modules/util/resample.py
+
25
−
19
View file @
54955f73
import
h5py
import
numpy
as
np
from
scipy.interpolate
import
RegularGridInterpolator
,
griddata
from
cartopy.crs
import
LambertAzimuthalEqualArea
import
cartopy.crs
as
ccrs
from
netCDF4
import
Dataset
import
xarray
as
xr
from
util.util
import
get_grid_values_all
# resample methods:
...
...
@@ -72,7 +70,7 @@ def reproject(fld_2d, lat_2d, lon_2d, proj, target_grid=None, grid_spacing=15000
automatically. The target grid is always returned.
:param grid_spacing: distance between the target grid points (in meters)
:param method: resampling method:
'
linear
'
,
'
nearest
'
,
'
cubic
'
:return: reprojected 2D scalar field, the target grid
(will be 2D if rotate=True)
:return: reprojected 2D scalar field, the target grid
"""
data_xy
=
proj
.
transform_points
(
ccrs
.
PlateCarree
(),
lon_2d
,
lat_2d
)[...,
:
2
]
...
...
@@ -112,29 +110,37 @@ def bisect_great_circle(lon_a, lat_a, lon_b, lat_b):
return
lon_c
,
lat_c
def
acspo_sst
(
filename
):
def
acspo_sst
(
filename
,
stride
=
2
,
grid_spacing
=
2000
):
h5f
=
h5py
.
File
(
filename
,
'
r
'
)
sst
=
get_grid_values_all
(
h5f
,
'
sea_surface_temperature
'
)
sst
=
sst
[
0
,
:,
:]
print
(
sst
.
shape
)
lons
=
get_grid_values_all
(
h5f
,
'
lon
'
)
lats
=
get_grid_values_all
(
h5f
,
'
lat
'
)
print
(
lons
.
shape
,
lats
.
shape
)
sst
=
sst
[::
2
,
::
2
]
lons
=
lons
[::
2
,
::
2
]
lats
=
lats
[::
2
,
::
2
]
# operational
# sst = get_grid_values_all(h5f, 'sea_surface_temperature')
# sst = sst[0, :, :]
# lons = get_grid_values_all(h5f, 'lon')
# lats = get_grid_values_all(h5f, 'lat')
# classic
sst
=
get_grid_values_all
(
h5f
,
'
sst_regression
'
)
sst
=
sst
[:,
:]
lons
=
get_grid_values_all
(
h5f
,
'
longitude
'
)
lats
=
get_grid_values_all
(
h5f
,
'
latitude
'
)
print
(
'
data dims:
'
,
lons
.
shape
,
lats
.
shape
)
sst
=
sst
[::
stride
,
::
stride
]
lons
=
lons
[::
stride
,
::
stride
]
lats
=
lats
[::
stride
,
::
stride
]
ylen
,
xlen
=
lons
.
shape
print
(
ylen
,
xlen
)
print
(
'
final dims:
'
,
ylen
,
xlen
)
cen_lon
=
lons
[
ylen
//
2
,
xlen
//
2
]
cen_lat
=
lats
[
ylen
//
2
,
xlen
//
2
]
print
(
cen_lat
,
cen_lon
)
cen_lon
=
lons
[
ylen
//
stride
,
xlen
//
stride
]
cen_lat
=
lats
[
ylen
//
stride
,
xlen
//
stride
]
print
(
'
center latitude/longitude:
'
,
cen_lat
,
cen_lon
)
proj
=
get_projection
(
'
LambertAzimuthalEqualArea
'
,
cen_lat
,
cen_lon
)
fld_reproj
,
(
y_map_2d
,
x_map_2d
)
=
reproject
(
sst
,
lats
,
lons
,
proj
,
grid_spacing
=
2000.0
)
fld_reproj
,
(
y_map_2d
,
x_map_2d
)
=
reproject
(
sst
,
lats
,
lons
,
proj
,
grid_spacing
=
grid_spacing
)
return
fld_reproj
,
proj
,
y_map_2d
,
x_map_2d
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