From 6c072dbe8232b32590c78c287a5d50c04867675c Mon Sep 17 00:00:00 2001 From: Ben Barton Date: Fri, 24 Nov 2023 14:02:18 +0000 Subject: [PATCH 1/9] Added new branch for merging corrections --- coast/_utils/plot_util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/coast/_utils/plot_util.py b/coast/_utils/plot_util.py index 085f2a2e..5ecf8406 100644 --- a/coast/_utils/plot_util.py +++ b/coast/_utils/plot_util.py @@ -523,7 +523,6 @@ def plot_polar_contour(lon, lat, var, ax_in, **kwargs): Returns: plot object: can be used for making a colorbar """ - crs_ps = ccrs.CRS("epsg:3413") # North pole projection crs_wgs84 = ccrs.CRS("epsg:4326") # NSIDC grid From c6b9c24731f578c653329c12ffc89d083cca9a5a Mon Sep 17 00:00:00 2001 From: Ben Barton Date: Fri, 24 Nov 2023 14:33:45 +0000 Subject: [PATCH 2/9] Added code to plot_polar_contour() New code uses cartopy instead of pyproj. Cartopy is 100% needed in the ax_in.contour() command so I've put in try: import cartopy.crs as ccrs --- coast/_utils/plot_util.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/coast/_utils/plot_util.py b/coast/_utils/plot_util.py index 2a7671ed..bf3e76fb 100644 --- a/coast/_utils/plot_util.py +++ b/coast/_utils/plot_util.py @@ -539,16 +539,24 @@ def plot_polar_contour(lon, lat, var, ax_in, **kwargs): Returns: plot object: can be used for making a colorbar """ - - # crs_ps = pyproj.Proj("epsg:3413") # North pole projection - # crs_wgs84 = pyproj.Proj("epsg:4326") - transformer = pyproj.Transformer.from_crs("epsg:3413", "epsg:4326") + 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 = 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) + x_grid, y_grid = np.meshgrid(np.linspace(-3850, 3750, 304) * 1000, + np.linspace(-5350, 5850, 448) * 1000) + 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 From 079e27debe0564270f9516be4f90aaf4c3c1f7d7 Mon Sep 17 00:00:00 2001 From: BlackBot Date: Fri, 24 Nov 2023 14:51:24 +0000 Subject: [PATCH 3/9] Apply Black formatting to Python code. --- coast/_utils/plot_util.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/coast/_utils/plot_util.py b/coast/_utils/plot_util.py index bf3e76fb..8f7e5861 100644 --- a/coast/_utils/plot_util.py +++ b/coast/_utils/plot_util.py @@ -544,12 +544,11 @@ def plot_polar_contour(lon, lat, var, ax_in, **kwargs): except ImportError: warn("No cartopy found - please run\nconda install -c conda-forge cartopy") sys.exit(-1) - - crs_ps = ccrs.CRS("epsg:3413") # North pole projection + + 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) + x_grid, y_grid = np.meshgrid(np.linspace(-3850, 3750, 304) * 1000, np.linspace(-5350, 5850, 448) * 1000) 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] From ce43a35dbe5c84d3883487b12700d08119a07491 Mon Sep 17 00:00:00 2001 From: PylintBot Date: Fri, 24 Nov 2023 14:52:15 +0000 Subject: [PATCH 4/9] Update pylint THESHOLD score --- .pylint-score | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylint-score b/.pylint-score index 197e4388..981f67a6 100644 --- a/.pylint-score +++ b/.pylint-score @@ -1 +1 @@ -5.79 +5.81 From dfa5d44e1dbac413134362d60494b68e471661c2 Mon Sep 17 00:00:00 2001 From: Ben Barton Date: Fri, 24 Nov 2023 15:01:00 +0000 Subject: [PATCH 5/9] Try changing the test to get the gitactions happy --- tests/test_velocity_plot_util.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_velocity_plot_util.py b/tests/test_velocity_plot_util.py index 952e7006..6180d411 100644 --- a/tests/test_velocity_plot_util.py +++ b/tests/test_velocity_plot_util.py @@ -122,12 +122,14 @@ def test_plot_polar_contour(): lon = np.array(([5, 8, 11], [6, 9, 12], [7, 10, 13])) temp = np.array(([2, 1, 0], [2, 1, 0], [2, 2, 1])) figsize = (5, 5) # Figure size - mrc = ccrs.NorthPolarStereo(central_longitude=0.0) - fig = plt.figure(figsize=figsize) - ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.75], projection=mrc) - cs1 = plot_util.plot_polar_contour(lon, lat, temp, ax1) - assert isinstance(cs1, cartopy.mpl.contour.GeoContourSet) - + try: + mrc = ccrs.NorthPolarStereo(central_longitude=0.0) + fig = plt.figure(figsize=figsize) + ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.75], projection=mrc) + cs1 = plot_util.plot_polar_contour(lon, lat, temp, ax1) + assert isinstance(cs1, cartopy.mpl.contour.GeoContourSet) + except AssertionError: + assert False def test_set_circle(): """Test the plot_util.set_circle function.""" From 4a82a67c5e629e5ce70dd54f8087f7cec776aa24 Mon Sep 17 00:00:00 2001 From: BlackBot Date: Fri, 24 Nov 2023 15:06:28 +0000 Subject: [PATCH 6/9] Apply Black formatting to Python code. --- tests/test_velocity_plot_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_velocity_plot_util.py b/tests/test_velocity_plot_util.py index 6180d411..07aade85 100644 --- a/tests/test_velocity_plot_util.py +++ b/tests/test_velocity_plot_util.py @@ -131,6 +131,7 @@ def test_plot_polar_contour(): except AssertionError: assert False + def test_set_circle(): """Test the plot_util.set_circle function.""" figsize = (5, 5) # Figure size From 5d40177d3b9ca424bf87ce7ecd77c5f8941358c0 Mon Sep 17 00:00:00 2001 From: Ben Barton Date: Fri, 24 Nov 2023 15:14:59 +0000 Subject: [PATCH 7/9] Try changing the test to import cartopy --- tests/test_velocity_plot_util.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_velocity_plot_util.py b/tests/test_velocity_plot_util.py index 07aade85..69cc96f2 100644 --- a/tests/test_velocity_plot_util.py +++ b/tests/test_velocity_plot_util.py @@ -118,18 +118,20 @@ def test_velocity_grid_to_geo(): def test_plot_polar_contour(): """Test the plot_util.plot_polar_contour function.""" - lat = np.array(([50, 48, 46], [60, 58, 56], [70, 68, 66])) # y, x - lon = np.array(([5, 8, 11], [6, 9, 12], [7, 10, 13])) - temp = np.array(([2, 1, 0], [2, 1, 0], [2, 2, 1])) - figsize = (5, 5) # Figure size try: + import cartopy.crs as ccrs # mapping plots + lat = np.array(([50, 48, 46], [60, 58, 56], [70, 68, 66])) # y, x + lon = np.array(([5, 8, 11], [6, 9, 12], [7, 10, 13])) + temp = np.array(([2, 1, 0], [2, 1, 0], [2, 2, 1])) + figsize = (5, 5) # Figure size + mrc = ccrs.NorthPolarStereo(central_longitude=0.0) fig = plt.figure(figsize=figsize) ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.75], projection=mrc) cs1 = plot_util.plot_polar_contour(lon, lat, temp, ax1) assert isinstance(cs1, cartopy.mpl.contour.GeoContourSet) - except AssertionError: - assert False + except ImportError: + warn("No cartopy found - please run\nconda install -c conda-forge cartopy") def test_set_circle(): From 15d2b4ceea55f2a3fe7209b7863b7dbac7bb7771 Mon Sep 17 00:00:00 2001 From: BlackBot Date: Fri, 24 Nov 2023 15:15:32 +0000 Subject: [PATCH 8/9] Apply Black formatting to Python code. --- tests/test_velocity_plot_util.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_velocity_plot_util.py b/tests/test_velocity_plot_util.py index 69cc96f2..f84d193a 100644 --- a/tests/test_velocity_plot_util.py +++ b/tests/test_velocity_plot_util.py @@ -120,6 +120,7 @@ def test_plot_polar_contour(): """Test the plot_util.plot_polar_contour function.""" try: import cartopy.crs as ccrs # mapping plots + lat = np.array(([50, 48, 46], [60, 58, 56], [70, 68, 66])) # y, x lon = np.array(([5, 8, 11], [6, 9, 12], [7, 10, 13])) temp = np.array(([2, 1, 0], [2, 1, 0], [2, 2, 1])) From c46a5c657fee1e302b619a17f34e097d692088c5 Mon Sep 17 00:00:00 2001 From: Ben Barton Date: Fri, 24 Nov 2023 15:21:38 +0000 Subject: [PATCH 9/9] Putting the test back how it was --- tests/test_velocity_plot_util.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/tests/test_velocity_plot_util.py b/tests/test_velocity_plot_util.py index f84d193a..952e7006 100644 --- a/tests/test_velocity_plot_util.py +++ b/tests/test_velocity_plot_util.py @@ -118,21 +118,15 @@ def test_velocity_grid_to_geo(): def test_plot_polar_contour(): """Test the plot_util.plot_polar_contour function.""" - try: - import cartopy.crs as ccrs # mapping plots - - lat = np.array(([50, 48, 46], [60, 58, 56], [70, 68, 66])) # y, x - lon = np.array(([5, 8, 11], [6, 9, 12], [7, 10, 13])) - temp = np.array(([2, 1, 0], [2, 1, 0], [2, 2, 1])) - figsize = (5, 5) # Figure size - - mrc = ccrs.NorthPolarStereo(central_longitude=0.0) - fig = plt.figure(figsize=figsize) - ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.75], projection=mrc) - cs1 = plot_util.plot_polar_contour(lon, lat, temp, ax1) - assert isinstance(cs1, cartopy.mpl.contour.GeoContourSet) - except ImportError: - warn("No cartopy found - please run\nconda install -c conda-forge cartopy") + lat = np.array(([50, 48, 46], [60, 58, 56], [70, 68, 66])) # y, x + lon = np.array(([5, 8, 11], [6, 9, 12], [7, 10, 13])) + temp = np.array(([2, 1, 0], [2, 1, 0], [2, 2, 1])) + figsize = (5, 5) # Figure size + mrc = ccrs.NorthPolarStereo(central_longitude=0.0) + fig = plt.figure(figsize=figsize) + ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.75], projection=mrc) + cs1 = plot_util.plot_polar_contour(lon, lat, temp, ax1) + assert isinstance(cs1, cartopy.mpl.contour.GeoContourSet) def test_set_circle():