Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basemap draw line between latitude longitude

I am plotting start/end locations for tornadoes. The csv file has the data such that:

TouchDownLat TouchDownLong LiftoffLat LiftoffLong
31.53         -97.15       31.74      -96.88
46.45         -100.67      46.67      -100.47
43.1          -83.85       43.17      -83.42

etc...

What I have done was taken each latitude and longitude and separated it into a numpy array as such:

import matplotlib.pyplot as plt
import csv
import numpy as np
from mpl_toolkits.basemap import Basemap
with open(fname, 'rb') as f:
    w = csv.reader(f, delimiter = ',')
    for i, line in enumerate (w):
      if i == 0 or line[2][0:4] not in str(range(2007,2018)):
          pass
      else:
          lat_td.append(line[27])
          long_td.append(line[28])
          lat_lift.append(line[29])
          long_lift.append(line[30])

touchdown = np.array([[lat_td], [long_td]])
lift = np.array([[lat_lift], [long_lift]])

For the basemap, I am finding the max/min for all the lat/long so that it makes a map to cut out the states that didn't have a tornado (example: I don't want to see California when looking at EF-5 tornado locations)

m = Basemap(projection = 'merc', llcrnrlat=float(min(lat_td)) - 2,\
    urcrnrlat=float(max(lat_lift)) + 2, llcrnrlon=float(max(long_td)) - 2,\
    urcrnrlon=float(min(long_lift)) + 2,lat_ts=40,resolution='l')
m.drawcoastlines()
m.fillcontinents(color='white')
m.drawmapboundary(fill_color='white')
m.drawstates(color='black')
m.drawcountries(color='black')
plt.title("#wedgez")

So, now comes the question: I am looking to plot the track of the tornado using the lat/long in the numpy array. How would I go about doing so?

like image 815
Brandon Molyneaux Avatar asked Dec 23 '22 19:12

Brandon Molyneaux


1 Answers

If I understand correctly, you are looking for a way to plot a path, given the coordinates of the path's points. Then, you can plot the path as follows:

m = Basemap(projection = 'merc', llcrnrlat=float(min(lat_td)) - 2,\
    urcrnrlat=float(max(lat_lift)) + 2, llcrnrlon=float(max(long_td)) - 2,\
    urcrnrlon=float(min(long_lift)) + 2,lat_ts=40,resolution='l')

lat = [the list of lat coordinates here] 
lon = [the list of lon coordinates here] 

x, y = m(lon, lat)
m.plot(x, y, 'o-', markersize=5, linewidth=1) 

m.drawcoastlines()
m.fillcontinents(color='white')
m.drawmapboundary(fill_color='white')
m.drawstates(color='black')
m.drawcountries(color='black')
plt.title("#wedgez")
plt.show() 
like image 194
kimalser Avatar answered Dec 28 '22 08:12

kimalser