Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
toargridding
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
esde
toar-public
toargridding
Commits
ca66f488
Commit
ca66f488
authored
11 months ago
by
Carsten Hinz
Browse files
Options
Downloads
Patches
Plain Diff
rename of parameter
adopted test to use function of Grid class
parent
601e40fd
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!11
Creation of first beta release version
,
!4
Resolve "coordinate ranges do not match"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/coordinates.py
+16
-25
16 additions, 25 deletions
tests/coordinates.py
toargridding/grids.py
+5
-4
5 additions, 4 deletions
toargridding/grids.py
with
21 additions
and
29 deletions
tests/coordinates.py
+
16
−
25
View file @
ca66f488
...
@@ -4,36 +4,27 @@ from toargridding.variables import Coordinate
...
@@ -4,36 +4,27 @@ from toargridding.variables import Coordinate
from
toargridding.metadata
import
Coordinates
from
toargridding.metadata
import
Coordinates
import
numpy
as
np
import
numpy
as
np
from
pandas
import
Series
from
pandas
import
Series
from
toargridding.grids
import
RegularGrid
import
matplotlib.pyplot
as
plt
def
coord_to_index
(
coord
:
Series
,
x0_axis
:
float
,
d_axis
:
float
,
binWrap
:
int
=
None
)
->
np
.
array
:
print
(
"
Script for visual inspection of coordinate results for longitude and latitude
"
)
"""
converts a coordinate into a bin index on one axis
Parameters:
lon
=
Coordinate
.
from_resolution
(
Coordinates
.
longitude
,
1
,
-
180
,
180
,
True
)
----------
print
(
lon
)
coord:
coordinate for conversion
x0_axis:
offset of the axis
d_axis:
resolution of the axis
"""
binIDs
=
(
np
.
ceil
((
coord
/
d_axis
)
-
0.5
)
-
x0_axis
/
d_axis
).
astype
(
int
)
binIDs
[
binIDs
>=
binWrap
]
-=
binWrap
return
binIDs
print
(
"
\n
"
)
print
(
"
Script for visual inspection of coordinate results for longitude and latitude
"
)
lat
=
Coordinate
.
from_resolution
(
Coordinates
.
latitude
,
1.9
,
-
90
,
90
,
False
)
print
(
lat
)
lon
=
Coordinate
.
from_resolution
(
Coordinates
.
longitude
,
2.5
,
-
180
,
180
,
True
)
testGrid
=
RegularGrid
(
lat_resolution
=
1.9
,
lon_resolution
=
2.5
)
print
(
lon
)
testData
=
[
x
+
0.1
for
x
in
range
(
-
180
,
18
0
)]
testData
=
[
x
+
0.1
for
x
in
np
.
a
range
(
-
180
,
18
1
,
.
5
)]
testBins
=
coord_to_index
(
Series
(
testData
),
lon
.
min
,
lon
.
step
,
len
(
lon
.
data
)
)
testBins
=
testGrid
.
coord_to_index
(
Series
(
testData
),
lon
.
min
,
lon
.
step
,
len
(
lon
.
data
)
)
print
(
testBins
)
print
(
len
(
lon
.
data
))
for
val
,
bin
in
zip
(
testData
,
testBins
):
print
(
lon
.
data
[
144
]
)
print
(
val
,
"
->
"
,
bin
)
print
(
"
\n
"
)
#lat = Coordinate.from_resolution(Coordinates.latitude, 1.9,-90,90, False
)
plt
.
plot
(
testData
,
testBins
)
#print(lat
)
plt
.
show
(
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
toargridding/grids.py
+
5
−
4
View file @
ca66f488
...
@@ -278,7 +278,7 @@ class RegularGrid(GridDefinition):
...
@@ -278,7 +278,7 @@ class RegularGrid(GridDefinition):
return
pd
.
Series
(
id_i
,
index
=
id_x
.
index
)
return
pd
.
Series
(
id_i
,
index
=
id_x
.
index
)
def
coord_to_index
(
self
,
coord
:
pd
.
Series
,
x0_axis
:
float
,
d_axis
:
float
,
max
4b
inWrap
:
int
=
None
)
->
np
.
array
:
def
coord_to_index
(
self
,
coord
:
pd
.
Series
,
x0_axis
:
float
,
d_axis
:
float
,
max
B
in
4
Wrap
:
int
=
None
)
->
np
.
array
:
"""
converts a coordinate into a bin index on one axis
"""
converts a coordinate into a bin index on one axis
Parameters:
Parameters:
...
@@ -289,12 +289,13 @@ class RegularGrid(GridDefinition):
...
@@ -289,12 +289,13 @@ class RegularGrid(GridDefinition):
offset of the axis
offset of the axis
d_axis:
d_axis:
resolution of the axis
resolution of the axis
max
4b
inWrap:
max
B
in
4
Wrap:
this is the maximum bin number. If it is set, thw bin numbers wrap around, like for the latitude
this is the maximum bin number. If it is set, thw bin numbers wrap around, like for the latitude
"""
"""
ids
=
(
np
.
ceil
((
coord
/
d_axis
)
-
0.5
)
-
x0_axis
/
d_axis
).
astype
(
int
)
ids
=
(
np
.
ceil
((
coord
/
d_axis
)
-
0.5
)
-
x0_axis
/
d_axis
).
astype
(
int
)
if
max4binWrap
is
not
None
:
if
maxBin4Wrap
is
not
None
:
ids
[
ids
>=
max4binWrap
]
%=
max4binWrap
ids
[
ids
>=
maxBin4Wrap
]
%=
maxBin4Wrap
ids
[
ids
<
0
]
+=
maxBin4Wrap
return
ids
return
ids
def
get_empty_grid
(
self
,
time
:
Variable
,
metadata
:
Metadata
)
->
xr
.
Dataset
:
# TODO make CF-compliant => docs
def
get_empty_grid
(
self
,
time
:
Variable
,
metadata
:
Metadata
)
->
xr
.
Dataset
:
# TODO make CF-compliant => docs
...
...
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