Skip to content

Instantly share code, notes, and snippets.

@djgagne
Last active May 21, 2019 03:21
Show Gist options
  • Save djgagne/efce3db8bcaa814d2a1838958a550301 to your computer and use it in GitHub Desktop.
Save djgagne/efce3db8bcaa814d2a1838958a550301 to your computer and use it in GitHub Desktop.
Spotter Network Chaser Map
import urllib.request
import numpy as np
from scipy.spatial import cKDTree
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from scipy.ndimage import gaussian_filter
from datetime import datetime
import matplotlib.pyplot as plt
fp = urllib.request.urlopen("http://www.spotternetwork.org/feeds/gr-no.txt")
objs = []
for line in fp:
if b"Object" in line:
objs.append(line.decode("utf-8")[7:].strip().split(","))
kd = cKDTree(np.array(objs, dtype=float)[:, ::-1])
lons = np.arange(-102, -95, 0.1)
lats = np.arange(33, 40, 0.1)
lon_grid, lat_grid = np.meshgrid(lons, lats)
points = np.vstack([lon_grid.ravel(), lat_grid.ravel()]).T
print(points.shape)
matches = kd.query_ball_point(points, 0.2)
match_grid = np.array([len(x) for x in matches]).reshape(lon_grid.shape)
proj = ccrs.PlateCarree()
fig = plt.figure(figsize=(10, 6))
ax = fig.add_subplot(1, 1, 1, projection=proj)
countries = cfeature.NaturalEarthFeature("cultural", "admin_0_countries", "50m", facecolor="None", edgecolor="k")
states = cfeature.NaturalEarthFeature("cultural", "admin_1_states_provinces", "50m", facecolor="None", edgecolor="k")
ax.add_feature(countries)
ax.add_feature(states)
plt.pcolormesh(lon_grid, lat_grid, np.ma.array(match_grid, mask=match_grid<=2))
plt.colorbar()
valid = datetime.utcnow()
valid_str = valid.strftime("%Y-%m-%d %H:%M")
valid_out = valid.strftime("%Y%m%d_%H%M")
plt.title(f"Spotter Network Chaser Neighborhood Counts Valid {valid_str}")
plt.savefig(f"chaser_hist_{valid_out}.png", dpi=200, bbox_inches="tight")
@djgagne
Copy link
Author

djgagne commented May 20, 2019

Here is a short script for grabbing and plotting spotter network reports as a neighborhood map.
Requires

  • numpy
  • scipy
  • cartopy
  • matplotlib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment