Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0653/merge plot polar contour #654

Merged
merged 10 commits into from
Dec 4, 2023
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