Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymistral
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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 Spring
pymistral
Commits
5cce74d6
Commit
5cce74d6
authored
4 years ago
by
Aaron Spring
Browse files
Options
Downloads
Patches
Plain Diff
plot stereo print
parent
9229f9a0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pymistral/plot.py
+35
-9
35 additions, 9 deletions
pymistral/plot.py
pymistral/tests/test_plot.py
+14
-0
14 additions, 0 deletions
pymistral/tests/test_plot.py
with
49 additions
and
9 deletions
pymistral/plot.py
+
35
−
9
View file @
5cce74d6
...
...
@@ -34,7 +34,7 @@ class CartopyMap(object):
self
,
ax
=
None
,
proj
=
None
,
plot
_lon_lat_
axi
s
=
True
,
draw
_lon_lat_
label
s
=
True
,
feature
=
None
,
plot_type
=
'
pcolormesh
'
,
rm_cyclic
=
True
,
...
...
@@ -44,7 +44,7 @@ class CartopyMap(object):
ax
=
ax
,
proj
=
proj
,
feature
=
feature
,
plot
_lon_lat_
axis
=
plot
_lon_lat_
axi
s
,
draw
_lon_lat_
labels
=
draw
_lon_lat_
label
s
,
plot_type
=
plot_type
,
rm_cyclic
=
rm_cyclic
,
**
kwargs
,
...
...
@@ -55,7 +55,7 @@ class CartopyMap(object):
ax
=
None
,
proj
=
ccrs
.
PlateCarree
(),
feature
=
'
land
'
,
plot
_lon_lat_
axi
s
=
True
,
draw
_lon_lat_
label
s
=
True
,
plot_type
=
'
pcolormesh
'
,
rm_cyclic
=
True
,
**
kwargs
,
...
...
@@ -68,6 +68,22 @@ class CartopyMap(object):
if
isinstance
(
proj
,
str
):
proj
=
eval
(
f
'
ccrs.
{
proj
}
()
'
)
stereo_maps
=
(
ccrs
.
Stereographic
,
ccrs
.
NorthPolarStereo
,
ccrs
.
SouthPolarStereo
,
)
if
isinstance
(
proj
,
stereo_maps
):
round
=
True
import
matplotlib.path
as
mpath
theta
=
np
.
linspace
(
0
,
2
*
np
.
pi
,
100
)
center
,
radius
=
[
0.5
,
0.5
],
0.5
verts
=
np
.
vstack
([
np
.
sin
(
theta
),
np
.
cos
(
theta
)]).
T
circle
=
mpath
.
Path
(
verts
*
radius
+
center
)
else
:
round
=
False
xda
=
self
.
_obj
# da, convert to da or error
if
not
isinstance
(
xda
,
xr
.
DataArray
):
...
...
@@ -99,12 +115,12 @@ class CartopyMap(object):
assert
lon
,
(
lon
,
xda
.
coords
)
assert
lat
,
(
lat
,
xda
.
coords
)
if
plot
_lon_lat_
axi
s
:
if
draw
_lon_lat_
label
s
:
draw_labels
=
True
else
:
draw_labels
=
False
if
proj
!=
ccrs
.
PlateCarree
():
plot
_lon_lat_
axi
s
=
False
draw
_lon_lat_
label
s
=
False
if
plot_type
==
'
contourf
'
:
rm_cyclic
=
False
...
...
@@ -117,6 +133,13 @@ class CartopyMap(object):
kwargs
[
'
cbar_kwargs
'
]
=
{
'
shrink
'
:
0.6
}
if
ax
is
None
:
if
round
:
print
(
'
use stereo maps and facet plots by:
'
,
'
fig,ax=plt.subplots(subplot_kw=
'
f
"
{
'
projection
'
:
ccrs
.
NorthPolarStereo
()
}
\n
"
'
d.isel(time=0).plot_map(proj=proj,ax=ax)
'
,
)
if
single_plot
:
axm
=
getattr
(
xda
.
plot
,
plot_type
)(
lon
,
...
...
@@ -134,6 +157,8 @@ class CartopyMap(object):
**
kwargs
,
)
else
:
if
round
:
ax
.
set_boundary
(
circle
,
transform
=
ax
.
transAxes
)
axm
=
getattr
(
xda
.
plot
,
plot_type
)(
lon
,
lat
,
ax
=
ax
,
transform
=
ccrs
.
PlateCarree
(),
**
kwargs
)
...
...
@@ -151,14 +176,15 @@ class CartopyMap(object):
edgecolor
=
'
k
'
,
)
if
plot
_lon_lat_
axi
s
:
if
draw
_lon_lat_
label
s
:
_set_lon_lat_axis
(
axes
,
proj
)
else
:
gl
=
axes
.
gridlines
(
draw_labels
=
draw_labels
)
gl
.
top_labels
=
False
gl
.
right_labels
=
False
gl
.
xlines
=
False
gl
.
ylines
=
False
if
proj
not
in
stereo_maps
:
gl
.
xlines
=
False
gl
.
ylines
=
False
if
single_plot
:
if
ax
is
None
:
...
...
@@ -178,7 +204,7 @@ def _rm_singul_lon(ds, lon='lon', lat='lat'):
lons
=
ds
[
lon
].
values
fixed_lons
=
lons
.
copy
()
for
i
,
start
in
enumerate
(
np
.
argmax
(
np
.
abs
(
np
.
diff
(
lons
))
>
180
,
axis
=
1
)):
fixed_lons
[
i
,
start
+
1
:]
+=
360
fixed_lons
[
i
,
start
+
1
:]
+=
360
lons_da
=
xr
.
DataArray
(
fixed_lons
,
ds
[
lat
].
coords
)
ds
=
ds
.
assign_coords
({
lon
:
lons_da
})
return
ds
...
...
This diff is collapsed.
Click to expand it.
pymistral/tests/test_plot.py
+
14
−
0
View file @
5cce74d6
import
pytest
import
pymistral
import
cartopy.crs
as
ccrs
import
matplotlib.pyplot
as
plt
projections
=
[
ccrs
.
PlateCarree
(),
ccrs
.
Robinson
()]
plot_types
=
[
'
pcolormesh
'
,
'
contourf
'
]
...
...
@@ -50,3 +51,16 @@ def test_plot_map_facet(da, rc, plot_type, proj):
@pytest.mark.parametrize
(
'
projstr
'
,
[
None
,
'
Robinson
'
,
'
AlbersEqualArea
'
])
def
test_plot_map_projstr
(
da
,
projstr
):
da
.
isel
(
time
=
0
).
plot_map
(
proj
=
projstr
)
@pytest.mark.parametrize
(
'
da
'
,
[
pytest
.
lazy_fixture
(
'
rasm_da
'
),
pytest
.
lazy_fixture
(
'
air_temperature_da
'
),
],
)
@pytest.mark.parametrize
(
'
projstr
'
,
[
'
NorthPolarStereo
'
])
def
test_plot_map_stereo
(
da
,
projstr
):
fig
,
ax
=
plt
.
subplots
(
subplot_kw
=
{
'
projection
'
:
ccrs
.
NorthPolarStereo
()})
da
.
isel
(
time
=
0
).
plot_map
(
proj
=
projstr
,
ax
=
ax
)
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