Skip to content

Instantly share code, notes, and snippets.

View shaystrong's full-sized avatar

Shay Strong shaystrong

  • Helsinki, Finland
  • 11:27 (UTC +03:00)
View GitHub Profile
@shaystrong
shaystrong / ec2jupyter.md
Last active August 28, 2016 02:34
jupyter notebook on EC2
@shaystrong
shaystrong / Readme.md
Last active March 26, 2020 06:52
SWIR DG processing
  1. Image download from ftp --> upload to AWS s3 bucket

  2. Pull to AWS EC2 machine. Save off SWIR band ratios as tif with appropriate contrast. The SWIR data is an 8-band image. You need to first grab onnly the bands you need for visualization (8-3-1 or 6-3-1 make good combos)

import rasterio
import numpy as np

raster='18NOV09185526-A2AS-058669488010_01_P001.TIF'. #your file
import os
import geopandas as gpd
import pandas as pd
import boto3

os.system('cat my_roi_4326.geojson | supermercado burn 18 | mercantile shapes | fio collect > my_roi_4326_outtiles.geojson')

tiles = gpd.read_file('my_roi_4326_outtiles.geojson')
tiles.id=tiles.id.map(lambda x: x.lstrip('(').rstrip(')'))

The Taco GraphTM

ML Team Contest, 1

I have this lovely ‘Keep Pursuing’ backpack with the new EV logo (retail $295). I wanted to give it to the person in our team that has a proven track record of (1) collaborating with others, (2) being helpful, & (3) adding true technical value to our team. So maybe we start by looking at the tacos people on our team have recieved.

alt text. alt text

But wait!...

%matplotlib inline
import osmnx as ox
import matplotlib.pyplot as plt
place_name = "Nzwani Centre, Comores"
graph = ox.graph_from_place(place_name, which_result=2)
fig, ax = ox.plot_graph(graph)
area = ox.gdf_from_place(place_name)
buildings = ox.buildings_from_place(place_name)
@shaystrong
shaystrong / vsicurl & COG
Created May 8, 2019 05:00
use GDAL to grab make a COG vrt
gdalbuildvrt foo.vrt /vsicurl/http://opendata.digitalglobe.com/cyclone-kenneth/pre-event/2017-10-28/103001007206B400/3023101.tif
@shaystrong
shaystrong / GDAL translate + mbtiles
Created May 8, 2019 05:03
translate a tif to mbtiles and unpack them
gdal_translate -of MBTiles nzwani_dg_wv3_05032019_104001004A465900.tif nzwani_dg_wv3_05032019_104001004A465900.mbtiles
mb-util nzwani_dg_wv3_05032019_104001004A465900.mbtiles tiles/
@shaystrong
shaystrong / flattenTMS
Created May 8, 2019 05:10
'flatten' TMS nested xyz to single directory structure
def flattenTMS(tilepath,zoom,voc):
"""flatten the TMS tile structure to put all images in one directory
e.g. tilepath='tiles', zoom='18'"""
import glob,os
for i in glob.glob(tilepath+'/'+zoom+'/*/*png'):
filename_split = os.path.splitext(i)
filename_zero, fileext = filename_split
basename = os.path.basename(filename_zero)
strn=i.split('/')[-3]+'_'+i.split('/')[-2]+'_'+i.split('/')[-1]
#write_xml_annotation(strn, boxCoords)
@shaystrong
shaystrong / building boxes
Created May 8, 2019 05:13
building polygons to rectangles
def footprint2box(vector):
df = vector
df['geometry']=df.envelope #round to nearest (axis-aligned) rectangle
df['class']='building' #all buildings we will just call class=buildings
return df
df=footprint2box(buildings)
@shaystrong
shaystrong / tms_utils
Last active May 8, 2019 05:19
geospatial boxes to VOC xml boxes
def ll2subpix(lat,long):
import numpy as np
n = 2 ** zoom
xtile = n * ((long + 180) / 360)
ytile = n * (1 - (np.log(np.tan(lat*np.pi/180) + 1/(np.cos(lat*np.pi/180))) / np.pi)) / 2
fracy,integery=np.modf(ytile)
fracx,integerx=np.modf(xtile)
return fracy,integery,fracx,integerx
def tmsVOCxml(dirr,label):