Skip to content

Instantly share code, notes, and snippets.

Avatar

Sean Gorman Seagor

View GitHub Profile
@Seagor
Seagor / twitter_public_streaming.py
Created Jul 5, 2016
Stream and filter Tweets using the Twitter Public Streaming API
View twitter_public_streaming.py
#!/bin/sh
"exec" "twxec" "-e" "filter_stream()" "$0" "$@"
import oauth2 as oauth
from trickle import twitter as tw
{{docstring "Make sure you have registered an application with Twitter in order to obtain your credentials. Once you have them, start streaming tweets using one of the filtering parameteres below"}}
app_key = {{string Twitter_App_Key}}
app_secret = {{string Twitter_App_Secret}}
@Seagor
Seagor / twitter_public_streaming.py
Created May 5, 2016
Stream and Filter Tweets using the Twitter Public Streaming API
View twitter_public_streaming.py
#!/bin/sh
"exec" "twxec" "-e" "filter_stream()" "$0" "$@"
import oauth2 as oauth
from trickle import twitter as tw
{{docstring "Make sure you have registered an application with Twitter in order to obtain your credentials. Once you have them, start streaming tweets using one of the filtering parameteres below"}}
app_key = {{string Twitter_App_Key}}
app_secret = {{string Twitter_App_Secret}}
View planet boat size plots.py
import pandas as pd
areas = []
for i, img in enumerate(found_objects):
for r, reg in enumerate(img):
for cnt in reg['contours']:
areas.append((cv2.contourArea(cnt), r, i))
df = pd.DataFrame(data = areas, columns=['area', 'dock', 'image'])
View planet ship counter.py
import cv2
from skimage.morphology import binary_opening
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
%matplotlib inline
View planet dock-land masking.py
normalize = lambda x: (255 / (x.max() - x.min())) * (x - x.min())
smooth = lambda x: ndimage.convolve(x, np.ones([3,3])/9)
def threshold_mask(img, threshold=150):
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
mask = np.ones(gray.shape).astype(np.uint8)
mask[gray < threshold] = 0
return mask
def scanline_mask(imask):
View planet labs pier-boat cropping.py
import numpy as np
import cv2
from skimage import measure
from skimage.measure import regionprops
from skimage.morphology import skeletonize, convex_hull_image, medial_axis, opening
from scipy import ndimage
def seg_buffer(im, dist=25):
mask = im.copy()
View planet labs geotiff downloader.py
from planet import api
import sys, os
import urllib2, httplib
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
class NoRedirection(urllib2.HTTPErrorProcessor):
def http_response(self, request, response):
View planet labs metadata source.py
import gevent
from planet import api
import geojson
bbox = {{ string bbox }}
minx, miny, maxx, maxy = None, None, None, None
if bbox is not None:
minx, miny, maxx, maxy = bbox.split(',')
if minx is not None:
View satellite crop area.py
import os
import rasterio
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
def render_array(arr1, arr2=None, width=7, height=7, cmap=plt.cm.jet):
if arr2 is None:
fig, ax = plt.subplots(1, figsize=(width,height), facecolor='white')
View satellite coastline buffer.py
import cv2
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
def buffer_coastline(img, threshold=135):
arr = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
mask = np.ndarray(arr.shape + (3,)).astype(np.uint8)
below = arr < threshold
You can’t perform that action at this time.