Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pyicon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Aaron Wienkers
pyicon
Commits
d8146433
Commit
d8146433
authored
1 year ago
by
Fraser William Goldsworth
Browse files
Options
Downloads
Patches
Plain Diff
added the tgrid docstring example to the tests
parent
a4997410
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pyicon/tests/test_pyicon_calc_xr.py
+52
-14
52 additions, 14 deletions
pyicon/tests/test_pyicon_calc_xr.py
with
52 additions
and
14 deletions
pyicon/tests/test_pyicon_calc_xr.py
+
52
−
14
View file @
d8146433
...
...
@@ -2,7 +2,12 @@ from itertools import product
import
pytest
import
numpy
as
np
import
pyicon
as
pyic
from
.conftest
import
eager_raw_grid
,
eager_processed_tgrid
,
lazy_raw_grid
,
lazy_processed_tgrid
from
.conftest
import
(
eager_raw_grid
,
eager_processed_tgrid
,
lazy_raw_grid
,
lazy_processed_tgrid
,
)
@pytest.mark.parametrize
(
"
raw_grid
"
,
[
"
lazy_raw_grid
"
,
"
eager_raw_grid
"
])
...
...
@@ -26,14 +31,17 @@ def test_convert_tgrid_data(raw_grid, request):
assert
converted_tgrid
[
info
].
min
().
values
==
0
or
-
1
if
info
.
startswith
(
"
v
"
)
or
info
.
startswith
(
"
edge_vertices
"
):
assert
converted_tgrid
[
info
].
max
().
values
==
\
converted_tgrid
.
dims
[
"
vertex
"
]
-
1
assert
(
converted_tgrid
[
info
].
max
().
values
==
converted_tgrid
.
dims
[
"
vertex
"
]
-
1
)
elif
info
.
startswith
(
"
e
"
):
assert
converted_tgrid
[
info
].
max
().
values
==
\
converted_tgrid
.
dims
[
"
edge
"
]
-
1
assert
(
converted_tgrid
[
info
].
max
().
values
==
converted_tgrid
.
dims
[
"
edge
"
]
-
1
)
elif
info
.
startswith
(
"
c
"
)
or
info
.
startswith
(
"
a
"
):
assert
converted_tgrid
[
info
].
max
().
values
==
\
converted_tgrid
.
dims
[
"
cell
"
]
-
1
assert
(
converted_tgrid
[
info
].
max
().
values
==
converted_tgrid
.
dims
[
"
cell
"
]
-
1
)
# Conversion of ecv lat and lon to degrees
for
point
,
dim
in
product
(
"
ecv
"
,
(
"
lat
"
,
"
lon
"
)):
...
...
@@ -52,7 +60,15 @@ def test_convert_tgrid_data(raw_grid, request):
assert
"
cell
"
in
converted_tgrid
.
dims
@pytest.mark.parametrize
(
"
tgrid
"
,
[
"
lazy_raw_grid
"
,
"
lazy_processed_tgrid
"
,
"
eager_raw_grid
"
,
"
eager_processed_tgrid
"
])
@pytest.mark.parametrize
(
"
tgrid
"
,
[
"
lazy_raw_grid
"
,
"
lazy_processed_tgrid
"
,
"
eager_raw_grid
"
,
"
eager_processed_tgrid
"
,
],
)
def
test_xr_crop_tgrid
(
tgrid
,
request
):
tgrid
=
request
.
getfixturevalue
(
tgrid
)
...
...
@@ -64,10 +80,17 @@ def test_xr_crop_tgrid(tgrid, request):
tgrid
[
"
clon
"
]
=
tgrid
[
"
clon
"
].
compute
()
tgrid
[
"
clat
"
]
=
tgrid
[
"
clat
"
].
compute
()
ireg_c
=
tgrid
[
"
cell
"
].
where
(
(
tgrid
[
"
clon
"
]
>
-
5
)
&
(
tgrid
[
"
clon
"
]
<
5
)
&
(
tgrid
[
"
clat
"
]
>
-
5
)
&
(
tgrid
[
"
clat
"
]
<
5
),
drop
=
True
).
astype
(
"
int32
"
)
ireg_c
=
(
tgrid
[
"
cell
"
]
.
where
(
(
tgrid
[
"
clon
"
]
>
-
5
)
&
(
tgrid
[
"
clon
"
]
<
5
)
&
(
tgrid
[
"
clat
"
]
>
-
5
)
&
(
tgrid
[
"
clat
"
]
<
5
),
drop
=
True
,
)
.
astype
(
"
int32
"
)
)
# This checks ireg_c is as expected
assert
ireg_c
.
sum
()
==
301614
...
...
@@ -93,8 +116,23 @@ def test_xr_crop_tgrid(tgrid, request):
assert
cropped_tgrid
[
"
ireg_v
"
].
sum
()
==
135385
assert
cropped_tgrid
[
"
ireg_v
"
].
prod
()
==
-
1427286351937536000
@pytest.mark.parametrize
(
"
processed_tgrid
"
,
[
"
lazy_processed_tgrid
"
,
"
eager_processed_tgrid
"
])
# Try running the example code from the docstring
clon
=
tgrid
.
clon
.
compute
().
data
*
180.0
/
np
.
pi
clat
=
tgrid
.
clat
.
compute
().
data
*
180.0
/
np
.
pi
lon_reg
=
[
6
,
10
]
lat_reg
=
[
-
32
,
-
30
]
ireg_c
=
np
.
where
(
(
clon
>
lon_reg
[
0
])
&
(
clon
<=
lon_reg
[
1
])
&
(
clat
>
lat_reg
[
0
])
&
(
clat
<=
lat_reg
[
1
])
)[
0
]
pyic
.
xr_crop_tgrid
(
tgrid
,
ireg_c
)
@pytest.mark.parametrize
(
"
processed_tgrid
"
,
[
"
lazy_processed_tgrid
"
,
"
eager_processed_tgrid
"
]
)
def
test_nabla_funcs
(
processed_tgrid
,
request
):
processed_tgrid
=
request
.
getfixturevalue
(
processed_tgrid
)
...
...
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