Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cartopy behavior when plotting projected data

I am using cartopy to draw my maps. Its a great tool! For some of my data I have the problem that the data is not properly mapped around 0deg or the dateline. See the example below.

I know the same feature from matplotlib.basemap, where it can be solved by using the add_cyclic routine. I wondered if somebody can recommend how to best fix this problem in cartopy.

Thanks!

Alex

Cartopy problem

like image 921
allion Avatar asked Feb 18 '14 20:02

allion


2 Answers

When plotting global data like this you will always need to add a cyclic point to your input data and coordinate. I don't believe Cartopy currently includes a function to do this for you, but you can do it yourself quite simply for the time being. Assuming you have a 1d array of longitudes and a 2d array of data where the first dimension is latitude and the second is longitude:

import numpy as np

dlon = lons[1] - lons[0]
new_lons = np.concatenate((lons, lons[-1:] + dlon))
new_data = np.concatenate((data, data[:, 0:1]), axis=1)

If you have different shaped data or coordinates then you will need to adjust this to your needs.

like image 71
ajdawson Avatar answered Nov 08 '22 19:11

ajdawson


The cartopy development team has included the required feature in the developoment branch. For details see here

like image 40
allion Avatar answered Nov 08 '22 17:11

allion