Skip to content

Instantly share code, notes, and snippets.

View Seagor's full-sized avatar

Sean Gorman Seagor

View GitHub Profile
@Seagor
Seagor / twitter_public_streaming.py
Created July 5, 2016 19:04
Stream and filter Tweets using the Twitter Public Streaming API
#!/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 19:06
Stream and Filter Tweets using the Twitter Public Streaming API
#!/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}}
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'])
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
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):
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()
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):
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:
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')
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