Cartopy set_extent error when the extents are too small?

38 views Asked by At

Whenever I make the set_extent (or slice()) limits too small, I get the message:

File "/--path--/python3.10/site-packages/shapefile.py", line 1287, in __shpHeader
    self.shpLength = unpack(">i", shp.read(4))[0] * 2
struct.error: unpack requires a buffer of 4 bytes

Searching it up just gives me threads of people with bad shapefiles. I didn't download any shapefiles?

Used code from this tutorial for a base map: http://tech.weatherforce.org/blog/ecmwf-data-animation/index.html

def make_figure():
    fig = plt.figure()
    ax = plt.axes(projection=ccrs.PlateCarree())

    # generate a basemap with country borders, oceans and coastlines
    ax.add_feature(cfeat.LAND)
    ax.add_feature(cfeat.OCEAN)
    ax.add_feature(cfeat.COASTLINE)
    ax.add_feature(cfeat.BORDERS)
    ax.set_extent((-7.5, 50, 30, 90), ccrs.PlateCarree()) #my one addition
    return fig, ax

make_figure();

I want to fit just one country on my map, so I used the 'slice' command from the tutorial to make it work area = ds.t2m.sel(longitude=slice(270, 310), latitude=slice(30, 4)). Got the same error I posted.

Tried the set_extent then. The extents set right now work without an issue, but the moment I change, for example, 90 to 60, I get the same error everytime. Tried different parts of the world and it just seems the set_extent or slicing works as long as the region is big enough, and anything smaller than some unspecified limit has the error appear. Is zooming in too much messing with resolution of the cartopy features or something?? Also tried changing the projection, but admittedly I might've messed that up (and when googling, every method of displaying a single country that I saw used PlateCarree with even smaller extents). I'm very new to cartopy and python in general, so I don't know if I'm missing something obvious.

0

There are 0 answers