Skip to content

Commit

Permalink
Merge pull request #654 from British-Oceanographic-Data-Centre/0653/m…
Browse files Browse the repository at this point in the history
…erge_plot_polar_contour

0653/merge plot polar contour
  • Loading branch information
soutobias authored Dec 4, 2023
2 parents de885f2 + c46a5c6 commit 308ffd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pylint-score
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.79
5.81
17 changes: 12 additions & 5 deletions coast/_utils/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,16 +539,23 @@ def plot_polar_contour(lon, lat, var, ax_in, **kwargs):
Returns:
plot object: can be used for making a colorbar
"""
try:
import cartopy.crs as ccrs # mapping plots
except ImportError:
warn("No cartopy found - please run\nconda install -c conda-forge cartopy")
sys.exit(-1)

# crs_ps = pyproj.Proj("epsg:3413") # North pole projection
# crs_wgs84 = pyproj.Proj("epsg:4326")
transformer = pyproj.Transformer.from_crs("epsg:3413", "epsg:4326")
crs_ps = ccrs.CRS("epsg:3413") # North pole projection
crs_wgs84 = ccrs.CRS("epsg:4326")
# NSIDC grid
x_grid, y_grid = np.meshgrid(np.linspace(-3850, 3750, 304) * 1000, np.linspace(-5350, 5850, 448) * 1000)
lon_grid, lat_grid = transformer.transform(x_grid, y_grid)
grid = crs_wgs84.transform_points(crs_ps, x_grid, y_grid)
# output is x, y, z triple but we don't need z
lon_grid = grid[:, :, 0]
lat_grid = grid[:, :, 1]
points = np.vstack((lon.flatten(), lat.flatten())).T
grid_var = si.griddata(points, var.flatten(), (lon_grid, lat_grid), method="linear")
cs_out = ax_in.contour(x_grid, y_grid, grid_var, **kwargs)
cs_out = ax_in.contour(x_grid, y_grid, grid_var, transform=ccrs.epsg(3413), **kwargs)
return cs_out


Expand Down

0 comments on commit 308ffd7

Please sign in to comment.