British-Oceanographic-Data-Centre / COAsT

A Coastal Ocean Assessment Tool built as an extendable python framework for nemo models
https://british-oceanographic-data-centre.github.io/COAsT/
MIT License
23 stars 11 forks source link

Issue with new plot_util.plot_polar_contour() #653

Open jpolton opened 7 months ago

jpolton commented 7 months ago

Hi Jeff, I've just had a look at what's been merged into develop. It looks like there have bene some changes to plot_util.plot_polar_contour() which mean it now doesn't work with the gc31_arctic_example_plot.py script. This is what I had working once I'd taken the pyproj dependency out.

def plot_polar_contour(lon, lat, var, ax_in, **kwargs):

    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)
    grid = crs_wgs84.transform_points(crs_ps, x_grid, y_grid)
    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, transform=ccrs.epsg(3413), **kwargs)
    return cs_out

Or, to get it working in the current format with pyproj you'll need to change two lines to:

transformer = pyproj.Transformer.from_crs("epsg:3413", "epsg:4326", always_xy=True)
cs_out = ax_in.contour(x_grid, y_grid, grid_var, transform=ccrs.epsg(3413), **kwargs)

Thanks, Ben

jpolton commented 7 months ago

Thanks @b-barton. I've made this an Issue so we get it sorted. I haven't got head space to think about this at the moment but our plan is to merge develop into Master 2 weeks today (Dec7), so we will get it sorted by then. Odd that this got into develop without being spotted. Hmmm

b-barton commented 7 months ago

Hi, Great. Perhaps there was a merge conflict with the version before I removed the pyproj dependency that was merged the wrong way.

Thanks, Ben


From: jpolton @.> Sent: 23 November 2023 15:06 To: British-Oceanographic-Data-Centre/COAsT @.> Cc: Barton, Benjamin I. @.>; Mention @.> Subject: Re: [British-Oceanographic-Data-Centre/COAsT] Issue with new plot_util.plot_polar_contour() (Issue #653)

Caution: This email has originated from outside of the organisation. Do not click links or open attachments unless you have verified the sender and content is safe. Thank you.

Thanks @b-bartonhttps://github.com/b-barton. I've made this an Issue so we get it sorted. I haven't got head space to think about this at the moment but our plan is to merge develop into Master 2 weeks today (Dec7), so we will get it sorted by then. Odd that this got into develop without being spotted. Hmmm

— Reply to this email directly, view it on GitHubhttps://github.com/British-Oceanographic-Data-Centre/COAsT/issues/653#issuecomment-1824584732, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOLG5A6LSY6XBQEROH6QC4DYF5Q6VAVCNFSM6AAAAAA7X46YMWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRUGU4DINZTGI. You are receiving this because you were mentioned.Message ID: @.***>

This email and any attachments are intended solely for the use of the named recipients. If you are not the intended recipient you must not use, disclose, copy or distribute this email or any of its attachments and should notify the sender immediately and delete this email from your system. The National Oceanography Centre (NOC) has taken every reasonable precaution to minimise risk of this email or any attachments containing viruses or malware but the recipient should carry out its own virus and malware checks before opening the attachments. NOC does not accept any liability for any losses or damages which the recipient may sustain due to presence of any viruses. Opinions, conclusions or other information in this message and attachments that are not related directly to NOC business are solely those of the author and do not represent the views of NOC.

b-barton commented 7 months ago

I've made a new branch with the version of the code without pyproj: 0653/merge_plot_polar_contour

b-barton commented 7 months ago

I've taken the develop branch and changed the code in plot_util.plot_polar_contour() to use cartopy. This function definitely needs cartopy. It can be tested with example_scripts\configuration_gallery\gc31_arctic_example_plot.py. I'm guessing there has been some problems with git actions and cartopy so I've put the same as other functions that use cartopy with the:

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)
b-barton commented 7 months ago

There is a pull request