Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Carl Schreck
py-examples
Commits
319c42f0
Commit
319c42f0
authored
Feb 15, 2020
by
Carl Schreck
Browse files
initial commit
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
cartopy_set_extent.py
0 → 100644
View file @
319c42f0
""" Script to test out issues with subsetting maps."""
__author__
=
"Carl Schreck"
__email__
=
"cjschrec@ncsu.edu"
__copyright__
=
"Copyright 2020, North Carolina State University"
__license__
=
"BSD-3.0"
import
matplotlib.pyplot
as
plt
import
cartopy.crs
as
ccrs
from
matplotlib.ticker
import
AutoLocator
min_lon
=
180
max_lon
=
360
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_extent
([
min_lon
,
max_lon
,
-
90
,
90
],
crs
=
ccrs
.
PlateCarree
())
plt
.
savefig
(
f
'figures/set_extent.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_xlim
(
min_lon
,
max_lon
)
ax
.
set_ylim
(
-
90
,
90
)
plt
.
savefig
(
f
'figures/set_xlim.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
min_lon
=
190
max_lon
=
360
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_extent
([
min_lon
,
max_lon
,
-
90
,
90
],
crs
=
ccrs
.
PlateCarree
())
plt
.
savefig
(
f
'figures/set_extent.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_xlim
(
min_lon
,
max_lon
)
ax
.
set_ylim
(
-
90
,
90
)
plt
.
savefig
(
f
'figures/set_xlim.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
min_lon
=
170
max_lon
=
360
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_extent
([
min_lon
,
max_lon
,
-
90
,
90
],
crs
=
ccrs
.
PlateCarree
())
plt
.
savefig
(
f
'figures/set_extent.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_xlim
(
min_lon
,
max_lon
)
ax
.
set_ylim
(
-
90
,
90
)
plt
.
savefig
(
f
'figures/set_xlim.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
min_lon
=
-
160
max_lon
=
160
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_extent
([
min_lon
,
max_lon
,
-
90
,
90
],
crs
=
ccrs
.
PlateCarree
())
plt
.
savefig
(
f
'figures/set_extent.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_xlim
(
min_lon
,
max_lon
)
ax
.
set_ylim
(
-
90
,
90
)
plt
.
savefig
(
f
'figures/set_xlim.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
min_lon
=
-
190
max_lon
=
0
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_extent
([
min_lon
,
max_lon
,
-
90
,
90
],
crs
=
ccrs
.
PlateCarree
())
plt
.
savefig
(
f
'figures/set_extent.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
plt
.
figure
()
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
180
))
ax
.
coastlines
()
ax
.
gridlines
()
ax
.
gridlines
().
xlabels_bottom
=
True
ax
.
gridlines
().
ylabels_left
=
True
ax
.
set_xlim
(
min_lon
,
max_lon
)
ax
.
set_ylim
(
-
90
,
90
)
plt
.
savefig
(
f
'figures/set_xlim.
{
min_lon
}
.
{
max_lon
}
.png'
)
plt
.
show
()
dateline_test.py
0 → 100644
View file @
319c42f0
import
cartopy.feature
import
cartopy.crs
as
ccrs
import
matplotlib.pyplot
as
plt
ax
=
plt
.
axes
(
projection
=
ccrs
.
PlateCarree
(
central_longitude
=
240
))
ax
.
set_extent
([
170
,
360
,
15
,
80
],
crs
=
ccrs
.
PlateCarree
())
# add some features to make the map a little more polished
ax
.
add_feature
(
cartopy
.
feature
.
LAND
)
ax
.
add_feature
(
cartopy
.
feature
.
OCEAN
)
ax
.
coastlines
(
'50m'
)
plt
.
show
()
\ No newline at end of file
quick_map.py
0 → 100644
View file @
319c42f0
""" Draw a quick map of data in a file."""
__author__
=
"Carl Schreck"
__email__
=
"cjschrec@ncsu.edu"
__copyright__
=
"Copyright 2020, North Carolina State University"
__license__
=
"BSD-3.0"
import
xarray
as
xr
import
os
from
matplotlib
import
pyplot
as
plt
import
cartopy.crs
as
ccrs
import
cjs
# '~carl/lib/python'
cjs
.
tstamp
(
'Here we go!'
)
# These are some parameters that could be useful to have up top
path
=
f
'
{
os
.
environ
[
"DATA_DIR"
]
}
/prism/netcdf/tmin-198101.nc'
var_name
=
'tmin'
ds
=
xr
.
open_dataset
(
path
)
ax
=
plt
.
axes
(
projection
=
ccrs
.
AlbersEqualArea
(
central_longitude
=
360
-
95
,
standard_parallels
=
(
40
,
60
)))
plt
.
gca
().
outline_patch
.
set_visible
(
False
)
ax
.
set_extent
([
-
118
,
-
75
,
23.5
,
50.5
])
shp_name
=
'ne_10m_admin_1_states_provinces_lakes'
cjs
.
add_map
(
ax
,
shp_name
,
edgecolor
=
'none'
,
facecolor
=
'silver'
,
zorder
=
1
,
usa_only
=
True
)
cjs
.
add_map
(
ax
,
shp_name
,
edgecolor
=
(
0.2
,
0.2
,
0.2
),
facecolor
=
'none'
,
zorder
=
3
,
usa_only
=
True
)
ds
[
var_name
].
isel
(
time
=
0
).
plot
(
ax
=
ax
,
zorder
=
2
,
transform
=
ccrs
.
PlateCarree
())
plt
.
show
()
cjs
.
tstamp
(
'Thank you, come again.'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment