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
bc422734
Commit
bc422734
authored
3 years ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
52851844
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/lon_lat_grid.py
+5
-3
5 additions, 3 deletions
modules/util/lon_lat_grid.py
with
5 additions
and
3 deletions
modules/util/lon_lat_grid.py
+
5
−
3
View file @
bc422734
...
@@ -19,7 +19,7 @@ class MyGenericException(Exception):
...
@@ -19,7 +19,7 @@ class MyGenericException(Exception):
class
LonLatGrid
:
class
LonLatGrid
:
# grd_lons, grd_lats: the longitude, latitude of each grid point (must be 2D grids), must have same shape
# grd_lons, grd_lats: the longitude, latitude of each grid point (must be 2D grids), must have same shape
# Incoming longitude must be in range: 0 - 360 degrees
# Incoming longitude must be in range: 0 - 360 degrees
# Can have NaN for off Earth grid points.
# Can have NaN for off Earth grid points
(these are handled internally)
.
def
__init__
(
self
,
grd_lons
,
grd_lats
):
def
__init__
(
self
,
grd_lons
,
grd_lats
):
if
grd_lons
.
shape
!=
grd_lats
.
shape
:
if
grd_lons
.
shape
!=
grd_lats
.
shape
:
raise
MyGenericException
(
'
incoming lons,lats must have same shape
'
)
raise
MyGenericException
(
'
incoming lons,lats must have same shape
'
)
...
@@ -50,9 +50,10 @@ class LonLatGrid:
...
@@ -50,9 +50,10 @@ class LonLatGrid:
# locate nearest neighbor for incoming target in earth coordinates (Should not have NaNs)
# locate nearest neighbor for incoming target in earth coordinates (Should not have NaNs)
# lons, lats can be flat or 2D
# lons, lats can be flat or 2D
# closeness_threshold: if < distance of located_point to target, return off grid
# incoming longitude must be in range: 0 - 360 degrees
# incoming longitude must be in range: 0 - 360 degrees
# returns NN indexes relative to the grid determined in the ctr.
# returns NN indexes relative to the grid determined in the ctr.
def
value_to_index
(
self
,
lons
,
lats
):
def
value_to_index
(
self
,
lons
,
lats
,
closeness_threshold
=
2000
):
if
lons
.
shape
!=
lats
.
shape
:
if
lons
.
shape
!=
lats
.
shape
:
raise
MyGenericException
(
'
incoming lons,lats must have same shape
'
)
raise
MyGenericException
(
'
incoming lons,lats must have same shape
'
)
...
@@ -65,8 +66,9 @@ class LonLatGrid:
...
@@ -65,8 +66,9 @@ class LonLatGrid:
xy
=
np
.
stack
([
lons
,
lats
],
axis
=
1
)
xy
=
np
.
stack
([
lons
,
lats
],
axis
=
1
)
dist
,
indices
=
self
.
kd
.
query
(
np
.
deg2rad
(
xy
))
dist
,
indices
=
self
.
kd
.
query
(
np
.
deg2rad
(
xy
))
dist
*=
6370000
# convert unit radius to meters
valid
=
indices
<
self
.
map_indexes
.
size
valid
=
(
indices
<
self
.
map_indexes
.
size
)
&
(
dist
<
closeness_threshold
)
indices
=
indices
[
valid
]
indices
=
indices
[
valid
]
return
self
.
map_indexes
[
indices
],
indices
return
self
.
map_indexes
[
indices
],
indices
...
...
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