Giter Site home page Giter Site logo

Comments (3)

LiamBindle avatar LiamBindle commented on September 18, 2024 1

I just tried cartopy version 0.18.1.dev113+g3565f78 (which includes SciTools/cartopy#1622). Here is the result.

ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_global()
ax.coastlines()

image

plt.pcolormesh(
    ds.lons.isel(nf=0).values, 
    ds.lats.isel(nf=0).values, 
    ds.SpeciesConc_NO2.isel(nf=0, lev=0, time=0).values, 
    vmax=8e-9
)

image

plt.pcolormesh(
    ds.lons.isel(nf=1).values, 
    ds.lats.isel(nf=1).values, 
    ds.SpeciesConc_NO2.isel(nf=1, lev=0, time=0).values, 
    vmax=8e-9
)

image

So SciTools/cartopy#1622 does fix the horizontal streaking that we see. Thanks again @htonchia and @greglucas, this is terrific!

from gchp.

LiamBindle avatar LiamBindle commented on September 18, 2024

Just following up on my prefered workaround. Here's a minimal example.

I forgot to mention that with this method you have to plot each grid-box that crosses the AM as a polygon and manually specify its color. Since this is a minimal example, I omitted logic to only do this for grid-boxes that cross the AM, and instead I do it for all grid-boxes on nf=1. This can be sped up by using masked arrays with pcolormesh() and then only drawing polygons for grid-boxes that cross the AM.

Note: This method also requires grid-box corners.

import shapely.geometry
import pyproj

# Get grid corners in epsg:4326
lons = grid.xe.isel(nf=1).values   # Note: grid.xe and grid.ye are the grid's corners
lats = grid.ye.isel(nf=1).values

# Project corners to gnomonic space centered on the face nf=1
gno = ccrs.Gnomonic(20, -150)
xe, ye = pyproj.transform('epsg:4326', gno.proj4_init, lons, lats, always_xy=True)

# We have to manually assign colors to polygons, tf. create norm and cmap
cmap = plt.get_cmap('viridis')
norm = plt.Normalize(vmin=0, vmax=8e-9)

for j in range(ds.dims['Ydim']):
    for i in range(ds.dims['Xdim']):
        fill=cmap(norm(ds.SpeciesConc_NO2.isel(lev=0, nf=1, Ydim=j, Xdim=i).values[0])) # color of polygon
        polygon = shapely.geometry.Polygon([(xe[j,i], ye[j,i]), (xe[j+1,i], ye[j+1,i]), (xe[j+1,i+1], ye[j+1,i+1]), (xe[j,i+1], ye[j,i+1])]) # create a polygon
        ax.add_geometries( # add the polygon to the plot
            [polygon],
            gno, edgecolor=fill, facecolor=fill
        )

image

A full example of this method can be found here

This can make plots that look like this
image

from gchp.

WilliamDowns avatar WilliamDowns commented on September 18, 2024

Good to know this will be officially fixed with Cartopy 0.19, which will make it easy to include in GCPy once we can confirm that our plotting works correctly in that new version.

from gchp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.