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
bc11f16b
Commit
bc11f16b
authored
1 year ago
by
Fraser William Goldsworth
Browse files
Options
Downloads
Patches
Plain Diff
updated tests, nabla failing
parent
08d7a8b0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pyicon/tests/conftest.py
+37
-15
37 additions, 15 deletions
pyicon/tests/conftest.py
pyicon/tests/test_pyicon_calc_xr.py
+12
-5
12 additions, 5 deletions
pyicon/tests/test_pyicon_calc_xr.py
pyicon/tests/test_pyicon_plotting.py
+11
-11
11 additions, 11 deletions
pyicon/tests/test_pyicon_plotting.py
with
60 additions
and
31 deletions
pyicon/tests/conftest.py
+
37
−
15
View file @
bc11f16b
import
pytest
from
pathlib
import
Path
import
pytest
import
xarray
as
xr
import
pyicon
as
pyic
@pytest.fixture
()
def
raw_grid
():
cur_dir
=
Path
(
__file__
).
parent
.
resolve
()
grid_path
=
cur_dir
/
"
test_data/icon_grid_0014_R02B04_O.nc
"
def
lazy_raw_grid
():
path_data
=
Path
(
pyic
.
params
[
'
path_example_data
'
])
path_data
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
grid_path
=
path_data
/
"
icon_grid_0014_R02B04_O.nc
"
if
not
grid_path
.
exists
():
import
requests
...
...
@@ -19,37 +21,57 @@ def raw_grid():
raise
FileNotFoundError
(
"
{grid_path} does not exist and unable to
\
download it
"
)
ds_grid
=
xr
.
open_dataset
(
grid_path
)
ds_grid
=
xr
.
open_dataset
(
grid_path
,
chunks
=
"
auto
"
)
return
ds_grid
@pytest.fixture
()
def
processed_tgrid
(
raw_grid
):
return
pyic
.
convert_tgrid_data
(
raw_grid
)
def
eager_raw_grid
(
lazy_raw_grid
):
ds_raw_grid
=
lazy_raw_grid
.
compute
()
return
ds_raw_grid
@pytest.fixture
()
def
lazy_processed_tgrid
(
lazy_raw_grid
):
return
pyic
.
convert_tgrid_data
(
lazy_raw_grid
)
@pytest.fixture
()
def
eager_processed_tgrid
(
eager_raw_grid
):
return
pyic
.
convert_tgrid_data
(
eager_raw_grid
)
@pytest.fixture
()
def
examp_icon_dataset
():
#cur_dir = Path(__file__).parent.resolve()
#fpath_data = cur_dir / "test_data/icon_example_data_r2b6.nc"
def
lazy_examp_icon_dataset
():
path_data
=
Path
(
pyic
.
params
[
'
path_example_data
'
])
path_data
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
fpath_data
=
path_data
/
"
icon_example_data_r2b4.nc
"
if
not
fpath_data
.
exists
():
import
requests
download_link
=
"
https://swift.dkrz.de/v1/dkrz_
07387162e5cd4c81b1376bd7c648bb60
/pyicon_
example
_data/icon_example_data_r2b4.nc
"
download_link
=
"
https://swift.dkrz.de/v1/dkrz_
83018ad4-3c8d-4c7d-b684-7ba0742caa1a
/pyicon_
test
_data/icon_example_data_r2b4.nc
?temp_url_sig=03fb5d20a44832c7cf736ab83c1be3936364dbf6&temp_url_expires=2026-11-24T11:53:16Z
"
try
:
r
=
requests
.
get
(
download_link
,
allow_redirects
=
True
)
r
=
requests
.
get
(
download_link
,
allow_redirects
=
True
,
stream
=
True
)
with
open
(
fpath_data
,
"
wb
"
)
as
fobj
:
fobj
.
write
(
r
.
content
)
except
:
raise
FileNotFoundError
(
"
{fpath_data} does not exist and unable to
\
download it
"
)
ds
=
xr
.
open_dataset
(
fpath_data
)
ds
=
xr
.
open_dataset
(
fpath_data
,
chunks
=
"
auto
"
)
return
ds
@pytest.fixture
()
def
examp_icon_dataarray
(
examp_icon_dataset
):
return
examp_icon_dataset
[
"
to
"
]
def
eager_examp_icon_dataset
(
lazy_examp_icon_dataset
):
return
lazy_examp_icon_dataset
.
compute
()
@pytest.fixture
()
def
lazy_examp_icon_dataarray
(
lazy_examp_icon_dataset
):
return
lazy_examp_icon_dataset
[
"
to
"
]
@pytest.fixture
()
def
eager_examp_icon_dataarray
(
eager_examp_icon_dataset
):
return
eager_examp_icon_dataset
[
"
to
"
]
This diff is collapsed.
Click to expand it.
pyicon/tests/test_pyicon_calc_xr.py
+
12
−
5
View file @
bc11f16b
...
...
@@ -2,10 +2,12 @@ from itertools import product
import
pytest
import
numpy
as
np
import
pyicon
as
pyic
from
.conftest
import
raw_grid
,
processed_tgrid
from
.conftest
import
eager_
raw_grid
,
eager_processed_tgrid
,
lazy_raw_grid
,
lazy_
processed_tgrid
def
test_convert_tgrid_data
(
raw_grid
):
@pytest.mark.parametrize
(
"
raw_grid
"
,
[
"
lazy_raw_grid
"
,
"
eager_raw_grid
"
])
def
test_convert_tgrid_data
(
raw_grid
,
request
):
raw_grid
=
request
.
getfixturevalue
(
raw_grid
)
converted_tgrid
=
pyic
.
convert_tgrid_data
(
raw_grid
)
# Check conversion to pythonic indexing of neighbour info has worked
...
...
@@ -50,9 +52,8 @@ def test_convert_tgrid_data(raw_grid):
assert
"
cell
"
in
converted_tgrid
.
dims
@pytest.mark.parametrize
(
"
tgrid
"
,
[
"
raw_grid
"
,
"
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
):
# Set ireg_c and crop the grid
tgrid
=
request
.
getfixturevalue
(
tgrid
)
for
point
,
dim
in
product
(
"
cev
"
,
[
"
lon
"
,
"
lat
"
]):
...
...
@@ -60,6 +61,9 @@ def test_xr_crop_tgrid(tgrid, request):
if
tgrid
[
coord
].
units
==
"
radian
"
:
tgrid
[
coord
]
=
np
.
degrees
(
tgrid
[
coord
])
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
),
...
...
@@ -90,7 +94,10 @@ def test_xr_crop_tgrid(tgrid, request):
assert
cropped_tgrid
[
"
ireg_v
"
].
prod
()
==
-
1427286351937536000
def
test_nabla_funcs
(
processed_tgrid
):
@pytest.mark.parametrize
(
"
processed_tgrid
"
,
[
"
lazy_processed_tgrid
"
,
"
eager_processed_tgrid
"
])
def
test_nabla_funcs
(
processed_tgrid
,
request
):
processed_tgrid
=
request
.
getfixturevalue
(
processed_tgrid
)
# Want to check curl of a gradient
gradient
=
pyic
.
xr_calc_grad
(
processed_tgrid
,
processed_tgrid
[
"
clon
"
])
curl_of_grad
=
pyic
.
xr_calc_curl
(
processed_tgrid
,
gradient
)
...
...
This diff is collapsed.
Click to expand it.
pyicon/tests/test_pyicon_plotting.py
+
11
−
11
View file @
bc11f16b
...
...
@@ -2,19 +2,19 @@ import pytest
import
pyicon
as
pyic
import
xarray
as
xr
import
matplotlib.pyplot
as
plt
from
.conftest
import
examp_icon_dataarray
from
.conftest
import
lazy_examp_icon_dataarray
,
eager_
examp_icon_dataarray
def
test_plot
(
examp_icon_dataarray
):
pyic
.
plot
(
examp_icon_dataarray
.
isel
(
time
=
0
,
depth
=
0
))
return
def
test_plot_sec
(
examp_icon_dataarray
):
pyic
.
plot_sec
(
examp_icon_dataarray
.
isel
(
time
=
0
),
section
=
'
170W
'
)
@pytest.mark.parametrize
(
"
examp_icon_dataarray
"
,
[
"
lazy_examp_icon_dataarray
"
,
"
eager_examp_icon_dataarray
"
])
@pytest.mark.parametrize
(
"
grid_type,
"
,
[
"
auto
"
,
"
native
"
])
def
test_plot
(
examp_icon_dataarray
,
grid_type
,
request
):
examp_icon_dataarray
=
request
.
getfixturevalue
(
examp_icon_dataarray
)
pyic
.
plot
(
examp_icon_dataarray
.
isel
(
time
=
0
,
depth
=
0
),
grid_type
=
grid_type
)
return
#def test_shade():
# dai = pyic.interp_to_rectgrid_xr(da)
# dai = dai.compute()
# pyic.shade(dai.lon, dai.lat, dai)
# return
@pytest.mark.parametrize
(
"
examp_icon_dataarray
"
,
[
"
lazy_examp_icon_dataarray
"
,
"
eager_examp_icon_dataarray
"
])
def
test_plot_sec
(
examp_icon_dataarray
,
request
):
examp_icon_dataarray
=
request
.
getfixturevalue
(
examp_icon_dataarray
)
pyic
.
plot_sec
(
examp_icon_dataarray
.
isel
(
time
=
0
),
section
=
'
170W
'
)
return
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