Last active
September 26, 2015 02:20
-
-
Save jakebrinkmann/275085c60fe128434752 to your computer and use it in GitHub Desktop.
Working with USGS Machine-to-machine interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from matplotlib.patches import Polygon | |
from mpl_toolkits.basemap import Basemap | |
import numpy as np | |
from usgs import api | |
fig, ax = plt.subplots(1) | |
m = Basemap(llcrnrlon=-180,llcrnrlat=-85,urcrnrlon=180,urcrnrlat=85,projection='mill') | |
dataset = 'EO1_HYP_PUB' | |
node = 'EE' | |
patches = [] | |
for year in range(2001, 2016): | |
sceneids = api.search(dataset, node, start_date='%s-01-01' % year, | |
end_date='%s-12-31' % year, | |
max_results=25000, extended=False) | |
print '%d: %d' % (year, len(sceneids)) | |
for s in sceneids: | |
coords = [s['upperLeftCoordinate'], s['upperRightCoordinate'], | |
s['lowerRightCoordinate'], s['lowerLeftCoordinate'], | |
s['upperLeftCoordinate']] | |
lats = [float(c['latitude']) for c in coords] | |
lons = [float(c['longitude']) for c in coords] | |
maxdiff = max(lons) - min(lons) | |
if maxdiff > 90: | |
for i in range(len(lons)): | |
if lons[i] > 0: | |
lons[i] = lons[i] - 360 | |
x, y = m( lons, lats ) | |
xy = zip(x,y) | |
poly = Polygon( xy, facecolor='#e41a1c', edgecolor='#e41a1c', alpha=0.4) | |
patches.append(poly) | |
m.drawcoastlines(linewidth=1.25) | |
m.fillcontinents(color='0.8') | |
m.drawparallels(np.arange(-80,81,20),labels=[1,1,0,0]) | |
m.drawmeridians(np.arange(-180,180,60),labels=[0,0,0,1]) | |
for point in patches: | |
ax.add_patch(point) | |
plt.title(dataset + ' - %d Scenes' % len(patches)) | |
font0 = {'family': 'monospace', 'style': 'italic'} | |
plt.text(0.62, 0.01, '[email protected]', fontdict=font0, transform=ax.transAxes) | |
plt.savefig('hyperion_acqs.png', dpi=80) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment