Question

I was trying to plot data only on continent. I asked a question about this before and I've got the answer here. Now when I implemented it in the code, the program will run without giving an error.

However, it RUNS FOREVER. When I use ctrl + C to force stop it, it traces back to "if not (map.is_land(X[i], Y[i])):", so I think there's something wrong here. But I can't figure it out.

Here is the part of code that involves picking out non-continental data and removing them:

X, Y = map(Lon,Lat)
ocean = []
for i in range(len(X)):
    if not (map.is_land(X[i], Y[i])):
        ocean.append(i)

X_new = np.delete(X, ocean)
Y_new = np.delete(Y, ocean)
HDO_new = np.delete(HDO, ocean)
Was it helpful?

Solution

Since you use a for loop, the program should stop anyway, the only problem is how large is X. I can only give two suggestions:

1) try to print the value of len(X) before entering the for cicle to see how big is

2) try to use xrange instead of range, if you use python 2.x

Keep also in mind that using list with some hundred thousand element seems to be slow. Eventually try using a smaller data sample, if you can

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top